#include <stdio.h>
#include <cuda_runtime.h>
//#include <cutil.h>

#define TILE_WIDTH 64
#define WIDTH_PER_THREAD 2
#define N 4096


void err_handling(cudaError_t *err, const char *str)
{
	if (*err != cudaSuccess) {
		printf("%s\n", str);
		exit(EXIT_FAILURE);
	}
}

__global__ void matMul(const float *A, const float *B, float *C, int m, int k, int n)
{
	__shared__ float sh_A[TILE_WIDTH][TILE_WIDTH];
	__shared__ float sh_B00[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];
	__shared__ float sh_B01[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];
	__shared__ float sh_B10[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];
	__shared__ float sh_B11[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];

	int x = threadIdx.x; int y = threadIdx.y;
	int tx = threadIdx.x*WIDTH_PER_THREAD; int ty = threadIdx.y*WIDTH_PER_THREAD;

	
	int r = blockIdx.y*TILE_WIDTH + y;
	//int c = blockIdx.x*TILE_WIDTH + x;
	int row = blockIdx.y*TILE_WIDTH + ty;
	int col = blockIdx.x*TILE_WIDTH + tx;

	float c00 = 0.0;
	float c01 = 0.0;
	float c10 = 0.0;
	float c11 = 0.0;

	float a00 = 0.0;
	float a01 = 0.0;
	float a10 = 0.0;
	float a11 = 0.0;

	float b00 = 0.0;
	float b01 = 0.0;
	float b10 = 0.0;
	float b11 = 0.0;
	
	for (int t = 0; t < k/TILE_WIDTH; ++t) {
		sh_A[y][x]       = A[r*k      + t*TILE_WIDTH + x];
		sh_A[y][x+32]    = A[r*k      + t*TILE_WIDTH + x + 32];
		sh_A[y+32][x]    = A[(r+32)*k + t*TILE_WIDTH + x];
		sh_A[y+32][x+32] = A[(r+32)*k + t*TILE_WIDTH + x + 32];
		sh_B00[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty)*k + col];
		sh_B01[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty)*k + col+1];
		sh_B10[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty+1)*k + col];
		sh_B11[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty+1)*k + col+1];
		__syncthreads();

		for (int i = 0; i < TILE_WIDTH; i += WIDTH_PER_THREAD) {
			a00 = sh_A[ty][i];
			a01 = sh_A[ty][i+1];
			a10 = sh_A[ty+1][i];
			a11 = sh_A[ty+1][i+1];

			b00 = sh_B00[i/WIDTH_PER_THREAD][x];
			b01 = sh_B01[i/WIDTH_PER_THREAD][x];
			b10 = sh_B10[i/WIDTH_PER_THREAD][x];
			b11 = sh_B11[i/WIDTH_PER_THREAD][x];
			
			c00 += a00*b00 + a01*b10;
			c01 += a00*b01 + a01*b11;
			c10 += a10*b00 + a11*b10;
			c11 += a10*b01 + a11*b11;
		}
		__syncthreads();
	}
	C[row*n + col] = c00;
	C[row*n + col+1] = c01;
	C[(row+1)*n + col] = c10;
	C[(row+1)*n + col+1] = c11;
}

