#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define DEFAULT_ROW  16384
#define DEFAULT_COL  16384
// time stamp function in seconds
double getTimeStamp() {
	struct timeval tv ;
	gettimeofday( &tv, NULL ) ;
	return (double) tv.tv_usec/1000000 + tv.tv_sec ;
}
// host side matrix addition
void h_addmat(float *A, float *B, float *C, int nx, int ny){ 
	float* ia = A, *ib =B, *ic =C;
	for (int iy =0; iy<ny; iy++){
		for (int ix =0; ix<nx; ix++){
			
			ic[ix] = ia[ix] + ib[ix];
			//if (iy*nx + ix == 67133440) printf("the addition in host: %.6f + %.6f = %.6f\n",ia[ix],ib[ix],ic[ix]);
			
		}
		ia += nx;
		ib += nx;
		ic += nx;
	}
 }

//host side matrix comparison
int h_compareResult(float *h_C, float *d_C, int noElems){ 
	float *host_c = h_C,*device_c = d_C;
	for (int i =0; i<noElems; i++){
		if (*(host_c) != *(device_c)){
#ifdef DEBUG

			printf("the i = %d\n", i);
			printf("the data of CPU is %.6f\n", *(host_c));
			printf("the data of GPU is %.6f\n", *(device_c));

#endif
			return 1;
		} 
		host_c++;
		device_c++;
	}
	return 0;
 }

// device-side matrix addition
__global__ void f_addmat( float *A, float *B, float *C, int nx, int ny ){
	// kernel code might look something like this
	// but you may want to pad the matrices and index into them accordingly
	int ix = threadIdx.x + blockIdx.x*blockDim.x ;
	int iy = threadIdx.y + blockIdx.y*blockDim.y ;
	int idx = iy*nx + ix ;
	if( (ix<nx) && (iy<ny) )
	C[idx] = A[idx] + B[idx] ;
	//printf("the addition at idx = %d in device: %.6f + %.6f = %.6f\n",idx, A[idx],B[idx],C[idx]);
}

// device-side matrix addition
__global__ void f_addmat4( float *A, float *B, float *C, int nx, int ny, int mode_number ){
	// kernel code might look something like this
	// but you may want to pad the matrices and index into them accordingly
	int ix = threadIdx.x + blockIdx.x*blockDim.x ;
	int iy = threadIdx.y + blockIdx.y*blockDim.y ;
	int idx = iy*nx + ix ;
	if( (ix<nx) && (iy<ny) ){
		int i;
		int index;
		for (i = 0; i< 4; i++){

			// compute 4 element in this thread.
			index = idx + i * mode_number;
			//if (index >1000 && i == 3) printf("the addition when idenx = %d in device: %.6f + %.6f = %.6f\n",index,A[idx],B[idx],C[idx]);
			C[index] = A[index] + B[index] ;
		}
	}
	
	//if (idx == 0) printf("the addition in device: %.6f + %.6f = %.6f\n",A[idx],B[idx],C[idx]);
}
/*
void initData(float* add, int new_nx, int block_x, int nx, int ny){
	int row,col;
	float a = 5.0;
	for (row=0; row< ny; row++){
		for (col=0; col< new_nx; col++){
			if (row == ny -1){	// last block
				if (col%8 < (8 - nx%8)) *(add++) = ((float)rand()/(float)(RAND_MAX)) * a;
				else *(add++) = 0;
			}
			else{
				if (col%8 < block_x ) *(add++) = ((float)rand()/(float)(RAND_MAX)) * a;
				else *(add++) = 0;
			}
		}
	}

}
// host side matrix addition
void h_addmat(float *A, float *B, float *C, int nx, int ny, int new_nx, int block_x){ 
	float* ia = A, *ib =B, *ic =C;
	for (int iy =0; iy<ny; iy++){
		for (int ix =0; ix<new_nx; ix++){
			if (iy== ny -1){	// last block
				if (ix%8 < (8 - nx%8)) *(ic++) = *(ia++) + *(ib++);
				else{
					ia++;
					ib++;
				}
			}
			else{
				if (ix%8 < block_x ) *(ic++) = *(ia++) + *(ib++);
				else{
					ia++;
					ib++;
				}
			}

			//if (iy*nx + ix == 67133440) printf("the addition in host: %.6f + %.6f = %.6f\n",ia[ix],ib[ix],ic[ix]);
			
		}
	}
 }
void removePading(float* h_dC, float* h_temp_dC, int nx, int ny, int new_nx, int block_x){
	int row,col;
	int count=0;
	float *r_padding = h_temp_dC, *r = h_dC;
	for (row=0; row< ny; row++){
		for (col=0; col< new_nx; col++){
			if (row == ny -1){	// last block
				if (col%8 < (8 - nx%8)){
					r[count] = r_padding[row * new_nx + col];
					count ++;
				}
			}
			else{
				if (col%8 < block_x ){
					r[count] = r_padding[row * new_nx + col];
					count ++;
				}
			}
			
		}
	}

}
*/
void initData(float* add, int noElems){
	int i;
	float a = 5.0;
	for (i=0; i< noElems; i++){
		*(add++) = ((float)rand()/(float)(RAND_MAX)) * a;
	}

}


