/* matrixadd.cu
 * 
 *
 * Jonathan Lehman
 * February 12, 2012
 *
 * Homework Assignment 3
 *
 * This program uses a CUDA capable GPU to add two randomly generated matrices in parallel.  The matrix dimensions
 * are specified by the user as an argument, as are the grid and block dimensions to be used on the GPU.
 * This program outputs the time it takes to do the matrix addition (not including the time it takes to transfer data
 * from the host to the device or back.  It also checks arguments to ensure that it will give correct error messages for 
 * any invalid input or data sizes that the GPU cannot handle.
 * 
 */

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

__global__
void add( float*, float*, float*, int, int );
void buildArrays( void );
void checkArgs(int, char**);
void checkGPUCapabilities(int, int, int, int, int);
double getTime();

//user input
int GRID_WIDTH;
int GRID_HEIGHT;
int BLOCK_WIDTH;
int BLOCK_HEIGHT;
int MATRIX_HEIGHT;
int MATRIX_WIDTH;

int NUM_VALUES;

// Keep track of the time.
double startTime, stopTime;


//arrays
float* a;
float* b;
float* c;

int main( int argc, char *argv[] ){
  	
	float *dev_a, *dev_b, *dev_c;
	
	//check validity of arguments
	checkArgs(argc, argv);
  
	//assign variables
	GRID_WIDTH = atoi(argv[1]);
	GRID_HEIGHT = atoi(argv[2]);
	BLOCK_WIDTH = atoi(argv[3]);
	BLOCK_HEIGHT = atoi(argv[4]);
	MATRIX_HEIGHT = atoi(argv[5]);
	MATRIX_WIDTH = atoi(argv[6]);
	
	NUM_VALUES = MATRIX_WIDTH * MATRIX_HEIGHT;
	
	//check that GPU can handle arguments
	checkGPUCapabilities(GRID_WIDTH, GRID_HEIGHT, BLOCK_WIDTH, BLOCK_HEIGHT, NUM_VALUES);
  
	/* Initialize the source arrays here. */
  	a = new float[NUM_VALUES];
  	b = new float[NUM_VALUES];
  	c = new float[NUM_VALUES];
  
  	//fill array a and b with random doubles
  	buildArrays();
  	
  	//TEST print array values
  	/*printf( "The a array:\n" );
  	for( int i = 0; i < NUM_VALUES; i++ ) 
  		printf( "%f\n", a[i] );
    	printf( "\n" );
    	
    	printf( "The b array:\n" );
  	for( int i = 0; i < NUM_VALUES; i++ ) 
  		printf( "%f\n", b[i] );
    	printf( "\n" );*/
    	
    	//check if there will be enough blocks to handle matrix size (if not some threads will take on more than one addition)
    	int reps = ceil((double)(MATRIX_WIDTH * MATRIX_HEIGHT) / (BLOCK_WIDTH * BLOCK_HEIGHT));
   
  	
  	/* Allocate global device memory. */
  	cudaMalloc( (void **)&dev_a, sizeof(float) * NUM_VALUES );
  	cudaMalloc( (void **)&dev_b, sizeof(float) * NUM_VALUES );
  	cudaMalloc( (void **)&dev_c, sizeof(float) * NUM_VALUES );
  
  	/* Copy the host values to global device memory. */
  	cudaMemcpy( dev_a, a, sizeof(float) * NUM_VALUES, cudaMemcpyHostToDevice );
  	cudaMemcpy( dev_b, b, sizeof(float) * NUM_VALUES, cudaMemcpyHostToDevice);
  	
  	/* Start the timer. */
  	startTime = getTime();
  
  	/* Execute the kernel. */
  	dim3 grid(GRID_WIDTH, GRID_HEIGHT); //blocks w x h
  	dim3 block(BLOCK_WIDTH, BLOCK_HEIGHT); //threads w x h
  	add<<<grid, block>>>(dev_a, dev_b, dev_c, NUM_VALUES, reps);

  	/* Wait for the kernel to complete. Needed for timing. */  
  	cudaThreadSynchronize();
  	
  	/* Stop the timer and print the resulting time. */
	  stopTime = getTime();
	  double totalTime = stopTime - startTime;
	  printf( "Time: %f secs\n", totalTime );
  
  	/* Get result from device. */
  	cudaMemcpy(c, dev_c, sizeof(float) * NUM_VALUES, cudaMemcpyDeviceToHost);
  	
  	/*printf( "The c array:\n" );
  	for( int i = 0; i < NUM_VALUES; i++ ) 
  		printf( "%f\n", c[i] );
    	printf( "\n" );*/
  
    	
  	/* Free the allocated device memory. */
  	cudaFree(dev_a);
  	cudaFree(dev_b);
  	cudaFree(dev_c);
  
  	//free allocated host memory
	free(a);
	free(b);
	free(c);
}

__global__
void add( float *a, float *b, float *c, int size , int reps)
{
	//grid dimensions (# blocks)
	int gridW = gridDim.x;   
	int gridH = gridDim.y;
	
	//block dimensions (# threads)
	int blockW = blockDim.x;
        int blockH = blockDim.y;
	
        //block id
	int blockX = blockIdx.x;
	int blockY = blockIdx.y;  
	
	//thread id
	int threadX = threadIdx.x;
	int threadY = threadIdx.y;
       
        
        //loop through number of times matrix elements fill more than an entire grid
	for(int i = 0; i < reps; i++){
		int colNum = threadX + blockW * blockX; 
		int rowNum = threadY + blockH * blockY;
	
		int index = rowNum * blockW + colNum + (gridW * gridH * blockW * blockH * i);
	
		//check that element index is within the arrays being added
		if(index < size){
		  c[index] = a[index]+b[index];
		}
        }        
}

void buildArrays( void ){
	/* Seed the random number generator. */
	srand( 200 );

	for(int i = 0; i < NUM_VALUES; i++){
		float val = rand() / (float(RAND_MAX));
		a[i] = val;
	}
  
	srand( 300 );
  
	for(int i = 0; i < NUM_VALUES; i++){ 
  		float val = rand() / (float(RAND_MAX));
  		b[i] = val;
  	}


}

