#include <bits/stdc++.h>
using namespace std;

// Kernel function for matrix multiplication
__global__
void GPUmatmul(int N, double *x, double *y, double *ans)
{
	//calculates unique thread ID in the block
	int t= (blockDim.x*blockDim.y)*threadIdx.z+(threadIdx.y*blockDim.x)+(threadIdx.x);
	//calculates unique block ID in the grid
	int b= (gridDim.x*gridDim.y)*blockIdx.z+(blockIdx.y*gridDim.x)+(blockIdx.x);
	//block size (this is redundant though)
	int T= blockDim.x*blockDim.y*blockDim.z;
	//grid size (this is redundant though)
	int B= gridDim.x*gridDim.y*gridDim.z;
	
	/*
	 * Each cell in the matrix is assigned to a different thread. 
	 * Each thread do O(N*number of asssigned cell) computation.
	 * Assigned cells of different threads does not overlape with
	 * each other. And so no need for synchronization.
	 */
	 
    for (int i=b;i<N;i+=B)
    {
		for(int j=t;j<N;j+=T)
		{
			for(int k=0;k<N;k++)
			{
				ans[i*N+j]+=(x[i*N+k]*y[k*N+j]);
			}
		}
	}
}

void CPUmatmul(int N,double *x, double *y, double *ans)
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			for(int k=0;k<N;k++)
			{
				ans[i*N+j]+=(x[i*N+k]*y[k*N+j]);
			}
		}
	}
}

bool check(int N,double *ans)
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			if(ans[i*N+j]!=20.0)return false;
		}
	}
	return true;
}


int main(void)
{
	//size of matrix
	int N = 1<<9;
	
	double *x, *y, *ans;

	// Allocate Unified Memory – accessible from CPU or GPU
	cudaMallocManaged(&x, N*N*sizeof(double));
	cudaMallocManaged(&y, N*N*sizeof(double));
	cudaMallocManaged(&ans, N*N*sizeof(double));

	// initialize x,y and ans arrays on the host
	for (int i = 0; i < N; i++) 
	{
		for(int j=0;j<N;j++)
		{
			x[i*N+j]=5;
			y[i*N+j]=(i==j?1:0);
			ans[i*N+j]=(double)0.000000000000;
		}
	}


	clock_t t;
	double avg=0;
	cout<<"Strting CPU computation"<<endl;
	for(int i=0;i<=3;i++)
	{
		t=clock();
		CPUmatmul(N, x, y,ans);
		t = clock() - t;
		if(i)avg+=t;  //we will ignore the first run
		printf ("It took CPU-%d %f ms.\n",i,(((double)t)/CLOCKS_PER_SEC)*1000);
	}
	avg/=3;
	avg/=CLOCKS_PER_SEC;
	avg*=1000;
	printf ("It took %lf ms on avg.\n",avg);
	if(check(N,ans))cout<<"RUN OK."<<endl;
	else cout<<"RUN NOT OK."<<endl;

	// initialize x,y and ans arrays on the host
	for (int i = 0; i < N; i++) 
	{
		for(int j=0;j<N;j++)
		{
			x[i*N+j]=5;
			y[i*N+j]=(i==j?1:0);
			ans[i*N+j]=(double)0.000000000000;
		}
	}
	avg=0;
	cout<<"Strting GPU computation"<<endl;
	// Run kernel on GPU
	for(int i=0;i<=3;i++)
	{
		t=clock();
		GPUmatmul<<<dim3(16,16,16), dim3(16,8,8)>>>(N, x, y,ans);
		cudaDeviceSynchronize();
		t = clock() - t;
		if(i)avg+=t; //we will ignore the first run
		printf ("It took GPU-%d %f ms.\n",i,(((double)t)/CLOCKS_PER_SEC)*1000);
	}
	avg/=3;
	avg/=CLOCKS_PER_SEC;
	avg*=1000;
	printf ("It took %lf ms on avg.\n",avg);
	if(check(N,ans))cout<<"RUN OK."<<endl;
	else cout<<"RUN NOT OK."<<endl;


	// Free memory
	cudaFree(x);
	cudaFree(y); 
	return 0;
}

	.file	"tmpxft_00299bae_00000000-6_MatMul.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB10830:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE10830:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB12555:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE12555:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z9CPUmatmuliPdS_S_
	.type	_Z9CPUmatmuliPdS_S_, @function
_Z9CPUmatmuliPdS_S_:
.LFB10825:
	.cfi_startproc
	endbr64
	movq	%rsi, %r8
	movslq	%edi, %rsi
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edi, %eax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rcx, %r10
	salq	$3, %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdx, %rbx
	xorl	%edx, %edx
.L4:
	cmpl	%eax, %ebp
	jge	.L3
	movq	%rbx, %r11
	leaq	(%r10,%rdx), %rcx
	leaq	(%r8,%rdx), %r13
	xorl	%r9d, %r9d
.L8:
	movq	%r11, %r12
	xorl	%edi, %edi