int main(int argc, char* argv[]){

	if(argc != 3){
		printf("Error: wrong number of argument\n");
		exit(0);
	}

	int nx = atoi(argv[1]);
	int ny = atoi(argv[2]);

	// do the input argument check.
	if(nx<=0 || ny<= 0){
		printf("Error: input arguement can't be zero or negative\n");
		exit(0);
	}

	int noElems = nx * ny;
	int bytes = noElems * sizeof(float);
#ifdef DEBUG
	printf("the input row # is %d\n",nx);
	printf("the input col # is %d\n",ny);
	printf("the noElems is %d\n",noElems);
	printf("the bytes is %d\n",bytes);
#endif
	// according to input dimension and GPU limitation, calculate the minmum ny;
	int block_x, block_y, min_blocky = 1;
	while ((ny + min_blocky-1)/min_blocky > 65535){
		min_blocky ++;
	}
	block_y = min_blocky;

	// according to minimum block_y and max of 1024 threads per block, calculate the maximum nx;
	block_x = 1024 / block_y;


	// alloc memeory host-side
	float *h_A;
	float *h_B;
	float *h_dC;
	float *h_hC = (float*) malloc(bytes); // host result
	
	//pin memeory in host side
	cudaHostAlloc((void**)&h_A, bytes, 0);	
	cudaHostAlloc((void**)&h_B, bytes, 0);	
	cudaHostAlloc((void**)&h_dC, bytes, 0);
	
	// init matrices with random data
	initData(h_A, noElems);
	initData(h_B, noElems);
	
	//alloc memeory device-side
	float *d_A, *d_B, *d_C;
	cudaMalloc( &d_A, bytes);
	cudaMalloc( &d_B, bytes);
	cudaMalloc( &d_C, bytes);
	
	// getting host side result
	h_addmat( h_A, h_B, h_hC, nx, ny) ;

	
	int i;
	// calculating minimum bytes each Stream should take according to the calculated block_y
	
	int minimumBytesPerStream = nx * sizeof(float) * 4 * block_y;	
	while (minimumBytesPerStream < 4194304*16){	// 4194304 is when 1024(thread) * 2 (blocks/SMS) * 16 (SMS) * 4 (sizeof(Float)) * 2 (Two float number required for addition), we want data transfer is multiple of this number
		minimumBytesPerStream = minimumBytesPerStream * 2;
	}
	// yPerStream is mutiple of 4 so every thread can process 4 different y in one stream
	int yPerStream = minimumBytesPerStream/ nx;	
	// calculating bytes each Stream according to the calculated yPerStream
	int bytesPerStream = nx * sizeof(float) * yPerStream;
	// calculating number of Streams according to the calculated bytesPerStream
	int NSTREAMS = bytes/bytesPerStream;
	// if there is data remain where they are not multiple of bytesPerStream
	int remainBytes = bytes%bytesPerStream;
	// initialize the stream array
	cudaStream_t stream[NSTREAMS+1];
	// input the pre-calculated block size and calculate the grid size
	dim3 block( block_x, block_y ) ; // you will want to configure this
	dim3 grid( (nx + block.x-1)/block.x, (bytesPerStream/(sizeof(float) * nx) + block.y-1)/block.y ) ;

#ifdef DEBUG
	printf("the final bytesPerStream is = %d\n", bytesPerStream);

	printf("the remainBytes is = %d\n", remainBytes);
	printf("the final block size is x = %d and y = %d \n",block_x, block_y);
	printf("the final grid dimension is x = %d and y = %d \n",(nx + block_x-1)/block_x, (yPerStream + block.y-1)/block.y );
#endif
	// initialize the event for calculating accumulate kernel time.
	// NOTE: if we don't need to calculating the accumulate kernel time, the total time is at least 10% faster.
	// But  kernel time is important to show. 
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	double timeStampA = getTimeStamp() ;
	double timeStampB= getTimeStamp() ;
	float milliseconds;
	float AccumulateKernelTime = 0;
	for(i = 1; i <=NSTREAMS; i++ ){
		// create stream
		cudaStreamCreate(&stream[i]);
		//calculating offset
		int offset = (i-1) * bytesPerStream/4;
		//Asynch copy data from host to device 
		cudaMemcpyAsync(&d_A[offset],&h_A[offset],bytesPerStream, cudaMemcpyHostToDevice, stream[i]);
		cudaMemcpyAsync(&d_B[offset],&h_B[offset],bytesPerStream, cudaMemcpyHostToDevice, stream[i]);
		//record the timestamp before kernel invoke
		cudaEventRecord(start);
		//invoke kernel
		f_addmat4<<<grid, block,0,stream[i]>>>( &d_A[offset], &d_B[offset], &d_C[offset], nx, bytesPerStream/(4* sizeof(float) * nx), bytesPerStream/(4* sizeof(float)) ) ;
		//record the timestamp before kernel invoke		
		cudaEventRecord(stop);	
		cudaEventSynchronize(stop);
		// write down the difference
		cudaEventElapsedTime(&milliseconds, start, stop);
		// add this time to accumulated time
		AccumulateKernelTime += milliseconds/1000;
		//Asynch copy data from device back to host 
		cudaMemcpyAsync(&h_dC[offset],&d_C[offset],bytesPerStream, cudaMemcpyDeviceToHost,stream[i]);
	}
	// if there is remaining byte, we do the process one more time
	if(remainBytes != 0){
		int remainEle = remainBytes/4;
		cudaStream_t last;
		cudaStreamCreate(&last);
		int offset = NSTREAMS * bytesPerStream/4;
		cudaMemcpyAsync(&d_A[offset],&h_A[offset],remainBytes, cudaMemcpyHostToDevice, last);
		cudaMemcpyAsync(&d_B[offset],&h_B[offset],remainBytes, cudaMemcpyHostToDevice, last);
		dim3 grid( (nx + block.x-1)/block.x, (remainEle/nx + block.y-1)/block.y ) ;
		cudaEventRecord(start);
		f_addmat<<<grid, block,0,last>>>( &d_A[offset], &d_B[offset], &d_C[offset], nx, remainEle/nx ) ;
		cudaEventRecord(stop);	
		cudaEventElapsedTime(&milliseconds, start, stop);
		AccumulateKernelTime += milliseconds/1000;
		cudaMemcpyAsync(&h_dC[offset],&d_C[offset],remainBytes, cudaMemcpyDeviceToHost,last);
		cudaStreamSynchronize(last);
	}

	double timeStampC = getTimeStamp() ;
	//wait for all stream finish the job
	for(i = 1; i <=NSTREAMS; i++ ){
		cudaStreamSynchronize(stream[i]);
	}
	
	cudaDeviceSynchronize() ;
	//time where device side jobs have been finished
	double timeStampD = getTimeStamp() ;

	// free some Host and GPU resources that are not needed anymore
	cudaFreeHost(h_A);
	cudaFreeHost(h_B);
	cudaFree( d_A ) ; cudaFree( d_B ) ; cudaFree( d_C ) ;

#ifdef DEBUG
	float * ptr;
	int n;
	ptr = h_dC;
	n = 0;
	ptr = ptr + n;
	printf("the data of GPU at index %d before comparison is %.6f\n", n,*(ptr));
#endif	
	//h_compareResult compares the result computed by host and result computed by device
	//if any element is not same, the function will return 1, otherwise print out the time 
	if (h_compareResult(h_hC,h_dC,noElems) == 1){
			printf("Error: the two results don't match\n");
	}
	else{
		//printf(" %.6f  %.6f %.6f %.6f\n",timeStampD - timeStampA,timeStampB - timeStampA, AccumulateKernelTime, timeStampD - timeStampC  );
		printf(" %.6f  %.6f %.6f %.6f\n",timeStampD - timeStampA,timeStampB - timeStampA, AccumulateKernelTime, timeStampD - timeStampC  );
	}
	// free rest Host Side Resources
	cudaFreeHost(h_dC);
	free(h_hC);
	cudaDeviceReset();
}

	.file	"tmpxft_002802ec_00000000-6_var4.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12getTimeStampv
	.type	_Z12getTimeStampv, @function
_Z12getTimeStampv:
.LFB2027:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cvtsi2sdq	8(%rsp), %xmm1
	cvtsi2sdq	16(%rsp), %xmm0
	divsd	.LC0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12getTimeStampv, .-_Z12getTimeStampv
	.globl	_Z8h_addmatPfS_S_ii
	.type	_Z8h_addmatPfS_S_ii, @function
_Z8h_addmatPfS_S_ii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%ecx, %r11
	movq	%rsi, %r9
	movq	%rdx, %r10
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	salq	$2, %r11
	xorl	%edx, %edx
	xorl	%esi, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
.L7:
	leaq	(%r10,%rdx), %r12
	leaq	(%r9,%rdx), %rbp
	leaq	(%rdi,%rdx), %rbx
	cmpl	%r8d, %esi
	jge	.L12
	xorl	%eax, %eax
.L9:
	cmpl	%eax, %ecx
	jle	.L13
	movss	(%rbx,%rax,4), %xmm0
	addss	0(%rbp,%rax,4), %xmm0
	movss	%xmm0, (%r12,%rax,4)
	incq	%rax
	jmp	.L9
.L13:
	incl	%esi
	addq	%r11, %rdx
	jmp	.L7
.L12:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z8h_addmatPfS_S_ii, .-_Z8h_addmatPfS_S_ii
	.globl	_Z15h_compareResultPfS_i
	.type	_Z15h_compareResultPfS_i, @function
_Z15h_compareResultPfS_i:
.LFB2029:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L15:
	cmpl	%eax, %edx
	jle	.L20
	movss	(%rdi,%rax,4), %xmm0
	incq	%rax
	ucomiss	-4(%rsi,%rax,4), %xmm0
	jp	.L19
	je	.L15
	jmp	.L19
.L20:
	xorl	%eax, %eax
	ret
.L19:
	movl	$1, %eax
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z15h_compareResultPfS_i, .-_Z15h_compareResultPfS_i
	.globl	_Z8initDataPfi
	.type	_Z8initDataPfi, @function
