
/*************************************
 * Matrix-Vector product CUDA kernel *
 * V2: With Shared memory            *
 *************************************/

#include <stdio.h>

#define CUDA_SAFE_CALL( call ) {                                         \
 cudaError_t err = call;                                                 \
 if( cudaSuccess != err ) {                                              \
   fprintf(stderr,"CUDA: error occurred in cuda routine. Exiting...\n"); \
   exit(err);                                                            \
 } }

#define	A(i,j)		A[ (j) + ((i)*(n)) ]
#define	x(i) 		x[ (i) ]
#define	y(i) 		y[ (i) ]
#define	y_gpu(i) 	y_gpu[ (i) ]
#define	y_cpu(i) 	y_cpu[ (i) ]
#define	d_A(i,j) 	d_A[ (j) + ((i)*(n)) ]
#define	d_x(i) 		d_x[ (i) ]
#define	d_y(i) 		d_y[ (i) ]

#define min(i,j)	( (i)<(j) ? (i) : (j) )

#define	BLOCKSIZE	32

__global__ void compute_kernel( unsigned int m, unsigned int n, float *d_A, float *d_x, float *d_y ) {
  
  /* Obtain (x,y) coordinates of the thread within the block */

  /* Obtain the global index to a matrix row (variable i). Note that there is only one dimension in the grid
     so blockIdx.x and blockDim.x are the only existing variables */
  unsigned int i;
  unsigned int j;
  i = blockIdx.x * BLOCKSIZE;
  j = blockIdx.y * BLOCKSIZE;

  __syncthreads();


  /* Declare share memory space of a piece of array d_x of size BLOCKSIZE */
  __shared__ float b[BLOCKSIZE];
  /* Declare share memory space of a square block of order BLOCKSIZE */
  __shared__ float a[BLOCKSIZE*BLOCKSIZE];
  
  __syncthreads();


  if( i < m ) { /* Prevent work on positions beyond m */
 
    b[threadIdx.x] = d_x[i + threadIdx.x];
    __syncthreads();

     /* Implement Part 1 here */
     /* Loop (threadIdx.x:BLOCKSIZE:n-1) */
        /* Copy subvector x in shared memory */
        /* Perform the add+product on a local variable */
      float sum = 0.0f;
      for(int k=threadIdx.x;k<n-1;k+=BLOCKSIZE){
        sum += d_A(j,k)*b[k];
      }

     /* Save local variable in shared memory */
     a[i+BLOCKSIZE*j] = sum;

     /* Implement Part 2 here */
     /* Only if threadIdx.x==0 */
     if(threadIdx.x==0){
       for(int l = 0;l<BLOCKSIZE;l++){
         d_y(i)+=a[i + BLOCKSIZE*l];
       }
     }

       /* Add all column elements along a row of the shared memory square block */
       /* Save result in d_y */

  }
}

int cu_matrix_vector( unsigned int m, unsigned int n, float *h_A, float *h_x, float *h_y ) {

  // Allocate device memory
  float *d_A, *d_x, *d_y;
  CUDA_SAFE_CALL( cudaMalloc((void **) &d_A, m*n*sizeof(float) ) );
  CUDA_SAFE_CALL( cudaMalloc((void **) &d_x,   n*sizeof(float) ) );
  CUDA_SAFE_CALL( cudaMalloc((void **) &d_y, m  *sizeof(float) ) );

  // Copy host memory to device 
  CUDA_SAFE_CALL( cudaMemcpy( d_A, h_A, m*n*sizeof(float), cudaMemcpyHostToDevice ) );
  CUDA_SAFE_CALL( cudaMemcpy( d_x, h_x,   n*sizeof(float), cudaMemcpyHostToDevice ) );

  int n_blocks = (int) ceil( (float) m / (float) BLOCKSIZE );

  // Execute the kernel
  dim3 dimGrid( n_blocks );
  dim3 dimBlock( BLOCKSIZE, BLOCKSIZE );
  compute_kernel<<< dimGrid, dimBlock >>>( m, n, d_A, d_x, d_y );

  // Copy device memory to host 
  CUDA_SAFE_CALL( cudaMemcpy( h_y, d_y, m  *sizeof(float), cudaMemcpyDeviceToHost ) );

  // Deallocate device memory
  CUDA_SAFE_CALL( cudaFree(d_A) );
  CUDA_SAFE_CALL( cudaFree(d_x) );
  CUDA_SAFE_CALL( cudaFree(d_y) );

  return EXIT_SUCCESS;
}
 
int matrix_vector( unsigned int m, unsigned int n, float *A, float *x, float *y ) {

  unsigned int i, j;
  for( i=0; i<m; i++ ) {
    y( i ) = 0.0f;
    for( j=0; j<n; j++ ) {
      y( i ) += A( i, j ) * x( j );
    }
  }
  return EXIT_SUCCESS;

}

