//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <time.h>
#include <cuda.h>

const int MIN_SIZE=1280; 
const int MAX_SIZE=10000;
const int STEP_SIZE=256;
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
float* a;
float* b;
float* c;
float* a1;
float* b1;
float* c1;
float* a2;
float* b2;
float* c2;
float* c3;
float* c4;
int n;

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
__global__ void kernelFunc(float* ad, float* bd, float* cd, int n) {
    __shared__ float as[32][32];
    __shared__ float bs[32][32];

    int tx = threadIdx.x;
    int ty = threadIdx.y;
    
  int x = (blockIdx.x * blockDim.x) + tx;
	int y = (blockIdx.y * blockDim.y) + ty;

    if ((x<n)&(y<n) )
	{

    float v = 0.0f;
    
    int yn = y * n;
    int s = n / 32;
    for(int m=0; m<s; m++) {
        int m32 = m * 32;
        as[ty][tx] = ad[yn + (m32 + tx)];
        bs[ty][tx] = bd[(m32 + ty) * n + x];
        
        __syncthreads();
        
        for(int i=0; i<32; i++) {
            v += as[ty][i] * bs[i][tx];
        }
        
        __syncthreads();
    }
    
    cd[yn + x] = v;   
	}
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void matrixMultiply(float* ad,float* bd,float* cd,float *H2DBandWidthInMBs,float *D2HBandWidthInMbs) {
	

    cudaMalloc((void**)&ad, n * n * sizeof(float));
    cudaMalloc((void**)&bd, n * n * sizeof(float));
    cudaMalloc((void**)&cd, n * n * sizeof(float));

    cudaEvent_t start, stop;

	float time;

	cudaEventCreate(&start);

	cudaEventCreate(&stop);

	cudaEventRecord( start, 0 );


    cudaMemcpy(ad, a, n * n * sizeof(float), cudaMemcpyHostToDevice);
    cudaMemcpy(bd, b, n * n * sizeof(float), cudaMemcpyHostToDevice);

	cudaEventRecord( stop, 0 );

	cudaEventSynchronize( stop );

	cudaEventElapsedTime( &time, start, stop );

	cudaEventDestroy( start );

	cudaEventDestroy( stop );

	*H2DBandWidthInMBs = (1e3f * 2*n*n* sizeof(float)) /
                     (time* (float)(1 << 20));
	//printf("HostToDevice bandwidthInMBs %f\n",H2DBandWidthInMBs );
	//printf("cudaMemcpyHostToDevice(ms) %f\n", 1000*(tc1 - tc0) / (float) CLOCKS_PER_SEC);
    dim3 block(32, 32);           
    dim3 grid((n+31)/32, (n+31)/32);
    
    kernelFunc<<<grid, block>>>(ad, bd, cd, n);

	float time1;

	cudaEventCreate(&start);

	cudaEventCreate(&stop);

	cudaEventRecord( start, 0 );
	
    cudaMemcpy(c, cd, n * n * sizeof(float), cudaMemcpyDeviceToHost);

	cudaEventRecord( stop, 0 );

	cudaEventSynchronize( stop );

	cudaEventElapsedTime( &time1, start, stop );

	cudaEventDestroy( start );

	cudaEventDestroy( stop );

	*D2HBandWidthInMbs = (1e3f * n*n* sizeof(float)) /
                     (time1* (float)(1 << 20));
	//printf("DeviceToHostbandwidthInMBs %f\n",D2HBandWidthInMbs );
	//printf("cudaMemcpyDeviceToHost(ms) %f\n", 1000*(tg1 - tg0) / (float) CLOCKS_PER_SEC);
    cudaFree(ad);
    cudaFree(bd);
    cudaFree(cd);
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void fill(float* data, int size) {
    for (int i=0; i<size; ++i)
        data[i] = rand() / (float) RAND_MAX;
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void save(char* name, int n, float H2DBandWidthInMBs,float D2HBandWidthInMbs) {
	char fname[128];
	FILE* f;
/*
	sprintf(fname, "results/result-mm-%s_%d.txt", name, n);
	f = fopen(fname, "w");
	for (int i=0; i<n * n; ++i)
		fprintf(f, "%f\n", c[i]);
	fclose(f);
*/	
	sprintf(fname, "runtime-mm-%s.txt", name);
	f = fopen(fname, "a");

	fprintf(f, "size of matrix%d : H2DBandWidthInMBs     %f D2HBandWidthInMbs    %f \n",  
		n, H2DBandWidthInMBs,D2HBandWidthInMbs);
	fclose(f);
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int main(int argc, char** argv) {
	remove("runtime-mm-gpu-optimized.txt");
	int devicenum,dev;
	struct cudaDeviceProp p;
	cudaGetDeviceCount(&devicenum);
	for (dev=0;dev<devicenum;dev++){
		cudaGetDeviceProperties(&p, dev);
	printf("\nDevice %d: \%s\"\n",dev,p.name);
	}
    cudaGetDeviceProperties(&p, 0);
    printf("maxGridSize: %d %d %d\n", p.maxGridSize[0], p.maxGridSize[1], p.maxGridSize[2]);
    printf("maxThreadsDim: %d %d %d\n", p.maxThreadsDim[0], p.maxThreadsDim[1], p.maxThreadsDim[2]);
    printf("maxThreadsPerBlock: %d\n", p.maxThreadsPerBlock);
    printf("warpSize: %d\n", p.warpSize);
    printf("totalGlobalMem(MB): %d\n", p.totalGlobalMem/1024/1024);
    printf("sharedMemPerBlock: %d\n", p.sharedMemPerBlock);
	float H2DBandWidthInMBs,D2HBandWidthInMbs;
	for(n=MIN_SIZE; n<=MAX_SIZE; n+=STEP_SIZE) {

		a = (float*)malloc(n * n * sizeof(float));
		b = (float*)malloc(n * n * sizeof(float));
		c = (float*)malloc(n * n * sizeof(float));
		
		if(n*n*sizeof(float)*8<=p.totalGlobalMem){
		srand(0);
		fill(a, n * n);
		fill(b, n * n);
		printf("gpu N*N=%d\n",n);
		//clock_t t0 = clock(); 
		matrixMultiply(a,b,c,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
		//clock_t t1 = clock(); 
		//printf("gpu time(ms)%f\n",(1000*(t1-t0)/(float) CLOCKS_PER_SEC));
		save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
		}

		if (n*n*sizeof(float)*8>p.totalGlobalMem){
		a1 = (float*)malloc(n/2 * n * sizeof(float));a2 = (float*)malloc(n/2 * n * sizeof(float));
		b1 = (float*)malloc(n* n/2 * sizeof(float));b2 = (float*)malloc(n * n/2 * sizeof(float));
		c1 = (float*)malloc(n/2 * n/2 * sizeof(float));c2 = (float*)malloc(n/2 * n/2 * sizeof(float));
		c3 = (float*)malloc(n/2 * n/2 * sizeof(float));c4 = (float*)malloc(n/2 * n/2 * sizeof(float));
		if (n/2*n*sizeof(float)*8> (p.totalGlobalMem-50*1024*1024))
			break;
		srand(0);
		fill(a1, n/2 * n);fill(a2, n/2 * n);
		fill(b1, n * n/2);fill(b2, n * n/2);
		printf("gpu N*N %d\n",n);

		//clock_t Mt0 = clock(); 
			matrixMultiply(a1,b1,c1,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
			matrixMultiply(a1,b2,c2,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
			matrixMultiply(a2,b1,c3,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
			matrixMultiply(a2,b2,c4,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
		//clock_t Mt1 = clock(); 
		//printf("gpu Matrix time(ms)%f\n",(1000*(Mt1-Mt0)/(float) CLOCKS_PER_SEC));		

		}
		
		free(a);free(a2);free(a1);
		free(b);free(b2);free(b1);
		free(c);free(c2);free(c1);
		free(c4);free(c3);
		
	}
    
	cudaThreadExit();
		return 0;
}

	.file	"tmpxft_00245f05_00000000-6_io.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
	.globl	_Z4fillPfi
	.type	_Z4fillPfi, @function
_Z4fillPfi:
.LFB2028:
	.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
.L3:
	cmpl	%ebx, %ebp
	jle	.L7
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L3
.L7:
	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	_Z4fillPfi, .-_Z4fillPfi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"runtime-mm-%s.txt"
.LC2:
	.string	"a"
.LC3:
	.string	"size of matrix%d : H2DBandWidthInMBs     %f D2HBandWidthInMbs    %f \n"
	.text
	.globl	_Z4savePciff
	.type	_Z4savePciff, @function
_Z4savePciff:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %r8
	leaq	.LC1(%rip), %rcx
	movl	$128, %edx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%esi, %ebp
	movl	$2, %esi
	subq	$168, %rsp
	.cfi_def_cfa_offset 192
	movss	%xmm0, 12(%rsp)
	leaq	24(%rsp), %rbx
	movss	%xmm1, 8(%rsp)
	movq	%rbx, %rdi
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	%rbx, %rdi
	leaq	.LC2(%rip), %rsi
	call	fopen@PLT
	movss	12(%rsp), %xmm0
	movl	%ebp, %ecx
	movss	8(%rsp), %xmm1
	movq	%rax, %rdi
	movq	%rax, %rbx
	movl	$2, %esi
	movb	$2, %al
	leaq	.LC3(%rip), %rdx
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	call	__fprintf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$168, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z4savePciff, .-_Z4savePciff
	.globl	_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i
	.type	_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i, @function
_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10kernelFuncPfS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L11:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i, .-_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i
	.globl	_Z10kernelFuncPfS_S_i
	.type	_Z10kernelFuncPfS_S_i, @function
_Z10kernelFuncPfS_S_i:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i
	.cfi_endproc
.LFE2056:
	.size	_Z10kernelFuncPfS_S_i, .-_Z10kernelFuncPfS_S_i
	.globl	_Z14matrixMultiplyPfS_S_S_S_
	.type	_Z14matrixMultiplyPfS_S_S_S_, @function
_Z14matrixMultiplyPfS_S_S_S_:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%r8, %rbx
	subq	$104, %rsp
	.cfi_def_cfa_offset 144
	movq	%rsi, 16(%rsp)
	movl	n(%rip), %esi
	leaq	48(%rsp), %r12
	leaq	56(%rsp), %rbp
	movq	%rdx, 8(%rsp)
	imull	%esi, %esi
	movq	%rdi, 24(%rsp)
	leaq	24(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	n(%rip), %esi
	leaq	16(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	n(%rip), %esi
	leaq	8(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movq	%r12, %rdi
	call	cudaEventCreate@PLT
	movq	%rbp, %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	n(%rip), %edx
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	a(%rip), %rsi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	n(%rip), %edx
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	b(%rip), %rsi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	40(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	$32, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	n(%rip), %eax
	movss	.LC4(%rip), %xmm0
	movl	$1, %esi
	cvtsi2ssl	%eax, %xmm1
	addl	$31, %eax
	cltd
	idivl	%ecx
	mulss	%xmm1, %xmm0
	movl	$1, %ecx
	movabsq	$137438953504, %rdx
	mulss	%xmm1, %xmm0
	movss	.LC6(%rip), %xmm1
	mulss	.LC5(%rip), %xmm0
	mulss	40(%rsp), %xmm1
	divss	%xmm1, %xmm0
	movl	%eax, 76(%rsp)
	movl	%eax, 80(%rsp)
	movq	76(%rsp), %rdi
	movss	%xmm0, 0(%r13)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movl	n(%rip), %ecx
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z35__device_stub__Z10kernelFuncPfS_S_iPfS_S_i
.L17:
	movq	%r12, %rdi
	call	cudaEventCreate@PLT
	movq	%rbp, %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	n(%rip), %edx
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	c(%rip), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	44(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	cvtsi2ssl	n(%rip), %xmm1
	movq	24(%rsp), %rdi
	movss	.LC7(%rip), %xmm0
	mulss	%xmm1, %xmm0
	mulss	%xmm1, %xmm0
	movss	.LC6(%rip), %xmm1
	mulss	.LC5(%rip), %xmm0
	mulss	44(%rsp), %xmm1
	divss	%xmm1, %xmm0
	movss	%xmm0, (%rbx)
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$104, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14matrixMultiplyPfS_S_S_S_, .-_Z14matrixMultiplyPfS_S_S_S_
	.section	.rodata.str1.1
.LC8:
	.string	"runtime-mm-gpu-optimized.txt"
.LC9:
	.string	"\nDevice %d: %s\"\n"
.LC10:
	.string	"maxGridSize: %d %d %d\n"
.LC11:
	.string	"maxThreadsDim: %d %d %d\n"
.LC12:
	.string	"maxThreadsPerBlock: %d\n"
.LC13:
	.string	"warpSize: %d\n"
.LC14:
	.string	"totalGlobalMem(MB): %d\n"
.LC15:
	.string	"sharedMemPerBlock: %d\n"
.LC16:
	.string	"gpu N*N=%d\n"
.LC17:
	.string	"gpu-optimized"
.LC18:
	.string	"gpu N*N %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC8(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC9(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$1080, %rsp
	.cfi_def_cfa_offset 1136
	movq	%fs:40, %rax
	movq	%rax, 1064(%rsp)
	xorl	%eax, %eax
	call	remove@PLT
	leaq	20(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
.L21:
	cmpl	%ebx, 20(%rsp)
	leaq	32(%rsp), %rbp
	jle	.L32
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	%ebx, %edx
	movq	%rbp, %rcx
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebx
	call	__printf_chk@PLT
	jmp	.L21
.L32:
	movq	%rbp, %rdi
	xorl	%esi, %esi
	leaq	.LC16(%rip), %rbp
	call	cudaGetDeviceProperties_v2@PLT
	movl	376(%rsp), %r8d
	xorl	%eax, %eax
	movl	372(%rsp), %ecx
	movl	368(%rsp), %edx
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	364(%rsp), %r8d
	xorl	%eax, %eax
	movl	360(%rsp), %ecx
	movl	356(%rsp), %edx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	352(%rsp), %edx
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	340(%rsp), %edx
	leaq	.LC13(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	320(%rsp), %rdx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	shrq	$20, %rdx
	call	__printf_chk@PLT
	movq	328(%rsp), %rdx
	leaq	.LC15(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$1280, %eax
.L23:
	movl	%eax, n(%rip)
	cmpl	$10000, %eax
	jg	.L28
	imull	%eax, %eax
	movslq	%eax, %rbx
	leaq	0(,%rbx,4), %r12
	salq	$5, %rbx
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, a(%rip)
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, b(%rip)
	call	malloc@PLT
	movq	%rax, c(%rip)
	cmpq	%rbx, 320(%rsp)
	jb	.L24
	xorl	%edi, %edi
	call	srand@PLT
	movl	n(%rip), %esi
	movq	a(%rip), %rdi
	imull	%esi, %esi
	call	_Z4fillPfi
	movl	n(%rip), %esi
	movq	b(%rip), %rdi
	imull	%esi, %esi
	call	_Z4fillPfi
	movl	n(%rip), %edx
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	24(%rsp), %rcx
	leaq	28(%rsp), %r8
	movq	b(%rip), %rsi
	movq	a(%rip), %rdi
	movq	c(%rip), %rdx
	call	_Z14matrixMultiplyPfS_S_S_S_
	movss	28(%rsp), %xmm1
	movss	24(%rsp), %xmm0
	leaq	.LC17(%rip), %rdi
	movl	n(%rip), %esi
	call	_Z4savePciff
.L24:
	movl	n(%rip), %ebx
	movq	320(%rsp), %r14
	movl	%ebx, %r12d
	imull	%ebx, %r12d
	movslq	%r12d, %rax
	salq	$5, %rax
	cmpq	%rax, %r14
	jnb	.L25
	movl	%ebx, %eax
	movl	$2, %r13d
	sarl	%r12d
	subq	$52428800, %r14
	cltd
	movslq	%r12d, %r12
	idivl	%r13d
	salq	$2, %r12
	imull	%eax, %ebx
	movslq	%ebx, %r15
	leaq	0(,%r15,4), %rdi
	salq	$5, %r15
	movq	%rdi, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, a1(%rip)
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, a2(%rip)
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, b1(%rip)
	call	malloc@PLT
	movq	%rax, b2(%rip)
	movl	%ebx, %eax
	cltd
	idivl	%r13d
	movslq	%eax, %rbx
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, c1(%rip)
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, c2(%rip)
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, c3(%rip)
	call	malloc@PLT
	movq	%rax, c4(%rip)
	cmpq	%r15, %r14
	jnb	.L26
.L28:
	call	cudaThreadExit@PLT
	movq	1064(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L26:
	xorl	%edi, %edi
	leaq	24(%rsp), %r12
	leaq	.LC17(%rip), %rbx
	call	srand@PLT
	movl	n(%rip), %esi
	movq	a1(%rip), %rdi
	movl	%esi, %eax
	cltd
	idivl	%r13d
	imull	%eax, %esi
	call	_Z4fillPfi
	movl	n(%rip), %esi
	movq	a2(%rip), %rdi
	movl	%esi, %eax
	cltd
	idivl	%r13d
	leaq	28(%rsp), %r13
	imull	%eax, %esi
	call	_Z4fillPfi
	movl	n(%rip), %esi
	movq	b1(%rip), %rdi
	imull	%esi, %esi
	sarl	%esi
	call	_Z4fillPfi
	movl	n(%rip), %esi
	movq	b2(%rip), %rdi
	imull	%esi, %esi
	sarl	%esi
	call	_Z4fillPfi
	movl	n(%rip), %edx
	leaq	.LC18(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	c1(%rip), %rdx
	movq	%r13, %r8
	movq	%r12, %rcx
	movq	b1(%rip), %rsi
	movq	a1(%rip), %rdi
	call	_Z14matrixMultiplyPfS_S_S_S_
	movss	28(%rsp), %xmm1
	movss	24(%rsp), %xmm0
	movq	%rbx, %rdi
	movl	n(%rip), %esi
	call	_Z4savePciff
	movq	c2(%rip), %rdx
	movq	%r13, %r8
	movq	%r12, %rcx
	movq	b2(%rip), %rsi
	movq	a1(%rip), %rdi
	call	_Z14matrixMultiplyPfS_S_S_S_
	movss	28(%rsp), %xmm1
	movss	24(%rsp), %xmm0
	movq	%rbx, %rdi
	movl	n(%rip), %esi
	call	_Z4savePciff
	movq	c3(%rip), %rdx
	movq	%r13, %r8
	movq	%r12, %rcx
	movq	b1(%rip), %rsi
	movq	a2(%rip), %rdi
	call	_Z14matrixMultiplyPfS_S_S_S_
	movss	28(%rsp), %xmm1
	movss	24(%rsp), %xmm0
	movq	%rbx, %rdi
	movl	n(%rip), %esi
	call	_Z4savePciff
	movq	b2(%rip), %rsi
	movq	%r13, %r8
	movq	%r12, %rcx
	movq	a2(%rip), %rdi
	movq	c4(%rip), %rdx
	call	_Z14matrixMultiplyPfS_S_S_S_
	movss	28(%rsp), %xmm1
	movss	24(%rsp), %xmm0
	movq	%rbx, %rdi
	movl	n(%rip), %esi
	call	_Z4savePciff
.L25:
	movq	a(%rip), %rdi
	call	free@PLT
	movq	a2(%rip), %rdi
	call	free@PLT
	movq	a1(%rip), %rdi
	call	free@PLT
	movq	b(%rip), %rdi
	call	free@PLT
	movq	b2(%rip), %rdi
	call	free@PLT
	movq	b1(%rip), %rdi
	call	free@PLT
	movq	c(%rip), %rdi
	call	free@PLT
	movq	c2(%rip), %rdi
	call	free@PLT
	movq	c1(%rip), %rdi
	call	free@PLT
	movq	c4(%rip), %rdi
	call	free@PLT
	movq	c3(%rip), %rdi
	call	free@PLT
	movl	n(%rip), %eax
	addl	$256, %eax
	jmp	.L23
.L29:
	addq	$1080, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z10kernelFuncPfS_S_i"
	.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	.LC19(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10kernelFuncPfS_S_i(%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
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	c4
	.align 8
	.type	c4, @object
	.size	c4, 8
c4:
	.zero	8
	.globl	c3
	.align 8
	.type	c3, @object
	.size	c3, 8
c3:
	.zero	8
	.globl	c2
	.align 8
	.type	c2, @object
	.size	c2, 8
c2:
	.zero	8
	.globl	b2
	.align 8
	.type	b2, @object
	.size	b2, 8
b2:
	.zero	8
	.globl	a2
	.align 8
	.type	a2, @object
	.size	a2, 8
a2:
	.zero	8
	.globl	c1
	.align 8
	.type	c1, @object
	.size	c1, 8
c1:
	.zero	8
	.globl	b1
	.align 8
	.type	b1, @object
	.size	b1, 8
b1:
	.zero	8
	.globl	a1
	.align 8
	.type	a1, @object
	.size	a1, 8
a1:
	.zero	8
	.globl	c
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	b
	.align 8
	.type	b, @object
	.size	b, 8
b:
	.zero	8
	.globl	a
	.align 8
	.type	a, @object
	.size	a, 8
a:
	.zero	8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC4:
	.long	1157234688
	.align 4
.LC5:
	.long	1082130432
	.align 4
.LC6:
	.long	1233125376
	.align 4
.LC7:
	.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 <stdio.h>
#include <time.h>
#include <hip/hip_runtime.h>

const int MIN_SIZE=1280; 
const int MAX_SIZE=10000;
const int STEP_SIZE=256;
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
float* a;
float* b;
float* c;
float* a1;
float* b1;
float* c1;
float* a2;
float* b2;
float* c2;
float* c3;
float* c4;
int n;

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
__global__ void kernelFunc(float* ad, float* bd, float* cd, int n) {
    __shared__ float as[32][32];
    __shared__ float bs[32][32];

    int tx = threadIdx.x;
    int ty = threadIdx.y;
    
  int x = (blockIdx.x * blockDim.x) + tx;
	int y = (blockIdx.y * blockDim.y) + ty;

    if ((x<n)&(y<n) )
	{

    float v = 0.0f;
    
    int yn = y * n;
    int s = n / 32;
    for(int m=0; m<s; m++) {
        int m32 = m * 32;
        as[ty][tx] = ad[yn + (m32 + tx)];
        bs[ty][tx] = bd[(m32 + ty) * n + x];
        
        __syncthreads();
        
        for(int i=0; i<32; i++) {
            v += as[ty][i] * bs[i][tx];
        }
        
        __syncthreads();
    }
    
    cd[yn + x] = v;   
	}
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void matrixMultiply(float* ad,float* bd,float* cd,float *H2DBandWidthInMBs,float *D2HBandWidthInMbs) {
	

    hipMalloc((void**)&ad, n * n * sizeof(float));
    hipMalloc((void**)&bd, n * n * sizeof(float));
    hipMalloc((void**)&cd, n * n * sizeof(float));

    hipEvent_t start, stop;

	float time;

	hipEventCreate(&start);

	hipEventCreate(&stop);

	hipEventRecord( start, 0 );


    hipMemcpy(ad, a, n * n * sizeof(float), hipMemcpyHostToDevice);
    hipMemcpy(bd, b, n * n * sizeof(float), hipMemcpyHostToDevice);

	hipEventRecord( stop, 0 );

	hipEventSynchronize( stop );

	hipEventElapsedTime( &time, start, stop );

	hipEventDestroy( start );

	hipEventDestroy( stop );

	*H2DBandWidthInMBs = (1e3f * 2*n*n* sizeof(float)) /
                     (time* (float)(1 << 20));
	//printf("HostToDevice bandwidthInMBs %f\n",H2DBandWidthInMBs );
	//printf("cudaMemcpyHostToDevice(ms) %f\n", 1000*(tc1 - tc0) / (float) CLOCKS_PER_SEC);
    dim3 block(32, 32);           
    dim3 grid((n+31)/32, (n+31)/32);
    
    kernelFunc<<<grid, block>>>(ad, bd, cd, n);

	float time1;

	hipEventCreate(&start);

	hipEventCreate(&stop);

	hipEventRecord( start, 0 );
	
    hipMemcpy(c, cd, n * n * sizeof(float), hipMemcpyDeviceToHost);

	hipEventRecord( stop, 0 );

	hipEventSynchronize( stop );

	hipEventElapsedTime( &time1, start, stop );

	hipEventDestroy( start );

	hipEventDestroy( stop );

	*D2HBandWidthInMbs = (1e3f * n*n* sizeof(float)) /
                     (time1* (float)(1 << 20));
	//printf("DeviceToHostbandwidthInMBs %f\n",D2HBandWidthInMbs );
	//printf("cudaMemcpyDeviceToHost(ms) %f\n", 1000*(tg1 - tg0) / (float) CLOCKS_PER_SEC);
    hipFree(ad);
    hipFree(bd);
    hipFree(cd);
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void fill(float* data, int size) {
    for (int i=0; i<size; ++i)
        data[i] = rand() / (float) RAND_MAX;
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void save(char* name, int n, float H2DBandWidthInMBs,float D2HBandWidthInMbs) {
	char fname[128];
	FILE* f;
/*
	sprintf(fname, "results/result-mm-%s_%d.txt", name, n);
	f = fopen(fname, "w");
	for (int i=0; i<n * n; ++i)
		fprintf(f, "%f\n", c[i]);
	fclose(f);
*/	
	sprintf(fname, "runtime-mm-%s.txt", name);
	f = fopen(fname, "a");

	fprintf(f, "size of matrix%d : H2DBandWidthInMBs     %f D2HBandWidthInMbs    %f \n",  
		n, H2DBandWidthInMBs,D2HBandWidthInMbs);
	fclose(f);
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int main(int argc, char** argv) {
	remove("runtime-mm-gpu-optimized.txt");
	int devicenum,dev;
	struct hipDeviceProp_t p;
	hipGetDeviceCount(&devicenum);
	for (dev=0;dev<devicenum;dev++){
		hipGetDeviceProperties(&p, dev);
	printf("\nDevice %d: \%s\"\n",dev,p.name);
	}
    hipGetDeviceProperties(&p, 0);
    printf("maxGridSize: %d %d %d\n", p.maxGridSize[0], p.maxGridSize[1], p.maxGridSize[2]);
    printf("maxThreadsDim: %d %d %d\n", p.maxThreadsDim[0], p.maxThreadsDim[1], p.maxThreadsDim[2]);
    printf("maxThreadsPerBlock: %d\n", p.maxThreadsPerBlock);
    printf("warpSize: %d\n", p.warpSize);
    printf("totalGlobalMem(MB): %d\n", p.totalGlobalMem/1024/1024);
    printf("sharedMemPerBlock: %d\n", p.sharedMemPerBlock);
	float H2DBandWidthInMBs,D2HBandWidthInMbs;
	for(n=MIN_SIZE; n<=MAX_SIZE; n+=STEP_SIZE) {

		a = (float*)malloc(n * n * sizeof(float));
		b = (float*)malloc(n * n * sizeof(float));
		c = (float*)malloc(n * n * sizeof(float));
		
		if(n*n*sizeof(float)*8<=p.totalGlobalMem){
		srand(0);
		fill(a, n * n);
		fill(b, n * n);
		printf("gpu N*N=%d\n",n);
		//clock_t t0 = clock(); 
		matrixMultiply(a,b,c,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
		//clock_t t1 = clock(); 
		//printf("gpu time(ms)%f\n",(1000*(t1-t0)/(float) CLOCKS_PER_SEC));
		save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
		}

		if (n*n*sizeof(float)*8>p.totalGlobalMem){
		a1 = (float*)malloc(n/2 * n * sizeof(float));a2 = (float*)malloc(n/2 * n * sizeof(float));
		b1 = (float*)malloc(n* n/2 * sizeof(float));b2 = (float*)malloc(n * n/2 * sizeof(float));
		c1 = (float*)malloc(n/2 * n/2 * sizeof(float));c2 = (float*)malloc(n/2 * n/2 * sizeof(float));
		c3 = (float*)malloc(n/2 * n/2 * sizeof(float));c4 = (float*)malloc(n/2 * n/2 * sizeof(float));
		if (n/2*n*sizeof(float)*8> (p.totalGlobalMem-50*1024*1024))
			break;
		srand(0);
		fill(a1, n/2 * n);fill(a2, n/2 * n);
		fill(b1, n * n/2);fill(b2, n * n/2);
		printf("gpu N*N %d\n",n);

		//clock_t Mt0 = clock(); 
			matrixMultiply(a1,b1,c1,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
			matrixMultiply(a1,b2,c2,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
			matrixMultiply(a2,b1,c3,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
			matrixMultiply(a2,b2,c4,&H2DBandWidthInMBs,&D2HBandWidthInMbs);
			save("gpu-optimized", n, H2DBandWidthInMBs,D2HBandWidthInMbs);
		//clock_t Mt1 = clock(); 
		//printf("gpu Matrix time(ms)%f\n",(1000*(Mt1-Mt0)/(float) CLOCKS_PER_SEC));		

		}
		
		free(a);free(a2);free(a1);
		free(b);free(b2);free(b1);
		free(c);free(c2);free(c1);
		free(c4);free(c3);
		
	}
    
	hipDeviceReset();
		return 0;
}

	.text
	.file	"io.hip"
	.globl	_Z25__device_stub__kernelFuncPfS_S_i # -- Begin function _Z25__device_stub__kernelFuncPfS_S_i
	.type	_Z25__device_stub__kernelFuncPfS_S_i,@function
_Z25__device_stub__kernelFuncPfS_S_i:   # @_Z25__device_stub__kernelFuncPfS_S_i
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z10kernelFuncPfS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z25__device_stub__kernelFuncPfS_S_i, .Lfunc_end0-_Z25__device_stub__kernelFuncPfS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z14matrixMultiplyPfS_S_S_S_
.LCPI1_0:
	.long	0x44fa0000                      # float 2000
.LCPI1_1:
	.long	0x40800000                      # float 4
.LCPI1_2:
	.long	0x49800000                      # float 1048576
.LCPI1_3:
	.long	0x447a0000                      # float 1000
	.text
	.globl	_Z14matrixMultiplyPfS_S_S_S_
	.type	_Z14matrixMultiplyPfS_S_S_S_,@function
_Z14matrixMultiplyPfS_S_S_S_:           # @_Z14matrixMultiplyPfS_S_S_S_
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%r8, %rbx
	movq	%rcx, %r14
	leaq	24(%rsp), %rbp
	movq	%rdi, (%rbp)
	leaq	16(%rsp), %r15
	movq	%rsi, (%r15)
	leaq	8(%rsp), %r12
	movq	%rdx, (%r12)
	movl	n(%rip), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	movq	%rbp, %rdi
	callq	hipMalloc
	movl	n(%rip), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	movq	%r15, %rdi
	callq	hipMalloc
	movl	n(%rip), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	movq	%r12, %rdi
	callq	hipMalloc
	leaq	40(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbp), %rdi
	movq	a(%rip), %rsi
	movl	n(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movq	b(%rip), %rsi
	movl	n(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rsi
	movq	(%r13), %rdx
	leaq	52(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	(%r12), %rdi
	callq	hipEventDestroy
	movq	(%r13), %rdi
	callq	hipEventDestroy
	movl	n(%rip), %eax
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm1
	mulss	%xmm0, %xmm1
	mulss	.LCPI1_1(%rip), %xmm1
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	mulss	.LCPI1_2(%rip), %xmm0
	divss	%xmm0, %xmm1
	movss	%xmm1, (%r14)
	leal	31(%rax), %ecx
	addl	$62, %eax
	testl	%ecx, %ecx
	cmovnsl	%ecx, %eax
	sarl	$5, %eax
	movq	%rax, %rdi
	shlq	$32, %rdi
	orq	%rax, %rdi
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	n(%rip), %ecx
	callq	_Z25__device_stub__kernelFuncPfS_S_i
.LBB1_2:
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventCreate
	leaq	32(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	movq	(%r14), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	c(%rip), %rdi
	movq	8(%rsp), %rsi
	movl	n(%rip), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r15), %rdi
	callq	hipEventSynchronize
	movq	(%r14), %rsi
	movq	(%r15), %rdx
	leaq	48(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	movq	(%r14), %rdi
	callq	hipEventDestroy
	movq	(%r15), %rdi
	callq	hipEventDestroy
	xorps	%xmm0, %xmm0
	cvtsi2ssl	n(%rip), %xmm0
	movss	.LCPI1_3(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm1
	mulss	%xmm0, %xmm1
	mulss	.LCPI1_1(%rip), %xmm1
	movss	(%r12), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	mulss	.LCPI1_2(%rip), %xmm0
	divss	%xmm0, %xmm1
	movss	%xmm1, (%rbx)
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z14matrixMultiplyPfS_S_S_S_, .Lfunc_end1-_Z14matrixMultiplyPfS_S_S_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z4fillPfi
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z4fillPfi
	.type	_Z4fillPfi,@function
_Z4fillPfi:                             # @_Z4fillPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB2_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
.LBB2_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB2_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
.LBB2_4:                                # %._crit_edge
	retq
.Lfunc_end2:
	.size	_Z4fillPfi, .Lfunc_end2-_Z4fillPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z4savePciff                    # -- Begin function _Z4savePciff
	.type	_Z4savePciff,@function
_Z4savePciff:                           # @_Z4savePciff
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$152, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movss	%xmm1, 12(%rsp)                 # 4-byte Spill
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	movl	%esi, %ebx
	movq	%rdi, %rdx
	leaq	16(%rsp), %r14
	movl	$.L.str, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.1, %esi
	movq	%r14, %rdi
	callq	fopen
	movq	%rax, %r14
	xorps	%xmm0, %xmm0
	cvtss2sd	8(%rsp), %xmm0                  # 4-byte Folded Reload
	xorps	%xmm1, %xmm1
	cvtss2sd	12(%rsp), %xmm1                 # 4-byte Folded Reload
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	movl	%ebx, %edx
	movb	$2, %al
	callq	fprintf
	movq	%r14, %rdi
	addq	$152, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end3:
	.size	_Z4savePciff, .Lfunc_end3-_Z4savePciff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$1496, %rsp                     # imm = 0x5D8
	.cfi_def_cfa_offset 1552
	.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	$.L.str.3, %edi
	callq	remove
	leaq	20(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	jle	.LBB4_3
# %bb.1:                                # %.lr.ph.preheader
	leaq	24(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.4, %edi
	movl	%ebp, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	cmpl	20(%rsp), %ebp
	jl	.LBB4_2
.LBB4_3:                                # %._crit_edge
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	336(%rbx), %esi
	movl	340(%rbx), %edx
	movl	344(%rbx), %ecx
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	324(%rbx), %esi
	movl	328(%rbx), %edx
	movl	332(%rbx), %ecx
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	320(%rbx), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	308(%rbx), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movq	288(%rbx), %rsi
	shrq	$20, %rsi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movq	296(%rbx), %rsi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1280, n(%rip)                  # imm = 0x500
	movl	$1280, %ebp                     # imm = 0x500
	leaq	16(%rsp), %rbx
	leaq	12(%rsp), %r14
.LBB4_4:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_7 Depth 2
                                        #     Child Loop BB4_10 Depth 2
                                        #     Child Loop BB4_17 Depth 2
                                        #     Child Loop BB4_20 Depth 2
                                        #     Child Loop BB4_24 Depth 2
                                        #     Child Loop BB4_27 Depth 2
	movl	%ebp, %r15d
	imull	%r15d, %r15d
	leaq	(,%r15,4), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, a(%rip)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, b(%rip)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, c(%rip)
	movq	%r15, %rax
	shlq	$5, %rax
	movq	312(%rsp), %r13
	cmpq	%r13, %rax
	ja	.LBB4_13
# %bb.5:                                #   in Loop: Header=BB4_4 Depth=1
	xorl	%ebp, %ebp
	xorl	%edi, %edi
	callq	srand
	movl	n(%rip), %r15d
	testl	%r15d, %r15d
	je	.LBB4_12
# %bb.6:                                # %.lr.ph.preheader.i
                                        #   in Loop: Header=BB4_4 Depth=1
	movq	a(%rip), %r12
	imull	%r15d, %r15d
	xorl	%r13d, %r13d
.LBB4_7:                                # %.lr.ph.i
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB4_7
# %bb.8:                                # %_Z4fillPfi.exit
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	n(%rip), %r15d
	testl	%r15d, %r15d
	je	.LBB4_12
# %bb.9:                                # %.lr.ph.preheader.i5
                                        #   in Loop: Header=BB4_4 Depth=1
	movq	b(%rip), %r12
	imull	%r15d, %r15d
	xorl	%r13d, %r13d
.LBB4_10:                               # %.lr.ph.i7
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB4_10
# %bb.11:                               # %_Z4fillPfi.exit11.loopexit
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	n(%rip), %ebp
.LBB4_12:                               # %_Z4fillPfi.exit11
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	$.L.str.11, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	movq	a(%rip), %rdi
	movq	b(%rip), %rsi
	movq	c(%rip), %rdx
	movq	%rbx, %rcx
	movq	%r14, %r8
	callq	_Z14matrixMultiplyPfS_S_S_S_
	movl	n(%rip), %esi
	movss	16(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	movl	$.L.str.12, %edi
	callq	_Z4savePciff
	movl	n(%rip), %ebp
	movq	312(%rsp), %r13
	movl	%ebp, %r15d
	imull	%r15d, %r15d
	movq	%r15, %rax
	shlq	$5, %rax
.LBB4_13:                               #   in Loop: Header=BB4_4 Depth=1
	cmpq	%r13, %rax
	jbe	.LBB4_30
# %bb.14:                               #   in Loop: Header=BB4_4 Depth=1
	movl	%ebp, %eax
	shrl	$31, %eax
	addl	%ebp, %eax
	sarl	%eax
	imull	%ebp, %eax
	movslq	%eax, %rbp
	leaq	(,%rbp,4), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, a1(%rip)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, a2(%rip)
	addl	%r15d, %r15d
	andl	$-4, %r15d
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, b1(%rip)
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, b2(%rip)
	movl	%ebp, %eax
	shrl	$31, %eax
	addl	%ebp, %eax
	sarl	%eax
	movslq	%eax, %r15
	shlq	$2, %r15
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, c1(%rip)
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, c2(%rip)
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, c3(%rip)
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, c4(%rip)
	shlq	$5, %rbp
	addq	$-52428800, %r13                # imm = 0xFCE00000
	cmpq	%r13, %rbp
	ja	.LBB4_31
# %bb.15:                               #   in Loop: Header=BB4_4 Depth=1
	xorl	%edi, %edi
	callq	srand
	movl	n(%rip), %esi
	movl	%esi, %eax
	shrl	$31, %eax
	addl	%esi, %eax
	sarl	%eax
	imull	%esi, %eax
	testl	%eax, %eax
	jle	.LBB4_22
# %bb.16:                               # %.lr.ph.preheader.i12
                                        #   in Loop: Header=BB4_4 Depth=1
	movq	a1(%rip), %r15
	movl	%eax, %r12d
	xorl	%r13d, %r13d
.LBB4_17:                               # %.lr.ph.i14
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r15,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB4_17
# %bb.18:                               # %_Z4fillPfi.exit18
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	n(%rip), %esi
	movl	%esi, %eax
	shrl	$31, %eax
	addl	%esi, %eax
	sarl	%eax
	imull	%esi, %eax
	testl	%eax, %eax
	jle	.LBB4_22
# %bb.19:                               # %.lr.ph.preheader.i19
                                        #   in Loop: Header=BB4_4 Depth=1
	movq	a2(%rip), %r15
	movl	%eax, %r12d
	xorl	%r13d, %r13d
.LBB4_20:                               # %.lr.ph.i21
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r15,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB4_20
# %bb.21:                               # %_Z4fillPfi.exit25.loopexit
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	n(%rip), %esi
.LBB4_22:                               # %_Z4fillPfi.exit25
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	%esi, %r15d
	imull	%r15d, %r15d
	cmpl	$2, %r15d
	jb	.LBB4_29
# %bb.23:                               # %.lr.ph.preheader.i26
                                        #   in Loop: Header=BB4_4 Depth=1
	movq	b1(%rip), %r12
	shrl	%r15d
	xorl	%r13d, %r13d
.LBB4_24:                               # %.lr.ph.i28
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB4_24
# %bb.25:                               # %_Z4fillPfi.exit32
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	n(%rip), %esi
	movl	%esi, %r15d
	imull	%r15d, %r15d
	cmpl	$2, %r15d
	jb	.LBB4_29
# %bb.26:                               # %.lr.ph.preheader.i33
                                        #   in Loop: Header=BB4_4 Depth=1
	movq	b2(%rip), %r12
	shrl	%r15d
	xorl	%r13d, %r13d
.LBB4_27:                               # %.lr.ph.i35
                                        #   Parent Loop BB4_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	movss	%xmm0, (%r12,%r13,4)
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB4_27
# %bb.28:                               # %_Z4fillPfi.exit39.loopexit
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	n(%rip), %esi
.LBB4_29:                               # %_Z4fillPfi.exit39
                                        #   in Loop: Header=BB4_4 Depth=1
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	movq	a1(%rip), %rdi
	movq	b1(%rip), %rsi
	movq	c1(%rip), %rdx
	movq	%rbx, %rcx
	movq	%r14, %r8
	callq	_Z14matrixMultiplyPfS_S_S_S_
	movl	n(%rip), %esi
	movss	16(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	movl	$.L.str.12, %edi
	callq	_Z4savePciff
	movq	a1(%rip), %rdi
	movq	b2(%rip), %rsi
	movq	c2(%rip), %rdx
	movq	%rbx, %rcx
	movq	%r14, %r8
	callq	_Z14matrixMultiplyPfS_S_S_S_
	movl	n(%rip), %esi
	movss	16(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	movl	$.L.str.12, %edi
	callq	_Z4savePciff
	movq	a2(%rip), %rdi
	movq	b1(%rip), %rsi
	movq	c3(%rip), %rdx
	movq	%rbx, %rcx
	movq	%r14, %r8
	callq	_Z14matrixMultiplyPfS_S_S_S_
	movl	n(%rip), %esi
	movss	16(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	movl	$.L.str.12, %edi
	callq	_Z4savePciff
	movq	a2(%rip), %rdi
	movq	b2(%rip), %rsi
	movq	c4(%rip), %rdx
	movq	%rbx, %rcx
	movq	%r14, %r8
	callq	_Z14matrixMultiplyPfS_S_S_S_
	movl	n(%rip), %esi
	movss	16(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	12(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	movl	$.L.str.12, %edi
	callq	_Z4savePciff
.LBB4_30:                               #   in Loop: Header=BB4_4 Depth=1
	movq	a(%rip), %rdi
	callq	free
	movq	a2(%rip), %rdi
	callq	free
	movq	a1(%rip), %rdi
	callq	free
	movq	b(%rip), %rdi
	callq	free
	movq	b2(%rip), %rdi
	callq	free
	movq	b1(%rip), %rdi
	callq	free
	movq	c(%rip), %rdi
	callq	free
	movq	c2(%rip), %rdi
	callq	free
	movq	c1(%rip), %rdi
	callq	free
	movq	c4(%rip), %rdi
	callq	free
	movq	c3(%rip), %rdi
	callq	free
	movl	n(%rip), %eax
	leal	256(%rax), %ebp
	movl	%ebp, n(%rip)
	cmpl	$9745, %eax                     # imm = 0x2611
	jl	.LBB4_4
.LBB4_31:
	callq	hipDeviceReset
	xorl	%eax, %eax
	addq	$1496, %rsp                     # imm = 0x5D8
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_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	$_Z10kernelFuncPfS_S_i, %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	a,@object                       # @a
	.bss
	.globl	a
	.p2align	3, 0x0
a:
	.quad	0
	.size	a, 8

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

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

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

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

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

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

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

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

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

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

	.type	n,@object                       # @n
	.globl	n
	.p2align	2, 0x0
n:
	.long	0                               # 0x0
	.size	n, 4

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"runtime-mm-%s.txt"
	.size	.L.str, 18

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"size of matrix%d : H2DBandWidthInMBs     %f D2HBandWidthInMbs    %f \n"
	.size	.L.str.2, 70

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"runtime-mm-gpu-optimized.txt"
	.size	.L.str.3, 29

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\nDevice %d: %s\"\n"
	.size	.L.str.4, 17

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"maxGridSize: %d %d %d\n"
	.size	.L.str.5, 23

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"maxThreadsDim: %d %d %d\n"
	.size	.L.str.6, 25

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"maxThreadsPerBlock: %d\n"
	.size	.L.str.7, 24

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"warpSize: %d\n"
	.size	.L.str.8, 14

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"totalGlobalMem(MB): %d\n"
	.size	.L.str.9, 24

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"sharedMemPerBlock: %d\n"
	.size	.L.str.10, 23

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"gpu N*N=%d\n"
	.size	.L.str.11, 12

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"gpu-optimized"
	.size	.L.str.12, 14

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"gpu N*N %d\n"
	.size	.L.str.13, 12

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10kernelFuncPfS_S_i"
	.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

	.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 _Z25__device_stub__kernelFuncPfS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z10kernelFuncPfS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10kernelFuncPfS_S_i   ; -- Begin function _Z10kernelFuncPfS_S_i
	.globl	_Z10kernelFuncPfS_S_i
	.p2align	8
	.type	_Z10kernelFuncPfS_S_i,@function
_Z10kernelFuncPfS_S_i:                  ; @_Z10kernelFuncPfS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x2c
	s_load_b32 s2, s[0:1], 0x18
	v_and_b32_e32 v3, 0x3ff, v0
	v_bfe_u32 v2, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s3, 16
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[0:1], null, s14, s3, v[3:4]
	v_mad_u64_u32 v[4:5], null, s15, s4, v[2:3]
	s_mov_b32 s3, exec_lo
	v_max_i32_e32 v1, v0, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s2, v1
	s_cbranch_execz .LBB0_7
; %bb.1:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_mul_lo_u32 v1, v4, s2
	v_mov_b32_e32 v4, 0
	s_cmp_lt_i32 s2, 32
	s_cbranch_scc1 .LBB0_6
; %bb.2:                                ; %.lr.ph
	v_lshlrev_b32_e32 v4, 2, v3
	v_lshlrev_b32_e32 v5, 7, v2
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(VALU_DEP_4)
	v_add_nc_u32_e32 v3, v1, v3
	s_lshr_b32 s3, s3, 27
	v_or_b32_e32 v6, 0x1000, v4
	v_dual_mov_b32 v4, 0 :: v_dual_add_nc_u32 v7, v5, v4
	s_add_i32 s3, s2, s3
	s_mov_b32 s8, 0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u32_e32 v8, v6, v5
	s_ashr_i32 s3, s3, 5
.LBB0_3:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	s_lshl_b32 s9, s8, 5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v10, s9, v2
	v_add_nc_u32_e32 v9, s9, v3
	s_mov_b32 s9, 0
	v_mad_u64_u32 v[11:12], null, v10, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v10, 31, v9
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v12, 31, v11
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, vcc_lo, s4, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v11, vcc_lo, s6, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s7, v12, vcc_lo
	global_load_b32 v10, v[9:10], off
	global_load_b32 v11, v[11:12], off
	v_mov_b32_e32 v9, v6
	s_waitcnt vmcnt(1)
	ds_store_b32 v7, v10
	s_waitcnt vmcnt(0)
	ds_store_b32 v8, v11
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_4:                                ;   Parent Loop BB0_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v10, s9, v5
	s_add_i32 s9, s9, 4
	ds_load_b32 v11, v9
	ds_load_b32 v10, v10
	v_add_nc_u32_e32 v9, 0x80, v9
	s_cmpk_eq_i32 s9, 0x80
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v4, v10, v11
	s_cbranch_scc0 .LBB0_4
; %bb.5:                                ;   in Loop: Header=BB0_3 Depth=1
	s_add_i32 s8, s8, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s8, s3
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_3
.LBB0_6:                                ; %Flow63
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v1, v0
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v4, off
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10kernelFuncPfS_S_i
		.amdhsa_group_segment_fixed_size 8192
		.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 13
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z10kernelFuncPfS_S_i, .Lfunc_end0-_Z10kernelFuncPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 492
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 8192 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         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: 8192
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10kernelFuncPfS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10kernelFuncPfS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
