/*
 Ye Wang
 CPEG655
 lab2 problem 1.b
 */
#include <stdio.h>
#include <assert.h>
#include <cuda_runtime.h>
#include <sys/time.h>

__global__ void
matrixMul_1b(int BLOCK_SIZE, float *C, float *A, float *B, int N);

void mm(float * C, float * A, float * B, int N);
float GetRand(int seed);
void randomInit(float *data, int size, float val);
void constantInit(float *data, int size, float val);
int matrixMultiply(int block_size, dim3 &dimsA, dim3 &dimsB);

int main()
{

int block_size = 8;//16 or 8
for(int i=0;i<2;i++,block_size*=2){
    int N=512;
    for(int j=0;j<2;j++,N*=2){
        dim3 dimsA(N,N);
        dim3 dimsB(N,N);
        matrixMultiply(block_size, dimsA, dimsB);
    }
}
    return 0;
}


__global__ void
matrixMul_1b(int BLOCK_SIZE, float *C, float *A, float *B, int N)
{
    // Block index
    int bx = blockIdx.x;
    int by = blockIdx.y;
    // Thread index
    int tx = threadIdx.x+bx*BLOCK_SIZE;
    int ty = threadIdx.y+by*BLOCK_SIZE;
    
    float Csub = 0;
    
    for (int i= 0; i < N; i++)
    {
        Csub+=A[ty*N+i]*B[tx+N*i];
    }
    C[N * ty + tx] = Csub;
}


void mm(float * C, float * A, float * B, int N)
{
    int i,j,k;
    float sum=0;
    for(j=0;j<N;j++)
        for(i=0;i<N;i++){
            C[i*N+j]=0;
            sum=0;
            for(k=0;k<N;k++)
                sum+=A[i*N+k]*B[k*N+j];
            C[i*N+j]=sum;
        }
    
}
float GetRand(int seed)
{
    struct timeval tv;
    gettimeofday(&tv,NULL);
    srand(tv.tv_usec%17+seed);
    return((rand()% 1000) / 1.02);
}

void randomInit(float *data, int size, float val)
{
    for (int i = 0; i < size; ++i)
    {
        data[i] = GetRand(i);
    }
}
void constantInit(float *data, int size, float val)
{
    for (int i = 0; i < size; ++i)
    {
        data[i] = val;//+i%2;
    }
}

int matrixMultiply( int block_size, dim3 &dimsA, dim3 &dimsB)
{
    printf("START: Block[%d,%d], Matrix[%d,%d]\n",block_size,block_size,dimsB.x,dimsA.y);
    // Allocate host memory for matrices A and B
    unsigned int size_A = dimsA.x * dimsA.y;
    unsigned int mem_size_A = sizeof(float) * size_A;
    float *h_A = (float *)malloc(mem_size_A);
    unsigned int size_B = dimsB.x * dimsB.y;
    unsigned int mem_size_B = sizeof(float) * size_B;
    float *h_B = (float *)malloc(mem_size_B);
    
    // Initialize host memory
    randomInit(h_A, size_A, 2.1f);
    randomInit(h_B, size_B, 1.f);
    
    unsigned int size_C = dimsB.x * dimsA.y;
    // Allocate device memory
    float *d_A, *d_B, *d_C;
    dim3 dimsC(dimsB.x, dimsA.y, 1);
    unsigned int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
    float *h_C = (float *) malloc(mem_size_C);
    float *test_C = (float *) malloc(mem_size_C);
    constantInit(test_C, size_C, 0.f);
    constantInit(h_C, size_C, 0.f);
    cudaMalloc((void **) &d_A, mem_size_A);
    cudaMalloc((void **) &d_B, mem_size_B);
    cudaMalloc((void **) &d_C, mem_size_C);
    cudaMemcpy(d_A, h_A, mem_size_A, cudaMemcpyHostToDevice);
    cudaMemcpy(d_B, h_B, mem_size_B, cudaMemcpyHostToDevice);
    cudaMemcpy(d_C, h_C, mem_size_C, cudaMemcpyHostToDevice);
    // Setup execution parameters
    dim3 threads(block_size, block_size);
    dim3 grid(dimsA.y/block_size, dimsB.x/block_size);
    cudaDeviceSynchronize();//////////////////////****
    
    // Allocate CUDA events that we'll use for timing
    cudaEvent_t start;
    cudaEventCreate(&start);
    
    cudaEvent_t stop;
    cudaEventCreate(&stop);
    
    // Record the start event
    cudaEventRecord(start, NULL);
    
    // Execute th kernel
    int nIter = 100;
    
    for (int j = 0; j < nIter; j++)
    {
        matrixMul_1b<<< grid, threads >>>(block_size, d_C, d_A, d_B, dimsA.x);
    }
    
    // Record the stop event
    cudaEventRecord(stop, NULL);
    
    cudaEventSynchronize(stop);
    
    float msecTotal = 0.0f;
    cudaEventElapsedTime(&msecTotal, start, stop);
    
    // Compute and print the performance
    float msecPerMatrixMul = msecTotal / nIter;
    double flopsPerMatrixMul = 2.0 * (double)dimsA.x * (double)dimsA.y * (double)dimsB.x;
    double gigaFlops = (flopsPerMatrixMul * 1.0e-9f) / (msecPerMatrixMul / 1000.0f);
    printf( "REPORT:\n Performance= %.2f GFlop/s\n Time= %.3f msec\n Size= %.0f Ops\n WorkgroupSize= %u threads/block\n",
           gigaFlops,
           msecPerMatrixMul,
           flopsPerMatrixMul,
           threads.x * threads.y);
    
    // Copy t_C,h_A,h_B,dimsA.x);esult from device to host
    cudaMemcpy(h_C, d_C, mem_size_C, cudaMemcpyDeviceToHost);
    
    //double eps = 1.e-6 ;
    mm(test_C,h_A,h_B,dimsA.x);
    int verify=1;
    for (int i=0;i<mem_size_C/4;i++)
    {
        if(h_C[i]!=test_C[i]&&(fabs(h_C[i]-test_C[i])/test_C[i])>1E-6){
            printf("Matrix[A:%d,B:%d,C:%d] C[%d]=%f,  Expect= %f\n",mem_size_A,mem_size_B,mem_size_C,i,h_C[i],test_C[i]);
            verify=0;
            break;
        }
    }
    free(h_A);
    free(test_C);
    free(h_B);
    free(h_C);
    cudaFree(d_A);
    cudaFree(d_B);
    cudaFree(d_C);
    cudaDeviceReset();
    if (verify) {
        printf("SUCCESS!\n\n");
        return true;
    }else{
        printf("WRONG RESULT!\n\n");
        return false;
    }    
}


	.file	"tmpxft_003537cc_00000000-6_1b.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z2mmPfS_S_i
	.type	_Z2mmPfS_S_i, @function
