#include <iostream>
#include <cuda_runtime.h>
#include <chrono>
#include <stdlib.h>
#include <stdio.h>

#define BLOCK 16

/*

0 0 X X    0 0 0 0
0 0 X X    0 0 0 0 
0 0 0 0    X X 0 0 
0 0 0 0    X X 0 0

*/

struct Matrix{
	int width;
	int height;
	float* elements;

};

__global__ void blockedMatMulKernel(const Matrix A, const Matrix B, Matrix C){
	int row = threadIdx.y;
	int col = threadIdx.x;
	if (blockDim.y * blockIdx.y + row >= A.height || blockDim.x * blockIdx.x + col >= B.width )
		return;
	float C_rc = 0; 
	for (int e = 0; e < A.width/blockDim.x; ++e){
		__shared__ float A_block [BLOCK][BLOCK];
		__shared__ float B_block [BLOCK][BLOCK];

		A_block[row][col] = A.elements[A.width * (blockDim.y * blockIdx.y + row) + blockDim.x * e + col];
		B_block[row][col] = B.elements[B.width * (e * blockDim.x + row) + blockIdx.x * blockDim.x + col];
		__syncthreads();

		for (int i = 0; i < BLOCK; ++i)
			C_rc += A_block[row][i] * B_block[i][col];

		__syncthreads(); // make sure that C is calculated before you go and overwrite A & B in next iter

	}

	C.elements[B.width * (blockDim.y * blockIdx.y + row) + col + blockDim.x * blockIdx.x] = C_rc;
	__syncthreads();
}

void matMulBlocked(Matrix A, Matrix B, Matrix C){
	Matrix d_A, d_B, d_C;

	cudaMalloc(&(d_A.elements), sizeof(float) * A.width * A.height);
	cudaMalloc(&(d_B.elements), sizeof(float) * B.width * B.height);
	cudaMalloc(&(d_C.elements), sizeof(float) * C.width * C.height);

	cudaMemcpy(d_A.elements, A.elements, sizeof(float) * A.width* A.height, cudaMemcpyHostToDevice);
	cudaMemcpy(d_B.elements, B.elements, sizeof(float) * B.width* B.height, cudaMemcpyHostToDevice);
	cudaMemcpy(d_C.elements, C.elements, sizeof(float) * C.width* C.height, cudaMemcpyHostToDevice);

	d_A.width = A.width;
	d_A.height = A.height;
	d_B.width = B.width;
	d_B.height = B.height;
	d_C.width = C.width;
	d_C.height = C.height;

	dim3 block (BLOCK,BLOCK);
	dim3 numBlocks ((A.height + BLOCK - 1)/BLOCK, (B.width + BLOCK - 1)/BLOCK);
	blockedMatMulKernel<<<numBlocks, block>>>(d_A, d_B, d_C);
	cudaDeviceSynchronize();

	cudaMemcpy(C.elements, d_C.elements, sizeof(float) * C.width* C.height, cudaMemcpyDeviceToHost);

	for (int i = 0; i < A.height; ++i){
		for (int j = 0; j < B.width; ++j){
			std::cout<<C.elements[i*B.width + j]<<" ";
		}
		std::cout<<std::endl;
	}

	cudaFree(d_A.elements);
	cudaFree(d_B.elements);
	cudaFree(d_C.elements);
}

void serialMatMul(int n, int p, int m, float* A, float* B, float* C){
	for (int i = 0; i < m; ++i){
		for (int j = 0; j < n; ++j){
			float sum = 0;
			for (int k = 0; k < p; ++k){
				sum += A[i*p + k] * B[k*n + j];
			}
			C[i * n + j] = sum;
		}
	}
}

int main(int argc, char* argv[]){
	if (argc < 4){
		std::cout<<"please include 3 integers for matrix dimensions"<<std::endl;
		exit(1);
	}

	int m = atoi(argv[1]);
	int p = atoi(argv[2]);
	int n = atoi(argv[3]);

	Matrix A, B, C;
	A.height = m;
	C.height = m;
	B.height = p;
	B.width = n;
	A.width = p;
	C.width = n;

	A.elements = new float[m*p];
	B.elements = new float[p*n];
	C.elements = new float[m*n];

	for (int i = 0; i < m; ++i)
		for (int j = 0; j < p; ++j)
			A.elements[i*p + j] = (float)rand()/(float)(RAND_MAX);

	for (int i = 0; i < p; ++i)
		for (int j = 0; j < n; ++j)		
			B.elements[i*n + j] = (float)rand()/(float)(RAND_MAX);

	auto s = std::chrono::high_resolution_clock::now();
    serialMatMul(n, p, m, A.elements, B.elements, C.elements);
    auto end = std::chrono::high_resolution_clock::now();
    auto diff = std::chrono::duration_cast<std::chrono::microseconds>(end - s);
    std::cout << "time: " << diff.count() << std::endl;
	for (int i = 0; i < m; ++i){
		for (int j = 0; j < n; ++j){
			std::cout<<C.elements[i*n + j]<<" ";
		}
		std::cout<<std::endl;
	}
	std::cout<<std::endl;

	cudaEvent_t start;
	cudaEvent_t stop;
	float time;

	cudaEventCreate(&start);
    cudaEventCreate(&stop);
	cudaEventRecord(start);

	matMulBlocked(A, B, C);

	cudaEventRecord(stop);
	cudaEventSynchronize(stop);
	cudaEventElapsedTime(&time, start, stop);

    std::cout<<"cuda time="<< time << std::endl;



	free(A.elements);
	free(B.elements);
	free(C.elements);

	return 0;
}
	.file	"tmpxft_002402b8_00000000-6_gemm_study.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3742:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3742:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4452:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4452:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z12serialMatMuliiiPfS_S_
	.type	_Z12serialMatMuliiiPfS_S_, @function
