/*
 * Tiled version of matrix multiplication
 * Sequential Matrix multiplication
 * TODO Step 1. Matrix dimensions are multiples of TILE_WIDTH [DONE]
 * TODO Step 1.a make each thread do more work
 * TODO Step 2. MAtrix dimensions are arbitary size
 */
#include<stdio.h>
#include<assert.h>
#include<cuda.h>
#include<stdlib.h>
#include<sys/time.h>
#include<errno.h>

#define DEBUG 0
#define VAL_LIMIT 10
 // TILE_WIDTH and MAT_DIM can be given at compile time check Makefile
#ifndef TILE_WIDTH
#define TILE_WIDTH 16
#endif

#ifndef MAT_DIM
#define MAT_DIM 1024 
#endif

cudaError_t cuerr;

/*
*	@DESC   : Allocate memory a linear aare of dimension r*c 
*	@PRAM   : number of rows and columns
*	@RETURN : address of the allocated memory
*	@SEE    :  
*	@TODO   :  
*	
*/
float *createMartrix(int r, int c)
{
    float * temp;
    temp = (float*) malloc(sizeof(float) *r *c);
    if(temp == NULL)
        printf("Cannot create matrix :(\n");
    return temp;
}

/*
*	@DESC   : Free the linear array memory
*	@PRAM   : pointer to the array
*	@RETURN : nothing
*	@SEE    :  
*	@TODO   :  
*	
*/
void destroyMAtrix(float *m)
{
    free(m);
}

/*
*	@DESC   : Initialize matrix with some random values
*	@PRAM   : pointer to the matrix and its dimensions
*	@RETURN : nothing
*	@SEE    :  
*	@TODO   :  
*	
*/
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);
        }
    }
}

/*
*	@DESC   : Sequential multiplication of matrix A and B result sotred in C
*	@PRAM   : host pointer to matrices A, B, and C dimensions of matrix C  and common
*           : dimension of matrix A, B
*	@RETURN : nothing
*	@SEE    :
*	@TODO   :
*	
*/
void matMul(float *A, float *B, float *C, int Ac, int Ar, int Bc) // Br == Ac
{
    for( int i=0; i<Ar; i++)
    {
        for( int j=0; j<Bc; j++)
        {
            float sum =0;
            for( int k=0; k<Ac; k++)
            {
                float a = A[ i*Ac + k];
                float b = B[ k*Bc + j];
                sum += a*b;
            }
            C[ i*Bc + j] = sum;
        }
    }
}

/*
 *	@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;
    cuerr = cudaSuccess;
    cuerr = cudaMalloc(m, size); 
    if (cuerr != cudaSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        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;
    cuerr = cudaSuccess;
    cuerr = cudaMemcpy(deviceptr, hostptr, size, cudaMemcpyHostToDevice);
    if (cuerr != cudaSuccess)
    {
        //fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(err));
        fprintf(stderr, "%s, %d.\n %s", __FILE__, __LINE__, cudaGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

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

/*
*	@DESC   : Multiplies matrix A with matrix B and stores output in C
*	@PRAM   : device pointers matrix A, matrix B, matrix C, dimensions of matrix C and
*	comman dimension for matrix A and B
*	@RETURN : Nothing
*	@SEE    : Tiled matrix multiplication
*	@TODO   : A detailed description
*	
*/
__global__ 
void matMulKernel(float *A, float *B, float *C, int Ac, int Ar, int Bc)
{
    __shared__ float Sa[TILE_WIDTH][TILE_WIDTH];
    __shared__ float Sb[TILE_WIDTH][TILE_WIDTH];

    int bx = blockIdx.x, by = blockIdx.y;
    int tx = threadIdx.x, ty = threadIdx.y;

    int Crow = by * TILE_WIDTH + ty;
    int Ccol = bx * TILE_WIDTH + tx;
    float sum;

    for( int phase=0 ; phase < MAT_DIM/TILE_WIDTH; phase++)
    {
        Sa[ty][tx] = A[Crow*MAT_DIM + phase*TILE_WIDTH + tx];
        Sb[ty][tx] = B[ (phase*TILE_WIDTH + ty)*MAT_DIM + Ccol];
        __syncthreads();
        
        for( int i=0 ; i<TILE_WIDTH ; i++)
        {
            float a = Sa[ty][i];
            float b = Sb[i][tx];
            sum += a*b;
        }
        __syncthreads();
    }
    C[Crow*MAT_DIM +  Ccol] = sum;
}