_Z2mmPfS_S_i:
.LFB2028:
	.cfi_startproc
	endbr64
	movslq	%ecx, %rax
	xorl	%r9d, %r9d
	movq	%rsi, %r11
	movq	%rdi, %r10
	salq	$2, %rax
	xorl	%esi, %esi
	cmpl	%ecx, %r9d
	jl	.L11
	ret
.L11:
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
.L6:
	leaq	(%r10,%rsi), %rdi
	movq	%r11, %rbp
	xorl	%ebx, %ebx
.L5:
	movl	$0x00000000, (%rdi)
	leaq	(%rdx,%rsi), %r12
	xorl	%r8d, %r8d
	xorps	%xmm0, %xmm0
.L4:
	movss	0(%rbp,%r8,4), %xmm1
	mulss	(%r12), %xmm1
	incq	%r8
	addq	%rax, %r12
	addss	%xmm1, %xmm0
	cmpl	%r8d, %ecx
	jg	.L4
	incl	%ebx
	movss	%xmm0, (%rdi)
	addq	%rax, %rbp
	addq	%rax, %rdi
	cmpl	%ebx, %ecx
	jne	.L5
	incl	%r9d
	addq	$4, %rsi
	cmpl	%ecx, %r9d
	jl	.L6
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z2mmPfS_S_i, .-_Z2mmPfS_S_i
	.globl	_Z7GetRandi
	.type	_Z7GetRandi, @function
_Z7GetRandi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	xorl	%esi, %esi
	movl	%edi, %ebx
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	movq	16(%rsp), %rax
	movl	$17, %ecx
	cqto
	idivq	%rcx
	leal	(%rbx,%rdx), %edi
	call	srand@PLT
	call	rand@PLT
	movl	$1000, %ecx
	cltd
	idivl	%ecx
	cvtsi2sdl	%edx, %xmm0
	divsd	.LC1(%rip), %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	cvtsd2ss	%xmm0, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7GetRandi, .-_Z7GetRandi
	.globl	_Z10randomInitPfif
	.type	_Z10randomInitPfif, @function
_Z10randomInitPfif:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L17:
	movl	%ebx, %edi
	cmpl	%ebx, %ebp
	jle	.L20
	call	_Z7GetRandi
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L17
.L20:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z10randomInitPfif, .-_Z10randomInitPfif
	.globl	_Z12constantInitPfif
	.type	_Z12constantInitPfif, @function
_Z12constantInitPfif:
.LFB2031:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L22:
	cmpl	%eax, %esi
	jle	.L24
	movss	%xmm0, (%rdi,%rax,4)
	incq	%rax
	jmp	.L22
.L24:
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z12constantInitPfif, .-_Z12constantInitPfif
	.globl	_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i
	.type	_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i, @function
