/*
   Program perform matrix multiplication
 */
#include<stdio.h>
#include<cuda.h>
#include<assert.h>
#include<stdlib.h>
#include<sys/time.h>
#define VAL_LIMIT 10
#define DEBUG 0
#define TILE_WIDTH 32
cudaError_t err;
/*
 *	@PRAM   : Number of rows and columns
 *	@RETURN : Pointer to created Matrix
 *	@DESC   :  
 *	@SEE    :  
 *	@TODO   : 
 *	
 */
float* createMatrix(int r,int c)
{
    float *temp;
    temp = (float*) malloc(sizeof(float)*r*c);
    return temp;
}

/*
 *	@DESC   : Frees the memory allocated to the matrix
 *	@PRAM   : pointer to the matrix
 *	@RETURN : Nothing
 *	@SEE    :  
 *	@TODO   :  
 *	
 */
void destroyMAtrix(float *mat)
{
    free(mat);
}

/*
 *	@PRAM   : Device pointer, number of rows and columns
 *	@RETURN : Nothing
 *	@DESC   : Creates a matrix of float * rows * columns on device
 *	@SEE    :  
 *	@TODO   :  
 *	
 */
void createMatrixDevice(float **m, int r, int c)
{
    int size = sizeof(float)*r*c;
    err = cudaSuccess;
    err = cudaMalloc(m, size); 
    if (err != cudaSuccess)
    {
        fprintf(stderr,"%s, %d.\n %s.",__FILE__,__LINE__,cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

/*
 *	@PRAM   : Host pointer, Device pointer, Number of rows and columns
 *	@RETURN : Nothing
 *	@DESC   : Copies data from host pointer to device pointer
 *	@SEE    :  
 *	@TODO   :  
 *	
 */
void transferToDevice(float *hostptr, float *deviceptr, int r, int c)
{
    int size = sizeof(float) * r*c;
    err = cudaSuccess;
    err = cudaMemcpy(deviceptr,hostptr,size,cudaMemcpyHostToDevice);
    if (err != cudaSuccess)
    {
        //fprintf(stderr,"%s, %d.\n %s.",__FILE__,__LINE__,cudaGetErrorString(err));
        fprintf(stderr,"%s",cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void transferFromDevice(float *hostptr, float *deviceptr, int r, int c)
{
    int size = sizeof(float) * r*c;
    err = cudaSuccess;
    err = cudaMemcpy(hostptr,deviceptr,size,cudaMemcpyDeviceToHost);
    if (err != cudaSuccess)
    {
        fprintf(stderr,"%s, %d.\n %s.",__FILE__,__LINE__,cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void initMatrix(float *m,int r,int c)
{
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            m[ i*c +j ] = (float) (rand()%VAL_LIMIT);
        }
    }
}

void matMul(float *A, float *B, float *C, int Aw, int Ah, int Bw)
{
    for( int i=0 ; i<Ah; i++)
    {
        for( int j=0; j<Bw; j++)
        {
            float sum=0;
            for( int k=0; k<Aw; k++) 
            {
                float a = A[i*Aw+k];
                float b = B[k*Bw +j];
                sum += a*b;
                if(DEBUG)
                    printf(" %d * %d +",i*Aw+k,k*Bw+j);
            }
            C[i*Bw+j] = sum;
                if(DEBUG)
                    printf("%d\n",i*Bw+j);
        }
    }

}

 __global__
void matMulKernel(float *A, float *B, float *C, int Ac, int Ar, int Bc)
{
    int row = blockIdx.x * TILE_WIDTH + threadIdx.x;
    int col = blockIdx.y * TILE_WIDTH + threadIdx.y;
    int sum = 0;
    for ( int i=0 ; i<Ar; i++)
    {
        sum += A[row *Ac + i] * B[ i *Bc + col];
    }
    C[row*Bc+col] = sum;
}

void pMatMul(float *A,float *B,float *C, int Ac, int Ar, int Bw)
{
    dim3 gridProp(ceil(Bw/TILE_WIDTH), ceil(Ar/TILE_WIDTH), 1);
    dim3 blockProp(TILE_WIDTH,TILE_WIDTH,1);
    matMulKernel<<<gridProp,blockProp>>>(A, B, C, Ac, Ar, Bw);
}


void printMat(float *mat, int r, int c)
{
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            printf("%4.1f \t",mat[i*c+j]);
        }
        printf("\n");
    }
}

bool check(float *mat, float *mat2, int r, int c)
{
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if( mat2[i*c+j] != mat[i*c+j])
                return false;
        }
    }
    return true;
}

int main()
{
    float *h_A, *h_B, *h_C,*h_D;
    float *d_A, *d_B, *d_C;
    float milisecs;
    unsigned int Ar=1024, Ac=1024;
    unsigned int Br=1024, Bc=1024;
    unsigned int Cr=1024, Cc=1024;

    assert(Ac == Br);

    cudaEvent_t start,stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    h_A = createMatrix(Ar, Ac);
    assert(h_A != NULL);
    h_B = createMatrix(Br, Bc);
    assert(h_B != NULL);
    h_C = createMatrix(Cr, Cc);
    assert(h_C != NULL);
    h_D = createMatrix(Cr, Cc);
    assert(h_D != NULL);

    initMatrix(h_A, Ar, Ac);
    initMatrix(h_B, Br, Bc);

    if(DEBUG){ 
        printf("Matrix A:\n");
        printMat(h_A, Ar, Ac);
        printf("Matrix B:\n");
        printMat(h_B, Br, Bc);
    }


    matMul(h_A, h_B, h_C, Ac, Ar, Bc);

    if(DEBUG){ 
        printf("Matrix C:\n");
        printMat(h_C, Cr, Cc);
    }


    createMatrixDevice(&d_A, Ar, Ac);
    createMatrixDevice(&d_B, Br, Bc);
    createMatrixDevice(&d_C, Cr, Cc);

    transferToDevice(h_A, d_A, Ar, Ac);
    transferToDevice(h_B, d_B, Br, Bc);

    cudaEventRecord(start);
    pMatMul(d_A, d_B, d_C, Ac, Ar, Bc);
    cudaEventRecord(stop);

    
    transferFromDevice(h_D, d_C, Cr, Cc);


    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&milisecs,start,stop);
    printf("Time required for parallel execution %f\n",milisecs);

    if(DEBUG){
        printf("Matrix D:\n");
        printMat(h_D, Cr, Cc);
    }

    if(check(h_D, h_C, Cr, Cc))
        printf("Success !! :) \n");
    else
        printf("Failed !! :( \n");

    cudaFree(d_A);
    cudaFree(d_B);
    cudaFree(d_C);
    destroyMAtrix(h_A);
    destroyMAtrix(h_B);
    destroyMAtrix(h_D);
    destroyMAtrix(h_C);
    return 0;
}

	.file	"tmpxft_00361c4a_00000000-6_matMul.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2040:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2040:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12createMatrixii
	.type	_Z12createMatrixii, @function
_Z12createMatrixii:
.LFB2027:
	.cfi_startproc
	endbr64
	movslq	%edi, %rdi
	movslq	%esi, %rsi
	imulq	%rsi, %rdi
	salq	$2, %rdi
	jmp	malloc@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z12createMatrixii, .-_Z12createMatrixii
	.globl	_Z13destroyMAtrixPf
	.type	_Z13destroyMAtrixPf, @function
_Z13destroyMAtrixPf:
.LFB2028:
	.cfi_startproc
	endbr64
	jmp	free@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z13destroyMAtrixPf, .-_Z13destroyMAtrixPf
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/indrajeet307/CudaExperiments/master/matMul/matMul.cu"
.LC1:
	.string	"%s, %d.\n %s."
	.text
	.globl	_Z18createMatrixDevicePPfii
	.type	_Z18createMatrixDevicePPfii, @function
_Z18createMatrixDevicePPfii:
.LFB2029:
	.cfi_startproc
	endbr64
	imull	%edx, %esi
	pushq	%rcx
	.cfi_def_cfa_offset 16
	xorl	%r8d, %r8d
	movl	%r8d, err(%rip)
	sall	$2, %esi
	movslq	%esi, %rsi
	call	cudaMalloc@PLT
	movl	%eax, err(%rip)
	testl	%eax, %eax
	je	.L4
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$56, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L4:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z18createMatrixDevicePPfii, .-_Z18createMatrixDevicePPfii
	.section	.rodata.str1.1
.LC2:
	.string	"%s"
	.text
	.globl	_Z16transferToDevicePfS_ii
	.type	_Z16transferToDevicePfS_ii, @function
_Z16transferToDevicePfS_ii:
.LFB2030:
	.cfi_startproc
	endbr64
	imull	%ecx, %edx
	pushq	%r8
	.cfi_def_cfa_offset 16
	movq	%rdi, %rax
	xorl	%r9d, %r9d
	movq	%rsi, %rdi
	movl	$1, %ecx
	movq	%rax, %rsi
	movl	%r9d, err(%rip)
	sall	$2, %edx
	movslq	%edx, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, err(%rip)
	testl	%eax, %eax
	je	.L8
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC2(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L8:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z16transferToDevicePfS_ii, .-_Z16transferToDevicePfS_ii
	.globl	_Z18transferFromDevicePfS_ii
	.type	_Z18transferFromDevicePfS_ii, @function
_Z18transferFromDevicePfS_ii:
.LFB2031:
	.cfi_startproc
	endbr64
	imull	%ecx, %edx
	pushq	%r8
	.cfi_def_cfa_offset 16
	xorl	%r9d, %r9d
	movl	$2, %ecx
	movl	%r9d, err(%rip)
	sall	$2, %edx
	movslq	%edx, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, err(%rip)
	testl	%eax, %eax
	je	.L11
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$89, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L11:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z18transferFromDevicePfS_ii, .-_Z18transferFromDevicePfS_ii
	.globl	_Z10initMatrixPfii
	.type	_Z10initMatrixPfii, @function
_Z10initMatrixPfii:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L15:
	cmpl	%esi, %r14d
	jge	.L14
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,4), %r15
.L18:
	cmpl	%ebx, %ebp
	jle	.L20
	movl	%esi, 12(%rsp)
	call	rand@PLT
	movl	$10, %ecx
	movl	12(%rsp), %esi
	cltd
	idivl	%ecx
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, (%r15,%rbx,4)
	incq	%rbx
	jmp	.L18
.L20:
	incl	%r14d
	addl	%ebp, %r13d
	jmp	.L15
.L14:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	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	_Z10initMatrixPfii, .-_Z10initMatrixPfii
	.globl	_Z6matMulPfS_S_iii
	.type	_Z6matMulPfS_S_iii, @function
_Z6matMulPfS_S_iii:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdx, %r10
	xorl	%r11d, %r11d
	movl	%ecx, %edx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	xorl	%esi, %esi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movslq	%r9d, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	salq	$2, %rbp
	xorl	%ebx, %ebx
.L22:
	cmpl	%r8d, %ebx
	jge	.L21
	movslq	%r11d, %rax
	leaq	(%r10,%rax,4), %r15
	movslq	%esi, %rax
	leaq	(%rdi,%rax,4), %r14
	xorl	%eax, %eax
.L27:
	cmpl	%eax, %r9d
	jle	.L24
	leaq	(%r12,%rax,4), %r13
	xorl	%ecx, %ecx
	xorps	%xmm0, %xmm0
.L25:
	cmpl	%ecx, %edx
	jle	.L29
	movss	(%r14,%rcx,4), %xmm1
	mulss	0(%r13), %xmm1
	incq	%rcx
	addq	%rbp, %r13
	addss	%xmm1, %xmm0
	jmp	.L25
.L29:
	movss	%xmm0, (%r15,%rax,4)
	incq	%rax
	jmp	.L27
.L24:
	incl	%ebx
	addl	%r9d, %r11d
	addl	%edx, %esi
	jmp	.L22
.L21:
	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
.LFE2033:
	.size	_Z6matMulPfS_S_iii, .-_Z6matMulPfS_S_iii
	.section	.rodata.str1.1
.LC4:
	.string	"%4.1f \t"
.LC5:
	.string	"\n"
	.text
	.globl	_Z8printMatPfii
	.type	_Z8printMatPfii, @function
_Z8printMatPfii:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L31:
	cmpl	%r14d, %r13d
	jge	.L30
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %rcx
.L34:
	cmpl	%r15d, %ebx
	jle	.L36
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rcx,%r15,4), %xmm0
	movq	%rcx, 8(%rsp)
	incq	%r15
	call	__printf_chk@PLT
	movq	8(%rsp), %rcx
	jmp	.L34
.L36:
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L31
.L30:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2035:
	.size	_Z8printMatPfii, .-_Z8printMatPfii
	.globl	_Z5checkPfS_ii
	.type	_Z5checkPfS_ii, @function
_Z5checkPfS_ii:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	%rdi, %r10
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
.L38:
	cmpl	%edx, %r9d
	jge	.L44
	movslq	%r8d, %rax
	xorl	%edi, %edi
	salq	$2, %rax
.L42:
	cmpl	%ecx, %edi
	jge	.L46
	movss	(%rsi,%rax), %xmm0
	addq	$4, %rax
	ucomiss	-4(%r10,%rax), %xmm0
	jp	.L43
	jne	.L43
	incl	%edi
	jmp	.L42
.L46:
	incl	%r9d
	addl	%ecx, %r8d
	jmp	.L38
.L43:
	xorl	%eax, %eax
	ret
.L44:
	movb	$1, %al
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z5checkPfS_ii, .-_Z5checkPfS_ii
	.globl	_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii
	.type	_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii, @function
_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii:
.LFB2062:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L47
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z12matMulKernelPfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L47:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2062:
	.size	_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii, .-_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii
	.globl	_Z12matMulKernelPfS_S_iii
	.type	_Z12matMulKernelPfS_S_iii, @function
_Z12matMulKernelPfS_S_iii:
.LFB2063:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2063:
	.size	_Z12matMulKernelPfS_S_iii, .-_Z12matMulKernelPfS_S_iii
	.globl	_Z7pMatMulPfS_S_iii
	.type	_Z7pMatMulPfS_S_iii, @function
_Z7pMatMulPfS_S_iii:
.LFB2034:
	.cfi_startproc
	endbr64
	movl	%r9d, %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%ecx, %r15d
	movl	$32, %ecx
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdx, %r14
	cltd
	idivl	%ecx
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%rdi, %r12
	movq	%rsi, %r13
	movl	%r8d, %ebx
	movl	%r9d, %ebp
	movl	$1, %esi
	xorl	%r9d, %r9d
	movl	%eax, 8(%rsp)
	movl	%r8d, %eax
	xorl	%r8d, %r8d
	cltd
	idivl	%ecx
	movabsq	$137438953504, %rdx
	movl	$1, %ecx
	movl	%eax, 12(%rsp)
	movq	8(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L52
	addq	$40, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%ebp, %r9d
	movl	%ebx, %r8d
	movl	%r15d, %ecx
	popq	%rbx
	.cfi_def_cfa_offset 48
	movq	%r14, %rdx
	popq	%rbp
	.cfi_def_cfa_offset 40
	movq	%r13, %rsi
	movq	%r12, %rdi
	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
	jmp	_Z39__device_stub__Z12matMulKernelPfS_S_iiiPfS_S_iii
.L52:
	.cfi_restore_state
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2034:
	.size	_Z7pMatMulPfS_S_iii, .-_Z7pMatMulPfS_S_iii
	.section	.rodata.str1.1
.LC6:
	.string	"Time required for parallel execution %f\n"
.LC7:
	.string	"Success !! :) \n"
.LC8:
	.string	"Failed !! :( \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$4194304, %edi
	call	malloc@PLT
	movl	$4194304, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$4194304, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$4194304, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$1024, %edx
	movl	$1024, %esi
	movq	%rbp, %rdi
	movq	%rax, %r13
	call	_Z10initMatrixPfii
	movl	$1024, %edx
	movl	$1024, %esi
	movq	%rbx, %rdi
	call	_Z10initMatrixPfii
	movl	$1024, %ecx
	movq	%r12, %rdx
	movq	%rbx, %rsi
	movl	$1024, %r9d
	movl	$1024, %r8d
	movq	%rbp, %rdi
	call	_Z6matMulPfS_S_iii
	leaq	16(%rsp), %rdi
	movl	$1024, %edx
	movl	$1024, %esi
	call	_Z18createMatrixDevicePPfii
	leaq	24(%rsp), %rdi
	movl	$1024, %edx
	movl	$1024, %esi
	call	_Z18createMatrixDevicePPfii
	leaq	32(%rsp), %rdi
	movl	$1024, %edx
	movl	$1024, %esi
	call	_Z18createMatrixDevicePPfii
	movq	16(%rsp), %rsi
	movl	$1024, %ecx
	movq	%rbp, %rdi
	movl	$1024, %edx
	call	_Z16transferToDevicePfS_ii
	movq	24(%rsp), %rsi
	movl	$1024, %ecx
	movq	%rbx, %rdi
	movl	$1024, %edx
	call	_Z16transferToDevicePfS_ii
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$1024, %r9d
	movq	16(%rsp), %rdi
	movl	$1024, %r8d
	movl	$1024, %ecx
	call	_Z7pMatMulPfS_S_iii
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rsi
	movl	$1024, %ecx
	movq	%r13, %rdi
	movl	$1024, %edx
	call	_Z18transferFromDevicePfS_ii
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$1024, %ecx
	movl	$1024, %edx
	movq	%r13, %rdi
	call	_Z5checkPfS_ii
	leaq	.LC7(%rip), %rsi
	testb	%al, %al
	jne	.L60
	leaq	.LC8(%rip), %rsi
.L60:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	addq	$72, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2037:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z12matMulKernelPfS_S_iii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2065:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12matMulKernelPfS_S_iii(%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
.LFE2065:
	.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
	.globl	err
	.bss
	.align 4
	.type	err, @object
	.size	err, 4
err:
	.zero	4
	.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:

/*
   Program perform matrix multiplication
 */
#include<stdio.h>
#include<hip/hip_runtime.h>
#include<assert.h>
#include<stdlib.h>
#include<sys/time.h>
#define VAL_LIMIT 10
#define DEBUG 0
#define TILE_WIDTH 32
hipError_t err;
/*
 *	@PRAM   : Number of rows and columns
 *	@RETURN : Pointer to created Matrix
 *	@DESC   :  
 *	@SEE    :  
 *	@TODO   : 
 *	
 */
float* createMatrix(int r,int c)
{
    float *temp;
    temp = (float*) malloc(sizeof(float)*r*c);
    return temp;
}

/*
 *	@DESC   : Frees the memory allocated to the matrix
 *	@PRAM   : pointer to the matrix
 *	@RETURN : Nothing
 *	@SEE    :  
 *	@TODO   :  
 *	
 */
void destroyMAtrix(float *mat)
{
    free(mat);
}

/*
 *	@PRAM   : Device pointer, number of rows and columns
 *	@RETURN : Nothing
 *	@DESC   : Creates a matrix of float * rows * columns on device
 *	@SEE    :  
 *	@TODO   :  
 *	
 */
void createMatrixDevice(float **m, int r, int c)
{
    int size = sizeof(float)*r*c;
    err = hipSuccess;
    err = hipMalloc(m, size); 
    if (err != hipSuccess)
    {
        fprintf(stderr,"%s, %d.\n %s.",__FILE__,__LINE__,hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

/*
 *	@PRAM   : Host pointer, Device pointer, Number of rows and columns
 *	@RETURN : Nothing
 *	@DESC   : Copies data from host pointer to device pointer
 *	@SEE    :  
 *	@TODO   :  
 *	
 */
void transferToDevice(float *hostptr, float *deviceptr, int r, int c)
{
    int size = sizeof(float) * r*c;
    err = hipSuccess;
    err = hipMemcpy(deviceptr,hostptr,size,hipMemcpyHostToDevice);
    if (err != hipSuccess)
    {
        //fprintf(stderr,"%s, %d.\n %s.",__FILE__,__LINE__,cudaGetErrorString(err));
        fprintf(stderr,"%s",hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void transferFromDevice(float *hostptr, float *deviceptr, int r, int c)
{
    int size = sizeof(float) * r*c;
    err = hipSuccess;
    err = hipMemcpy(hostptr,deviceptr,size,hipMemcpyDeviceToHost);
    if (err != hipSuccess)
    {
        fprintf(stderr,"%s, %d.\n %s.",__FILE__,__LINE__,hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
}

void initMatrix(float *m,int r,int c)
{
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            m[ i*c +j ] = (float) (rand()%VAL_LIMIT);
        }
    }
}

void matMul(float *A, float *B, float *C, int Aw, int Ah, int Bw)
{
    for( int i=0 ; i<Ah; i++)
    {
        for( int j=0; j<Bw; j++)
        {
            float sum=0;
            for( int k=0; k<Aw; k++) 
            {
                float a = A[i*Aw+k];
                float b = B[k*Bw +j];
                sum += a*b;
                if(DEBUG)
                    printf(" %d * %d +",i*Aw+k,k*Bw+j);
            }
            C[i*Bw+j] = sum;
                if(DEBUG)
                    printf("%d\n",i*Bw+j);
        }
    }

}

 __global__
void matMulKernel(float *A, float *B, float *C, int Ac, int Ar, int Bc)
{
    int row = blockIdx.x * TILE_WIDTH + threadIdx.x;
    int col = blockIdx.y * TILE_WIDTH + threadIdx.y;
    int sum = 0;
    for ( int i=0 ; i<Ar; i++)
    {
        sum += A[row *Ac + i] * B[ i *Bc + col];
    }
    C[row*Bc+col] = sum;
}

void pMatMul(float *A,float *B,float *C, int Ac, int Ar, int Bw)
{
    dim3 gridProp(ceil(Bw/TILE_WIDTH), ceil(Ar/TILE_WIDTH), 1);
    dim3 blockProp(TILE_WIDTH,TILE_WIDTH,1);
    matMulKernel<<<gridProp,blockProp>>>(A, B, C, Ac, Ar, Bw);
}


void printMat(float *mat, int r, int c)
{
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            printf("%4.1f \t",mat[i*c+j]);
        }
        printf("\n");
    }
}

bool check(float *mat, float *mat2, int r, int c)
{
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if( mat2[i*c+j] != mat[i*c+j])
                return false;
        }
    }
    return true;
}

int main()
{
    float *h_A, *h_B, *h_C,*h_D;
    float *d_A, *d_B, *d_C;
    float milisecs;
    unsigned int Ar=1024, Ac=1024;
    unsigned int Br=1024, Bc=1024;
    unsigned int Cr=1024, Cc=1024;

    assert(Ac == Br);

    hipEvent_t start,stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);

    h_A = createMatrix(Ar, Ac);
    assert(h_A != NULL);
    h_B = createMatrix(Br, Bc);
    assert(h_B != NULL);
    h_C = createMatrix(Cr, Cc);
    assert(h_C != NULL);
    h_D = createMatrix(Cr, Cc);
    assert(h_D != NULL);

    initMatrix(h_A, Ar, Ac);
    initMatrix(h_B, Br, Bc);

    if(DEBUG){ 
        printf("Matrix A:\n");
        printMat(h_A, Ar, Ac);
        printf("Matrix B:\n");
        printMat(h_B, Br, Bc);
    }


    matMul(h_A, h_B, h_C, Ac, Ar, Bc);

    if(DEBUG){ 
        printf("Matrix C:\n");
        printMat(h_C, Cr, Cc);
    }


    createMatrixDevice(&d_A, Ar, Ac);
    createMatrixDevice(&d_B, Br, Bc);
    createMatrixDevice(&d_C, Cr, Cc);

    transferToDevice(h_A, d_A, Ar, Ac);
    transferToDevice(h_B, d_B, Br, Bc);

    hipEventRecord(start);
    pMatMul(d_A, d_B, d_C, Ac, Ar, Bc);
    hipEventRecord(stop);

    
    transferFromDevice(h_D, d_C, Cr, Cc);


    hipEventSynchronize(stop);
    hipEventElapsedTime(&milisecs,start,stop);
    printf("Time required for parallel execution %f\n",milisecs);

    if(DEBUG){
        printf("Matrix D:\n");
        printMat(h_D, Cr, Cc);
    }

    if(check(h_D, h_C, Cr, Cc))
        printf("Success !! :) \n");
    else
        printf("Failed !! :( \n");

    hipFree(d_A);
    hipFree(d_B);
    hipFree(d_C);
    destroyMAtrix(h_A);
    destroyMAtrix(h_B);
    destroyMAtrix(h_D);
    destroyMAtrix(h_C);
    return 0;
}

	.text
	.file	"matMul.hip"
	.globl	_Z12createMatrixii              # -- Begin function _Z12createMatrixii
	.type	_Z12createMatrixii,@function
_Z12createMatrixii:                     # @_Z12createMatrixii
	.cfi_startproc
# %bb.0:
	movslq	%edi, %rax
	movslq	%esi, %rdi
	imulq	%rax, %rdi
	shlq	$2, %rdi
	jmp	malloc                          # TAILCALL
.Lfunc_end0:
	.size	_Z12createMatrixii, .Lfunc_end0-_Z12createMatrixii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13destroyMAtrixPf             # -- Begin function _Z13destroyMAtrixPf
	.type	_Z13destroyMAtrixPf,@function
_Z13destroyMAtrixPf:                    # @_Z13destroyMAtrixPf
	.cfi_startproc
# %bb.0:
	jmp	free                            # TAILCALL
.Lfunc_end1:
	.size	_Z13destroyMAtrixPf, .Lfunc_end1-_Z13destroyMAtrixPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z18createMatrixDevicePPfii     # -- Begin function _Z18createMatrixDevicePPfii
	.type	_Z18createMatrixDevicePPfii,@function
_Z18createMatrixDevicePPfii:            # @_Z18createMatrixDevicePPfii
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	imull	%edx, %esi
	shll	$2, %esi
	movl	$0, err(%rip)
	movslq	%esi, %rsi
	callq	hipMalloc
	movl	%eax, err(%rip)
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB2_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$56, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z18createMatrixDevicePPfii, .Lfunc_end2-_Z18createMatrixDevicePPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z16transferToDevicePfS_ii      # -- Begin function _Z16transferToDevicePfS_ii
	.type	_Z16transferToDevicePfS_ii,@function
_Z16transferToDevicePfS_ii:             # @_Z16transferToDevicePfS_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rax
	imull	%ecx, %edx
	shll	$2, %edx
	movl	$0, err(%rip)
	movslq	%edx, %rdx
	movq	%rsi, %rdi
	movq	%rax, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, err(%rip)
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB3_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movq	%rax, %rdi
	movq	%rbx, %rsi
	callq	fputs@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z16transferToDevicePfS_ii, .Lfunc_end3-_Z16transferToDevicePfS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z18transferFromDevicePfS_ii    # -- Begin function _Z18transferFromDevicePfS_ii
	.type	_Z18transferFromDevicePfS_ii,@function
_Z18transferFromDevicePfS_ii:           # @_Z18transferFromDevicePfS_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	imull	%ecx, %edx
	shll	$2, %edx
	movl	$0, err(%rip)
	movslq	%edx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, err(%rip)
	testl	%eax, %eax
	jne	.LBB4_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB4_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$89, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	_Z18transferFromDevicePfS_ii, .Lfunc_end4-_Z18transferFromDevicePfS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10initMatrixPfii              # -- Begin function _Z10initMatrixPfii
	.type	_Z10initMatrixPfii,@function
_Z10initMatrixPfii:                     # @_Z10initMatrixPfii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB5_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB5_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB5_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB5_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB5_4:                                #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB5_4
.LBB5_5:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB5_2
.LBB5_6:                                # %._crit_edge13
	addq	$24, %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_end5:
	.size	_Z10initMatrixPfii, .Lfunc_end5-_Z10initMatrixPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z6matMulPfS_S_iii              # -- Begin function _Z6matMulPfS_S_iii
	.type	_Z6matMulPfS_S_iii,@function
_Z6matMulPfS_S_iii:                     # @_Z6matMulPfS_S_iii
	.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
	.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, -8(%rsp)                  # 8-byte Spill
	movq	%rsi, -16(%rsp)                 # 8-byte Spill
	movq	%rdi, -24(%rsp)                 # 8-byte Spill
	testl	%r8d, %r8d
	jle	.LBB6_9
# %bb.1:                                # %.preheader29.lr.ph
	movslq	%r9d, %rdi
	movl	%r8d, %r8d
	movl	%edi, %r10d
	movl	%ecx, %r11d
	leaq	(,%rdi,4), %rbx
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.LBB6_2:                                # %.preheader29
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_4 Depth 2
                                        #       Child Loop BB6_6 Depth 3
	testl	%r9d, %r9d
	jle	.LBB6_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	%r14d, %eax
	movq	-24(%rsp), %rdx                 # 8-byte Reload
	leaq	(%rdx,%rax,4), %r12
	movq	%r15, %rax
	imulq	%rdi, %rax
	movq	-8(%rsp), %rdx                  # 8-byte Reload
	leaq	(%rdx,%rax,4), %r13
	movq	-16(%rsp), %rsi                 # 8-byte Reload
	xorl	%eax, %eax
.LBB6_4:                                # %.preheader
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB6_6 Depth 3
	xorps	%xmm0, %xmm0
	testl	%ecx, %ecx
	jle	.LBB6_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB6_4 Depth=2
	movq	%rsi, %rbp
	xorl	%edx, %edx
.LBB6_6:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        #     Parent Loop BB6_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r12,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rbp), %xmm1
	addss	%xmm1, %xmm0
	incq	%rdx
	addq	%rbx, %rbp
	cmpq	%rdx, %r11
	jne	.LBB6_6
.LBB6_7:                                # %._crit_edge
                                        #   in Loop: Header=BB6_4 Depth=2
	movss	%xmm0, (%r13,%rax,4)
	incq	%rax
	addq	$4, %rsi
	cmpq	%r10, %rax
	jne	.LBB6_4
.LBB6_8:                                # %._crit_edge33
                                        #   in Loop: Header=BB6_2 Depth=1
	incq	%r15
	addl	%ecx, %r14d
	cmpq	%r8, %r15
	jne	.LBB6_2
.LBB6_9:                                # %._crit_edge35
	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_end6:
	.size	_Z6matMulPfS_S_iii, .Lfunc_end6-_Z6matMulPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z27__device_stub__matMulKernelPfS_S_iii # -- Begin function _Z27__device_stub__matMulKernelPfS_S_iii
	.type	_Z27__device_stub__matMulKernelPfS_S_iii,@function
_Z27__device_stub__matMulKernelPfS_S_iii: # @_Z27__device_stub__matMulKernelPfS_S_iii
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z12matMulKernelPfS_S_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end7:
	.size	_Z27__device_stub__matMulKernelPfS_S_iii, .Lfunc_end7-_Z27__device_stub__matMulKernelPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z7pMatMulPfS_S_iii             # -- Begin function _Z7pMatMulPfS_S_iii
	.type	_Z7pMatMulPfS_S_iii,@function
_Z7pMatMulPfS_S_iii:                    # @_Z7pMatMulPfS_S_iii
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%r9d, %ebx
	movl	%r8d, %r14d
	movl	%ecx, %ebp
	movq	%rdx, %r15
	movq	%rsi, %r12
	leal	31(%rbx), %ecx
	testl	%r9d, %r9d
	cmovnsl	%r9d, %ecx
	sarl	$5, %ecx
	leal	31(%r14), %eax
	testl	%r8d, %r8d
	cmovnsl	%r8d, %eax
	movq	%rdi, %r13
	sarl	$5, %eax
	shlq	$32, %rax
	orq	%rcx, %rax
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movq	%rax, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	je	.LBB8_2
# %bb.1:
	addq	$8, %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
.LBB8_2:
	.cfi_def_cfa_offset 64
	movq	%r13, %rdi
	movq	%r12, %rsi
	movq	%r15, %rdx
	movl	%ebp, %ecx
	movl	%r14d, %r8d
	movl	%ebx, %r9d
	addq	$8, %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
	jmp	_Z27__device_stub__matMulKernelPfS_S_iii # TAILCALL
.Lfunc_end8:
	.size	_Z7pMatMulPfS_S_iii, .Lfunc_end8-_Z7pMatMulPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8printMatPfii                 # -- Begin function _Z8printMatPfii
	.type	_Z8printMatPfii,@function
_Z8printMatPfii:                        # @_Z8printMatPfii
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB9_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB9_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB9_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB9_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB9_4:                                #   Parent Loop BB9_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB9_4
.LBB9_5:                                # %._crit_edge
                                        #   in Loop: Header=BB9_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB9_2
.LBB9_6:                                # %._crit_edge13
	addq	$24, %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_end9:
	.size	_Z8printMatPfii, .Lfunc_end9-_Z8printMatPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z5checkPfS_ii                  # -- Begin function _Z5checkPfS_ii
	.type	_Z5checkPfS_ii,@function
_Z5checkPfS_ii:                         # @_Z5checkPfS_ii
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB10_1
# %bb.3:                                # %.preheader.lr.ph
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edx, %edx
	movl	%ecx, %r8d
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
	xorl	%eax, %eax
.LBB10_4:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_7 Depth 2
	testl	%ecx, %ecx
	jle	.LBB10_8
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB10_4 Depth=1
	movl	%r9d, %ebx
	leaq	(%rdi,%rbx,4), %r11
	leaq	(%rsi,%rbx,4), %rbx
	xorl	%r14d, %r14d
.LBB10_7:                               #   Parent Loop BB10_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rbx,%r14,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r11,%r14,4), %xmm0
	jne	.LBB10_9
	jp	.LBB10_9
# %bb.6:                                #   in Loop: Header=BB10_7 Depth=2
	incq	%r14
	cmpq	%r14, %r8
	jne	.LBB10_7
.LBB10_8:                               # %._crit_edge
                                        #   in Loop: Header=BB10_4 Depth=1
	incq	%r10
	cmpq	%rdx, %r10
	setae	%al
	addl	%ecx, %r9d
	cmpq	%rdx, %r10
	jne	.LBB10_4
.LBB10_9:
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	jmp	.LBB10_2
.LBB10_1:
	movb	$1, %al
.LBB10_2:                               # %.thread
	andb	$1, %al
                                        # kill: def $al killed $al killed $rax
	retq
.Lfunc_end10:
	.size	_Z5checkPfS_ii, .Lfunc_end10-_Z5checkPfS_ii
	.cfi_endproc
                                        # -- End function
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r12
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r15
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r14
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
	movq	%r12, 8(%rsp)                   # 8-byte Spill
.LBB11_1:                               # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_2 Depth 2
	xorl	%r13d, %r13d
.LBB11_2:                               #   Parent Loop BB11_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	$1024, %r13                     # imm = 0x400
	jne	.LBB11_2
# %bb.3:                                # %._crit_edge.i
                                        #   in Loop: Header=BB11_1 Depth=1
	incq	%rbx
	addq	$4096, %r12                     # imm = 0x1000
	cmpq	$1024, %rbx                     # imm = 0x400
	jne	.LBB11_1
# %bb.4:                                # %.preheader.i46.preheader
	xorl	%ebx, %ebx
	movq	%r15, %r12
.LBB11_5:                               # %.preheader.i46
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_6 Depth 2
	xorl	%r13d, %r13d
.LBB11_6:                               #   Parent Loop BB11_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	$1024, %r13                     # imm = 0x400
	jne	.LBB11_6
# %bb.7:                                # %._crit_edge.i53
                                        #   in Loop: Header=BB11_5 Depth=1
	incq	%rbx
	addq	$4096, %r12                     # imm = 0x1000
	cmpq	$1024, %rbx                     # imm = 0x400
	jne	.LBB11_5
# %bb.8:                                # %.preheader29.i.preheader
	xorl	%eax, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
.LBB11_9:                               # %.preheader29.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_10 Depth 2
                                        #       Child Loop BB11_11 Depth 3
	movq	%rax, %rdx
	shlq	$12, %rdx
	addq	%r14, %rdx
	movq	%r15, %rsi
	xorl	%edi, %edi
.LBB11_10:                              # %.preheader.i58
                                        #   Parent Loop BB11_9 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB11_11 Depth 3
	xorps	%xmm0, %xmm0
	movq	%rsi, %r8
	xorl	%r9d, %r9d
.LBB11_11:                              # %.lr.ph.i
                                        #   Parent Loop BB11_9 Depth=1
                                        #     Parent Loop BB11_10 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%rcx,%r9,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%r8), %xmm1
	addss	%xmm1, %xmm0
	incq	%r9
	addq	$4096, %r8                      # imm = 0x1000
	cmpq	$1024, %r9                      # imm = 0x400
	jne	.LBB11_11
# %bb.12:                               # %._crit_edge.i63
                                        #   in Loop: Header=BB11_10 Depth=2
	movss	%xmm0, (%rdx,%rdi,4)
	incq	%rdi
	addq	$4, %rsi
	cmpq	$1024, %rdi                     # imm = 0x400
	jne	.LBB11_10
# %bb.13:                               # %._crit_edge33.i
                                        #   in Loop: Header=BB11_9 Depth=1
	incq	%rax
	addq	$4096, %rcx                     # imm = 0x1000
	cmpq	$1024, %rax                     # imm = 0x400
	jne	.LBB11_9
# %bb.14:                               # %_Z6matMulPfS_S_iii.exit
	leaq	56(%rsp), %rbp
	movq	%rbp, %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$1024, %edx                     # imm = 0x400
	callq	_Z18createMatrixDevicePPfii
	leaq	48(%rsp), %r12
	movq	%r12, %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$1024, %edx                     # imm = 0x400
	callq	_Z18createMatrixDevicePPfii
	leaq	40(%rsp), %r13
	movq	%r13, %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$1024, %edx                     # imm = 0x400
	callq	_Z18createMatrixDevicePPfii
	movq	(%rbp), %rsi
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movl	$1024, %edx                     # imm = 0x400
	movl	$1024, %ecx                     # imm = 0x400
	callq	_Z16transferToDevicePfS_ii
	movq	(%r12), %rsi
	movq	%r15, %rdi
	movl	$1024, %edx                     # imm = 0x400
	movl	$1024, %ecx                     # imm = 0x400
	callq	_Z16transferToDevicePfS_ii
	movq	24(%rsp), %rdi
	xorl	%ebx, %ebx
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbp), %rdi
	movq	(%r12), %rsi
	movq	(%r13), %rdx
	movl	$1024, %ecx                     # imm = 0x400
	movl	$1024, %r8d                     # imm = 0x400
	movl	$1024, %r9d                     # imm = 0x400
	callq	_Z7pMatMulPfS_S_iii
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rsi
	movq	32(%rsp), %r13                  # 8-byte Reload
	movq	%r13, %rdi
	movl	$1024, %edx                     # imm = 0x400
	movl	$1024, %ecx                     # imm = 0x400
	callq	_Z18transferFromDevicePfS_ii
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	68(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r12), %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movl	$4096, %eax                     # imm = 0x1000
	movq	%r14, %rcx
	movq	%r13, %rsi
	xorl	%edx, %edx
.LBB11_15:                              # %.preheader.i64
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_17 Depth 2
	xorl	%edi, %edi
.LBB11_17:                              #   Parent Loop BB11_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rcx,%rdi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%rsi,%rdi,4), %xmm0
	jne	.LBB11_19
	jp	.LBB11_19
# %bb.16:                               #   in Loop: Header=BB11_17 Depth=2
	incq	%rdi
	cmpq	$1024, %rdi                     # imm = 0x400
	jne	.LBB11_17
# %bb.18:                               # %._crit_edge.i69
                                        #   in Loop: Header=BB11_15 Depth=1
	cmpq	$1023, %rbx                     # imm = 0x3FF
	leaq	1(%rbx), %rdi
	setae	%dl
	addq	%rax, %rsi
	addq	%rax, %rcx
	movq	%rdi, %rbx
	cmpq	$1024, %rdi                     # imm = 0x400
	jne	.LBB11_15
.LBB11_19:                              # %_Z5checkPfS_ii.exit
	movl	$.Lstr.1, %eax
	movl	$.Lstr, %edi
	testb	$1, %dl
	cmovneq	%rax, %rdi
	callq	puts@PLT
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$72, %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_end11:
	.size	main, .Lfunc_end11-main
	.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	.LBB12_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB12_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12matMulKernelPfS_S_iii, %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_end12:
	.size	__hip_module_ctor, .Lfunc_end12-__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	.LBB13_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
.LBB13_2:
	retq
.Lfunc_end13:
	.size	__hip_module_dtor, .Lfunc_end13-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	err,@object                     # @err
	.bss
	.globl	err
	.p2align	2, 0x0
err:
	.long	0                               # 0x0
	.size	err, 4

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s, %d.\n %s."
	.size	.L.str, 13

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/indrajeet307/CudaExperiments/master/matMul/matMul.hip"
	.size	.L.str.1, 116

	.type	_Z12matMulKernelPfS_S_iii,@object # @_Z12matMulKernelPfS_S_iii
	.section	.rodata,"a",@progbits
	.globl	_Z12matMulKernelPfS_S_iii
	.p2align	3, 0x0
_Z12matMulKernelPfS_S_iii:
	.quad	_Z27__device_stub__matMulKernelPfS_S_iii
	.size	_Z12matMulKernelPfS_S_iii, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"%4.1f \t"
	.size	.L.str.3, 8

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Time required for parallel execution %f\n"
	.size	.L.str.5, 41

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12matMulKernelPfS_S_iii"
	.size	.L__unnamed_1, 26

	.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	"Failed !! :( "
	.size	.Lstr, 14

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Success !! :) "
	.size	.Lstr.1, 15

	.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__matMulKernelPfS_S_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12matMulKernelPfS_S_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12matMulKernelPfS_S_iii ; -- Begin function _Z12matMulKernelPfS_S_iii
	.globl	_Z12matMulKernelPfS_S_iii
	.p2align	8
	.type	_Z12matMulKernelPfS_S_iii,@function
_Z12matMulKernelPfS_S_iii:              ; @_Z12matMulKernelPfS_S_iii
; %bb.0:
	s_clause 0x2
	s_load_b128 s[4:7], s[0:1], 0x18
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v5, s14, 5, v1
	v_lshl_add_u32 v0, s15, 5, v0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s5, 1
	s_cbranch_scc1 .LBB0_4
; %bb.1:                                ; %.lr.ph
	v_mul_lo_u32 v1, v5, s4
	v_dual_mov_b32 v6, 0 :: v_dual_mov_b32 v3, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s8, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s9, v2, vcc_lo
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cvt_f32_i32_e32 v6, v6
	s_add_i32 s5, s5, -1
	s_cmp_eq_u32 s5, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[7:8], 2, v[3:4]
	v_add_nc_u32_e32 v3, s6, v3
	v_add_co_u32 v7, vcc_lo, s10, v7
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v8, vcc_lo, s11, v8, vcc_lo
	global_load_b32 v4, v[1:2], off
	global_load_b32 v7, v[7:8], off
	v_add_co_u32 v1, vcc_lo, v1, 4
	v_add_co_ci_u32_e32 v2, vcc_lo, 0, v2, vcc_lo
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v6, v4, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_i32_f32_e32 v6, v6
	s_cbranch_scc0 .LBB0_2
; %bb.3:                                ; %._crit_edge.loopexit
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_i32_e32 v1, v6
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v1, 0
.LBB0_5:                                ; %Flow
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, v5, s6, v[0:1]
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_store_b32 v[2:3], v1, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12matMulKernelPfS_S_iii
		.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	_Z12matMulKernelPfS_S_iii, .Lfunc_end0-_Z12matMulKernelPfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 304
; 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:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .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:           _Z12matMulKernelPfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12matMulKernelPfS_S_iii.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
