#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <cuda_runtime.h>
#define WIDTH 1024
#define THREADSPERBLOCK 16
#define BLOCKSPERGRID 1

int M[WIDTH][WIDTH] = {0};
int N[WIDTH][WIDTH] = {0};
int P[WIDTH][WIDTH] = {0};
int MxN[WIDTH][WIDTH] = {0};

__global__ void mat_mul(int *Md, int *Nd, int *Pd);

int main(int argc, char *argv[])
{
    float elapsedTime1;
    float elapsedTime2;

    for (int i = 0; i < WIDTH; ++i)
    {
        for (int j = 0; j < WIDTH; ++j)
        {
            M[i][j] = (int)(rand() % 255 + 1);
            N[i][j] = (int)(rand() % 255 + 1);
        }
    }

    struct timeval starttime, endtime;
    gettimeofday(&starttime, NULL);
    for (int i = 0; i < WIDTH; ++i)
    {
        for (int j = 0; j < WIDTH; ++j)
        {
            for (int k = 0; k < WIDTH; ++k)
            {
                MxN[i][j] += M[i][k] * N[k][j];
            }
        }
    }
    gettimeofday(&endtime, NULL);
    double executime;
    executime = (endtime.tv_sec - starttime.tv_sec) * 1000.0;
    executime += (endtime.tv_usec - starttime.tv_usec) / 1000.0;
    printf("CPU time: %13lf msec\n", executime);

    // Original
    size_t size = WIDTH * WIDTH * sizeof(int);
    int *Md, *Nd, *Pd;
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    cudaEventRecord(start, 0);
    for (int i = 0; i < WIDTH; i++)
    {
        for (int j = i + 1; j < WIDTH; j++)
        {
            int temp = N[i][j];
            N[i][j] = N[j][i];
            N[j][i] = temp;
        }
    }
    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&elapsedTime1, start, stop);
    printf("CPU transpose time: %13f msec\n", elapsedTime1);

    cudaMalloc((void **)&Md, size);
    cudaMemcpy(Md, M, size, cudaMemcpyHostToDevice);
    cudaMalloc((void **)&Nd, size);
    cudaMemcpy(Nd, N, size, cudaMemcpyHostToDevice);
    cudaMalloc((void **)&Pd, size);

    dim3 dimGrid(BLOCKSPERGRID, BLOCKSPERGRID);
    dim3 dimBlock(THREADSPERBLOCK, THREADSPERBLOCK);

    cudaEventRecord(start, 0);
    mat_mul<<<dimGrid, dimBlock>>>(Md, Nd, Pd);
    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&elapsedTime2, start, stop);
    printf("GPU mat-mul time: %13f msec\n", elapsedTime2);
    printf("GPU total time: %13f msec\n", elapsedTime1 + elapsedTime2);

    cudaError_t cuda_err = cudaGetLastError();
    if (cudaSuccess != cuda_err)
    {
        printf("before kernel call: error = %s\n", cudaGetErrorString(cuda_err));
        exit(1);
    }
    cudaEventDestroy(start);
    cudaEventDestroy(stop);
    cudaMemcpy(P, Pd, size, cudaMemcpyDeviceToHost);
    int pass = 1;
    for (int i = 0; i < WIDTH; ++i)
    {
        for (int j = 0; j < WIDTH; ++j)
        {
            if (MxN[i][j] != P[i][j])
            {
                printf("MxN[%d][%d] = %d   P[%d][%d] = %d\n", i, j, MxN[i][j], i, j, P[i][j]);
                pass = 0;
                break;
            }
        }
    }
    printf("Test %s\n", (pass) ? "PASSED" : "FAILED");
    cudaFree(Md);
    cudaFree(Nd);
    cudaFree(Pd);

    return 0;
}

__global__ void mat_mul(int *Md, int *Nd, int *Pd)
{
    int x, y;
    int Pvalue;
    int tx = threadIdx.x;
    int ty = threadIdx.y;
    int tid = tx + ty * blockDim.x;

    while (tid < WIDTH * WIDTH)
    {
        x = tid % WIDTH;
        y = tid / WIDTH;
        Pvalue = 0;
        for (int k = 0; k < WIDTH; ++k)
        {
            int Melement = *(Md + y * WIDTH + k);
            int Nelement = *(Nd + x * WIDTH + k);
            Pvalue += Melement * Nelement;
        }
        *(Pd + y * WIDTH + x) = Pvalue;
        tid += blockDim.x * blockDim.y;
    }
}

	.file	"tmpxft_002b7abf_00000000-6_1T_CPU.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_
	.type	_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_, @function