int main( int argc, char *argv[] ) {
  unsigned int m, n;
  unsigned int i, j;

  /* Generating input data */
  if( argc<3 ) {
    printf("Usage: %s n_rows n_cols \n",argv[0]);
    exit(-1);
  }
  sscanf(argv[1],"%d",&m);
  sscanf(argv[2],"%d",&n);
  float *A = (float *) malloc( m*n*sizeof(float) );
  float *x = (float *) malloc(   n*sizeof(float) );
  printf("%s: Generating a random matrix of size %dx%d and a vector of size %d...\n",argv[0],m,n,n);
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      A( i, j ) = 2.0f * ( (float) rand() / RAND_MAX ) - 1.0f;
    }
  }
  for( j=0; j<n; j++ ) {
    x( j ) = 2.0f * ( (float) rand() / RAND_MAX ) - 1.0f;
  }


  // Allocate CUDA events that we'll use for timing
  cudaEvent_t start, stop;
  CUDA_SAFE_CALL( cudaEventCreate(&start) );
  CUDA_SAFE_CALL( cudaEventCreate(&stop) );

  printf("%s: y=A*x in CPU...\n",argv[0]);
  float *y_cpu = (float *) malloc( m*sizeof(float) );
  CUDA_SAFE_CALL( cudaEventRecord(start, NULL) ); // Record the start event
  matrix_vector( m, n, A, x, y_cpu );
  CUDA_SAFE_CALL( cudaEventRecord(stop, NULL) );  // Record the stop event
  CUDA_SAFE_CALL( cudaEventSynchronize(stop) );   // Wait for the stop event to complete
  float msecCPU = 0.0f;
  CUDA_SAFE_CALL( cudaEventElapsedTime(&msecCPU, start, stop) );

  printf("%s: y=A*x in GPU...\n",argv[0]);
  float *y_gpu = (float *) malloc( m*sizeof(float) );
  CUDA_SAFE_CALL( cudaEventRecord(start, NULL) ); // Record the start event
  cu_matrix_vector( m, n, A, x, y_gpu );
  CUDA_SAFE_CALL( cudaEventRecord(stop, NULL) );  // Record the stop event
  CUDA_SAFE_CALL( cudaEventSynchronize(stop) );   // Wait for the stop event to complete
  float msecGPU = 0.0f;
  CUDA_SAFE_CALL( cudaEventElapsedTime(&msecGPU, start, stop) );

  /* Check for correctness */
  float max = fabs( y_cpu( 0 ) );
  for( i=1; i<m; i++ ) {
    max = fabs( y_cpu( i ) > max ? y_cpu( i ) : max );
  }
  float error = 0.0f;
  for( i=0; i<m; i++ ) {
    error += fabs( y_gpu( i ) - y_cpu( i ) );
  }
  printf("Error CPU/GPU = %.3e\n",error/max);
  double flops = 2.0 * (double) m * (double) n;
  double gigaFlopsCPU = (flops * 1.0e-9f) / (msecCPU / 1000.0f);
  double gigaFlopsGPU = (flops * 1.0e-9f) / (msecGPU / 1000.0f);
  printf("CPU time = %.2f msec.\n",msecCPU);
  printf("GPU time = %.2f msec.\n",msecGPU);
  printf("Gflops CPU = %.2f \n",gigaFlopsCPU);
  printf("Gflops GPU = %.2f \n",gigaFlopsGPU);
  
  free(A);
  free(x);
  free(y_cpu);
  free(y_gpu);
  
}


	.file	"tmpxft_00269aa1_00000000-6_MatrixVectorProduct_v2.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
	.globl	_Z13matrix_vectorjjPfS_S_
	.type	_Z13matrix_vectorjjPfS_S_, @function
_Z13matrix_vectorjjPfS_S_:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%edi, %r9d
	xorl	%r10d, %r10d
	movl	%esi, %edi
	xorl	%esi, %esi
.L3:
	cmpl	%r9d, %esi
	jnb	.L8
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L5:
	movss	%xmm0, (%r8,%rsi,4)
	cmpl	%edi, %eax
	jnb	.L9
	leal	(%r10,%rax), %r11d
	movss	(%rdx,%r11,4), %xmm1
	mulss	(%rcx,%rax,4), %xmm1
	incq	%rax
	addss	%xmm1, %xmm0
	jmp	.L5
.L9:
	incq	%rsi
	addl	%edi, %r10d
	jmp	.L3
.L8:
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z13matrix_vectorjjPfS_S_, .-_Z13matrix_vectorjjPfS_S_
	.globl	_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_
	.type	_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_, @function
_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_:
.LFB2054:
	.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	.L10
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z14compute_kerneljjPfS_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
.L10:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_, .-_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_
	.globl	_Z14compute_kerneljjPfS_S_
	.type	_Z14compute_kerneljjPfS_S_, @function
_Z14compute_kerneljjPfS_S_:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_
	.cfi_endproc
.LFE2055:
	.size	_Z14compute_kerneljjPfS_S_, .-_Z14compute_kerneljjPfS_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"CUDA: error occurred in cuda routine. Exiting...\n"
	.text
	.globl	_Z16cu_matrix_vectorjjPfS_S_
	.type	_Z16cu_matrix_vectorjjPfS_S_, @function
