/* Program : To find the matrix multiplication of rectangular matrices without tiling
 * Author : Anant Shah
 * Date : 11-9-2018
 * Roll Number : EE16B105
 **/

#include<stdio.h>

#define ERROR_HANDLER(error_msg,line) error_handler(error_msg,line)
#define ROWS_M 4096
#define COLS_M 8192
#define ROWS_N 8192
#define COLS_N 16384
#define NUM_THREADS_X 16
#define NUM_THREADS_Y 16

void error_handler(cudaError_t error_msg,int line){
	/* Will terminate the program if an error caused due to a CUDA statement */
	if(error_msg!=cudaSuccess){
		printf("%s in %s at line %d",cudaGetErrorString(error_msg),__FILE__,line);
		exit(EXIT_FAILURE);
	}
}

void fill_matrix(double *mat,unsigned numRows,unsigned numCols){
	for(unsigned i=0;i<numRows;i++){
		for(unsigned j=0;j<numCols;j++){
			mat[i*numCols+j] = i*2.1f+j*3.2f;
		}
	}
}

void print_matrix_to_file(double *mat,unsigned numRows,unsigned numCols){
	const char 	*fname = "assignment2_out";
	FILE		*f = fopen(fname,"a");
	for(unsigned i=0;i<numRows;i++){
		for(unsigned j=0;j<numCols;j++){
			fprintf(f,"%4.4f ", mat[i*numCols+j]);
		}
		fprintf(f,"\n");
	}
	fclose(f);
}

__global__ void matrixMul(double *M,double *N,double *P,unsigned numRows_M,unsigned numCols_N,unsigned dim){
	/* Program : To find the rectangular matrix matrix multiplication 
	 * Shared Memory and Tiling has not been used in this kernel
	 * Parameters : M - Matrix M of size (numRows_M,dim)
	 * 		N - Matrix N of size (dim,numCols_N)
	 *		P - Output matrix (M*N)
	 *		numRows_M - Number of rows in the M matrix
	 *		numCols_N - Number of columns in the N matrix
	 *		dim - Numbor of columns in M = Number of rows in N
 	 */

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

	if(Row<numRows_M && Col<numCols_N){
		double	pSum = 0.0;
		for(int i=0;i<dim;i++){
			pSum += M[Row*dim+i]*N[i*numCols_N+Col];
		}
		P[Row*numCols_N+Col] = pSum;
	}
}

int main(int argc,char **argv){
	if(argc!=1){
		printf("error : Invalid number of arguments\n");
		exit(EXIT_FAILURE);
	}

	if(COLS_M!=ROWS_N){
		printf("Error : Invalid matrix dimensions");
		exit(EXIT_FAILURE);
	}

	/************************************* Variable Initialization **************************************/
	double		*h_M; /*Rectangular matrix M on the host */	
	double		*d_M; /*Rectangular matrix M on the device */
	size_t		size_M; /* Size of the rectangular matrix M  in bytes */
	double		*h_N; /* Rectangular matrix N on the host */
	double		*d_N; /* Rectangular matrix N on the device */
	size_t		size_N; /* Size of the matrix N in bytes */
	double		*h_P; /* Product M*N on the host */
	double		*d_P; /* Product M*N on the device */
	size_t		size_P; /* Size of the matrix P in bytes */
	cudaEvent_t	start,stop;

	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	size_M = sizeof(double)*ROWS_M*COLS_M;
	size_N = sizeof(double)*ROWS_N*COLS_N;
	size_P = sizeof(double)*ROWS_M*COLS_N;

	/************************************** Memory Allocation on the Host ********************************/
	h_M = (double *)malloc(size_M);
	h_N = (double *)malloc(size_N);
	h_P = (double *)malloc(size_P);
	
	/************************************** Initialize the matrices ***************************************/
	fill_matrix(h_M,ROWS_M,COLS_M);
	fill_matrix(h_N,ROWS_N,COLS_N);

	/************************************** Allocate memory on the device *********************************/
	ERROR_HANDLER(cudaMalloc((void **)&d_M,size_M),__LINE__);
	ERROR_HANDLER(cudaMalloc((void **)&d_N,size_N),__LINE__);
	ERROR_HANDLER(cudaMalloc((void **)&d_P,size_P),__LINE__);

	/************************************** Copy Matrices to the device ***********************************/

	ERROR_HANDLER(cudaMemcpy(d_M,h_M,size_M,cudaMemcpyHostToDevice),__LINE__);
	ERROR_HANDLER(cudaMemcpy(d_N,h_N,size_N,cudaMemcpyHostToDevice),__LINE__);

	/************************************** Kernel invocation *********************************************/

	dim3	threads(NUM_THREADS_X,NUM_THREADS_Y); /*2-D layout of the threads in a block */
	dim3	blocks((COLS_N+NUM_THREADS_X-1)/NUM_THREADS_X,(ROWS_M+NUM_THREADS_Y-1)/NUM_THREADS_Y); /*2-D layout of blocks in a grid */

	cudaEventRecord(start);	
	matrixMul<<<blocks,threads>>>(d_M,d_N,d_P,ROWS_M,COLS_N,COLS_M); /* The last parameter could have been <ROWS_N> */
	cudaEventRecord(stop);

	ERROR_HANDLER(cudaMemcpy(h_P,d_P,size_P,cudaMemcpyDeviceToHost),__LINE__);

	cudaEventSynchronize(stop);

	float run_time = 0.0;
	cudaEventElapsedTime(&run_time,start,stop);
	printf("Run-Time(seconds) : %.4f",run_time/1000);

	print_matrix_to_file(h_P,ROWS_M,COLS_N);
	
	/********************************** Free Allocated Memory ********************************************/

	cudaFree(d_M);
	cudaFree(d_N);
	cudaFree(d_P);
	free(h_M);
	free(h_N);
	free(h_P);
}	

	.file	"tmpxft_0023e4d9_00000000-6_ee16b105_6.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/anantshah200/CS6023/master/Assignment2/ee16b105_6.cu"
