#include <stdio.h>
#include <sys/time.h>
#include <cuda.h>

const int THREADS = 512;

static void CudaTest(const char *msg)
{
  cudaError_t e;
  cudaDeviceSynchronize();
  if (cudaSuccess != (e = cudaGetLastError())) {
    fprintf(stderr, "%s: %d\n", msg, e);
    fprintf(stderr, "%s\n", cudaGetErrorString(e));
    exit(-1);
  }
}

__global__ void matrixMult(const int N, int part, float *d_A, float *d_B, float *d_C) 
{
  int index = threadIdx.x + blockIdx.x * blockDim.x; 
  double pSum = 0.0;

  if (index < part * N) 
  { 
    int r = index / N;
    int c = index % N;

#pragma loop unroll
    for (int i = 0; i < N; i++) {
      pSum += d_A[r * N + i] * d_B[i * N + c];
    }
    d_C[index] = pSum; 
  } 
}

int main(int argc, char* argv[])
{
  if(argc != 3) {fprintf(stderr, "usage: <exe>, size_of_array, num_groups\n"); exit(-1);}

  const int N = atoi(argv[1]);
  float *d_A, *d_B, *d_C; //device variables 

  cudaDeviceProp prop;
  cudaGetDeviceProperties(&prop, 0);
  printf("Running on %s\n", prop.name); 

  //timing
  struct timeval start, end; 
  double runtime = 0.0, total = 0.0;

  const int factor = atoi(argv[2]);
  int part = N / factor;

  //allocate on CPU
  float *arrayA, *arrayB, *arrayC;
  cudaHostAlloc(&arrayA, N * N * sizeof(float), cudaHostAllocDefault); CudaTest("failed allocation");
  cudaHostAlloc(&arrayB, N * N * sizeof(float), cudaHostAllocDefault); CudaTest("failed allocation");
  cudaHostAlloc(&arrayC, N * N * sizeof(float), cudaHostAllocDefault); CudaTest("failed allocation");

  //create cuda streams
  cudaStream_t streams[factor];
  for(int i = 0; i < factor; i++) {cudaStreamCreate(&streams[i]);}

  //fill array inputs on CPU
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {     
      arrayA[i * N + j] = 1.0 * (i * N + j);
      arrayB[i * N + j] = 2.0 * i;
    } 

  //allocate space on GPU
  cudaMalloc((void**) &d_A, part * N * sizeof(float)); CudaTest("failed allocation");
  cudaMalloc((void**) &d_B, N * N * sizeof(float)); CudaTest("failed allocation");
  cudaMalloc((void**) &d_C, part * N * sizeof(float)); CudaTest("failed allocation");

  cudaMemcpyAsync(d_B, arrayB, N * N * sizeof(float), cudaMemcpyHostToDevice); CudaTest("failed to send data to GPU");

  for(int i = 0; i < factor; i++) {
    //send part data to GPU for MM
    cudaMemcpyAsync(d_A, &arrayA[(i * part) * N], part * N * sizeof(float), cudaMemcpyHostToDevice, streams[i]); 
                                                                  CudaTest("failed to send data to GPU");
 
    //run first kernel
    gettimeofday(&start, NULL);   
    matrixMult<<<((part * N + THREADS -1)/THREADS), THREADS, 0, streams[i]>>> (N, part, d_A, d_B, d_C); //CudaTest("failed kernel"); 
    cudaDeviceSynchronize();
    gettimeofday(&end, NULL);
    runtime = end.tv_sec + (end.tv_usec / 1000000.0) - start.tv_sec - (start.tv_usec / 1000000.0);
    total += runtime;
   
    //send part data back to CPU for MM
    cudaMemcpyAsync(&arrayC[(i * part) * N], d_C, part * N * sizeof(float), cudaMemcpyDeviceToHost, streams[i]); 
                                                                         CudaTest("failed to send data back");
  }
  printf("\nCompute time for Matrix Multiply: %.8f s\n", total);

  //check result
/*  for (int i = 0; i < N; i++) 
    for(int j = 0; j < N; j++) 
    { 
      printf("Array C: %.2lf \n", arrayC[i * N + j]);  
    }
*/

  //free streams
  for(int i = 0; i < factor; i ++) {
    cudaStreamSynchronize(streams[i]);
    cudaStreamDestroy(streams[i]);
  }

  //free memory
  cudaFree(d_A); cudaFree(d_B); cudaFree(d_C);
  cudaFreeHost(arrayA); cudaFreeHost(arrayB); cudaFreeHost(arrayC); 
  
  return 0;
}

	.file	"tmpxft_002133cd_00000000-6_optGPUtest.cudafe1.cpp"
	.text