.L5:
	movsd	0(%r13,%rdi,8), %xmm0
	mulsd	(%r12), %xmm0
	incq	%rdi
	addq	%rsi, %r12
	addsd	(%rcx), %xmm0
	movsd	%xmm0, (%rcx)
	cmpl	%edi, %eax
	jg	.L5
	incl	%r9d
	addq	$8, %r11
	addq	$8, %rcx
	cmpl	%r9d, %eax
	jne	.L8
	incl	%ebp
	addq	%rsi, %rdx
	jmp	.L4
.L3:
	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
.LFE10825:
	.size	_Z9CPUmatmuliPdS_S_, .-_Z9CPUmatmuliPdS_S_
	.globl	_Z5checkiPd
	.type	_Z5checkiPd, @function
_Z5checkiPd:
.LFB10826:
	.cfi_startproc
	endbr64
	movslq	%edi, %rcx
	movsd	.LC0(%rip), %xmm0
	xorl	%edx, %edx
	salq	$3, %rcx
.L13:
	cmpl	%edi, %edx
	jge	.L21
	xorl	%eax, %eax
.L16:
	ucomisd	(%rsi,%rax,8), %xmm0
	jp	.L17
	jne	.L17
	incq	%rax
	cmpl	%eax, %edi
	jg	.L16
	incl	%edx
	addq	%rcx, %rsi
	jmp	.L13
.L21:
	movb	$1, %al
	ret
.L17:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE10826:
	.size	_Z5checkiPd, .-_Z5checkiPd
	.globl	_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_
	.type	_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_, @function