void checkArgs(int argc, char *argv[]){
	
	//check number of arguments
	if(argc != 7){
		fprintf(stderr, "\nmatrixadd: Incorrect number of arguments. matrixadd requires 6 arguments not %d\nCorrect usage: \"matrixadd grid-width grid-height blck-width blck-height mat-height mat-width\"\n", argc - 1);
		exit(1);
	}
	
	
	char* invalChar;
	long arg;
	
	//check each argument
	for(int i = 1; i < 7; i++){
		//check for overflow of argument
		if((arg = strtol(argv[i], &invalChar, 10)) >= INT_MAX){
			fprintf(stderr, "\nmatrixadd: Overflow. Invalid argument %d for matrixadd, '%s'.\nThe argument must be a valid, positive, non-zero integer less than %d.\n", i, argv[i], INT_MAX);
			exit(1);
		}
	
		//check that argument is a valid positive integer and check underflow
		if(!(arg > 0) || (*invalChar)){
			fprintf(stderr, "\nmatrixadd: Invalid argument %d for matrixadd, '%s'.  The argument must be a valid, positive, non-zero integer.\n", i, argv[i]);
			exit(1);
		}
		
	}	
}

void checkGPUCapabilities(int gridW, int gridH, int blockW, int blockH, int size){
	//check what GPU is being used
	int devId;  
	cudaGetDevice( &devId );
	
	//get device properties for GPU being used
	cudaDeviceProp gpuProp;
	cudaGetDeviceProperties( &gpuProp, devId );
	
	//check if GPU has enough memory to handle the 3 arrays
	if(gpuProp.totalGlobalMem < (size * sizeof(float)) * 3){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU does not have enough memory to handle the data size: %ld. It can only handle data sizes up to %ld.\n", (size * sizeof(float)) * 3, gpuProp.totalGlobalMem);
		exit(1);
	}
	
	//check if GPU can handle the number of threads per bloc
	if(gpuProp.maxThreadsPerBlock < (blockW * blockH)){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d threads per block, not %d.\n", gpuProp.maxThreadsPerBlock, (blockW * blockH));
		exit(1);
	}
	
	//check that GPU can handle the number of threads in the block width
	if(gpuProp.maxThreadsDim[0] < blockW){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block width of each block, not %d.\n", gpuProp.maxThreadsDim[0], blockW );
		exit(1);
	}
	
	//check that GPU can handle the number of threads in the block height
	if(gpuProp.maxThreadsDim[1] < blockH){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block height of each block, not %d.\n", gpuProp.maxThreadsDim[1], blockH );
		exit(1);
	}
	
	//check that GPU can handle the number of blocks in the grid width
	if(gpuProp.maxGridSize[0] < gridW){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid width of each grid, not %d.\n", gpuProp.maxGridSize[0], gridW );
		exit(1);
	}
	
	//check that GPU can handle the number of blocks in the grid height
	if(gpuProp.maxGridSize[1] < gridH){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid height of each grid, not %d.\n", gpuProp.maxGridSize[1], gridH );
		exit(1);
	}
}

double getTime(){
  timeval thetime;
  gettimeofday( &thetime, 0 );
  return thetime.tv_sec + thetime.tv_usec / 1000000.0;
}

	.file	"tmpxft_003b6ca7_00000000-6_matrixadd.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11buildArraysv
	.type	_Z11buildArraysv, @function
_Z11buildArraysv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	$200, %edi
	xorl	%ebx, %ebx
	call	srand@PLT
.L3:
	cmpl	%ebx, NUM_VALUES(%rip)
	jle	.L9
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movq	a(%rip), %rax
	movss	%xmm0, (%rax,%rbx,4)
	incq	%rbx
	jmp	.L3
.L9:
	movl	$300, %edi
	xorl	%ebx, %ebx
	call	srand@PLT
.L5:
	cmpl	%ebx, NUM_VALUES(%rip)
	jle	.L10
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	movq	b(%rip), %rax
	movss	%xmm0, (%rax,%rbx,4)
	incq	%rbx
	jmp	.L5
.L10:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11buildArraysv, .-_Z11buildArraysv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"\nmatrixadd: Incorrect number of arguments. matrixadd requires 6 arguments not %d\nCorrect usage: \"matrixadd grid-width grid-height blck-width blck-height mat-height mat-width\"\n"
.LC2:
	.string	"\nmatrixadd: Overflow. Invalid argument %d for matrixadd, '%s'.\nThe argument must be a valid, positive, non-zero integer less than %d.\n"
.LC3:
	.string	"\nmatrixadd: Invalid argument %d for matrixadd, '%s'.  The argument must be a valid, positive, non-zero integer.\n"
	.text
	.globl	_Z9checkArgsiPPc
	.type	_Z9checkArgsiPPc, @function
_Z9checkArgsiPPc:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$40, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	cmpl	$7, %edi
	je	.L20
	leal	-1(%rdi), %ecx
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L22
.L20:
	leaq	8(%rsi), %rbx
	movl	$1, %ecx
	leaq	16(%rsp), %rbp
.L16:
	movq	(%rbx), %rdi
	movl	$10, %edx
	movq	%rbp, %rsi
	movl	%ecx, 12(%rsp)
	call	__isoc23_strtol@PLT
	movl	12(%rsp), %ecx
	cmpq	$2147483646, %rax
	jle	.L13
	movq	(%rbx), %r8
	movl	$2147483647, %r9d
	movl	$2, %esi
	xorl	%eax, %eax
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	call	__fprintf_chk@PLT
.L22:
	movl	$1, %edi
	call	exit@PLT
.L13:
	testq	%rax, %rax
	jg	.L14
.L15:
	movq	(%rbx), %r8
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L22
.L14:
	movq	16(%rsp), %rax
	cmpb	$0, (%rax)
	jne	.L15
	incl	%ecx
	addq	$8, %rbx
	cmpl	$7, %ecx
	jne	.L16
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$40, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z9checkArgsiPPc, .-_Z9checkArgsiPPc
	.section	.rodata.str1.1
