// Matrix Multiplication in gpu with 2D grid of blocks with 1D block shape
// Compile with: nvcc -o test matrix_multiplication_2D_2D.cu -std=c++11

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <chrono>
 
// Multiplies matrices using GPU with 2D grid
__global__ void multiply_matrix_gpu(long *matA, long *matB, long *matC, const int n) {
    unsigned int ix = threadIdx.x + blockIdx.x * blockDim.x;
    unsigned int iy = blockIdx.y;

    if (ix < n && iy < n) {
        for(int k=0; k<n; k++) {
            matC[iy*n+ix] += matA[iy*n+k] * matB[k*n+ix];
        }
    }
}

// Multiplies matrices in host
void multiply_matrix_host(long *matA, long *matB, long *matC, int n) {
    for(int i = 0; i<n; i++) {
        for(int j=0; j<n; j++) {
            for(int k=0; k<n; k++) {
                matC[i*n+j] += matA[i*n+k] * matB[j+k*n];
            }
        }
    }
}

// Compares two matrices
void checkResult(long *hostRef, long *gpuRef, const int n) {
    double epsilon = 1.0E-8;
    bool match = 1;

    for (int i = 0; i < n*n; i++) {
        if (abs(hostRef[i] - gpuRef[i]) > epsilon) {
            match = 0;
            printf("host %ld gpu %ld\n", hostRef[i], gpuRef[i]);
            break;
        }
    }

    if (match) printf("Matrix match.\n\n");
    else printf("Matrix does not not match.\n\n");
}
 
int main(int argc, char* argv[]) {
    // Set up device
    int dev = 0;
    cudaDeviceProp deviceProp;
    cudaGetDeviceProperties(&deviceProp, dev);
    printf("Using Device %d: %s\n", dev, deviceProp.name);
    cudaSetDevice(dev);

    // Size of matrix
    int n = 1000;
    int bytes = n * n * sizeof(long*);

    // Host matrix memory
    long *h_a = (long *)malloc(bytes);
    long *h_b = (long *)malloc(bytes);

    // Results
    long *hostRef = (long *)malloc(bytes);
    long *gpuRef = (long *)malloc(bytes);

    // Initialize matrix on host
    for(int i = 0; i < n*n; i++ ) {
        h_a[i] = i+1;
        h_b[i] = i+1;
    }

    // Initialize matrix with 0s
    memset(hostRef, 0, bytes);
    memset(gpuRef, 0, bytes);

    // Multiply matrix on host
    auto start_cpu = std::chrono::high_resolution_clock::now();
    multiply_matrix_host(h_a, h_b, hostRef, n);
    auto end_cpu =  std::chrono::high_resolution_clock::now();

    // Measure total time in host
    std::chrono::duration<float, std::milli> duration_ms = end_cpu - start_cpu;
    printf("multiply_matrix_host elapsed %f ms\n", duration_ms.count());

    // Device matrix global memory
    long *d_a, *d_b, *d_c;
    cudaMalloc((void **)&d_a, bytes);
    cudaMalloc((void **)&d_b, bytes);
    cudaMalloc((void **)&d_c, bytes);

    // Transfer data from host to device
    cudaMemcpy(d_a, h_a, bytes, cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, h_b, bytes, cudaMemcpyHostToDevice);
    cudaMemset(d_c, 0, bytes);  // Initialize matrix with 0s

    // Kernel execution configuration
    dim3 block(128);
    dim3 grid((n + block.x - 1) / block.x, n);
    printf("grid.x %d grid.y %d block.x %d \n", grid.x, grid.y, block.x);

    // Execute kernel
    start_cpu = std::chrono::high_resolution_clock::now();
    multiply_matrix_gpu<<<grid, block>>>(d_a, d_b, d_c, n);
    cudaDeviceSynchronize();
    end_cpu =  std::chrono::high_resolution_clock::now();

    // Measure total time
    duration_ms = end_cpu - start_cpu;
    printf("multiply_matrix_gpu elapsed %f ms\n", duration_ms.count());

    // Copy result from device to host
    cudaMemcpy(gpuRef, d_c, bytes, cudaMemcpyDeviceToHost);

    // Check results
    checkResult(hostRef, gpuRef, n);

    // Free memory
    cudaFree(d_a);
    cudaFree(d_b);
    cudaFree(d_c);
    free(h_a);
    free(h_b);
    free(hostRef);
    free(gpuRef);
    
    cudaDeviceReset();

    return 0;
}

	.file	"tmpxft_0025897d_00000000-6_matrix_multiplication_2D_1D.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3743:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3743:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z20multiply_matrix_hostPlS_S_i
	.type	_Z20multiply_matrix_hostPlS_S_i, @function