int main(void)
{
	cudaError_t err = cudaSuccess;
	
	int m = N;
	int n = N;
	int k = N;
	
	float *A = (float*)malloc(m*k*sizeof(float));
	float *B = (float*)malloc(k*n*sizeof(float));
	float *C = (float*)malloc(m*n*sizeof(float));

	if (A == NULL || B == NULL || C == NULL) {
		printf("allocate host error!\n");
		return 1;
	}

	for (int i = 0; i < m*k; ++i) {
		A[i] = rand()/(float)RAND_MAX;
	}

	for (int i = 0; i < k*n; ++i) {
		B[i] = rand()/(float)RAND_MAX;
	}

	for (int i = 0; i < m*n; ++i) {
		C[i] = rand()/(float)RAND_MAX;
	}

	float *dev_A = NULL;
	float *dev_B = NULL;
	float *dev_C = NULL;

	err = cudaMalloc((void**)&dev_A, m*k*sizeof(float));
	err_handling(&err, "allocate devecie error A!");

	err = cudaMalloc((void**)&dev_B, k*n*sizeof(float));
	err_handling(&err, "allocate devecie error B!");

	err = cudaMalloc((void**)&dev_C, m*n*sizeof(float));
	err_handling(&err, "allocate devecie error C!");
	
	err = cudaMemcpy(dev_A, A, m*k*sizeof(float), cudaMemcpyHostToDevice);
	err_handling(&err, "memcpy to A error!");

	err = cudaMemcpy(dev_B, B, k*n*sizeof(float), cudaMemcpyHostToDevice);
	err_handling(&err, "memcpy to B error!");

	dim3 dimGrid((m-1)/TILE_WIDTH+1, (n-1)/TILE_WIDTH+1, 1);
	dim3 dimBlock(TILE_WIDTH/WIDTH_PER_THREAD, TILE_WIDTH/WIDTH_PER_THREAD, 1);

	cudaEvent_t start, stop;

	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	
	cudaEventRecord(start, 0);
	matMul<<<dimGrid, dimBlock>>>(dev_A, dev_B, dev_C, m, k, n);
	cudaEventRecord(stop, 0);

	cudaEventSynchronize(start);
	cudaEventSynchronize(stop);

	float time_elapsed = 0;
	cudaEventElapsedTime(&time_elapsed, start, stop);
	printf("%fms\n", time_elapsed);

	err = cudaMemcpy(C, dev_C, m*n*sizeof(float), cudaMemcpyDeviceToHost);
	err_handling(&err, "memcpy to host C error!");

	printf("%f %f\n", C[100*N+100], C[234*N+234]);

	err = cudaFree(dev_A);
	err_handling(&err, "mem free A error!");

	err = cudaFree(dev_B);
	err_handling(&err, "mem free B error!");

	err = cudaFree(dev_C);
	err_handling(&err, "mem free C error!");

	err = cudaDeviceReset();
	err_handling(&err, "device reset error!");

	return 0;
}

	.file	"tmpxft_002cfa2a_00000000-6_tiled_matmul-2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s\n"
	.text
	.globl	_Z12err_handlingP9cudaErrorPKc
	.type	_Z12err_handlingP9cudaErrorPKc, @function
_Z12err_handlingP9cudaErrorPKc:
.LFB2027:
	.cfi_startproc
	endbr64
	cmpl	$0, (%rdi)
	je	.L2
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rsi, %rdx
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12err_handlingP9cudaErrorPKc, .-_Z12err_handlingP9cudaErrorPKc
	.globl	_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii
	.type	_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii, @function
_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z6matMulPKfS0_Pfiii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L8:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii, .-_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii
	.globl	_Z6matMulPKfS0_Pfiii
	.type	_Z6matMulPKfS0_Pfiii, @function
_Z6matMulPKfS0_Pfiii:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii
	.cfi_endproc
.LFE2054:
	.size	_Z6matMulPKfS0_Pfiii, .-_Z6matMulPKfS0_Pfiii
	.section	.rodata.str1.1
.LC1:
	.string	"allocate host error!\n"
.LC3:
	.string	"allocate devecie error A!"
.LC4:
	.string	"allocate devecie error B!"
.LC5:
	.string	"allocate devecie error C!"
.LC6:
	.string	"memcpy to A error!"
.LC7:
	.string	"memcpy to B error!"
.LC9:
	.string	"%fms\n"
.LC10:
	.string	"memcpy to host C error!"
.LC11:
	.string	"%f %f\n"
.LC12:
	.string	"mem free A error!"
.LC13:
	.string	"mem free B error!"
.LC14:
	.string	"mem free C error!"
.LC15:
	.string	"device reset error!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%edx, %edx
	movl	$67108864, %edi
	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
	subq	$88, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	movl	%edx, (%rsp)
	call	malloc@PLT
	movl	$67108864, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movl	$67108864, %edi
	movq	%rax, %r12
	call	malloc@PLT
	testq	%r13, %r13
	movq	%rax, %rbp
	sete	%al
	testq	%r12, %r12
	sete	%dl
	orb	%dl, %al
	jne	.L22
	xorl	%ebx, %ebx
	testq	%rbp, %rbp
	jne	.L14
.L22:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L13
.L14:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, 0(%r13,%rbx,4)
	incq	%rbx
	cmpq	$16777216, %rbx
	jne	.L14
	xorl	%ebx, %ebx
.L17:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	cmpq	$16777216, %rbx
	jne	.L17
	xorl	%ebx, %ebx