.LC4:
	.string	"\nmatrixadd: Insufficient GPU. GPU does not have enough memory to handle the data size: %ld. It can only handle data sizes up to %ld.\n"
.LC5:
	.string	"\nmatrixadd: Insufficient GPU. GPU can only handle %d threads per block, not %d.\n"
.LC6:
	.string	"\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block width of each block, not %d.\n"
.LC7:
	.string	"\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block height of each block, not %d.\n"
.LC8:
	.string	"\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid width of each grid, not %d.\n"
.LC9:
	.string	"\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid height of each grid, not %d.\n"
	.text
	.globl	_Z20checkGPUCapabilitiesiiiii
	.type	_Z20checkGPUCapabilitiesiiiii, @function
_Z20checkGPUCapabilitiesiiiii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	%edi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%esi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	%r8d, %ebx
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1104
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDevice@PLT
	movl	12(%rsp), %esi
	leaq	16(%rsp), %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movslq	%ebx, %rcx
	movq	304(%rsp), %r8
	imulq	$12, %rcx, %rcx
	cmpq	%rcx, %r8
	jnb	.L24
	movq	stderr(%rip), %rdi
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L32
.L24:
	movl	%r12d, %r8d
	movl	336(%rsp), %ecx
	imull	%ebp, %r8d
	cmpl	%r8d, %ecx
	jge	.L25
	leaq	.LC5(%rip), %rdx
.L33:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L32:
	movl	$1, %edi
	call	exit@PLT