#APP

	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s: %d\n"
.LC1:
	.string	"%s\n"
#NO_APP
	.text
	.type	_ZL8CudaTestPKc, @function
_ZL8CudaTestPKc:
.LFB2027:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rdx
	.cfi_def_cfa_offset 32
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L1
	movq	stderr(%rip), %rdi
	movl	%eax, %r8d
	movq	%rbp, %rcx
	movl	%eax, %ebx
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L1:
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_ZL8CudaTestPKc, .-_ZL8CudaTestPKc
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_
	.type	_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_, @function
_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	48(%rsp), %rdi
	movl	%esi, 24(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 16(%rsp)
	leaq	32(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L6
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10matrixMultiiPfS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	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 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L6:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_, .-_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_
	.globl	_Z10matrixMultiiPfS_S_
	.type	_Z10matrixMultiiPfS_S_, @function
_Z10matrixMultiiPfS_S_:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_
	.cfi_endproc
.LFE2054:
	.size	_Z10matrixMultiiPfS_S_, .-_Z10matrixMultiiPfS_S_
	.section	.rodata.str1.1
.LC3:
	.string	"usage: <exe>, size_of_array, num_groups\n"
.LC4:
	.string	"Running on %s\n"
.LC5:
	.string	"failed allocation"
.LC6:
	.string	"failed to send data to GPU"
.LC8:
	.string	"failed to send data back"
.LC9:
	.string	"\nCompute time for Matrix Multiply: %.8f s\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$1192, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	je	.L12
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L12:
	movq	8(%rsi), %rdi
	leaq	-1088(%rbp), %r13
	movq	%rsi, %r12
	call	atoi@PLT
	movq	%r13, %rdi
	xorl	%esi, %esi
	movl	%eax, %ebx
	call	cudaGetDeviceProperties_v2@PLT
	movq	%r13, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rsi
	leaq	.LC5(%rip), %r13
	call	__printf_chk@PLT
	movq	16(%r12), %rdi
	call	atoi@PLT
	leaq	-1168(%rbp), %rdi
	movl	%eax, -1220(%rbp)
	movl	%ebx, %eax
	cltd
	idivl	-1220(%rbp)
	xorl	%edx, %edx
	movl	%eax, -1224(%rbp)
	movl	%ebx, %eax
	imull	%ebx, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, -1208(%rbp)
	call	cudaHostAlloc@PLT
	movq	%r13, %rdi
	call	_ZL8CudaTestPKc
	movq	-1208(%rbp), %rsi
	xorl	%edx, %edx
	leaq	-1160(%rbp), %rdi
	call	cudaHostAlloc@PLT
	movq	%r13, %rdi
	call	_ZL8CudaTestPKc
	movq	-1208(%rbp), %rsi
	xorl	%edx, %edx
	leaq	-1152(%rbp), %rdi
	call	cudaHostAlloc@PLT
	movq	%r13, %rdi
	call	_ZL8CudaTestPKc
	movslq	-1220(%rbp), %rax
	movq	%rsp, %rcx
	leaq	15(,%rax,8), %rdx
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rcx
.L13:
	cmpq	%rcx, %rsp
	je	.L14
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L13
.L14:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L15
	orq	$0, -8(%rsp,%rax)
.L15:
	movq	%rsp, %r12
	xorl	%r15d, %r15d
	movq	%r12, %r14
.L16:
	movl	-1220(%rbp), %eax
	cmpl	%eax, %r15d
	jge	.L32
	movq	%r14, %rdi
	incl	%r15d
	addq	$8, %r14
	call	cudaStreamCreate@PLT
	jmp	.L16
.L32:
	movslq	%ebx, %rdi
	movq	-1168(%rbp), %r9
	xorl	%r8d, %r8d
	xorl	%esi, %esi
	movq	-1160(%rbp), %r10
	salq	$2, %rdi
	xorl	%eax, %eax
.L18:
	cmpl	%ebx, %eax
	jge	.L33
	cvtsi2sdl	%eax, %xmm0
	movq	%rsi, %rcx
	xorl	%edx, %edx
	addsd	%xmm0, %xmm0
	cvtsd2ss	%xmm0, %xmm0
.L19:
	leal	(%rdx,%r8), %r11d
	incl	%edx
	cvtsi2ssl	%r11d, %xmm1
	movss	%xmm1, (%r9,%rcx)
	movss	%xmm0, (%r10,%rcx)
	addq	$4, %rcx
	cmpl	%edx, %ebx
	jne	.L19
	incl	%eax
	addq	%rdi, %rsi
	addl	%ebx, %r8d
	jmp	.L18
.L33:
	movl	-1224(%rbp), %r15d
	leaq	-1192(%rbp), %rdi
	xorl	%r14d, %r14d
	imull	%ebx, %r15d
	movslq	%r15d, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, -1216(%rbp)
	call	cudaMalloc@PLT
	movq	%r13, %rdi
	call	_ZL8CudaTestPKc
	movq	-1208(%rbp), %rsi
	leaq	-1184(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	%r13, %rdi
	call	_ZL8CudaTestPKc
	movq	-1216(%rbp), %rsi
	leaq	-1176(%rbp), %rdi
	call	cudaMalloc@PLT
	movq	%r13, %rdi
	xorl	%r13d, %r13d
	call	_ZL8CudaTestPKc
	movq	-1208(%rbp), %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	movq	-1160(%rbp), %rsi
	movq	-1184(%rbp), %rdi
	call	cudaMemcpyAsync@PLT
	leaq	.LC6(%rip), %rdi
	call	_ZL8CudaTestPKc
	leal	511(%r15), %eax
	movl	$512, %ecx
	movq	$0x000000000, -1208(%rbp)
	movabsq	$4294967808, %r15
	cltd
	idivl	%ecx
	movl	%eax, -1228(%rbp)
.L21:
	cmpl	%r13d, -1220(%rbp)
	jle	.L34
	movq	-1168(%rbp), %rsi
	movq	(%r12,%r13,8), %r8
	movl	$1, %ecx
	movq	-1216(%rbp), %rdx
	movq	-1192(%rbp), %rdi
	addq	%r14, %rsi
	call	cudaMemcpyAsync@PLT
	leaq	.LC6(%rip), %rdi
	call	_ZL8CudaTestPKc
	xorl	%esi, %esi
	leaq	-1120(%rbp), %rdi
	call	gettimeofday@PLT
	movq	(%r12,%r13,8), %r9
	xorl	%r8d, %r8d
	movq	%r15, %rdx
	movl	-1228(%rbp), %eax
	movl	$1, %ecx
	movq	%r15, -1132(%rbp)
	movl	$1, -1124(%rbp)
	movl	%eax, -1144(%rbp)
	movabsq	$4294967297, %rax
	movq	%rax, -1140(%rbp)
	movq	-1144(%rbp), %rdi
	movl	-1136(%rbp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	movq	-1176(%rbp), %r8
	movq	-1184(%rbp), %rcx
	movl	%ebx, %edi
	movq	-1192(%rbp), %rdx
	movl	-1224(%rbp), %esi
	call	_Z36__device_stub__Z10matrixMultiiPfS_S_iiPfS_S_
.L22:
	call	cudaDeviceSynchronize@PLT
	leaq	-1104(%rbp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	-1152(%rbp), %rdi
	movq	(%r12,%r13,8), %r8
	movl	$2, %ecx
	cvtsi2sdq	-1096(%rbp), %xmm0
	movsd	.LC7(%rip), %xmm2
	incq	%r13
	cvtsi2sdq	-1104(%rbp), %xmm1
	movq	-1216(%rbp), %rdx
	addq	%r14, %rdi
	movq	-1176(%rbp), %rsi
	divsd	%xmm2, %xmm0
	addsd	%xmm1, %xmm0
	cvtsi2sdq	-1120(%rbp), %xmm1
	subsd	%xmm1, %xmm0
	cvtsi2sdq	-1112(%rbp), %xmm1
	divsd	%xmm2, %xmm1
	subsd	%xmm1, %xmm0
	addsd	-1208(%rbp), %xmm0
	movsd	%xmm0, -1208(%rbp)
	call	cudaMemcpyAsync@PLT
	leaq	.LC8(%rip), %rdi
	call	_ZL8CudaTestPKc
	movq	-1216(%rbp), %rax
	addq	%rax, %r14
	jmp	.L21
.L34:
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	xorl	%ebx, %ebx
	movsd	-1208(%rbp), %xmm0
	call	__printf_chk@PLT
.L24:
	cmpl	%ebx, -1220(%rbp)
	jle	.L35
	movq	(%r12,%rbx,8), %rdi
	call	cudaStreamSynchronize@PLT
	movq	(%r12,%rbx,8), %rdi
	incq	%rbx
	call	cudaStreamDestroy@PLT
	jmp	.L24
.L35:
	movq	-1192(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1184(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1176(%rbp), %rdi
	call	cudaFree@PLT
	movq	-1168(%rbp), %rdi
	call	cudaFreeHost@PLT
	movq	-1160(%rbp), %rdi
	call	cudaFreeHost@PLT
	movq	-1152(%rbp), %rdi
	call	cudaFreeHost@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z10matrixMultiiPfS_S_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10matrixMultiiPfS_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
.LFE2056:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC7:
	.long	0
	.long	1093567616
	.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 <sys/time.h>
#include <hip/hip_runtime.h>

const int THREADS = 512;

static void CudaTest(const char *msg)
{
  hipError_t e;
  hipDeviceSynchronize();
  if (hipSuccess != (e = hipGetLastError())) {
    fprintf(stderr, "%s: %d\n", msg, e);
    fprintf(stderr, "%s\n", hipGetErrorString(e));
    exit(-1);
  }
}

__global__ void matrixMult(const int N, int part, float *d_A, float *d_B, float *d_C) 
{
  int index = threadIdx.x + blockIdx.x * blockDim.x; 
  double pSum = 0.0;

  if (index < part * N) 
  { 
    int r = index / N;
    int c = index % N;

#pragma loop unroll
    for (int i = 0; i < N; i++) {
      pSum += d_A[r * N + i] * d_B[i * N + c];
    }
    d_C[index] = pSum; 
  } 
}

int main(int argc, char* argv[])
{
  if(argc != 3) {fprintf(stderr, "usage: <exe>, size_of_array, num_groups\n"); exit(-1);}

  const int N = atoi(argv[1]);
  float *d_A, *d_B, *d_C; //device variables 

  hipDeviceProp_t prop;
  hipGetDeviceProperties(&prop, 0);
  printf("Running on %s\n", prop.name); 

  //timing
  struct timeval start, end; 
  double runtime = 0.0, total = 0.0;

  const int factor = atoi(argv[2]);
  int part = N / factor;

  //allocate on CPU
  float *arrayA, *arrayB, *arrayC;
  hipHostAlloc(&arrayA, N * N * sizeof(float), hipHostMallocDefault); CudaTest("failed allocation");
  hipHostAlloc(&arrayB, N * N * sizeof(float), hipHostMallocDefault); CudaTest("failed allocation");
  hipHostAlloc(&arrayC, N * N * sizeof(float), hipHostMallocDefault); CudaTest("failed allocation");

  //create cuda streams
  hipStream_t streams[factor];
  for(int i = 0; i < factor; i++) {hipStreamCreate(&streams[i]);}

  //fill array inputs on CPU
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {     
      arrayA[i * N + j] = 1.0 * (i * N + j);
      arrayB[i * N + j] = 2.0 * i;
    } 

  //allocate space on GPU
  hipMalloc((void**) &d_A, part * N * sizeof(float)); CudaTest("failed allocation");
  hipMalloc((void**) &d_B, N * N * sizeof(float)); CudaTest("failed allocation");
  hipMalloc((void**) &d_C, part * N * sizeof(float)); CudaTest("failed allocation");

  hipMemcpyAsync(d_B, arrayB, N * N * sizeof(float), hipMemcpyHostToDevice); CudaTest("failed to send data to GPU");

  for(int i = 0; i < factor; i++) {
    //send part data to GPU for MM
    hipMemcpyAsync(d_A, &arrayA[(i * part) * N], part * N * sizeof(float), hipMemcpyHostToDevice, streams[i]); 
                                                                  CudaTest("failed to send data to GPU");
 
    //run first kernel
    gettimeofday(&start, NULL);   
    matrixMult<<<((part * N + THREADS -1)/THREADS), THREADS, 0, streams[i]>>> (N, part, d_A, d_B, d_C); //CudaTest("failed kernel"); 
    hipDeviceSynchronize();
    gettimeofday(&end, NULL);
    runtime = end.tv_sec + (end.tv_usec / 1000000.0) - start.tv_sec - (start.tv_usec / 1000000.0);
    total += runtime;
   
    //send part data back to CPU for MM
    hipMemcpyAsync(&arrayC[(i * part) * N], d_C, part * N * sizeof(float), hipMemcpyDeviceToHost, streams[i]); 
                                                                         CudaTest("failed to send data back");
  }
  printf("\nCompute time for Matrix Multiply: %.8f s\n", total);

  //check result
/*  for (int i = 0; i < N; i++) 
    for(int j = 0; j < N; j++) 
    { 
      printf("Array C: %.2lf \n", arrayC[i * N + j]);  
    }
*/

  //free streams
  for(int i = 0; i < factor; i ++) {
    hipStreamSynchronize(streams[i]);
    hipStreamDestroy(streams[i]);
  }

  //free memory
  hipFree(d_A); hipFree(d_B); hipFree(d_C);
  hipHostFree(arrayA); hipHostFree(arrayB); hipHostFree(arrayC); 
  
  return 0;
}

	.text
	.file	"optGPUtest.hip"
	.globl	_Z25__device_stub__matrixMultiiPfS_S_ # -- Begin function _Z25__device_stub__matrixMultiiPfS_S_
	.type	_Z25__device_stub__matrixMultiiPfS_S_,@function
_Z25__device_stub__matrixMultiiPfS_S_:  # @_Z25__device_stub__matrixMultiiPfS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	4(%rsp), %rax
	movl	%edi, (%rax)
	movq	%rsp, %rdi
	movl	%esi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%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	$_Z10matrixMultiiPfS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z25__device_stub__matrixMultiiPfS_S_, .Lfunc_end0-_Z25__device_stub__matrixMultiiPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$1624, %rsp                     # imm = 0x658
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	cmpl	$3, %edi
	jne	.LBB1_19
# %bb.1:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r15d
	leaq	-1664(%rbp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.1, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %ebx
	movl	%r15d, %eax
	cltd
	idivl	%ebx
	movl	%eax, -48(%rbp)                 # 4-byte Spill
	movl	%r15d, -44(%rbp)                # 4-byte Spill
	movl	%r15d, %r14d
	imull	%r14d, %r14d
	shlq	$2, %r14
	leaq	-88(%rbp), %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	movl	$.L.str.2, %edi
	callq	_ZL8CudaTestPKc
	leaq	-80(%rbp), %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	movl	$.L.str.2, %edi
	callq	_ZL8CudaTestPKc
	leaq	-112(%rbp), %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	movl	$.L.str.2, %edi
	callq	_ZL8CudaTestPKc
	movq	%rsp, %r13
	movl	%ebx, %eax
	movq	%rsp, %r12
	movq	%rax, -56(%rbp)                 # 8-byte Spill
	leaq	15(,%rax,8), %rax
	andq	$-16, %rax
	subq	%rax, %r12
	movq	%r12, %rsp
	testl	%ebx, %ebx
	jle	.LBB1_4
# %bb.2:
	movq	-56(%rbp), %r15                 # 8-byte Reload
	movq	%r12, %rbx
.LBB1_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	callq	hipStreamCreate
	addq	$8, %rbx
	decq	%r15
	jne	.LBB1_3
.LBB1_4:                                # %.preheader82
	cmpl	$0, -44(%rbp)                   # 4-byte Folded Reload
	jle	.LBB1_9
# %bb.5:                                # %.preheader.lr.ph
	movq	-88(%rbp), %rax
	movq	-80(%rbp), %rcx
	movl	-44(%rbp), %edx                 # 4-byte Reload
	xorl	%esi, %esi
	xorl	%edi, %edi
.LBB1_6:                                # %.lr.ph85
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_7 Depth 2
	movl	%esi, %r8d
	shlq	$2, %r8
	leaq	(%rcx,%r8), %r9
	addq	%rax, %r8
	xorps	%xmm0, %xmm0
	cvtsi2sd	%edi, %xmm0
	addsd	%xmm0, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	xorl	%r10d, %r10d
.LBB1_7:                                #   Parent Loop BB1_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%rsi,%r10), %r11d
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r11d, %xmm1
	movss	%xmm1, (%r8,%r10,4)
	movss	%xmm0, (%r9,%r10,4)
	incq	%r10
	cmpq	%r10, %rdx
	jne	.LBB1_7
# %bb.8:                                # %._crit_edge
                                        #   in Loop: Header=BB1_6 Depth=1
	incq	%rdi
	addq	%rdx, %rsi
	cmpq	%rdx, %rdi
	jne	.LBB1_6
.LBB1_9:                                # %._crit_edge87
	movq	%r12, -72(%rbp)                 # 8-byte Spill
	movl	-48(%rbp), %eax                 # 4-byte Reload
	movl	%eax, %r15d
	imull	-44(%rbp), %r15d                # 4-byte Folded Reload
	movslq	%r15d, %r12
	shlq	$2, %r12
	leaq	-104(%rbp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movl	$.L.str.2, %edi
	callq	_ZL8CudaTestPKc
	leaq	-120(%rbp), %rbx
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movl	$.L.str.2, %edi
	callq	_ZL8CudaTestPKc
	leaq	-96(%rbp), %rdi
	movq	%r12, -136(%rbp)                # 8-byte Spill
	movq	%r12, %rsi
	callq	hipMalloc
	movl	$.L.str.2, %edi
	callq	_ZL8CudaTestPKc
	movq	(%rbx), %rdi
	movq	-80(%rbp), %rsi
	xorl	%ebx, %ebx
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	hipMemcpyAsync
	movl	$.L.str.3, %edi
	callq	_ZL8CudaTestPKc
	cmpl	$0, -56(%rbp)                   # 4-byte Folded Reload
	jle	.LBB1_10
# %bb.15:                               # %.lr.ph91
	movq	%r13, -128(%rbp)                # 8-byte Spill
	movabsq	$4294967296, %rcx               # imm = 0x100000000
	leal	511(%r15), %eax
	leal	1022(%r15), %edx
	testl	%eax, %eax
	cmovnsl	%eax, %edx
	sarl	$9, %edx
	btsq	$32, %rdx
	movq	%rdx, -144(%rbp)                # 8-byte Spill
	xorps	%xmm0, %xmm0
	movsd	%xmm0, -64(%rbp)                # 8-byte Spill
	addq	$512, %rcx                      # imm = 0x200
	movq	%rcx, -152(%rbp)                # 8-byte Spill
	xorl	%r13d, %r13d
	movq	-136(%rbp), %r12                # 8-byte Reload
.LBB1_16:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, -160(%rbp)                # 8-byte Spill
	movq	-104(%rbp), %rdi
	movslq	%ebx, %r14
	shlq	$2, %r14
	movq	-88(%rbp), %rsi
	addq	%r14, %rsi
	movq	-72(%rbp), %rbx                 # 8-byte Reload
	movq	(%rbx,%r13,8), %r8
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movl	$.L.str.3, %edi
	callq	_ZL8CudaTestPKc
	leaq	-192(%rbp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx,%r13,8), %r9
	movq	-144(%rbp), %rdi                # 8-byte Reload
	movl	$1, %esi
	movq	-152(%rbp), %rdx                # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_18
# %bb.17:                               #   in Loop: Header=BB1_16 Depth=1
	movq	-104(%rbp), %rdx
	movq	-120(%rbp), %rcx
	movq	-96(%rbp), %r8
	movl	-44(%rbp), %edi                 # 4-byte Reload
	movl	-48(%rbp), %esi                 # 4-byte Reload
	callq	_Z25__device_stub__matrixMultiiPfS_S_
.LBB1_18:                               #   in Loop: Header=BB1_16 Depth=1
	callq	hipDeviceSynchronize
	leaq	-176(%rbp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm0, %xmm0
	cvtsi2sdq	-176(%rbp), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdq	-168(%rbp), %xmm1
	movsd	.LCPI1_0(%rip), %xmm3           # xmm3 = mem[0],zero
	divsd	%xmm3, %xmm1
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sdq	-192(%rbp), %xmm0
	xorps	%xmm2, %xmm2
	cvtsi2sdq	-184(%rbp), %xmm2
	subsd	%xmm0, %xmm1
	divsd	%xmm3, %xmm2
	subsd	%xmm2, %xmm1
	movsd	-64(%rbp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	addsd	%xmm1, %xmm0
	movsd	%xmm0, -64(%rbp)                # 8-byte Spill
	addq	-112(%rbp), %r14
	movq	-96(%rbp), %rsi
	movq	-72(%rbp), %rax                 # 8-byte Reload
	movq	(%rax,%r13,8), %r8
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
	movl	$.L.str.4, %edi
	callq	_ZL8CudaTestPKc
	incq	%r13
	movq	-160(%rbp), %rax                # 8-byte Reload
	addl	%r15d, %eax
	movq	-56(%rbp), %r14                 # 8-byte Reload
	cmpq	%r13, %r14
	movq	%rax, %rbx
	jne	.LBB1_16
# %bb.12:                               # %._crit_edge92
	movl	$.L.str.5, %edi
	movsd	-64(%rbp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	testl	%r14d, %r14d
	movq	-128(%rbp), %r13                # 8-byte Reload
	movq	-72(%rbp), %r12                 # 8-byte Reload
	jle	.LBB1_11
# %bb.13:                               # %.lr.ph95.preheader
	xorl	%ebx, %ebx
.LBB1_14:                               # %.lr.ph95
                                        # =>This Inner Loop Header: Depth=1
	movq	(%r12,%rbx,8), %rdi
	callq	hipStreamSynchronize
	movq	(%r12,%rbx,8), %rdi
	callq	hipStreamDestroy
	incq	%rbx
	cmpq	%rbx, %r14
	jne	.LBB1_14
	jmp	.LBB1_11
.LBB1_10:                               # %._crit_edge92.thread
	movl	$.L.str.5, %edi
	xorps	%xmm0, %xmm0
	movb	$1, %al
	callq	printf
.LBB1_11:                               # %._crit_edge96
	movq	-104(%rbp), %rdi
	callq	hipFree
	movq	-120(%rbp), %rdi
	callq	hipFree
	movq	-96(%rbp), %rdi
	callq	hipFree
	movq	-88(%rbp), %rdi
	callq	hipHostFree
	movq	-80(%rbp), %rdi
	callq	hipHostFree
	movq	-112(%rbp), %rdi
	callq	hipHostFree
	movq	%r13, %rsp
	xorl	%eax, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB1_19:
	.cfi_def_cfa %rbp, 16
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$40, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$-1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	_ZL8CudaTestPKc,@function       # -- Begin function _ZL8CudaTestPKc
_ZL8CudaTestPKc:                        # @_ZL8CudaTestPKc
	.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, %r14
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_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
.LBB2_2:
	.cfi_def_cfa_offset 32
	movl	%eax, %ebx
	movq	stderr(%rip), %rdi
	movl	$.L.str.6, %esi
	movq	%r14, %rdx
	movl	%eax, %ecx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %r14
	movl	%ebx, %edi
	callq	hipGetErrorString
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %edi
	callq	exit
.Lfunc_end2:
	.size	_ZL8CudaTestPKc, .Lfunc_end2-_ZL8CudaTestPKc
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10matrixMultiiPfS_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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB4_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z10matrixMultiiPfS_S_,@object  # @_Z10matrixMultiiPfS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z10matrixMultiiPfS_S_
	.p2align	3, 0x0
_Z10matrixMultiiPfS_S_:
	.quad	_Z25__device_stub__matrixMultiiPfS_S_
	.size	_Z10matrixMultiiPfS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"usage: <exe>, size_of_array, num_groups\n"
	.size	.L.str, 41

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Running on %s\n"
	.size	.L.str.1, 15

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"failed allocation"
	.size	.L.str.2, 18

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"failed to send data to GPU"
	.size	.L.str.3, 27

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"failed to send data back"
	.size	.L.str.4, 25

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\nCompute time for Matrix Multiply: %.8f s\n"
	.size	.L.str.5, 43

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10matrixMultiiPfS_S_"
	.size	.L__unnamed_1, 23

	.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 _Z25__device_stub__matrixMultiiPfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z10matrixMultiiPfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10matrixMultiiPfS_S_  ; -- Begin function _Z10matrixMultiiPfS_S_
	.globl	_Z10matrixMultiiPfS_S_
	.p2align	8
	.type	_Z10matrixMultiiPfS_S_,@function
_Z10matrixMultiiPfS_S_:                 ; @_Z10matrixMultiiPfS_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_mul_i32 s3, s3, s2
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, s3, v1
	s_and_saveexec_b32 s3, vcc_lo
	s_cbranch_execz .LBB0_7
; %bb.1:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x18
	v_ashrrev_i32_e32 v2, 31, v1
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB0_5
; %bb.2:                                ; %.lr.ph
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v4, v1, v2
	s_add_i32 s8, s2, s3
	v_mov_b32_e32 v5, 0
	s_xor_b32 s3, s8, s3
	v_mov_b32_e32 v6, 0
	v_cvt_f32_u32_e32 v0, s3
	s_sub_i32 s8, 0, s3
	v_xor_b32_e32 v4, v4, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, s8, v0
	v_mul_hi_u32 v3, v0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v0, v3
	v_mul_hi_u32 v0, v4, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v0, s3
	v_sub_nc_u32_e32 v0, v4, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v3, s3, v0
	v_cmp_le_u32_e32 vcc_lo, s3, v0
	v_cndmask_b32_e32 v0, v0, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v3, s3, v0
	v_cmp_le_u32_e32 vcc_lo, s3, v0
	s_mov_b32 s3, 0
	v_cndmask_b32_e32 v0, v0, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v0, v0, v2
	v_sub_nc_u32_e32 v3, v0, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_sub_nc_u32_e32 v0, v1, v3
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v7, s3, v0
	v_ashrrev_i32_e32 v4, 31, v3
	s_add_i32 s3, s3, 1
	s_cmp_eq_u32 s2, s3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v8, 31, v7
	v_lshlrev_b64 v[9:10], 2, v[3:4]
	v_add_nc_u32_e32 v3, s2, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, vcc_lo, s6, v9
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v10, vcc_lo, s7, v10, vcc_lo
	v_add_co_u32 v7, vcc_lo, s4, v7
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v8, vcc_lo
	global_load_b32 v4, v[9:10], off
	global_load_b32 v7, v[7:8], off
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v4, v7, v4
	v_cvt_f64_f32_e32 v[7:8], v4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[5:6], v[5:6], v[7:8]
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ; %._crit_edge.loopexit
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_f64_e32 v0, v[5:6]
	s_branch .LBB0_6
.LBB0_5:
	v_mov_b32_e32 v0, 0
.LBB0_6:                                ; %Flow
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[1:2], v0, off
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10matrixMultiiPfS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 0
		.amdhsa_next_free_vgpr 11
		.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	_Z10matrixMultiiPfS_S_, .Lfunc_end0-_Z10matrixMultiiPfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 464
; NumSgprs: 18
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 11
; 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: 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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .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:           _Z10matrixMultiiPfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10matrixMultiiPfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