_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_:
.LFB10852:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%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)
	movq	%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	.L22
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z9GPUmatmuliPdS_S_(%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
.L22:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE10852:
	.size	_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_, .-_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_
	.globl	_Z9GPUmatmuliPdS_S_
	.type	_Z9GPUmatmuliPdS_S_, @function
_Z9GPUmatmuliPdS_S_:
.LFB10853:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_
	.cfi_endproc
.LFE10853:
	.size	_Z9GPUmatmuliPdS_S_, .-_Z9GPUmatmuliPdS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"Strting CPU computation"
.LC7:
	.string	"It took CPU-%d %f ms.\n"
.LC9:
	.string	"It took %lf ms on avg.\n"
.LC10:
	.string	"RUN OK."
.LC11:
	.string	"RUN NOT OK."
.LC12:
	.string	"Strting GPU computation"
.LC13:
	.string	"It took GPU-%d %f ms.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB10827:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$1, %edx
	movl	$2097152, %esi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	call	cudaMallocManaged@PLT
	leaq	32(%rsp), %rdi
	movl	$1, %edx
	movl	$2097152, %esi
	call	cudaMallocManaged@PLT
	leaq	40(%rsp), %rdi
	movl	$1, %edx
	movl	$2097152, %esi
	call	cudaMallocManaged@PLT
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	xorl	%edx, %edx
	movq	40(%rsp), %r8
.L28:
	movq	%rdx, %rax
	xorl	%ecx, %ecx
	salq	$12, %rax
.L30:
	movq	.LC3(%rip), %rbx
	xorps	%xmm0, %xmm0
	movq	%rbx, (%rsi,%rax)
	cmpl	%edx, %ecx
	jne	.L29
	movsd	.LC1(%rip), %xmm0
.L29:
	incl	%ecx
	movsd	%xmm0, (%rdi,%rax)
	movq	$0x000000000, (%r8,%rax)
	addq	$8, %rax
	cmpl	$512, %ecx
	jne	.L30
	incq	%rdx
	cmpq	$512, %rdx
	jne	.L28
	leaq	_ZSt4cout(%rip), %rbx
	leaq	.LC4(%rip), %rsi
	xorl	%ebp, %ebp
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	xorps	%xmm1, %xmm1
.L33:
	movsd	%xmm1, 8(%rsp)
	call	clock@PLT
	movq	40(%rsp), %rcx
	movq	32(%rsp), %rdx
	movl	$512, %edi
	movq	24(%rsp), %rsi
	movq	%rax, %r12
	call	_Z9CPUmatmuliPdS_S_
	call	clock@PLT
	movsd	8(%rsp), %xmm1
	subq	%r12, %rax
	testl	%ebp, %ebp
	cvtsi2sdq	%rax, %xmm0
	je	.L32
	addsd	%xmm0, %xmm1
.L32:
	movl	%ebp, %edx
	divsd	.LC5(%rip), %xmm0
	leaq	.LC7(%rip), %rsi
	movb	$1, %al
	mulsd	.LC6(%rip), %xmm0
	movl	$2, %edi
	incl	%ebp
	movsd	%xmm1, 8(%rsp)
	call	__printf_chk@PLT
	cmpl	$4, %ebp
	movsd	8(%rsp), %xmm1
	jne	.L33
	divsd	.LC8(%rip), %xmm1
	movaps	%xmm1, %xmm0
	divsd	.LC5(%rip), %xmm0
	leaq	.LC9(%rip), %rbp
	mulsd	.LC6(%rip), %xmm0
	movq	%rbp, %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	movq	40(%rsp), %rsi
	movl	$512, %edi
	call	_Z5checkiPd
	leaq	.LC11(%rip), %rsi
	testb	%al, %al
	je	.L59
	leaq	.LC10(%rip), %rsi
.L59:
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	xorl	%edx, %edx
	movq	40(%rsp), %r8
.L35:
	movq	%rdx, %rax
	xorl	%ecx, %ecx
	salq	$12, %rax
.L38:
	movq	.LC3(%rip), %r10
	xorps	%xmm0, %xmm0
	movq	%r10, (%rsi,%rax)
	cmpl	%edx, %ecx
	jne	.L37
	movsd	.LC1(%rip), %xmm0
.L37:
	incl	%ecx
	movsd	%xmm0, (%rdi,%rax)
	movq	$0x000000000, (%r8,%rax)
	addq	$8, %rax
	cmpl	$512, %ecx
	jne	.L38
	incq	%rdx
	cmpq	$512, %rdx
	jne	.L35
	leaq	.LC12(%rip), %rsi
	movq	%rbx, %rdi
	xorl	%r12d, %r12d
	xorl	%r15d, %r15d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movabsq	$34359738384, %r13
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L42:
	call	clock@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r13, %rdx
	movl	$8, %ecx
	movl	$16, %esi
	movq	%rax, %r14
	movabsq	$68719476752, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movq	40(%rsp), %rcx
	movq	32(%rsp), %rdx
	movl	$512, %edi
	movq	24(%rsp), %rsi
	call	_Z33__device_stub__Z9GPUmatmuliPdS_S_iPdS_S_
.L40:
	call	cudaDeviceSynchronize@PLT
	call	clock@PLT
	subq	%r14, %rax
	testl	%r12d, %r12d
	cvtsi2sdq	%rax, %xmm0
	je	.L41
	movq	%r15, %xmm2
	addsd	%xmm0, %xmm2
	movq	%xmm2, %r15
.L41:
	divsd	.LC5(%rip), %xmm0
	movl	%r12d, %edx
	movb	$1, %al
	incl	%r12d
	mulsd	.LC6(%rip), %xmm0
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpl	$4, %r12d
	jne	.L42
	movq	%r15, %xmm0
	movq	%rbp, %rsi
	movl	$2, %edi
	movb	$1, %al
	divsd	.LC8(%rip), %xmm0
	divsd	.LC5(%rip), %xmm0
	mulsd	.LC6(%rip), %xmm0
	call	__printf_chk@PLT
	movq	40(%rsp), %rsi
	movl	$512, %edi
	call	_Z5checkiPd
	leaq	.LC10(%rip), %rsi
	testb	%al, %al
	jne	.L60
	leaq	.LC11(%rip), %rsi
.L60:
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
	call	__stack_chk_fail@PLT
.L45:
	addq	$88, %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
.LFE10827:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z9GPUmatmuliPdS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB10855:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9GPUmatmuliPdS_S_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE10855:
	.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	1077149696
	.align 8
.LC1:
	.long	0
	.long	1072693248
	.align 8
.LC3:
	.long	0
	.long	1075052544
	.align 8
.LC5:
	.long	0
	.long	1093567616
	.align 8
.LC6:
	.long	0
	.long	1083129856
	.align 8
.LC8:
	.long	0
	.long	1074266112
	.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 <bits/stdc++.h>
using namespace std;

// Kernel function for matrix multiplication
__global__
void GPUmatmul(int N, double *x, double *y, double *ans)
{
	//calculates unique thread ID in the block
	int t= (blockDim.x*blockDim.y)*threadIdx.z+(threadIdx.y*blockDim.x)+(threadIdx.x);
	//calculates unique block ID in the grid
	int b= (gridDim.x*gridDim.y)*blockIdx.z+(blockIdx.y*gridDim.x)+(blockIdx.x);
	//block size (this is redundant though)
	int T= blockDim.x*blockDim.y*blockDim.z;
	//grid size (this is redundant though)
	int B= gridDim.x*gridDim.y*gridDim.z;
	
	/*
	 * Each cell in the matrix is assigned to a different thread. 
	 * Each thread do O(N*number of asssigned cell) computation.
	 * Assigned cells of different threads does not overlape with
	 * each other. And so no need for synchronization.
	 */
	 
    for (int i=b;i<N;i+=B)
    {
		for(int j=t;j<N;j+=T)
		{
			for(int k=0;k<N;k++)
			{
				ans[i*N+j]+=(x[i*N+k]*y[k*N+j]);
			}
		}
	}
}

void CPUmatmul(int N,double *x, double *y, double *ans)
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			for(int k=0;k<N;k++)
			{
				ans[i*N+j]+=(x[i*N+k]*y[k*N+j]);
			}
		}
	}
}

