//---------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

//---------------------------------------------------------------------------------
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** 	A = M x N		****			AxB=C
     //****		B = N x K		****
  	 //**** 	C = M x K		****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


static const int M = 3;
static const int N = 5;
static const int K = 4;
static const int TILE_WIDTH = 2;

using namespace std;
//---------------------------------------------------------------------------------
/**
 * This macro checks return value of the CUDA runtime call and exits
 * the application if the call failed.
 */
#define CUDA_CHECK_RETURN(value) {											\
	cudaError_t _m_cudaStat = value;										\
	if (_m_cudaStat != cudaSuccess) {										\
		fprintf(stderr, "Error %s at line %d in file %s\n",					\
				cudaGetErrorString(_m_cudaStat), __LINE__, __FILE__);		\
		exit(1);															\
	} }
//---------------------------------------------------------------------------------
__global__ void MatrixMulKernel(int ARows,int ACols, int BRows,
	    int BCols, int CRows, int CCols,unsigned int* A_d, unsigned int *B_d, unsigned int *C_d) {

	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** Populate matrixMultiplication kernel function ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


	int CValue = 0;

	    int Row = blockIdx.y*TILE_WIDTH + threadIdx.y;
	    int Col = blockIdx.x*TILE_WIDTH + threadIdx.x;

	    __shared__ int As[TILE_WIDTH][TILE_WIDTH];
	    __shared__ int Bs[TILE_WIDTH][TILE_WIDTH];

	    for (int k = 0; k < (TILE_WIDTH + ACols - 1)/TILE_WIDTH; k++) {

	         if (k*TILE_WIDTH + threadIdx.x < ACols && Row < ARows)
	             As[threadIdx.y][threadIdx.x] = A_d[Row*ACols + k*TILE_WIDTH + threadIdx.x];
	         else
	             As[threadIdx.y][threadIdx.x] = 0;

	         if (k*TILE_WIDTH + threadIdx.y < BRows && Col < BCols)
	             Bs[threadIdx.y][threadIdx.x] = B_d[(k*TILE_WIDTH + threadIdx.y)*BCols + Col];
	         else
	             Bs[threadIdx.y][threadIdx.x] = 0;

	         __syncthreads();

	         for (int n = 0; n < TILE_WIDTH; ++n)
	             CValue += As[threadIdx.y][n] * Bs[n][threadIdx.x];

	         __syncthreads();
	    }

	    if (Row < CRows && Col < CCols)
	        C_d[((blockIdx.y * blockDim.y + threadIdx.y)*CCols) +
	           (blockIdx.x * blockDim.x)+ threadIdx.x] = CValue;



	}




//---------------------------------------------------------------------------------
int main(void) {
	unsigned int **A ;
	unsigned int **B ;
	unsigned int **C ;
	unsigned int *A_h;
	unsigned int *A_d;
	unsigned int *B_h;
	unsigned int *B_d;
	unsigned int *C_h;
	unsigned int *C_d;
	unsigned int D[M][K];
	//Set Device
	CUDA_CHECK_RETURN(cudaSetDevice(0));

	//See random number generator
	srand(time(NULL));

	//Clear command prompt
	cout << "\033[2J\033[1;1H";

	cout << "Allocating arrays on host ... ";
	A_h = new unsigned int[M*N];
	B_h = new unsigned int[N*K];
	C_h = new unsigned int[M*K];

	A = new unsigned int* [M];
	for (int i = 0; i < M; ++i) {
		A[i] = new unsigned int[N];
	}

	B = new unsigned int* [N];
	for (int i = 0; i < N; ++i) {
		B[i] = new unsigned int[K];
	}
	C = new unsigned int* [M];
		for (int i = 0; i < M; ++i) {
			C[i] = new unsigned int[K];
		}
	cout << "done.\nPopluating input matrix on host ...";
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			A[i][j] = rand()% 11;
		}
	}

	for (int i = 0; i < N; ++i) {
			for (int j = 0; j < K; ++j) {
				B[i][j] = rand()% 11;
			}
		}

	for (int i = 0; i < M; ++i) {
			for (int j = 0; j < K; ++j) {
				C[i][j] =0;
			}
		}
	cout << "done.\nConverting 2-dimensional input matrix to 1-dimensional array on host ... ";
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
		// **** Add code for converting 2-dimensional input matrix to 1-dimensional array here  ****
		//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			A_h[i*N+j] = A[i][j];
		}
	}

	for (int i = 0; i < N; ++i) {
			for (int j = 0; j < K; ++j) {
				B_h[i*K+j] = B[i][j];
			}
		}
	cout << "done.\nAllocating arrays on device ... ";
	CUDA_CHECK_RETURN(
			cudaMalloc((void** ) &A_d, sizeof(unsigned int) * M*N));
	CUDA_CHECK_RETURN(
			cudaMalloc((void** ) &B_d, sizeof(unsigned int) * N*K));
	CUDA_CHECK_RETURN(
			cudaMalloc((void** ) &C_d, sizeof(unsigned int) * M*K));


	cout << "done.\nCopying arrays from host to device ... ";
	CUDA_CHECK_RETURN(
			cudaMemcpy(A_d, A_h, sizeof(int) * M*N,
					cudaMemcpyHostToDevice));
	CUDA_CHECK_RETURN(
			cudaMemcpy(B_d, B_h, sizeof(int) * N*K,
						cudaMemcpyHostToDevice));

	cout << "done.\nLaunching kernel ... ";


    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** define kernel launch parameters ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

	dim3 dimGrid(((K-1)/TILE_WIDTH+1), ((M-1)/TILE_WIDTH+1), 1);
	dim3 dimBlock(TILE_WIDTH, TILE_WIDTH, 1);

	//Time kernel launch
	//Time kernel launch
	cudaEvent_t start, stop;
	CUDA_CHECK_RETURN(cudaEventCreate(&start));
	CUDA_CHECK_RETURN(cudaEventCreate(&stop));
	float elapsedTime;

	CUDA_CHECK_RETURN(cudaEventRecord(start, 0));



    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** Add kernel call here ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	MatrixMulKernel<<< dimGrid, dimBlock >>>(M,N,N,K,M,K,A_d, B_d, C_d);


	CUDA_CHECK_RETURN(cudaEventRecord(stop, 0));

	CUDA_CHECK_RETURN(cudaEventSynchronize(stop));
	CUDA_CHECK_RETURN(cudaEventElapsedTime(&elapsedTime, start, stop));
	CUDA_CHECK_RETURN(cudaThreadSynchronize());	// Wait for the GPU launched work to complete
	CUDA_CHECK_RETURN(cudaGetLastError()); //Check if an error occurred in device code
	CUDA_CHECK_RETURN(cudaEventDestroy(start));
	CUDA_CHECK_RETURN(cudaEventDestroy(stop));
	cout << "done.\nElapsed kernel time: " << elapsedTime << " ms\n";

	cout << "Copying results back to host .... \n";
	CUDA_CHECK_RETURN(
			cudaMemcpy(C_h, C_d, sizeof(int) * M*K,
					cudaMemcpyDeviceToHost));


	cout << "done.\nConverting 1-dimensional output array to 2-dimensional matrix on host ... ";

    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** Add code for converting 1-dimensional output array to 2-dimensional matrix here  ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	for (int i = 0; i < M; ++i) {
			for (int j = 0; j < K; ++j) {

				C[i][j] =C_h[i*K+j] ;
			}

	}




	clock_t st, ed;

	st = clock();



	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	    // **** Check that results from kernel are correct ****
	    // **** Complete validation code below             ****
		//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@



	 for(int i=0;i<M;++i)
	        {
	            for(int j=0;j<K;++j)
	            {
	                D[i][j]=0;
	                for(int k=0;k<N;++k)
	                    D[i][j]=D[i][j]+(A[i][k]*B[k][j]);

	        }

	        }

		bool valid = true;
		for (int i = 0; i < M; ++i) {
				for (int j = 0; j < K; ++j) {
				if(C[i][j] != D[i][j])
				{
					cout << "\ndone.\n***GPU results are incorrect***";
					valid = false;
					break;
				}
			}
			if(!valid){
				break;
			}
		}

	cout<<"done\n";
	if (valid) {
			cout << "GPU results are valid.\n";
	}

    	ed = clock() - st;
	cout << "Elapsed time on host: " << ((float) ed) / CLOCKS_PER_SEC * 1000
			<< " ms" << endl;

	cout << "Freeing memory on device ... ";
	CUDA_CHECK_RETURN(cudaFree((void* ) A_d));
	CUDA_CHECK_RETURN(cudaFree((void* ) B_d));
	CUDA_CHECK_RETURN(cudaFree((void* ) C_d));
	CUDA_CHECK_RETURN(cudaDeviceReset());

	cout << "done.\nFreeing memory on host ... ";
	delete[] A_h;
	delete[] B_h;
	delete[] C_h;

	for (int i = 0; i < M; ++i) {
		delete[] A[i];
	}
	delete[] A;

	for (int i = 0; i < N; ++i) {
		delete[] B[i];
	}
	delete[] B;

	cout << "done.\nExiting program.\n";
	cout<<"  Kushagra Trivedi\n  3080669\n";
	return 0;
}


	.file	"tmpxft_0025f1ba_00000000-6_matrixMul.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_
	.type	_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_, @function