_Z12serialMatMuliiiPfS_S_:
.LFB3735:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%r10d, %r10d
	xorl	%r11d, %r11d
	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
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movslq	%edi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	salq	$2, %rbp
	xorl	%ebx, %ebx
.L4:
	cmpl	%r12d, %ebx
	jge	.L3
	movslq	%r11d, %rax
	leaq	(%r9,%rax,4), %r15
	movslq	%r10d, %rax
	leaq	(%rcx,%rax,4), %r14
	xorl	%eax, %eax
.L9:
	cmpl	%eax, %edi
	jle	.L6
	leaq	(%r8,%rax,4), %r13
	xorl	%edx, %edx
	xorps	%xmm0, %xmm0
.L7:
	cmpl	%edx, %esi
	jle	.L12
	movss	(%r14,%rdx,4), %xmm1
	mulss	0(%r13), %xmm1
	incq	%rdx
	addq	%rbp, %r13
	addss	%xmm1, %xmm0
	jmp	.L7
.L12:
	movss	%xmm0, (%r15,%rax,4)
	incq	%rax
	jmp	.L9
.L6:
	incl	%ebx
	addl	%edi, %r11d
	addl	%esi, %r10d
	jmp	.L4
.L3:
	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
.LFE3735:
	.size	_Z12serialMatMuliiiPfS_S_, .-_Z12serialMatMuliiiPfS_S_
	.globl	_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_
	.type	_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_, @function