.L18:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, 0(%rbp,%rbx,4)
	incq	%rbx
	cmpq	$16777216, %rbx
	jne	.L18
	xorl	%eax, %eax
	movq	%rsp, %rbx
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi
	movq	%rax, 8(%rsp)
	movq	%rax, 16(%rsp)
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	leaq	16(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	leaq	24(%rsp), %rdi
	movl	$67108864, %esi
	call	cudaMalloc@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	leaq	.LC6(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$67108864, %edx
	call	cudaMemcpy@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	leaq	32(%rsp), %rdi
	movabsq	$274877907008, %rax
	movl	$1, 56(%rsp)
	movq	%rax, 48(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	68(%rsp), %ecx
	movl	56(%rsp), %esi
	xorl	%r9d, %r9d
	movq	60(%rsp), %rdx
	movq	48(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$4096, %r9d
	movl	$4096, %r8d
	movq	8(%rsp), %rdi
	movl	$4096, %ecx
	call	_Z34__device_stub__Z6matMulPKfS0_PfiiiPKfS0_Pfiii
.L19:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	4(%rsp), %rdi
	movl	$0x00000000, 4(%rsp)
	call	cudaEventElapsedTime@PLT
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	4(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movl	$67108864, %edx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	leaq	.LC11(%rip), %rsi
	movb	$2, %al
	movl	$2, %edi
	cvtss2sd	1638800(%rbp), %xmm0
	cvtss2sd	3834792(%rbp), %xmm1
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC14(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	call	cudaDeviceReset@PLT
	leaq	.LC15(%rip), %rsi
	movq	%rbx, %rdi
	movl	%eax, (%rsp)
	call	_Z12err_handlingP9cudaErrorPKc
	xorl	%eax, %eax
.L13:
	movq	72(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$88, %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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC16:
	.string	"_Z6matMulPKfS0_Pfiii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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	.LC16(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6matMulPKfS0_Pfiii(%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
.LFE2056:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC2:
	.long	805306368
	.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 <hip/hip_runtime.h>
//#include <cutil.h>

#define TILE_WIDTH 64
#define WIDTH_PER_THREAD 2
#define N 4096


void err_handling(hipError_t *err, const char *str)
{
	if (*err != hipSuccess) {
		printf("%s\n", str);
		exit(EXIT_FAILURE);
	}
}

__global__ void matMul(const float *A, const float *B, float *C, int m, int k, int n)
{
	__shared__ float sh_A[TILE_WIDTH][TILE_WIDTH];
	__shared__ float sh_B00[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];
	__shared__ float sh_B01[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];
	__shared__ float sh_B10[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];
	__shared__ float sh_B11[TILE_WIDTH/WIDTH_PER_THREAD][TILE_WIDTH/WIDTH_PER_THREAD];

	int x = threadIdx.x; int y = threadIdx.y;
	int tx = threadIdx.x*WIDTH_PER_THREAD; int ty = threadIdx.y*WIDTH_PER_THREAD;

	
	int r = blockIdx.y*TILE_WIDTH + y;
	//int c = blockIdx.x*TILE_WIDTH + x;
	int row = blockIdx.y*TILE_WIDTH + ty;
	int col = blockIdx.x*TILE_WIDTH + tx;

	float c00 = 0.0;
	float c01 = 0.0;
	float c10 = 0.0;
	float c11 = 0.0;

	float a00 = 0.0;
	float a01 = 0.0;
	float a10 = 0.0;
	float a11 = 0.0;

	float b00 = 0.0;
	float b01 = 0.0;
	float b10 = 0.0;
	float b11 = 0.0;
	
	for (int t = 0; t < k/TILE_WIDTH; ++t) {
		sh_A[y][x]       = A[r*k      + t*TILE_WIDTH + x];
		sh_A[y][x+32]    = A[r*k      + t*TILE_WIDTH + x + 32];
		sh_A[y+32][x]    = A[(r+32)*k + t*TILE_WIDTH + x];
		sh_A[y+32][x+32] = A[(r+32)*k + t*TILE_WIDTH + x + 32];
		sh_B00[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty)*k + col];
		sh_B01[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty)*k + col+1];
		sh_B10[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty+1)*k + col];
		sh_B11[ty/WIDTH_PER_THREAD][tx/WIDTH_PER_THREAD] = B[(t*TILE_WIDTH + ty+1)*k + col+1];
		__syncthreads();

		for (int i = 0; i < TILE_WIDTH; i += WIDTH_PER_THREAD) {
			a00 = sh_A[ty][i];
			a01 = sh_A[ty][i+1];
			a10 = sh_A[ty+1][i];
			a11 = sh_A[ty+1][i+1];

			b00 = sh_B00[i/WIDTH_PER_THREAD][x];
			b01 = sh_B01[i/WIDTH_PER_THREAD][x];
			b10 = sh_B10[i/WIDTH_PER_THREAD][x];
			b11 = sh_B11[i/WIDTH_PER_THREAD][x];
			
			c00 += a00*b00 + a01*b10;
			c01 += a00*b01 + a01*b11;
			c10 += a10*b00 + a11*b10;
			c11 += a10*b01 + a11*b11;
		}
		__syncthreads();
	}
	C[row*n + col] = c00;
	C[row*n + col+1] = c01;
	C[(row+1)*n + col] = c10;
	C[(row+1)*n + col+1] = c11;
}

int main(void)
{
	hipError_t err = hipSuccess;
	
	int m = N;
	int n = N;
	int k = N;
	
	float *A = (float*)malloc(m*k*sizeof(float));
	float *B = (float*)malloc(k*n*sizeof(float));
	float *C = (float*)malloc(m*n*sizeof(float));

	if (A == NULL || B == NULL || C == NULL) {
		printf("allocate host error!\n");
		return 1;
	}

	for (int i = 0; i < m*k; ++i) {
		A[i] = rand()/(float)RAND_MAX;
	}

	for (int i = 0; i < k*n; ++i) {
		B[i] = rand()/(float)RAND_MAX;
	}

	for (int i = 0; i < m*n; ++i) {
		C[i] = rand()/(float)RAND_MAX;
	}

	float *dev_A = NULL;
	float *dev_B = NULL;
	float *dev_C = NULL;

	err = hipMalloc((void**)&dev_A, m*k*sizeof(float));
	err_handling(&err, "allocate devecie error A!");

	err = hipMalloc((void**)&dev_B, k*n*sizeof(float));
	err_handling(&err, "allocate devecie error B!");

	err = hipMalloc((void**)&dev_C, m*n*sizeof(float));
	err_handling(&err, "allocate devecie error C!");
	
	err = hipMemcpy(dev_A, A, m*k*sizeof(float), hipMemcpyHostToDevice);
	err_handling(&err, "memcpy to A error!");

	err = hipMemcpy(dev_B, B, k*n*sizeof(float), hipMemcpyHostToDevice);
	err_handling(&err, "memcpy to B error!");

	dim3 dimGrid((m-1)/TILE_WIDTH+1, (n-1)/TILE_WIDTH+1, 1);
	dim3 dimBlock(TILE_WIDTH/WIDTH_PER_THREAD, TILE_WIDTH/WIDTH_PER_THREAD, 1);

	hipEvent_t start, stop;

	hipEventCreate(&start);
	hipEventCreate(&stop);
	
	hipEventRecord(start, 0);
	matMul<<<dimGrid, dimBlock>>>(dev_A, dev_B, dev_C, m, k, n);
	hipEventRecord(stop, 0);

	hipEventSynchronize(start);
	hipEventSynchronize(stop);

	float time_elapsed = 0;
	hipEventElapsedTime(&time_elapsed, start, stop);
	printf("%fms\n", time_elapsed);

	err = hipMemcpy(C, dev_C, m*n*sizeof(float), hipMemcpyDeviceToHost);
	err_handling(&err, "memcpy to host C error!");

	printf("%f %f\n", C[100*N+100], C[234*N+234]);

	err = hipFree(dev_A);
	err_handling(&err, "mem free A error!");

	err = hipFree(dev_B);
	err_handling(&err, "mem free B error!");

	err = hipFree(dev_C);
	err_handling(&err, "mem free C error!");

	err = hipDeviceReset();
	err_handling(&err, "device reset error!");

	return 0;
}

	.text
	.file	"tiled_matmul-2.hip"
	.globl	_Z12err_handlingP10hipError_tPKc # -- Begin function _Z12err_handlingP10hipError_tPKc
	.type	_Z12err_handlingP10hipError_tPKc,@function
_Z12err_handlingP10hipError_tPKc:       # @_Z12err_handlingP10hipError_tPKc
	.cfi_startproc
# %bb.0:
	cmpl	$0, (%rdi)
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rsi, %rdi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z12err_handlingP10hipError_tPKc, .Lfunc_end0-_Z12err_handlingP10hipError_tPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__matMulPKfS0_Pfiii # -- Begin function _Z21__device_stub__matMulPKfS0_Pfiii
	.type	_Z21__device_stub__matMulPKfS0_Pfiii,@function
_Z21__device_stub__matMulPKfS0_Pfiii:   # @_Z21__device_stub__matMulPKfS0_Pfiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6matMulPKfS0_Pfiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z21__device_stub__matMulPKfS0_Pfiii, .Lfunc_end1-_Z21__device_stub__matMulPKfS0_Pfiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
	.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	$56, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	malloc
	movq	%rax, %r15
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	malloc
	movq	%rax, %r14
	movl	$67108864, %edi                 # imm = 0x4000000
	callq	malloc
	testq	%r15, %r15
	je	.LBB2_34
# %bb.1:
	testq	%r14, %r14
	je	.LBB2_34
# %bb.2:
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.LBB2_34
# %bb.3:                                # %.preheader103.preheader
	xorl	%r12d, %r12d
.LBB2_4:                                # %.preheader103
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%r15,%r12,4)
	incq	%r12
	cmpq	$16777216, %r12                 # imm = 0x1000000
	jne	.LBB2_4
# %bb.5:                                # %.preheader102.preheader
	xorl	%r12d, %r12d
.LBB2_6:                                # %.preheader102
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, (%r14,%r12,4)
	incq	%r12
	cmpq	$16777216, %r12                 # imm = 0x1000000
	jne	.LBB2_6
# %bb.7:                                # %.preheader.preheader
	xorl	%r12d, %r12d
.LBB2_8:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r12,4)
	incq	%r12
	cmpq	$16777216, %r12                 # imm = 0x1000000
	jne	.LBB2_8
# %bb.9:
	xorl	%eax, %eax
	leaq	32(%rsp), %rdi
	movq	%rax, (%rdi)
	movq	%rax, 16(%rsp)
	movq	%rax, 8(%rsp)
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_10
# %bb.12:                               # %_Z12err_handlingP10hipError_tPKc.exit
	leaq	16(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_13
# %bb.14:                               # %_Z12err_handlingP10hipError_tPKc.exit66
	leaq	8(%rsp), %rdi
	movl	$67108864, %esi                 # imm = 0x4000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_15
# %bb.16:                               # %_Z12err_handlingP10hipError_tPKc.exit69
	movq	32(%rsp), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_17
# %bb.18:                               # %_Z12err_handlingP10hipError_tPKc.exit72
	movq	16(%rsp), %rdi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_19
# %bb.20:                               # %_Z12err_handlingP10hipError_tPKc.exit75
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r14), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$274877907008, %rdi             # imm = 0x4000000040
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_22
# %bb.21:
	movq	32(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$4096, %ecx                     # imm = 0x1000
	movl	$4096, %r8d                     # imm = 0x1000
	movl	$4096, %r9d                     # imm = 0x1000
	callq	_Z21__device_stub__matMulPKfS0_Pfiii
.LBB2_22:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rdi
	callq	hipEventSynchronize
	leaq	52(%rsp), %r14
	movl	$0, (%r14)
	movq	40(%rsp), %rsi
	movq	24(%rsp), %rdx
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movq	8(%rsp), %rsi
	movl	$67108864, %edx                 # imm = 0x4000000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_23
# %bb.24:                               # %_Z12err_handlingP10hipError_tPKc.exit78
	xorps	%xmm0, %xmm0
	cvtss2sd	1638800(%rbx), %xmm0
	cvtss2sd	3834792(%rbx), %xmm1
	movl	$.L.str.9, %edi
	movb	$2, %al
	callq	printf
	movq	32(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB2_25
# %bb.26:                               # %_Z12err_handlingP10hipError_tPKc.exit81
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB2_27
# %bb.28:                               # %_Z12err_handlingP10hipError_tPKc.exit84
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB2_29
# %bb.30:                               # %_Z12err_handlingP10hipError_tPKc.exit87
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB2_31
# %bb.32:                               # %_Z12err_handlingP10hipError_tPKc.exit90
	xorl	%eax, %eax
	jmp	.LBB2_33
.LBB2_34:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %eax
.LBB2_33:
	addq	$56, %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
.LBB2_10:
	.cfi_def_cfa_offset 96
	movl	$.L.str.2, %edi
	jmp	.LBB2_11
.LBB2_13:
	movl	$.L.str.3, %edi
	jmp	.LBB2_11
.LBB2_15:
	movl	$.L.str.4, %edi
	jmp	.LBB2_11
.LBB2_17:
	movl	$.L.str.5, %edi
	jmp	.LBB2_11
.LBB2_19:
	movl	$.L.str.6, %edi
	jmp	.LBB2_11
.LBB2_23:
	movl	$.L.str.8, %edi
	jmp	.LBB2_11
.LBB2_25:
	movl	$.L.str.10, %edi
	jmp	.LBB2_11
.LBB2_27:
	movl	$.L.str.11, %edi
	jmp	.LBB2_11
.LBB2_29:
	movl	$.L.str.12, %edi
	jmp	.LBB2_11
.LBB2_31:
	movl	$.L.str.13, %edi
.LBB2_11:
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6matMulPKfS0_Pfiii, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6matMulPKfS0_Pfiii,@object    # @_Z6matMulPKfS0_Pfiii
	.section	.rodata,"a",@progbits
	.globl	_Z6matMulPKfS0_Pfiii
	.p2align	3, 0x0
_Z6matMulPKfS0_Pfiii:
	.quad	_Z21__device_stub__matMulPKfS0_Pfiii
	.size	_Z6matMulPKfS0_Pfiii, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"allocate devecie error A!"
	.size	.L.str.2, 26

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"allocate devecie error B!"
	.size	.L.str.3, 26

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"allocate devecie error C!"
	.size	.L.str.4, 26

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"memcpy to A error!"
	.size	.L.str.5, 19

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"memcpy to B error!"
	.size	.L.str.6, 19

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%fms\n"
	.size	.L.str.7, 6

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"memcpy to host C error!"
	.size	.L.str.8, 24

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%f %f\n"
	.size	.L.str.9, 7

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"mem free A error!"
	.size	.L.str.10, 18

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"mem free B error!"
	.size	.L.str.11, 18

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"mem free C error!"
	.size	.L.str.12, 18

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"device reset error!"
	.size	.L.str.13, 20

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6matMulPKfS0_Pfiii"
	.size	.L__unnamed_1, 21

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"allocate host error!"
	.size	.Lstr, 21

	.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 _Z21__device_stub__matMulPKfS0_Pfiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6matMulPKfS0_Pfiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6matMulPKfS0_Pfiii    ; -- Begin function _Z6matMulPKfS0_Pfiii
	.globl	_Z6matMulPKfS0_Pfiii
	.p2align	8
	.type	_Z6matMulPKfS0_Pfiii,@function
_Z6matMulPKfS0_Pfiii:                   ; @_Z6matMulPKfS0_Pfiii
; %bb.0:
	s_clause 0x2
	s_load_b64 s[2:3], s[0:1], 0x1c
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_and_b32_e32 v6, 0x3ff, v0
	v_bfe_u32 v1, v0, 10, 10
	s_lshl_b32 s8, s15, 6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v0, 1, v6
	v_lshlrev_b32_e32 v5, 1, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_lshl_add_u32 v0, s14, 6, v0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 64
	s_cbranch_scc1 .LBB0_5
; %bb.1:                                ; %.lr.ph
	v_lshlrev_b32_e32 v2, 2, v6
	v_lshlrev_b32_e32 v3, 7, v1
	v_add_nc_u32_e32 v4, s8, v1
	v_lshlrev_b32_e32 v14, 9, v1
	s_ashr_i32 s9, s2, 31
	v_lshl_add_u32 v9, v1, 8, v2
	v_mov_b32_e32 v1, 0
	v_or_b32_e32 v7, 0x4000, v2
	v_dual_mov_b32 v2, 0 :: v_dual_add_nc_u32 v13, v3, v2
	s_lshr_b32 s9, s9, 26
	v_add_nc_u32_e32 v15, 0x2000, v9
	s_delay_alu instid0(VALU_DEP_3)
	v_dual_mov_b32 v3, 0 :: v_dual_add_nc_u32 v10, v7, v3
	v_mul_lo_u32 v8, v4, s2
	v_dual_mov_b32 v4, 0 :: v_dual_add_nc_u32 v11, 0x5000, v13
	v_add_nc_u32_e32 v12, 0x6000, v13
	v_add_nc_u32_e32 v13, 0x7000, v13
	s_add_i32 s9, s2, s9
	s_lshl_b32 s10, s2, 5
	s_ashr_i32 s9, s9, 6
	s_mov_b32 s11, 0
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b32 s12, s11, 6
	v_add_nc_u32_e32 v17, s12, v5
	v_add3_u32 v16, s12, v6, v8
	s_mov_b32 s12, -2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[20:21], null, v17, s2, v[0:1]
	v_add_nc_u32_e32 v18, s10, v16
	v_ashrrev_i32_e32 v17, 31, v16
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v19, 31, v18
	v_add_nc_u32_e32 v22, s2, v20
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[16:17], 2, v[16:17]
	v_ashrrev_i32_e32 v21, 31, v20
	v_lshlrev_b64 v[18:19], 2, v[18:19]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v23, 31, v22
	v_add_co_u32 v16, vcc_lo, s4, v16
	s_delay_alu instid0(VALU_DEP_4)
	v_lshlrev_b64 v[20:21], 2, v[20:21]
	v_add_co_ci_u32_e32 v17, vcc_lo, s5, v17, vcc_lo
	v_add_co_u32 v18, vcc_lo, s4, v18
	v_lshlrev_b64 v[22:23], 2, v[22:23]
	v_add_co_ci_u32_e32 v19, vcc_lo, s5, v19, vcc_lo
	v_add_co_u32 v20, vcc_lo, s6, v20
	v_add_co_ci_u32_e32 v21, vcc_lo, s7, v21, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v22, vcc_lo, s6, v22
	v_add_co_ci_u32_e32 v23, vcc_lo, s7, v23, vcc_lo
	s_clause 0x3
	global_load_b32 v24, v[16:17], off
	global_load_b32 v25, v[16:17], off offset:128
	global_load_b32 v26, v[18:19], off
	global_load_b32 v27, v[18:19], off offset:128
	s_clause 0x1
	global_load_b64 v[18:19], v[20:21], off
	global_load_b64 v[20:21], v[22:23], off
	v_dual_mov_b32 v17, v7 :: v_dual_mov_b32 v16, v14
	s_waitcnt vmcnt(4)
	ds_store_2addr_b32 v9, v24, v25 offset1:32
	s_waitcnt vmcnt(2)
	ds_store_2addr_b32 v15, v26, v27 offset1:32
	s_waitcnt vmcnt(1)
	ds_store_b32 v10, v18
	ds_store_b32 v11, v19
	s_waitcnt vmcnt(0)
	ds_store_b32 v12, v20
	ds_store_b32 v13, v21
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	ds_load_2addr_b64 v[18:21], v16 offset1:32
	ds_load_2addr_stride64_b32 v[22:23], v17 offset0:32 offset1:48
	ds_load_2addr_stride64_b32 v[24:25], v17 offset1:16
	s_add_i32 s12, s12, 2
	v_add_nc_u32_e32 v16, 8, v16
	s_cmp_gt_u32 s12, 61
	s_waitcnt lgkmcnt(1)
	v_mul_f32_e32 v26, v19, v22
	v_dual_mul_f32 v19, v19, v23 :: v_dual_mul_f32 v22, v21, v22
	v_mul_f32_e32 v21, v21, v23
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_dual_fmac_f32 v26, v18, v24 :: v_dual_add_nc_u32 v17, 0x80, v17
	v_dual_fmac_f32 v19, v18, v25 :: v_dual_fmac_f32 v22, v20, v24
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v21, v20, v25
	v_dual_add_f32 v3, v3, v26 :: v_dual_add_f32 v4, v4, v19
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_add_f32 v1, v1, v22 :: v_dual_add_f32 v2, v2, v21
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s11, s11, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s11, s9
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_2
	s_branch .LBB0_6
.LBB0_5:
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v1, 0
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v3, 0
.LBB0_6:                                ; %Flow188
	v_add_nc_u32_e32 v7, s8, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[5:6], null, v7, s3, v[0:1]
	v_add_nc_u32_e32 v7, s3, v5
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v8, 31, v7
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_add_co_u32 v5, vcc_lo, s0, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	v_add_co_u32 v7, vcc_lo, s0, v7
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	s_clause 0x1
	global_store_b64 v[5:6], v[3:4], off
	global_store_b64 v[7:8], v[1:2], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6matMulPKfS0_Pfiii
		.amdhsa_group_segment_fixed_size 32768
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 36
		.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 28
		.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	_Z6matMulPKfS0_Pfiii, .Lfunc_end0-_Z6matMulPKfS0_Pfiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 792
; NumSgprs: 18
; NumVgprs: 28
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 32768 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 28
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