_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_:
.LFB3660:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movq	208(%rsp), %rax
	movl	%edi, 44(%rsp)
	leaq	64(%rsp), %rdi
	movl	%esi, 40(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rax, 16(%rsp)
	movq	216(%rsp), %rax
	movl	%edx, 36(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rax, 8(%rsp)
	movq	224(%rsp), %rax
	movl	%ecx, 32(%rsp)
	leaq	56(%rsp), %rcx
	movl	%r8d, 28(%rsp)
	movl	%r9d, 24(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 168(%rsp)
	movq	%rsp, %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	56(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z15MatrixMulKerneliiiiiiPjS_S_(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 224
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L2:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3660:
	.size	_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_, .-_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_
	.globl	_Z15MatrixMulKerneliiiiiiPjS_S_
	.type	_Z15MatrixMulKerneliiiiiiPjS_S_, @function
_Z15MatrixMulKerneliiiiiiPjS_S_:
.LFB3661:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_
	.cfi_endproc
.LFE3661:
	.size	_Z15MatrixMulKerneliiiiiiPjS_S_, .-_Z15MatrixMulKerneliiiiiiPjS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/kusht07/Parallel-Cuda-codes/master/matrixMulnxm/src/matrixMul.cu"
.LC1:
	.string	"Error %s at line %d in file %s\n"
.LC2:
	.string	"\033[2J\033[1;1H"
.LC3:
	.string	"Allocating arrays on host ... "
.LC4:
	.string	"done.\nPopluating input matrix on host ..."
.LC5:
	.string	"done.\nConverting 2-dimensional input matrix to 1-dimensional array on host ... "
.LC6:
	.string	"done.\nAllocating arrays on device ... "
.LC7:
	.string	"done.\nCopying arrays from host to device ... "
.LC8:
	.string	"done.\nLaunching kernel ... "
.LC9:
	.string	"done.\nElapsed kernel time: "
.LC10:
	.string	" ms\n"
.LC11:
	.string	"Copying results back to host .... \n"
.LC12:
	.string	"done.\nConverting 1-dimensional output array to 2-dimensional matrix on host ... "
.LC13:
	.string	"\ndone.\n***GPU results are incorrect***"
.LC14:
	.string	"done\n"
.LC15:
	.string	"GPU results are valid.\n"
.LC16:
	.string	"Elapsed time on host: "
.LC19:
	.string	" ms"
.LC20:
	.string	"Freeing memory on device ... "
.LC21:
	.string	"done.\nFreeing memory on host ... "
.LC22:
	.string	"done.\nExiting program.\n"
.LC23:
	.string	"  Kushagra Trivedi\n  3080669\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%edi, %edi
	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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$248, %rsp
	.cfi_def_cfa_offset 304
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L9
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$94, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L9:
	xorl	%edi, %edi
	xorl	%r12d, %r12d
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$60, %edi
	call	_Znam@PLT
	movl	$80, %edi
	movq	%rax, 8(%rsp)
	call	_Znam@PLT
	movl	$48, %edi
	movq	%rax, 24(%rsp)
	call	_Znam@PLT
	movl	$24, %edi
	movq	%rax, 16(%rsp)
	call	_Znam@PLT
	movl	$20, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	movl	$20, %edi
	movq	%rax, (%rbx)
	movq	%rax, %r15
	call	_Znam@PLT
	movl	$20, %edi
	movq	%rax, 8(%rbx)
	movq	%rax, %r14
	call	_Znam@PLT
	movl	$40, %edi
	movq	%rax, 16(%rbx)
	movq	%rax, %r13
	call	_Znam@PLT
	movq	%rax, %rbp
.L10:
	movl	$16, %edi
	call	_Znam@PLT
	movq	%rax, 0(%rbp,%r12,8)
	incq	%r12
	cmpq	$5, %r12
	jne	.L10
	movl	$24, %edi
	call	_Znam@PLT
	movl	$16, %edi
	movq	%rax, %r12
	call	_Znam@PLT
	movl	$16, %edi
	movq	%rax, (%r12)
	movq	%rax, 48(%rsp)
	call	_Znam@PLT
	movl	$16, %edi
	movq	%rax, 8(%r12)
	movq	%rax, 32(%rsp)
	call	_Znam@PLT
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rax, 16(%r12)
	movq	%rax, 80(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	xorl	%esi, %esi
.L11:
	xorl	%ecx, %ecx
.L12:
	movq	%rcx, 88(%rsp)
	movq	%rsi, 64(%rsp)
	call	rand@PLT
	movl	$11, %ecx
	movq	64(%rsp), %rsi
	cltd
	idivl	%ecx
	movq	(%rbx,%rsi,8), %rdi
	movq	88(%rsp), %rcx
	movl	%edx, (%rdi,%rcx)
	addq	$4, %rcx
	cmpq	$20, %rcx
	jne	.L12
	incq	%rsi
	cmpq	$3, %rsi
	jne	.L11
	xorl	%esi, %esi
.L13:
	xorl	%ecx, %ecx
.L14:
	movq	%rcx, 88(%rsp)
	movq	%rsi, 64(%rsp)
	call	rand@PLT
	movl	$11, %ecx
	movq	64(%rsp), %rsi
	cltd
	idivl	%ecx
	movq	0(%rbp,%rsi,8), %rdi
	movq	88(%rsp), %rcx
	movl	%edx, (%rdi,%rcx)
	addq	$4, %rcx
	cmpq	$16, %rcx
	jne	.L14
	incq	%rsi
	cmpq	$5, %rsi
	jne	.L13
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L15:
	movq	(%r12,%rax,8), %rdx
	incq	%rax
	movups	%xmm0, (%rdx)
	cmpq	$3, %rax
	jne	.L15
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movups	(%r15), %xmm1
	movq	8(%rsp), %rax
	movq	8(%rsp), %rdx
	movups	(%r14), %xmm2
	movups	%xmm1, (%rax)
	movl	16(%r15), %eax
	movups	%xmm2, 20(%rdx)
	movl	%eax, 16(%rdx)
	movl	16(%r14), %eax
	movl	%eax, 36(%rdx)
	movups	0(%r13), %xmm3
	movups	%xmm3, 40(%rdx)
	movl	16(%r13), %eax
	movl	%eax, 56(%rdx)
	xorl	%eax, %eax
.L16:
	movq	0(%rbp,%rax,8), %rcx
	movq	%rax, %rdx
	incq	%rax
	salq	$4, %rdx
	movups	(%rcx), %xmm4
	movq	24(%rsp), %rcx
	movaps	%xmm4, 64(%rsp)
	movups	%xmm4, (%rcx,%rdx)
	cmpq	$5, %rax
	jne	.L16
	leaq	_ZSt4cout(%rip), %r15
	leaq	.LC6(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	112(%rsp), %rdi
	movl	$60, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$154, %r8d
	movq	%rax, %rcx
.L75:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L17:
	leaq	120(%rsp), %rdi
	movl	$80, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L18
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$156, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L18:
	leaq	128(%rsp), %rdi
	movl	$48, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L19
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$158, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L19:
	leaq	.LC7(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	112(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movl	$60, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$163, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L20:
	movq	120(%rsp), %rdi
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movl	$80, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$166, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L21:
	leaq	.LC8(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	136(%rsp), %rdi
	movabsq	$8589934594, %rax
	movl	$1, 160(%rsp)
	movq	%rax, 152(%rsp)
	movq	%rax, 164(%rsp)
	movl	$1, 172(%rsp)
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$183, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L22:
	leaq	144(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$184, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L23:
	movq	136(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$187, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L24:
	movl	172(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	164(%rsp), %rdx
	movq	152(%rsp), %rdi
	movl	160(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	%rax
	.cfi_def_cfa_offset 312
	movl	$4, %ecx
	movl	$5, %edx
	movl	$5, %esi
	pushq	136(%rsp)
	.cfi_def_cfa_offset 320
	movl	$4, %r9d
	movl	$3, %r8d
	movl	$3, %edi
	pushq	136(%rsp)
	.cfi_def_cfa_offset 328
	pushq	136(%rsp)
	.cfi_def_cfa_offset 336
	call	_Z45__device_stub__Z15MatrixMulKerneliiiiiiPjS_S_iiiiiiPjS_S_
	addq	$32, %rsp
	.cfi_def_cfa_offset 304
.L25:
	movq	144(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L26
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$197, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L26:
	movq	144(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L27
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$199, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L27:
	movq	144(%rsp), %rdx
	movq	136(%rsp), %rsi
	leaq	108(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L28
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$200, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L28:
	call	cudaThreadSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L29
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$201, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L29:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L30
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$202, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L30:
	movq	136(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L31
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$203, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L31:
	movq	144(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L32
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$204, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L32:
	leaq	.LC9(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	108(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	16(%rsp), %rdi
	movl	$2, %ecx
	movq	128(%rsp), %rsi
	movl	$48, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L33
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$208, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L33:
	leaq	.LC12(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	16(%rsp), %rax
	movups	(%rax), %xmm6
	movq	48(%rsp), %rax
	movups	%xmm6, (%rax)
	movq	16(%rsp), %rax
	movaps	%xmm6, 64(%rsp)
	movups	16(%rax), %xmm1
	movq	32(%rsp), %rax
	movups	%xmm1, (%rax)
	movq	16(%rsp), %rax
	movaps	%xmm1, 48(%rsp)
	movups	32(%rax), %xmm3
	movq	80(%rsp), %rax
	movups	%xmm3, (%rax)
	movaps	%xmm3, 32(%rsp)
	call	clock@PLT
	leaq	176(%rsp), %rcx
	xorl	%esi, %esi
	movq	%rax, %r13
	movq	%rcx, %rdi
.L34:
	movq	(%rbx,%rsi,8), %r10
	xorl	%eax, %eax
.L36:
	xorl	%r8d, %r8d
	xorl	%edx, %edx
.L35:
	movq	0(%rbp,%rdx,8), %r9
	movl	(%r9,%rax), %r9d
	imull	(%r10,%rdx,4), %r9d
	incq	%rdx
	addl	%r9d, %r8d
	cmpq	$5, %rdx
	jne	.L35
	movl	%r8d, (%rdi,%rax)
	addq	$4, %rax
	cmpq	$16, %rax
	jne	.L36
	incq	%rsi
	addq	$16, %rdi
	cmpq	$3, %rsi
	jne	.L34
	xorl	%edx, %edx
.L37:
	movq	(%r12,%rdx,8), %rsi
	xorl	%eax, %eax
.L40:
	movl	(%rcx,%rax), %edi
	cmpl	%edi, (%rsi,%rax)
	je	.L38
	leaq	.LC13(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	xorl	%r14d, %r14d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L39
.L38:
	addq	$4, %rax
	cmpq	$16, %rax
	jne	.L40
	incq	%rdx
	addq	$16, %rcx
	cmpq	$3, %rdx
	jne	.L37
	movb	$1, %r14b
.L39:
	leaq	_ZSt4cout(%rip), %r12
	leaq	.LC14(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	testb	%r14b, %r14b
	je	.L41
	leaq	.LC15(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L41:
	call	clock@PLT
	leaq	.LC16(%rip), %rsi
	movq	%r15, %rdi
	subq	%r13, %rax
	movq	%rax, %r14
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtsi2ssq	%r14, %xmm0
	divss	.LC17(%rip), %xmm0
	mulss	.LC18(%rip), %xmm0
	movq	%rax, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC19(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	.LC20(%rip), %rsi
	movq	%r15, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L42
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$279, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L42:
	movq	120(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L43
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$280, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L43:
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L44
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$281, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L44:
	call	cudaDeviceReset@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L45
	call	cudaGetErrorString@PLT
	leaq	.LC0(%rip), %r9
	movl	$282, %r8d
	movq	%rax, %rcx
	jmp	.L75
.L45:
	leaq	.LC21(%rip), %rsi
	movq	%r15, %rdi
	xorl	%r13d, %r13d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	8(%rsp), %rdi
	call	_ZdaPv@PLT
	movq	24(%rsp), %rdi
	call	_ZdaPv@PLT
	movq	16(%rsp), %rdi
	call	_ZdaPv@PLT
.L47:
	movq	(%rbx,%r13,8), %rdi
	testq	%rdi, %rdi
	je	.L46
	call	_ZdaPv@PLT
.L46:
	incq	%r13
	cmpq	$3, %r13
	jne	.L47
	movq	%rbx, %rdi
	xorl	%ebx, %ebx
	call	_ZdaPv@PLT
.L49:
	movq	0(%rbp,%rbx,8), %rdi
	testq	%rdi, %rdi
	je	.L48
	call	_ZdaPv@PLT
.L48:
	incq	%rbx
	cmpq	$5, %rbx
	jne	.L49
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	leaq	.LC22(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC23(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L50
	call	__stack_chk_fail@PLT
.L50:
	addq	$248, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	main, .-main
	.section	.rodata.str1.1
.LC25:
	.string	"_Z15MatrixMulKerneliiiiiiPjS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3663:
	.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	.LC25(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z15MatrixMulKerneliiiiiiPjS_S_(%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
.LFE3663:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC17:
	.long	1232348160
	.align 4
.LC18:
	.long	1148846080
	.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:

//---------------------------------------------------------------------------------

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>

//---------------------------------------------------------------------------------
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** 	A = M x N		****			AxB=C
     //****		B = N x K		****
  	 //**** 	C = M x K		****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


static const int M = 3;
static const int N = 5;
static const int K = 4;
static const int TILE_WIDTH = 2;

using namespace std;
//---------------------------------------------------------------------------------
/**
 * This macro checks return value of the CUDA runtime call and exits
 * the application if the call failed.
 */
#define CUDA_CHECK_RETURN(value) {											\
	hipError_t _m_cudaStat = value;										\
	if (_m_cudaStat != hipSuccess) {										\
		fprintf(stderr, "Error %s at line %d in file %s\n",					\
				hipGetErrorString(_m_cudaStat), __LINE__, __FILE__);		\
		exit(1);															\
	} }
//---------------------------------------------------------------------------------
__global__ void MatrixMulKernel(int ARows,int ACols, int BRows,
	    int BCols, int CRows, int CCols,unsigned int* A_d, unsigned int *B_d, unsigned int *C_d) {

	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** Populate matrixMultiplication kernel function ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


	int CValue = 0;

	    int Row = blockIdx.y*TILE_WIDTH + threadIdx.y;
	    int Col = blockIdx.x*TILE_WIDTH + threadIdx.x;

	    __shared__ int As[TILE_WIDTH][TILE_WIDTH];
	    __shared__ int Bs[TILE_WIDTH][TILE_WIDTH];

	    for (int k = 0; k < (TILE_WIDTH + ACols - 1)/TILE_WIDTH; k++) {

	         if (k*TILE_WIDTH + threadIdx.x < ACols && Row < ARows)
	             As[threadIdx.y][threadIdx.x] = A_d[Row*ACols + k*TILE_WIDTH + threadIdx.x];
	         else
	             As[threadIdx.y][threadIdx.x] = 0;

	         if (k*TILE_WIDTH + threadIdx.y < BRows && Col < BCols)
	             Bs[threadIdx.y][threadIdx.x] = B_d[(k*TILE_WIDTH + threadIdx.y)*BCols + Col];
	         else
	             Bs[threadIdx.y][threadIdx.x] = 0;

	         __syncthreads();

	         for (int n = 0; n < TILE_WIDTH; ++n)
	             CValue += As[threadIdx.y][n] * Bs[n][threadIdx.x];

	         __syncthreads();
	    }

	    if (Row < CRows && Col < CCols)
	        C_d[((blockIdx.y * blockDim.y + threadIdx.y)*CCols) +
	           (blockIdx.x * blockDim.x)+ threadIdx.x] = CValue;



	}




//---------------------------------------------------------------------------------
int main(void) {
	unsigned int **A ;
	unsigned int **B ;
	unsigned int **C ;
	unsigned int *A_h;
	unsigned int *A_d;
	unsigned int *B_h;
	unsigned int *B_d;
	unsigned int *C_h;
	unsigned int *C_d;
	unsigned int D[M][K];
	//Set Device
	CUDA_CHECK_RETURN(hipSetDevice(0));

	//See random number generator
	srand(time(NULL));

	//Clear command prompt
	cout << "\033[2J\033[1;1H";

	cout << "Allocating arrays on host ... ";
	A_h = new unsigned int[M*N];
	B_h = new unsigned int[N*K];
	C_h = new unsigned int[M*K];

	A = new unsigned int* [M];
	for (int i = 0; i < M; ++i) {
		A[i] = new unsigned int[N];
	}

	B = new unsigned int* [N];
	for (int i = 0; i < N; ++i) {
		B[i] = new unsigned int[K];
	}
	C = new unsigned int* [M];
		for (int i = 0; i < M; ++i) {
			C[i] = new unsigned int[K];
		}
	cout << "done.\nPopluating input matrix on host ...";
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			A[i][j] = rand()% 11;
		}
	}

	for (int i = 0; i < N; ++i) {
			for (int j = 0; j < K; ++j) {
				B[i][j] = rand()% 11;
			}
		}

	for (int i = 0; i < M; ++i) {
			for (int j = 0; j < K; ++j) {
				C[i][j] =0;
			}
		}
	cout << "done.\nConverting 2-dimensional input matrix to 1-dimensional array on host ... ";
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
		// **** Add code for converting 2-dimensional input matrix to 1-dimensional array here  ****
		//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			A_h[i*N+j] = A[i][j];
		}
	}

	for (int i = 0; i < N; ++i) {
			for (int j = 0; j < K; ++j) {
				B_h[i*K+j] = B[i][j];
			}
		}
	cout << "done.\nAllocating arrays on device ... ";
	CUDA_CHECK_RETURN(
			hipMalloc((void** ) &A_d, sizeof(unsigned int) * M*N));
	CUDA_CHECK_RETURN(
			hipMalloc((void** ) &B_d, sizeof(unsigned int) * N*K));
	CUDA_CHECK_RETURN(
			hipMalloc((void** ) &C_d, sizeof(unsigned int) * M*K));


	cout << "done.\nCopying arrays from host to device ... ";
	CUDA_CHECK_RETURN(
			hipMemcpy(A_d, A_h, sizeof(int) * M*N,
					hipMemcpyHostToDevice));
	CUDA_CHECK_RETURN(
			hipMemcpy(B_d, B_h, sizeof(int) * N*K,
						hipMemcpyHostToDevice));

	cout << "done.\nLaunching kernel ... ";


    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** define kernel launch parameters ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

	dim3 dimGrid(((K-1)/TILE_WIDTH+1), ((M-1)/TILE_WIDTH+1), 1);
	dim3 dimBlock(TILE_WIDTH, TILE_WIDTH, 1);

	//Time kernel launch
	//Time kernel launch
	hipEvent_t start, stop;
	CUDA_CHECK_RETURN(hipEventCreate(&start));
	CUDA_CHECK_RETURN(hipEventCreate(&stop));
	float elapsedTime;

	CUDA_CHECK_RETURN(hipEventRecord(start, 0));



    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** Add kernel call here ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	MatrixMulKernel<<< dimGrid, dimBlock >>>(M,N,N,K,M,K,A_d, B_d, C_d);


	CUDA_CHECK_RETURN(hipEventRecord(stop, 0));

	CUDA_CHECK_RETURN(hipEventSynchronize(stop));
	CUDA_CHECK_RETURN(hipEventElapsedTime(&elapsedTime, start, stop));
	CUDA_CHECK_RETURN(hipDeviceSynchronize());	// Wait for the GPU launched work to complete
	CUDA_CHECK_RETURN(hipGetLastError()); //Check if an error occurred in device code
	CUDA_CHECK_RETURN(hipEventDestroy(start));
	CUDA_CHECK_RETURN(hipEventDestroy(stop));
	cout << "done.\nElapsed kernel time: " << elapsedTime << " ms\n";

	cout << "Copying results back to host .... \n";
	CUDA_CHECK_RETURN(
			hipMemcpy(C_h, C_d, sizeof(int) * M*K,
					hipMemcpyDeviceToHost));


	cout << "done.\nConverting 1-dimensional output array to 2-dimensional matrix on host ... ";

    //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	// **** Add code for converting 1-dimensional output array to 2-dimensional matrix here  ****
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	for (int i = 0; i < M; ++i) {
			for (int j = 0; j < K; ++j) {

				C[i][j] =C_h[i*K+j] ;
			}

	}




	clock_t st, ed;

	st = clock();



	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	    // **** Check that results from kernel are correct ****
	    // **** Complete validation code below             ****
		//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@



	 for(int i=0;i<M;++i)
	        {
	            for(int j=0;j<K;++j)
	            {
	                D[i][j]=0;
	                for(int k=0;k<N;++k)
	                    D[i][j]=D[i][j]+(A[i][k]*B[k][j]);

	        }

	        }

		bool valid = true;
		for (int i = 0; i < M; ++i) {
				for (int j = 0; j < K; ++j) {
				if(C[i][j] != D[i][j])
				{
					cout << "\ndone.\n***GPU results are incorrect***";
					valid = false;
					break;
				}
			}
			if(!valid){
				break;
			}
		}

	cout<<"done\n";
	if (valid) {
			cout << "GPU results are valid.\n";
	}

    	ed = clock() - st;
	cout << "Elapsed time on host: " << ((float) ed) / CLOCKS_PER_SEC * 1000
			<< " ms" << endl;

	cout << "Freeing memory on device ... ";
	CUDA_CHECK_RETURN(hipFree((void* ) A_d));
	CUDA_CHECK_RETURN(hipFree((void* ) B_d));
	CUDA_CHECK_RETURN(hipFree((void* ) C_d));
	CUDA_CHECK_RETURN(hipDeviceReset());

	cout << "done.\nFreeing memory on host ... ";
	delete[] A_h;
	delete[] B_h;
	delete[] C_h;

	for (int i = 0; i < M; ++i) {
		delete[] A[i];
	}
	delete[] A;

	for (int i = 0; i < N; ++i) {
		delete[] B[i];
	}
	delete[] B;

	cout << "done.\nExiting program.\n";
	cout<<"  Kushagra Trivedi\n  3080669\n";
	return 0;
}


	.text
	.file	"matrixMul.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_ # -- Begin function _Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_
	.type	_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_,@function
_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_: # @_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	28(%rsp), %rax
	movl	%edi, (%rax)
	leaq	24(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	20(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	16(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	8(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	80(%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	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	216(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	40(%rsp), %r12
	leaq	32(%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	$_Z15MatrixMulKerneliiiiiiPjS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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_end0:
	.size	_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_, .Lfunc_end0-_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x49742400                      # float 1.0E+6
.LCPI1_1:
	.long	0x447a0000                      # float 1000
	.text
	.globl	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	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB1_1
# %bb.3:
	xorl	%ebx, %ebx
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$30, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$60, %edi
	callq	_Znam
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	movl	$80, %edi
	callq	_Znam
	movq	%rax, %r13
	movl	$48, %edi
	callq	_Znam
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movl	$24, %edi
	callq	_Znam
	movq	%rax, %r14
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movl	$20, %edi
	callq	_Znam
	movq	%rax, (%r14,%rbx,8)
	incq	%rbx
	cmpq	$3, %rbx
	jne	.LBB1_4
# %bb.5:
	movl	$40, %edi
	callq	_Znam
	movq	%rax, %rbx
	xorl	%r15d, %r15d
.LBB1_6:                                # =>This Inner Loop Header: Depth=1
	movl	$16, %edi
	callq	_Znam
	movq	%rax, (%rbx,%r15,8)
	incq	%r15
	cmpq	$5, %r15
	jne	.LBB1_6
# %bb.7:
	movl	$24, %edi
	callq	_Znam
	movq	%rax, %rbp
	xorl	%r15d, %r15d
.LBB1_8:                                # =>This Inner Loop Header: Depth=1
	movl	$16, %edi
	callq	_Znam
	movq	%rax, (%rbp,%r15,8)
	incq	%r15
	cmpq	$3, %r15
	jne	.LBB1_8
# %bb.9:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$41, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%r15d, %r15d
.LBB1_10:                               # %.preheader241
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_11 Depth 2
	xorl	%r12d, %r12d
.LBB1_11:                               #   Parent Loop BB1_10 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$780903145, %rax, %rcx          # imm = 0x2E8BA2E9
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$33, %rcx
	addl	%edx, %ecx
	leal	(%rcx,%rcx,4), %edx
	leal	(%rcx,%rdx,2), %ecx
	subl	%ecx, %eax
	movq	(%r14,%r15,8), %rcx
	movl	%eax, (%rcx,%r12,4)
	incq	%r12
	cmpq	$5, %r12
	jne	.LBB1_11
# %bb.12:                               #   in Loop: Header=BB1_10 Depth=1
	incq	%r15
	cmpq	$3, %r15
	jne	.LBB1_10
# %bb.13:                               # %.preheader239.preheader
	xorl	%r15d, %r15d
.LBB1_14:                               # %.preheader239
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_15 Depth 2
	xorl	%r12d, %r12d
.LBB1_15:                               #   Parent Loop BB1_14 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$780903145, %rax, %rcx          # imm = 0x2E8BA2E9
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$33, %rcx
	addl	%edx, %ecx
	leal	(%rcx,%rcx,4), %edx
	leal	(%rcx,%rdx,2), %ecx
	subl	%ecx, %eax
	movq	(%rbx,%r15,8), %rcx
	movl	%eax, (%rcx,%r12,4)
	incq	%r12
	cmpq	$4, %r12
	jne	.LBB1_15
# %bb.16:                               #   in Loop: Header=BB1_14 Depth=1
	incq	%r15
	cmpq	$5, %r15
	jne	.LBB1_14
# %bb.17:                               # %.preheader237.preheader
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.LBB1_18:                               # %.preheader237
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbp,%rax,8), %rcx
	movups	%xmm0, (%rcx)
	incq	%rax
	cmpq	$3, %rax
	jne	.LBB1_18
# %bb.19:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$79, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%eax, %eax
	movq	56(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rcx
	movq	%r13, %r12
.LBB1_20:                               # %.preheader236
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_21 Depth 2
	movq	(%r14,%rax,8), %rdx
	xorl	%esi, %esi
.LBB1_21:                               #   Parent Loop BB1_20 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rdx,%rsi,4), %edi
	movl	%edi, (%rcx,%rsi,4)
	incq	%rsi
	cmpq	$5, %rsi
	jne	.LBB1_21
# %bb.22:                               #   in Loop: Header=BB1_20 Depth=1
	incq	%rax
	addq	$20, %rcx
	cmpq	$3, %rax
	jne	.LBB1_20
# %bb.23:                               # %.preheader234.preheader
	xorl	%eax, %eax
	movq	%r12, %rcx
.LBB1_24:                               # %.preheader234
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_25 Depth 2
	movq	(%rbx,%rax,8), %rdx
	xorl	%esi, %esi
.LBB1_25:                               #   Parent Loop BB1_24 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rdx,%rsi,4), %edi
	movl	%edi, (%rcx,%rsi,4)
	incq	%rsi
	cmpq	$4, %rsi
	jne	.LBB1_25
# %bb.26:                               #   in Loop: Header=BB1_24 Depth=1
	incq	%rax
	addq	$16, %rcx
	cmpq	$5, %rax
	jne	.LBB1_24
# %bb.27:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$38, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	32(%rsp), %rdi
	movl	$60, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_28
# %bb.29:
	leaq	24(%rsp), %rdi
	movl	$80, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_30
# %bb.31:
	leaq	16(%rsp), %rdi
	movl	$48, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_32
# %bb.33:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$45, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	32(%rsp), %rdi
	movl	$60, %edx
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_34
# %bb.35:
	movq	24(%rsp), %rdi
	movl	$80, %edx
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_36
# %bb.37:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$27, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	movq	48(%rsp), %r15                  # 8-byte Reload
	jne	.LBB1_38
# %bb.39:
	movq	%rsp, %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB1_40
# %bb.41:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB1_42
# %bb.43:
	movabsq	$8589934594, %rdi               # imm = 0x200000002
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_45
# %bb.44:
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$3, %edi
	movl	$5, %esi
	movl	$5, %edx
	movl	$4, %ecx
	movl	$3, %r8d
	movl	$4, %r9d
	pushq	24(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	40(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB1_45:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB1_46
# %bb.47:
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB1_48
# %bb.49:
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	44(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB1_50
# %bb.51:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB1_52
# %bb.53:
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_54
# %bb.55:
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB1_56
# %bb.57:
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB1_58
# %bb.59:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$27, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	44(%rsp), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.10, %esi
	movl	$4, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$35, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	16(%rsp), %rsi
	movl	$48, %edx
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_60
# %bb.61:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.12, %esi
	movl	$80, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%eax, %eax
.LBB1_62:                               # %.preheader233
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_63 Depth 2
	movq	(%rbp,%rax,8), %rdx
	xorl	%esi, %esi
.LBB1_63:                               #   Parent Loop BB1_62 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r15,%rsi,4), %edi
	movl	%edi, (%rdx,%rsi,4)
	incq	%rsi
	cmpq	$4, %rsi
	jne	.LBB1_63
# %bb.64:                               #   in Loop: Header=BB1_62 Depth=1
	incq	%rax
	addq	$16, %r15
	cmpq	$3, %rax
	jne	.LBB1_62
# %bb.65:
	xorl	%r12d, %r12d
	callq	clock
	movq	%rax, %r15
.LBB1_66:                               # %.preheader232
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_67 Depth 2
                                        #       Child Loop BB1_68 Depth 3
	movq	(%r14,%r12,8), %rax
	movq	%r12, %rcx
	shlq	$4, %rcx
	addq	%rsp, %rcx
	addq	$64, %rcx
	xorl	%edx, %edx
.LBB1_67:                               #   Parent Loop BB1_66 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_68 Depth 3
	leaq	(%rcx,%rdx,4), %rsi
	xorl	%edi, %edi
	xorl	%r8d, %r8d
.LBB1_68:                               #   Parent Loop BB1_66 Depth=1
                                        #     Parent Loop BB1_67 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	(%rbx,%rdi,8), %r9
	movl	(%r9,%rdx,4), %r9d
	imull	(%rax,%rdi,4), %r9d
	addl	%r9d, %r8d
	incq	%rdi
	cmpq	$5, %rdi
	jne	.LBB1_68
# %bb.69:                               #   in Loop: Header=BB1_67 Depth=2
	movl	%r8d, (%rsi)
	incq	%rdx
	cmpq	$4, %rdx
	jne	.LBB1_67
# %bb.70:                               #   in Loop: Header=BB1_66 Depth=1
	incq	%r12
	cmpq	$3, %r12
	jne	.LBB1_66
# %bb.71:                               # %.preheader.preheader
	leaq	64(%rsp), %rax
	xorl	%ecx, %ecx
.LBB1_72:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_74 Depth 2
	movq	(%rbp,%rcx,8), %rdx
	xorl	%esi, %esi
.LBB1_74:                               #   Parent Loop BB1_72 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rdx,%rsi,4), %edi
	cmpl	(%rax,%rsi,4), %edi
	jne	.LBB1_75
# %bb.73:                               #   in Loop: Header=BB1_74 Depth=2
	incq	%rsi
	cmpq	$4, %rsi
	jne	.LBB1_74
# %bb.76:                               #   in Loop: Header=BB1_72 Depth=1
	incq	%rcx
	addq	$16, %rax
	cmpq	$3, %rcx
	jne	.LBB1_72
# %bb.77:                               # %.critedge
	movl	$_ZSt4cout, %edi
	movl	$.L.str.14, %esi
	movl	$5, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.15, %esi
	movl	$23, %edx
	jmp	.LBB1_78
.LBB1_75:                               # %.thread
	movl	$_ZSt4cout, %edi
	movl	$.L.str.13, %esi
	movl	$38, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.14, %esi
	movl	$5, %edx
.LBB1_78:
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	callq	clock
	movq	%rax, %rbp
	subq	%r15, %rbp
	movl	$_ZSt4cout, %edi
	movl	$.L.str.16, %esi
	movl	$22, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtsi2ss	%rbp, %xmm0
	divss	.LCPI1_0(%rip), %xmm0
	mulss	.LCPI1_1(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.17, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.18, %esi
	movl	$29, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	32(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_79
# %bb.80:
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	movq	56(%rsp), %r15                  # 8-byte Reload
	jne	.LBB1_81
# %bb.82:
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_83
# %bb.84:
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB1_85
# %bb.86:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.19, %esi
	movl	$33, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r15, %rdi
	callq	_ZdaPv
	movq	%r13, %rdi
	callq	_ZdaPv
	movq	48(%rsp), %rdi                  # 8-byte Reload
	callq	_ZdaPv
	xorl	%r15d, %r15d
.LBB1_87:                               # =>This Inner Loop Header: Depth=1
	movq	(%r14,%r15,8), %rdi
	testq	%rdi, %rdi
	je	.LBB1_89
# %bb.88:                               #   in Loop: Header=BB1_87 Depth=1
	callq	_ZdaPv
.LBB1_89:                               #   in Loop: Header=BB1_87 Depth=1
	incq	%r15
	cmpq	$3, %r15
	jne	.LBB1_87
# %bb.90:
	movq	%r14, %rdi
	callq	_ZdaPv
	xorl	%r14d, %r14d
.LBB1_91:                               # =>This Inner Loop Header: Depth=1
	movq	(%rbx,%r14,8), %rdi
	testq	%rdi, %rdi
	je	.LBB1_93
# %bb.92:                               #   in Loop: Header=BB1_91 Depth=1
	callq	_ZdaPv
.LBB1_93:                               #   in Loop: Header=BB1_91 Depth=1
	incq	%r14
	cmpq	$5, %r14
	jne	.LBB1_91
# %bb.94:
	movq	%rbx, %rdi
	callq	_ZdaPv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.20, %esi
	movl	$23, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.21, %esi
	movl	$29, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%eax, %eax
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	.cfi_def_cfa_offset 176
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$96, %ecx
	jmp	.LBB1_2
.LBB1_28:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$157, %ecx
	jmp	.LBB1_2
.LBB1_30:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$159, %ecx
	jmp	.LBB1_2
.LBB1_32:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$161, %ecx
	jmp	.LBB1_2
.LBB1_34:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$167, %ecx
	jmp	.LBB1_2
.LBB1_36:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$170, %ecx
	jmp	.LBB1_2
.LBB1_38:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$185, %ecx
	jmp	.LBB1_2
.LBB1_40:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$186, %ecx
	jmp	.LBB1_2
.LBB1_42:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$189, %ecx
	jmp	.LBB1_2
.LBB1_46:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$199, %ecx
	jmp	.LBB1_2
.LBB1_48:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$201, %ecx
	jmp	.LBB1_2
.LBB1_50:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$202, %ecx
	jmp	.LBB1_2
.LBB1_52:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$203, %ecx
	jmp	.LBB1_2
.LBB1_54:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$204, %ecx
	jmp	.LBB1_2
.LBB1_56:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$205, %ecx
	jmp	.LBB1_2
.LBB1_58:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$206, %ecx
	jmp	.LBB1_2
.LBB1_60:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$212, %ecx
	jmp	.LBB1_2
.LBB1_79:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$281, %ecx                      # imm = 0x119
	jmp	.LBB1_2
.LBB1_81:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$282, %ecx                      # imm = 0x11A
	jmp	.LBB1_2
.LBB1_83:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$283, %ecx                      # imm = 0x11B
	jmp	.LBB1_2
.LBB1_85:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %r8d
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$284, %ecx                      # imm = 0x11C
.LBB1_2:
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15MatrixMulKerneliiiiiiPjS_S_, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z15MatrixMulKerneliiiiiiPjS_S_,@object # @_Z15MatrixMulKerneliiiiiiPjS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z15MatrixMulKerneliiiiiiPjS_S_
	.p2align	3, 0x0
_Z15MatrixMulKerneliiiiiiPjS_S_:
	.quad	_Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_
	.size	_Z15MatrixMulKerneliiiiiiPjS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Error %s at line %d in file %s\n"
	.size	.L.str, 32

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/kusht07/Parallel-Cuda-codes/master/matrixMulnxm/src/matrixMul.hip"
	.size	.L.str.1, 128

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\033[2J\033[1;1H"
	.size	.L.str.2, 11

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Allocating arrays on host ... "
	.size	.L.str.3, 31

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"done.\nPopluating input matrix on host ..."
	.size	.L.str.4, 42

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"done.\nConverting 2-dimensional input matrix to 1-dimensional array on host ... "
	.size	.L.str.5, 80

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"done.\nAllocating arrays on device ... "
	.size	.L.str.6, 39

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"done.\nCopying arrays from host to device ... "
	.size	.L.str.7, 46

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"done.\nLaunching kernel ... "
	.size	.L.str.8, 28

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"done.\nElapsed kernel time: "
	.size	.L.str.9, 28

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	" ms\n"
	.size	.L.str.10, 5

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Copying results back to host .... \n"
	.size	.L.str.11, 36

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"done.\nConverting 1-dimensional output array to 2-dimensional matrix on host ... "
	.size	.L.str.12, 81

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"\ndone.\n***GPU results are incorrect***"
	.size	.L.str.13, 39

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"done\n"
	.size	.L.str.14, 6

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"GPU results are valid.\n"
	.size	.L.str.15, 24

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Elapsed time on host: "
	.size	.L.str.16, 23

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	" ms"
	.size	.L.str.17, 4

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"Freeing memory on device ... "
	.size	.L.str.18, 30

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"done.\nFreeing memory on host ... "
	.size	.L.str.19, 34

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"done.\nExiting program.\n"
	.size	.L.str.20, 24

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"  Kushagra Trivedi\n  3080669\n"
	.size	.L.str.21, 30

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15MatrixMulKerneliiiiiiPjS_S_"
	.size	.L__unnamed_1, 32

	.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

	.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 _Z30__device_stub__MatrixMulKerneliiiiiiPjS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z15MatrixMulKerneliiiiiiPjS_S_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15MatrixMulKerneliiiiiiPjS_S_ ; -- Begin function _Z15MatrixMulKerneliiiiiiPjS_S_
	.globl	_Z15MatrixMulKerneliiiiiiPjS_S_
	.p2align	8
	.type	_Z15MatrixMulKerneliiiiiiPjS_S_,@function
_Z15MatrixMulKerneliiiiiiPjS_S_:        ; @_Z15MatrixMulKerneliiiiiiPjS_S_
; %bb.0:
	s_clause 0x3
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[16:17], s[0:1], 0x10
	s_load_b128 s[8:11], s[0:1], 0x18
	s_load_b64 s[12:13], s[0:1], 0x28
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v6, s15, 1, v1
	v_lshl_add_u32 v2, s14, 1, v5
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s5, 1
	s_cbranch_scc1 .LBB0_9
; %bb.1:                                ; %.lr.ph
	v_dual_mov_b32 v0, 0 :: v_dual_lshlrev_b32 v7, 2, v5
	v_mul_lo_u32 v9, v6, s5
	v_cmp_gt_i32_e64 s2, s4, v6
	v_cmp_gt_i32_e64 s3, s7, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_lshl_add_u32 v8, v1, 3, v7
	v_dual_mov_b32 v4, 0 :: v_dual_lshlrev_b32 v11, 3, v1
	s_add_i32 s18, s5, 1
	s_lshr_b32 s4, s18, 1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v10, 16, v8
	s_mov_b32 s18, 0
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_7 Depth 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b32 s19, s18, 1
	v_dual_mov_b32 v3, 0 :: v_dual_add_nc_u32 v12, s19, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_u32_e32 vcc_lo, s5, v12
	s_and_b32 s21, s2, vcc_lo
	s_and_saveexec_b32 s20, s21
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_nc_u32_e32 v3, v12, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[12:13], 2, v[3:4]
	v_add_co_u32 v12, vcc_lo, s8, v12
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v13, vcc_lo, s9, v13, vcc_lo
	global_load_b32 v3, v[12:13], off
.LBB0_4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s20
	v_dual_mov_b32 v13, 0 :: v_dual_add_nc_u32 v12, s19, v1
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v3
	v_cmp_gt_u32_e32 vcc_lo, s6, v12
	s_and_b32 s20, s3, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s19, s20
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_mad_u64_u32 v[13:14], null, v12, s7, v[2:3]
	v_mov_b32_e32 v14, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[12:13], 2, v[13:14]
	v_add_co_u32 v12, vcc_lo, s10, v12
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v13, vcc_lo, s11, v13, vcc_lo
	global_load_b32 v13, v[12:13], off
.LBB0_6:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	s_mov_b32 s20, 0
	s_mov_b32 s19, -1
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v13
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_7:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_lshl_add_u32 v3, s20, 2, v11
	v_lshl_add_u32 v12, s20, 3, v7
	v_cndmask_b32_e64 v15, 0, 1, s19
	s_mov_b32 s19, 0
	s_mov_b32 s20, 1
	ds_load_b32 v3, v3
	ds_load_b32 v14, v12 offset:16
	v_cmp_ne_u32_e32 vcc_lo, 1, v15
	s_waitcnt lgkmcnt(0)
	v_mad_u64_u32 v[12:13], null, v14, v3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v0, v12
	s_cbranch_vccz .LBB0_7
; %bb.8:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s18, s18, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s18, s4
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
	s_branch .LBB0_10
.LBB0_9:
	v_mov_b32_e32 v0, 0
.LBB0_10:                               ; %Flow76
	v_cmp_gt_i32_e32 vcc_lo, s16, v6
	v_cmp_gt_i32_e64 s2, s17, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_12
; %bb.11:
	s_load_b32 s0, s[0:1], 0x3c
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s1, s0, 16
	s_and_b32 s0, s0, 0xffff
	v_mad_u64_u32 v[2:3], null, s15, s1, v[1:2]
	s_mul_i32 s14, s14, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v1, v2, s17
	v_mov_b32_e32 v2, 0
	v_add3_u32 v1, s14, v5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s12, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s13, v2, vcc_lo
	global_store_b32 v[1:2], v0, off
.LBB0_12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15MatrixMulKerneliiiiiiPjS_S_
		.amdhsa_group_segment_fixed_size 32
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 16
		.amdhsa_next_free_sgpr 22
		.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	_Z15MatrixMulKerneliiiiiiPjS_S_, .Lfunc_end0-_Z15MatrixMulKerneliiiiiiPjS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 612
; NumSgprs: 24
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 32 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 24
; NumVGPRsForWavesPerEU: 16
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 32
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15MatrixMulKerneliiiiiiPjS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     24
    .sgpr_spill_count: 0
    .symbol:         _Z15MatrixMulKerneliiiiiiPjS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