_Z16cu_matrix_vectorjjPfS_S_:
.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
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%rcx, 16(%rsp)
	movq	%r8, 24(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	movl	%edi, %eax
	leaq	40(%rsp), %rdi
	imull	%esi, %eax
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L30
	movl	%ebp, %eax
	leaq	48(%rsp), %rdi
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L17
.L30:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%r14d, %edi
	jmp	.L31
.L17:
	movl	%ebx, %r15d
	leaq	56(%rsp), %rdi
	leaq	0(,%r15,4), %r14
	movq	%r14, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	je	.L18
.L32:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%r12d, %edi
.L31:
	call	exit@PLT
.L18:
	movq	(%rsp), %rdx
	movq	40(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L19
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%r13d, %edi
	jmp	.L31
.L19:
	movq	8(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	48(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %r12d
	testl	%eax, %eax
	jne	.L32
	cvtsi2ssq	%r15, %xmm0
	mulss	.LC2(%rip), %xmm0
	call	ceilf@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$137438953504, %rdx
	cvttss2sil	%xmm0, %eax
	movl	%eax, 64(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 68(%rsp)
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movq	56(%rsp), %r8
	movq	48(%rsp), %rcx
	movl	%ebp, %esi
	movl	%ebx, %edi
	movq	40(%rsp), %rdx
	call	_Z40__device_stub__Z14compute_kerneljjPfS_S_jjPfS_S_
.L23:
	movq	56(%rsp), %rsi
	movq	24(%rsp), %rdi
	movl	$2, %ecx
	movq	%r14, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L33
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L33
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L33
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L27
.L33:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	jmp	.L31
.L27:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z16cu_matrix_vectorjjPfS_S_, .-_Z16cu_matrix_vectorjjPfS_S_
	.section	.rodata.str1.1
.LC3:
	.string	"Usage: %s n_rows n_cols \n"
.LC4:
	.string	"%d"
.LC5:
	.string	"%s: Generating a random matrix of size %dx%d and a vector of size %d...\n"
.LC8:
	.string	"%s: y=A*x in CPU...\n"
.LC9:
	.string	"%s: y=A*x in GPU...\n"
.LC11:
	.string	"Error CPU/GPU = %.3e\n"
.LC14:
	.string	"CPU time = %.2f msec.\n"
.LC15:
	.string	"GPU time = %.2f msec.\n"
.LC16:
	.string	"Gflops CPU = %.2f \n"
.LC17:
	.string	"Gflops GPU = %.2f \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.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
	movq	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jg	.L35
	movq	(%rsi), %rdx
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	call	__printf_chk@PLT
	orl	$-1, %edi
	jmp	.L63
.L35:
	movq	8(%rsi), %rdi
	leaq	.LC4(%rip), %rbx
	leaq	8(%rsp), %rdx
	xorl	%eax, %eax
	movq	%rbx, %rsi
	call	__isoc23_sscanf@PLT
	movq	16(%r13), %rdi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	leaq	12(%rsp), %rdx
	call	__isoc23_sscanf@PLT
	movl	8(%rsp), %r14d
	movl	12(%rsp), %ebx
	movl	%r14d, %edi
	imull	%ebx, %edi
	salq	$2, %rdi
	call	malloc@PLT
	movl	%ebx, %edi
	salq	$2, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	0(%r13), %rdx
	movl	%ebx, %r9d
	movl	%ebx, %r8d
	movq	%rax, %rbp
	movl	%r14d, %ecx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
.L36:
	cmpl	8(%rsp), %ebx
	jnb	.L66
	xorl	%r14d, %r14d
.L38:
	cmpl	12(%rsp), %r14d
	jnb	.L67
	call	rand@PLT
	movl	%eax, %edx
	movl	12(%rsp), %eax
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC6(%rip), %xmm0
	imull	%ebx, %eax
	addl	%r14d, %eax
	incl	%r14d
	addss	%xmm0, %xmm0
	subss	.LC7(%rip), %xmm0
	movl	%eax, %eax
	movss	%xmm0, (%r12,%rax,4)
	jmp	.L38
.L67:
	incl	%ebx
	jmp	.L36
.L66:
	xorl	%ebx, %ebx
.L39:
	cmpl	12(%rsp), %ebx
	jnb	.L68
	call	rand@PLT
	movl	%eax, %edx
	movl	%ebx, %eax
	incl	%ebx
	cvtsi2ssl	%edx, %xmm0
	mulss	.LC6(%rip), %xmm0
	addss	%xmm0, %xmm0
	subss	.LC7(%rip), %xmm0
	movss	%xmm0, 0(%rbp,%rax,4)
	jmp	.L39
.L68:
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L41
.L64:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
.L63:
	call	exit@PLT
.L41:
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L64
	movq	0(%r13), %rdx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	8(%rsp), %edi
	salq	$2, %rdi
	call	malloc@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %rbx
	call	cudaEventRecord@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movl	12(%rsp), %esi
	movl	8(%rsp), %edi
	movq	%rbx, %r8
	movq	%rbp, %rcx
	movq	%r12, %rdx
	call	_Z13matrix_vectorjjPfS_S_
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	16(%rsp), %rdi
	movl	$0x00000000, 16(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movq	0(%r13), %rdx
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	8(%rsp), %edi
	salq	$2, %rdi
	call	malloc@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rax, %r13
	call	cudaEventRecord@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movl	12(%rsp), %esi
	movl	8(%rsp), %edi
	movq	%r13, %r8
	movq	%rbp, %rcx
	movq	%r12, %rdx
	call	_Z16cu_matrix_vectorjjPfS_S_
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L65
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	20(%rsp), %rdi
	movl	$0x00000000, 20(%rsp)
	call	cudaEventElapsedTime@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L50
.L65:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	%r14d, %edi
	jmp	.L63
.L50:
	movss	(%rbx), %xmm1
	movss	.LC10(%rip), %xmm3
	movl	8(%rsp), %edx
	xorl	%eax, %eax
	andps	%xmm3, %xmm1
.L51:
	leal	1(%rax), %ecx
	cmpl	%edx, %ecx
	jnb	.L69
	movss	4(%rbx,%rax,4), %xmm0
	incq	%rax
	maxss	%xmm1, %xmm0
	movaps	%xmm0, %xmm1
	jmp	.L51
.L69:
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L54:
	cmpl	%edx, %eax
	jnb	.L70
	movss	0(%r13,%rax,4), %xmm2
	subss	(%rbx,%rax,4), %xmm2
	incq	%rax
	andps	%xmm3, %xmm2
	addss	%xmm2, %xmm0
	jmp	.L54
.L70:
	divss	%xmm1, %xmm0
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	8(%rsp), %eax
	movss	16(%rsp), %xmm2
	movss	.LC13(%rip), %xmm3
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	cvtsi2sdq	%rax, %xmm0
	movl	12(%rsp), %eax
	cvtsi2sdq	%rax, %xmm1
	movb	$1, %al
	addsd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm0
	movaps	%xmm2, %xmm1
	divss	%xmm3, %xmm1
	mulsd	.LC12(%rip), %xmm0
	movaps	%xmm0, %xmm4
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm1, %xmm4
	movss	20(%rsp), %xmm1
	divss	%xmm3, %xmm1
	movq	%xmm4, %r14
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	movq	%xmm0, %r15
	cvtss2sd	%xmm2, %xmm0
	call	__printf_chk@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	20(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	%r14, %xmm0
	movb	$1, %al
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r15, %xmm0
	leaq	.LC17(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L60
	call	__stack_chk_fail@PLT
.L60:
	addq	$56, %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
.LFE2029:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z14compute_kerneljjPfS_S_"
	.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	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14compute_kerneljjPfS_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
.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	1023410176
	.align 4
.LC6:
	.long	805306368
	.align 4
.LC7:
	.long	1065353216
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC10:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC12:
	.long	-536870912
	.long	1041313291
	.section	.rodata.cst4
	.align 4
.LC13:
	.long	1148846080
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


/*************************************
 * Matrix-Vector product CUDA kernel *
 * V2: With Shared memory            *
 *************************************/


#include <hip/hip_runtime.h>
#include <stdio.h>

#define CUDA_SAFE_CALL( call ) {                                         \
 hipError_t err = call;                                                 \
 if( hipSuccess != err ) {                                              \
   fprintf(stderr,"CUDA: error occurred in cuda routine. Exiting...\n"); \
   exit(err);                                                            \
 } }

#define	A(i,j)		A[ (j) + ((i)*(n)) ]
#define	x(i) 		x[ (i) ]
#define	y(i) 		y[ (i) ]
#define	y_gpu(i) 	y_gpu[ (i) ]
#define	y_cpu(i) 	y_cpu[ (i) ]
#define	d_A(i,j) 	d_A[ (j) + ((i)*(n)) ]
#define	d_x(i) 		d_x[ (i) ]
#define	d_y(i) 		d_y[ (i) ]

#define min(i,j)	( (i)<(j) ? (i) : (j) )

#define	BLOCKSIZE	32

__global__ void compute_kernel( unsigned int m, unsigned int n, float *d_A, float *d_x, float *d_y ) {
  
  /* Obtain (x,y) coordinates of the thread within the block */

  /* Obtain the global index to a matrix row (variable i). Note that there is only one dimension in the grid
     so blockIdx.x and blockDim.x are the only existing variables */
  unsigned int i;
  unsigned int j;
  i = blockIdx.x * BLOCKSIZE;
  j = blockIdx.y * BLOCKSIZE;

  __syncthreads();


  /* Declare share memory space of a piece of array d_x of size BLOCKSIZE */
  __shared__ float b[BLOCKSIZE];
  /* Declare share memory space of a square block of order BLOCKSIZE */
  __shared__ float a[BLOCKSIZE*BLOCKSIZE];
  
  __syncthreads();


  if( i < m ) { /* Prevent work on positions beyond m */
 
    b[threadIdx.x] = d_x[i + threadIdx.x];
    __syncthreads();

     /* Implement Part 1 here */
     /* Loop (threadIdx.x:BLOCKSIZE:n-1) */
        /* Copy subvector x in shared memory */
        /* Perform the add+product on a local variable */
      float sum = 0.0f;
      for(int k=threadIdx.x;k<n-1;k+=BLOCKSIZE){
        sum += d_A(j,k)*b[k];
      }

     /* Save local variable in shared memory */
     a[i+BLOCKSIZE*j] = sum;

     /* Implement Part 2 here */
     /* Only if threadIdx.x==0 */
     if(threadIdx.x==0){
       for(int l = 0;l<BLOCKSIZE;l++){
         d_y(i)+=a[i + BLOCKSIZE*l];
       }
     }

       /* Add all column elements along a row of the shared memory square block */
       /* Save result in d_y */

  }
}

int cu_matrix_vector( unsigned int m, unsigned int n, float *h_A, float *h_x, float *h_y ) {

  // Allocate device memory
  float *d_A, *d_x, *d_y;
  CUDA_SAFE_CALL( hipMalloc((void **) &d_A, m*n*sizeof(float) ) );
  CUDA_SAFE_CALL( hipMalloc((void **) &d_x,   n*sizeof(float) ) );
  CUDA_SAFE_CALL( hipMalloc((void **) &d_y, m  *sizeof(float) ) );

  // Copy host memory to device 
  CUDA_SAFE_CALL( hipMemcpy( d_A, h_A, m*n*sizeof(float), hipMemcpyHostToDevice ) );
  CUDA_SAFE_CALL( hipMemcpy( d_x, h_x,   n*sizeof(float), hipMemcpyHostToDevice ) );

  int n_blocks = (int) ceil( (float) m / (float) BLOCKSIZE );

  // Execute the kernel
  dim3 dimGrid( n_blocks );
  dim3 dimBlock( BLOCKSIZE, BLOCKSIZE );
  compute_kernel<<< dimGrid, dimBlock >>>( m, n, d_A, d_x, d_y );

  // Copy device memory to host 
  CUDA_SAFE_CALL( hipMemcpy( h_y, d_y, m  *sizeof(float), hipMemcpyDeviceToHost ) );

  // Deallocate device memory
  CUDA_SAFE_CALL( hipFree(d_A) );
  CUDA_SAFE_CALL( hipFree(d_x) );
  CUDA_SAFE_CALL( hipFree(d_y) );

  return EXIT_SUCCESS;
}
 
int matrix_vector( unsigned int m, unsigned int n, float *A, float *x, float *y ) {

  unsigned int i, j;
  for( i=0; i<m; i++ ) {
    y( i ) = 0.0f;
    for( j=0; j<n; j++ ) {
      y( i ) += A( i, j ) * x( j );
    }
  }
  return EXIT_SUCCESS;

}

int main( int argc, char *argv[] ) {
  unsigned int m, n;
  unsigned int i, j;

  /* Generating input data */
  if( argc<3 ) {
    printf("Usage: %s n_rows n_cols \n",argv[0]);
    exit(-1);
  }
  sscanf(argv[1],"%d",&m);
  sscanf(argv[2],"%d",&n);
  float *A = (float *) malloc( m*n*sizeof(float) );
  float *x = (float *) malloc(   n*sizeof(float) );
  printf("%s: Generating a random matrix of size %dx%d and a vector of size %d...\n",argv[0],m,n,n);
  for( i=0; i<m; i++ ) {
    for( j=0; j<n; j++ ) {
      A( i, j ) = 2.0f * ( (float) rand() / RAND_MAX ) - 1.0f;
    }
  }
  for( j=0; j<n; j++ ) {
    x( j ) = 2.0f * ( (float) rand() / RAND_MAX ) - 1.0f;
  }


  // Allocate CUDA events that we'll use for timing
  hipEvent_t start, stop;
  CUDA_SAFE_CALL( hipEventCreate(&start) );
  CUDA_SAFE_CALL( hipEventCreate(&stop) );

  printf("%s: y=A*x in CPU...\n",argv[0]);
  float *y_cpu = (float *) malloc( m*sizeof(float) );
  CUDA_SAFE_CALL( hipEventRecord(start, NULL) ); // Record the start event
  matrix_vector( m, n, A, x, y_cpu );
  CUDA_SAFE_CALL( hipEventRecord(stop, NULL) );  // Record the stop event
  CUDA_SAFE_CALL( hipEventSynchronize(stop) );   // Wait for the stop event to complete
  float msecCPU = 0.0f;
  CUDA_SAFE_CALL( hipEventElapsedTime(&msecCPU, start, stop) );

  printf("%s: y=A*x in GPU...\n",argv[0]);
  float *y_gpu = (float *) malloc( m*sizeof(float) );
  CUDA_SAFE_CALL( hipEventRecord(start, NULL) ); // Record the start event
  cu_matrix_vector( m, n, A, x, y_gpu );
  CUDA_SAFE_CALL( hipEventRecord(stop, NULL) );  // Record the stop event
  CUDA_SAFE_CALL( hipEventSynchronize(stop) );   // Wait for the stop event to complete
  float msecGPU = 0.0f;
  CUDA_SAFE_CALL( hipEventElapsedTime(&msecGPU, start, stop) );

  /* Check for correctness */
  float max = fabs( y_cpu( 0 ) );
  for( i=1; i<m; i++ ) {
    max = fabs( y_cpu( i ) > max ? y_cpu( i ) : max );
  }
  float error = 0.0f;
  for( i=0; i<m; i++ ) {
    error += fabs( y_gpu( i ) - y_cpu( i ) );
  }
  printf("Error CPU/GPU = %.3e\n",error/max);
  double flops = 2.0 * (double) m * (double) n;
  double gigaFlopsCPU = (flops * 1.0e-9f) / (msecCPU / 1000.0f);
  double gigaFlopsGPU = (flops * 1.0e-9f) / (msecGPU / 1000.0f);
  printf("CPU time = %.2f msec.\n",msecCPU);
  printf("GPU time = %.2f msec.\n",msecGPU);
  printf("Gflops CPU = %.2f \n",gigaFlopsCPU);
  printf("Gflops GPU = %.2f \n",gigaFlopsGPU);
  
  free(A);
  free(x);
  free(y_cpu);
  free(y_gpu);
  
}


	.text
	.file	"MatrixVectorProduct_v2.hip"
	.globl	_Z29__device_stub__compute_kerneljjPfS_S_ # -- Begin function _Z29__device_stub__compute_kerneljjPfS_S_
	.type	_Z29__device_stub__compute_kerneljjPfS_S_,@function
_Z29__device_stub__compute_kerneljjPfS_S_: # @_Z29__device_stub__compute_kerneljjPfS_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	$_Z14compute_kerneljjPfS_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	_Z29__device_stub__compute_kerneljjPfS_S_, .Lfunc_end0-_Z29__device_stub__compute_kerneljjPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z16cu_matrix_vectorjjPfS_S_
.LCPI1_0:
	.long	0x3d000000                      # float 0.03125
	.text
	.globl	_Z16cu_matrix_vectorjjPfS_S_
	.type	_Z16cu_matrix_vectorjjPfS_S_,@function
_Z16cu_matrix_vectorjjPfS_S_:           # @_Z16cu_matrix_vectorjjPfS_S_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	%r8, %r14
	movq	%rcx, 48(%rsp)                  # 8-byte Spill
	movq	%rdx, %r13
	movl	%esi, %ebp
	movl	%esi, %ebx
	movl	%edi, 4(%rsp)                   # 4-byte Spill
	imull	%edi, %ebx
	shlq	$2, %rbx
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.1:
	movq	%r14, 40(%rsp)                  # 8-byte Spill
	movl	%ebp, 36(%rsp)                  # 4-byte Spill
	movl	%ebp, %r12d
	shlq	$2, %r12
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.2:
	movl	4(%rsp), %r14d                  # 4-byte Reload
	leaq	(,%r14,4), %r15
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_13
# %bb.3:
	movq	24(%rsp), %rdi
	movq	%r13, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.4:
	movq	16(%rsp), %rdi
	movq	48(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.5:
	cvtsi2ss	%r14, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	btsq	$32, %rdi
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	movl	36(%rsp), %esi                  # 4-byte Reload
	jne	.LBB1_7
# %bb.6:
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rcx
	movq	8(%rsp), %r8
	movl	4(%rsp), %edi                   # 4-byte Reload
	callq	_Z29__device_stub__compute_kerneljjPfS_S_
.LBB1_7:
	movq	8(%rsp), %rsi
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.8:
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.9:
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.10:
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.11:
	xorl	%eax, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_14:
	.cfi_def_cfa_offset 112
	movl	%eax, %ebx
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$49, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	%ebx, %edi
	callq	exit
.LBB1_12:
	movl	%eax, %r15d
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$49, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	%r15d, %edi
	callq	exit
.LBB1_13:
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$49, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	%ebp, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z16cu_matrix_vectorjjPfS_S_, .Lfunc_end1-_Z16cu_matrix_vectorjjPfS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z13matrix_vectorjjPfS_S_       # -- Begin function _Z13matrix_vectorjjPfS_S_
	.type	_Z13matrix_vectorjjPfS_S_,@function
_Z13matrix_vectorjjPfS_S_:              # @_Z13matrix_vectorjjPfS_S_
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	je	.LBB2_7
# %bb.1:                                # %.lr.ph20
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	%edi, %eax
	movl	%esi, %edi
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.LBB2_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	movl	$0, (%r8,%r10,4)
	testl	%esi, %esi
	je	.LBB2_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	xorps	%xmm0, %xmm0
	xorl	%r11d, %r11d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%r9,%r11), %ebx
	movss	(%rdx,%rbx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rcx,%r11,4), %xmm1
	addss	%xmm1, %xmm0
	movss	%xmm0, (%r8,%r10,4)
	incq	%r11
	cmpq	%r11, %rdi
	jne	.LBB2_4
.LBB2_5:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r10
	addq	%rdi, %r9
	cmpq	%rax, %r10
	jne	.LBB2_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
.LBB2_7:                                # %._crit_edge21
	xorl	%eax, %eax
	retq
.Lfunc_end2:
	.size	_Z13matrix_vectorjjPfS_S_, .Lfunc_end2-_Z13matrix_vectorjjPfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI3_1:
	.long	0xbf800000                      # float -1
.LCPI3_4:
	.long	0x447a0000                      # float 1000
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI3_2:
	.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_3:
	.quad	0x3e112e0be0000000              # double 9.9999997171806853E-10
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	%rsi, %r13
	cmpl	$2, %edi
	jle	.LBB3_39
# %bb.1:
	movq	8(%r13), %rdi
	xorl	%r15d, %r15d
	movq	%rsp, %rdx
	movl	$.L.str.2, %esi
	movq	%rdx, %r12
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movq	16(%r13), %rdi
	leaq	4(%rsp), %r14
	movl	$.L.str.2, %esi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	movl	(%r12), %ebp
	movl	(%r14), %r12d
	movl	%r12d, %edi
	imull	%ebp, %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r12, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%r13, 24(%rsp)                  # 8-byte Spill
	movq	(%r13), %rsi
	movl	$.L.str.3, %edi
	movl	%ebp, %edx
	movl	%r12d, %ecx
	movl	%r12d, %r8d
	xorl	%eax, %eax
	callq	printf
	movq	%rsp, %rax
	movl	(%rax), %ecx
	leaq	4(%rsp), %rax
	movl	(%rax), %eax
	testl	%ecx, %ecx
	je	.LBB3_2
# %bb.8:                                # %.preheader95.preheader
	movl	%eax, %edx
	movq	24(%rsp), %r12                  # 8-byte Reload
.LBB3_9:                                # %.preheader95
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_12 Depth 2
	testl	%edx, %edx
	je	.LBB3_10
# %bb.11:                               # %.lr.ph.preheader
                                        #   in Loop: Header=BB3_9 Depth=1
	xorl	%ebp, %ebp
.LBB3_12:                               # %.lr.ph
                                        #   Parent Loop BB3_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movss	.LCPI3_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	.LCPI3_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm0
	addss	%xmm1, %xmm0
	movl	4(%rsp), %eax
	movl	%r15d, %ecx
	imull	%eax, %ecx
	addl	%ebp, %ecx
	movss	%xmm0, (%rbx,%rcx,4)
	incl	%ebp
	cmpl	%eax, %ebp
	jb	.LBB3_12
# %bb.13:                               # %._crit_edge.loopexit
                                        #   in Loop: Header=BB3_9 Depth=1
	movl	(%rsp), %ecx
	movl	%eax, %edx
	jmp	.LBB3_14
.LBB3_10:                               #   in Loop: Header=BB3_9 Depth=1
	xorl	%edx, %edx
.LBB3_14:                               # %._crit_edge
                                        #   in Loop: Header=BB3_9 Depth=1
	incl	%r15d
	cmpl	%ecx, %r15d
	jb	.LBB3_9
	jmp	.LBB3_3
.LBB3_2:
	movq	24(%rsp), %r12                  # 8-byte Reload
.LBB3_3:                                # %.preheader94
	testl	%eax, %eax
	je	.LBB3_6
# %bb.4:                                # %.lr.ph99.preheader
	xorl	%r15d, %r15d
.LBB3_5:                                # %.lr.ph99
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	addss	%xmm0, %xmm0
	addss	.LCPI3_1(%rip), %xmm0
	movss	%xmm0, (%r14,%r15,4)
	incq	%r15
	movl	4(%rsp), %eax
	cmpq	%rax, %r15
	jb	.LBB3_5
.LBB3_6:                                # %._crit_edge100
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.15:
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.16:
	movq	(%r12), %rsi
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%rsp), %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.17:
	movl	(%rsp), %eax
	testq	%rax, %rax
	je	.LBB3_24
# %bb.18:                               # %.lr.ph20.i
	movl	4(%rsp), %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
.LBB3_19:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_21 Depth 2
	movl	$0, (%r15,%rsi,4)
	testq	%rcx, %rcx
	je	.LBB3_23
# %bb.20:                               # %.lr.ph.i
                                        #   in Loop: Header=BB3_19 Depth=1
	xorps	%xmm0, %xmm0
	xorl	%edi, %edi
.LBB3_21:                               #   Parent Loop BB3_19 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	leal	(%rdx,%rdi), %r8d
	movss	(%rbx,%r8,4), %xmm1             # xmm1 = mem[0],zero,zero,zero
	mulss	(%r14,%rdi,4), %xmm1
	addss	%xmm1, %xmm0
	incq	%rdi
	cmpq	%rdi, %rcx
	jne	.LBB3_21
# %bb.22:                               # %._crit_edge.i.loopexit
                                        #   in Loop: Header=BB3_19 Depth=1
	movss	%xmm0, (%r15,%rsi,4)
.LBB3_23:                               # %._crit_edge.i
                                        #   in Loop: Header=BB3_19 Depth=1
	incq	%rsi
	addq	%rcx, %rdx
	cmpq	%rax, %rsi
	jne	.LBB3_19
.LBB3_24:                               # %_Z13matrix_vectorjjPfS_S_.exit
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.25:
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.26:
	leaq	44(%rsp), %rdi
	movl	$0, (%rdi)
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.27:
	movq	(%r12), %rsi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%rsp), %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.28:
	movl	(%rsp), %edi
	movl	4(%rsp), %esi
	movq	%rbx, %rdx
	movq	%r14, %rcx
	movq	%r12, %r8
	callq	_Z16cu_matrix_vectorjjPfS_S_
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.29:
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.30:
	leaq	20(%rsp), %rdi
	movl	$0, (%rdi)
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB3_7
# %bb.31:
	movss	(%r15), %xmm1                   # xmm1 = mem[0],zero,zero,zero
	andps	.LCPI3_2(%rip), %xmm1
	movl	(%rsp), %eax
	cmpq	$2, %rax
	jb	.LBB3_32
# %bb.37:                               # %.lr.ph105.preheader
	movl	$1, %ecx
	movaps	.LCPI3_2(%rip), %xmm2           # xmm2 = [NaN,NaN,NaN,NaN]
.LBB3_38:                               # %.lr.ph105
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r15,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	maxss	%xmm1, %xmm0
	andps	%xmm2, %xmm0
	incq	%rcx
	movaps	%xmm0, %xmm1
	cmpq	%rcx, %rax
	jne	.LBB3_38
	jmp	.LBB3_33
.LBB3_32:
	movaps	%xmm1, %xmm0
.LBB3_33:                               # %.preheader
	xorps	%xmm1, %xmm1
	testq	%rax, %rax
	je	.LBB3_36
# %bb.34:                               # %.lr.ph109.preheader
	xorl	%ecx, %ecx
	movaps	.LCPI3_2(%rip), %xmm2           # xmm2 = [NaN,NaN,NaN,NaN]
.LBB3_35:                               # %.lr.ph109
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r12,%rcx,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	subss	(%r15,%rcx,4), %xmm3
	andps	%xmm2, %xmm3
	addss	%xmm3, %xmm1
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB3_35
.LBB3_36:                               # %._crit_edge110
	divss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movl	(%rsp), %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movl	4(%rsp), %eax
	xorps	%xmm3, %xmm3
	cvtsi2sd	%rax, %xmm3
	addsd	%xmm0, %xmm0
	mulsd	%xmm0, %xmm3
	mulsd	.LCPI3_3(%rip), %xmm3
	movss	44(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI3_4(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	divss	%xmm2, %xmm1
	cvtss2sd	%xmm1, %xmm1
	movapd	%xmm3, %xmm4
	divsd	%xmm1, %xmm4
	movsd	%xmm4, 48(%rsp)                 # 8-byte Spill
	movss	20(%rsp), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	divss	%xmm2, %xmm1
	cvtss2sd	%xmm1, %xmm1
	divsd	%xmm1, %xmm3
	movsd	%xmm3, 24(%rsp)                 # 8-byte Spill
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	20(%rsp), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.9, %edi
	movsd	48(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.L.str.10, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_7:
	.cfi_def_cfa_offset 112
	movl	%eax, %ebp
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$49, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	%ebp, %edi
	callq	exit
.LBB3_39:
	movq	(%r13), %rsi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	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	$_Z14compute_kerneljjPfS_S_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z14compute_kerneljjPfS_S_,@object # @_Z14compute_kerneljjPfS_S_
	.section	.rodata,"a",@progbits
	.globl	_Z14compute_kerneljjPfS_S_
	.p2align	3, 0x0
_Z14compute_kerneljjPfS_S_:
	.quad	_Z29__device_stub__compute_kerneljjPfS_S_
	.size	_Z14compute_kerneljjPfS_S_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA: error occurred in cuda routine. Exiting...\n"
	.size	.L.str, 50

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Usage: %s n_rows n_cols \n"
	.size	.L.str.1, 26

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%d"
	.size	.L.str.2, 3

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"%s: Generating a random matrix of size %dx%d and a vector of size %d...\n"
	.size	.L.str.3, 73

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%s: y=A*x in CPU...\n"
	.size	.L.str.4, 21

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%s: y=A*x in GPU...\n"
	.size	.L.str.5, 21

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Error CPU/GPU = %.3e\n"
	.size	.L.str.6, 22

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"CPU time = %.2f msec.\n"
	.size	.L.str.7, 23

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"GPU time = %.2f msec.\n"
	.size	.L.str.8, 23

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Gflops CPU = %.2f \n"
	.size	.L.str.9, 20

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Gflops GPU = %.2f \n"
	.size	.L.str.10, 20

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14compute_kerneljjPfS_S_"
	.size	.L__unnamed_1, 27

	.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 _Z29__device_stub__compute_kerneljjPfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14compute_kerneljjPfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14compute_kerneljjPfS_S_ ; -- Begin function _Z14compute_kerneljjPfS_S_
	.globl	_Z14compute_kerneljjPfS_S_
	.p2align	8
	.type	_Z14compute_kerneljjPfS_S_,@function
_Z14compute_kerneljjPfS_S_:             ; @_Z14compute_kerneljjPfS_S_
; %bb.0:
	s_load_b64 s[8:9], s[0:1], 0x0
	s_lshl_b32 s2, s14, 5
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_barrier
	buffer_gl0_inv
	s_cmp_ge_u32 s2, s8
	s_cbranch_scc1 .LBB0_9
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x8
	v_dual_mov_b32 v2, 0 :: v_dual_add_nc_u32 v1, s2, v0
	s_load_b64 s[0:1], s[0:1], 0x18
	s_add_i32 s3, s9, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	s_mov_b32 s6, exec_lo
	global_load_b32 v1, v[3:4], off
	v_lshlrev_b32_e32 v3, 2, v0
	s_waitcnt vmcnt(0)
	ds_store_b32 v3, v1 offset:4096
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s3, v0
	s_cbranch_execz .LBB0_5
; %bb.2:                                ; %.lr.ph
	v_lshl_or_b32 v1, v0, 2, 0x1000
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v5, v0
	v_mov_b32_e32 v2, 0
	s_mul_i32 s7, s15, s9
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b32 s8, s7, 5
	s_mov_b32 s7, 0
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v3, s8, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 2, v[3:4]
	v_add_co_u32 v6, vcc_lo, s4, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v7, vcc_lo
	global_load_b32 v3, v[6:7], off
	ds_load_b32 v6, v1
	v_add_nc_u32_e32 v5, 32, v5
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_dual_fmac_f32 v2, v3, v6 :: v_dual_add_nc_u32 v1, 0x80, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_u32_e32 vcc_lo, s3, v5
	s_or_b32 s7, vcc_lo, s7
	s_and_not1_b32 exec_lo, exec_lo, s7
	s_cbranch_execnz .LBB0_3
; %bb.4:                                ; %Flow54
	s_or_b32 exec_lo, exec_lo, s7
.LBB0_5:                                ; %Flow55
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s6
	s_lshl_b32 s3, s15, 10
	s_mov_b32 s4, exec_lo
	s_add_i32 s3, s2, s3
	s_lshl_b32 s3, s3, 2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mov_b32_e32 v1, s3
	s_mov_b32 s3, 0
	ds_store_b32 v1, v2
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_9
; %bb.6:                                ; %.preheader
	s_lshl_b64 s[4:5], s[2:3], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s0, s4
	s_addc_u32 s1, s1, s5
	s_load_b32 s2, s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_mov_b32_e32 v0, s2
	s_lshl_b32 s2, s14, 7
.LBB0_7:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_i32 s4, s2, s3
	s_addk_i32 s3, 0x80
	v_mov_b32_e32 v1, s4
	s_cmpk_lg_i32 s3, 0x1000
	ds_load_b32 v1, v1
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v0, v1, v0
	s_cbranch_scc1 .LBB0_7
; %bb.8:                                ; %.loopexit
	v_mov_b32_e32 v1, 0
	global_store_b32 v1, v0, s[0:1]
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14compute_kerneljjPfS_S_
		.amdhsa_group_segment_fixed_size 4224
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 32
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 8
		.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	_Z14compute_kerneljjPfS_S_, .Lfunc_end0-_Z14compute_kerneljjPfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 448
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4224 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .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
    .group_segment_fixed_size: 4224
    .kernarg_segment_align: 8
    .kernarg_segment_size: 32
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14compute_kerneljjPfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14compute_kerneljjPfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