_Z8initDataPfi:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L22:
	cmpl	%ebx, %ebp
	jle	.L25
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC1(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L22
.L25:
	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	_Z8initDataPfi, .-_Z8initDataPfi
	.globl	_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii
	.type	_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii, @function
_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z8f_addmatPfS_S_ii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L26:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii, .-_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii
	.globl	_Z8f_addmatPfS_S_ii
	.type	_Z8f_addmatPfS_S_ii, @function
_Z8f_addmatPfS_S_ii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii
	.cfi_endproc
.LFE2057:
	.size	_Z8f_addmatPfS_S_ii, .-_Z8f_addmatPfS_S_ii
	.globl	_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii
	.type	_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii, @function
_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii:
.LFB2058:
	.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	.L31
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z9f_addmat4PfS_S_iii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L31:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii, .-_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii
	.globl	_Z9f_addmat4PfS_S_iii
	.type	_Z9f_addmat4PfS_S_iii, @function
_Z9f_addmat4PfS_S_iii:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2059:
	.size	_Z9f_addmat4PfS_S_iii, .-_Z9f_addmat4PfS_S_iii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"Error: wrong number of argument\n"
.LC5:
	.string	"Error: input arguement can't be zero or negative\n"
.LC7:
	.string	"Error: the two results don't match\n"
.LC8:
	.string	" %.6f  %.6f %.6f %.6f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$232, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	je	.L37
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	jmp	.L65
.L37:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %r12d
	call	atoi@PLT
	movl	%eax, %r8d
	testl	%r12d, %r12d
	jle	.L57
	testl	%eax, %eax
	jg	.L38
.L57:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
.L65:
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L38:
	movl	%r12d, %eax
	movl	$1, %r13d
	leal	-1(%r8), %ecx
	imull	%r8d, %eax
	movl	%eax, -192(%rbp)
	leal	0(,%rax,4), %r15d
.L40:
	leal	(%rcx,%r13), %eax
	cltd
	idivl	%r13d
	cmpl	$65535, %eax
	jle	.L66
	incl	%r13d
	jmp	.L40
.L66:
	movl	$1024, %eax
	movslq	%r15d, %rbx
	movl	%r8d, -184(%rbp)
	cltd
	movq	%rbx, %rdi
	idivl	%r13d
	movl	%eax, %r14d
	call	malloc@PLT
	movq	%rbx, %rsi
	leaq	-168(%rbp), %rdi
	xorl	%edx, %edx
	movq	%rax, -216(%rbp)
	call	cudaHostAlloc@PLT
	movq	%rbx, %rsi
	leaq	-160(%rbp), %rdi
	xorl	%edx, %edx
	call	cudaHostAlloc@PLT
	xorl	%edx, %edx
	movq	%rbx, %rsi
	leaq	-152(%rbp), %rdi
	call	cudaHostAlloc@PLT
	movl	-192(%rbp), %esi
	movq	-168(%rbp), %rdi
	call	_Z8initDataPfi
	movl	-192(%rbp), %esi
	movq	-160(%rbp), %rdi
	call	_Z8initDataPfi
	movq	%rbx, %rsi
	leaq	-144(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	%rbx, %rsi
	leaq	-136(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	%rbx, %rsi
	leaq	-128(%rbp), %rdi
	movslq	%r12d, %rbx
	call	cudaMalloc@PLT
	movl	-184(%rbp), %r8d
	movl	%r12d, %ecx
	movq	-216(%rbp), %rdx
	movq	-160(%rbp), %rsi
	movq	-168(%rbp), %rdi
	call	_Z8h_addmatPfS_S_ii
	movl	%r12d, %eax
	imull	%r13d, %eax
	sall	$4, %eax
.L42:
	cmpl	$67108863, %eax
	jg	.L67
	addl	%eax, %eax
	jmp	.L42
.L67:
	cltd
	movq	%rsp, %rcx
	idivl	%r12d
	imull	%r12d, %eax
	sall	$2, %eax
	movl	%eax, -200(%rbp)
	movl	%r15d, %eax
	cltd
	idivl	-200(%rbp)
	movl	%eax, -204(%rbp)
	incl	%eax
	cltq
	movl	%edx, -208(%rbp)
	leaq	15(,%rax,8), %rdx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L44:
	cmpq	%rcx, %rsp
	je	.L45
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L44
.L45:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L46
	orq	$0, -8(%rsp,%rax)
.L46:
	movslq	-200(%rbp), %rax
	xorl	%edx, %edx
	leaq	0(,%rbx,4), %rdi
	movslq	%r13d, %rcx
	movq	%rsp, -240(%rbp)
	salq	$4, %rbx
	movq	%rax, -184(%rbp)
	leal	-1(%r12,%r14), %eax
	divl	%r14d
	movl	$1, -84(%rbp)
	movl	$1, -72(%rbp)
	xorl	%edx, %edx
	movl	%eax, -244(%rbp)
	movl	%eax, -80(%rbp)
	movq	-184(%rbp), %rax
	divq	%rdi
	xorl	%edx, %edx
	leaq	-120(%rbp), %rdi
	leaq	-1(%rcx,%rax), %rax
	divq	%rcx
	movl	%eax, -76(%rbp)
	call	cudaEventCreate@PLT
	leaq	-112(%rbp), %rdi
	call	cudaEventCreate@PLT
	call	_Z12getTimeStampv
	movsd	%xmm0, -232(%rbp)
	call	_Z12getTimeStampv
	movq	-184(%rbp), %rax
	movq	%rbx, -256(%rbp)
	movl	$0x00000000, -188(%rbp)
	shrq	$4, %rax
	movsd	%xmm0, -264(%rbp)
	movl	%eax, -248(%rbp)
	movq	-240(%rbp), %rax
	movl	$1, -220(%rbp)
	leaq	8(%rax), %r15
	xorl	%eax, %eax
	movl	%eax, -224(%rbp)
.L47:
	movl	-204(%rbp), %ecx
	cmpl	%ecx, -220(%rbp)
	jg	.L68
	movq	%r15, %rdi
	call	cudaStreamCreate@PLT
	movl	-224(%rbp), %eax
	movq	(%r15), %r8
	movl	$4, %ecx
	movq	-168(%rbp), %rsi
	movq	-144(%rbp), %rdi
	cltd
	idivl	%ecx
	movq	-184(%rbp), %rdx
	movl	$1, %ecx
	cltq
	leaq	0(,%rax,4), %rbx
	addq	%rbx, %rsi
	addq	%rbx, %rdi
	call	cudaMemcpyAsync@PLT
	movq	-160(%rbp), %rsi
	movq	(%r15), %r8
	movl	$1, %ecx
	movq	-136(%rbp), %rdi
	movq	-184(%rbp), %rdx
	addq	%rbx, %rsi
	addq	%rbx, %rdi
	call	cudaMemcpyAsync@PLT
	movq	-120(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%r14d, -92(%rbp)
	movl	-84(%rbp), %ecx
	xorl	%r8d, %r8d
	movq	(%r15), %r9
	movq	-80(%rbp), %rdi
	movl	%r13d, -88(%rbp)
	movl	-72(%rbp), %esi
	movq	-92(%rbp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L48
	movq	-184(%rbp), %rax
	xorl	%edx, %edx
	movq	-136(%rbp), %rsi
	movl	%r12d, %ecx
	movq	-144(%rbp), %rdi
	movl	-248(%rbp), %r9d
	divq	-256(%rbp)
	movq	-128(%rbp), %rdx
	addq	%rbx, %rsi
	addq	%rbx, %rdx
	addq	%rbx, %rdi
	movl	%eax, %r8d
	call	_Z35__device_stub__Z9f_addmat4PfS_S_iiiPfS_S_iii
.L48:
	movq	-112(%rbp), %rdi
	xorl	%esi, %esi
	addq	$8, %r15
	call	cudaEventRecord@PLT
	movq	-112(%rbp), %rdi
	call	cudaEventSynchronize@PLT
	movq	-112(%rbp), %rdx
	movq	-120(%rbp), %rsi
	leaq	-172(%rbp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	-128(%rbp), %rsi
	movq	-8(%r15), %r8
	movl	$2, %ecx
	movss	-172(%rbp), %xmm0
	divss	.LC6(%rip), %xmm0
	addss	-188(%rbp), %xmm0
	addq	%rbx, %rsi
	movq	-184(%rbp), %rdx
	addq	-152(%rbp), %rbx
	movq	%rbx, %rdi
	movss	%xmm0, -188(%rbp)
	call	cudaMemcpyAsync@PLT
	movl	-200(%rbp), %ecx
	incl	-220(%rbp)
	addl	%ecx, -224(%rbp)
	jmp	.L47
.L68:
	cmpl	$0, -208(%rbp)
	je	.L50
	leaq	-104(%rbp), %rdi
	movl	$4, %ebx
	call	cudaStreamCreate@PLT
	movslq	-208(%rbp), %rax
	movq	-104(%rbp), %r8
	movl	-204(%rbp), %ecx
	movq	-168(%rbp), %rsi
	movq	%rax, -184(%rbp)
	movl	-200(%rbp), %eax
	movq	-144(%rbp), %rdi
	imull	%ecx, %eax
	movl	$1, %ecx
	cltd
	idivl	%ebx
	movq	-184(%rbp), %rdx
	cltq
	leaq	0(,%rax,4), %r15
	addq	%r15, %rsi
	addq	%r15, %rdi
	call	cudaMemcpyAsync@PLT
	movq	-160(%rbp), %rsi
	movq	-104(%rbp), %r8
	movl	$1, %ecx
	movq	-136(%rbp), %rdi
	movq	-184(%rbp), %rdx
	addq	%r15, %rsi
	addq	%r15, %rdi
	call	cudaMemcpyAsync@PLT
	movl	-208(%rbp), %eax
	movq	-120(%rbp), %rdi
	xorl	%esi, %esi
	movl	$1, -60(%rbp)
	cltd
	idivl	%ebx
	cltd
	idivl	%r12d
	xorl	%edx, %edx
	movl	%eax, %ebx
	movl	-244(%rbp), %eax
	movl	%eax, -68(%rbp)
	leal	-1(%r13,%rbx), %eax
	divl	%r13d
	movl	%eax, -64(%rbp)
	call	cudaEventRecord@PLT
	movl	%r14d, -92(%rbp)
	movl	-84(%rbp), %ecx
	xorl	%r8d, %r8d
	movq	-104(%rbp), %r9
	movq	-68(%rbp), %rdi
	movl	%r13d, -88(%rbp)
	movl	-60(%rbp), %esi
	movq	-92(%rbp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L51
	movq	-128(%rbp), %rdx
	movq	-136(%rbp), %rsi
	movl	%ebx, %r8d
	movl	%r12d, %ecx
	movq	-144(%rbp), %rdi
	addq	%r15, %rdx
	addq	%r15, %rsi
	addq	%r15, %rdi
	call	_Z33__device_stub__Z8f_addmatPfS_S_iiPfS_S_ii
.L51:
	movq	-112(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-112(%rbp), %rdx
	movq	-120(%rbp), %rsi
	leaq	-172(%rbp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	-128(%rbp), %rsi
	movq	-152(%rbp), %rdi
	movl	$2, %ecx
	movss	-172(%rbp), %xmm0
	divss	.LC6(%rip), %xmm0
	addss	-188(%rbp), %xmm0
	movq	-104(%rbp), %r8
	movq	-184(%rbp), %rdx
	addq	%r15, %rdi
	addq	%r15, %rsi
	movss	%xmm0, -188(%rbp)
	call	cudaMemcpyAsync@PLT
	movq	-104(%rbp), %rdi
	call	cudaStreamSynchronize@PLT
.L50:
	call	_Z12getTimeStampv
	xorl	%ebx, %ebx
	movsd	%xmm0, -184(%rbp)
.L52:
	incq	%rbx
	cmpl	%ebx, -204(%rbp)
	jl	.L69
	movq	-240(%rbp), %rax
	movq	(%rax,%rbx,8), %rdi
	call	cudaStreamSynchronize@PLT
	jmp	.L52
.L69:
	call	cudaDeviceSynchronize@PLT
	call	_Z12getTimeStampv
	movq	-168(%rbp), %rdi
	movsd	%xmm0, -200(%rbp)
	call	cudaFreeHost@PLT
	movq	-160(%rbp), %rdi
	call	cudaFreeHost@PLT
	movq	-144(%rbp), %rdi
	call	cudaFree@PLT
	movq	-136(%rbp), %rdi
	call	cudaFree@PLT
	movq	-128(%rbp), %rdi
	call	cudaFree@PLT
	movl	-192(%rbp), %edx
	movq	-152(%rbp), %rsi
	movq	-216(%rbp), %rdi
	call	_Z15h_compareResultPfS_i
	movsd	-200(%rbp), %xmm3
	decl	%eax
	jne	.L54
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L55
.L54:
	movaps	%xmm3, %xmm0
	movsd	-264(%rbp), %xmm1
	movb	$4, %al
	subsd	-232(%rbp), %xmm0
	subsd	-184(%rbp), %xmm3
	subsd	-232(%rbp), %xmm1
	movl	$2, %edi
	cvtss2sd	-188(%rbp), %xmm2
	leaq	.LC8(%rip), %rsi
	call	__printf_chk@PLT
.L55:
	movq	-152(%rbp), %rdi
	call	cudaFreeHost@PLT
	movq	-216(%rbp), %rdi
	call	free@PLT
	call	cudaDeviceReset@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z9f_addmat4PfS_S_iii"
.LC10:
	.string	"_Z8f_addmatPfS_S_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z9f_addmat4PfS_S_iii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC10(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z8f_addmatPfS_S_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2061:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1093567616
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	805306368
	.align 4
.LC2:
	.long	1084227584
	.align 4
.LC6:
	.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 <sys/time.h>
#define DEFAULT_ROW  16384
#define DEFAULT_COL  16384
// time stamp function in seconds
double getTimeStamp() {
	struct timeval tv ;
	gettimeofday( &tv, NULL ) ;
	return (double) tv.tv_usec/1000000 + tv.tv_sec ;
}
// host side matrix addition
void h_addmat(float *A, float *B, float *C, int nx, int ny){ 
	float* ia = A, *ib =B, *ic =C;
	for (int iy =0; iy<ny; iy++){
		for (int ix =0; ix<nx; ix++){
			
			ic[ix] = ia[ix] + ib[ix];
			//if (iy*nx + ix == 67133440) printf("the addition in host: %.6f + %.6f = %.6f\n",ia[ix],ib[ix],ic[ix]);
			
		}
		ia += nx;
		ib += nx;
		ic += nx;
	}
 }

//host side matrix comparison
int h_compareResult(float *h_C, float *d_C, int noElems){ 
	float *host_c = h_C,*device_c = d_C;
	for (int i =0; i<noElems; i++){
		if (*(host_c) != *(device_c)){
#ifdef DEBUG

			printf("the i = %d\n", i);
			printf("the data of CPU is %.6f\n", *(host_c));
			printf("the data of GPU is %.6f\n", *(device_c));

#endif
			return 1;
		} 
		host_c++;
		device_c++;
	}
	return 0;
 }

// device-side matrix addition
__global__ void f_addmat( float *A, float *B, float *C, int nx, int ny ){
	// kernel code might look something like this
	// but you may want to pad the matrices and index into them accordingly
	int ix = threadIdx.x + blockIdx.x*blockDim.x ;
	int iy = threadIdx.y + blockIdx.y*blockDim.y ;
	int idx = iy*nx + ix ;
	if( (ix<nx) && (iy<ny) )
	C[idx] = A[idx] + B[idx] ;
	//printf("the addition at idx = %d in device: %.6f + %.6f = %.6f\n",idx, A[idx],B[idx],C[idx]);
}

// device-side matrix addition
__global__ void f_addmat4( float *A, float *B, float *C, int nx, int ny, int mode_number ){
	// kernel code might look something like this
	// but you may want to pad the matrices and index into them accordingly
	int ix = threadIdx.x + blockIdx.x*blockDim.x ;
	int iy = threadIdx.y + blockIdx.y*blockDim.y ;
	int idx = iy*nx + ix ;
	if( (ix<nx) && (iy<ny) ){
		int i;
		int index;
		for (i = 0; i< 4; i++){

			// compute 4 element in this thread.
			index = idx + i * mode_number;
			//if (index >1000 && i == 3) printf("the addition when idenx = %d in device: %.6f + %.6f = %.6f\n",index,A[idx],B[idx],C[idx]);
			C[index] = A[index] + B[index] ;
		}
	}
	
	//if (idx == 0) printf("the addition in device: %.6f + %.6f = %.6f\n",A[idx],B[idx],C[idx]);
}
/*
void initData(float* add, int new_nx, int block_x, int nx, int ny){
	int row,col;
	float a = 5.0;
	for (row=0; row< ny; row++){
		for (col=0; col< new_nx; col++){
			if (row == ny -1){	// last block
				if (col%8 < (8 - nx%8)) *(add++) = ((float)rand()/(float)(RAND_MAX)) * a;
				else *(add++) = 0;
			}
			else{
				if (col%8 < block_x ) *(add++) = ((float)rand()/(float)(RAND_MAX)) * a;
				else *(add++) = 0;
			}
		}
	}

}
// host side matrix addition
void h_addmat(float *A, float *B, float *C, int nx, int ny, int new_nx, int block_x){ 
	float* ia = A, *ib =B, *ic =C;
	for (int iy =0; iy<ny; iy++){
		for (int ix =0; ix<new_nx; ix++){
			if (iy== ny -1){	// last block
				if (ix%8 < (8 - nx%8)) *(ic++) = *(ia++) + *(ib++);
				else{
					ia++;
					ib++;
				}
			}
			else{
				if (ix%8 < block_x ) *(ic++) = *(ia++) + *(ib++);
				else{
					ia++;
					ib++;
				}
			}

			//if (iy*nx + ix == 67133440) printf("the addition in host: %.6f + %.6f = %.6f\n",ia[ix],ib[ix],ic[ix]);
			
		}
	}
 }
void removePading(float* h_dC, float* h_temp_dC, int nx, int ny, int new_nx, int block_x){
	int row,col;
	int count=0;
	float *r_padding = h_temp_dC, *r = h_dC;
	for (row=0; row< ny; row++){
		for (col=0; col< new_nx; col++){
			if (row == ny -1){	// last block
				if (col%8 < (8 - nx%8)){
					r[count] = r_padding[row * new_nx + col];
					count ++;
				}
			}
			else{
				if (col%8 < block_x ){
					r[count] = r_padding[row * new_nx + col];
					count ++;
				}
			}
			
		}
	}

}
*/
void initData(float* add, int noElems){
	int i;
	float a = 5.0;
	for (i=0; i< noElems; i++){
		*(add++) = ((float)rand()/(float)(RAND_MAX)) * a;
	}

}


int main(int argc, char* argv[]){

	if(argc != 3){
		printf("Error: wrong number of argument\n");
		exit(0);
	}

	int nx = atoi(argv[1]);
	int ny = atoi(argv[2]);

	// do the input argument check.
	if(nx<=0 || ny<= 0){
		printf("Error: input arguement can't be zero or negative\n");
		exit(0);
	}

	int noElems = nx * ny;
	int bytes = noElems * sizeof(float);
#ifdef DEBUG
	printf("the input row # is %d\n",nx);
	printf("the input col # is %d\n",ny);
	printf("the noElems is %d\n",noElems);
	printf("the bytes is %d\n",bytes);
#endif
	// according to input dimension and GPU limitation, calculate the minmum ny;
	int block_x, block_y, min_blocky = 1;
	while ((ny + min_blocky-1)/min_blocky > 65535){
		min_blocky ++;
	}
	block_y = min_blocky;

	// according to minimum block_y and max of 1024 threads per block, calculate the maximum nx;
	block_x = 1024 / block_y;


	// alloc memeory host-side
	float *h_A;
	float *h_B;
	float *h_dC;
	float *h_hC = (float*) malloc(bytes); // host result
	
	//pin memeory in host side
	hipHostAlloc((void**)&h_A, bytes, 0);	
	hipHostAlloc((void**)&h_B, bytes, 0);	
	hipHostAlloc((void**)&h_dC, bytes, 0);
	
	// init matrices with random data
	initData(h_A, noElems);
	initData(h_B, noElems);
	
	//alloc memeory device-side
	float *d_A, *d_B, *d_C;
	hipMalloc( &d_A, bytes);
	hipMalloc( &d_B, bytes);
	hipMalloc( &d_C, bytes);
	
	// getting host side result
	h_addmat( h_A, h_B, h_hC, nx, ny) ;

	
	int i;
	// calculating minimum bytes each Stream should take according to the calculated block_y
	
	int minimumBytesPerStream = nx * sizeof(float) * 4 * block_y;	
	while (minimumBytesPerStream < 4194304*16){	// 4194304 is when 1024(thread) * 2 (blocks/SMS) * 16 (SMS) * 4 (sizeof(Float)) * 2 (Two float number required for addition), we want data transfer is multiple of this number
		minimumBytesPerStream = minimumBytesPerStream * 2;
	}
	// yPerStream is mutiple of 4 so every thread can process 4 different y in one stream
	int yPerStream = minimumBytesPerStream/ nx;	
	// calculating bytes each Stream according to the calculated yPerStream
	int bytesPerStream = nx * sizeof(float) * yPerStream;
	// calculating number of Streams according to the calculated bytesPerStream
	int NSTREAMS = bytes/bytesPerStream;
	// if there is data remain where they are not multiple of bytesPerStream
	int remainBytes = bytes%bytesPerStream;
	// initialize the stream array
	hipStream_t stream[NSTREAMS+1];
	// input the pre-calculated block size and calculate the grid size
	dim3 block( block_x, block_y ) ; // you will want to configure this
	dim3 grid( (nx + block.x-1)/block.x, (bytesPerStream/(sizeof(float) * nx) + block.y-1)/block.y ) ;

#ifdef DEBUG
	printf("the final bytesPerStream is = %d\n", bytesPerStream);

	printf("the remainBytes is = %d\n", remainBytes);
	printf("the final block size is x = %d and y = %d \n",block_x, block_y);
	printf("the final grid dimension is x = %d and y = %d \n",(nx + block_x-1)/block_x, (yPerStream + block.y-1)/block.y );
#endif
	// initialize the event for calculating accumulate kernel time.
	// NOTE: if we don't need to calculating the accumulate kernel time, the total time is at least 10% faster.
	// But  kernel time is important to show. 
	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);
	double timeStampA = getTimeStamp() ;
	double timeStampB= getTimeStamp() ;
	float milliseconds;
	float AccumulateKernelTime = 0;
	for(i = 1; i <=NSTREAMS; i++ ){
		// create stream
		hipStreamCreate(&stream[i]);
		//calculating offset
		int offset = (i-1) * bytesPerStream/4;
		//Asynch copy data from host to device 
		hipMemcpyAsync(&d_A[offset],&h_A[offset],bytesPerStream, hipMemcpyHostToDevice, stream[i]);
		hipMemcpyAsync(&d_B[offset],&h_B[offset],bytesPerStream, hipMemcpyHostToDevice, stream[i]);
		//record the timestamp before kernel invoke
		hipEventRecord(start);
		//invoke kernel
		f_addmat4<<<grid, block,0,stream[i]>>>( &d_A[offset], &d_B[offset], &d_C[offset], nx, bytesPerStream/(4* sizeof(float) * nx), bytesPerStream/(4* sizeof(float)) ) ;
		//record the timestamp before kernel invoke		
		hipEventRecord(stop);	
		hipEventSynchronize(stop);
		// write down the difference
		hipEventElapsedTime(&milliseconds, start, stop);
		// add this time to accumulated time
		AccumulateKernelTime += milliseconds/1000;
		//Asynch copy data from device back to host 
		hipMemcpyAsync(&h_dC[offset],&d_C[offset],bytesPerStream, hipMemcpyDeviceToHost,stream[i]);
	}
	// if there is remaining byte, we do the process one more time
	if(remainBytes != 0){
		int remainEle = remainBytes/4;
		hipStream_t last;
		hipStreamCreate(&last);
		int offset = NSTREAMS * bytesPerStream/4;
		hipMemcpyAsync(&d_A[offset],&h_A[offset],remainBytes, hipMemcpyHostToDevice, last);
		hipMemcpyAsync(&d_B[offset],&h_B[offset],remainBytes, hipMemcpyHostToDevice, last);
		dim3 grid( (nx + block.x-1)/block.x, (remainEle/nx + block.y-1)/block.y ) ;
		hipEventRecord(start);
		f_addmat<<<grid, block,0,last>>>( &d_A[offset], &d_B[offset], &d_C[offset], nx, remainEle/nx ) ;
		hipEventRecord(stop);	
		hipEventElapsedTime(&milliseconds, start, stop);
		AccumulateKernelTime += milliseconds/1000;
		hipMemcpyAsync(&h_dC[offset],&d_C[offset],remainBytes, hipMemcpyDeviceToHost,last);
		hipStreamSynchronize(last);
	}

	double timeStampC = getTimeStamp() ;
	//wait for all stream finish the job
	for(i = 1; i <=NSTREAMS; i++ ){
		hipStreamSynchronize(stream[i]);
	}
	
	hipDeviceSynchronize() ;
	//time where device side jobs have been finished
	double timeStampD = getTimeStamp() ;

	// free some Host and GPU resources that are not needed anymore
	hipHostFree(h_A);
	hipHostFree(h_B);
	hipFree( d_A ) ; hipFree( d_B ) ; hipFree( d_C ) ;

#ifdef DEBUG
	float * ptr;
	int n;
	ptr = h_dC;
	n = 0;
	ptr = ptr + n;
	printf("the data of GPU at index %d before comparison is %.6f\n", n,*(ptr));
#endif	
	//h_compareResult compares the result computed by host and result computed by device
	//if any element is not same, the function will return 1, otherwise print out the time 
	if (h_compareResult(h_hC,h_dC,noElems) == 1){
			printf("Error: the two results don't match\n");
	}
	else{
		//printf(" %.6f  %.6f %.6f %.6f\n",timeStampD - timeStampA,timeStampB - timeStampA, AccumulateKernelTime, timeStampD - timeStampC  );
		printf(" %.6f  %.6f %.6f %.6f\n",timeStampD - timeStampA,timeStampB - timeStampA, AccumulateKernelTime, timeStampD - timeStampC  );
	}
	// free rest Host Side Resources
	hipHostFree(h_dC);
	free(h_hC);
	hipDeviceReset();
}

	.text
	.file	"var4.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12getTimeStampv
.LCPI0_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z12getTimeStampv
	.type	_Z12getTimeStampv,@function
_Z12getTimeStampv:                      # @_Z12getTimeStampv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cvtsi2sdq	8(%rbx), %xmm1
	divsd	.LCPI0_0(%rip), %xmm1
	cvtsi2sdq	(%rbx), %xmm0
	addsd	%xmm1, %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z12getTimeStampv, .Lfunc_end0-_Z12getTimeStampv
	.cfi_endproc
                                        # -- End function
	.globl	_Z8h_addmatPfS_S_ii             # -- Begin function _Z8h_addmatPfS_S_ii
	.type	_Z8h_addmatPfS_S_ii,@function
_Z8h_addmatPfS_S_ii:                    # @_Z8h_addmatPfS_S_ii
	.cfi_startproc
# %bb.0:
	testl	%r8d, %r8d
	jle	.LBB1_6
# %bb.1:                                # %.preheader.lr.ph
	movslq	%ecx, %rax
	movl	%eax, %r9d
	shlq	$2, %rax
	xorl	%r10d, %r10d
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	testl	%ecx, %ecx
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_2 Depth=1
	xorl	%r11d, %r11d
.LBB1_4:                                # %.lr.ph
                                        #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rdi,%r11,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%rsi,%r11,4), %xmm0
	movss	%xmm0, (%rdx,%r11,4)
	incq	%r11
	cmpq	%r11, %r9
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incl	%r10d
	addq	%rax, %rdx
	addq	%rax, %rsi
	addq	%rax, %rdi
	cmpl	%r8d, %r10d
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge30
	retq
.Lfunc_end1:
	.size	_Z8h_addmatPfS_S_ii, .Lfunc_end1-_Z8h_addmatPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z15h_compareResultPfS_i        # -- Begin function _Z15h_compareResultPfS_i
	.type	_Z15h_compareResultPfS_i,@function
_Z15h_compareResultPfS_i:               # @_Z15h_compareResultPfS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB2_1
# %bb.2:                                # %.lr.ph.preheader
	movss	(%rdi), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movl	$1, %eax
	ucomiss	(%rsi), %xmm0
	jne	.LBB2_7
	jnp	.LBB2_3
.LBB2_7:                                # %._crit_edge
	retq
.LBB2_1:
	xorl	%eax, %eax
	retq
.LBB2_3:                                # %.lr.ph24.preheader
	movl	%edx, %eax
	movl	$1, %r8d
.LBB2_5:                                # %.lr.ph24
                                        # =>This Inner Loop Header: Depth=1
	movq	%r8, %rcx
	cmpl	%ecx, %eax
	je	.LBB2_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB2_5 Depth=1
	movss	(%rdi,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	leaq	1(%rcx), %r8
	ucomiss	(%rsi,%rcx,4), %xmm0
	jne	.LBB2_6
	jnp	.LBB2_5
.LBB2_6:                                # %._crit_edge.loopexit.loopexit
	xorl	%eax, %eax
	cmpl	%edx, %ecx
	setl	%al
	retq
.Lfunc_end2:
	.size	_Z15h_compareResultPfS_i, .Lfunc_end2-_Z15h_compareResultPfS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__f_addmatPfS_S_ii # -- Begin function _Z23__device_stub__f_addmatPfS_S_ii
	.type	_Z23__device_stub__f_addmatPfS_S_ii,@function
_Z23__device_stub__f_addmatPfS_S_ii:    # @_Z23__device_stub__f_addmatPfS_S_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z8f_addmatPfS_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z23__device_stub__f_addmatPfS_S_ii, .Lfunc_end3-_Z23__device_stub__f_addmatPfS_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__f_addmat4PfS_S_iii # -- Begin function _Z24__device_stub__f_addmat4PfS_S_iii
	.type	_Z24__device_stub__f_addmat4PfS_S_iii,@function
_Z24__device_stub__f_addmat4PfS_S_iii:  # @_Z24__device_stub__f_addmat4PfS_S_iii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z9f_addmat4PfS_S_iii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z24__device_stub__f_addmat4PfS_S_iii, .Lfunc_end4-_Z24__device_stub__f_addmat4PfS_S_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z8initDataPfi
.LCPI5_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI5_1:
	.long	0x40a00000                      # float 5
	.text
	.globl	_Z8initDataPfi
	.type	_Z8initDataPfi,@function
_Z8initDataPfi:                         # @_Z8initDataPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB5_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI5_0(%rip), %xmm0
	mulss	.LCPI5_1(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpl	%r15d, %r14d
	jne	.LBB5_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB5_4:                                # %._crit_edge
	retq
.Lfunc_end5:
	.size	_Z8initDataPfi, .Lfunc_end5-_Z8initDataPfi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI6_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI6_1:
	.long	0x40a00000                      # float 5
.LCPI6_3:
	.long	0x447a0000                      # float 1000
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI6_2:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$248, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	cmpl	$3, %edi
	jne	.LBB6_1
# %bb.3:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	16(%rbx), %rdi
	callq	atoi
	testl	%r14d, %r14d
	jle	.LBB6_5
# %bb.4:
	testl	%eax, %eax
	jle	.LBB6_5
# %bb.6:
	movl	%eax, %edi
	movl	%edi, %r12d
	imull	%r14d, %r12d
	movq	%r14, -160(%rbp)                # 8-byte Spill
	movl	%r14d, %ecx
	shll	$4, %ecx
	movl	$1, %edx
	xorl	%r14d, %r14d
	xorl	%esi, %esi
.LBB6_7:                                # =>This Inner Loop Header: Depth=1
	movl	%edx, %ebx
	movq	%rsi, %rax
	incq	%rsi
	addl	%edi, %eax
                                        # kill: def $eax killed $eax killed $rax
	cltd
	idivl	%esi
	leal	1(%rbx), %edx
	addl	%ecx, %r14d
	cmpl	$65535, %eax                    # imm = 0xFFFF
	jg	.LBB6_7
# %bb.8:
	movq	%rdi, -80(%rbp)                 # 8-byte Spill
	leal	(,%r12,4), %ecx
	xorl	%r15d, %r15d
	movl	$1024, %eax                     # imm = 0x400
	xorl	%edx, %edx
	movq	%rsi, -216(%rbp)                # 8-byte Spill
	divl	%esi
                                        # kill: def $eax killed $eax def $rax
	movq	%rax, -56(%rbp)                 # 8-byte Spill
	movl	%ecx, -72(%rbp)                 # 4-byte Spill
	movslq	%ecx, %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, -232(%rbp)                # 8-byte Spill
	leaq	-128(%rbp), %rdi
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	-120(%rbp), %rdi
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	-152(%rbp), %rdi
	movq	%r13, -64(%rbp)                 # 8-byte Spill
	movq	%r13, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	movq	%r12, -224(%rbp)                # 8-byte Spill
	testl	%r12d, %r12d
	jle	.LBB6_13
# %bb.9:                                # %.lr.ph.i.preheader
	movq	-128(%rbp), %rax
	movq	%rax, -48(%rbp)                 # 8-byte Spill
	movl	-224(%rbp), %r13d               # 4-byte Reload
	xorl	%r12d, %r12d
.LBB6_10:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movss	.LCPI6_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	.LCPI6_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movq	-48(%rbp), %rax                 # 8-byte Reload
	movss	%xmm0, (%rax,%r12,4)
	incq	%r12
	cmpl	%r12d, %r13d
	jne	.LBB6_10
# %bb.11:                               # %_Z8initDataPfi.exit
	movq	-120(%rbp), %rax
	movq	%rax, -48(%rbp)                 # 8-byte Spill
	xorl	%r12d, %r12d
.LBB6_12:                               # %.lr.ph.i140
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI6_0(%rip), %xmm0
	mulss	.LCPI6_1(%rip), %xmm0
	movq	-48(%rbp), %rax                 # 8-byte Reload
	movss	%xmm0, (%rax,%r12,4)
	incq	%r12
	cmpl	%r12d, %r13d
	jne	.LBB6_12
.LBB6_13:                               # %_Z8initDataPfi.exit144
	leaq	-112(%rbp), %rdi
	movq	-64(%rbp), %r12                 # 8-byte Reload
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	-104(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	-96(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movq	-120(%rbp), %rax
	movq	-128(%rbp), %rcx
	movq	-160(%rbp), %r8                 # 8-byte Reload
	movslq	%r8d, %rdx
	movl	%r8d, %r12d
	shlq	$2, %rdx
	movq	-232(%rbp), %rsi                # 8-byte Reload
	movq	-80(%rbp), %r9                  # 8-byte Reload
.LBB6_14:                               # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_15 Depth 2
	xorl	%edi, %edi
.LBB6_15:                               # %.lr.ph.i145
                                        #   Parent Loop BB6_14 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rcx,%rdi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%rax,%rdi,4), %xmm0
	movss	%xmm0, (%rsi,%rdi,4)
	incq	%rdi
	cmpq	%rdi, %r12
	jne	.LBB6_15
# %bb.16:                               # %._crit_edge.i.loopexit
                                        #   in Loop: Header=BB6_14 Depth=1
	incl	%r15d
	addq	%rdx, %rsi
	addq	%rdx, %rax
	addq	%rdx, %rcx
	cmpl	%r9d, %r15d
	jne	.LBB6_14
.LBB6_17:                               # =>This Inner Loop Header: Depth=1
	movl	%r14d, %eax
	leal	(%rax,%rax), %r14d
	cmpl	$67108864, %eax                 # imm = 0x4000000
	jl	.LBB6_17
# %bb.18:
	movq	%rsp, -280(%rbp)                # 8-byte Spill
	leaq	(,%r12,4), %rcx
                                        # kill: def $eax killed $eax killed $rax
	xorl	%edx, %edx
	divl	%r8d
	movl	%ecx, %r10d
	imull	%eax, %r10d
	movl	-72(%rbp), %eax                 # 4-byte Reload
	cltd
	idivl	%r10d
	movl	%edx, -180(%rbp)                # 4-byte Spill
	movl	%eax, %r13d
	leal	1(%r13), %eax
	movq	%rax, -208(%rbp)                # 8-byte Spill
	leaq	15(,%rax,8), %rax
	andq	$-16, %rax
	movq	%rsp, %r14
	subq	%rax, %r14
	movq	%r14, %rsp
	movq	-56(%rbp), %r9                  # 8-byte Reload
	movl	%r9d, %esi
	movl	%ebx, %edi
	leal	(%r8,%r9), %eax
	decl	%eax
	xorl	%edx, %edx
	divl	%r9d
                                        # kill: def $eax killed $eax def $rax
	movq	%rax, -192(%rbp)                # 8-byte Spill
	movl	%r10d, -64(%rbp)                # 4-byte Spill
	movslq	%r10d, %rax
	movq	%rax, -48(%rbp)                 # 8-byte Spill
	xorl	%edx, %edx
	divq	%rcx
	addq	%rdi, %rax
	decq	%rax
	shlq	$32, %rdi
	orq	%rsi, %rdi
	movq	%rdi, -72(%rbp)                 # 8-byte Spill
	xorl	%edx, %edx
	divq	-216(%rbp)                      # 8-byte Folded Reload
	movq	%rax, %r15
	leaq	-144(%rbp), %rdi
	callq	hipEventCreate
	leaq	-88(%rbp), %rdi
	callq	hipEventCreate
	leaq	-176(%rbp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	movsd	%xmm0, -264(%rbp)               # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sdq	(%rbx), %xmm0
	movsd	%xmm0, -248(%rbp)               # 8-byte Spill
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	movsd	%xmm0, -256(%rbp)               # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sdq	(%rbx), %xmm0
	movsd	%xmm0, -240(%rbp)               # 8-byte Spill
	movq	%r13, -200(%rbp)                # 8-byte Spill
	testl	%r13d, %r13d
	movq	%r14, -272(%rbp)                # 8-byte Spill
	jle	.LBB6_19
# %bb.20:                               # %.lr.ph
	shlq	$32, %r15
	addq	-192(%rbp), %r15                # 8-byte Folded Reload
	movq	%r15, -288(%rbp)                # 8-byte Spill
	shlq	$4, %r12
	movl	-64(%rbp), %ebx                 # 4-byte Reload
	movl	%ebx, %eax
	sarl	$4, %eax
	movl	%eax, -184(%rbp)                # 4-byte Spill
	addq	$8, %r14
	movq	-208(%rbp), %r15                # 8-byte Reload
	leaq	-1(%r15), %rax
	xorpd	%xmm0, %xmm0
	movss	%xmm0, -56(%rbp)                # 4-byte Spill
	movl	$1, %r13d
	movq	-48(%rbp), %r15                 # 8-byte Reload
.LBB6_21:                               # =>This Inner Loop Header: Depth=1
	movq	%rax, -80(%rbp)                 # 8-byte Spill
	movq	%r14, %rdi
	callq	hipStreamCreate
	leal	-1(%r13), %eax
	imull	%ebx, %eax
	sarl	$2, %eax
	movslq	%eax, %rbx
	shlq	$2, %rbx
	movq	-112(%rbp), %rdi
	addq	%rbx, %rdi
	movq	-128(%rbp), %rsi
	addq	%rbx, %rsi
	movq	(%r14), %r8
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	-104(%rbp), %rdi
	addq	%rbx, %rdi
	movq	-120(%rbp), %rsi
	addq	%rbx, %rsi
	movq	(%r14), %r8
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	-144(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r14), %r9
	movq	-288(%rbp), %rdi                # 8-byte Reload
	movl	$1, %esi
	movq	-72(%rbp), %rdx                 # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_23
# %bb.22:                               #   in Loop: Header=BB6_21 Depth=1
	movq	-112(%rbp), %rdi
	addq	%rbx, %rdi
	movq	-104(%rbp), %rsi
	addq	%rbx, %rsi
	movq	-96(%rbp), %rcx
	addq	%rbx, %rcx
	movq	-48(%rbp), %rax                 # 8-byte Reload
	xorl	%edx, %edx
	divq	%r12
	movq	%rcx, %rdx
	movq	-160(%rbp), %rcx                # 8-byte Reload
                                        # kill: def $ecx killed $ecx killed $rcx
	movl	%eax, %r8d
	movl	-184(%rbp), %r9d                # 4-byte Reload
	callq	_Z24__device_stub__f_addmat4PfS_S_iii
.LBB6_23:                               #   in Loop: Header=BB6_21 Depth=1
	movq	-88(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	-88(%rbp), %rdi
	callq	hipEventSynchronize
	movq	-144(%rbp), %rsi
	movq	-88(%rbp), %rdx
	leaq	-132(%rbp), %rdi
	callq	hipEventElapsedTime
	movss	-132(%rbp), %xmm0               # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI6_3(%rip), %xmm0
	movss	-56(%rbp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm1
	movss	%xmm1, -56(%rbp)                # 4-byte Spill
	movq	-152(%rbp), %rdi
	addq	%rbx, %rdi
	addq	-96(%rbp), %rbx
	movq	(%r14), %r8
	movq	%rbx, %rsi
	movq	-48(%rbp), %rdx                 # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpyAsync
	incq	%r13
	addq	$8, %r14
	movq	-80(%rbp), %rax                 # 8-byte Reload
	decq	%rax
	movl	-64(%rbp), %ebx                 # 4-byte Reload
	jne	.LBB6_21
	jmp	.LBB6_24
.LBB6_19:
	xorpd	%xmm0, %xmm0
	movss	%xmm0, -56(%rbp)                # 4-byte Spill
	movl	-64(%rbp), %ebx                 # 4-byte Reload
.LBB6_24:                               # %._crit_edge
	movl	-180(%rbp), %r14d               # 4-byte Reload
	testl	%r14d, %r14d
	je	.LBB6_28
# %bb.25:
	movl	%r14d, %r12d
	sarl	$2, %r12d
	leaq	-176(%rbp), %rdi
	movq	%rdi, %r15
	callq	hipStreamCreate
	imull	-200(%rbp), %ebx                # 4-byte Folded Reload
	sarl	$2, %ebx
	movslq	%ebx, %rbx
	shlq	$2, %rbx
	movq	-112(%rbp), %rdi
	addq	%rbx, %rdi
	movq	-128(%rbp), %rsi
	addq	%rbx, %rsi
	movslq	%r14d, %r14
	movq	(%r15), %r8
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	-104(%rbp), %rdi
	addq	%rbx, %rdi
	movq	-120(%rbp), %rsi
	addq	%rbx, %rsi
	movq	(%r15), %r8
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movl	%r12d, %eax
	cltd
	movq	-160(%rbp), %r13                # 8-byte Reload
	idivl	%r13d
	movl	%eax, %r12d
	movq	-216(%rbp), %rcx                # 8-byte Reload
	leal	(%r12,%rcx), %eax
	decl	%eax
	xorl	%edx, %edx
	divl	%ecx
                                        # kill: def $eax killed $eax def $rax
	shlq	$32, %rax
	movq	-192(%rbp), %r15                # 8-byte Reload
	orq	%rax, %r15
	movq	-144(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	-176(%rbp), %rax
	movq	(%rax), %r9
	movq	%r15, %rdi
	movl	$1, %esi
	movq	-72(%rbp), %rdx                 # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_27
# %bb.26:
	movq	-112(%rbp), %rdi
	addq	%rbx, %rdi
	movq	-104(%rbp), %rsi
	addq	%rbx, %rsi
	movq	-96(%rbp), %rdx
	addq	%rbx, %rdx
	movl	%r13d, %ecx
	movl	%r12d, %r8d
	callq	_Z23__device_stub__f_addmatPfS_S_ii
.LBB6_27:
	movq	-88(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	-144(%rbp), %rsi
	movq	-88(%rbp), %rdx
	leaq	-132(%rbp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI6_3(%rip), %xmm0
	movss	-56(%rbp), %xmm1                # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm1
	movss	%xmm1, -56(%rbp)                # 4-byte Spill
	movq	-152(%rbp), %rdi
	addq	%rbx, %rdi
	addq	-96(%rbp), %rbx
	movq	-176(%rbp), %r8
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
	movq	-176(%rbp), %rdi
	callq	hipStreamSynchronize
.LBB6_28:
	leaq	-176(%rbp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	movsd	%xmm0, -48(%rbp)                # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sdq	(%rbx), %xmm0
	movsd	%xmm0, -80(%rbp)                # 8-byte Spill
	cmpl	$0, -200(%rbp)                  # 4-byte Folded Reload
	movq	-224(%rbp), %r14                # 8-byte Reload
	movq	-208(%rbp), %r15                # 8-byte Reload
	movq	-272(%rbp), %r12                # 8-byte Reload
	jle	.LBB6_31
# %bb.29:                               # %.lr.ph169.preheader
	movl	$1, %ebx
.LBB6_30:                               # %.lr.ph169
                                        # =>This Inner Loop Header: Depth=1
	movq	(%r12,%rbx,8), %rdi
	callq	hipStreamSynchronize
	incq	%rbx
	cmpq	%rbx, %r15
	jne	.LBB6_30
.LBB6_31:                               # %._crit_edge170
	callq	hipDeviceSynchronize
	leaq	-176(%rbp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	movsd	%xmm0, -64(%rbp)                # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sdq	(%rbx), %xmm0
	movsd	%xmm0, -72(%rbp)                # 8-byte Spill
	movq	-128(%rbp), %rdi
	callq	hipHostFree
	movq	-120(%rbp), %rdi
	callq	hipHostFree
	movq	-112(%rbp), %rdi
	callq	hipFree
	movq	-104(%rbp), %rdi
	callq	hipFree
	movq	-96(%rbp), %rdi
	callq	hipFree
	testl	%r14d, %r14d
	movq	-232(%rbp), %rbx                # 8-byte Reload
	jle	.LBB6_38
# %bb.32:                               # %.lr.ph.i148.preheader
	movq	-152(%rbp), %rax
	movss	(%rbx), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%rax), %xmm0
	jne	.LBB6_37
	jp	.LBB6_37
# %bb.33:                               # %.lr.ph174.preheader
	movl	%r14d, %ecx
	movl	$1, %esi
.LBB6_35:                               # %.lr.ph174
                                        # =>This Inner Loop Header: Depth=1
	movq	%rsi, %rdx
	cmpl	%edx, %ecx
	je	.LBB6_36
# %bb.34:                               # %.lr.ph.i148
                                        #   in Loop: Header=BB6_35 Depth=1
	movss	(%rbx,%rdx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	leaq	1(%rdx), %rsi
	ucomiss	(%rax,%rdx,4), %xmm0
	jne	.LBB6_36
	jnp	.LBB6_35
.LBB6_36:                               # %_Z15h_compareResultPfS_i.exit
	cmpl	%r14d, %edx
	jge	.LBB6_38
.LBB6_37:                               # %.critedge
	movl	$.Lstr, %edi
	callq	puts@PLT
	jmp	.LBB6_39
.LBB6_38:                               # %_Z15h_compareResultPfS_i.exit.thread
	movsd	.LCPI6_2(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	-264(%rbp), %xmm2               # 8-byte Reload
                                        # xmm2 = mem[0],zero
	divsd	%xmm0, %xmm2
	addsd	-248(%rbp), %xmm2               # 8-byte Folded Reload
	movsd	-256(%rbp), %xmm1               # 8-byte Reload
                                        # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	addsd	-240(%rbp), %xmm1               # 8-byte Folded Reload
	movsd	-48(%rbp), %xmm4                # 8-byte Reload
                                        # xmm4 = mem[0],zero
	divsd	.LCPI6_2(%rip), %xmm4
	addsd	-80(%rbp), %xmm4                # 8-byte Folded Reload
	movsd	-64(%rbp), %xmm3                # 8-byte Reload
                                        # xmm3 = mem[0],zero
	divsd	.LCPI6_2(%rip), %xmm3
	addsd	-72(%rbp), %xmm3                # 8-byte Folded Reload
	movapd	%xmm3, %xmm0
	subsd	%xmm2, %xmm0
	subsd	%xmm2, %xmm1
	xorps	%xmm2, %xmm2
	cvtss2sd	-56(%rbp), %xmm2                # 4-byte Folded Reload
	subsd	%xmm4, %xmm3
	movl	$.L.str.3, %edi
	movb	$4, %al
	callq	printf
.LBB6_39:
	movq	-152(%rbp), %rdi
	callq	hipHostFree
	movq	%rbx, %rdi
	callq	free
	callq	hipDeviceReset
	movq	-280(%rbp), %rsp                # 8-byte Reload
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB6_1:
	.cfi_def_cfa %rbp, 16
	movl	$.Lstr.2, %edi
	jmp	.LBB6_2
.LBB6_5:
	movl	$.Lstr.1, %edi
.LBB6_2:
	callq	puts@PLT
	xorl	%edi, %edi
	callq	exit
.Lfunc_end6:
	.size	main, .Lfunc_end6-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8f_addmatPfS_S_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9f_addmat4PfS_S_iii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z8f_addmatPfS_S_ii,@object     # @_Z8f_addmatPfS_S_ii
	.section	.rodata,"a",@progbits
	.globl	_Z8f_addmatPfS_S_ii
	.p2align	3, 0x0
_Z8f_addmatPfS_S_ii:
	.quad	_Z23__device_stub__f_addmatPfS_S_ii
	.size	_Z8f_addmatPfS_S_ii, 8

	.type	_Z9f_addmat4PfS_S_iii,@object   # @_Z9f_addmat4PfS_S_iii
	.globl	_Z9f_addmat4PfS_S_iii
	.p2align	3, 0x0
_Z9f_addmat4PfS_S_iii:
	.quad	_Z24__device_stub__f_addmat4PfS_S_iii
	.size	_Z9f_addmat4PfS_S_iii, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	" %.6f  %.6f %.6f %.6f\n"
	.size	.L.str.3, 23

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8f_addmatPfS_S_ii"
	.size	.L__unnamed_1, 20

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z9f_addmat4PfS_S_iii"
	.size	.L__unnamed_2, 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: the two results don't match"
	.size	.Lstr, 35

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Error: input arguement can't be zero or negative"
	.size	.Lstr.1, 49

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Error: wrong number of argument"
	.size	.Lstr.2, 32

	.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 _Z23__device_stub__f_addmatPfS_S_ii
	.addrsig_sym _Z24__device_stub__f_addmat4PfS_S_iii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8f_addmatPfS_S_ii
	.addrsig_sym _Z9f_addmat4PfS_S_iii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8f_addmatPfS_S_ii     ; -- Begin function _Z8f_addmatPfS_S_ii
	.globl	_Z8f_addmatPfS_S_ii
	.p2align	8
	.type	_Z8f_addmatPfS_S_ii,@function
_Z8f_addmatPfS_S_ii:                    ; @_Z8f_addmatPfS_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b64 s[4:5], s[0:1], 0x18
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s4, v0
	v_cmp_gt_i32_e64 s2, s5, v1
	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_2
; %bb.1:
	s_load_b128 s[8:11], s[0:1], 0x0
	v_mad_u64_u32 v[2:3], null, v1, s4, v[0:1]
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v1, vcc_lo
	v_add_co_u32 v4, vcc_lo, s10, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, s11, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[4:5], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v2, v2, v3
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8f_addmatPfS_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 6
		.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	_Z8f_addmatPfS_S_ii, .Lfunc_end0-_Z8f_addmatPfS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 232
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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
	.protected	_Z9f_addmat4PfS_S_iii   ; -- Begin function _Z9f_addmat4PfS_S_iii
	.globl	_Z9f_addmat4PfS_S_iii
	.p2align	8
	.type	_Z9f_addmat4PfS_S_iii,@function
_Z9f_addmat4PfS_S_iii:                  ; @_Z9f_addmat4PfS_S_iii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[2:3], null, s14, s2, v[1:2]
	v_mad_u64_u32 v[3:4], null, s15, s3, v[0:1]
	v_cmp_gt_i32_e32 vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e64 s2, s5, v3
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB1_3
; %bb.1:                                ; %.preheader.preheader
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_mad_u64_u32 v[0:1], null, v3, s4, v[2:3]
	s_mov_b32 s2, 4
.LBB1_2:                                ; %.preheader
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_ashrrev_i32_e32 v1, 31, v0
	s_add_i32 s2, s2, -1
	s_cmp_lg_u32 s2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	v_add_nc_u32_e32 v0, s6, v0
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s8, v1
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s9, v2, vcc_lo
	v_add_co_u32 v5, vcc_lo, s10, v1
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v2, vcc_lo
	v_add_co_u32 v1, vcc_lo, s0, v1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v4, v[5:6], off
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v3, v3, v4
	global_store_b32 v[1:2], v3, off
	s_cbranch_scc1 .LBB1_2
.LBB1_3:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9f_addmat4PfS_S_iii
		.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 7
		.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_end1:
	.size	_Z9f_addmat4PfS_S_iii, .Lfunc_end1-_Z9f_addmat4PfS_S_iii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 260
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; 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:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8f_addmatPfS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8f_addmatPfS_S_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .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:           _Z9f_addmat4PfS_S_iii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9f_addmat4PfS_S_iii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
