/*  Molecular dynamics simulation linear code for binary Lennard-Jones liquid
   under NVE ensemble; Author: You-Liang Zhu, Email: youliangzhu@ciac.ac.cn
    Copyright: You-Liang Zhu
    This code is free: you can redistribute it and/or modify it under the terms
   of the GNU General Public License.*/
#include <ctype.h>
#include <cuda_runtime.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
// check CUDA error
void checkCUDAError(const char *msg) {
  cudaError_t err = cudaGetLastError();
  if (cudaSuccess != err) {
    fprintf(stderr, "Cuda error: %s: %s.\n", msg, cudaGetErrorString(err));
    exit(-1);
  }
}

// matrix multiplication C=A*B by device
extern "C" __global__ void matrix_kernel(float *d_c, float *d_a, float *d_b,
                                         int wa, int ha, int wb) {
  float sum = 0;

  // 绑定线程到矩阵的 row 行 col 列的元素
  int row = blockIdx.x * blockDim.x + threadIdx.x;
  int col = blockIdx.y * blockDim.y + threadIdx.y;

  if (row < ha && col < wb) {
    for (int i = 0; i < wa; i++) {
      sum += d_a[row * wa + i] * d_b[i * wb + col];
    }
    d_c[row * wb + col] = sum;
  }
}

// matrix multiplication C=A*B by host
void MatrixMulCPU(float *h_d, float *h_a, float *h_b, int wa, int ha, int wb) {
  // write codes here
  for (int i = 0; i < ha; i++) {
    for (int j = 0; j < wb; j++) {
      float e = 0;
      for (int k = 0; k < wa; k++) {
        e += h_a[i * wa + k] * h_b[k * wb + j];
      }
      h_d[i * wb + j] = e;
    }
  }
}

int main(int argc, char **argv) {
  int wa = 128;                 // the width of matrix A
  int ha = 64;                  // the hight of matrix A
  int wb = ha;                  // the width of matrix B
  int N = wa * ha;              // the number of elements
  float *h_a, *h_b, *h_c, *h_d; // pointer for host memory
  float *d_a, *d_b, *d_c;       // pointer for device memory

  cudaSetDevice(0); // set GPU ID for computation

  int numThreadsPerBlock = 16; // define block size
  int numBlocks_x =
      (int)ceil((float)ha / (float)numThreadsPerBlock); // define grid size
  int numBlocks_y =
      (int)ceil((float)wb / (float)numThreadsPerBlock); // define grid size

  // Part 1 of 5: allocate host and device memory
  size_t memSize = N * sizeof(float);

  h_a = (float *)malloc(memSize);
  h_b = (float *)malloc(memSize);
  h_c = (float *)malloc(ha * wb * sizeof(float));
  h_d = (float *)malloc(ha * wb * sizeof(float));
  cudaMalloc((void **)&d_a, memSize);
  cudaMalloc((void **)&d_b, memSize);
  cudaMalloc((void **)&d_c, ha * wb * sizeof(float));

  // Part 2 of 5: initiate host array
  for (unsigned int i = 0; i < N; i++) {
    int ran = rand();
    float fran = (float)ran / (float)RAND_MAX;
    h_a[i] = fran;

    ran = rand();
    fran = (float)ran / (float)RAND_MAX;
    h_b[i] = fran;
  }

  //  matrix multiplication by host
  MatrixMulCPU(h_d, h_a, h_b, wa, ha, wb);

  // Part 3 of 5: copy data from host to device
  cudaMemcpy(d_a, h_a, memSize, cudaMemcpyHostToDevice);
  cudaMemcpy(d_b, h_b, memSize, cudaMemcpyHostToDevice);
  checkCUDAError("cudaMemcpy");

  // Part 4 of 5: launch kernel
  dim3 dimGrid(numBlocks_x, numBlocks_y);
  dim3 dimBlock(numThreadsPerBlock, numThreadsPerBlock);

  matrix_kernel<<<dimGrid, dimBlock>>>(d_c, d_a, d_b, wa, ha, wb);

  // seems that this function has been declared
  /* cudaThreadSynchronize(); // block until the device has completed */

  // check if kernel execution generated an error
  checkCUDAError("kernel execution");

  // Part 5 of 5: device to host copy
  cudaMemcpy(h_c, d_c, ha * wb * sizeof(float), cudaMemcpyDeviceToHost);
  // Check for any CUDA errors
  checkCUDAError("cudaMemcpy");

  /* for (int y = 0; y < ha; y++) { */
  /*     for (int x = 0; x < wb; x++) */
  /*         printf("%02.2f ", h_c[y * wb + x]); */
  /*     printf("\n"); */
  /* } */

  // check the results from device
  for (unsigned int i = 0; i < ha * wb; i++) {
    if (abs(h_c[i] - h_d[i]) > 0.00001) {
      fprintf(stderr, "Failed!!! %d %f %f\n", i, h_c[i], h_d[i]);
      // free device memory
      cudaFree(d_a);
      cudaFree(d_b);
      cudaFree(d_c);
      // free host memory
      free(h_a);
      free(h_b);
      free(h_c);
      free(h_d);
      exit(-1);
    }
  }
  // free device memory
  cudaFree(d_a);
  cudaFree(d_b);
  cudaFree(d_c);
  // free host memory
  free(h_a);
  free(h_b);
  free(h_c);
  free(h_d);
  // If the program makes it this far, then the results are correct and
  // there are no run-time errors.  Good work!
  printf("Success!\n");
  return 0;
}

	.file	"tmpxft_0023df8f_00000000-6_CUDA-example-matrix-multiplication-training.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Cuda error: %s: %s.\n"
	.text
	.globl	_Z14checkCUDAErrorPKc
	.type	_Z14checkCUDAErrorPKc, @function