_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 24(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movq	%rsp, %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z12matrixMul_1biPfS_S_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L25:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i, .-_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i
	.globl	_Z12matrixMul_1biPfS_S_i
	.type	_Z12matrixMul_1biPfS_S_i, @function
_Z12matrixMul_1biPfS_S_i:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i
	.cfi_endproc
.LFE2058:
	.size	_Z12matrixMul_1biPfS_S_i, .-_Z12matrixMul_1biPfS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"START: Block[%d,%d], Matrix[%d,%d]\n"
.LC8:
	.string	"REPORT:\n Performance= %.2f GFlop/s\n Time= %.3f msec\n Size= %.0f Ops\n WorkgroupSize= %u threads/block\n"
.LC11:
	.string	"Matrix[A:%d,B:%d,C:%d] C[%d]=%f,  Expect= %f\n"
.LC12:
	.string	"SUCCESS!\n\n"
.LC13:
	.string	"WRONG RESULT!\n\n"
	.text
	.globl	_Z14matrixMultiplyiR4dim3S0_
	.type	_Z14matrixMultiplyiR4dim3S0_, @function
_Z14matrixMultiplyiR4dim3S0_:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edi, %ecx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movl	4(%rsi), %r9d
	movl	(%rdx), %r8d
	movl	%edi, %edx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	0(%rbp), %r15d
	imull	4(%rbp), %r15d
	leal	0(,%r15,4), %r14d
	movq	%r14, %rdi
	movl	%r14d, 52(%rsp)
	call	malloc@PLT
	movl	0(%r13), %r12d
	imull	4(%r13), %r12d
	movq	%rax, 16(%rsp)
	leal	0(,%r12,4), %eax
	movq	%rax, %rdi
	movl	%eax, 56(%rsp)
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movss	.LC3(%rip), %xmm0
	movq	16(%rsp), %rdi
	movl	%r15d, %esi
	movq	%rax, 24(%rsp)
	call	_Z10randomInitPfif
	movss	.LC4(%rip), %xmm0
	movq	24(%rsp), %rdi
	movl	%r12d, %esi
	call	_Z10randomInitPfif
	movl	0(%r13), %r12d
	imull	4(%rbp), %r12d
	leal	0(,%r12,4), %eax
	movq	%rax, %rdi
	movl	%eax, 60(%rsp)
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r15
	call	malloc@PLT
	xorps	%xmm0, %xmm0
	movl	%r12d, %esi
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	_Z12constantInitPfif
	movq	%r15, %rdi
	call	_Z12constantInitPfif
	movq	%r14, %rsi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	movq	72(%rsp), %rdi
	movq	%r14, %rdx
	movl	$1, %ecx
	movl	$100, %r14d
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movq	80(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	88(%rsp), %rdi
	movq	8(%rsp), %rdx
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	0(%r13), %eax
	xorl	%edx, %edx
	movl	$1, 120(%rsp)
	movl	$1, 132(%rsp)
	divl	%ebx
	xorl	%edx, %edx
	movl	%eax, %ecx
	movl	4(%rbp), %eax
	movl	%ecx, 128(%rsp)
	divl	%ebx
	movl	%eax, 124(%rsp)
	call	cudaDeviceSynchronize@PLT
	leaq	96(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	104(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	96(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
.L32:
	movl	%ebx, 112(%rsp)
	movl	120(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	124(%rsp), %rdi
	movl	132(%rsp), %esi
	movl	%ebx, 116(%rsp)
	movq	112(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movl	0(%rbp), %r8d
	movq	80(%rsp), %rcx
	movl	%ebx, %edi
	movq	72(%rsp), %rdx
	movq	88(%rsp), %rsi
	call	_Z38__device_stub__Z12matrixMul_1biPfS_S_iiPfS_S_i
.L31:
	decl	%r14d
	jne	.L32
	movq	104(%rsp), %rdi
	xorl	%esi, %esi
	imull	%ebx, %ebx
	andl	$1073741823, %r12d
	call	cudaEventRecord@PLT
	movq	104(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	104(%rsp), %rdx
	movq	96(%rsp), %rsi
	leaq	68(%rsp), %rdi
	movl	$0x00000000, 68(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	0(%rbp), %eax
	movss	68(%rsp), %xmm1
	movl	%ebx, %edx
	divss	.LC5(%rip), %xmm1
	movaps	%xmm1, %xmm3
	movl	$2, %edi
	divss	.LC7(%rip), %xmm3
	cvtsi2sdq	%rax, %xmm2
	movl	4(%rbp), %eax
	cvtss2sd	%xmm3, %xmm3
	cvtss2sd	%xmm1, %xmm1
	leaq	.LC8(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	movl	0(%r13), %eax
	addsd	%xmm2, %xmm2
	mulsd	%xmm0, %xmm2
	cvtsi2sdq	%rax, %xmm0
	movb	$3, %al
	mulsd	%xmm0, %xmm2
	movsd	.LC6(%rip), %xmm0
	mulsd	%xmm2, %xmm0
	divsd	%xmm3, %xmm0
	call	__printf_chk@PLT
	movq	8(%rsp), %rdx
	movq	88(%rsp), %rsi
	movq	%r15, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	0(%rbp), %ecx
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z2mmPfS_S_i
	movsd	.LC10(%rip), %xmm4
	xorl	%r9d, %r9d
	movss	.LC9(%rip), %xmm3
.L39:
	cmpl	%r12d, %r9d
	jnb	.L53
	movq	32(%rsp), %rax
	movss	(%r15,%r9,4), %xmm0
	movss	(%rax,%r9,4), %xmm1
	ucomiss	%xmm1, %xmm0
	jp	.L48
	je	.L40
.L48:
	movaps	%xmm0, %xmm2
	subss	%xmm1, %xmm2
	andps	%xmm3, %xmm2
	divss	%xmm1, %xmm2
	cvtss2sd	%xmm2, %xmm2
	comisd	%xmm4, %xmm2
	jbe	.L40
	movl	60(%rsp), %r8d
	movl	56(%rsp), %ecx
	movl	$2, %edi
	movb	$2, %al
	movl	52(%rsp), %edx
	cvtss2sd	%xmm0, %xmm0
	leaq	.LC11(%rip), %rsi
	cvtss2sd	%xmm1, %xmm1
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	jmp	.L43
.L40:
	incq	%r9
	jmp	.L39
.L53:
	movl	$1, %ebx
.L43:
	movq	16(%rsp), %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	%r15, %rdi
	call	free@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	call	cudaDeviceReset@PLT
	leaq	.LC12(%rip), %rsi
	testl	%ebx, %ebx
	jne	.L52
	leaq	.LC13(%rip), %rsi
.L52:
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L47
	call	__stack_chk_fail@PLT
.L47:
	addq	$152, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z14matrixMultiplyiR4dim3S0_, .-_Z14matrixMultiplyiR4dim3S0_
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movabsq	$2199023256064, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	$2, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	$8, %ebx
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
.L55:
	leaq	12(%rsp), %r13
	movq	%rsp, %r12
	movl	%ebx, %edi
	movq	%r14, (%rsp)
	movq	%r13, %rdx
	movq	%r12, %rsi
	movl	$1, 8(%rsp)
	movq	%r14, 12(%rsp)
	movl	$1, 20(%rsp)
	call	_Z14matrixMultiplyiR4dim3S0_
	movl	%ebx, %edi
	movq	%r13, %rdx
	movq	%r12, %rsi
	movabsq	$4398046512128, %rax
	movl	$1, 8(%rsp)
	addl	%ebx, %ebx
	movq	%rax, (%rsp)
	movq	%rax, 12(%rsp)
	movl	$1, 20(%rsp)
	call	_Z14matrixMultiplyiR4dim3S0_
	decl	%ebp
	je	.L59
	movl	$1, %ebp
	jmp	.L55
.L59:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z12matrixMul_1biPfS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12matrixMul_1biPfS_S_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	-2061584302
	.long	1072714219
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1074161254
	.align 4
.LC4:
	.long	1065353216
	.align 4
.LC5:
	.long	1120403456
	.section	.rodata.cst8
	.align 8
.LC6:
	.long	-536870912
	.long	1041313291
	.section	.rodata.cst4
	.align 4
.LC7:
	.long	1148846080
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC9:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC10:
	.long	-1598689907
	.long	1051772663
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

/*
 Ye Wang
 CPEG655
 lab2 problem 1.b
 */
#include <stdio.h>
#include <assert.h>
#include <hip/hip_runtime.h>
#include <sys/time.h>

__global__ void
matrixMul_1b(int BLOCK_SIZE, float *C, float *A, float *B, int N);

void mm(float * C, float * A, float * B, int N);
float GetRand(int seed);
void randomInit(float *data, int size, float val);
void constantInit(float *data, int size, float val);
int matrixMultiply(int block_size, dim3 &dimsA, dim3 &dimsB);

int main()
{

int block_size = 8;//16 or 8
for(int i=0;i<2;i++,block_size*=2){
    int N=512;
    for(int j=0;j<2;j++,N*=2){
        dim3 dimsA(N,N);
        dim3 dimsB(N,N);
        matrixMultiply(block_size, dimsA, dimsB);
    }
}
    return 0;
}


__global__ void
matrixMul_1b(int BLOCK_SIZE, float *C, float *A, float *B, int N)
{
    // Block index
    int bx = blockIdx.x;
    int by = blockIdx.y;
    // Thread index
    int tx = threadIdx.x+bx*BLOCK_SIZE;
    int ty = threadIdx.y+by*BLOCK_SIZE;
    
    float Csub = 0;
    
    for (int i= 0; i < N; i++)
    {
        Csub+=A[ty*N+i]*B[tx+N*i];
    }
    C[N * ty + tx] = Csub;
}


void mm(float * C, float * A, float * B, int N)
{
    int i,j,k;
    float sum=0;
    for(j=0;j<N;j++)
        for(i=0;i<N;i++){
            C[i*N+j]=0;
            sum=0;
            for(k=0;k<N;k++)
                sum+=A[i*N+k]*B[k*N+j];
            C[i*N+j]=sum;
        }
    
}
float GetRand(int seed)
{
    struct timeval tv;
    gettimeofday(&tv,NULL);
    srand(tv.tv_usec%17+seed);
    return((rand()% 1000) / 1.02);
}

void randomInit(float *data, int size, float val)
{
    for (int i = 0; i < size; ++i)
    {
        data[i] = GetRand(i);
    }
}
void constantInit(float *data, int size, float val)
{
    for (int i = 0; i < size; ++i)
    {
        data[i] = val;//+i%2;
    }
}

int matrixMultiply( int block_size, dim3 &dimsA, dim3 &dimsB)
{
    printf("START: Block[%d,%d], Matrix[%d,%d]\n",block_size,block_size,dimsB.x,dimsA.y);
    // Allocate host memory for matrices A and B
    unsigned int size_A = dimsA.x * dimsA.y;
    unsigned int mem_size_A = sizeof(float) * size_A;
    float *h_A = (float *)malloc(mem_size_A);
    unsigned int size_B = dimsB.x * dimsB.y;
    unsigned int mem_size_B = sizeof(float) * size_B;
    float *h_B = (float *)malloc(mem_size_B);
    
    // Initialize host memory
    randomInit(h_A, size_A, 2.1f);
    randomInit(h_B, size_B, 1.f);
    
    unsigned int size_C = dimsB.x * dimsA.y;
    // Allocate device memory
    float *d_A, *d_B, *d_C;
    dim3 dimsC(dimsB.x, dimsA.y, 1);
    unsigned int mem_size_C = dimsC.x * dimsC.y * sizeof(float);
    float *h_C = (float *) malloc(mem_size_C);
    float *test_C = (float *) malloc(mem_size_C);
    constantInit(test_C, size_C, 0.f);
    constantInit(h_C, size_C, 0.f);
    hipMalloc((void **) &d_A, mem_size_A);
    hipMalloc((void **) &d_B, mem_size_B);
    hipMalloc((void **) &d_C, mem_size_C);
    hipMemcpy(d_A, h_A, mem_size_A, hipMemcpyHostToDevice);
    hipMemcpy(d_B, h_B, mem_size_B, hipMemcpyHostToDevice);
    hipMemcpy(d_C, h_C, mem_size_C, hipMemcpyHostToDevice);
    // Setup execution parameters
    dim3 threads(block_size, block_size);
    dim3 grid(dimsA.y/block_size, dimsB.x/block_size);
    hipDeviceSynchronize();//////////////////////****
    
    // Allocate CUDA events that we'll use for timing
    hipEvent_t start;
    hipEventCreate(&start);
    
    hipEvent_t stop;
    hipEventCreate(&stop);
    
    // Record the start event
    hipEventRecord(start, NULL);
    
    // Execute th kernel
    int nIter = 100;
    
    for (int j = 0; j < nIter; j++)
    {
        matrixMul_1b<<< grid, threads >>>(block_size, d_C, d_A, d_B, dimsA.x);
    }
    
    // Record the stop event
    hipEventRecord(stop, NULL);
    
    hipEventSynchronize(stop);
    
    float msecTotal = 0.0f;
    hipEventElapsedTime(&msecTotal, start, stop);
    
    // Compute and print the performance
    float msecPerMatrixMul = msecTotal / nIter;
    double flopsPerMatrixMul = 2.0 * (double)dimsA.x * (double)dimsA.y * (double)dimsB.x;
    double gigaFlops = (flopsPerMatrixMul * 1.0e-9f) / (msecPerMatrixMul / 1000.0f);
    printf( "REPORT:\n Performance= %.2f GFlop/s\n Time= %.3f msec\n Size= %.0f Ops\n WorkgroupSize= %u threads/block\n",
           gigaFlops,
           msecPerMatrixMul,
           flopsPerMatrixMul,
           threads.x * threads.y);
    
    // Copy t_C,h_A,h_B,dimsA.x);esult from device to host
    hipMemcpy(h_C, d_C, mem_size_C, hipMemcpyDeviceToHost);
    
    //double eps = 1.e-6 ;
    mm(test_C,h_A,h_B,dimsA.x);
    int verify=1;
    for (int i=0;i<mem_size_C/4;i++)
    {
        if(h_C[i]!=test_C[i]&&(fabs(h_C[i]-test_C[i])/test_C[i])>1E-6){
            printf("Matrix[A:%d,B:%d,C:%d] C[%d]=%f,  Expect= %f\n",mem_size_A,mem_size_B,mem_size_C,i,h_C[i],test_C[i]);
            verify=0;
            break;
        }
    }
    free(h_A);
    free(test_C);
    free(h_B);
    free(h_C);
    hipFree(d_A);
    hipFree(d_B);
    hipFree(d_C);
    hipDeviceReset();
    if (verify) {
        printf("SUCCESS!\n\n");
        return true;
    }else{
        printf("WRONG RESULT!\n\n");
        return false;
    }    
}


	.text
	.file	"1b.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$8, %ebx
	movb	$1, %al
	movl	$1, %r12d
	leaq	28(%rsp), %r14
	leaq	16(%rsp), %r15
.LBB0_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	movl	%eax, 12(%rsp)                  # 4-byte Spill
	movl	$512, %r13d                     # imm = 0x200
	movb	$1, %bpl
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r13d, 28(%rsp)
	movl	%r13d, 32(%rsp)
	movl	%r12d, 36(%rsp)
	movl	%r13d, 16(%rsp)
	movl	%r13d, 20(%rsp)
	movl	%r12d, 24(%rsp)
	movl	%ebx, %edi
	movq	%r14, %rsi
	movq	%r15, %rdx
	callq	_Z14matrixMultiplyiR4dim3S0_
	addl	%r13d, %r13d
	testb	$1, %bpl
	movl	$0, %ebp
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	addl	%ebx, %ebx
	testb	$1, 12(%rsp)                    # 1-byte Folded Reload
	movl	$0, %eax
	jne	.LBB0_1
# %bb.4:
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z14matrixMultiplyiR4dim3S0_
.LCPI1_0:
	.long	0x42c80000                      # float 100
.LCPI1_2:
	.long	0x447a0000                      # float 1000
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_1:
	.quad	0x3e112e0be0000000              # double 9.9999997171806853E-10
.LCPI1_4:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI1_3:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.text
	.globl	_Z14matrixMultiplyiR4dim3S0_
	.type	_Z14matrixMultiplyiR4dim3S0_,@function
_Z14matrixMultiplyiR4dim3S0_:           # @_Z14matrixMultiplyiR4dim3S0_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r12
	movq	%rsi, %r14
	movl	%edi, %r15d
	movl	(%rdx), %ecx
	movl	4(%rsi), %r8d
	movl	$.L.str, %edi
	movl	%r15d, %esi
	movl	%r15d, %edx
	xorl	%eax, %eax
	callq	printf
	movl	4(%r14), %ebx
	movq	%r14, (%rsp)                    # 8-byte Spill
	imull	(%r14), %ebx
	leal	(,%rbx,4), %edi
	movq	%rdi, 56(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %r13
	movl	4(%r12), %ebp
	movq	%r12, 16(%rsp)                  # 8-byte Spill
	imull	(%r12), %ebp
	leal	(,%rbp,4), %edi
	movq	%rdi, 48(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %r14
	testl	%ebx, %ebx
	jle	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader.i
	movl	%ebx, %ebx
	xorl	%r12d, %r12d
.LBB1_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movl	%r12d, %edi
	callq	_Z7GetRandi
	movss	%xmm0, (%r13,%r12,4)
	incq	%r12
	cmpq	%r12, %rbx
	jne	.LBB1_2
.LBB1_3:                                # %_Z10randomInitPfif.exit
	movq	%r13, 64(%rsp)                  # 8-byte Spill
	testl	%ebp, %ebp
	jle	.LBB1_6
# %bb.4:                                # %.lr.ph.preheader.i99
	movl	%ebp, %ebx
	xorl	%r12d, %r12d
.LBB1_5:                                # %.lr.ph.i101
                                        # =>This Inner Loop Header: Depth=1
	movl	%r12d, %edi
	callq	_Z7GetRandi
	movss	%xmm0, (%r14,%r12,4)
	incq	%r12
	cmpq	%r12, %rbx
	jne	.LBB1_5
.LBB1_6:                                # %_Z10randomInitPfif.exit105
	movq	(%rsp), %rax                    # 8-byte Reload
	movl	4(%rax), %r13d
	movq	16(%rsp), %rax                  # 8-byte Reload
	imull	(%rax), %r13d
	leal	(,%r13,4), %ebx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %rbp
	movq	%rbx, 72(%rsp)                  # 8-byte Spill
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %rbx
	testl	%r13d, %r13d
	jle	.LBB1_8
# %bb.7:                                # %.lr.ph.preheader.i106
	movl	%r13d, %r12d
	shlq	$2, %r12
	movq	%rbx, %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	callq	memset@PLT
	movq	%rbp, %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	callq	memset@PLT
.LBB1_8:                                # %_Z12constantInitPfif.exit118
	movq	%r13, 80(%rsp)                  # 8-byte Spill
	movq	%rbx, 88(%rsp)                  # 8-byte Spill
	leaq	40(%rsp), %rdi
	movq	56(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	48(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	72(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	40(%rsp), %rax
	movq	(%rax), %rdi
	movq	64(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rax
	movq	(%rax), %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rax
	movq	(%rax), %rdi
	movq	%rbp, 96(%rsp)                  # 8-byte Spill
	movq	%rbp, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%r15d, %eax
	movq	%rax, %r12
	shlq	$32, %r12
	orq	%rax, %r12
	movq	(%rsp), %rax                    # 8-byte Reload
	movl	4(%rax), %eax
	xorl	%edx, %edx
	divl	%r15d
	movl	%eax, %ecx
	movq	16(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %eax
	xorl	%edx, %edx
	divl	%r15d
	movl	%eax, %ebp
	shlq	$32, %rbp
	orq	%rcx, %rbp
	callq	hipDeviceSynchronize
	leaq	104(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$100, %ebx
.LBB1_9:                                # =>This Inner Loop Header: Depth=1
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_11
# %bb.10:                               #   in Loop: Header=BB1_9 Depth=1
	movq	8(%rsp), %rsi
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rcx
	movq	(%rsp), %rax                    # 8-byte Reload
	movl	(%rax), %r8d
	movl	%r15d, %edi
	callq	_Z27__device_stub__matrixMul_1biPfS_S_i
.LBB1_11:                               #   in Loop: Header=BB1_9 Depth=1
	decl	%ebx
	jne	.LBB1_9
# %bb.12:
	movq	24(%rsp), %rdi
	xorl	%ebp, %ebp
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	116(%rsp), %r12
	movl	$0, (%r12)
	movq	104(%rsp), %rsi
	movq	24(%rsp), %rdx
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	movss	(%r12), %xmm3                   # xmm3 = mem[0],zero,zero,zero
	divss	.LCPI1_0(%rip), %xmm3
	movq	(%rsp), %rbx                    # 8-byte Reload
	movl	(%rbx), %eax
	movl	4(%rbx), %ecx
	cvtsi2sd	%rax, %xmm0
	addsd	%xmm0, %xmm0
	cvtsi2sd	%rcx, %xmm1
	mulsd	%xmm0, %xmm1
	movq	16(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %eax
	cvtsi2sd	%rax, %xmm2
	mulsd	%xmm1, %xmm2
	movsd	.LCPI1_1(%rip), %xmm0           # xmm0 = mem[0],zero
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm3, %xmm1
	divss	.LCPI1_2(%rip), %xmm3
	mulsd	%xmm2, %xmm0
	cvtss2sd	%xmm3, %xmm3
	divsd	%xmm3, %xmm0
	imull	%r15d, %r15d
	movl	$.L.str.1, %edi
	movl	%r15d, %esi
	movb	$3, %al
	callq	printf
	movq	8(%rsp), %rsi
	movq	96(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%rbx), %ecx
	movq	88(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdi
	movq	64(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rsi
	movq	%r14, %rdx
	callq	_Z2mmPfS_S_i
	movq	80(%rsp), %rax                  # 8-byte Reload
	andl	$1073741823, %eax               # imm = 0x3FFFFFFF
	je	.LBB1_18
# %bb.13:                               # %.lr.ph.preheader
	movl	%eax, %eax
	movb	$1, %bpl
	xorl	%r8d, %r8d
	movaps	.LCPI1_3(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movsd	.LCPI1_4(%rip), %xmm2           # xmm2 = mem[0],zero
.LBB1_14:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r15,%r8,4), %xmm3             # xmm3 = mem[0],zero,zero,zero
	movss	(%r12,%r8,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm3
	jne	.LBB1_15
	jnp	.LBB1_17
.LBB1_15:                               #   in Loop: Header=BB1_14 Depth=1
	movaps	%xmm3, %xmm4
	subss	%xmm1, %xmm4
	andps	%xmm0, %xmm4
	cvtss2sd	%xmm4, %xmm4
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm1, %xmm4
	ucomisd	%xmm2, %xmm4
	ja	.LBB1_16
.LBB1_17:                               #   in Loop: Header=BB1_14 Depth=1
	incq	%r8
	cmpq	%rax, %r8
	setb	%bpl
	jne	.LBB1_14
	jmp	.LBB1_18
.LBB1_16:
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm3, %xmm0
	movl	$.L.str.2, %edi
	movq	56(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movq	48(%rsp), %rdx                  # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	%r13d, %ecx
                                        # kill: def $r8d killed $r8d killed $r8
	movb	$2, %al
	callq	printf
.LBB1_18:                               # %.loopexit
	movq	%rbx, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	callq	hipDeviceReset
	movl	$.Lstr, %eax
	movl	$.Lstr.1, %edi
	testb	$1, %bpl
	cmovneq	%rax, %rdi
	notb	%bpl
	movzbl	%bpl, %ebx
	andl	$1, %ebx
	callq	puts@PLT
	movl	%ebx, %eax
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z14matrixMultiplyiR4dim3S0_, .Lfunc_end1-_Z14matrixMultiplyiR4dim3S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z27__device_stub__matrixMul_1biPfS_S_i # -- Begin function _Z27__device_stub__matrixMul_1biPfS_S_i
	.type	_Z27__device_stub__matrixMul_1biPfS_S_i,@function
_Z27__device_stub__matrixMul_1biPfS_S_i: # @_Z27__device_stub__matrixMul_1biPfS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	4(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	24(%rsp), %rdx
	movq	%rcx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z12matrixMul_1biPfS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z27__device_stub__matrixMul_1biPfS_S_i, .Lfunc_end2-_Z27__device_stub__matrixMul_1biPfS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z2mmPfS_S_i                    # -- Begin function _Z2mmPfS_S_i
	.type	_Z2mmPfS_S_i,@function
_Z2mmPfS_S_i:                           # @_Z2mmPfS_S_i
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB3_8
# %bb.1:                                # %.preheader.lr.ph
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%ecx, %eax
	leaq	(,%rax,4), %r8
	xorl	%r9d, %r9d
.LBB3_2:                                # %.lr.ph33.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_3 Depth 2
                                        #       Child Loop BB3_4 Depth 3
	leaq	(%rdi,%r9,4), %r10
	xorl	%r11d, %r11d
	xorl	%ebx, %ebx
.LBB3_3:                                # %.lr.ph33
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_4 Depth 3
	movl	%r11d, %r14d
	leaq	(%rsi,%r14,4), %r15
	movq	%rbx, %r14
	imulq	%rax, %r14
	movl	$0, (%r10,%r14,4)
	xorps	%xmm0, %xmm0
	movq	%rdx, %r12
	xorl	%r13d, %r13d
.LBB3_4:                                #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_3 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r15,%r13,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%r12), %xmm1
	addss	%xmm1, %xmm0
	incq	%r13
	addq	%r8, %r12
	cmpq	%r13, %rax
	jne	.LBB3_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB3_3 Depth=2
	movss	%xmm0, (%r10,%r14,4)
	incq	%rbx
	addl	%ecx, %r11d
	cmpq	%rax, %rbx
	jne	.LBB3_3
# %bb.6:                                # %._crit_edge34
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%r9
	addq	$4, %rdx
	cmpq	%rax, %r9
	jne	.LBB3_2
# %bb.7:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
.LBB3_8:                                # %._crit_edge36
	retq
.Lfunc_end3:
	.size	_Z2mmPfS_S_i, .Lfunc_end3-_Z2mmPfS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7GetRandi
.LCPI4_0:
	.quad	0x3ff051eb851eb852              # double 1.02
	.text
	.globl	_Z7GetRandi
	.type	_Z7GetRandi,@function
_Z7GetRandi:                            # @_Z7GetRandi
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edi, %ebx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	8(%r14), %rcx
	movabsq	$8680820740569200761, %rdx      # imm = 0x7878787878787879
	movq	%rcx, %rax
	imulq	%rdx
	movq	%rdx, %rax
	shrq	$63, %rax
	shrq	$3, %rdx
	addl	%eax, %edx
	movl	%edx, %eax
	shll	$4, %eax
	addl	%edx, %eax
	subl	%eax, %ecx
	addl	%ecx, %ebx
	movl	%ebx, %edi
	callq	srand
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	subl	%ecx, %eax
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z7GetRandi, .Lfunc_end4-_Z7GetRandi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10randomInitPfif              # -- Begin function _Z10randomInitPfif
	.type	_Z10randomInitPfif,@function
_Z10randomInitPfif:                     # @_Z10randomInitPfif
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB5_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r15d
	xorl	%r14d, %r14d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%r14d, %edi
	callq	_Z7GetRandi
	movss	%xmm0, (%rbx,%r14,4)
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB5_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB5_4:                                # %._crit_edge
	retq
.Lfunc_end5:
	.size	_Z10randomInitPfif, .Lfunc_end5-_Z10randomInitPfif
	.cfi_endproc
                                        # -- End function
	.globl	_Z12constantInitPfif            # -- Begin function _Z12constantInitPfif
	.type	_Z12constantInitPfif,@function
_Z12constantInitPfif:                   # @_Z12constantInitPfif
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB6_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%esi, %eax
	xorl	%ecx, %ecx
.LBB6_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	%xmm0, (%rdi,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB6_2
.LBB6_3:                                # %._crit_edge
	retq
.Lfunc_end6:
	.size	_Z12constantInitPfif, .Lfunc_end6-_Z12constantInitPfif
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12matrixMul_1biPfS_S_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12matrixMul_1biPfS_S_i,@object # @_Z12matrixMul_1biPfS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z12matrixMul_1biPfS_S_i
	.p2align	3, 0x0
_Z12matrixMul_1biPfS_S_i:
	.quad	_Z27__device_stub__matrixMul_1biPfS_S_i
	.size	_Z12matrixMul_1biPfS_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"START: Block[%d,%d], Matrix[%d,%d]\n"
	.size	.L.str, 36

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"REPORT:\n Performance= %.2f GFlop/s\n Time= %.3f msec\n Size= %.0f Ops\n WorkgroupSize= %u threads/block\n"
	.size	.L.str.1, 102

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Matrix[A:%d,B:%d,C:%d] C[%d]=%f,  Expect= %f\n"
	.size	.L.str.2, 46

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12matrixMul_1biPfS_S_i"
	.size	.L__unnamed_1, 25

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"WRONG RESULT!\n"
	.size	.Lstr, 15

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"SUCCESS!\n"
	.size	.Lstr.1, 10

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z27__device_stub__matrixMul_1biPfS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12matrixMul_1biPfS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12matrixMul_1biPfS_S_i ; -- Begin function _Z12matrixMul_1biPfS_S_i
	.globl	_Z12matrixMul_1biPfS_S_i
	.p2align	8
	.type	_Z12matrixMul_1biPfS_S_i,@function
_Z12matrixMul_1biPfS_S_i:               ; @_Z12matrixMul_1biPfS_S_i
; %bb.0:
	s_clause 0x2
	s_load_b32 s7, s[0:1], 0x0
	s_load_b32 s6, s[0:1], 0x20
	s_load_b64 s[4:5], s[0:1], 0x18
	v_bfe_u32 v1, v0, 10, 10
	s_load_b128 s[0:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s7, v[1:2]
	v_and_b32_e32 v3, 0x3ff, v0
	s_cmp_lt_i32 s6, 1
	v_mad_u64_u32 v[0:1], null, s14, s7, v[3:4]
	s_delay_alu instid0(VALU_DEP_3)
	v_mul_lo_u32 v1, v2, s6
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v2, 31, v1
	v_mov_b32_e32 v6, 0
	v_mov_b32_e32 v4, v0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s2, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v3, vcc_lo
	s_mov_b32 s2, s6
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v5, 31, v4
	s_add_i32 s2, s2, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s2, 0
	v_lshlrev_b64 v[7:8], 2, v[4:5]
	v_add_nc_u32_e32 v4, s6, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s4, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v8, vcc_lo
	global_load_b32 v5, v[2:3], off
	global_load_b32 v7, v[7:8], off
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v6, v5, v7
	s_cbranch_scc0 .LBB0_2
	s_branch .LBB0_4
.LBB0_3:
	v_mov_b32_e32 v6, 0
.LBB0_4:                                ; %Flow43
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v1, v0
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v6, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12matrixMul_1biPfS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 36
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 9
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z12matrixMul_1biPfS_S_i, .Lfunc_end0-_Z12matrixMul_1biPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 296
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 36
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12matrixMul_1biPfS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12matrixMul_1biPfS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