.L25:
	movl	340(%rsp), %ecx
	movl	%r12d, %r8d
	leaq	.LC6(%rip), %rdx
	cmpl	%r12d, %ecx
	jl	.L33
	movl	344(%rsp), %ecx
	movl	%ebp, %r8d
	leaq	.LC7(%rip), %rdx
	cmpl	%ebp, %ecx
	jl	.L33
	movl	352(%rsp), %ecx
	movl	%r14d, %r8d
	leaq	.LC8(%rip), %rdx
	cmpl	%r14d, %ecx
	jl	.L33
	movl	356(%rsp), %ecx
	movl	%r13d, %r8d
	leaq	.LC9(%rip), %rdx
	cmpl	%r13d, %ecx
	jl	.L33
	movq	1048(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$1056, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z20checkGPUCapabilitiesiiiii, .-_Z20checkGPUCapabilitiesiiiii
	.globl	_Z7getTimev
	.type	_Z7getTimev, @function
_Z7getTimev:
.LFB2031:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cvtsi2sdq	8(%rsp), %xmm1
	cvtsi2sdq	16(%rsp), %xmm0
	divsd	.LC10(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z7getTimev, .-_Z7getTimev
	.globl	_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii
	.type	_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii, @function
_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	4(%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	.L37
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z3addPfS_S_ii(%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
.L37:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii, .-_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii
	.globl	_Z3addPfS_S_ii
	.type	_Z3addPfS_S_ii, @function
_Z3addPfS_S_ii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii
	.cfi_endproc
.LFE2057:
	.size	_Z3addPfS_S_ii, .-_Z3addPfS_S_ii
	.section	.rodata.str1.1
.LC11:
	.string	"Time: %f secs\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z9checkArgsiPPc
	movq	8(%rbx), %rdi
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %r12d
	movl	%eax, GRID_WIDTH(%rip)
	call	atoi@PLT
	movq	24(%rbx), %rdi
	movl	%eax, %r13d
	movl	%eax, GRID_HEIGHT(%rip)
	call	atoi@PLT
	movq	32(%rbx), %rdi
	movl	%eax, %r14d
	movl	%eax, BLOCK_WIDTH(%rip)
	call	atoi@PLT
	movq	40(%rbx), %rdi
	movl	%eax, %r15d
	movl	%eax, BLOCK_HEIGHT(%rip)
	call	atoi@PLT
	movq	48(%rbx), %rdi
	movabsq	$2305843009213693950, %rbx
	movl	%eax, %ebp
	movl	%eax, MATRIX_HEIGHT(%rip)
	call	atoi@PLT
	movl	%ebp, %r8d
	movl	%r12d, %edi
	movl	%r15d, %ecx
	imull	%eax, %r8d
	movl	%r14d, %edx
	movl	%r13d, %esi
	movl	%eax, MATRIX_WIDTH(%rip)
	movl	%r8d, NUM_VALUES(%rip)
	call	_Z20checkGPUCapabilitiesiiiii
	movslq	NUM_VALUES(%rip), %rdi
	cmpq	%rdi, %rbx
	jb	.L43
	salq	$2, %rdi
	call	_Znam@PLT
	movslq	NUM_VALUES(%rip), %rdi
	movq	%rax, a(%rip)
	cmpq	%rdi, %rbx
	jnb	.L44
.L43:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L49
	call	__cxa_throw_bad_array_new_length@PLT
.L44:
	salq	$2, %rdi
	call	_Znam@PLT
	movslq	NUM_VALUES(%rip), %rdi
	movq	%rax, b(%rip)
	cmpq	%rdi, %rbx
	jb	.L43
	salq	$2, %rdi
	call	_Znam@PLT
	movq	%rax, c(%rip)
	call	_Z11buildArraysv
	leaq	8(%rsp), %rdi
	movslq	NUM_VALUES(%rip), %rsi
	movl	MATRIX_WIDTH(%rip), %ebp
	movl	MATRIX_HEIGHT(%rip), %r13d
	movl	BLOCK_WIDTH(%rip), %ebx
	salq	$2, %rsi
	movl	BLOCK_HEIGHT(%rip), %r12d
	call	cudaMalloc@PLT
	movslq	NUM_VALUES(%rip), %rsi
	leaq	16(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	NUM_VALUES(%rip), %rsi
	leaq	24(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movslq	NUM_VALUES(%rip), %rdx
	movq	a(%rip), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movslq	NUM_VALUES(%rip), %rdx
	movq	b(%rip), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	call	_Z7getTimev
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movl	GRID_WIDTH(%rip), %eax
	movl	$1, %esi
	movsd	%xmm0, startTime(%rip)
	movl	%eax, 32(%rsp)
	movl	GRID_HEIGHT(%rip), %eax
	movl	%eax, 36(%rsp)
	movl	BLOCK_WIDTH(%rip), %eax
	movq	32(%rsp), %rdi
	movl	%eax, 44(%rsp)
	movl	BLOCK_HEIGHT(%rip), %eax
	movl	%eax, 48(%rsp)
	movq	44(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	imull	%r13d, %ebp
	imull	%r12d, %ebx
	cvtsi2sdl	%ebp, %xmm0
	cvtsi2sdl	%ebx, %xmm1
	divsd	%xmm1, %xmm0
	call	ceil@PLT
	movl	NUM_VALUES(%rip), %ecx
	movq	24(%rsp), %rdx
	cvttsd2sil	%xmm0, %r8d
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z28__device_stub__Z3addPfS_S_iiPfS_S_ii
.L46:
	call	cudaThreadSynchronize@PLT
	call	_Z7getTimev
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movsd	%xmm0, stopTime(%rip)
	subsd	startTime(%rip), %xmm0
	call	__printf_chk@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movslq	NUM_VALUES(%rip), %rdx
	movq	c(%rip), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	a(%rip), %rdi
	call	free@PLT
	movq	b(%rip), %rdi
	call	free@PLT
	movq	c(%rip), %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L47
.L49:
	call	__stack_chk_fail@PLT
.L47:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z3addPfS_S_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z3addPfS_S_ii(%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
.LFE2059:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	c
	.bss
	.align 8
	.type	c, @object
	.size	c, 8
c:
	.zero	8
	.globl	b
	.align 8
	.type	b, @object
	.size	b, 8
b:
	.zero	8
	.globl	a
	.align 8
	.type	a, @object
	.size	a, 8
a:
	.zero	8
	.globl	stopTime
	.align 8
	.type	stopTime, @object
	.size	stopTime, 8
stopTime:
	.zero	8
	.globl	startTime
	.align 8
	.type	startTime, @object
	.size	startTime, 8
startTime:
	.zero	8
	.globl	NUM_VALUES
	.align 4
	.type	NUM_VALUES, @object
	.size	NUM_VALUES, 4
NUM_VALUES:
	.zero	4
	.globl	MATRIX_WIDTH
	.align 4
	.type	MATRIX_WIDTH, @object
	.size	MATRIX_WIDTH, 4
MATRIX_WIDTH:
	.zero	4
	.globl	MATRIX_HEIGHT
	.align 4
	.type	MATRIX_HEIGHT, @object
	.size	MATRIX_HEIGHT, 4
MATRIX_HEIGHT:
	.zero	4
	.globl	BLOCK_HEIGHT
	.align 4
	.type	BLOCK_HEIGHT, @object
	.size	BLOCK_HEIGHT, 4
BLOCK_HEIGHT:
	.zero	4
	.globl	BLOCK_WIDTH
	.align 4
	.type	BLOCK_WIDTH, @object
	.size	BLOCK_WIDTH, 4
BLOCK_WIDTH:
	.zero	4
	.globl	GRID_HEIGHT
	.align 4
	.type	GRID_HEIGHT, @object
	.size	GRID_HEIGHT, 4
GRID_HEIGHT:
	.zero	4
	.globl	GRID_WIDTH
	.align 4
	.type	GRID_WIDTH, @object
	.size	GRID_WIDTH, 4
GRID_WIDTH:
	.zero	4
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC10:
	.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:

/* matrixadd.cu
 * 
 *
 * Jonathan Lehman
 * February 12, 2012
 *
 * Homework Assignment 3
 *
 * This program uses a CUDA capable GPU to add two randomly generated matrices in parallel.  The matrix dimensions
 * are specified by the user as an argument, as are the grid and block dimensions to be used on the GPU.
 * This program outputs the time it takes to do the matrix addition (not including the time it takes to transfer data
 * from the host to the device or back.  It also checks arguments to ensure that it will give correct error messages for 
 * any invalid input or data sizes that the GPU cannot handle.
 * 
 */

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <math.h>
#include <sys/time.h>

__global__
void add( float*, float*, float*, int, int );
void buildArrays( void );
void checkArgs(int, char**);
void checkGPUCapabilities(int, int, int, int, int);
double getTime();

//user input
int GRID_WIDTH;
int GRID_HEIGHT;
int BLOCK_WIDTH;
int BLOCK_HEIGHT;
int MATRIX_HEIGHT;
int MATRIX_WIDTH;

int NUM_VALUES;

// Keep track of the time.
double startTime, stopTime;


//arrays
float* a;
float* b;
float* c;

int main( int argc, char *argv[] ){
  	
	float *dev_a, *dev_b, *dev_c;
	
	//check validity of arguments
	checkArgs(argc, argv);
  
	//assign variables
	GRID_WIDTH = atoi(argv[1]);
	GRID_HEIGHT = atoi(argv[2]);
	BLOCK_WIDTH = atoi(argv[3]);
	BLOCK_HEIGHT = atoi(argv[4]);
	MATRIX_HEIGHT = atoi(argv[5]);
	MATRIX_WIDTH = atoi(argv[6]);
	
	NUM_VALUES = MATRIX_WIDTH * MATRIX_HEIGHT;
	
	//check that GPU can handle arguments
	checkGPUCapabilities(GRID_WIDTH, GRID_HEIGHT, BLOCK_WIDTH, BLOCK_HEIGHT, NUM_VALUES);
  
	/* Initialize the source arrays here. */
  	a = new float[NUM_VALUES];
  	b = new float[NUM_VALUES];
  	c = new float[NUM_VALUES];
  
  	//fill array a and b with random doubles
  	buildArrays();
  	
  	//TEST print array values
  	/*printf( "The a array:\n" );
  	for( int i = 0; i < NUM_VALUES; i++ ) 
  		printf( "%f\n", a[i] );
    	printf( "\n" );
    	
    	printf( "The b array:\n" );
  	for( int i = 0; i < NUM_VALUES; i++ ) 
  		printf( "%f\n", b[i] );
    	printf( "\n" );*/
    	
    	//check if there will be enough blocks to handle matrix size (if not some threads will take on more than one addition)
    	int reps = ceil((double)(MATRIX_WIDTH * MATRIX_HEIGHT) / (BLOCK_WIDTH * BLOCK_HEIGHT));
   
  	
  	/* Allocate global device memory. */
  	hipMalloc( (void **)&dev_a, sizeof(float) * NUM_VALUES );
  	hipMalloc( (void **)&dev_b, sizeof(float) * NUM_VALUES );
  	hipMalloc( (void **)&dev_c, sizeof(float) * NUM_VALUES );
  
  	/* Copy the host values to global device memory. */
  	hipMemcpy( dev_a, a, sizeof(float) * NUM_VALUES, hipMemcpyHostToDevice );
  	hipMemcpy( dev_b, b, sizeof(float) * NUM_VALUES, hipMemcpyHostToDevice);
  	
  	/* Start the timer. */
  	startTime = getTime();
  
  	/* Execute the kernel. */
  	dim3 grid(GRID_WIDTH, GRID_HEIGHT); //blocks w x h
  	dim3 block(BLOCK_WIDTH, BLOCK_HEIGHT); //threads w x h
  	add<<<grid, block>>>(dev_a, dev_b, dev_c, NUM_VALUES, reps);

  	/* Wait for the kernel to complete. Needed for timing. */  
  	hipDeviceSynchronize();
  	
  	/* Stop the timer and print the resulting time. */
	  stopTime = getTime();
	  double totalTime = stopTime - startTime;
	  printf( "Time: %f secs\n", totalTime );
  
  	/* Get result from device. */
  	hipMemcpy(c, dev_c, sizeof(float) * NUM_VALUES, hipMemcpyDeviceToHost);
  	
  	/*printf( "The c array:\n" );
  	for( int i = 0; i < NUM_VALUES; i++ ) 
  		printf( "%f\n", c[i] );
    	printf( "\n" );*/
  
    	
  	/* Free the allocated device memory. */
  	hipFree(dev_a);
  	hipFree(dev_b);
  	hipFree(dev_c);
  
  	//free allocated host memory
	free(a);
	free(b);
	free(c);
}

__global__
void add( float *a, float *b, float *c, int size , int reps)
{
	//grid dimensions (# blocks)
	int gridW = gridDim.x;   
	int gridH = gridDim.y;
	
	//block dimensions (# threads)
	int blockW = blockDim.x;
        int blockH = blockDim.y;
	
        //block id
	int blockX = blockIdx.x;
	int blockY = blockIdx.y;  
	
	//thread id
	int threadX = threadIdx.x;
	int threadY = threadIdx.y;
       
        
        //loop through number of times matrix elements fill more than an entire grid
	for(int i = 0; i < reps; i++){
		int colNum = threadX + blockW * blockX; 
		int rowNum = threadY + blockH * blockY;
	
		int index = rowNum * blockW + colNum + (gridW * gridH * blockW * blockH * i);
	
		//check that element index is within the arrays being added
		if(index < size){
		  c[index] = a[index]+b[index];
		}
        }        
}

void buildArrays( void ){
	/* Seed the random number generator. */
	srand( 200 );

	for(int i = 0; i < NUM_VALUES; i++){
		float val = rand() / (float(RAND_MAX));
		a[i] = val;
	}
  
	srand( 300 );
  
	for(int i = 0; i < NUM_VALUES; i++){ 
  		float val = rand() / (float(RAND_MAX));
  		b[i] = val;
  	}


}

void checkArgs(int argc, char *argv[]){
	
	//check number of arguments
	if(argc != 7){
		fprintf(stderr, "\nmatrixadd: Incorrect number of arguments. matrixadd requires 6 arguments not %d\nCorrect usage: \"matrixadd grid-width grid-height blck-width blck-height mat-height mat-width\"\n", argc - 1);
		exit(1);
	}
	
	
	char* invalChar;
	long arg;
	
	//check each argument
	for(int i = 1; i < 7; i++){
		//check for overflow of argument
		if((arg = strtol(argv[i], &invalChar, 10)) >= INT_MAX){
			fprintf(stderr, "\nmatrixadd: Overflow. Invalid argument %d for matrixadd, '%s'.\nThe argument must be a valid, positive, non-zero integer less than %d.\n", i, argv[i], INT_MAX);
			exit(1);
		}
	
		//check that argument is a valid positive integer and check underflow
		if(!(arg > 0) || (*invalChar)){
			fprintf(stderr, "\nmatrixadd: Invalid argument %d for matrixadd, '%s'.  The argument must be a valid, positive, non-zero integer.\n", i, argv[i]);
			exit(1);
		}
		
	}	
}

void checkGPUCapabilities(int gridW, int gridH, int blockW, int blockH, int size){
	//check what GPU is being used
	int devId;  
	hipGetDevice( &devId );
	
	//get device properties for GPU being used
	hipDeviceProp_t gpuProp;
	hipGetDeviceProperties( &gpuProp, devId );
	
	//check if GPU has enough memory to handle the 3 arrays
	if(gpuProp.totalGlobalMem < (size * sizeof(float)) * 3){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU does not have enough memory to handle the data size: %ld. It can only handle data sizes up to %ld.\n", (size * sizeof(float)) * 3, gpuProp.totalGlobalMem);
		exit(1);
	}
	
	//check if GPU can handle the number of threads per bloc
	if(gpuProp.maxThreadsPerBlock < (blockW * blockH)){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d threads per block, not %d.\n", gpuProp.maxThreadsPerBlock, (blockW * blockH));
		exit(1);
	}
	
	//check that GPU can handle the number of threads in the block width
	if(gpuProp.maxThreadsDim[0] < blockW){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block width of each block, not %d.\n", gpuProp.maxThreadsDim[0], blockW );
		exit(1);
	}
	
	//check that GPU can handle the number of threads in the block height
	if(gpuProp.maxThreadsDim[1] < blockH){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block height of each block, not %d.\n", gpuProp.maxThreadsDim[1], blockH );
		exit(1);
	}
	
	//check that GPU can handle the number of blocks in the grid width
	if(gpuProp.maxGridSize[0] < gridW){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid width of each grid, not %d.\n", gpuProp.maxGridSize[0], gridW );
		exit(1);
	}
	
	//check that GPU can handle the number of blocks in the grid height
	if(gpuProp.maxGridSize[1] < gridH){
		fprintf(stderr, "\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid height of each grid, not %d.\n", gpuProp.maxGridSize[1], gridH );
		exit(1);
	}
}

double getTime(){
  timeval thetime;
  gettimeofday( &thetime, 0 );
  return thetime.tv_sec + thetime.tv_usec / 1000000.0;
}

	.text
	.file	"matrixadd.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_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
	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	$40, %rsp
	.cfi_def_cfa_offset 96
	.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, %rbx
	callq	_Z9checkArgsiPPc
	movq	8(%rbx), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%eax, GRID_WIDTH(%rip)
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %r14d
	movl	%eax, GRID_HEIGHT(%rip)
	movq	24(%rbx), %rdi
	callq	atoi
	movl	%eax, %r15d
	movl	%eax, BLOCK_WIDTH(%rip)
	movq	32(%rbx), %rdi
	callq	atoi
	movl	%eax, %r12d
	movl	%eax, BLOCK_HEIGHT(%rip)
	movq	40(%rbx), %rdi
	callq	atoi
	movl	%eax, %r13d
	movl	%eax, MATRIX_HEIGHT(%rip)
	movq	48(%rbx), %rdi
	callq	atoi
	movl	%eax, MATRIX_WIDTH(%rip)
	imull	%eax, %r13d
	movl	%r13d, NUM_VALUES(%rip)
	movl	%ebp, %edi
	movl	%r14d, %esi
	movl	%r15d, %edx
	movl	%r12d, %ecx
	movl	%r13d, %r8d
	callq	_Z20checkGPUCapabilitiesiiiii
	movslq	NUM_VALUES(%rip), %rax
	leaq	(,%rax,4), %rcx
	testq	%rax, %rax
	movq	$-1, %rbx
	cmovnsq	%rcx, %rbx
	movq	%rbx, %rdi
	callq	_Znam
	movq	%rax, a(%rip)
	movq	%rbx, %rdi
	callq	_Znam
	movq	%rax, b(%rip)
	movq	%rbx, %rdi
	callq	_Znam
	movq	%rax, c(%rip)
	callq	_Z11buildArraysv
	movl	MATRIX_WIDTH(%rip), %r12d
	movl	MATRIX_HEIGHT(%rip), %r13d
	movl	BLOCK_WIDTH(%rip), %ebp
	movl	BLOCK_HEIGHT(%rip), %r15d
	movslq	NUM_VALUES(%rip), %rsi
	shlq	$2, %rsi
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movslq	NUM_VALUES(%rip), %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	callq	hipMalloc
	movslq	NUM_VALUES(%rip), %rsi
	shlq	$2, %rsi
	movq	%rsp, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	a(%rip), %rsi
	movslq	NUM_VALUES(%rip), %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r14), %rdi
	movq	b(%rip), %rsi
	movslq	NUM_VALUES(%rip), %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cvtsi2sdq	(%rbx), %xmm0
	cvtsi2sdq	8(%rbx), %xmm1
	divsd	.LCPI0_0(%rip), %xmm1
	addsd	%xmm0, %xmm1
	movsd	%xmm1, startTime(%rip)
	movl	GRID_WIDTH(%rip), %eax
	movl	GRID_HEIGHT(%rip), %edi
	shlq	$32, %rdi
	orq	%rax, %rdi
	movl	BLOCK_WIDTH(%rip), %eax
	movl	BLOCK_HEIGHT(%rip), %edx
	shlq	$32, %rdx
	orq	%rax, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_2
# %bb.1:
	imull	%r12d, %r13d
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r13d, %xmm0
	imull	%ebp, %r15d
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r15d, %xmm1
	divsd	%xmm1, %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %r8d
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	movl	NUM_VALUES(%rip), %ecx
	callq	_Z18__device_stub__addPfS_S_ii
.LBB0_2:
	callq	hipDeviceSynchronize
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	xorps	%xmm1, %xmm1
	cvtsi2sdq	(%rbx), %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sdq	8(%rbx), %xmm0
	divsd	.LCPI0_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, stopTime(%rip)
	subsd	startTime(%rip), %xmm0
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	movq	c(%rip), %rdi
	movq	(%rsp), %rsi
	movslq	NUM_VALUES(%rip), %rdx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	a(%rip), %rdi
	callq	free
	movq	b(%rip), %rdi
	callq	free
	movq	c(%rip), %rdi
	callq	free
	xorl	%eax, %eax
	addq	$40, %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
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z9checkArgsiPPc                # -- Begin function _Z9checkArgsiPPc
	.type	_Z9checkArgsiPPc,@function
_Z9checkArgsiPPc:                       # @_Z9checkArgsiPPc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$7, %edi
	jne	.LBB1_9
# %bb.1:
	movq	%rsi, %r14
	movl	$1, %ebx
	leaq	8(%rsp), %r15
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	movq	(%r14,%rbx,8), %rdi
	movq	%r15, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	$2147483647, %rax               # imm = 0x7FFFFFFF
	jge	.LBB1_8
# %bb.3:                                #   in Loop: Header=BB1_2 Depth=1
	testq	%rax, %rax
	jle	.LBB1_7
# %bb.4:                                #   in Loop: Header=BB1_2 Depth=1
	movq	8(%rsp), %rax
	cmpb	$0, (%rax)
	jne	.LBB1_7
# %bb.5:                                #   in Loop: Header=BB1_2 Depth=1
	incq	%rbx
	cmpq	$7, %rbx
	jne	.LBB1_2
# %bb.6:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB1_7:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rdi
	movq	(%r14,%rbx,8), %rcx
	movl	$.L.str.3, %esi
	movl	%ebx, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_10
.LBB1_8:
	movq	stderr(%rip), %rdi
	movq	(%r14,%rbx,8), %rcx
	movl	$.L.str.2, %esi
	movl	%ebx, %edx
	movl	$2147483647, %r8d               # imm = 0x7FFFFFFF
	xorl	%eax, %eax
	callq	fprintf
.LBB1_10:
	movl	$1, %edi
	callq	exit
.LBB1_9:
	movl	%edi, %edx
	movq	stderr(%rip), %rdi
	decl	%edx
	movl	$.L.str.1, %esi
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_10
.Lfunc_end1:
	.size	_Z9checkArgsiPPc, .Lfunc_end1-_Z9checkArgsiPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z20checkGPUCapabilitiesiiiii   # -- Begin function _Z20checkGPUCapabilitiesiiiii
	.type	_Z20checkGPUCapabilitiesiiiii,@function
_Z20checkGPUCapabilitiesiiiii:          # @_Z20checkGPUCapabilitiesiiiii
	.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	$1480, %rsp                     # imm = 0x5C8
	.cfi_def_cfa_offset 1536
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, %r12d
	movl	%ecx, %r14d
	movl	%edx, %r15d
	movl	%esi, %ebx
	movl	%edi, %ebp
	leaq	4(%rsp), %r13
	movq	%r13, %rdi
	callq	hipGetDevice
	movl	(%r13), %esi
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipGetDevicePropertiesR0600
	movq	288(%r13), %rcx
	movslq	%r12d, %rax
	shlq	$2, %rax
	leaq	(%rax,%rax,2), %rdx
	cmpq	%rdx, %rcx
	jb	.LBB2_7
# %bb.1:
	movl	328(%rsp), %edx
	movl	%r14d, %ecx
	imull	%r15d, %ecx
	cmpl	%ecx, %edx
	jl	.LBB2_8
# %bb.2:
	movl	332(%rsp), %edx
	cmpl	%r15d, %edx
	jl	.LBB2_9
# %bb.3:
	movl	336(%rsp), %edx
	cmpl	%r14d, %edx
	jl	.LBB2_10
# %bb.4:
	movl	344(%rsp), %edx
	cmpl	%ebp, %edx
	jl	.LBB2_11
# %bb.5:
	movl	348(%rsp), %edx
	cmpl	%ebx, %edx
	jl	.LBB2_12
# %bb.6:
	addq	$1480, %rsp                     # imm = 0x5C8
	.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
.LBB2_7:
	.cfi_def_cfa_offset 1536
	movq	stderr(%rip), %rdi
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB2_14
.LBB2_8:
	movq	stderr(%rip), %rdi
	movl	$.L.str.5, %esi
	jmp	.LBB2_13
.LBB2_9:
	movq	stderr(%rip), %rdi
	movl	$.L.str.6, %esi
	movl	%r15d, %ecx
	jmp	.LBB2_13
.LBB2_10:
	movq	stderr(%rip), %rdi
	movl	$.L.str.7, %esi
	movl	%r14d, %ecx
	jmp	.LBB2_13
.LBB2_11:
	movq	stderr(%rip), %rdi
	movl	$.L.str.8, %esi
	movl	%ebp, %ecx
	jmp	.LBB2_13
.LBB2_12:
	movq	stderr(%rip), %rdi
	movl	$.L.str.9, %esi
	movl	%ebx, %ecx
.LBB2_13:
	xorl	%eax, %eax
	callq	fprintf
.LBB2_14:
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z20checkGPUCapabilitiesiiiii, .Lfunc_end2-_Z20checkGPUCapabilitiesiiiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z11buildArraysv
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z11buildArraysv
	.type	_Z11buildArraysv,@function
_Z11buildArraysv:                       # @_Z11buildArraysv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$200, %edi
	callq	srand
	cmpl	$0, NUM_VALUES(%rip)
	jle	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movq	a(%rip), %rax
	movss	%xmm0, (%rax,%rbx,4)
	incq	%rbx
	movslq	NUM_VALUES(%rip), %rax
	cmpq	%rax, %rbx
	jl	.LBB3_2
.LBB3_3:                                # %._crit_edge
	movl	$300, %edi                      # imm = 0x12C
	callq	srand
	cmpl	$0, NUM_VALUES(%rip)
	jle	.LBB3_6
# %bb.4:                                # %.lr.ph11.preheader
	xorl	%ebx, %ebx
.LBB3_5:                                # %.lr.ph11
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	movq	b(%rip), %rax
	movss	%xmm0, (%rax,%rbx,4)
	incq	%rbx
	movslq	NUM_VALUES(%rip), %rax
	cmpq	%rax, %rbx
	jl	.LBB3_5
.LBB3_6:                                # %._crit_edge12
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z11buildArraysv, .Lfunc_end3-_Z11buildArraysv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7getTimev
.LCPI4_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z7getTimev
	.type	_Z7getTimev,@function
_Z7getTimev:                            # @_Z7getTimev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cvtsi2sdq	(%rbx), %xmm1
	cvtsi2sdq	8(%rbx), %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z7getTimev, .Lfunc_end4-_Z7getTimev
	.cfi_endproc
                                        # -- End function
	.globl	_Z18__device_stub__addPfS_S_ii  # -- Begin function _Z18__device_stub__addPfS_S_ii
	.type	_Z18__device_stub__addPfS_S_ii,@function
_Z18__device_stub__addPfS_S_ii:         # @_Z18__device_stub__addPfS_S_ii
	.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	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	movq	%rsp, %rcx
	movl	%r8d, (%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	$_Z3addPfS_S_ii, %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_end5:
	.size	_Z18__device_stub__addPfS_S_ii, .Lfunc_end5-_Z18__device_stub__addPfS_S_ii
	.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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3addPfS_S_ii, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	GRID_WIDTH,@object              # @GRID_WIDTH
	.bss
	.globl	GRID_WIDTH
	.p2align	2, 0x0
GRID_WIDTH:
	.long	0                               # 0x0
	.size	GRID_WIDTH, 4

	.type	GRID_HEIGHT,@object             # @GRID_HEIGHT
	.globl	GRID_HEIGHT
	.p2align	2, 0x0
GRID_HEIGHT:
	.long	0                               # 0x0
	.size	GRID_HEIGHT, 4

	.type	BLOCK_WIDTH,@object             # @BLOCK_WIDTH
	.globl	BLOCK_WIDTH
	.p2align	2, 0x0
BLOCK_WIDTH:
	.long	0                               # 0x0
	.size	BLOCK_WIDTH, 4

	.type	BLOCK_HEIGHT,@object            # @BLOCK_HEIGHT
	.globl	BLOCK_HEIGHT
	.p2align	2, 0x0
BLOCK_HEIGHT:
	.long	0                               # 0x0
	.size	BLOCK_HEIGHT, 4

	.type	MATRIX_HEIGHT,@object           # @MATRIX_HEIGHT
	.globl	MATRIX_HEIGHT
	.p2align	2, 0x0
MATRIX_HEIGHT:
	.long	0                               # 0x0
	.size	MATRIX_HEIGHT, 4

	.type	MATRIX_WIDTH,@object            # @MATRIX_WIDTH
	.globl	MATRIX_WIDTH
	.p2align	2, 0x0
MATRIX_WIDTH:
	.long	0                               # 0x0
	.size	MATRIX_WIDTH, 4

	.type	NUM_VALUES,@object              # @NUM_VALUES
	.globl	NUM_VALUES
	.p2align	2, 0x0
NUM_VALUES:
	.long	0                               # 0x0
	.size	NUM_VALUES, 4

	.type	startTime,@object               # @startTime
	.globl	startTime
	.p2align	3, 0x0
startTime:
	.quad	0x0000000000000000              # double 0
	.size	startTime, 8

	.type	stopTime,@object                # @stopTime
	.globl	stopTime
	.p2align	3, 0x0
stopTime:
	.quad	0x0000000000000000              # double 0
	.size	stopTime, 8

	.type	a,@object                       # @a
	.globl	a
	.p2align	3, 0x0
a:
	.quad	0
	.size	a, 8

	.type	b,@object                       # @b
	.globl	b
	.p2align	3, 0x0
b:
	.quad	0
	.size	b, 8

	.type	c,@object                       # @c
	.globl	c
	.p2align	3, 0x0
c:
	.quad	0
	.size	c, 8

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Time: %f secs\n"
	.size	.L.str, 15

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\nmatrixadd: Incorrect number of arguments. matrixadd requires 6 arguments not %d\nCorrect usage: \"matrixadd grid-width grid-height blck-width blck-height mat-height mat-width\"\n"
	.size	.L.str.1, 176

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\nmatrixadd: Overflow. Invalid argument %d for matrixadd, '%s'.\nThe argument must be a valid, positive, non-zero integer less than %d.\n"
	.size	.L.str.2, 135

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\nmatrixadd: Invalid argument %d for matrixadd, '%s'.  The argument must be a valid, positive, non-zero integer.\n"
	.size	.L.str.3, 113

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\nmatrixadd: Insufficient GPU. GPU does not have enough memory to handle the data size: %ld. It can only handle data sizes up to %ld.\n"
	.size	.L.str.4, 134

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\nmatrixadd: Insufficient GPU. GPU can only handle %d threads per block, not %d.\n"
	.size	.L.str.5, 81

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block width of each block, not %d.\n"
	.size	.L.str.6, 104

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\nmatrixadd: Insufficient GPU. GPU can only handle %d threads as the block height of each block, not %d.\n"
	.size	.L.str.7, 105

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid width of each grid, not %d.\n"
	.size	.L.str.8, 101

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\nmatrixadd: Insufficient GPU. GPU can only handle %d blocks as the grid height of each grid, not %d.\n"
	.size	.L.str.9, 102

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3addPfS_S_ii"
	.size	.L__unnamed_1, 15

	.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 _Z18__device_stub__addPfS_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z3addPfS_S_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3addPfS_S_ii          ; -- Begin function _Z3addPfS_S_ii
	.globl	_Z3addPfS_S_ii
	.p2align	8
	.type	_Z3addPfS_S_ii,@function
_Z3addPfS_S_ii:                         ; @_Z3addPfS_S_ii
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s3, 1
	s_cbranch_scc1 .LBB0_5
; %bb.1:                                ; %.lr.ph
	s_clause 0x3
	s_load_b32 s10, s[0:1], 0x2c
	s_load_b64 s[8:9], s[0:1], 0x20
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[0:1], s[0:1], 0x10
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v2, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s11, s10, 16
	s_and_b32 s10, s10, 0xffff
	s_mul_i32 s15, s15, s11
	s_mul_i32 s8, s8, s9
	v_add3_u32 v3, s15, s14, v1
	s_mul_i32 s8, s8, s11
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mul_i32 s8, s8, s10
	v_mad_u64_u32 v[0:1], null, v3, s10, v[2:3]
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s9, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s2, v0
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_2 Depth=1
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	v_add_co_u32 v3, vcc_lo, s4, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v2, vcc_lo
	v_add_co_u32 v5, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v2, vcc_lo
	v_add_co_u32 v1, vcc_lo, s0, v1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v4, v[5:6], off
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v3, v3, v4
	global_store_b32 v[1:2], v3, off
.LBB0_4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
	v_add_nc_u32_e32 v0, s8, v0
	s_add_i32 s3, s3, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s3, 0
	s_cbranch_scc0 .LBB0_2
.LBB0_5:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3addPfS_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 7
		.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	_Z3addPfS_S_ii, .Lfunc_end0-_Z3addPfS_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 268
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     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:           _Z3addPfS_S_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z3addPfS_S_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