.LC1:
	.string	"%s in %s at line %d"
	.text
	.globl	_Z13error_handler9cudaErrori
	.type	_Z13error_handler9cudaErrori, @function
_Z13error_handler9cudaErrori:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	%esi, 12(%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r8d
	movl	$2, %edi
	leaq	.LC0(%rip), %rcx
	movq	%rax, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z13error_handler9cudaErrori, .-_Z13error_handler9cudaErrori
	.globl	_Z11fill_matrixPdjj
	.type	_Z11fill_matrixPdjj, @function
_Z11fill_matrixPdjj:
.LFB2028:
	.cfi_startproc
	endbr64
	movss	.LC2(%rip), %xmm2
	movss	.LC3(%rip), %xmm3
	movq	%rdi, %r8
	xorl	%ecx, %ecx
	xorl	%edi, %edi
.L9:
	cmpl	%esi, %ecx
	je	.L17
	xorl	%eax, %eax
	movl	%ecx, %r9d
.L15:
	cmpl	%edx, %eax
	je	.L18
	movl	%eax, %r11d
	cvtsi2ssq	%r9, %xmm0
	leal	(%rax,%rdi), %r10d
	incl	%eax
	cvtsi2ssq	%r11, %xmm1
	mulss	%xmm2, %xmm0
	mulss	%xmm3, %xmm1
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, (%r8,%r10,8)
	jmp	.L15
.L18:
	incl	%ecx
	addl	%edx, %edi
	jmp	.L9
.L17:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11fill_matrixPdjj, .-_Z11fill_matrixPdjj
	.section	.rodata.str1.1
.LC4:
	.string	"a"
.LC5:
	.string	"assignment2_out"
.LC6:
	.string	"%4.4f "
.LC7:
	.string	"\n"
	.text
	.globl	_Z20print_matrix_to_filePdjj
	.type	_Z20print_matrix_to_filePdjj, @function
_Z20print_matrix_to_filePdjj:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	leaq	.LC5(%rip), %rdi
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%esi, %ebx
	leaq	.LC4(%rip), %rsi
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	fopen@PLT
	movq	%rax, 8(%rsp)
.L20:
	cmpq	%rbx, %r12
	je	.L25
	movl	%r15d, %ebp
.L22:
	leal	(%r14,%r15), %eax
	cmpl	%eax, %ebp
	je	.L26
	movl	%ebp, %eax
	movq	8(%rsp), %rdi
	leaq	.LC6(%rip), %rdx
	incl	%ebp
	movsd	0(%r13,%rax,8), %xmm0
	movl	$2, %esi
	movb	$1, %al
	call	__fprintf_chk@PLT
	jmp	.L22
.L26:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	incq	%r12
	leaq	.LC7(%rip), %rdx
	movl	%ebp, %r15d
	call	__fprintf_chk@PLT
	jmp	.L20
.L25:
	movq	8(%rsp), %rdi
	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
	jmp	fclose@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z20print_matrix_to_filePdjj, .-_Z20print_matrix_to_filePdjj
	.globl	_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj
	.type	_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj, @function
_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj:
.LFB2055:
	.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	.L27
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z9matrixMulPdS_S_jjj(%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
.L27:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj, .-_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj
	.globl	_Z9matrixMulPdS_S_jjj
	.type	_Z9matrixMulPdS_S_jjj, @function
_Z9matrixMulPdS_S_jjj:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj
	.cfi_endproc
.LFE2056:
	.size	_Z9matrixMulPdS_S_jjj, .-_Z9matrixMulPdS_S_jjj
	.section	.rodata.str1.1
.LC8:
	.string	"error : Invalid number of arguments\n"
.LC11:
	.string	"Run-Time(seconds) : %.4f"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$80, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	decl	%edi
	je	.L33
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L33:
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$268435456, %edi
	call	malloc@PLT
	movl	$1073741824, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$8192, %edx
	movl	$4096, %esi
	movq	%r12, %rdi
	movq	%rax, %rbx
	call	_Z11fill_matrixPdjj
	movl	$16384, %edx
	movl	$8192, %esi
	movq	%rbp, %rdi
	call	_Z11fill_matrixPdjj
	leaq	8(%rsp), %rdi
	movl	$268435456, %esi
	call	cudaMalloc@PLT
	movl	$107, %esi
	movl	%eax, %edi
	call	_Z13error_handler9cudaErrori
	leaq	16(%rsp), %rdi
	movl	$1073741824, %esi
	call	cudaMalloc@PLT
	movl	$108, %esi
	movl	%eax, %edi
	call	_Z13error_handler9cudaErrori
	leaq	24(%rsp), %rdi
	movl	$536870912, %esi
	call	cudaMalloc@PLT
	movl	$109, %esi
	movl	%eax, %edi
	call	_Z13error_handler9cudaErrori
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$268435456, %edx
	call	cudaMemcpy@PLT
	movl	$113, %esi
	movl	%eax, %edi
	call	_Z13error_handler9cudaErrori
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$1073741824, %edx
	call	cudaMemcpy@PLT
	movl	$114, %esi
	movl	%eax, %edi
	call	_Z13error_handler9cudaErrori
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	movabsq	$68719476752, %rax
	movq	%rax, 48(%rsp)
	movl	$1073741825, %eax
	salq	$10, %rax
	movl	$1, 56(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	cudaEventRecord@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	48(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$8192, %r9d
	movl	$16384, %r8d
	movq	8(%rsp), %rdi
	movl	$4096, %ecx
	call	_Z35__device_stub__Z9matrixMulPdS_S_jjjPdS_S_jjj
.L34:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	movl	$125, %esi
	movl	%eax, %edi
	call	_Z13error_handler9cudaErrori
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	4(%rsp), %rdi
	movl	$0x00000000, 4(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movss	4(%rsp), %xmm0
	divss	.LC10(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$16384, %edx
	movl	$4096, %esi
	movq	%rbx, %rdi
	call	_Z20print_matrix_to_filePdjj
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$80, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z9matrixMulPdS_S_jjj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	_Z9matrixMulPdS_S_jjj(%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
.LFE2058:
	.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
.LC2:
	.long	1074161254
	.align 4
.LC3:
	.long	1078774989
	.align 4
.LC10:
	.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:

/* Program : To find the matrix multiplication of rectangular matrices without tiling
 * Author : Anant Shah
 * Date : 11-9-2018
 * Roll Number : EE16B105
 **/


#include <hip/hip_runtime.h>
#include<stdio.h>

#define ERROR_HANDLER(error_msg,line) error_handler(error_msg,line)
#define ROWS_M 4096
#define COLS_M 8192
#define ROWS_N 8192
#define COLS_N 16384
#define NUM_THREADS_X 16
#define NUM_THREADS_Y 16

void error_handler(hipError_t error_msg,int line){
	/* Will terminate the program if an error caused due to a CUDA statement */
	if(error_msg!=hipSuccess){
		printf("%s in %s at line %d",hipGetErrorString(error_msg),__FILE__,line);
		exit(EXIT_FAILURE);
	}
}

void fill_matrix(double *mat,unsigned numRows,unsigned numCols){
	for(unsigned i=0;i<numRows;i++){
		for(unsigned j=0;j<numCols;j++){
			mat[i*numCols+j] = i*2.1f+j*3.2f;
		}
	}
}

void print_matrix_to_file(double *mat,unsigned numRows,unsigned numCols){
	const char 	*fname = "assignment2_out";
	FILE		*f = fopen(fname,"a");
	for(unsigned i=0;i<numRows;i++){
		for(unsigned j=0;j<numCols;j++){
			fprintf(f,"%4.4f ", mat[i*numCols+j]);
		}
		fprintf(f,"\n");
	}
	fclose(f);
}

__global__ void matrixMul(double *M,double *N,double *P,unsigned numRows_M,unsigned numCols_N,unsigned dim){
	/* Program : To find the rectangular matrix matrix multiplication 
	 * Shared Memory and Tiling has not been used in this kernel
	 * Parameters : M - Matrix M of size (numRows_M,dim)
	 * 		N - Matrix N of size (dim,numCols_N)
	 *		P - Output matrix (M*N)
	 *		numRows_M - Number of rows in the M matrix
	 *		numCols_N - Number of columns in the N matrix
	 *		dim - Numbor of columns in M = Number of rows in N
 	 */

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

	if(Row<numRows_M && Col<numCols_N){
		double	pSum = 0.0;
		for(int i=0;i<dim;i++){
			pSum += M[Row*dim+i]*N[i*numCols_N+Col];
		}
		P[Row*numCols_N+Col] = pSum;
	}
}

int main(int argc,char **argv){
	if(argc!=1){
		printf("error : Invalid number of arguments\n");
		exit(EXIT_FAILURE);
	}

	if(COLS_M!=ROWS_N){
		printf("Error : Invalid matrix dimensions");
		exit(EXIT_FAILURE);
	}

	/************************************* Variable Initialization **************************************/
	double		*h_M; /*Rectangular matrix M on the host */	
	double		*d_M; /*Rectangular matrix M on the device */
	size_t		size_M; /* Size of the rectangular matrix M  in bytes */
	double		*h_N; /* Rectangular matrix N on the host */
	double		*d_N; /* Rectangular matrix N on the device */
	size_t		size_N; /* Size of the matrix N in bytes */
	double		*h_P; /* Product M*N on the host */
	double		*d_P; /* Product M*N on the device */
	size_t		size_P; /* Size of the matrix P in bytes */
	hipEvent_t	start,stop;

	hipEventCreate(&start);
	hipEventCreate(&stop);
	size_M = sizeof(double)*ROWS_M*COLS_M;
	size_N = sizeof(double)*ROWS_N*COLS_N;
	size_P = sizeof(double)*ROWS_M*COLS_N;

	/************************************** Memory Allocation on the Host ********************************/
	h_M = (double *)malloc(size_M);
	h_N = (double *)malloc(size_N);
	h_P = (double *)malloc(size_P);
	
	/************************************** Initialize the matrices ***************************************/
	fill_matrix(h_M,ROWS_M,COLS_M);
	fill_matrix(h_N,ROWS_N,COLS_N);

	/************************************** Allocate memory on the device *********************************/
	ERROR_HANDLER(hipMalloc((void **)&d_M,size_M),__LINE__);
	ERROR_HANDLER(hipMalloc((void **)&d_N,size_N),__LINE__);
	ERROR_HANDLER(hipMalloc((void **)&d_P,size_P),__LINE__);

	/************************************** Copy Matrices to the device ***********************************/

	ERROR_HANDLER(hipMemcpy(d_M,h_M,size_M,hipMemcpyHostToDevice),__LINE__);
	ERROR_HANDLER(hipMemcpy(d_N,h_N,size_N,hipMemcpyHostToDevice),__LINE__);

	/************************************** Kernel invocation *********************************************/

	dim3	threads(NUM_THREADS_X,NUM_THREADS_Y); /*2-D layout of the threads in a block */
	dim3	blocks((COLS_N+NUM_THREADS_X-1)/NUM_THREADS_X,(ROWS_M+NUM_THREADS_Y-1)/NUM_THREADS_Y); /*2-D layout of blocks in a grid */

	hipEventRecord(start);	
	matrixMul<<<blocks,threads>>>(d_M,d_N,d_P,ROWS_M,COLS_N,COLS_M); /* The last parameter could have been <ROWS_N> */
	hipEventRecord(stop);

	ERROR_HANDLER(hipMemcpy(h_P,d_P,size_P,hipMemcpyDeviceToHost),__LINE__);

	hipEventSynchronize(stop);

	float run_time = 0.0;
	hipEventElapsedTime(&run_time,start,stop);
	printf("Run-Time(seconds) : %.4f",run_time/1000);

	print_matrix_to_file(h_P,ROWS_M,COLS_N);
	
	/********************************** Free Allocated Memory ********************************************/

	hipFree(d_M);
	hipFree(d_N);
	hipFree(d_P);
	free(h_M);
	free(h_N);
	free(h_P);
}	

	.text
	.file	"ee16b105_6.hip"
	.globl	_Z13error_handler10hipError_ti  # -- Begin function _Z13error_handler10hipError_ti
	.type	_Z13error_handler10hipError_ti,@function
_Z13error_handler10hipError_ti:         # @_Z13error_handler10hipError_ti
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%esi, %ebx
	callq	hipGetErrorString
	movl	$.L.str, %edi
	movl	$.L.str.1, %edx
	movq	%rax, %rsi
	movl	%ebx, %ecx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z13error_handler10hipError_ti, .Lfunc_end0-_Z13error_handler10hipError_ti
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z11fill_matrixPdjj
.LCPI1_0:
	.long	0x40066666                      # float 2.0999999
.LCPI1_1:
	.long	0x404ccccd                      # float 3.20000005
	.text
	.globl	_Z11fill_matrixPdjj
	.type	_Z11fill_matrixPdjj,@function
_Z11fill_matrixPdjj:                    # @_Z11fill_matrixPdjj
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB1_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %eax
	xorl	%ecx, %ecx
	movss	.LCPI1_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI1_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorl	%r8d, %r8d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	testl	%edx, %edx
	je	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	%r8d, %r9d
	xorps	%xmm2, %xmm2
	cvtsi2ss	%r9, %xmm2
	mulss	%xmm0, %xmm2
	xorl	%r9d, %r9d
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r9d, %r10d
	xorps	%xmm3, %xmm3
	cvtsi2ss	%r10, %xmm3
	mulss	%xmm1, %xmm3
	addss	%xmm2, %xmm3
	cvtss2sd	%xmm3, %xmm3
	leal	(%rcx,%r9), %r10d
	movsd	%xmm3, (%rdi,%r10,8)
	incq	%r9
	cmpq	%r9, %rax
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incl	%r8d
	addq	%rax, %rcx
	cmpl	%esi, %r8d
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge15
	retq
.Lfunc_end1:
	.size	_Z11fill_matrixPdjj, .Lfunc_end1-_Z11fill_matrixPdjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z20print_matrix_to_filePdjj    # -- Begin function _Z20print_matrix_to_filePdjj
	.type	_Z20print_matrix_to_filePdjj,@function
_Z20print_matrix_to_filePdjj:           # @_Z20print_matrix_to_filePdjj
	.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
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r15
	movl	%ebp, 12(%rsp)                  # 4-byte Spill
	testl	%ebp, %ebp
	je	.LBB2_4
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %ecx
	movl	%ebx, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
	xorl	%ebp, %ebp
	movl	%ecx, 8(%rsp)                   # 4-byte Spill
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_5 Depth 2
	movq	16(%rsp), %r12                  # 8-byte Reload
	movl	%ebx, %r13d
	testl	%ecx, %ecx
	je	.LBB2_3
.LBB2_5:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r13d, %eax
	movsd	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.4, %esi
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	incl	%r13d
	decq	%r12
	jne	.LBB2_5
.LBB2_3:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	$10, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	incl	%ebp
	movl	8(%rsp), %ecx                   # 4-byte Reload
	addl	%ecx, %ebx
	cmpl	12(%rsp), %ebp                  # 4-byte Folded Reload
	jne	.LBB2_2
.LBB2_4:                                # %._crit_edge17
	movq	%r15, %rdi
	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
	jmp	fclose                          # TAILCALL
.Lfunc_end2:
	.size	_Z20print_matrix_to_filePdjj, .Lfunc_end2-_Z20print_matrix_to_filePdjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__matrixMulPdS_S_jjj # -- Begin function _Z24__device_stub__matrixMulPdS_S_jjj
	.type	_Z24__device_stub__matrixMulPdS_S_jjj,@function
_Z24__device_stub__matrixMulPdS_S_jjj:  # @_Z24__device_stub__matrixMulPdS_S_jjj
	.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	$_Z9matrixMulPdS_S_jjj, %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_end3:
	.size	_Z24__device_stub__matrixMulPdS_S_jjj, .Lfunc_end3-_Z24__device_stub__matrixMulPdS_S_jjj
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x40066666                      # float 2.0999999
.LCPI4_1:
	.long	0x404ccccd                      # float 3.20000005
.LCPI4_2:
	.long	0x447a0000                      # float 1000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$1, %edi
	jne	.LBB4_12
# %bb.1:
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movl	$268435456, %edi                # imm = 0x10000000
	callq	malloc
	movq	%rax, %rbx
	movl	$1073741824, %edi               # imm = 0x40000000
	callq	malloc
	movq	%rax, %r14
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r15
	xorl	%eax, %eax
	movss	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movq	%rbx, %rcx
.LBB4_2:                                # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_3 Depth 2
	movl	%eax, %edx
	xorps	%xmm2, %xmm2
	cvtsi2ss	%rdx, %xmm2
	mulss	%xmm0, %xmm2
	xorl	%edx, %edx
.LBB4_3:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edx, %esi
	xorps	%xmm3, %xmm3
	cvtsi2ss	%rsi, %xmm3
	mulss	%xmm1, %xmm3
	addss	%xmm2, %xmm3
	cvtss2sd	%xmm3, %xmm3
	movsd	%xmm3, (%rcx,%rdx,8)
	incq	%rdx
	cmpq	$8192, %rdx                     # imm = 0x2000
	jne	.LBB4_3
# %bb.4:                                # %._crit_edge.i
                                        #   in Loop: Header=BB4_2 Depth=1
	incl	%eax
	addq	$65536, %rcx                    # imm = 0x10000
	cmpl	$4096, %eax                     # imm = 0x1000
	jne	.LBB4_2
# %bb.5:                                # %.preheader.i26.preheader
	xorl	%eax, %eax
	movq	%r14, %rcx
.LBB4_6:                                # %.preheader.i26
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_7 Depth 2
	movl	%eax, %edx
	xorps	%xmm2, %xmm2
	cvtsi2ss	%rdx, %xmm2
	mulss	%xmm0, %xmm2
	xorl	%edx, %edx
.LBB4_7:                                #   Parent Loop BB4_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edx, %esi
	xorps	%xmm3, %xmm3
	cvtsi2ss	%rsi, %xmm3
	mulss	%xmm1, %xmm3
	addss	%xmm2, %xmm3
	cvtss2sd	%xmm3, %xmm3
	movsd	%xmm3, (%rcx,%rdx,8)
	incq	%rdx
	cmpq	$16384, %rdx                    # imm = 0x4000
	jne	.LBB4_7
# %bb.8:                                # %._crit_edge.i31
                                        #   in Loop: Header=BB4_6 Depth=1
	incl	%eax
	addq	$131072, %rcx                   # imm = 0x20000
	cmpl	$8192, %eax                     # imm = 0x2000
	jne	.LBB4_6
# %bb.9:                                # %_Z11fill_matrixPdjj.exit33
	leaq	32(%rsp), %r13
	movl	$268435456, %esi                # imm = 0x10000000
	movq	%r13, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$109, %esi
	callq	_Z13error_handler10hipError_ti
	leaq	24(%rsp), %r12
	movl	$1073741824, %esi               # imm = 0x40000000
	movq	%r12, %rdi
	callq	hipMalloc
	movl	%eax, %edi
	movl	$110, %esi
	callq	_Z13error_handler10hipError_ti
	leaq	8(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	movl	%eax, %edi
	movl	$111, %esi
	callq	_Z13error_handler10hipError_ti
	movq	(%r13), %rdi
	movl	$268435456, %edx                # imm = 0x10000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$115, %esi
	callq	_Z13error_handler10hipError_ti
	movq	(%r12), %rdi
	movl	$1073741824, %edx               # imm = 0x40000000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$116, %esi
	callq	_Z13error_handler10hipError_ti
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$1099511628800, %rdi            # imm = 0x10000000400
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_11
# %bb.10:
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$4096, %ecx                     # imm = 0x1000
	movl	$16384, %r8d                    # imm = 0x4000
	movl	$8192, %r9d                     # imm = 0x2000
	callq	_Z24__device_stub__matrixMulPdS_S_jjj
.LBB4_11:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	movl	$127, %esi
	callq	_Z13error_handler10hipError_ti
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	44(%rsp), %r12
	movl	$0, (%r12)
	movq	16(%rsp), %rsi
	movq	(%rsp), %rdx
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	movss	(%r12), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI4_2(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movq	%r15, %rdi
	movl	$4096, %esi                     # imm = 0x1000
	movl	$16384, %edx                    # imm = 0x4000
	callq	_Z20print_matrix_to_filePdjj
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB4_12:
	.cfi_def_cfa_offset 96
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	main, .Lfunc_end4-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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9matrixMulPdS_S_jjj, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s in %s at line %d"
	.size	.L.str, 20

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/anantshah200/CS6023/master/Assignment2/ee16b105_6.hip"
	.size	.L.str.1, 116

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"assignment2_out"
	.size	.L.str.2, 16

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"a"
	.size	.L.str.3, 2

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%4.4f "
	.size	.L.str.4, 7

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

	.type	.L.str.7,@object                # @.str.7
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.7:
	.asciz	"Run-Time(seconds) : %.4f"
	.size	.L.str.7, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9matrixMulPdS_S_jjj"
	.size	.L__unnamed_1, 22

	.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	"error : Invalid number of arguments"
	.size	.Lstr, 36

	.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 _Z24__device_stub__matrixMulPdS_S_jjj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9matrixMulPdS_S_jjj
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9matrixMulPdS_S_jjj   ; -- Begin function _Z9matrixMulPdS_S_jjj
	.globl	_Z9matrixMulPdS_S_jjj
	.p2align	8
	.type	_Z9matrixMulPdS_S_jjj,@function
_Z9matrixMulPdS_S_jjj:                  ; @_Z9matrixMulPdS_S_jjj
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_bfe_u32 v2, v0, 10, 10
	v_and_b32_e32 v3, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[0:1], null, s15, s3, v[2:3]
	v_mad_u64_u32 v[1:2], null, s14, s2, v[3:4]
	v_cmp_gt_u32_e32 vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_u32_e64 s2, s5, v1
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_cmp_eq_u32 s6, 0
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	v_mul_lo_u32 v4, v0, s6
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v5, 0
	v_dual_mov_b32 v3, 0 :: v_dual_mov_b32 v6, v1
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_mov_b32_e32 v7, v5
	v_lshlrev_b64 v[8:9], 3, v[4:5]
	v_add_nc_u32_e32 v4, 1, v4
	s_add_i32 s6, s6, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s6, 0
	v_lshlrev_b64 v[10:11], 3, v[6:7]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v7, vcc_lo, s8, v8
	v_add_co_ci_u32_e32 v8, vcc_lo, s9, v9, vcc_lo
	v_add_nc_u32_e32 v6, s5, v6
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v9, vcc_lo, s10, v10
	v_add_co_ci_u32_e32 v10, vcc_lo, s11, v11, vcc_lo
	global_load_b64 v[7:8], v[7:8], off
	global_load_b64 v[9:10], v[9:10], off
	s_waitcnt vmcnt(0)
	v_fma_f64 v[2:3], v[7:8], v[9:10], v[2:3]
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v2, 0
	v_mov_b32_e32 v3, 0
.LBB0_5:                                ; %Flow54
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[4:5], null, v0, s5, v[1:2]
	v_mov_b32_e32 v5, 0
	v_lshlrev_b64 v[0:1], 3, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b64 v[0:1], v[2:3], off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9matrixMulPdS_S_jjj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 12
		.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	_Z9matrixMulPdS_S_jjj, .Lfunc_end0-_Z9matrixMulPdS_S_jjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; 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
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9matrixMulPdS_S_jjj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9matrixMulPdS_S_jjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