bool check(int N,double *ans)
{
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			if(ans[i*N+j]!=20.0)return false;
		}
	}
	return true;
}


int main(void)
{
	//size of matrix
	int N = 1<<9;
	
	double *x, *y, *ans;

	// Allocate Unified Memory – accessible from CPU or GPU
	hipMallocManaged(&x, N*N*sizeof(double));
	hipMallocManaged(&y, N*N*sizeof(double));
	hipMallocManaged(&ans, N*N*sizeof(double));

	// initialize x,y and ans arrays on the host
	for (int i = 0; i < N; i++) 
	{
		for(int j=0;j<N;j++)
		{
			x[i*N+j]=5;
			y[i*N+j]=(i==j?1:0);
			ans[i*N+j]=(double)0.000000000000;
		}
	}


	clock_t t;
	double avg=0;
	cout<<"Strting CPU computation"<<endl;
	for(int i=0;i<=3;i++)
	{
		t=clock();
		CPUmatmul(N, x, y,ans);
		t = clock() - t;
		if(i)avg+=t;  //we will ignore the first run
		printf ("It took CPU-%d %f ms.\n",i,(((double)t)/CLOCKS_PER_SEC)*1000);
	}
	avg/=3;
	avg/=CLOCKS_PER_SEC;
	avg*=1000;
	printf ("It took %lf ms on avg.\n",avg);
	if(check(N,ans))cout<<"RUN OK."<<endl;
	else cout<<"RUN NOT OK."<<endl;

	// initialize x,y and ans arrays on the host
	for (int i = 0; i < N; i++) 
	{
		for(int j=0;j<N;j++)
		{
			x[i*N+j]=5;
			y[i*N+j]=(i==j?1:0);
			ans[i*N+j]=(double)0.000000000000;
		}
	}
	avg=0;
	cout<<"Strting GPU computation"<<endl;
	// Run kernel on GPU
	for(int i=0;i<=3;i++)
	{
		t=clock();
		GPUmatmul<<<dim3(16,16,16), dim3(16,8,8)>>>(N, x, y,ans);
		hipDeviceSynchronize();
		t = clock() - t;
		if(i)avg+=t; //we will ignore the first run
		printf ("It took GPU-%d %f ms.\n",i,(((double)t)/CLOCKS_PER_SEC)*1000);
	}
	avg/=3;
	avg/=CLOCKS_PER_SEC;
	avg*=1000;
	printf ("It took %lf ms on avg.\n",avg);
	if(check(N,ans))cout<<"RUN OK."<<endl;
	else cout<<"RUN NOT OK."<<endl;


	// Free memory
	hipFree(x);
	hipFree(y); 
	return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z24__device_stub__GPUmatmuliPdS_S_ # -- Begin function _Z24__device_stub__GPUmatmuliPdS_S_
	.type	_Z24__device_stub__GPUmatmuliPdS_S_,@function
_Z24__device_stub__GPUmatmuliPdS_S_:    # @_Z24__device_stub__GPUmatmuliPdS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$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	4(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	24(%rsp), %rdx
	movq	%rcx, (%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	$_Z9GPUmatmuliPdS_S_, %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	_Z24__device_stub__GPUmatmuliPdS_S_, .Lfunc_end0-_Z24__device_stub__GPUmatmuliPdS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9CPUmatmuliPdS_S_             # -- Begin function _Z9CPUmatmuliPdS_S_
	.type	_Z9CPUmatmuliPdS_S_,@function
_Z9CPUmatmuliPdS_S_:                    # @_Z9CPUmatmuliPdS_S_
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jle	.LBB1_8
# %bb.1:                                # %.preheader23.lr.ph
	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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edi, %eax
	leaq	(,%rax,8), %r8
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.LBB1_2:                                # %.preheader.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
                                        #       Child Loop BB1_4 Depth 3
	movl	%r9d, %r11d
	leaq	(%rsi,%r11,8), %r11
	movq	%r10, %rbx
	imulq	%rax, %rbx
	leaq	(%rcx,%rbx,8), %rbx
	movq	%rdx, %r14
	xorl	%r15d, %r15d
.LBB1_3:                                # %.preheader
                                        #   Parent Loop BB1_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_4 Depth 3
	movsd	(%rbx,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movq	%r14, %r12
	xorl	%r13d, %r13d
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        #     Parent Loop BB1_3 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%r11,%r13,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%r12), %xmm1
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%rbx,%r15,8)
	incq	%r13
	addq	%r8, %r12
	cmpq	%r13, %rax
	jne	.LBB1_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_3 Depth=2
	incq	%r15
	addq	$8, %r14
	cmpq	%rax, %r15
	jne	.LBB1_3
# %bb.6:                                # %._crit_edge26
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%r10
	addl	%edi, %r9d
	cmpq	%rax, %r10
	jne	.LBB1_2
# %bb.7:
	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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
.LBB1_8:                                # %._crit_edge28
	retq
.Lfunc_end1:
	.size	_Z9CPUmatmuliPdS_S_, .Lfunc_end1-_Z9CPUmatmuliPdS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z5checkiPd
.LCPI2_0:
	.quad	0x4034000000000000              # double 20
	.text
	.globl	_Z5checkiPd
	.type	_Z5checkiPd,@function
_Z5checkiPd:                            # @_Z5checkiPd
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jle	.LBB2_1
# %bb.3:                                # %.preheader.lr.ph
	movl	%edi, %ecx
	xorl	%edx, %edx
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	xorl	%r8d, %r8d
	xorl	%eax, %eax
.LBB2_4:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_6 Depth 2
	movl	%edx, %r9d
	leaq	(%rsi,%r9,8), %r9
	xorl	%r10d, %r10d
.LBB2_6:                                #   Parent Loop BB2_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r9,%r10,8), %xmm1             # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	jne	.LBB2_2
	jp	.LBB2_2
# %bb.5:                                #   in Loop: Header=BB2_6 Depth=2
	incq	%r10
	cmpq	%r10, %rcx
	jne	.LBB2_6
# %bb.7:                                # %._crit_edge
                                        #   in Loop: Header=BB2_4 Depth=1
	incq	%r8
	cmpq	%rcx, %r8
	setae	%al
	addl	%edi, %edx
	cmpq	%rcx, %r8
	jne	.LBB2_4
	jmp	.LBB2_2
.LBB2_1:
	movb	$1, %al
.LBB2_2:                                # %.thread
	andb	$1, %al
                                        # kill: def $al killed $al killed $rax
	retq
.Lfunc_end2:
	.size	_Z5checkiPd, .Lfunc_end2-_Z5checkiPd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI3_1:
	.quad	0x8000000000000000              # double -0
.LCPI3_2:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI3_3:
	.quad	0x408f400000000000              # double 1000
.LCPI3_4:
	.quad	0x4008000000000000              # double 3
.LCPI3_5:
	.quad	0x4034000000000000              # double 20
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	32(%rsp), %rbx
	movl	$2097152, %esi                  # imm = 0x200000
	movq	%rbx, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	24(%rsp), %r14
	movl	$2097152, %esi                  # imm = 0x200000
	movq	%r14, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	16(%rsp), %r15
	movl	$2097152, %esi                  # imm = 0x200000
	movq	%r15, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%rbx), %rax
	movq	(%r14), %rcx
	xorl	%edx, %edx
	movq	(%r15), %rsi
	movabsq	$4617315517961601024, %r15      # imm = 0x4014000000000000
	movsd	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$4096, %edi                     # imm = 0x1000
.LBB3_1:                                # %.preheader101
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
	xorl	%r8d, %r8d
.LBB3_2:                                #   Parent Loop BB3_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r15, (%rax,%r8,8)
	movapd	%xmm0, %xmm1
	cmpq	%r8, %rdx
	je	.LBB3_4
# %bb.3:                                #   in Loop: Header=BB3_2 Depth=2
	xorpd	%xmm1, %xmm1
.LBB3_4:                                #   in Loop: Header=BB3_2 Depth=2
	movsd	%xmm1, (%rcx,%r8,8)
	movq	$0, (%rsi,%r8,8)
	incq	%r8
	cmpq	$512, %r8                       # imm = 0x200
	jne	.LBB3_2
# %bb.5:                                #   in Loop: Header=BB3_1 Depth=1
	incq	%rdx
	addq	%rdi, %rsi
	addq	%rdi, %rcx
	addq	%rdi, %rax
	cmpq	$512, %rdx                      # imm = 0x200
	jne	.LBB3_1
# %bb.6:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$23, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorpd	%xmm0, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
.LBB3_7:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_8 Depth 2
                                        #       Child Loop BB3_9 Depth 3
                                        #         Child Loop BB3_10 Depth 4
	callq	clock
	movq	%rax, %r14
	movq	32(%rsp), %rax
	movq	24(%rsp), %rcx
	movq	16(%rsp), %rdx
	xorl	%esi, %esi
.LBB3_8:                                # %.preheader.lr.ph.i
                                        #   Parent Loop BB3_7 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_9 Depth 3
                                        #         Child Loop BB3_10 Depth 4
	movq	%rsi, %rdi
	shlq	$12, %rdi
	addq	%rdx, %rdi
	movq	%rcx, %r8
	xorl	%r9d, %r9d
.LBB3_9:                                # %.preheader.i
                                        #   Parent Loop BB3_7 Depth=1
                                        #     Parent Loop BB3_8 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB3_10 Depth 4
	movsd	(%rdi,%r9,8), %xmm0             # xmm0 = mem[0],zero
	movq	%r8, %r10
	xorl	%r11d, %r11d
.LBB3_10:                               #   Parent Loop BB3_7 Depth=1
                                        #     Parent Loop BB3_8 Depth=2
                                        #       Parent Loop BB3_9 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movsd	(%rax,%r11,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%r10), %xmm1
	addsd	%xmm1, %xmm0
	movsd	%xmm0, (%rdi,%r9,8)
	incq	%r11
	addq	$4096, %r10                     # imm = 0x1000
	cmpq	$512, %r11                      # imm = 0x200
	jne	.LBB3_10
# %bb.11:                               # %._crit_edge.i83
                                        #   in Loop: Header=BB3_9 Depth=3
	incq	%r9
	addq	$8, %r8
	cmpq	$512, %r9                       # imm = 0x200
	jne	.LBB3_9
# %bb.12:                               # %._crit_edge26.i
                                        #   in Loop: Header=BB3_8 Depth=2
	incq	%rsi
	addq	$4096, %rax                     # imm = 0x1000
	cmpq	$512, %rsi                      # imm = 0x200
	jne	.LBB3_8
# %bb.13:                               # %_Z9CPUmatmuliPdS_S_.exit
                                        #   in Loop: Header=BB3_7 Depth=1
	callq	clock
	subq	%r14, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movsd	.LCPI3_1(%rip), %xmm1           # xmm1 = mem[0],zero
	testl	%ebx, %ebx
	je	.LBB3_15
# %bb.14:                               # %_Z9CPUmatmuliPdS_S_.exit
                                        #   in Loop: Header=BB3_7 Depth=1
	movapd	%xmm0, %xmm1
.LBB3_15:                               # %_Z9CPUmatmuliPdS_S_.exit
                                        #   in Loop: Header=BB3_7 Depth=1
	movsd	8(%rsp), %xmm2                  # 8-byte Reload
                                        # xmm2 = mem[0],zero
	addsd	%xmm1, %xmm2
	movsd	%xmm2, 8(%rsp)                  # 8-byte Spill
	divsd	.LCPI3_2(%rip), %xmm0
	mulsd	.LCPI3_3(%rip), %xmm0
	movl	$.L.str.1, %edi
	movl	%ebx, %esi
	movb	$1, %al
	callq	printf
	incl	%ebx
	cmpl	$4, %ebx
	jne	.LBB3_7
# %bb.16:
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	.LCPI3_4(%rip), %xmm0
	divsd	.LCPI3_2(%rip), %xmm0
	mulsd	.LCPI3_3(%rip), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	xorl	%ecx, %ecx
	movq	16(%rsp), %rax
	xorl	%edx, %edx
.LBB3_17:                               # %.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_19 Depth 2
	xorl	%esi, %esi
.LBB3_19:                               #   Parent Loop BB3_17 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rax,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	ucomisd	.LCPI3_5(%rip), %xmm0
	jne	.LBB3_21
	jp	.LBB3_21
# %bb.18:                               #   in Loop: Header=BB3_19 Depth=2
	incq	%rsi
	cmpq	$512, %rsi                      # imm = 0x200
	jne	.LBB3_19
# %bb.20:                               # %._crit_edge.i
                                        #   in Loop: Header=BB3_17 Depth=1
	cmpq	$511, %rcx                      # imm = 0x1FF
	leaq	1(%rcx), %rsi
	setae	%dl
	addq	$4096, %rax                     # imm = 0x1000
	movq	%rsi, %rcx
	cmpq	$512, %rsi                      # imm = 0x200
	jne	.LBB3_17
.LBB3_21:                               # %_Z5checkiPd.exit
	movl	$_ZSt4cout, %edi
	testb	$1, %dl
	je	.LBB3_23
# %bb.22:
	movl	$.L.str.3, %esi
	movl	$7, %edx
	jmp	.LBB3_24
.LBB3_23:
	movl	$.L.str.4, %esi
	movl	$11, %edx
.LBB3_24:
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	32(%rsp), %rax
	movq	24(%rsp), %rcx
	xorl	%edx, %edx
	movq	16(%rsp), %rsi
	movsd	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$4096, %edi                     # imm = 0x1000
.LBB3_25:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_26 Depth 2
	xorl	%r8d, %r8d
.LBB3_26:                               #   Parent Loop BB3_25 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r15, (%rax,%r8,8)
	movapd	%xmm0, %xmm1
	cmpq	%r8, %rdx
	je	.LBB3_28
# %bb.27:                               #   in Loop: Header=BB3_26 Depth=2
	xorpd	%xmm1, %xmm1
.LBB3_28:                               #   in Loop: Header=BB3_26 Depth=2
	movsd	%xmm1, (%rcx,%r8,8)
	movq	$0, (%rsi,%r8,8)
	incq	%r8
	cmpq	$512, %r8                       # imm = 0x200
	jne	.LBB3_26
# %bb.29:                               #   in Loop: Header=BB3_25 Depth=1
	incq	%rdx
	addq	%rdi, %rsi
	addq	%rdi, %rcx
	addq	%rdi, %rax
	cmpq	$512, %rdx                      # imm = 0x200
	jne	.LBB3_25
# %bb.30:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$23, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorpd	%xmm0, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
	movabsq	$68719476752, %r14              # imm = 0x1000000010
	movabsq	$34359738384, %r15              # imm = 0x800000010
.LBB3_31:                               # =>This Inner Loop Header: Depth=1
	callq	clock
	movq	%rax, %r12
	movq	%r14, %rdi
	movl	$16, %esi
	movq	%r15, %rdx
	movl	$8, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_33
# %bb.32:                               #   in Loop: Header=BB3_31 Depth=1
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rcx
	movl	$512, %edi                      # imm = 0x200
	callq	_Z24__device_stub__GPUmatmuliPdS_S_
.LBB3_33:                               #   in Loop: Header=BB3_31 Depth=1
	callq	hipDeviceSynchronize
	callq	clock
	subq	%r12, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movsd	.LCPI3_1(%rip), %xmm1           # xmm1 = mem[0],zero
	testl	%ebx, %ebx
	je	.LBB3_35
# %bb.34:                               #   in Loop: Header=BB3_31 Depth=1
	movapd	%xmm0, %xmm1
.LBB3_35:                               #   in Loop: Header=BB3_31 Depth=1
	movsd	8(%rsp), %xmm2                  # 8-byte Reload
                                        # xmm2 = mem[0],zero
	addsd	%xmm1, %xmm2
	movsd	%xmm2, 8(%rsp)                  # 8-byte Spill
	divsd	.LCPI3_2(%rip), %xmm0
	mulsd	.LCPI3_3(%rip), %xmm0
	movl	$.L.str.6, %edi
	movl	%ebx, %esi
	movb	$1, %al
	callq	printf
	incl	%ebx
	cmpl	$4, %ebx
	jne	.LBB3_31
# %bb.36:
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	.LCPI3_4(%rip), %xmm0
	divsd	.LCPI3_2(%rip), %xmm0
	mulsd	.LCPI3_3(%rip), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	xorl	%edx, %edx
	movq	16(%rsp), %rax
	xorl	%ecx, %ecx
	movsd	.LCPI3_5(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB3_37:                               # %.lr.ph.i85
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_39 Depth 2
	xorl	%esi, %esi
.LBB3_39:                               #   Parent Loop BB3_37 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rax,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	ucomisd	%xmm1, %xmm0
	jne	.LBB3_41
	jp	.LBB3_41
# %bb.38:                               #   in Loop: Header=BB3_39 Depth=2
	incq	%rsi
	cmpq	$512, %rsi                      # imm = 0x200
	jne	.LBB3_39
# %bb.40:                               # %._crit_edge.i92
                                        #   in Loop: Header=BB3_37 Depth=1
	cmpq	$511, %rdx                      # imm = 0x1FF
	leaq	1(%rdx), %rsi
	setae	%cl
	addq	$4096, %rax                     # imm = 0x1000
	movq	%rsi, %rdx
	cmpq	$512, %rsi                      # imm = 0x200
	jne	.LBB3_37
.LBB3_41:                               # %_Z5checkiPd.exit95
	movl	$_ZSt4cout, %edi
	testb	$1, %cl
	je	.LBB3_43
# %bb.42:
	movl	$.L.str.3, %esi
	movl	$7, %edx
	jmp	.LBB3_44
.LBB3_43:
	movl	$.L.str.4, %esi
	movl	$11, %edx
.LBB3_44:
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9GPUmatmuliPdS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9GPUmatmuliPdS_S_,@object     # @_Z9GPUmatmuliPdS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z9GPUmatmuliPdS_S_
	.p2align	3, 0x0
_Z9GPUmatmuliPdS_S_:
	.quad	_Z24__device_stub__GPUmatmuliPdS_S_
	.size	_Z9GPUmatmuliPdS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Strting CPU computation"
	.size	.L.str, 24

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"It took CPU-%d %f ms.\n"
	.size	.L.str.1, 23

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"It took %lf ms on avg.\n"
	.size	.L.str.2, 24

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"RUN OK."
	.size	.L.str.3, 8

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"RUN NOT OK."
	.size	.L.str.4, 12

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Strting GPU computation"
	.size	.L.str.5, 24

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"It took GPU-%d %f ms.\n"
	.size	.L.str.6, 23

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

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

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9GPUmatmuliPdS_S_     ; -- Begin function _Z9GPUmatmuliPdS_S_
	.globl	_Z9GPUmatmuliPdS_S_
	.p2align	8
	.type	_Z9GPUmatmuliPdS_S_,@function
_Z9GPUmatmuliPdS_S_:                    ; @_Z9GPUmatmuliPdS_S_
; %bb.0:
	s_clause 0x1
	s_load_b64 s[6:7], s[0:1], 0x20
	s_load_b32 s2, s[0:1], 0x0
	s_add_u32 s4, s0, 32
	s_addc_u32 s5, s1, 0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s3, s7, s6
	s_mul_i32 s6, s6, s14
	s_mul_i32 s7, s3, s15
	s_add_i32 s6, s6, s13
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s20, s6, s7
	s_cmp_ge_i32 s20, s2
	s_cbranch_scc1 .LBB0_9
; %bb.1:                                ; %.preheader45.lr.ph
	s_clause 0x1
	s_load_b64 s[10:11], s[4:5], 0xc
	s_load_b32 s21, s[0:1], 0x28
	v_bfe_u32 v1, v0, 20, 10
	v_bfe_u32 v2, v0, 10, 10
	v_dual_mov_b32 v11, 0 :: v_dual_and_b32 v0, 0x3ff, v0
	s_mul_i32 s14, s2, s20
	s_load_b64 s[8:9], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s10, 16
	s_and_b32 s5, s10, 0xffff
	s_mul_i32 s21, s21, s3
	s_mul_i32 s10, s4, s5
	v_mul_u32_u24_e32 v2, s5, v2
	v_mul_lo_u32 v1, s10, v1
	s_load_b128 s[4:7], s[0:1], 0x8
	s_and_b32 s0, s11, 0xffff
	s_cmp_gt_i32 s2, 0
	s_mul_i32 s10, s10, s0
	s_cselect_b32 s22, -1, 0
	s_ashr_i32 s3, s2, 31
	s_ashr_i32 s11, s10, 31
	v_add3_u32 v0, v2, v0, v1
	s_lshl_b64 s[12:13], s[10:11], 3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v1, 31, v0
	v_cmp_gt_i32_e64 s0, s2, v0
	v_lshlrev_b64 v[1:2], 3, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	s_lshl_b64 s[6:7], s[2:3], 3
	s_mul_i32 s3, s21, s2
.LBB0_2:                                ; %.preheader45
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
                                        ;       Child Loop BB0_6 Depth 3
	s_and_saveexec_b32 s11, s0
	s_cbranch_execz .LBB0_8
; %bb.3:                                ; %.preheader.lr.ph
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_ashr_i32 s15, s14, 31
	v_dual_mov_b32 v4, v2 :: v_dual_mov_b32 v3, v1
	s_lshl_b64 s[16:17], s[14:15], 3
	v_mov_b32_e32 v12, v0
	s_add_u32 s16, s4, s16
	s_addc_u32 s17, s5, s17
	s_mul_i32 s15, s20, s2
	s_mov_b32 s23, 0
.LBB0_4:                                ; %.preheader
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_6 Depth 3
	s_and_not1_b32 vcc_lo, exec_lo, s22
	s_cbranch_vccnz .LBB0_7
; %bb.5:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_4 Depth=2
	v_dual_mov_b32 v10, v4 :: v_dual_add_nc_u32 v5, s15, v12
	v_mov_b32_e32 v9, v3
	s_mov_b64 s[18:19], s[16:17]
	s_mov_b32 s1, s2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v6, 31, v5
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s8, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s9, v6, vcc_lo
	global_load_b64 v[7:8], v[5:6], off
.LBB0_6:                                ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_4 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	global_load_b64 v[13:14], v11, s[18:19]
	global_load_b64 v[15:16], v[9:10], off
	v_add_co_u32 v9, vcc_lo, v9, s6
	s_add_i32 s1, s1, -1
	v_add_co_ci_u32_e32 v10, vcc_lo, s7, v10, vcc_lo
	s_add_u32 s18, s18, 8
	s_addc_u32 s19, s19, 0
	s_cmp_eq_u32 s1, 0
	s_waitcnt vmcnt(0)
	v_fma_f64 v[7:8], v[13:14], v[15:16], v[7:8]
	global_store_b64 v[5:6], v[7:8], off
	s_cbranch_scc0 .LBB0_6
.LBB0_7:                                ; %._crit_edge
                                        ;   in Loop: Header=BB0_4 Depth=2
	v_add_nc_u32_e32 v12, s10, v12
	v_add_co_u32 v3, s1, v3, s12
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v4, s1, s13, v4, s1
	v_cmp_le_i32_e32 vcc_lo, s2, v12
	s_or_b32 s23, vcc_lo, s23
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s23
	s_cbranch_execnz .LBB0_4
.LBB0_8:                                ; %Flow75
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s11
	s_add_i32 s20, s20, s21
	s_add_i32 s14, s14, s3
	s_cmp_ge_i32 s20, s2
	s_cbranch_scc0 .LBB0_2
.LBB0_9:                                ; %._crit_edge50
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9GPUmatmuliPdS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 13
		.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 1
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 2
		.amdhsa_next_free_vgpr 17
		.amdhsa_next_free_sgpr 24
		.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	_Z9GPUmatmuliPdS_S_, .Lfunc_end0-_Z9GPUmatmuliPdS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 516
; NumSgprs: 26
; NumVgprs: 17
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 3
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 26
; NumVGPRsForWavesPerEU: 17
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 13
; 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: 1
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 2
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