_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z7mat_mulPiS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L2:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_, .-_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_
	.globl	_Z7mat_mulPiS_S_
	.type	_Z7mat_mulPiS_S_, @function
_Z7mat_mulPiS_S_:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_
	.cfi_endproc
.LFE2053:
	.size	_Z7mat_mulPiS_S_, .-_Z7mat_mulPiS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"PASSED"
.LC1:
	.string	"FAILED"
.LC3:
	.string	"CPU time: %13lf msec\n"
.LC4:
	.string	"CPU transpose time: %13f msec\n"
.LC5:
	.string	"GPU mat-mul time: %13f msec\n"
.LC6:
	.string	"GPU total time: %13f msec\n"
.LC7:
	.string	"before kernel call: error = %s\n"
.LC8:
	.string	"MxN[%d][%d] = %d   P[%d][%d] = %d\n"
.LC9:
	.string	"Test %s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.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
	leaq	M(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
.L9:
	movq	%rbp, %rbx
	movl	$1024, %r15d
.L10:
	call	rand@PLT
	movl	$255, %r14d
	leaq	N(%rip), %r13
	cltd
	idivl	%r14d
	incl	%edx
	movl	%edx, (%r12,%rbx)
	call	rand@PLT
	cltd
	idivl	%r14d
	incl	%edx
	movl	%edx, 0(%r13,%rbx)
	addq	$4, %rbx
	decl	%r15d
	jne	.L10
	addq	$4096, %rbp
	cmpq	$4194304, %rbp
	jne	.L9
	leaq	72(%rsp), %rdi
	xorl	%esi, %esi
	leaq	MxN(%rip), %rbp
	call	gettimeofday@PLT
	xorl	%eax, %eax
	leaq	4096+N(%rip), %r11
.L12:
	leaq	N(%rip), %rbx
	leaq	(%rax,%rbp), %rcx
	movq	%rbx, %rdx
	leaq	(%r12,%rax), %r10
.L16:
	movl	(%rcx), %r8d
	movq	%rdx, %rdi
	xorl	%esi, %esi
.L13:
	movl	(%r10,%rsi,4), %r9d
	imull	(%rdi), %r9d
	incq	%rsi
	addq	$4096, %rdi
	addl	%r9d, %r8d
	cmpq	$1024, %rsi
	jne	.L13
	addq	$4, %rdx
	movl	%r8d, (%rcx)
	addq	$4, %rcx
	cmpq	%r11, %rdx
	jne	.L16
	addq	$4096, %rax
	cmpq	$4194304, %rax
	jne	.L12
	leaq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	88(%rsp), %rax
	subq	72(%rsp), %rax
	leaq	.LC3(%rip), %rsi
	cvtsi2sdq	%rax, %xmm1
	movq	96(%rsp), %rax
	subq	80(%rsp), %rax
	movl	$2, %edi
	cvtsi2sdq	%rax, %xmm0
	movsd	.LC2(%rip), %xmm2
	movb	$1, %al
	mulsd	%xmm2, %xmm1
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	xorl	%eax, %eax
.L19:
	incl	%eax
	movq	%rbx, %rdx
	movq	%rbx, %rcx
	movl	%eax, %esi
.L17:
	addq	$4, %rcx
	addq	$4096, %rdx
	cmpl	$1024, %esi
	je	.L35
	movl	(%rcx), %edi
	movl	(%rdx), %r8d
	incl	%esi
	movl	%r8d, (%rcx)
	movl	%edi, (%rdx)
	jmp	.L17
.L35:
	addq	$4100, %rbx
	cmpl	$1024, %eax
	jne	.L19
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	%rsp, %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	(%rsp), %xmm0
	call	__printf_chk@PLT
	leaq	8(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	movl	$4194304, %edx
	call	cudaMemcpy@PLT
	leaq	16(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	movl	$4194304, %edx
	call	cudaMemcpy@PLT
	leaq	24(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movabsq	$68719476752, %rax
	movl	$1, 56(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	cudaEventRecord@PLT
	movl	68(%rsp), %ecx
	movl	56(%rsp), %esi
	xorl	%r9d, %r9d
	movq	60(%rsp), %rdx
	movq	48(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z30__device_stub__Z7mat_mulPiS_S_PiS_S_
.L20:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	4(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	4(%rsp), %xmm0
	call	__printf_chk@PLT
	movss	(%rsp), %xmm0
	movb	$1, %al
	addss	4(%rsp), %xmm0
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L21
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L21:
	movq	32(%rsp), %rdi
	leaq	P(%rip), %r12
	xorl	%ebx, %ebx
	leaq	.LC8(%rip), %r13
	call	cudaEventDestroy@PLT
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$4194304, %edx
	call	cudaMemcpy@PLT
	movl	$1, %esi
.L22:
	movq	%rbx, %rax
	movl	%ebx, %edx
	xorl	%ecx, %ecx
	salq	$12, %rax
.L25:
	movl	0(%rbp,%rax), %r8d
	movl	(%r12,%rax), %edi
	cmpl	%edi, %r8d
	je	.L23
	pushq	%rdi
	.cfi_def_cfa_offset 184
	movl	%edx, %r9d
	movq	%r13, %rsi
	movl	$2, %edi
	pushq	%rcx
	.cfi_def_cfa_offset 192
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	xorl	%esi, %esi
	popq	%rdx
	.cfi_def_cfa_offset 176
	jmp	.L24
.L23:
	incl	%ecx
	addq	$4, %rax
	cmpl	$1024, %ecx
	jne	.L25
.L24:
	incq	%rbx
	cmpq	$1024, %rbx
	jne	.L22
	testl	%esi, %esi
	leaq	.LC0(%rip), %rax
	leaq	.LC1(%rip), %rdx
	movl	$2, %edi
	cmovne	%rax, %rdx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$120, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z7mat_mulPiS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z7mat_mulPiS_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
.LFE2055:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	MxN
	.bss
	.align 32
	.type	MxN, @object
	.size	MxN, 4194304
MxN:
	.zero	4194304
	.globl	P
	.align 32
	.type	P, @object
	.size	P, 4194304
P:
	.zero	4194304
	.globl	N
	.align 32
	.type	N, @object
	.size	N, 4194304
N:
	.zero	4194304
	.globl	M
	.align 32
	.type	M, @object
	.size	M, 4194304
M:
	.zero	4194304
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1083129856
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <hip/hip_runtime.h>
#define WIDTH 1024
#define THREADSPERBLOCK 16
#define BLOCKSPERGRID 1

int M[WIDTH][WIDTH] = {0};
int N[WIDTH][WIDTH] = {0};
int P[WIDTH][WIDTH] = {0};
int MxN[WIDTH][WIDTH] = {0};

__global__ void mat_mul(int *Md, int *Nd, int *Pd);

int main(int argc, char *argv[])
{
    float elapsedTime1;
    float elapsedTime2;

    for (int i = 0; i < WIDTH; ++i)
    {
        for (int j = 0; j < WIDTH; ++j)
        {
            M[i][j] = (int)(rand() % 255 + 1);
            N[i][j] = (int)(rand() % 255 + 1);
        }
    }

    struct timeval starttime, endtime;
    gettimeofday(&starttime, NULL);
    for (int i = 0; i < WIDTH; ++i)
    {
        for (int j = 0; j < WIDTH; ++j)
        {
            for (int k = 0; k < WIDTH; ++k)
            {
                MxN[i][j] += M[i][k] * N[k][j];
            }
        }
    }
    gettimeofday(&endtime, NULL);
    double executime;
    executime = (endtime.tv_sec - starttime.tv_sec) * 1000.0;
    executime += (endtime.tv_usec - starttime.tv_usec) / 1000.0;
    printf("CPU time: %13lf msec\n", executime);

    // Original
    size_t size = WIDTH * WIDTH * sizeof(int);
    int *Md, *Nd, *Pd;
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);

    hipEventRecord(start, 0);
    for (int i = 0; i < WIDTH; i++)
    {
        for (int j = i + 1; j < WIDTH; j++)
        {
            int temp = N[i][j];
            N[i][j] = N[j][i];
            N[j][i] = temp;
        }
    }
    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&elapsedTime1, start, stop);
    printf("CPU transpose time: %13f msec\n", elapsedTime1);

    hipMalloc((void **)&Md, size);
    hipMemcpy(Md, M, size, hipMemcpyHostToDevice);
    hipMalloc((void **)&Nd, size);
    hipMemcpy(Nd, N, size, hipMemcpyHostToDevice);
    hipMalloc((void **)&Pd, size);

    dim3 dimGrid(BLOCKSPERGRID, BLOCKSPERGRID);
    dim3 dimBlock(THREADSPERBLOCK, THREADSPERBLOCK);

    hipEventRecord(start, 0);
    mat_mul<<<dimGrid, dimBlock>>>(Md, Nd, Pd);
    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&elapsedTime2, start, stop);
    printf("GPU mat-mul time: %13f msec\n", elapsedTime2);
    printf("GPU total time: %13f msec\n", elapsedTime1 + elapsedTime2);

    hipError_t cuda_err = hipGetLastError();
    if (hipSuccess != cuda_err)
    {
        printf("before kernel call: error = %s\n", hipGetErrorString(cuda_err));
        exit(1);
    }
    hipEventDestroy(start);
    hipEventDestroy(stop);
    hipMemcpy(P, Pd, size, hipMemcpyDeviceToHost);
    int pass = 1;
    for (int i = 0; i < WIDTH; ++i)
    {
        for (int j = 0; j < WIDTH; ++j)
        {
            if (MxN[i][j] != P[i][j])
            {
                printf("MxN[%d][%d] = %d   P[%d][%d] = %d\n", i, j, MxN[i][j], i, j, P[i][j]);
                pass = 0;
                break;
            }
        }
    }
    printf("Test %s\n", (pass) ? "PASSED" : "FAILED");
    hipFree(Md);
    hipFree(Nd);
    hipFree(Pd);

    return 0;
}

__global__ void mat_mul(int *Md, int *Nd, int *Pd)
{
    int x, y;
    int Pvalue;
    int tx = threadIdx.x;
    int ty = threadIdx.y;
    int tid = tx + ty * blockDim.x;

    while (tid < WIDTH * WIDTH)
    {
        x = tid % WIDTH;
        y = tid / WIDTH;
        Pvalue = 0;
        for (int k = 0; k < WIDTH; ++k)
        {
            int Melement = *(Md + y * WIDTH + k);
            int Nelement = *(Nd + x * WIDTH + k);
            Pvalue += Melement * Nelement;
        }
        *(Pd + y * WIDTH + x) = Pvalue;
        tid += blockDim.x * blockDim.y;
    }
}

	.text
	.file	"1T_CPU.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x408f400000000000              # double 1000
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$104, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
.LBB0_1:                                # %.preheader87
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	movq	$-4096, %r15                    # imm = 0xF000
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$-2139062143, %rax, %rcx        # imm = 0x80808081
	shrq	$32, %rcx
	addl	%eax, %ecx
	movl	%ecx, %edx
	shrl	$31, %edx
	sarl	$7, %ecx
	addl	%edx, %ecx
	movl	%ecx, %edx
	shll	$8, %edx
	subl	%edx, %ecx
	addl	%ecx, %eax
	incl	%eax
	movl	%eax, M+4096(%rbx,%r15)
	callq	rand
	cltq
	imulq	$-2139062143, %rax, %rcx        # imm = 0x80808081
	shrq	$32, %rcx
	addl	%eax, %ecx
	movl	%ecx, %edx
	shrl	$31, %edx
	sarl	$7, %ecx
	addl	%edx, %ecx
	movl	%ecx, %edx
	shll	$8, %edx
	subl	%edx, %ecx
	addl	%ecx, %eax
	incl	%eax
	movl	%eax, N+4096(%rbx,%r15)
	addq	$4, %r15
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	incq	%r14
	addq	$4096, %rbx                     # imm = 0x1000
	cmpq	$1024, %r14                     # imm = 0x400
	jne	.LBB0_1
# %bb.4:
	xorl	%ebx, %ebx
	leaq	72(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	$M, %eax
.LBB0_5:                                # %.preheader86
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_6 Depth 2
                                        #       Child Loop BB0_7 Depth 3
	movl	$N, %ecx
	movq	%rbx, %rdx
	shlq	$12, %rdx
	xorl	%esi, %esi
.LBB0_6:                                # %.preheader85
                                        #   Parent Loop BB0_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_7 Depth 3
	leaq	(%rdx,%rsi,4), %rdi
	addq	$MxN, %rdi
	movl	(%rdi), %r8d
	movq	%rcx, %r9
	xorl	%r10d, %r10d
.LBB0_7:                                #   Parent Loop BB0_5 Depth=1
                                        #     Parent Loop BB0_6 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	(%r9), %r11d
	imull	(%rax,%r10,4), %r11d
	addl	%r11d, %r8d
	incq	%r10
	addq	$4096, %r9                      # imm = 0x1000
	cmpq	$1024, %r10                     # imm = 0x400
	jne	.LBB0_7
# %bb.8:                                #   in Loop: Header=BB0_6 Depth=2
	movl	%r8d, (%rdi)
	incq	%rsi
	addq	$4, %rcx
	cmpq	$1024, %rsi                     # imm = 0x400
	jne	.LBB0_6
# %bb.9:                                #   in Loop: Header=BB0_5 Depth=1
	incq	%rbx
	addq	$4096, %rax                     # imm = 0x1000
	cmpq	$1024, %rbx                     # imm = 0x400
	jne	.LBB0_5
# %bb.10:
	xorl	%r14d, %r14d
	leaq	88(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	movq	8(%rbx), %rcx
	subq	72(%rsp), %rax
	cvtsi2sd	%rax, %xmm1
	movsd	.LCPI0_0(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm1
	subq	80(%rsp), %rcx
	cvtsi2sd	%rcx, %xmm0
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$N+4, %eax
	movl	$N+4096, %ecx
	movl	$4100, %edx                     # imm = 0x1004
.LBB0_11:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_18 Depth 2
	cmpq	$1022, %r14                     # imm = 0x3FE
	ja	.LBB0_12
# %bb.17:                               # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_11 Depth=1
	movl	$1, %esi
	movq	%rcx, %rdi
.LBB0_18:                               # %.lr.ph
                                        #   Parent Loop BB0_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	-4(%rax,%rsi,4), %r8d
	movl	(%rdi), %r9d
	movl	%r9d, -4(%rax,%rsi,4)
	movl	%r8d, (%rdi)
	addq	$4096, %rdi                     # imm = 0x1000
	leaq	(%r14,%rsi), %r8
	incq	%r8
	incq	%rsi
	cmpq	$1024, %r8                      # imm = 0x400
	jne	.LBB0_18
.LBB0_12:                               # %.loopexit84
                                        #   in Loop: Header=BB0_11 Depth=1
	incq	%r14
	addq	%rdx, %rax
	addq	%rdx, %rcx
	cmpq	$1024, %r14                     # imm = 0x400
	jne	.LBB0_11
# %bb.13:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	44(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	leaq	56(%rsp), %rbx
	movl	$4194304, %esi                  # imm = 0x400000
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movl	$M, %esi
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	48(%rsp), %rbx
	movl	$4194304, %esi                  # imm = 0x400000
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movl	$N, %esi
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_15
# %bb.14:
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	32(%rsp), %rdx
	callq	_Z22__device_stub__mat_mulPiS_S_
.LBB0_15:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	68(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	movss	44(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	addss	(%rbx), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB0_16
# %bb.19:
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	movq	32(%rsp), %rsi
	movl	$P, %edi
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$1, %ebp
	xorl	%r14d, %r14d
	xorl	%ebx, %ebx
.LBB0_20:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_21 Depth 2
	xorl	%edx, %edx
.LBB0_21:                               #   Parent Loop BB0_20 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	MxN(%r14,%rdx,4), %ecx
	movl	P(%r14,%rdx,4), %eax
	cmpl	%eax, %ecx
	jne	.LBB0_22
# %bb.23:                               #   in Loop: Header=BB0_21 Depth=2
	incq	%rdx
	cmpq	$1024, %rdx                     # imm = 0x400
	jne	.LBB0_21
	jmp	.LBB0_24
.LBB0_22:                               #   in Loop: Header=BB0_20 Depth=1
	movl	%eax, (%rsp)
	xorl	%ebp, %ebp
	movl	$.L.str.5, %edi
	movl	%ebx, %esi
	movl	%ebx, %r8d
	movl	%edx, %r9d
	xorl	%eax, %eax
	callq	printf
.LBB0_24:                               # %.loopexit
                                        #   in Loop: Header=BB0_20 Depth=1
	incq	%rbx
	addq	$4096, %r14                     # imm = 0x1000
	cmpq	$1024, %rbx                     # imm = 0x400
	jne	.LBB0_20
# %bb.25:
	testl	%ebp, %ebp
	movl	$.L.str.8, %eax
	movl	$.L.str.7, %esi
	cmoveq	%rax, %rsi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$104, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB0_16:
	.cfi_def_cfa_offset 144
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__mat_mulPiS_S_ # -- Begin function _Z22__device_stub__mat_mulPiS_S_
	.type	_Z22__device_stub__mat_mulPiS_S_,@function
_Z22__device_stub__mat_mulPiS_S_:       # @_Z22__device_stub__mat_mulPiS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%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	$_Z7mat_mulPiS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z22__device_stub__mat_mulPiS_S_, .Lfunc_end1-_Z22__device_stub__mat_mulPiS_S_
	.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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7mat_mulPiS_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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	M,@object                       # @M
	.bss
	.globl	M
	.p2align	4, 0x0
M:
	.zero	4194304
	.size	M, 4194304

	.type	N,@object                       # @N
	.globl	N
	.p2align	4, 0x0
N:
	.zero	4194304
	.size	N, 4194304

	.type	P,@object                       # @P
	.globl	P
	.p2align	4, 0x0
P:
	.zero	4194304
	.size	P, 4194304

	.type	MxN,@object                     # @MxN
	.globl	MxN
	.p2align	4, 0x0
MxN:
	.zero	4194304
	.size	MxN, 4194304

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CPU time: %13lf msec\n"
	.size	.L.str, 22

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"CPU transpose time: %13f msec\n"
	.size	.L.str.1, 31

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

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"GPU mat-mul time: %13f msec\n"
	.size	.L.str.2, 29

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"GPU total time: %13f msec\n"
	.size	.L.str.3, 27

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"before kernel call: error = %s\n"
	.size	.L.str.4, 32

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"MxN[%d][%d] = %d   P[%d][%d] = %d\n"
	.size	.L.str.5, 35

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Test %s\n"
	.size	.L.str.6, 9

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"FAILED"
	.size	.L.str.8, 7

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7mat_mulPiS_S_"
	.size	.L__unnamed_1, 17

	.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 _Z22__device_stub__mat_mulPiS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym M
	.addrsig_sym N
	.addrsig_sym P
	.addrsig_sym _Z7mat_mulPiS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7mat_mulPiS_S_        ; -- Begin function _Z7mat_mulPiS_S_
	.globl	_Z7mat_mulPiS_S_
	.p2align	8
	.type	_Z7mat_mulPiS_S_,@function
_Z7mat_mulPiS_S_:                       ; @_Z7mat_mulPiS_S_
; %bb.0:
	s_load_b32 s4, s[0:1], 0x24
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_add_u32 s2, s0, 24
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s4, 0xffff
	s_mov_b32 s4, exec_lo
	v_mad_u32_u24 v6, v0, s8, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e32 0x100000, v6
	s_cbranch_execz .LBB0_5
; %bb.1:                                ; %.lr.ph
	s_load_b32 s9, s[2:3], 0xc
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s0, s9, 16
	s_mov_b32 s9, 0
	s_mul_i32 s8, s0, s8
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	v_ashrrev_i32_e32 v0, 31, v6
	s_mov_b64 s[0:1], 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v0, 22, v0
	v_add_nc_u32_e32 v1, v6, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v0, 10, v1
	v_and_b32_e32 v1, 0xfffffc00, v1
	v_mul_i32_i24_e32 v0, 0x400, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v2, 31, v1
	v_sub_nc_u32_e32 v0, v6, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_dual_mov_b32 v1, 0 :: v_dual_lshlrev_b32 v4, 10, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v9, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v10, vcc_lo, s7, v5, vcc_lo
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_co_u32 v4, vcc_lo, v7, s0
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v11, vcc_lo, v9, s0
	v_add_co_ci_u32_e32 v12, vcc_lo, s1, v10, vcc_lo
	s_add_u32 s0, s0, 4
	global_load_b32 v13, v[4:5], off
	global_load_b32 v11, v[11:12], off
	s_addc_u32 s1, s1, 0
	s_cmpk_eq_i32 s0, 0x1000
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[4:5], null, v11, v13, v[1:2]
	s_delay_alu instid0(VALU_DEP_1)
	v_mov_b32_e32 v1, v4
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
	v_add_nc_u32_e32 v6, s8, v6
	v_add_co_u32 v2, vcc_lo, s2, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_cmp_lt_i32_e32 vcc_lo, 0xfffff, v6
	s_or_b32 s9, vcc_lo, s9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v0, s0, v2, v0
	v_add_co_ci_u32_e64 v1, s0, v3, v1, s0
	global_store_b32 v[0:1], v4, off
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_2
.LBB0_5:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7mat_mulPiS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 14
		.amdhsa_next_free_sgpr 10
		.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	_Z7mat_mulPiS_S_, .Lfunc_end0-_Z7mat_mulPiS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 412
; NumSgprs: 12
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 12
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