_Z14checkCUDAErrorPKc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L2
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	leaq	.LC0(%rip), %rdx
	movq	%rax, %r8
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14checkCUDAErrorPKc, .-_Z14checkCUDAErrorPKc
	.globl	_Z12MatrixMulCPUPfS_S_iii
	.type	_Z12MatrixMulCPUPfS_S_iii, @function
_Z12MatrixMulCPUPfS_S_iii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r10
	xorl	%r11d, %r11d
	xorl	%edi, %edi
	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
	movq	%rdx, %r12
	movl	%ecx, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movslq	%r9d, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	salq	$2, %rbp
	xorl	%ebx, %ebx
.L7:
	cmpl	%r8d, %ebx
	jge	.L6
	movslq	%r11d, %rax
	leaq	(%r10,%rax,4), %r15
	movslq	%edi, %rax
	leaq	(%rsi,%rax,4), %r14
	xorl	%eax, %eax
.L12:
	cmpl	%eax, %r9d
	jle	.L9
	leaq	(%r12,%rax,4), %r13
	xorl	%ecx, %ecx
	xorps	%xmm0, %xmm0
.L10:
	cmpl	%ecx, %edx
	jle	.L14
	movss	(%r14,%rcx,4), %xmm1
	mulss	0(%r13), %xmm1
	incq	%rcx
	addq	%rbp, %r13
	addss	%xmm1, %xmm0
	jmp	.L10
.L14:
	movss	%xmm0, (%r15,%rax,4)
	incq	%rax
	jmp	.L12
.L9:
	incl	%ebx
	addl	%r9d, %r11d
	addl	%edx, %edi
	jmp	.L7
.L6:
	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
.LFE2028:
	.size	_Z12MatrixMulCPUPfS_S_iii, .-_Z12MatrixMulCPUPfS_S_iii
	.globl	_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii
	.type	_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii, @function