_Z20multiply_matrix_hostPlS_S_i:
.LFB3734:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rdx, %r10
	movq	%rdi, %r8
	xorl	%edx, %edx
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rsi, %rbx
	movslq	%ecx, %rsi
	movq	%rsi, %rax
	salq	$3, %rsi
.L3:
	cmpl	%eax, %ebp
	jge	.L2
	movq	%rbx, %r11
	leaq	(%r10,%rdx), %rcx
	leaq	(%r8,%rdx), %r14
	xorl	%r9d, %r9d
.L7:
	movq	%r11, %r12
	xorl	%edi, %edi
.L4:
	movq	(%r14,%rdi,8), %r13
	incq	%rdi
	imulq	(%r12), %r13
	addq	%rsi, %r12
	addq	%r13, (%rcx)
	cmpl	%edi, %eax
	jg	.L4
	incl	%r9d
	addq	$8, %r11
	addq	$8, %rcx
	cmpl	%r9d, %eax
	jne	.L7
	incl	%ebp
	addq	%rsi, %rdx
	jmp	.L3
.L2:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3734:
	.size	_Z20multiply_matrix_hostPlS_S_i, .-_Z20multiply_matrix_hostPlS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"host %ld gpu %ld\n"
.LC2:
	.string	"Matrix does not not match.\n\n"
.LC3:
	.string	"Matrix match.\n\n"
	.text
	.globl	_Z11checkResultPlS_i
	.type	_Z11checkResultPlS_i, @function
_Z11checkResultPlS_i:
.LFB3735:
	.cfi_startproc
	endbr64
	imull	%edx, %edx
	movsd	.LC0(%rip), %xmm0
	xorl	%eax, %eax
.L12:
	cmpl	%eax, %edx
	jle	.L20
	movq	(%rdi,%rax,8), %r9
	movq	(%rsi,%rax,8), %r10
	incq	%rax
	movq	%r9, %r8
	subq	%r10, %r8
	movq	%r8, %rcx
	negq	%rcx
	cmovs	%r8, %rcx
	cvtsi2sdq	%rcx, %xmm1
	comisd	%xmm0, %xmm1
	jbe	.L12
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%r9, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	movq	%r10, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	movl	$2, %edi
	jmp	.L19
.L20:
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
.L19:
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE3735:
	.size	_Z11checkResultPlS_i, .-_Z11checkResultPlS_i
	.globl	_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i
	.type	_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i, @function
_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i:
.LFB3765:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z19multiply_matrix_gpuPlS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L21:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3765:
	.size	_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i, .-_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i
	.globl	_Z19multiply_matrix_gpuPlS_S_i
	.type	_Z19multiply_matrix_gpuPlS_S_i, @function
_Z19multiply_matrix_gpuPlS_S_i:
.LFB3766:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i
	.cfi_endproc
.LFE3766:
	.size	_Z19multiply_matrix_gpuPlS_S_i, .-_Z19multiply_matrix_gpuPlS_S_i
	.section	.rodata.str1.1
.LC4:
	.string	"Using Device %d: %s\n"
.LC6:
	.string	"multiply_matrix_host elapsed %f ms\n"