/*
*	@DESC   : Wrapper function to set kernel configuration and invoke the kernel
*	@PRAM   : device pointers for matrix A, B, C, and dimensions for C
*	@RETURN : nothing
*	@SEE    :  
*	@TODO   :  
*	
*/
void pMatMul(float *A, float *B, float *C, int Ac, int Ar, int Bc)
{
    dim3 gridprop(ceil(Bc/TILE_WIDTH), ceil(Ar/TILE_WIDTH), 1);
    dim3 blockprop(TILE_WIDTH, TILE_WIDTH, 1);
    matMulKernel<<<gridprop, blockprop>>>(A, B, C, Ac, Ar, Bc);
}

/*
*	@DESC   : Print the matrix
*	@PRAM   : host pointer to the matrix and its dimensions
*	@RETURN : nothing   
*	@SEE    :  
*	@TODO   : 
*	
*/
void printMat(float *A, int r, int c)
{ for( int i=0; i<r; i++)
    {
        for( int j=0; j<c; j++)
        {
            printf("%3.2f\t", A[ i*c +j]);
        }
        printf("\n");
    }
}

/*
*	@DESC   : Check if the two given matrices are equal
*	@PRAM   : host matrix pointer A, B and their dimensions
*	@RETURN : true if matrices are equal else false
*	@SEE    :  
*	@TODO   :  
*	
*/
bool check(float *A, float *B, int r, int c)
{
    for( int i=0; i<r*c; i++)
    {
        if(A[i] != B[i])
            return false;
    }
    return true;
}