_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 20(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 16(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	matrix_kernel(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L15:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii, .-_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii
	.globl	matrix_kernel
	.type	matrix_kernel, @function
matrix_kernel:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii
	.cfi_endproc
.LFE2055:
	.size	matrix_kernel, .-matrix_kernel
	.section	.rodata.str1.1
.LC3:
	.string	"cudaMemcpy"
.LC4:
	.string	"kernel execution"
.LC7:
	.string	"Failed!!! %d %f %f\n"
.LC8:
	.string	"Success!\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%edi, %edi
	xorl	%r14d, %r14d
	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	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	cudaSetDevice@PLT
	movl	$32768, %edi
	call	malloc@PLT
	movl	$32768, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$16384, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$16384, %edi
	movq	%rax, %r13
	call	malloc@PLT
	leaq	8(%rsp), %rdi
	movl	$32768, %esi
	movq	%rax, %r12
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$32768, %esi
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$16384, %esi
	call	cudaMalloc@PLT
.L21:
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, 0(%rbp,%r14)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, (%rbx,%r14)
	addq	$4, %r14
	cmpq	$32768, %r14
	jne	.L21
	movl	$64, %r9d
	movq	%rbp, %rsi
	movq	%rbx, %rdx
	movq	%r12, %rdi
	movl	$64, %r8d
	movl	$128, %ecx
	leaq	.LC3(%rip), %r14
	call	_Z12MatrixMulCPUPfS_S_iii
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movl	$32768, %edx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$32768, %edx
	call	cudaMemcpy@PLT
	movq	%r14, %rdi
	call	_Z14checkCUDAErrorPKc
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$68719476752, %rdx
	movl	$1, %esi
	movabsq	$17179869188, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$64, %r9d
	movl	$64, %r8d
	movq	24(%rsp), %rdi
	movl	$128, %ecx
	call	_Z40__device_stub__Z13matrix_kernelPfS_S_iiiPfS_S_iii
.L22:
	leaq	.LC4(%rip), %rdi
	call	_Z14checkCUDAErrorPKc
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$16384, %edx
	call	cudaMemcpy@PLT
	movq	%r14, %rdi
	call	_Z14checkCUDAErrorPKc
	movsd	.LC6(%rip), %xmm4
	xorl	%ecx, %ecx
	movss	.LC5(%rip), %xmm3
.L25:
	movss	0(%r13,%rcx,4), %xmm0
	movss	(%r12,%rcx,4), %xmm1
	movaps	%xmm0, %xmm2
	subss	%xmm1, %xmm2
	andps	%xmm3, %xmm2
	cvtss2sd	%xmm2, %xmm2
	comisd	%xmm4, %xmm2
	jbe	.L30
	movl	$2, %esi
	movq	stderr(%rip), %rdi
	leaq	.LC7(%rip), %rdx
	movb	$2, %al
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	orl	$-1, %edi
	call	exit@PLT
.L30:
	incq	%rcx
	cmpq	$4096, %rcx
	jne	.L25
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	call	__printf_chk@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$64, %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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"matrix_kernel"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	matrix_kernel(%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
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC2:
	.long	805306368
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC5:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC6:
	.long	-1998362383
	.long	1055193269
	.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:

/*  Molecular dynamics simulation linear code for binary Lennard-Jones liquid
   under NVE ensemble; Author: You-Liang Zhu, Email: youliangzhu@ciac.ac.cn
    Copyright: You-Liang Zhu
    This code is free: you can redistribute it and/or modify it under the terms
   of the GNU General Public License.*/
#include <ctype.h>
#include <hip/hip_runtime.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
// check CUDA error
void checkCUDAError(const char *msg) {
  hipError_t err = hipGetLastError();
  if (hipSuccess != err) {
    fprintf(stderr, "Cuda error: %s: %s.\n", msg, hipGetErrorString(err));
    exit(-1);
  }
}

// matrix multiplication C=A*B by device
extern "C" __global__ void matrix_kernel(float *d_c, float *d_a, float *d_b,
                                         int wa, int ha, int wb) {
  float sum = 0;

  // 绑定线程到矩阵的 row 行 col 列的元素
  int row = blockIdx.x * blockDim.x + threadIdx.x;
  int col = blockIdx.y * blockDim.y + threadIdx.y;

  if (row < ha && col < wb) {
    for (int i = 0; i < wa; i++) {
      sum += d_a[row * wa + i] * d_b[i * wb + col];
    }
    d_c[row * wb + col] = sum;
  }
}

// matrix multiplication C=A*B by host
void MatrixMulCPU(float *h_d, float *h_a, float *h_b, int wa, int ha, int wb) {
  // write codes here
  for (int i = 0; i < ha; i++) {
    for (int j = 0; j < wb; j++) {
      float e = 0;
      for (int k = 0; k < wa; k++) {
        e += h_a[i * wa + k] * h_b[k * wb + j];
      }
      h_d[i * wb + j] = e;
    }
  }
}

int main(int argc, char **argv) {
  int wa = 128;                 // the width of matrix A
  int ha = 64;                  // the hight of matrix A
  int wb = ha;                  // the width of matrix B
  int N = wa * ha;              // the number of elements
  float *h_a, *h_b, *h_c, *h_d; // pointer for host memory
  float *d_a, *d_b, *d_c;       // pointer for device memory

  hipSetDevice(0); // set GPU ID for computation

  int numThreadsPerBlock = 16; // define block size
  int numBlocks_x =
      (int)ceil((float)ha / (float)numThreadsPerBlock); // define grid size
  int numBlocks_y =
      (int)ceil((float)wb / (float)numThreadsPerBlock); // define grid size

  // Part 1 of 5: allocate host and device memory
  size_t memSize = N * sizeof(float);

  h_a = (float *)malloc(memSize);
  h_b = (float *)malloc(memSize);
  h_c = (float *)malloc(ha * wb * sizeof(float));
  h_d = (float *)malloc(ha * wb * sizeof(float));
  hipMalloc((void **)&d_a, memSize);
  hipMalloc((void **)&d_b, memSize);
  hipMalloc((void **)&d_c, ha * wb * sizeof(float));

  // Part 2 of 5: initiate host array
  for (unsigned int i = 0; i < N; i++) {
    int ran = rand();
    float fran = (float)ran / (float)RAND_MAX;
    h_a[i] = fran;

    ran = rand();
    fran = (float)ran / (float)RAND_MAX;
    h_b[i] = fran;
  }

  //  matrix multiplication by host
  MatrixMulCPU(h_d, h_a, h_b, wa, ha, wb);

  // Part 3 of 5: copy data from host to device
  hipMemcpy(d_a, h_a, memSize, hipMemcpyHostToDevice);
  hipMemcpy(d_b, h_b, memSize, hipMemcpyHostToDevice);
  checkCUDAError("hipMemcpy");

  // Part 4 of 5: launch kernel
  dim3 dimGrid(numBlocks_x, numBlocks_y);
  dim3 dimBlock(numThreadsPerBlock, numThreadsPerBlock);

  matrix_kernel<<<dimGrid, dimBlock>>>(d_c, d_a, d_b, wa, ha, wb);

  // seems that this function has been declared
  /* cudaThreadSynchronize(); // block until the device has completed */

  // check if kernel execution generated an error
  checkCUDAError("kernel execution");

  // Part 5 of 5: device to host copy
  hipMemcpy(h_c, d_c, ha * wb * sizeof(float), hipMemcpyDeviceToHost);
  // Check for any CUDA errors
  checkCUDAError("hipMemcpy");

  /* for (int y = 0; y < ha; y++) { */
  /*     for (int x = 0; x < wb; x++) */
  /*         printf("%02.2f ", h_c[y * wb + x]); */
  /*     printf("\n"); */
  /* } */

  // check the results from device
  for (unsigned int i = 0; i < ha * wb; i++) {
    if (abs(h_c[i] - h_d[i]) > 0.00001) {
      fprintf(stderr, "Failed!!! %d %f %f\n", i, h_c[i], h_d[i]);
      // free device memory
      hipFree(d_a);
      hipFree(d_b);
      hipFree(d_c);
      // free host memory
      free(h_a);
      free(h_b);
      free(h_c);
      free(h_d);
      exit(-1);
    }
  }
  // free device memory
  hipFree(d_a);
  hipFree(d_b);
  hipFree(d_c);
  // free host memory
  free(h_a);
  free(h_b);
  free(h_c);
  free(h_d);
  // If the program makes it this far, then the results are correct and
  // there are no run-time errors.  Good work!
  printf("Success!\n");
  return 0;
}

	.text
	.file	"CUDA-example-matrix-multiplication-training.hip"
	.globl	_Z14checkCUDAErrorPKc           # -- Begin function _Z14checkCUDAErrorPKc
	.type	_Z14checkCUDAErrorPKc,@function
_Z14checkCUDAErrorPKc:                  # @_Z14checkCUDAErrorPKc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB0_2
# %bb.1:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB0_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z14checkCUDAErrorPKc, .Lfunc_end0-_Z14checkCUDAErrorPKc
	.cfi_endproc
                                        # -- End function
	.globl	__device_stub__matrix_kernel    # -- Begin function __device_stub__matrix_kernel
	.type	__device_stub__matrix_kernel,@function
__device_stub__matrix_kernel:           # @__device_stub__matrix_kernel
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	20(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$matrix_kernel, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	__device_stub__matrix_kernel, .Lfunc_end1-__device_stub__matrix_kernel
	.cfi_endproc
                                        # -- End function
	.globl	_Z12MatrixMulCPUPfS_S_iii       # -- Begin function _Z12MatrixMulCPUPfS_S_iii
	.type	_Z12MatrixMulCPUPfS_S_iii,@function
_Z12MatrixMulCPUPfS_S_iii:              # @_Z12MatrixMulCPUPfS_S_iii
	.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
	movq	%rsi, -16(%rsp)                 # 8-byte Spill
	movq	%rdi, -24(%rsp)                 # 8-byte Spill
	testl	%r8d, %r8d
	jle	.LBB2_9
# %bb.1:                                # %.preheader27.lr.ph
	movslq	%r9d, %rdi
	movl	%r8d, %r8d
	movl	%edi, %r10d
	movl	%ecx, %r11d
	leaq	(,%rdi,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	%r9d, %r9d
	jle	.LBB2_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r14d, %eax
	movq	-16(%rsp), %rdx                 # 8-byte Reload
	leaq	(%rdx,%rax,4), %r12
	movq	%r15, %rax
	imulq	%rdi, %rax
	movq	-24(%rsp), %rdx                 # 8-byte Reload
	leaq	(%rdx,%rax,4), %r13
	movq	-8(%rsp), %rdx                  # 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	%ecx, %ecx
	jle	.LBB2_7
# %bb.5:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_4 Depth=2
	movq	%rdx, %rbp
	xorl	%esi, %esi
.LBB2_6:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        #     Parent Loop BB2_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r12,%rsi,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rbp), %xmm1
	addss	%xmm1, %xmm0
	incq	%rsi
	addq	%rbx, %rbp
	cmpq	%rsi, %r11
	jne	.LBB2_6
.LBB2_7:                                # %._crit_edge
                                        #   in Loop: Header=BB2_4 Depth=2
	movss	%xmm0, (%r13,%rax,4)
	incq	%rax
	addq	$4, %rdx
	cmpq	%r10, %rax
	jne	.LBB2_4
.LBB2_8:                                # %._crit_edge31
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r15
	addl	%ecx, %r14d
	cmpq	%r8, %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	_Z12MatrixMulCPUPfS_S_iii, .Lfunc_end2-_Z12MatrixMulCPUPfS_S_iii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI3_1:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI3_2:
	.quad	0x3ee4f8b588e368f1              # double 1.0000000000000001E-5
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	xorl	%r13d, %r13d
	xorl	%edi, %edi
	callq	hipSetDevice
	movl	$32768, %edi                    # imm = 0x8000
	callq	malloc
	movq	%rax, %r12
	movl	$32768, %edi                    # imm = 0x8000
	callq	malloc
	movq	%rax, %r15
	movl	$16384, %edi                    # imm = 0x4000
	callq	malloc
	movq	%rax, %r14
	movl	$16384, %edi                    # imm = 0x4000
	callq	malloc
	movq	%rax, %rbx
	leaq	24(%rsp), %rdi
	movl	$32768, %esi                    # imm = 0x8000
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$32768, %esi                    # imm = 0x8000
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$16384, %esi                    # imm = 0x4000
	callq	hipMalloc
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%r12,%r13,4)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movss	%xmm0, (%r15,%r13,4)
	incq	%r13
	cmpq	$8192, %r13                     # imm = 0x2000
	jne	.LBB3_1
# %bb.2:                                # %.preheader27.i.preheader
	xorl	%eax, %eax
	movq	%r12, %rcx
.LBB3_3:                                # %.preheader27.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_4 Depth 2
                                        #       Child Loop BB3_5 Depth 3
	movq	%rax, %rdx
	shlq	$8, %rdx
	addq	%rbx, %rdx
	movq	%r15, %rsi
	xorl	%edi, %edi
.LBB3_4:                                # %.preheader.i
                                        #   Parent Loop BB3_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_5 Depth 3
	xorps	%xmm0, %xmm0
	movq	%rsi, %r8
	xorl	%r9d, %r9d
.LBB3_5:                                # %.lr.ph.i
                                        #   Parent Loop BB3_3 Depth=1
                                        #     Parent Loop BB3_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%rcx,%r9,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%r8), %xmm1
	addss	%xmm1, %xmm0
	incq	%r9
	addq	$256, %r8                       # imm = 0x100
	cmpq	$128, %r9
	jne	.LBB3_5
# %bb.6:                                # %._crit_edge.i
                                        #   in Loop: Header=BB3_4 Depth=2
	movss	%xmm0, (%rdx,%rdi,4)
	incq	%rdi
	addq	$4, %rsi
	cmpq	$64, %rdi
	jne	.LBB3_4
# %bb.7:                                # %._crit_edge31.i
                                        #   in Loop: Header=BB3_3 Depth=1
	incq	%rax
	addq	$512, %rcx                      # imm = 0x200
	cmpq	$64, %rax
	jne	.LBB3_3
# %bb.8:                                # %_Z12MatrixMulCPUPfS_S_iii.exit
	movq	24(%rsp), %rdi
	movl	$32768, %edx                    # imm = 0x8000
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	movl	$32768, %edx                    # imm = 0x8000
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.1, %edi
	callq	_Z14checkCUDAErrorPKc
	movabsq	$17179869188, %rdi              # imm = 0x400000004
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.9:
	movq	8(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movl	$128, %ecx
	movl	$64, %r8d
	movl	$64, %r9d
	callq	__device_stub__matrix_kernel
.LBB3_10:
	movl	$.L.str.2, %edi
	callq	_Z14checkCUDAErrorPKc
	movq	8(%rsp), %rsi
	movl	$16384, %edx                    # imm = 0x4000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.1, %edi
	callq	_Z14checkCUDAErrorPKc
	xorl	%edx, %edx
	movaps	.LCPI3_1(%rip), %xmm0           # xmm0 = [NaN,NaN,NaN,NaN]
	movsd	.LCPI3_2(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB3_11:                               # =>This Inner Loop Header: Depth=1
	movss	(%r14,%rdx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	movss	(%rbx,%rdx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	movaps	%xmm2, %xmm4
	subss	%xmm3, %xmm4
	andps	%xmm0, %xmm4
	cvtss2sd	%xmm4, %xmm4
	ucomisd	%xmm1, %xmm4
	ja	.LBB3_14
# %bb.12:                               #   in Loop: Header=BB3_11 Depth=1
	incq	%rdx
	cmpq	$4096, %rdx                     # imm = 0x1000
	jne	.LBB3_11
# %bb.13:
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB3_14:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rdi
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm2, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm3, %xmm1
	movl	$.L.str.3, %esi
                                        # kill: def $edx killed $edx killed $rdx
	movb	$2, %al
	callq	fprintf
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	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	$matrix_kernel, %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	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Cuda error: %s: %s.\n"
	.size	.L.str, 21

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

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"kernel execution"
	.size	.L.str.2, 17

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Failed!!! %d %f %f\n"
	.size	.L.str.3, 20

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"matrix_kernel"
	.size	.L__unnamed_1, 14

	.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	"Success!"
	.size	.Lstr, 9

	.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 __device_stub__matrix_kernel
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym matrix_kernel
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	matrix_kernel           ; -- Begin function matrix_kernel
	.globl	matrix_kernel
	.p2align	8
	.type	matrix_kernel,@function
matrix_kernel:                          ; @matrix_kernel
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[4:7], s[0:1], 0x18
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_i32_e32 vcc_lo, s5, v0
	v_cmp_gt_i32_e64 s2, s6, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_6
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_cmp_lt_i32 s4, 1
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	v_mul_lo_u32 v2, v0, s4
	v_mov_b32_e32 v6, 0
	v_mov_b32_e32 v4, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s10, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s11, v3, vcc_lo
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v5, 31, v4
	s_add_i32 s4, s4, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s4, 0
	v_lshlrev_b64 v[7:8], 2, v[4:5]
	v_add_nc_u32_e32 v4, s6, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s0, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	global_load_b32 v5, v[2:3], off
	global_load_b32 v7, v[7:8], off
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_waitcnt vmcnt(0)
	v_fmac_f32_e32 v6, v5, v7
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v6, 0
.LBB0_5:                                ; %Flow54
	v_mad_u64_u32 v[2:3], null, v0, s6, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s8, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s9, v1, vcc_lo
	global_store_b32 v[0:1], v6, off
.LBB0_6:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel matrix_kernel
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 9
		.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	matrix_kernel, .Lfunc_end0-matrix_kernel
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           matrix_kernel
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         matrix_kernel.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