.LC7:
	.string	"grid.x %d grid.y %d block.x %d \n"
.LC8:
	.string	"multiply_matrix_gpu elapsed %f ms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3736:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%esi, %esi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$1088, %rsp
	.cfi_def_cfa_offset 1136
	movq	%fs:40, %rax
	movq	%rax, 1080(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rbx
	movq	%rbx, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	%rbx, %rcx
	xorl	%edx, %edx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	$8000000, %edi
	call	malloc@PLT
	movl	$8000000, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movl	$8000000, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$8000000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	%rax, %rbx
	movl	$1, %eax
.L27:
	movq	%rax, -8(%r13,%rax,8)
	movq	%rax, -8(%r12,%rax,8)
	incq	%rax
	cmpq	$1000001, %rax
	jne	.L27
	xorl	%eax, %eax
	movl	$2000000, %ecx
	movq	%rbp, %rdi
	rep stosl
	movl	$2000000, %ecx
	movq	%rbx, %rdi
	rep stosl
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000, %ecx
	movq	%rbp, %rdx
	movq	%r12, %rsi
	movq	%r13, %rdi
	movq	%rax, %r14
	call	_Z20multiply_matrix_hostPlS_S_i
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	subq	%r14, %rax
	cvtsi2ssq	%rax, %xmm0
	movb	$1, %al
	divss	.LC5(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%rsp, %rdi
	movl	$8000000, %esi
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$8000000, %esi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$8000000, %esi
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	movl	$8000000, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$8000000, %edx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	movl	$8000000, %edx
	call	cudaMemset@PLT
	movl	$128, %r8d
	xorl	%eax, %eax
	movl	$1000, %ecx
	movl	$8, %edx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$33554433, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$7, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rax, %r14
	movabsq	$4294967296008, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$1000, %ecx
	movq	(%rsp), %rdi
	call	_Z44__device_stub__Z19multiply_matrix_gpuPlS_S_iPlS_S_i
.L28:
	call	cudaDeviceSynchronize@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	subq	%r14, %rax
	cvtsi2ssq	%rax, %xmm0
	movb	$1, %al
	divss	.LC5(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$8000000, %edx
	call	cudaMemcpy@PLT
	movl	$1000, %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	_Z11checkResultPlS_i
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	call	cudaDeviceReset@PLT
	movq	1080(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$1088, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3736:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z19multiply_matrix_gpuPlS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3768:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z19multiply_matrix_gpuPlS_S_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3768:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	-500134854
	.long	1044740494
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC5:
	.long	1232348160
	.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:

// Matrix Multiplication in gpu with 2D grid of blocks with 1D block shape
// Compile with: nvcc -o test matrix_multiplication_2D_2D.cu -std=c++11


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <chrono>
 
// Multiplies matrices using GPU with 2D grid
__global__ void multiply_matrix_gpu(long *matA, long *matB, long *matC, const int n) {
    unsigned int ix = threadIdx.x + blockIdx.x * blockDim.x;
    unsigned int iy = blockIdx.y;

    if (ix < n && iy < n) {
        for(int k=0; k<n; k++) {
            matC[iy*n+ix] += matA[iy*n+k] * matB[k*n+ix];
        }
    }
}

// Multiplies matrices in host
void multiply_matrix_host(long *matA, long *matB, long *matC, int n) {
    for(int i = 0; i<n; i++) {
        for(int j=0; j<n; j++) {
            for(int k=0; k<n; k++) {
                matC[i*n+j] += matA[i*n+k] * matB[j+k*n];
            }
        }
    }
}

// Compares two matrices
void checkResult(long *hostRef, long *gpuRef, const int n) {
    double epsilon = 1.0E-8;
    bool match = 1;

    for (int i = 0; i < n*n; i++) {
        if (abs(hostRef[i] - gpuRef[i]) > epsilon) {
            match = 0;
            printf("host %ld gpu %ld\n", hostRef[i], gpuRef[i]);
            break;
        }
    }

    if (match) printf("Matrix match.\n\n");
    else printf("Matrix does not not match.\n\n");
}
 
int main(int argc, char* argv[]) {
    // Set up device
    int dev = 0;
    hipDeviceProp_t deviceProp;
    hipGetDeviceProperties(&deviceProp, dev);
    printf("Using Device %d: %s\n", dev, deviceProp.name);
    hipSetDevice(dev);

    // Size of matrix
    int n = 1000;
    int bytes = n * n * sizeof(long*);

    // Host matrix memory
    long *h_a = (long *)malloc(bytes);
    long *h_b = (long *)malloc(bytes);

    // Results
    long *hostRef = (long *)malloc(bytes);
    long *gpuRef = (long *)malloc(bytes);

    // Initialize matrix on host
    for(int i = 0; i < n*n; i++ ) {
        h_a[i] = i+1;
        h_b[i] = i+1;
    }

    // Initialize matrix with 0s
    memset(hostRef, 0, bytes);
    memset(gpuRef, 0, bytes);

    // Multiply matrix on host
    auto start_cpu = std::chrono::high_resolution_clock::now();
    multiply_matrix_host(h_a, h_b, hostRef, n);
    auto end_cpu =  std::chrono::high_resolution_clock::now();

    // Measure total time in host
    std::chrono::duration<float, std::milli> duration_ms = end_cpu - start_cpu;
    printf("multiply_matrix_host elapsed %f ms\n", duration_ms.count());

    // Device matrix global memory
    long *d_a, *d_b, *d_c;
    hipMalloc((void **)&d_a, bytes);
    hipMalloc((void **)&d_b, bytes);
    hipMalloc((void **)&d_c, bytes);

    // Transfer data from host to device
    hipMemcpy(d_a, h_a, bytes, hipMemcpyHostToDevice);
    hipMemcpy(d_b, h_b, bytes, hipMemcpyHostToDevice);
    hipMemset(d_c, 0, bytes);  // Initialize matrix with 0s

    // Kernel execution configuration
    dim3 block(128);
    dim3 grid((n + block.x - 1) / block.x, n);
    printf("grid.x %d grid.y %d block.x %d \n", grid.x, grid.y, block.x);

    // Execute kernel
    start_cpu = std::chrono::high_resolution_clock::now();
    multiply_matrix_gpu<<<grid, block>>>(d_a, d_b, d_c, n);
    hipDeviceSynchronize();
    end_cpu =  std::chrono::high_resolution_clock::now();

    // Measure total time
    duration_ms = end_cpu - start_cpu;
    printf("multiply_matrix_gpu elapsed %f ms\n", duration_ms.count());

    // Copy result from device to host
    hipMemcpy(gpuRef, d_c, bytes, hipMemcpyDeviceToHost);

    // Check results
    checkResult(hostRef, gpuRef, n);

    // Free memory
    hipFree(d_a);
    hipFree(d_b);
    hipFree(d_c);
    free(h_a);
    free(h_b);
    free(hostRef);
    free(gpuRef);
    
    hipDeviceReset();

    return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_Z34__device_stub__multiply_matrix_gpuPlS_S_i # -- Begin function _Z34__device_stub__multiply_matrix_gpuPlS_S_i
	.type	_Z34__device_stub__multiply_matrix_gpuPlS_S_i,@function
_Z34__device_stub__multiply_matrix_gpuPlS_S_i: # @_Z34__device_stub__multiply_matrix_gpuPlS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z19multiply_matrix_gpuPlS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z34__device_stub__multiply_matrix_gpuPlS_S_i, .Lfunc_end0-_Z34__device_stub__multiply_matrix_gpuPlS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z20multiply_matrix_hostPlS_S_i # -- Begin function _Z20multiply_matrix_hostPlS_S_i
	.type	_Z20multiply_matrix_hostPlS_S_i,@function
_Z20multiply_matrix_hostPlS_S_i:        # @_Z20multiply_matrix_hostPlS_S_i
	.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	%rdx, -8(%rsp)                  # 8-byte Spill
	testl	%ecx, %ecx
	jle	.LBB1_7
# %bb.1:                                # %.preheader23.lr.ph
	movl	%ecx, %eax
	leaq	(,%rax,8), %r8
	xorl	%edx, %edx
	xorl	%r10d, %r10d
.LBB1_2:                                # %.preheader.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
                                        #       Child Loop BB1_4 Depth 3
	movl	%edx, %r11d
	leaq	(%rdi,%r11,8), %r11
	movq	%r10, %rbx
	imulq	%rax, %rbx
	movq	-8(%rsp), %r9                   # 8-byte Reload
	leaq	(%r9,%rbx,8), %rbx
	movq	%rsi, %r14
	xorl	%r15d, %r15d
.LBB1_3:                                # %.preheader
                                        #   Parent Loop BB1_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_4 Depth 3
	movq	(%rbx,%r15,8), %r12
	movq	%r14, %r13
	xorl	%ebp, %ebp
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        #     Parent Loop BB1_3 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	(%r13), %r9
	imulq	(%r11,%rbp,8), %r9
	addq	%r9, %r12
	movq	%r12, (%rbx,%r15,8)
	incq	%rbp
	addq	%r8, %r13
	cmpq	%rbp, %rax
	jne	.LBB1_4
# %bb.5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_3 Depth=2
	incq	%r15
	addq	$8, %r14
	cmpq	%rax, %r15
	jne	.LBB1_3
# %bb.6:                                # %._crit_edge26
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%r10
	addl	%ecx, %edx
	cmpq	%rax, %r10
	jne	.LBB1_2
.LBB1_7:                                # %._crit_edge28
	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	_Z20multiply_matrix_hostPlS_S_i, .Lfunc_end1-_Z20multiply_matrix_hostPlS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z11checkResultPlS_i            # -- Begin function _Z11checkResultPlS_i
	.type	_Z11checkResultPlS_i,@function
_Z11checkResultPlS_i:                   # @_Z11checkResultPlS_i
	.cfi_startproc
# %bb.0:
                                        # kill: def $edx killed $edx def $rdx
	movq	%rdi, %rax
	movl	$.Lstr.1, %edi
	testl	%edx, %edx
	je	puts@PLT                        # TAILCALL
# %bb.1:                                # %.lr.ph.preheader
	imull	%edx, %edx
	cmpl	$1, %edx
	adcl	$0, %edx
	xorl	%r9d, %r9d
	jmp	.LBB2_3
.LBB2_2:                                #   in Loop: Header=BB2_3 Depth=1
	incq	%r9
	cmpq	%r9, %rdx
	je	puts@PLT                        # TAILCALL
.LBB2_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rax,%r9,8), %rcx
	movq	(%rsi,%r9,8), %r8
	cmpq	%r8, %rcx
	je	.LBB2_2
# %bb.4:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$.L.str, %edi
	movq	%rcx, %rsi
	movq	%r8, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end2:
	.size	_Z11checkResultPlS_i, .Lfunc_end2-_Z11checkResultPlS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x49742400                      # float 1.0E+6
	.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	$1512, %rsp                     # imm = 0x5E8
	.cfi_def_cfa_offset 1568
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	40(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.3, %edi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	xorl	%edi, %edi
	callq	hipSetDevice
	movl	$8000000, %edi                  # imm = 0x7A1200
	callq	malloc
	movq	%rax, %rbx
	movl	$8000000, %edi                  # imm = 0x7A1200
	callq	malloc
	movq	%rax, %r14
	movl	$8000000, %edi                  # imm = 0x7A1200
	callq	malloc
	movq	%rax, %r15
	movl	$8000000, %edi                  # imm = 0x7A1200
	callq	malloc
	movq	%rax, %r13
	movl	$1, %eax
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	movq	%rax, -8(%rbx,%rax,8)
	movq	%rax, -8(%r14,%rax,8)
	incq	%rax
	cmpq	$1000001, %rax                  # imm = 0xF4241
	jne	.LBB3_1
# %bb.2:
	xorl	%r12d, %r12d
	movl	$8000000, %edx                  # imm = 0x7A1200
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$8000000, %edx                  # imm = 0x7A1200
	movq	%r13, 32(%rsp)                  # 8-byte Spill
	movq	%r13, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r13
	movq	%rbx, %rax
.LBB3_3:                                # %.preheader.lr.ph.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
                                        #       Child Loop BB3_5 Depth 3
	imulq	$8000, %r12, %rcx               # imm = 0x1F40
	addq	%r15, %rcx
	movq	%r14, %rdx
	xorl	%esi, %esi
.LBB3_4:                                # %.preheader.i
                                        #   Parent Loop BB3_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_5 Depth 3
	movq	(%rcx,%rsi,8), %rdi
	movq	%rdx, %r8
	xorl	%r9d, %r9d
.LBB3_5:                                #   Parent Loop BB3_3 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	(%r8), %r10
	imulq	(%rax,%r9,8), %r10
	addq	%r10, %rdi
	incq	%r9
	addq	$8000, %r8                      # imm = 0x1F40
	cmpq	$1000, %r9                      # imm = 0x3E8
	jne	.LBB3_5
# %bb.6:                                # %._crit_edge.i
                                        #   in Loop: Header=BB3_4 Depth=2
	movq	%rdi, (%rcx,%rsi,8)
	incq	%rsi
	addq	$8, %rdx
	cmpq	$1000, %rsi                     # imm = 0x3E8
	jne	.LBB3_4
# %bb.7:                                # %._crit_edge26.i
                                        #   in Loop: Header=BB3_3 Depth=1
	incq	%r12
	addq	$8000, %rax                     # imm = 0x1F40
	cmpq	$1000, %r12                     # imm = 0x3E8
	jne	.LBB3_3
# %bb.8:                                # %_Z20multiply_matrix_hostPlS_S_i.exit
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r13, %rax
	cvtsi2ss	%rax, %xmm0
	divss	.LCPI3_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	leaq	24(%rsp), %r13
	movl	$8000000, %esi                  # imm = 0x7A1200
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %rbp
	movl	$8000000, %esi                  # imm = 0x7A1200
	movq	%rbp, %rdi
	callq	hipMalloc
	leaq	8(%rsp), %r12
	movl	$8000000, %esi                  # imm = 0x7A1200
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r13), %rdi
	movl	$8000000, %edx                  # imm = 0x7A1200
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movl	$8000000, %edx                  # imm = 0x7A1200
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r12), %rdi
	movl	$8000000, %edx                  # imm = 0x7A1200
	xorl	%esi, %esi
	callq	hipMemset
	movl	$.L.str.5, %edi
	movl	$8, %esi
	movl	$1000, %edx                     # imm = 0x3E8
	movl	$128, %ecx
	xorl	%eax, %eax
	callq	printf
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r13
	movabsq	$4294967296008, %rdi            # imm = 0x3E800000008
	movabsq	$4294967424, %rdx               # imm = 0x100000080
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.9:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$1000, %ecx                     # imm = 0x3E8
	callq	_Z34__device_stub__multiply_matrix_gpuPlS_S_i
.LBB3_10:
	callq	hipDeviceSynchronize
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r13, %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	divss	.LCPI3_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movq	8(%rsp), %rsi
	movl	$8000000, %edx                  # imm = 0x7A1200
	movq	32(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r15, %rdi
	movq	%r12, %rsi
	movl	$1000, %edx                     # imm = 0x3E8
	callq	_Z11checkResultPlS_i
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	callq	hipDeviceReset
	xorl	%eax, %eax
	addq	$1512, %rsp                     # imm = 0x5E8
	.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_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	$_Z19multiply_matrix_gpuPlS_S_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_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	_Z19multiply_matrix_gpuPlS_S_i,@object # @_Z19multiply_matrix_gpuPlS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z19multiply_matrix_gpuPlS_S_i
	.p2align	3, 0x0
_Z19multiply_matrix_gpuPlS_S_i:
	.quad	_Z34__device_stub__multiply_matrix_gpuPlS_S_i
	.size	_Z19multiply_matrix_gpuPlS_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"host %ld gpu %ld\n"
	.size	.L.str, 18

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Using Device %d: %s\n"
	.size	.L.str.3, 21

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"multiply_matrix_host elapsed %f ms\n"
	.size	.L.str.4, 36

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"grid.x %d grid.y %d block.x %d \n"
	.size	.L.str.5, 33

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"multiply_matrix_gpu elapsed %f ms\n"
	.size	.L.str.6, 35

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z19multiply_matrix_gpuPlS_S_i"
	.size	.L__unnamed_1, 31

	.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	"Matrix does not not match.\n"
	.size	.Lstr, 28

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Matrix match.\n"
	.size	.Lstr.1, 15

	.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__multiply_matrix_gpuPlS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z19multiply_matrix_gpuPlS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z19multiply_matrix_gpuPlS_S_i ; -- Begin function _Z19multiply_matrix_gpuPlS_S_i
	.globl	_Z19multiply_matrix_gpuPlS_S_i
	.p2align	8
	.type	_Z19multiply_matrix_gpuPlS_S_i,@function
_Z19multiply_matrix_gpuPlS_S_i:         ; @_Z19multiply_matrix_gpuPlS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s6, s[0:1], 0x18
	s_mov_b32 s5, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_cmp_gt_i32 s6, 0
	v_mad_u64_u32 v[1:2], null, s14, s2, v[0:1]
	s_cselect_b32 s2, -1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_u32_e32 v0, s15, v1
	v_cmp_gt_u32_e32 vcc_lo, s6, v0
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph
	s_load_b64 s[2:3], s[0:1], 0x10
	s_mul_i32 s7, s15, s6
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v2, 0 :: v_dual_add_nc_u32 v3, s7, v1
	s_mov_b32 s8, 0
	v_mov_b32_e32 v4, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 3, v[3:4]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s2, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v4, vcc_lo
	s_load_b128 s[0:3], s[0:1], 0x0
	global_load_b64 v[5:6], v[3:4], off
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	v_lshlrev_b64 v[7:8], 3, v[1:2]
	s_add_i32 s4, s7, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_lshl_b64 s[10:11], s[4:5], 3
	s_waitcnt lgkmcnt(0)
	s_add_u32 s10, s0, s10
	v_add_co_u32 v7, vcc_lo, s2, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s3, v8, vcc_lo
	s_addc_u32 s11, s1, s11
	s_add_i32 s8, s8, 1
	global_load_b64 v[9:10], v2, s[10:11]
	global_load_b64 v[7:8], v[7:8], off
	s_cmp_lg_u32 s6, s8
	s_waitcnt vmcnt(0)
	v_mul_lo_u32 v0, v7, v10
	v_mul_lo_u32 v8, v8, v9
	v_mad_u64_u32 v[10:11], null, v7, v9, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add3_u32 v11, v8, v11, v0
	v_mov_b32_e32 v5, v10
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_mov_b32 v6, v11 :: v_dual_add_nc_u32 v1, s6, v1
	global_store_b64 v[3:4], v[10:11], off
	s_cbranch_scc1 .LBB0_2
.LBB0_3:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19multiply_matrix_gpuPlS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 12
		.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	_Z19multiply_matrix_gpuPlS_S_i, .Lfunc_end0-_Z19multiply_matrix_gpuPlS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 308
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; 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: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19multiply_matrix_gpuPlS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19multiply_matrix_gpuPlS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