_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_:
.LFB3764:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rcx
	movq	%rdi, 64(%rsp)
	movabsq	$4294967297, %rax
	movq	%rsi, 72(%rsp)
	leaq	16(%rsp), %rdi
	leaq	28(%rsp), %rsi
	movq	%rdx, 80(%rsp)
	movq	%rsp, %rdx
	movq	%rax, 16(%rsp)
	movl	$1, 24(%rsp)
	movq	%rax, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	8(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z19blockedMatMulKernel6MatrixS_S_(%rip), %rdi
	pushq	8(%rsp)
	.cfi_def_cfa_offset 128
	movq	44(%rsp), %rcx
	movl	52(%rsp), %r8d
	movq	32(%rsp), %rsi
	movl	40(%rsp), %edx
	leaq	80(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L13:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3764:
	.size	_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_, .-_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_
	.globl	_Z19blockedMatMulKernel6MatrixS_S_
	.type	_Z19blockedMatMulKernel6MatrixS_S_, @function
_Z19blockedMatMulKernel6MatrixS_S_:
.LFB3765:
	.cfi_startproc
	endbr64
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	movq	%rdi, 32(%rsp)
	leaq	32(%rsp), %rdi
	movq	%rsi, 40(%rsp)
	leaq	16(%rsp), %rsi
	movq	%rdx, 16(%rsp)
	movq	%rsp, %rdx
	movq	%rcx, 24(%rsp)
	movq	%r8, (%rsp)
	movq	%r9, 8(%rsp)
	call	_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_
	addq	$56, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3765:
	.size	_Z19blockedMatMulKernel6MatrixS_S_, .-_Z19blockedMatMulKernel6MatrixS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	" "
	.text
	.globl	_Z13matMulBlocked6MatrixS_S_
	.type	_Z13matMulBlocked6MatrixS_S_, @function
_Z13matMulBlocked6MatrixS_S_:
.LFB3734:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdx, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	sarq	$32, %r15
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r8, %r12
	movq	%rdi, %r8
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	sarq	$32, %r8
	movq	%r9, %rbp
	movq	%r12, %r14
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	movl	%r8d, %r13d
	sarq	$32, %r14
	subq	$200, %rsp
	.cfi_def_cfa_offset 256
	movq	%rcx, 32(%rsp)
	movq	%rsi, 24(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	movl	%edx, 20(%rsp)
	movslq	%edi, %rdx
	imulq	%r8, %rdx
	movq	%rdi, 56(%rsp)
	leaq	96(%rsp), %rdi
	movq	%r8, 48(%rsp)
	salq	$2, %rdx
	movq	%rdx, %rsi
	movq	%rdx, 40(%rsp)
	call	cudaMalloc@PLT
	movslq	%ebx, %rax
	leaq	112(%rsp), %rdi
	imulq	%r15, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movslq	%r12d, %rax
	leaq	128(%rsp), %rdi
	imulq	%r14, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movq	96(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	112(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdx
	movl	$1, %ecx
	movq	%rbp, %rsi
	movq	128(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	48(%rsp), %r8
	movl	$16, %esi
	xorl	%r9d, %r9d
	movabsq	$68719476752, %rcx
	movq	56(%rsp), %r10
	movl	%ebx, 104(%rsp)
	leal	15(%r8), %eax
	movl	%r8d, 92(%rsp)
	xorl	%r8d, %r8d
	cltd
	movq	%rcx, 64(%rsp)
	idivl	%esi
	movl	%r10d, 88(%rsp)
	movl	%r15d, 108(%rsp)
	movl	%r12d, 120(%rsp)
	movl	%r14d, 124(%rsp)
	movl	$1, 72(%rsp)
	movl	$1, 84(%rsp)
	movl	%eax, 76(%rsp)
	leal	15(%rbx), %eax
	cltd
	idivl	%esi
	movq	%rcx, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	movl	%eax, 80(%rsp)
	movq	76(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	movups	88(%rsp), %xmm1
	movups	104(%rsp), %xmm2
	leaq	168(%rsp), %rdx
	leaq	152(%rsp), %rsi
	movups	120(%rsp), %xmm3
	leaq	136(%rsp), %rdi
	movups	%xmm1, 136(%rsp)
	movups	%xmm2, 152(%rsp)
	movups	%xmm3, 168(%rsp)
	call	_Z48__device_stub__Z19blockedMatMulKernel6MatrixS_S_RK6MatrixS1_RS_
.L20:
	call	cudaDeviceSynchronize@PLT
	movq	(%rsp), %rdx
	movq	%rbp, %rdi
	xorl	%r12d, %r12d
	movq	128(%rsp), %rsi
	movl	$2, %ecx
	xorl	%r14d, %r14d
	call	cudaMemcpy@PLT
.L21:
	cmpl	%r13d, %r14d
	jge	.L23
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %rcx
.L24:
	cmpl	%r15d, 20(%rsp)
	jle	.L27
	leaq	_ZSt4cout(%rip), %rdi
	cvtss2sd	(%rcx,%r15,4), %xmm0
	movq	%rcx, (%rsp)
	incq	%r15
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	(%rsp), %rcx
	jmp	.L24
.L27:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incl	%r14d
	addl	%ebx, %r12d
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L21
.L23:
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	112(%rsp), %rdi
	call	cudaFree@PLT
	movq	128(%rsp), %rdi
	call	cudaFree@PLT
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$200, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3734:
	.size	_Z13matMulBlocked6MatrixS_S_, .-_Z13matMulBlocked6MatrixS_S_
	.section	.rodata.str1.1
.LC2:
	.string	"please include 3 integers for matrix dimensions"
.LC4:
	.string	"time: "
.LC5:
	.string	"cuda time="
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3736:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	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	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	jg	.L29
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %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
	movl	$1, %edi
	call	exit@PLT
.L29:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	movabsq	$2305843009213693950, %r15
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %r12d
	call	atoi@PLT
	movq	24(%rbx), %rdi
	movq	%r12, %r14
	movl	%eax, %ebp
	salq	$32, %r14
	call	atoi@PLT
	movl	%r12d, %edi
	movq	%rbp, %rcx
	movl	%ebp, %edx
	imull	%ebp, %edi
	movl	%eax, %ebx
	salq	$32, %rcx
	movl	%eax, %eax
	orq	%r14, %rdx
	orq	%rax, %rcx
	orq	%rax, %r14
	movq	%rcx, 16(%rsp)
	movslq	%edi, %rdi
	movq	%rdx, 24(%rsp)
	movq	%r14, 32(%rsp)
	cmpq	%rdi, %r15
	jb	.L30
	salq	$2, %rdi
	call	_Znam@PLT
	movl	%ebp, %edi
	imull	%ebx, %edi
	movq	%rax, %r13
	movslq	%edi, %rdi
	cmpq	%rdi, %r15
	jnb	.L31
.L30:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L47
	call	__cxa_throw_bad_array_new_length@PLT
.L31:
	salq	$2, %rdi
	call	_Znam@PLT
	movl	%r12d, %edi
	imull	%ebx, %edi
	movq	%rax, 8(%rsp)
	movslq	%edi, %rdi
	cmpq	%rdi, %r15
	jb	.L30
	salq	$2, %rdi
	call	_Znam@PLT
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	movq	%rax, %r14
.L33:
	cmpl	%r12d, %ecx
	jge	.L35
	movslq	%edx, %rax
	xorl	%r15d, %r15d
	leaq	0(%r13,%rax,4), %rsi
.L36:
	cmpl	%r15d, %ebp
	jle	.L48
	movl	%edx, 60(%rsp)
	movq	%rsi, 48(%rsp)
	movl	%ecx, 40(%rsp)
	call	rand@PLT
	movq	48(%rsp), %rsi
	movl	60(%rsp), %edx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC3(%rip), %xmm0
	movl	40(%rsp), %ecx
	movss	%xmm0, (%rsi,%r15,4)
	incq	%r15
	jmp	.L36
.L48:
	incl	%ecx
	addl	%ebp, %edx
	jmp	.L33
.L35:
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.L37:
	cmpl	%ebp, %ecx
	jge	.L39
	movq	8(%rsp), %rsi
	movslq	%edx, %rax
	xorl	%r15d, %r15d
	leaq	(%rsi,%rax,4), %rsi
.L40:
	cmpl	%r15d, %ebx
	jle	.L49
	movl	%edx, 60(%rsp)
	movq	%rsi, 48(%rsp)
	movl	%ecx, 40(%rsp)
	call	rand@PLT
	movq	48(%rsp), %rsi
	movl	60(%rsp), %edx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC3(%rip), %xmm0
	movl	40(%rsp), %ecx
	movss	%xmm0, (%rsi,%r15,4)
	incq	%r15
	jmp	.L40
.L49:
	incl	%ecx
	addl	%ebx, %edx
	jmp	.L37
.L39:
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	8(%rsp), %r8
	movq	%r14, %r9
	movl	%ebp, %esi
	movq	%r13, %rcx
	movl	%r12d, %edx
	movl	%ebx, %edi
	movq	%rax, %r15
	call	_Z12serialMatMuliiiPfS_S_
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	subq	%r15, %rax
	xorl	%r15d, %r15d
	cqto
	idivq	%rcx
	movq	%rax, %rbp
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %rsi
	xorl	%ebp, %ebp
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIlEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L41:
	cmpl	%r12d, %r15d
	jge	.L43
	movslq	%ebp, %rax
	xorl	%edx, %edx
	leaq	(%r14,%rax,4), %rcx
.L44:
	cmpl	%edx, %ebx
	jle	.L50
	leaq	_ZSt4cout(%rip), %rdi
	cvtss2sd	(%rcx,%rdx,4), %xmm0
	movq	%rcx, 48(%rsp)
	movq	%rdx, 40(%rsp)
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	40(%rsp), %rdx
	movq	48(%rsp), %rcx
	incq	%rdx
	jmp	.L44
.L50:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	incl	%r15d
	addl	%ebx, %ebp
	call	_ZNSolsEPFRSoS_E.isra.0
	jmp	.L41
.L43:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %r8
	movq	%r14, %r9
	movq	%r13, %rsi
	movq	8(%rsp), %rcx
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rdi
	call	_Z13matMulBlocked6MatrixS_S_
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	80(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	80(%rsp), %rdx
	movq	72(%rsp), %rsi
	leaq	68(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC5(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	68(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%r13, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
.L47:
	call	__stack_chk_fail@PLT
.L45:
	addq	$104, %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
.LFE3736:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z19blockedMatMulKernel6MatrixS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3767:
	.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	.LC6(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z19blockedMatMulKernel6MatrixS_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
.LFE3767:
	.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
.LC3:
	.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 <iostream>
#include <hip/hip_runtime.h>
#include <chrono>
#include <stdlib.h>
#include <stdio.h>

#define BLOCK 16

/*

0 0 X X    0 0 0 0
0 0 X X    0 0 0 0 
0 0 0 0    X X 0 0 
0 0 0 0    X X 0 0

*/

struct Matrix{
	int width;
	int height;
	float* elements;

};

__global__ void blockedMatMulKernel(const Matrix A, const Matrix B, Matrix C){
	int row = threadIdx.y;
	int col = threadIdx.x;
	if (blockDim.y * blockIdx.y + row >= A.height || blockDim.x * blockIdx.x + col >= B.width )
		return;
	float C_rc = 0; 
	for (int e = 0; e < A.width/blockDim.x; ++e){
		__shared__ float A_block [BLOCK][BLOCK];
		__shared__ float B_block [BLOCK][BLOCK];

		A_block[row][col] = A.elements[A.width * (blockDim.y * blockIdx.y + row) + blockDim.x * e + col];
		B_block[row][col] = B.elements[B.width * (e * blockDim.x + row) + blockIdx.x * blockDim.x + col];
		__syncthreads();

		for (int i = 0; i < BLOCK; ++i)
			C_rc += A_block[row][i] * B_block[i][col];

		__syncthreads(); // make sure that C is calculated before you go and overwrite A & B in next iter

	}

	C.elements[B.width * (blockDim.y * blockIdx.y + row) + col + blockDim.x * blockIdx.x] = C_rc;
	__syncthreads();
}

void matMulBlocked(Matrix A, Matrix B, Matrix C){
	Matrix d_A, d_B, d_C;

	hipMalloc(&(d_A.elements), sizeof(float) * A.width * A.height);
	hipMalloc(&(d_B.elements), sizeof(float) * B.width * B.height);
	hipMalloc(&(d_C.elements), sizeof(float) * C.width * C.height);

	hipMemcpy(d_A.elements, A.elements, sizeof(float) * A.width* A.height, hipMemcpyHostToDevice);
	hipMemcpy(d_B.elements, B.elements, sizeof(float) * B.width* B.height, hipMemcpyHostToDevice);
	hipMemcpy(d_C.elements, C.elements, sizeof(float) * C.width* C.height, hipMemcpyHostToDevice);

	d_A.width = A.width;
	d_A.height = A.height;
	d_B.width = B.width;
	d_B.height = B.height;
	d_C.width = C.width;
	d_C.height = C.height;

	dim3 block (BLOCK,BLOCK);
	dim3 numBlocks ((A.height + BLOCK - 1)/BLOCK, (B.width + BLOCK - 1)/BLOCK);
	blockedMatMulKernel<<<numBlocks, block>>>(d_A, d_B, d_C);
	hipDeviceSynchronize();

	hipMemcpy(C.elements, d_C.elements, sizeof(float) * C.width* C.height, hipMemcpyDeviceToHost);

	for (int i = 0; i < A.height; ++i){
		for (int j = 0; j < B.width; ++j){
			std::cout<<C.elements[i*B.width + j]<<" ";
		}
		std::cout<<std::endl;
	}

	hipFree(d_A.elements);
	hipFree(d_B.elements);
	hipFree(d_C.elements);
}

void serialMatMul(int n, int p, int m, float* A, float* B, float* C){
	for (int i = 0; i < m; ++i){
		for (int j = 0; j < n; ++j){
			float sum = 0;
			for (int k = 0; k < p; ++k){
				sum += A[i*p + k] * B[k*n + j];
			}
			C[i * n + j] = sum;
		}
	}
}

int main(int argc, char* argv[]){
	if (argc < 4){
		std::cout<<"please include 3 integers for matrix dimensions"<<std::endl;
		exit(1);
	}

	int m = atoi(argv[1]);
	int p = atoi(argv[2]);
	int n = atoi(argv[3]);

	Matrix A, B, C;
	A.height = m;
	C.height = m;
	B.height = p;
	B.width = n;
	A.width = p;
	C.width = n;

	A.elements = new float[m*p];
	B.elements = new float[p*n];
	C.elements = new float[m*n];

	for (int i = 0; i < m; ++i)
		for (int j = 0; j < p; ++j)
			A.elements[i*p + j] = (float)rand()/(float)(RAND_MAX);

	for (int i = 0; i < p; ++i)
		for (int j = 0; j < n; ++j)		
			B.elements[i*n + j] = (float)rand()/(float)(RAND_MAX);

	auto s = std::chrono::high_resolution_clock::now();
    serialMatMul(n, p, m, A.elements, B.elements, C.elements);
    auto end = std::chrono::high_resolution_clock::now();
    auto diff = std::chrono::duration_cast<std::chrono::microseconds>(end - s);
    std::cout << "time: " << diff.count() << std::endl;
	for (int i = 0; i < m; ++i){
		for (int j = 0; j < n; ++j){
			std::cout<<C.elements[i*n + j]<<" ";
		}
		std::cout<<std::endl;
	}
	std::cout<<std::endl;

	hipEvent_t start;
	hipEvent_t stop;
	float time;

	hipEventCreate(&start);
    hipEventCreate(&stop);
	hipEventRecord(start);

	matMulBlocked(A, B, C);

	hipEventRecord(stop);
	hipEventSynchronize(stop);
	hipEventElapsedTime(&time, start, stop);

    std::cout<<"cuda time="<< time << std::endl;



	free(A.elements);
	free(B.elements);
	free(C.elements);

	return 0;
}
	.text
	.file	"gemm_study.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z34__device_stub__blockedMatMulKernel6MatrixS_S_ # -- Begin function _Z34__device_stub__blockedMatMulKernel6MatrixS_S_
	.type	_Z34__device_stub__blockedMatMulKernel6MatrixS_S_,@function
_Z34__device_stub__blockedMatMulKernel6MatrixS_S_: # @_Z34__device_stub__blockedMatMulKernel6MatrixS_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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	80(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsi, 8(%rax)
	leaq	64(%rsp), %rsi
	movq	%rdx, (%rsi)
	movq	%rcx, 8(%rsi)
	leaq	48(%rsp), %rcx
	movq	%r8, (%rcx)
	movq	%r9, 8(%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rsi, 8(%rbx)
	movq	%rcx, 16(%rbx)
	leaq	32(%rsp), %r14
	leaq	16(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z19blockedMatMulKernel6MatrixS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z34__device_stub__blockedMatMulKernel6MatrixS_S_, .Lfunc_end0-_Z34__device_stub__blockedMatMulKernel6MatrixS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z13matMulBlocked6MatrixS_S_    # -- Begin function _Z13matMulBlocked6MatrixS_S_
	.type	_Z13matMulBlocked6MatrixS_S_,@function
_Z13matMulBlocked6MatrixS_S_:           # @_Z13matMulBlocked6MatrixS_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	$120, %rsp
	.cfi_def_cfa_offset 176
	.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	%r9, 8(%rsp)                    # 8-byte Spill
	movq	%r8, %r15
	movq	%rcx, 96(%rsp)                  # 8-byte Spill
	movq	%rdx, %rbp
	movq	%rsi, 80(%rsp)                  # 8-byte Spill
	movq	%rdi, %r13
	movq	%rdi, 88(%rsp)                  # 8-byte Spill
	movq	%rdi, %r14
	shrq	$32, %r14
	movq	%rdx, %rax
	shrq	$32, %rax
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	movq	%r8, %rax
	shrq	$32, %rax
	movq	%rax, 112(%rsp)                 # 8-byte Spill
	leaq	48(%rsp), %rdi
	movslq	%r13d, %rax
	sarq	$32, %r13
	imulq	%rax, %r13
	shlq	$2, %r13
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	64(%rsp), %rbx
	movslq	%ebp, %r12
	movq	%rbp, 16(%rsp)                  # 8-byte Spill
	sarq	$32, %rbp
	imulq	%r12, %rbp
	shlq	$2, %rbp
	movq	%rbx, %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movslq	%r15d, %rax
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	sarq	$32, %r15
	imulq	%rax, %r15
	shlq	$2, %r15
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	48(%rsp), %rax
	movq	(%rax), %rdi
	movq	80(%rsp), %rsi                  # 8-byte Reload
	movq	%r13, %rdx
	movq	%r14, %r13
	movq	8(%rsp), %r14                   # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbx), %rdi
	movq	96(%rsp), %rsi                  # 8-byte Reload
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rbx
	movq	(%rbx), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	88(%rsp), %rax                  # 8-byte Reload
	leaq	48(%rsp), %rcx
	movq	%rax, -8(%rcx)
	leaq	64(%rsp), %rcx
	movl	%r12d, -8(%rcx)
	movq	104(%rsp), %rax                 # 8-byte Reload
	movl	%eax, -4(%rcx)
	movq	72(%rsp), %rax                  # 8-byte Reload
	movl	%eax, -8(%rbx)
	leal	15(%r13), %eax
	leal	30(%r13), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$4, %ecx
	leal	15(%r12), %eax
	addl	$30, %r12d
	testl	%eax, %eax
	cmovnsl	%eax, %r12d
	movq	112(%rsp), %rax                 # 8-byte Reload
	movl	%eax, -4(%rbx)
	sarl	$4, %r12d
	shlq	$32, %r12
	orq	%rcx, %r12
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movq	%r12, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	40(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdx
	movq	64(%rsp), %rcx
	movq	24(%rsp), %r8
	movq	32(%rsp), %r9
	callq	_Z34__device_stub__blockedMatMulKernel6MatrixS_S_
.LBB1_2:
	callq	hipDeviceSynchronize
	movq	32(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%r13d, %r13d
	movq	16(%rsp), %rax                  # 8-byte Reload
	jle	.LBB1_8
# %bb.3:                                # %.preheader.lr.ph
	movl	%eax, %r15d
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
.LBB1_4:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_6 Depth 2
	movq	%r13, %r14
	testl	%eax, %eax
	jle	.LBB1_7
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB1_4 Depth=1
	movl	%r12d, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbx
	xorl	%r13d, %r13d
.LBB1_6:                                #   Parent Loop BB1_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r13,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r13
	cmpq	%r13, %r15
	jne	.LBB1_6
.LBB1_7:                                # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	movl	$_ZSt4cout, %eax
	addq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%rbp
	movq	16(%rsp), %rax                  # 8-byte Reload
	addl	%eax, %r12d
	movq	%r14, %r13
	cmpq	%r14, %rbp
	jne	.LBB1_4
.LBB1_8:                                # %._crit_edge53
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	addq	$120, %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	_Z13matMulBlocked6MatrixS_S_, .Lfunc_end1-_Z13matMulBlocked6MatrixS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12serialMatMuliiiPfS_S_       # -- Begin function _Z12serialMatMuliiiPfS_S_
	.type	_Z12serialMatMuliiiPfS_S_,@function
_Z12serialMatMuliiiPfS_S_:              # @_Z12serialMatMuliiiPfS_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
	.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	%r9, -8(%rsp)                   # 8-byte Spill
	movq	%r8, -16(%rsp)                  # 8-byte Spill
	movq	%rcx, -24(%rsp)                 # 8-byte Spill
	testl	%edx, %edx
	jle	.LBB2_9
# %bb.1:                                # %.preheader27.lr.ph
	movslq	%edi, %rcx
	movl	%edx, %edx
	movl	%ecx, %r10d
	movl	%esi, %r11d
	leaq	(,%rcx,4), %rbx
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.LBB2_2:                                # %.preheader27
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
                                        #       Child Loop BB2_6 Depth 3
	testl	%edi, %edi
	jle	.LBB2_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r14d, %eax
	movq	-24(%rsp), %r8                  # 8-byte Reload
	leaq	(%r8,%rax,4), %r12
	movq	%r15, %rax
	imulq	%rcx, %rax
	movq	-8(%rsp), %r8                   # 8-byte Reload
	leaq	(%r8,%rax,4), %r13
	movq	-16(%rsp), %r8                  # 8-byte Reload
	xorl	%eax, %eax
.LBB2_4:                                # %.preheader
                                        #   Parent Loop BB2_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_6 Depth 3
	xorps	%xmm0, %xmm0
	testl	%esi, %esi
	jle	.LBB2_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_4 Depth=2
	movq	%r8, %rbp
	xorl	%r9d, %r9d
.LBB2_6:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        #     Parent Loop BB2_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r12,%r9,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%rbp), %xmm1
	addss	%xmm1, %xmm0
	incq	%r9
	addq	%rbx, %rbp
	cmpq	%r9, %r11
	jne	.LBB2_6
.LBB2_7:                                # %._crit_edge
                                        #   in Loop: Header=BB2_4 Depth=2
	movss	%xmm0, (%r13,%rax,4)
	incq	%rax
	addq	$4, %r8
	cmpq	%r10, %rax
	jne	.LBB2_4
.LBB2_8:                                # %._crit_edge31
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r15
	addl	%esi, %r14d
	cmpq	%rdx, %r15
	jne	.LBB2_2
.LBB2_9:                                # %._crit_edge33
	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_end2:
	.size	_Z12serialMatMuliiiPfS_S_, .Lfunc_end2-_Z12serialMatMuliiiPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_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	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jle	.LBB3_20
# %bb.1:
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %r12d
	movq	24(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%r12d, %eax
	imull	%r15d, %eax
	cltq
	leaq	(,%rax,4), %rdi
	testl	%eax, %eax
	movq	$-1, %rbx
	cmovsq	%rbx, %rdi
	callq	_Znam
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movl	%ebp, %eax
	imull	%r12d, %eax
	cltq
	leaq	(,%rax,4), %rdi
	testl	%eax, %eax
	cmovsq	%rbx, %rdi
	callq	_Znam
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%ebp, 4(%rsp)                   # 4-byte Spill
	imull	%r15d, %ebp
	movslq	%ebp, %rax
	leaq	(,%rax,4), %rdi
	testl	%eax, %eax
	cmovsq	%rbx, %rdi
	movl	%r12d, %ebx
	callq	_Znam
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movl	%r15d, %eax
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	%r12d, %r12d
	movl	%r15d, 48(%rsp)                 # 4-byte Spill
	testl	%r15d, %r15d
	jle	.LBB3_7
# %bb.2:                                # %.preheader75.lr.ph
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.LBB3_3:                                # %.preheader75
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_5 Depth 2
	testl	%ebx, %ebx
	jle	.LBB3_6
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB3_3 Depth=1
	movl	%r14d, %eax
	movq	24(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %r13
	xorl	%ebp, %ebp
.LBB3_5:                                #   Parent Loop BB3_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%r13,%rbp,4)
	incq	%rbp
	cmpq	%rbp, %r12
	jne	.LBB3_5
.LBB3_6:                                # %._crit_edge
                                        #   in Loop: Header=BB3_3 Depth=1
	incq	%r15
	addl	%ebx, %r14d
	cmpq	32(%rsp), %r15                  # 8-byte Folded Reload
	jne	.LBB3_3
.LBB3_7:                                # %.preheader74
	movl	4(%rsp), %ebp                   # 4-byte Reload
	movl	%ebp, %r15d
	movl	%ebx, 44(%rsp)                  # 4-byte Spill
	testl	%ebx, %ebx
	jle	.LBB3_13
# %bb.8:                                # %.preheader73.lr.ph
	xorl	%r14d, %r14d
	xorl	%r13d, %r13d
.LBB3_9:                                # %.preheader73
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_11 Depth 2
	testl	%ebp, %ebp
	jle	.LBB3_12
# %bb.10:                               # %.lr.ph79
                                        #   in Loop: Header=BB3_9 Depth=1
	movl	%r14d, %eax
	movq	16(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbp
	xorl	%ebx, %ebx
.LBB3_11:                               #   Parent Loop BB3_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%rbp,%rbx,4)
	incq	%rbx
	cmpq	%rbx, %r15
	jne	.LBB3_11
.LBB3_12:                               # %._crit_edge80
                                        #   in Loop: Header=BB3_9 Depth=1
	incq	%r13
	movl	4(%rsp), %ebp                   # 4-byte Reload
	addl	%ebp, %r14d
	cmpq	%r12, %r13
	jne	.LBB3_9
.LBB3_13:                               # %._crit_edge82
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r14
	movl	%ebp, %edi
	movl	44(%rsp), %esi                  # 4-byte Reload
	movl	48(%rsp), %r13d                 # 4-byte Reload
	movl	%r13d, %edx
	movq	24(%rsp), %rcx                  # 8-byte Reload
	movq	16(%rsp), %r8                   # 8-byte Reload
	movq	8(%rsp), %r9                    # 8-byte Reload
	callq	_Z12serialMatMuliiiPfS_S_
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r14, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rbx
	shrq	$63, %rbx
	sarq	$7, %rdx
	addq	%rdx, %rbx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$6, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movq	%rbx, %rsi
	callq	_ZNSo9_M_insertIlEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	testl	%r13d, %r13d
	jle	.LBB3_19
# %bb.14:                               # %.preheader.lr.ph
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
.LBB3_15:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_17 Depth 2
	testl	%ebp, %ebp
	jle	.LBB3_18
# %bb.16:                               # %.lr.ph84
                                        #   in Loop: Header=BB3_15 Depth=1
	movl	%ebx, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r13
	xorl	%ebp, %ebp
.LBB3_17:                               #   Parent Loop BB3_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13,%rbp,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%rbp
	cmpq	%rbp, %r15
	jne	.LBB3_17
.LBB3_18:                               # %._crit_edge85
                                        #   in Loop: Header=BB3_15 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	movl	$_ZSt4cout, %eax
	addq	%rax, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%r14
	movl	4(%rsp), %ebp                   # 4-byte Reload
	addl	%ebp, %ebx
	cmpq	32(%rsp), %r14                  # 8-byte Folded Reload
	jne	.LBB3_15
.LBB3_19:                               # %._crit_edge87
	movq	32(%rsp), %r14                  # 8-byte Reload
	shlq	$32, %r14
	leaq	(%r14,%r15), %r13
	orq	%r12, %r14
	shlq	$32, %r12
	orq	%r15, %r12
	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
	leaq	64(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	leaq	56(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%r14, %rdi
	movq	24(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	movq	%r12, %rdx
	movq	16(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rcx
	movq	%r13, %r8
	movq	8(%rsp), %r12                   # 8-byte Reload
	movq	%r12, %r9
	callq	_Z13matMulBlocked6MatrixS_S_
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rbx), %rdi
	callq	hipEventSynchronize
	movq	(%rbp), %rsi
	movq	(%rbx), %rdx
	leaq	52(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%rbx), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$72, %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
.LBB3_20:
	.cfi_def_cfa_offset 128
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.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	$_Z19blockedMatMulKernel6MatrixS_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	_Z19blockedMatMulKernel6MatrixS_S_,@object # @_Z19blockedMatMulKernel6MatrixS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z19blockedMatMulKernel6MatrixS_S_
	.p2align	3, 0x0
_Z19blockedMatMulKernel6MatrixS_S_:
	.quad	_Z34__device_stub__blockedMatMulKernel6MatrixS_S_
	.size	_Z19blockedMatMulKernel6MatrixS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	" "
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"please include 3 integers for matrix dimensions"
	.size	.L.str.1, 48

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"time: "
	.size	.L.str.2, 7

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"cuda time="
	.size	.L.str.3, 11

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z19blockedMatMulKernel6MatrixS_S_"
	.size	.L__unnamed_1, 35

	.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 _Z34__device_stub__blockedMatMulKernel6MatrixS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z19blockedMatMulKernel6MatrixS_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	_Z19blockedMatMulKernel6MatrixS_S_ ; -- Begin function _Z19blockedMatMulKernel6MatrixS_S_
	.globl	_Z19blockedMatMulKernel6MatrixS_S_
	.p2align	8
	.type	_Z19blockedMatMulKernel6MatrixS_S_,@function
_Z19blockedMatMulKernel6MatrixS_S_:     ; @_Z19blockedMatMulKernel6MatrixS_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x3c
	s_load_b64 s[6:7], s[0:1], 0x0
	v_bfe_u32 v3, v0, 10, 10
	s_add_u32 s2, s0, 48
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s4, 16
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[3:4]
	s_mov_b32 s4, exec_lo
	v_cmpx_gt_u32_e64 s7, v1
	s_cbranch_execz .LBB0_8
; %bb.1:
	s_load_b32 s2, s[2:3], 0xc
	s_load_b32 s7, s[0:1], 0x10
	v_and_b32_e32 v0, 0x3ff, v0
	s_add_u32 s4, s0, 16
	s_addc_u32 s5, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[4:5], null, s14, s8, v[0:1]
	v_cmp_gt_u32_e32 vcc_lo, s7, v4
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.2:                                ; %.preheader
	s_load_b64 s[2:3], s[0:1], 0x28
	v_mov_b32_e32 v2, 0
	s_cmp_lt_u32 s6, s8
	s_cbranch_scc1 .LBB0_7
; %bb.3:                                ; %.lr.ph
	v_cvt_f32_u32_e32 v2, s8
	s_sub_i32 s10, 0, s8
	s_clause 0x1
	s_load_b64 s[0:1], s[0:1], 0x8
	s_load_b64 s[4:5], s[4:5], 0x8
	v_mad_u64_u32 v[5:6], null, v1, s6, v[0:1]
	v_rcp_iflag_f32_e32 v2, v2
	v_dual_mov_b32 v7, 0 :: v_dual_lshlrev_b32 v8, 6, v3
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v2, 0x4f7ffffe, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v2, v2
	v_readfirstlane_b32 s9, v2
	v_lshlrev_b32_e32 v2, 2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mul_i32 s10, s10, s9
	v_add_nc_u32_e32 v9, 0x400, v2
	s_mul_hi_u32 s10, s9, s10
	v_add_nc_u32_e32 v0, v8, v2
	v_mov_b32_e32 v2, 0
	s_add_i32 s9, s9, s10
	v_add_nc_u32_e32 v10, v9, v8
	s_mul_hi_u32 s9, s6, s9
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s10, s9, s8
	s_sub_i32 s6, s6, s10
	s_add_i32 s10, s9, 1
	s_sub_i32 s11, s6, s8
	s_cmp_ge_u32 s6, s8
	s_cselect_b32 s9, s10, s9
	s_cselect_b32 s6, s11, s6
	s_add_i32 s10, s9, 1
	s_cmp_ge_u32 s6, s8
	s_mov_b32 s6, 0
	s_cselect_b32 s9, s10, s9
.LBB0_4:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	s_mul_i32 s10, s6, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v13, s10, v3
	v_add_nc_u32_e32 v6, s10, v5
	s_mov_b32 s10, 0
	v_mad_u64_u32 v[11:12], null, v13, s7, v[4:5]
	v_mov_b32_e32 v12, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[13:14], 2, v[6:7]
	v_mov_b32_e32 v6, v9
	v_lshlrev_b64 v[11:12], 2, v[11:12]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v13, vcc_lo, s0, v13
	v_add_co_ci_u32_e32 v14, vcc_lo, s1, v14, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v11, vcc_lo, s4, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v12, vcc_lo
	global_load_b32 v13, v[13:14], off
	global_load_b32 v11, v[11:12], off
	s_waitcnt vmcnt(1)
	ds_store_b32 v0, v13
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v11
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_5:                                ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v11, s10, v8
	s_add_i32 s10, s10, 4
	ds_load_b32 v12, v6
	ds_load_b32 v11, v11
	v_add_nc_u32_e32 v6, 64, v6
	s_cmp_eq_u32 s10, 64
	s_waitcnt lgkmcnt(0)
	v_fmac_f32_e32 v2, v11, v12
	s_cbranch_scc0 .LBB0_5
; %bb.6:                                ;   in Loop: Header=BB0_4 Depth=1
	s_add_i32 s6, s6, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_ge_u32 s6, s9
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_4
.LBB0_7:                                ; %Flow55
	v_mad_u64_u32 v[5:6], null, v1, s7, v[4:5]
	v_mov_b32_e32 v6, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[5:6]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB0_8:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19blockedMatMulKernel6MatrixS_S_
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 15
		.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	_Z19blockedMatMulKernel6MatrixS_S_, .Lfunc_end0-_Z19blockedMatMulKernel6MatrixS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 616
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; 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:
      - .offset:         0
        .size:           16
        .value_kind:     by_value
      - .offset:         16
        .size:           16
        .value_kind:     by_value
      - .offset:         32
        .size:           16
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19blockedMatMulKernel6MatrixS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19blockedMatMulKernel6MatrixS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