int main()
{
    float *h_A, *h_B, *h_C, *h_D;
    float *d_A, *d_B, *d_C;
    float milli;

    int Ar = MAT_DIM, Ac = MAT_DIM;
    int Br = MAT_DIM, Bc = MAT_DIM;
    int Cr = MAT_DIM, Cc = MAT_DIM;

    assert(Ac == Br); // Matrix are multipliable

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


    h_A = createMartrix(Ar, Ac);
    assert(h_A != NULL);

    h_B = createMartrix(Br, Bc);
    assert(h_B != NULL);

    h_C = createMartrix(Cr, Cc);
    assert(h_C != NULL);

    h_D = createMartrix(Cr, Cc);
    assert(h_D != NULL);

    initMatrix(h_A, Ar, Ac);
    if(DEBUG)
    {
        printf("MAtrix A:\n");
        printMat(h_A, Ar, Ac);
    }

    initMatrix(h_B, Br, Bc);
    if(DEBUG)
    {
        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(&milli, start, stop);
    printf("Time required for (Configuration %d TILE_WIDTH and %d MAT_DIM) parallel \
    execution %f\n", TILE_WIDTH, MAT_DIM, milli);
    #if defined(TILE_WIDTH) && defined(MAT_DIM)
        char cmd[1024];
        char vals[256];
        sprintf(vals, "%d\t%d\t%f", TILE_WIDTH, MAT_DIM, milli);
        strcpy(cmd, "echo \"");
        strcat(cmd, vals);
        strcat(cmd, "\" >>res.data");
        system(cmd);
    #endif
    if(DEBUG)
    {
        printf("Matrix C:\n");
        printMat(h_C, 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);

    free(h_A);
    free(h_B);
    free(h_C);
    return 0;
}

	.file	"tmpxft_00382c8f_00000000-6_matMulTile.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Cannot create matrix :(\n"
	.text
	.globl	_Z13createMartrixii
	.type	_Z13createMartrixii, @function
_Z13createMartrixii:
.LFB2027:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	movslq	%edi, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	imulq	%rsi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L2
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L2:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13createMartrixii, .-_Z13createMartrixii
	.globl	_Z13destroyMAtrixPf
	.type	_Z13destroyMAtrixPf, @function
_Z13destroyMAtrixPf:
.LFB2028:
	.cfi_startproc
	endbr64
	jmp	free@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z13destroyMAtrixPf, .-_Z13destroyMAtrixPf
	.globl	_Z10initMatrixPfii
	.type	_Z10initMatrixPfii, @function
_Z10initMatrixPfii:
.LFB2029:
	.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
.L8:
	cmpl	%esi, %r14d
	jge	.L7
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,4), %r15
.L11:
	cmpl	%ebx, %ebp
	jle	.L13
	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	.L11
.L13:
	incl	%r14d
	addl	%ebp, %r13d
	jmp	.L8
.L7:
	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
.LFE2029:
	.size	_Z10initMatrixPfii, .-_Z10initMatrixPfii
	.globl	_Z6matMulPfS_S_iii
	.type	_Z6matMulPfS_S_iii, @function
_Z6matMulPfS_S_iii:
.LFB2030:
	.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
.L15:
	cmpl	%r8d, %ebx
	jge	.L14
	movslq	%r11d, %rax
	leaq	(%r10,%rax,4), %r15
	movslq	%esi, %rax
	leaq	(%rdi,%rax,4), %r14
	xorl	%eax, %eax
.L20:
	cmpl	%eax, %r9d
	jle	.L17
	leaq	(%r12,%rax,4), %r13
	xorl	%ecx, %ecx
	xorps	%xmm0, %xmm0
.L18:
	cmpl	%ecx, %edx
	jle	.L22
	movss	(%r14,%rcx,4), %xmm1
	mulss	0(%r13), %xmm1
	incq	%rcx
	addq	%rbp, %r13
	addss	%xmm1, %xmm0
	jmp	.L18
.L22:
	movss	%xmm0, (%r15,%rax,4)
	incq	%rax
	jmp	.L20
.L17:
	incl	%ebx
	addl	%r9d, %r11d
	addl	%edx, %esi
	jmp	.L15
.L14:
	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
.LFE2030:
	.size	_Z6matMulPfS_S_iii, .-_Z6matMulPfS_S_iii
	.section	.rodata.str1.1
.LC2:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/indrajeet307/CudaExperiments/master/matMulTile/matMulTile.cu"
.LC3:
	.string	"%s, %d.\n %s."
	.text
	.globl	_Z18createMatrixDevicePPfii
	.type	_Z18createMatrixDevicePPfii, @function
_Z18createMatrixDevicePPfii:
.LFB2031:
	.cfi_startproc
	endbr64
	imull	%edx, %esi
	pushq	%rcx
	.cfi_def_cfa_offset 16
	xorl	%r8d, %r8d
	movl	%r8d, cuerr(%rip)
	sall	$2, %esi
	movslq	%esi, %rsi
	call	cudaMalloc@PLT
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	je	.L23
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$119, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L23:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z18createMatrixDevicePPfii, .-_Z18createMatrixDevicePPfii
	.section	.rodata.str1.1
.LC4:
	.string	"%s, %d.\n %s"
	.text
	.globl	_Z16transferToDevicePfS_ii
	.type	_Z16transferToDevicePfS_ii, @function
_Z16transferToDevicePfS_ii:
.LFB2032:
	.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, cuerr(%rip)
	sall	$2, %edx
	movslq	%edx, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	je	.L26
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$140, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L26:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z16transferToDevicePfS_ii, .-_Z16transferToDevicePfS_ii
	.globl	_Z18transferFromDevicePfS_ii
	.type	_Z18transferFromDevicePfS_ii, @function
_Z18transferFromDevicePfS_ii:
.LFB2033:
	.cfi_startproc
	endbr64
	imull	%ecx, %edx
	pushq	%r8
	.cfi_def_cfa_offset 16
	xorl	%r9d, %r9d
	movl	$2, %ecx
	movl	%r9d, cuerr(%rip)
	sall	$2, %edx
	movslq	%edx, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	je	.L29
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$160, %r8d
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rcx
	movq	%rax, %r9
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L29:
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z18transferFromDevicePfS_ii, .-_Z18transferFromDevicePfS_ii
	.section	.rodata.str1.1
.LC5:
	.string	"%3.2f\t"
.LC6:
	.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
.L33:
	cmpl	%r14d, %r13d
	jge	.L32
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %rcx
.L36:
	cmpl	%r15d, %ebx
	jle	.L38
	leaq	.LC5(%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	.L36
.L38:
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L33
.L32:
	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
	imull	%ecx, %edx
	xorl	%eax, %eax
.L40:
	cmpl	%eax, %edx
	jle	.L45
	movss	(%rdi,%rax,4), %xmm0
	incq	%rax
	ucomiss	-4(%rsi,%rax,4), %xmm0
	jp	.L44
	je	.L40
	jmp	.L44
.L45:
	movb	$1, %al
	ret
.L44:
	xorl	%eax, %eax
	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	.L46
	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
.L46:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L48
	call	__stack_chk_fail@PLT
.L48:
	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	$16, %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	$68719476752, %rdx
	movl	$1, %ecx
	movl	%eax, 12(%rsp)
	movq	8(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L51
	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
.L51:
	.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
.LC7:
	.string	"Time required for (Configuration %d TILE_WIDTH and %d MAT_DIM) parallel     execution %f\n"
.LC8:
	.string	"%d\t%d\t%f"
.LC9:
	.string	"\" >>res.data"
.LC10:
	.string	"Success :) \n"
.LC11:
	.string	"Failed :( \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	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
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$1344, %rsp
	.cfi_def_cfa_offset 1392
	movq	%fs:40, %rax
	movq	%rax, 1336(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rdi
	leaq	56(%rsp), %r14
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$1024, %esi
	movl	$1024, %edi
	call	_Z13createMartrixii
	movl	$1024, %esi
	movl	$1024, %edi
	movq	%rax, %rbp
	call	_Z13createMartrixii
	movl	$1024, %esi
	movl	$1024, %edi
	movq	%rax, %rbx
	call	_Z13createMartrixii
	movl	$1024, %esi
	movl	$1024, %edi
	movq	%rax, %r12
	call	_Z13createMartrixii
	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
	movl	$1024, %ecx
	movl	$16, %edx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$1024, %r9d
	movq	%r14, %rdi
	movb	$1, %al
	movl	$16, %r8d
	movl	$256, %edx
	movl	$2, %esi
	cvtss2sd	12(%rsp), %xmm0
	leaq	.LC8(%rip), %rcx
	call	__sprintf_chk@PLT
	leaq	312(%rsp), %rdi
	movl	$1024, %edx
	movq	%r14, %rsi
	movl	$1869112165, 312(%rsp)
	movl	$2236527, 315(%rsp)
	call	__strcat_chk@PLT
	movl	$1024, %edx
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	__strcat_chk@PLT
	movq	%rax, %rdi
	call	system@PLT
	movq	%r12, %rsi
	movl	$1024, %ecx
	movq	%r13, %rdi
	movl	$1024, %edx
	call	_Z5checkPfS_ii
	leaq	.LC10(%rip), %rsi
	testb	%al, %al
	jne	.L59
	leaq	.LC11(%rip), %rsi
.L59:
	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	%r12, %rdi
	call	free@PLT
	movq	1336(%rsp), %rax
	subq	%fs:40, %rax
	je	.L57
	call	__stack_chk_fail@PLT
.L57:
	addq	$1344, %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
.LFE2037:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.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	.LC12(%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	cuerr
	.bss
	.align 4
	.type	cuerr, @object
	.size	cuerr, 4
cuerr:
	.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:

/*
 * Tiled version of matrix multiplication
 * Sequential Matrix multiplication
 * TODO Step 1. Matrix dimensions are multiples of TILE_WIDTH [DONE]
 * TODO Step 1.a make each thread do more work
 * TODO Step 2. MAtrix dimensions are arbitary size
 */
#include<stdio.h>
#include<assert.h>
#include<hip/hip_runtime.h>
#include<stdlib.h>
#include<sys/time.h>
#include<errno.h>

#define DEBUG 0
#define VAL_LIMIT 10
 // TILE_WIDTH and MAT_DIM can be given at compile time check Makefile
#ifndef TILE_WIDTH
#define TILE_WIDTH 16
#endif

#ifndef MAT_DIM
#define MAT_DIM 1024 
#endif

hipError_t cuerr;

/*
*	@DESC   : Allocate memory a linear aare of dimension r*c 
*	@PRAM   : number of rows and columns
*	@RETURN : address of the allocated memory
*	@SEE    :  
*	@TODO   :  
*	
*/
float *createMartrix(int r, int c)
{
    float * temp;
    temp = (float*) malloc(sizeof(float) *r *c);
    if(temp == NULL)
        printf("Cannot create matrix :(\n");
    return temp;
}

/*
*	@DESC   : Free the linear array memory
*	@PRAM   : pointer to the array
*	@RETURN : nothing
*	@SEE    :  
*	@TODO   :  
*	
*/
void destroyMAtrix(float *m)
{
    free(m);
}

/*
*	@DESC   : Initialize matrix with some random values
*	@PRAM   : pointer to the matrix and its dimensions
*	@RETURN : nothing
*	@SEE    :  
*	@TODO   :  
*	
*/
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);
        }
    }
}

/*
*	@DESC   : Sequential multiplication of matrix A and B result sotred in C
*	@PRAM   : host pointer to matrices A, B, and C dimensions of matrix C  and common
*           : dimension of matrix A, B
*	@RETURN : nothing
*	@SEE    :
*	@TODO   :
*	
*/
void matMul(float *A, float *B, float *C, int Ac, int Ar, int Bc) // Br == Ac
{
    for( int i=0; i<Ar; i++)
    {
        for( int j=0; j<Bc; j++)
        {
            float sum =0;
            for( int k=0; k<Ac; k++)
            {
                float a = A[ i*Ac + k];
                float b = B[ k*Bc + j];
                sum += a*b;
            }
            C[ i*Bc + j] = sum;
        }
    }
}

/*
 *	@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;
    cuerr = hipSuccess;
    cuerr = hipMalloc(m, size); 
    if (cuerr != hipSuccess)
    {
        fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, hipGetErrorString(cuerr));
        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;
    cuerr = hipSuccess;
    cuerr = hipMemcpy(deviceptr, hostptr, size, hipMemcpyHostToDevice);
    if (cuerr != hipSuccess)
    {
        //fprintf(stderr, "%s, %d.\n %s.", __FILE__, __LINE__, cudaGetErrorString(err));
        fprintf(stderr, "%s, %d.\n %s", __FILE__, __LINE__, hipGetErrorString(cuerr));
        exit(EXIT_FAILURE);
    }
}

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

/*
*	@DESC   : Multiplies matrix A with matrix B and stores output in C
*	@PRAM   : device pointers matrix A, matrix B, matrix C, dimensions of matrix C and
*	comman dimension for matrix A and B
*	@RETURN : Nothing
*	@SEE    : Tiled matrix multiplication
*	@TODO   : A detailed description
*	
*/
__global__ 
void matMulKernel(float *A, float *B, float *C, int Ac, int Ar, int Bc)
{
    __shared__ float Sa[TILE_WIDTH][TILE_WIDTH];
    __shared__ float Sb[TILE_WIDTH][TILE_WIDTH];

    int bx = blockIdx.x, by = blockIdx.y;
    int tx = threadIdx.x, ty = threadIdx.y;

    int Crow = by * TILE_WIDTH + ty;
    int Ccol = bx * TILE_WIDTH + tx;
    float sum;

    for( int phase=0 ; phase < MAT_DIM/TILE_WIDTH; phase++)
    {
        Sa[ty][tx] = A[Crow*MAT_DIM + phase*TILE_WIDTH + tx];
        Sb[ty][tx] = B[ (phase*TILE_WIDTH + ty)*MAT_DIM + Ccol];
        __syncthreads();
        
        for( int i=0 ; i<TILE_WIDTH ; i++)
        {
            float a = Sa[ty][i];
            float b = Sb[i][tx];
            sum += a*b;
        }
        __syncthreads();
    }
    C[Crow*MAT_DIM +  Ccol] = sum;
}

/*
*	@DESC   : Wrapper function to set kernel configuration and invoke the kernel
*	@PRAM   : device pointers for matrix A, B, C, and dimensions for C
*	@RETURN : nothing
*	@SEE    :  
*	@TODO   :  
*	
*/
void pMatMul(float *A, float *B, float *C, int Ac, int Ar, int Bc)
{
    dim3 gridprop(ceil(Bc/TILE_WIDTH), ceil(Ar/TILE_WIDTH), 1);
    dim3 blockprop(TILE_WIDTH, TILE_WIDTH, 1);
    matMulKernel<<<gridprop, blockprop>>>(A, B, C, Ac, Ar, Bc);
}

/*
*	@DESC   : Print the matrix
*	@PRAM   : host pointer to the matrix and its dimensions
*	@RETURN : nothing   
*	@SEE    :  
*	@TODO   : 
*	
*/
void printMat(float *A, int r, int c)
{ for( int i=0; i<r; i++)
    {
        for( int j=0; j<c; j++)
        {
            printf("%3.2f\t", A[ i*c +j]);
        }
        printf("\n");
    }
}

/*
*	@DESC   : Check if the two given matrices are equal
*	@PRAM   : host matrix pointer A, B and their dimensions
*	@RETURN : true if matrices are equal else false
*	@SEE    :  
*	@TODO   :  
*	
*/
bool check(float *A, float *B, int r, int c)
{
    for( int i=0; i<r*c; i++)
    {
        if(A[i] != B[i])
            return false;
    }
    return true;
}

int main()
{
    float *h_A, *h_B, *h_C, *h_D;
    float *d_A, *d_B, *d_C;
    float milli;

    int Ar = MAT_DIM, Ac = MAT_DIM;
    int Br = MAT_DIM, Bc = MAT_DIM;
    int Cr = MAT_DIM, Cc = MAT_DIM;

    assert(Ac == Br); // Matrix are multipliable

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


    h_A = createMartrix(Ar, Ac);
    assert(h_A != NULL);

    h_B = createMartrix(Br, Bc);
    assert(h_B != NULL);

    h_C = createMartrix(Cr, Cc);
    assert(h_C != NULL);

    h_D = createMartrix(Cr, Cc);
    assert(h_D != NULL);

    initMatrix(h_A, Ar, Ac);
    if(DEBUG)
    {
        printf("MAtrix A:\n");
        printMat(h_A, Ar, Ac);
    }

    initMatrix(h_B, Br, Bc);
    if(DEBUG)
    {
        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(&milli, start, stop);
    printf("Time required for (Configuration %d TILE_WIDTH and %d MAT_DIM) parallel \
    execution %f\n", TILE_WIDTH, MAT_DIM, milli);
    #if defined(TILE_WIDTH) && defined(MAT_DIM)
        char cmd[1024];
        char vals[256];
        sprintf(vals, "%d\t%d\t%f", TILE_WIDTH, MAT_DIM, milli);
        strcpy(cmd, "echo \"");
        strcat(cmd, vals);
        strcat(cmd, "\" >>res.data");
        system(cmd);
    #endif
    if(DEBUG)
    {
        printf("Matrix C:\n");
        printMat(h_C, 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);

    free(h_A);
    free(h_B);
    free(h_C);
    return 0;
}

	.text
	.file	"matMulTile.hip"
	.globl	_Z13createMartrixii             # -- Begin function _Z13createMartrixii
	.type	_Z13createMartrixii,@function
_Z13createMartrixii:                    # @_Z13createMartrixii
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movslq	%edi, %rax
	movslq	%esi, %rdi
	imulq	%rax, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB0_2
# %bb.1:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB0_2:
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z13createMartrixii, .Lfunc_end0-_Z13createMartrixii
	.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	_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	.LBB2_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
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r13d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB2_4:                                #   Parent Loop BB2_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	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%rbp
	addl	%ebx, %r13d
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	jne	.LBB2_2
.LBB2_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_end2:
	.size	_Z10initMatrixPfii, .Lfunc_end2-_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	.LBB3_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
.LBB3_2:                                # %.preheader29
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
                                        #       Child Loop BB3_6 Depth 3
	testl	%r9d, %r9d
	jle	.LBB3_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB3_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
.LBB3_4:                                # %.preheader
                                        #   Parent Loop BB3_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_6 Depth 3
	xorps	%xmm0, %xmm0
	testl	%ecx, %ecx
	jle	.LBB3_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB3_4 Depth=2
	movq	%rsi, %rbp
	xorl	%edx, %edx
.LBB3_6:                                # %.lr.ph
                                        #   Parent Loop BB3_2 Depth=1
                                        #     Parent Loop BB3_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	.LBB3_6
.LBB3_7:                                # %._crit_edge
                                        #   in Loop: Header=BB3_4 Depth=2
	movss	%xmm0, (%r13,%rax,4)
	incq	%rax
	addq	$4, %rsi
	cmpq	%r10, %rax
	jne	.LBB3_4
.LBB3_8:                                # %._crit_edge33
                                        #   in Loop: Header=BB3_2 Depth=1
	incq	%r15
	addl	%ecx, %r14d
	cmpq	%r8, %r15
	jne	.LBB3_2
.LBB3_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_end3:
	.size	_Z6matMulPfS_S_iii, .Lfunc_end3-_Z6matMulPfS_S_iii
	.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, cuerr(%rip)
	movslq	%esi, %rsi
	callq	hipMalloc
	movl	%eax, cuerr(%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.1, %esi
	movl	$.L.str.2, %edx
	movq	%rbx, %rdi
	movl	$119, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	_Z18createMatrixDevicePPfii, .Lfunc_end4-_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, cuerr(%rip)
	movslq	%edx, %rdx
	movq	%rsi, %rdi
	movq	%rax, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	jne	.LBB5_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB5_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %esi
	movl	$.L.str.2, %edx
	movq	%rbx, %rdi
	movl	$140, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end5:
	.size	_Z16transferToDevicePfS_ii, .Lfunc_end5-_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, cuerr(%rip)
	movslq	%edx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, cuerr(%rip)
	testl	%eax, %eax
	jne	.LBB6_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB6_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.1, %esi
	movl	$.L.str.2, %edx
	movq	%rbx, %rdi
	movl	$160, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	_Z18transferFromDevicePfS_ii, .Lfunc_end6-_Z18transferFromDevicePfS_ii
	.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	15(%rbx), %ecx
	testl	%r9d, %r9d
	cmovnsl	%r9d, %ecx
	sarl	$4, %ecx
	leal	15(%r14), %eax
	testl	%r8d, %r8d
	cmovnsl	%r8d, %eax
	movq	%rdi, %r13
	sarl	$4, %eax
	shlq	$32, %rax
	orq	%rcx, %rax
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	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.4, %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:
	imull	%ecx, %edx
	testl	%edx, %edx
	jle	.LBB10_3
# %bb.1:                                # %.lr.ph.preheader
	movss	(%rdi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%rsi), %xmm0
	jne	.LBB10_2
	jnp	.LBB10_5
.LBB10_2:
	xorl	%eax, %eax
                                        # kill: def $al killed $al killed $eax
	retq
.LBB10_3:
	movb	$1, %al
                                        # kill: def $al killed $al killed $eax
	retq
.LBB10_5:                               # %.lr.ph15.preheader
	movl	%edx, %eax
	movl	$1, %edx
.LBB10_6:                               # %.lr.ph15
                                        # =>This Inner Loop Header: Depth=1
	movq	%rdx, %rcx
	cmpq	%rdx, %rax
	je	.LBB10_8
# %bb.7:                                # %.lr.ph
                                        #   in Loop: Header=BB10_6 Depth=1
	movss	(%rdi,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	leaq	1(%rcx), %rdx
	ucomiss	(%rsi,%rcx,4), %xmm0
	jne	.LBB10_8
	jnp	.LBB10_6
.LBB10_8:                               # %._crit_edge.loopexit
	cmpq	%rax, %rcx
	setae	%al
                                        # kill: def $al killed $al killed $eax
	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	$1352, %rsp                     # imm = 0x548
	.cfi_def_cfa_offset 1408
	.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, 8(%rsp)                   # 8-byte Spill
	testq	%rax, %rax
	jne	.LBB11_2
# %bb.1:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB11_2:                               # %_Z13createMartrixii.exit
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r14
	testq	%rax, %rax
	jne	.LBB11_4
# %bb.3:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB11_4:                               # %_Z13createMartrixii.exit46
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r15
	testq	%rax, %rax
	jne	.LBB11_6
# %bb.5:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB11_6:                               # %_Z13createMartrixii.exit48
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.LBB11_8
# %bb.7:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB11_8:                               # %.preheader.i.preheader
	xorl	%ebx, %ebx
	movq	8(%rsp), %r13                   # 8-byte Reload
.LBB11_9:                               # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_10 Depth 2
	xorl	%ebp, %ebp
.LBB11_10:                              #   Parent Loop BB11_9 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, (%r13,%rbp,4)
	incq	%rbp
	cmpq	$1024, %rbp                     # imm = 0x400
	jne	.LBB11_10
# %bb.11:                               # %._crit_edge.i
                                        #   in Loop: Header=BB11_9 Depth=1
	incq	%rbx
	addq	$4096, %r13                     # imm = 0x1000
	cmpq	$1024, %rbx                     # imm = 0x400
	jne	.LBB11_9
# %bb.12:                               # %.preheader.i51.preheader
	xorl	%ebx, %ebx
	movq	%r14, %r13
.LBB11_13:                              # %.preheader.i51
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_14 Depth 2
	xorl	%ebp, %ebp
.LBB11_14:                              #   Parent Loop BB11_13 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, (%r13,%rbp,4)
	incq	%rbp
	cmpq	$1024, %rbp                     # imm = 0x400
	jne	.LBB11_14
# %bb.15:                               # %._crit_edge.i58
                                        #   in Loop: Header=BB11_13 Depth=1
	incq	%rbx
	addq	$4096, %r13                     # imm = 0x1000
	cmpq	$1024, %rbx                     # imm = 0x400
	jne	.LBB11_13
# %bb.16:                               # %.preheader29.i.preheader
	xorl	%eax, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
.LBB11_17:                              # %.preheader29.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB11_18 Depth 2
                                        #       Child Loop BB11_19 Depth 3
	movq	%rax, %rdx
	shlq	$12, %rdx
	addq	%r15, %rdx
	movq	%r14, %rsi
	xorl	%edi, %edi
.LBB11_18:                              # %.preheader.i63
                                        #   Parent Loop BB11_17 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB11_19 Depth 3
	xorps	%xmm0, %xmm0
	movq	%rsi, %r8
	xorl	%r9d, %r9d
.LBB11_19:                              # %.lr.ph.i
                                        #   Parent Loop BB11_17 Depth=1
                                        #     Parent Loop BB11_18 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_19
# %bb.20:                               # %._crit_edge.i68
                                        #   in Loop: Header=BB11_18 Depth=2
	movss	%xmm0, (%rdx,%rdi,4)
	incq	%rdi
	addq	$4, %rsi
	cmpq	$1024, %rdi                     # imm = 0x400
	jne	.LBB11_18
# %bb.21:                               # %._crit_edge33.i
                                        #   in Loop: Header=BB11_17 Depth=1
	incq	%rax
	addq	$4096, %rcx                     # imm = 0x1000
	cmpq	$1024, %rax                     # imm = 0x400
	jne	.LBB11_17
# %bb.22:                               # %_Z6matMulPfS_S_iii.exit
	leaq	48(%rsp), %rbp
	movq	%rbp, %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$1024, %edx                     # imm = 0x400
	callq	_Z18createMatrixDevicePPfii
	leaq	40(%rsp), %rbx
	movq	%rbx, %rdi
	movl	$1024, %esi                     # imm = 0x400
	movl	$1024, %edx                     # imm = 0x400
	callq	_Z18createMatrixDevicePPfii
	leaq	32(%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	(%rbx), %rsi
	movq	%r14, %rdi
	movl	$1024, %edx                     # imm = 0x400
	movl	$1024, %ecx                     # imm = 0x400
	callq	_Z16transferToDevicePfS_ii
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbp), %rdi
	movq	(%rbx), %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	%r12, %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	60(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.6, %edi
	movl	$16, %esi
	movl	$1024, %edx                     # imm = 0x400
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	leaq	64(%rsp), %rbx
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movl	$16, %edx
	movl	$1024, %ecx                     # imm = 0x400
	movb	$1, %al
	callq	sprintf
	leaq	320(%rsp), %r13
	movl	$1869112165, (%r13)             # imm = 0x6F686365
	movl	$2236527, 3(%r13)               # imm = 0x22206F
	movq	%r13, %rdi
	movq	%rbx, %rsi
	callq	strcat
	movq	%r13, %rdi
	callq	strlen@PLT
	movabsq	$3347130489411346466, %rcx      # imm = 0x2E7365723E3E2022
	movq	%rcx, 320(%rsp,%rax)
	movabsq	$27431034382349157, %rcx        # imm = 0x617461642E7365
	movq	%rcx, 325(%rsp,%rax)
	movq	%r13, %rdi
	callq	system
	movss	(%r12), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%r15), %xmm0
	jne	.LBB11_27
	jnp	.LBB11_23
.LBB11_27:                              # %.critedge
	movl	$.Lstr.1, %edi
.LBB11_28:                              # %_Z5checkPfS_ii.exit.thread
	callq	puts@PLT
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$1352, %rsp                     # imm = 0x548
	.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
.LBB11_23:                              # %.lr.ph.preheader
	.cfi_def_cfa_offset 1408
	movq	$-1, %rax
	movl	$.Lstr.2, %edi
.LBB11_24:                              # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	cmpq	$1048574, %rax                  # imm = 0xFFFFE
	je	.LBB11_28
# %bb.25:                               # %.lr.ph.i69
                                        #   in Loop: Header=BB11_24 Depth=1
	movss	8(%r12,%rax,4), %xmm0           # xmm0 = mem[0],zero,zero,zero
	leaq	1(%rax), %rcx
	ucomiss	8(%r15,%rax,4), %xmm0
	movq	%rcx, %rax
	jne	.LBB11_26
	jnp	.LBB11_24
.LBB11_26:                              # %_Z5checkPfS_ii.exit
	cmpq	$1048574, %rcx                  # imm = 0xFFFFE
	jbe	.LBB11_27
	jmp	.LBB11_28
.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	cuerr,@object                   # @cuerr
	.bss
	.globl	cuerr
	.p2align	2, 0x0
cuerr:
	.long	0                               # 0x0
	.size	cuerr, 4

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

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%s, %d.\n %s"
	.size	.L.str.3, 12

	.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.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"%3.2f\t"
	.size	.L.str.4, 7

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Time required for (Configuration %d TILE_WIDTH and %d MAT_DIM) parallel     execution %f\n"
	.size	.L.str.6, 90

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%d\t%d\t%f"
	.size	.L.str.7, 9

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"echo \""
	.size	.L.str.8, 7

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\" >>res.data"
	.size	.L.str.9, 13

	.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	"Cannot create matrix :("
	.size	.Lstr, 24

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Failed :( "
	.size	.Lstr.1, 11

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Success :) "
	.size	.Lstr.2, 12

	.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 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_mov_b32 s2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v2, 10, v1
	v_lshlrev_b32_e32 v6, 2, v0
	v_lshlrev_b32_e32 v3, 6, v1
	v_lshl_add_u32 v4, s14, 4, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_lshl_add_u32 v2, s15, 14, v2
	v_add_nc_u32_e32 v5, 0x400, v6
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v6, v3, v6
	v_or_b32_e32 v7, v2, v0
	s_delay_alu instid0(VALU_DEP_3)
	v_add_nc_u32_e32 v8, v5, v3
                                        ; implicit-def: $vgpr0
.LBB0_1:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_2 Depth 2
	s_lshl_b32 s3, s2, 4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v10, s3, v1
	v_add_nc_u32_e32 v9, s3, v7
	s_mov_b32 s3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v11, v10, 10, v4
	v_ashrrev_i32_e32 v10, 31, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v12, 31, v11
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, vcc_lo, s4, v9
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	v_add_co_u32 v11, vcc_lo, s6, v11
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v12, vcc_lo, s7, v12, vcc_lo
	global_load_b32 v10, v[9:10], off
	global_load_b32 v11, v[11:12], off
	v_mov_b32_e32 v9, v5
	s_waitcnt vmcnt(1)
	ds_store_b32 v6, v10
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v11
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_2:                                ;   Parent Loop BB0_1 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v10, s3, v3
	s_add_i32 s3, s3, 4
	ds_load_b32 v11, v9
	ds_load_b32 v10, v10
	v_add_nc_u32_e32 v9, 64, v9
	s_cmp_eq_u32 s3, 64
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v0, v10, v11
	s_cbranch_scc0 .LBB0_2
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 64
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_1
; %bb.4:
	v_add_nc_u32_e32 v1, v2, v4
	s_delay_alu instid0(VALU_DEP_1) | 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, s0, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[1:2], v0, 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 2048
		.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 13
		.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 = 392
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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: 2048
    .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:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
