/*https://cdac.in/index.aspx?id=ev_hpc_gpu-comp-nvidia-cuda-streams#hetr-cuda-prog-cuda-streams*/

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

//#define sizeOfArray 1024*1024

// 1. Execute Everything synchronously
// 2. Execute Everything asynchronously
// 3. Execute Memcpy Synchronously and kernel launch Asynchronously
// 4. Execute Memcpy asynchronously and kernel launch synchronously
// ** Measure variability across the above by chaning data size **
// ** Utilize Multiple Streams like in the example: https://devblogs.nvidia.com/gpu-pro-tip-cuda-7-streams-simplify-concurrency/ **
 
// Put global variables here
int REGS_PER_BLOCK, WARP_SIZE, MAX_THREADS_PER_BLOCK, *MAX_THREADS_DIM;
size_t TOTAL_GLOBAL_MEM, TOTAL_CONST_MEM;

__global__ void arrayAddition(int *device_a, int *device_b, int *device_result, int sizeOfArray)
{

	int threadId = threadIdx.x + blockIdx.x * blockDim.x ;

	if (threadId < sizeOfArray) 
        device_result[threadId]= device_a[threadId]+device_b[threadId]; 
} 

/*
 *checkCuda: will check to see if there is an error returned by CUDA runtime
 */
inline
void checkCuda(cudaError_t errMsg, const char* errContext)
{
	if(errMsg != cudaSuccess) {
		fprintf(stderr, "CUDA Runtime Error From %s: %s\n", errContext, cudaGetErrorString(errMsg));
		exit(EXIT_FAILURE);
	}
}

/*
 * getCUDAInfo() - originally named "getHardwareContraints in module 3
 * 							 - this function will get CUDA information pertaining to the hardware 
 * 							   on which we are operating... the code can then reason on these reports to determine
 * 								 the best way to structure memory transfers between the host and device
 */
void getCUDAInfo() {
	//=============================Gets number of cuda devices===========================================
    int deviceCount = 0;
    checkCuda(cudaGetDeviceCount(&deviceCount), "Failed deviceCount load");

    // This function call returns 0 if there are no CUDA capable devices.
    if (deviceCount == 0)
    {
        printf("There are no available device(s) that support CUDA\n");
    }
    else
    {
        printf("Detected %d CUDA Capable device(s)\n", deviceCount);
    }
//=============================Gets number of cuda devices===========================================
    
    // for each device found, store this device in some type of object
    int device;

    for (device = 0; device < deviceCount; device++) {
	
			// Sets the context of the device so that we know which device we are working with if there
			// are multiple	
			cudaSetDevice(device);
  		cudaDeviceProp deviceProp;

			// gets the "properties" struct that stores the properties of a device
			// from this property struct, we can query the limitations of this device
  		cudaGetDeviceProperties(&deviceProp, device);

			printf("\nDevice: %d \"%s\"\n===========================================\n", device, deviceProp.name);
	
			TOTAL_GLOBAL_MEM = deviceProp.totalGlobalMem;
			REGS_PER_BLOCK = deviceProp.regsPerBlock;
			WARP_SIZE = deviceProp.warpSize;
			MAX_THREADS_PER_BLOCK = deviceProp.maxThreadsPerBlock;
			MAX_THREADS_DIM = deviceProp.maxThreadsDim;
			TOTAL_CONST_MEM = deviceProp.totalConstMem; 
	printf("The %s has:\n\t-%zu total bytes of global memory\n\t-%zu bytes of constant memory\n\t-%d registers per block\n\t-%d threads per warp\n\t-A maximum of %d threads per block\n\t-A maximum thread dimension of %d x %d x %d\n", deviceProp.name, TOTAL_GLOBAL_MEM,TOTAL_CONST_MEM, REGS_PER_BLOCK, WARP_SIZE, MAX_THREADS_PER_BLOCK, MAX_THREADS_DIM[0], MAX_THREADS_DIM[1], MAX_THREADS_DIM[2]); 
	// What I think we care about:
	// 1. totalGlobalMem
	// 2. regsPerBlock
	// 3. warpSize (i.e. numThreadsPerBlock (is this equal to regsPerBlock??)
	// 4. maxThreadsperBlock
	// 5. maxThreadsDim[3]
    }
}

bool verifyResult(int *host_a, int *host_b, int **host_result,
					 				int num_streams, int sizeOfArray) {
	bool testPassed = true;
	for(int i = 0; i < num_streams; i++) {
		for(int j = 0; j < sizeOfArray; j++) {
			if((host_a[j] + host_b[j]) != host_result[i][j]) {
  			testPassed = false;
  			printf("Case %d Failed on Stream %d, iteration %d: %d + %d = Serial Result: %d ParallelResult: %d\n", 0,i, j, host_a[j], host_b[j], host_a[j] + host_b[j], host_result[i][j]);
  		}
		}
	}
	
	return testPassed;				 				
}

float testStream(int **device_a, int **device_b, int **device_result,
					 int *host_a, int *host_b, int **host_result,
					 cudaStream_t *streams, cudaEvent_t start, cudaEvent_t stop,
					 int num_streams, int sizeOfArray,int sync_test, 
					 int gridSize, int blockSize) {
	float elapsedTime = 0;
	for(int i = 0; i < num_streams; i++) {
		// Create new stream on each iteration
		checkCuda(cudaStreamCreate(&streams[i]), "cudaStreamCreate");
		
		// Allocate device memory for each iteration
  	cudaMalloc( ( void**)& device_a[i], sizeOfArray * sizeof ( **device_a ) ); 
  	cudaMalloc( ( void**)& device_b[i],sizeOfArray * sizeof ( **device_b ) ); 
  	cudaMalloc( ( void**)& device_result[i], sizeOfArray * sizeof ( **device_result ) ); 
		cudaEventRecord(start,0);
  	switch(sync_test) {
  		// Synchronous memcpy and kernel launch
  		case 0: 
  			checkCuda(cudaMemcpy(device_a[i], host_a,sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice), "host to device async memcpy 1"); 
  			checkCuda(cudaMemcpy(device_b[i], host_b, sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice), "host to device async memcpy 2"); 
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int)>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(cudaMemcpy(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), cudaMemcpyDeviceToHost), "device to host async memcpy");
  			break;
  		// Asynchronous memcpy and synchronous kernel launch
  		case 1:
  			checkCuda(cudaMemcpyAsync(device_a[i], host_a,sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice, streams[i]), "host to device async memcpy 1"); 
  			checkCuda(cudaMemcpyAsync(device_b[i], host_b, sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice, streams[i]), "host to device async memcpy 2"); 
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int)>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(cudaMemcpyAsync(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), cudaMemcpyDeviceToHost, streams[i]), "device to host async memcpy");
  			break;
  		// Synchronous memcpy and asynchronous kernel launch
  		case 2:
  			checkCuda(cudaMemcpy(device_a[i], host_a,sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice), "host to device async memcpy 1"); 
  			checkCuda(cudaMemcpy(device_b[i], host_b, sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice), "host to device async memcpy 2"); 
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int), streams[i]>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(cudaMemcpy(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), cudaMemcpyDeviceToHost), "device to host async memcpy");
  			break;
  		case 3: 
  			checkCuda(cudaMemcpyAsync(device_a[i], host_a,sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice, streams[i]), "host to device async memcpy 1"); 
  			checkCuda(cudaMemcpyAsync(device_b[i], host_b, sizeOfArray * sizeof ( int ), cudaMemcpyHostToDevice, streams[i]), "host to device async memcpy 2");
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int), streams[i]>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(cudaMemcpyAsync(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), cudaMemcpyDeviceToHost, streams[i]), "device to host async memcpy");
  			break;	
  		default:
  			break;
  	}

		
	}
  cudaEventRecord(stop, 0);
  cudaEventSynchronize(stop);
  cudaEventElapsedTime(&elapsedTime, start, stop); 
	return elapsedTime;
}


/* Check for safe return of all calls to the device */ 

int main ( int argc, char **argv ) 
{ 

	// Take block size and data size as input
	// Check block size to make sure it does not exceed the maximum number of threads per block
  int blockSize = 512;
  int sizeOfArray = 1024 * 1024;
	if(argc == 3) {
		//numRuns = atoi(argv[1]);
		blockSize = atoi(argv[1]);
		sizeOfArray = atoi(argv[2]);
	}
  const int num_streams = 10;
  int *host_a, *host_b, *host_result[num_streams]; 
  int *device_a[num_streams], *device_b[num_streams], *device_result[num_streams]; 
  getCUDAInfo();
  int gridSize =  ((sizeOfArray % blockSize) == 0) ? (sizeOfArray / blockSize) : ((sizeOfArray / blockSize) + 1);
  // Create array to store each stream:
  cudaStream_t streams[num_streams]; 

  cudaEvent_t start, stop; 
  float elapsedTime0, elapsedTime1 = 0, elapsedTime2 = 0, elapsedTime3 = 0 ; 

  cudaEventCreate( &start ); 
  cudaEventCreate( &stop ); 
	
	// Allocate host memory
	cudaHostAlloc((void **)&host_a, sizeOfArray*sizeof(int), cudaHostAllocDefault);
  cudaHostAlloc((void **)&host_b, sizeOfArray*sizeof(int), cudaHostAllocDefault);
  for(int i = 0; i < num_streams; i++) {
  	cudaHostAlloc((void **)&host_result[i], num_streams*sizeOfArray*sizeof(int), cudaHostAllocDefault);
  }
  
	
	// Initiailize host memory
  for(int index = 0; index < sizeOfArray; index++) 
  { 
   host_a[index] = rand()%10; 
   host_b[index] = rand()%10; 
  } 
	
	//cudaEventRecord(start,0);
	elapsedTime0 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams,  sizeOfArray, 0, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime0, start, stop); 
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  
  //cudaEventRecord(start, 0);
	elapsedTime1 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams,  sizeOfArray, 1, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime1, start, stop);
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  
  
  //cudaEventRecord(start, 0);
	elapsedTime2 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams,  sizeOfArray, 2, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime2, start, stop);
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  
  
  //cudaEventRecord(start, 0);
	elapsedTime3 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams, sizeOfArray, 3, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime3, start, stop);
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  /*cudaStream_t stream; 
  cudaStreamCreate(&stream); */
 

  //printf("*********** CDAC - Tech Workshop : hyPACK-2013 \n"); 
  printf("\n Size of array : %d \n", sizeOfArray); 
  printf("\n Time taken for synchronous memcpy and synchronous kernel launch: %f ms \n", elapsedTime0); 
  printf("\n Time taken for asynchronous memcpy and synchronous kernel launch: %f ms \n", elapsedTime1); 
  printf("\n Time taken for synchronous memcpy and asynchronous kernel launch: %f ms \n", elapsedTime2); 
  printf("\n Time taken for asynchronous memcpy and asynchronous kernel launch: %f ms \n", elapsedTime3); 
	
	for(int i = 0; i < num_streams; i++) {
		cudaStreamDestroy(streams[i]);	
	}
	cudaEventDestroy(stop);
	cudaEventDestroy(start);
  cudaFreeHost(host_a); 
  cudaFreeHost(host_b); 
  cudaFreeHost(host_result); 
  cudaFree(device_a); 
  cudaFree(device_b); 
  cudaFree(device_result); 

  return 0; 
}

	.file	"tmpxft_0028a770_00000000-6_stream_example.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
	.section	.rodata._Z9checkCuda9cudaErrorPKc.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA Runtime Error From %s: %s\n"
	.section	.text._Z9checkCuda9cudaErrorPKc,"axG",@progbits,_Z9checkCuda9cudaErrorPKc,comdat
	.weak	_Z9checkCuda9cudaErrorPKc
	.type	_Z9checkCuda9cudaErrorPKc, @function
_Z9checkCuda9cudaErrorPKc:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %rbx
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbx, %rcx
	leaq	.LC0(%rip), %rdx
	movq	%rax, %r8
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9checkCuda9cudaErrorPKc, .-_Z9checkCuda9cudaErrorPKc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Failed deviceCount load"
.LC2:
	.string	"There are no available device(s) that support CUDA\n"
.LC3:
	.string	"Detected %d CUDA Capable device(s)\n"
.LC4:
	.string	"\nDevice: %d \"%s\"\n===========================================\n"
.LC5:
	.string	"The %s has:\n\t-%zu total bytes of global memory\n\t-%zu bytes of constant memory\n\t-%d registers per block\n\t-%d threads per warp\n\t-A maximum of %d threads per block\n\t-A maximum thread dimension of %d x %d x %d\n"
	.text
	.globl	_Z11getCUDAInfov
	.type	_Z11getCUDAInfov, @function
_Z11getCUDAInfov:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	xorl	%edi, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1088
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	movl	%edi, 12(%rsp)
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	leaq	.LC1(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movl	12(%rsp), %edx
	testl	%edx, %edx
	jne	.L9
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L11:
	xorl	%ebx, %ebx
	leaq	.LC4(%rip), %r12
	jmp	.L10
.L9:
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L11
.L10:
	cmpl	%ebx, 12(%rsp)
	jle	.L15
	leaq	16(%rsp), %rbp
	movl	%ebx, %edi
	call	cudaSetDevice@PLT
	movl	%ebx, %esi
	movq	%rbp, %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movl	%ebx, %edx
	movq	%rbp, %rcx
	movq	%r12, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebx
	call	__printf_chk@PLT
	leaq	340(%rsp), %rsi
	movl	324(%rsp), %eax
	movl	336(%rsp), %edx
	movq	304(%rsp), %rcx
	movl	320(%rsp), %r9d
	movq	%rsi, MAX_THREADS_DIM(%rip)
	movl	$2, %edi
	movq	368(%rsp), %r8
	pushq	%rsi
	.cfi_def_cfa_offset 1096
	movl	356(%rsp), %esi
	movl	%eax, WARP_SIZE(%rip)
	movl	%edx, MAX_THREADS_PER_BLOCK(%rip)
	pushq	%rsi
	.cfi_def_cfa_offset 1104
	movl	360(%rsp), %esi
	movq	%rcx, TOTAL_GLOBAL_MEM(%rip)
	pushq	%rsi
	.cfi_def_cfa_offset 1112
	movl	364(%rsp), %esi
	movl	%r9d, REGS_PER_BLOCK(%rip)
	pushq	%rsi
	.cfi_def_cfa_offset 1120
	leaq	.LC5(%rip), %rsi
	pushq	%rdx
	.cfi_def_cfa_offset 1128
	movq	%rbp, %rdx
	pushq	%rax
	.cfi_def_cfa_offset 1136
	xorl	%eax, %eax
	movq	%r8, TOTAL_CONST_MEM(%rip)
	call	__printf_chk@PLT
	addq	$48, %rsp
	.cfi_def_cfa_offset 1088
	jmp	.L10
.L15:
	movq	1048(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$1056, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11getCUDAInfov, .-_Z11getCUDAInfov
	.section	.rodata.str1.1
.LC6:
	.string	"Case %d Failed on Stream %d, iteration %d: %d + %d = Serial Result: %d ParallelResult: %d\n"
	.text
	.globl	_Z12verifyResultPiS_PS_ii
	.type	_Z12verifyResultPiS_PS_ii, @function
_Z12verifyResultPiS_PS_ii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movb	$1, %al
	movq	%rsi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%r8d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movl	%ecx, 12(%rsp)
.L17:
	movl	%ebp, 8(%rsp)
	cmpl	%ebp, 12(%rsp)
	jle	.L23
	xorl	%ebx, %ebx
.L20:
	cmpl	%ebx, %r14d
	jle	.L24
	movq	(%r12,%rbp,8), %rsi
	movl	0(%r13,%rbx,4), %r9d
	movl	(%r15,%rbx,4), %edx
	movl	(%rsi,%rbx,4), %esi
	leal	(%r9,%rdx), %ecx
	cmpl	%esi, %ecx
	je	.L18
	pushq	%rax
	.cfi_def_cfa_offset 88
	movl	%ebx, %r8d
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%rsi
	.cfi_def_cfa_offset 96
	leaq	.LC6(%rip), %rsi
	pushq	%rcx
	.cfi_def_cfa_offset 104
	pushq	%rdx
	.cfi_def_cfa_offset 112
	movl	40(%rsp), %ecx
	xorl	%edx, %edx
	call	__printf_chk@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 80
	xorl	%eax, %eax
.L18:
	incq	%rbx
	jmp	.L20
.L24:
	incq	%rbp
	jmp	.L17
.L23:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	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	_Z12verifyResultPiS_PS_ii, .-_Z12verifyResultPiS_PS_ii
	.globl	_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i
	.type	_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i, @function
_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z13arrayAdditionPiS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L25:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i, .-_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i
	.globl	_Z13arrayAdditionPiS_S_i
	.type	_Z13arrayAdditionPiS_S_i, @function
_Z13arrayAdditionPiS_S_i:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i
	.cfi_endproc
.LFE2057:
	.size	_Z13arrayAdditionPiS_S_i, .-_Z13arrayAdditionPiS_S_i
	.section	.rodata.str1.1
.LC8:
	.string	"cudaStreamCreate"
.LC9:
	.string	"host to device async memcpy 1"
.LC10:
	.string	"host to device async memcpy 2"
.LC11:
	.string	"device to host async memcpy"
	.text
	.globl	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii
	.type	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii, @function
_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%r9, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	168(%rsp), %rax
	movq	%rcx, 16(%rsp)
	movq	%r8, 24(%rsp)
	movq	160(%rsp), %r13
	movq	%rax, 40(%rsp)
	movq	176(%rsp), %rax
	movq	%rax, 32(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	movslq	192(%rsp), %rax
	movl	$0x00000000, 60(%rsp)
	salq	$2, %rax
	movq	%rax, (%rsp)
	movslq	216(%rsp), %rax
	salq	$2, %rax
	movq	%rax, 8(%rsp)
.L31:
	cmpl	%r14d, 184(%rsp)
	jle	.L50
	movq	%r13, %rdi
	call	cudaStreamCreate@PLT
	leaq	.LC8(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movq	(%rsp), %rsi
	movq	%rbp, %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	movq	%r12, %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rsi
	movq	%rbx, %rdi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	cmpl	$2, 200(%rsp)
	je	.L32
	jg	.L33
	cmpl	$0, 200(%rsp)
	je	.L34
	cmpl	$1, 200(%rsp)
	jne	.L36
	movq	0(%r13), %r8
	movq	(%rsp), %rdx
	movl	$1, %ecx
	movq	16(%rsp), %rsi
	movq	0(%rbp), %rdi
	call	cudaMemcpyAsync@PLT
	leaq	.LC9(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movq	(%rsp), %rdx
	movq	0(%r13), %r8
	movl	$1, %ecx
	movq	24(%rsp), %rsi
	movq	(%r12), %rdi
	call	cudaMemcpyAsync@PLT
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movl	216(%rsp), %eax
	movl	208(%rsp), %edx
	xorl	%r9d, %r9d
	movl	%eax, 76(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movl	%edx, 64(%rsp)
	movq	%rax, 68(%rsp)
	jmp	.L47
.L33:
	cmpl	$3, 200(%rsp)
	jne	.L36
	movq	0(%r13), %r8
	movq	(%rsp), %rdx
	movl	$1, %ecx
	movq	16(%rsp), %rsi
	movq	0(%rbp), %rdi
	call	cudaMemcpyAsync@PLT
	leaq	.LC9(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movq	(%rsp), %rdx
	movq	0(%r13), %r8
	movl	$1, %ecx
	movq	24(%rsp), %rsi
	movq	(%r12), %rdi
	call	cudaMemcpyAsync@PLT
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movl	216(%rsp), %eax
	movl	208(%rsp), %edx
	movq	0(%r13), %r9
	movl	%eax, 76(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movl	%edx, 64(%rsp)
	movq	%rax, 68(%rsp)
	jmp	.L47
.L34:
	movq	(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	0(%rbp), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC9(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movq	(%r12), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movl	216(%rsp), %eax
	movl	208(%rsp), %edx
	xorl	%r9d, %r9d
	movl	%eax, 76(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
	movl	%edx, 64(%rsp)
	movq	%rax, 68(%rsp)
	jmp	.L49
.L32:
	movq	(%rsp), %rdx
	movq	16(%rsp), %rsi
	movl	$1, %ecx
	movq	0(%rbp), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC9(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	$1, %ecx
	movq	(%r12), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	_Z9checkCuda9cudaErrorPKc
	movl	216(%rsp), %eax
	movl	208(%rsp), %edx
	movq	0(%r13), %r9
	movl	%eax, 76(%rsp)
	movabsq	$4294967297, %rax
	movl	%edx, 64(%rsp)
	movq	%rax, 68(%rsp)
	movq	%rax, 80(%rsp)
	movl	84(%rsp), %ecx
.L49:
	movq	8(%rsp), %r8
	movq	76(%rsp), %rdx
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	movl	192(%rsp), %ecx
	movq	(%rbx), %rdx
	movq	(%r12), %rsi
	movq	0(%rbp), %rdi
	call	_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i
.L40:
	movq	(%r15,%r14,8), %rdi
	movq	(%rsp), %rdx
	movl	$2, %ecx
	movq	(%rbx), %rsi
	call	cudaMemcpy@PLT
	jmp	.L45
.L47:
	movq	8(%rsp), %r8
	movq	76(%rsp), %rdx
	movq	64(%rsp), %rdi
	movl	72(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	movl	192(%rsp), %ecx
	movq	(%rbx), %rdx
	movq	(%r12), %rsi
	movq	0(%rbp), %rdi
	call	_Z38__device_stub__Z13arrayAdditionPiS_S_iPiS_S_i
.L41:
	movq	(%r15,%r14,8), %rdi
	movq	0(%r13), %r8
	movl	$2, %ecx
	movq	(%rsp), %rdx
	movq	(%rbx), %rsi
	call	cudaMemcpyAsync@PLT
.L45:
	movl	%eax, %edi
	leaq	.LC11(%rip), %rsi
	call	_Z9checkCuda9cudaErrorPKc
.L36:
	incq	%r14
	addq	$8, %rbx
	addq	$8, %r13
	addq	$8, %rbp
	addq	$8, %r12
	jmp	.L31
.L50:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	32(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	60(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movss	60(%rsp), %xmm0
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2030:
	.size	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii, .-_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii
	.section	.rodata.str1.1
.LC12:
	.string	"\n Size of array : %d \n"
.LC13:
	.string	"\n Time taken for synchronous memcpy and synchronous kernel launch: %f ms \n"
.LC14:
	.string	"\n Time taken for asynchronous memcpy and synchronous kernel launch: %f ms \n"
.LC15:
	.string	"\n Time taken for synchronous memcpy and asynchronous kernel launch: %f ms \n"
.LC16:
	.string	"\n Time taken for asynchronous memcpy and asynchronous kernel launch: %f ms \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.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
	subq	$488, %rsp
	.cfi_def_cfa_offset 544
	movq	%fs:40, %rax
	movq	%rax, 472(%rsp)
	xorl	%eax, %eax
	cmpl	$3, %edi
	jne	.L60
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	call	atoi@PLT
	movq	16(%rbx), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movl	%eax, %ebx
	jmp	.L52
.L60:
	movl	$1048576, %ebx
	movl	$512, %ebp
.L52:
	call	_Z11getCUDAInfov
	movl	%ebx, %eax
	leaq	56(%rsp), %rdi
	movslq	%ebx, %r12
	cltd
	leaq	72(%rsp), %r14
	idivl	%ebp
	cmpl	$1, %edx
	sbbl	$-1, %eax
	imull	$10, %ebx, %r15d
	salq	$2, %r12
	movl	%eax, %r13d
	call	cudaEventCreate@PLT
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	%r12, %rsi
	leaq	40(%rsp), %rdi
	xorl	%edx, %edx
	call	cudaHostAlloc@PLT
	movslq	%r15d, %r15
	movq	%r12, %rsi
	leaq	48(%rsp), %rdi
	xorl	%edx, %edx
	movq	%r14, %r12
	call	cudaHostAlloc@PLT
	leaq	0(,%r15,4), %rax
	leaq	152(%rsp), %r15
	movq	%rax, (%rsp)
.L55:
	movq	(%rsp), %rsi
	movq	%r14, %rdi
	xorl	%edx, %edx
	addq	$8, %r14
	call	cudaHostAlloc@PLT
	cmpq	%r15, %r14
	jne	.L55
	xorl	%r14d, %r14d
	movl	$10, %r15d
.L56:
	cmpl	%r14d, %ebx
	jle	.L64
	call	rand@PLT
	cltd
	idivl	%r15d
	movq	40(%rsp), %rax
	movl	%edx, (%rax,%r14,4)
	call	rand@PLT
	cltd
	idivl	%r15d
	movq	48(%rsp), %rax
	movl	%edx, (%rax,%r14,4)
	incq	%r14
	jmp	.L56
.L64:
	leaq	312(%rsp), %rax
	leaq	152(%rsp), %r14
	movq	%r12, %r9
	movq	%rax, (%rsp)
	leaq	232(%rsp), %rax
	movq	%r14, %rdi
	movq	%rax, 8(%rsp)
	pushq	%rbp
	.cfi_def_cfa_offset 552
	pushq	%r13
	.cfi_def_cfa_offset 560
	pushq	$0
	.cfi_def_cfa_offset 568
	pushq	%rbx
	.cfi_def_cfa_offset 576
	pushq	$10
	.cfi_def_cfa_offset 584
	pushq	104(%rsp)
	.cfi_def_cfa_offset 592
	pushq	104(%rsp)
	.cfi_def_cfa_offset 600
	leaq	448(%rsp), %r15
	pushq	%r15
	.cfi_def_cfa_offset 608
	movq	112(%rsp), %r8
	movq	104(%rsp), %rcx
	movq	64(%rsp), %rdx
	movq	72(%rsp), %rsi
	call	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii
	movl	%ebx, %r8d
	movl	$10, %ecx
	movq	%r12, %rdx
	movss	%xmm0, 92(%rsp)
	movq	112(%rsp), %rsi
	movq	104(%rsp), %rdi
	addq	$64, %rsp
	.cfi_def_cfa_offset 544
	call	_Z12verifyResultPiS_PS_ii
	pushq	%rbp
	.cfi_def_cfa_offset 552
	movq	%r12, %r9
	movq	%r14, %rdi
	pushq	%r13
	.cfi_def_cfa_offset 560
	pushq	$1
	.cfi_def_cfa_offset 568
	pushq	%rbx
	.cfi_def_cfa_offset 576
	pushq	$10
	.cfi_def_cfa_offset 584
	pushq	104(%rsp)
	.cfi_def_cfa_offset 592
	pushq	104(%rsp)
	.cfi_def_cfa_offset 600
	pushq	%r15
	.cfi_def_cfa_offset 608
	movq	112(%rsp), %r8
	movq	104(%rsp), %rcx
	movq	64(%rsp), %rdx
	movq	72(%rsp), %rsi
	call	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii
	movl	%ebx, %r8d
	movl	$10, %ecx
	movq	%r12, %rdx
	movss	%xmm0, 88(%rsp)
	movq	112(%rsp), %rsi
	movq	104(%rsp), %rdi
	addq	$64, %rsp
	.cfi_def_cfa_offset 544
	call	_Z12verifyResultPiS_PS_ii
	pushq	%rbp
	.cfi_def_cfa_offset 552
	movq	%r12, %r9
	movq	%r14, %rdi
	pushq	%r13
	.cfi_def_cfa_offset 560
	pushq	$2
	.cfi_def_cfa_offset 568
	pushq	%rbx
	.cfi_def_cfa_offset 576
	pushq	$10
	.cfi_def_cfa_offset 584
	pushq	104(%rsp)
	.cfi_def_cfa_offset 592
	pushq	104(%rsp)
	.cfi_def_cfa_offset 600
	pushq	%r15
	.cfi_def_cfa_offset 608
	movq	112(%rsp), %r8
	movq	104(%rsp), %rcx
	movq	64(%rsp), %rdx
	movq	72(%rsp), %rsi
	call	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii
	movl	%ebx, %r8d
	movl	$10, %ecx
	movq	%r12, %rdx
	movss	%xmm0, 84(%rsp)
	movq	112(%rsp), %rsi
	movq	104(%rsp), %rdi
	addq	$64, %rsp
	.cfi_def_cfa_offset 544
	call	_Z12verifyResultPiS_PS_ii
	pushq	%rbp
	.cfi_def_cfa_offset 552
	movq	%r12, %r9
	movq	%r14, %rdi
	pushq	%r13
	.cfi_def_cfa_offset 560
	pushq	$3
	.cfi_def_cfa_offset 568
	pushq	%rbx
	.cfi_def_cfa_offset 576
	pushq	$10
	.cfi_def_cfa_offset 584
	pushq	104(%rsp)
	.cfi_def_cfa_offset 592
	pushq	104(%rsp)
	.cfi_def_cfa_offset 600
	pushq	%r15
	.cfi_def_cfa_offset 608
	movq	112(%rsp), %r8
	movq	104(%rsp), %rcx
	movq	64(%rsp), %rdx
	movq	72(%rsp), %rsi
	call	_Z10testStreamPPiS0_S0_S_S_S0_PP11CUstream_stP10CUevent_stS5_iiiii
	movq	112(%rsp), %rsi
	movl	%ebx, %r8d
	movq	%r12, %rdx
	movq	104(%rsp), %rdi
	addq	$64, %rsp
	.cfi_def_cfa_offset 544
	movl	$10, %ecx
	movd	%xmm0, %ebp
	call	_Z12verifyResultPiS_PS_ii
	movl	%ebx, %edx
	leaq	.LC12(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	movss	28(%rsp), %xmm3
	leaq	.LC13(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtss2sd	%xmm3, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	movss	24(%rsp), %xmm2
	leaq	.LC14(%rip), %rsi
	cvtss2sd	%xmm2, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	movss	20(%rsp), %xmm1
	leaq	.LC15(%rip), %rsi
	cvtss2sd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movd	%ebp, %xmm4
	movl	$2, %edi
	leaq	.LC16(%rip), %rsi
	movb	$1, %al
	cvtss2sd	%xmm4, %xmm0
	call	__printf_chk@PLT
.L58:
	movq	(%r15,%rbx,8), %rdi
	incq	%rbx
	call	cudaStreamDestroy@PLT
	cmpq	$10, %rbx
	jne	.L58
	movq	64(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	48(%rsp), %rdi
	call	cudaFreeHost@PLT
	leaq	72(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	%r14, %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	472(%rsp), %rax
	subq	%fs:40, %rax
	je	.L59
	call	__stack_chk_fail@PLT
.L59:
	addq	$488, %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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z13arrayAdditionPiS_S_i"
	.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	.LC17(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z13arrayAdditionPiS_S_i(%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	TOTAL_CONST_MEM
	.bss
	.align 8
	.type	TOTAL_CONST_MEM, @object
	.size	TOTAL_CONST_MEM, 8
TOTAL_CONST_MEM:
	.zero	8
	.globl	TOTAL_GLOBAL_MEM
	.align 8
	.type	TOTAL_GLOBAL_MEM, @object
	.size	TOTAL_GLOBAL_MEM, 8
TOTAL_GLOBAL_MEM:
	.zero	8
	.globl	MAX_THREADS_DIM
	.align 8
	.type	MAX_THREADS_DIM, @object
	.size	MAX_THREADS_DIM, 8
MAX_THREADS_DIM:
	.zero	8
	.globl	MAX_THREADS_PER_BLOCK
	.align 4
	.type	MAX_THREADS_PER_BLOCK, @object
	.size	MAX_THREADS_PER_BLOCK, 4
MAX_THREADS_PER_BLOCK:
	.zero	4
	.globl	WARP_SIZE
	.align 4
	.type	WARP_SIZE, @object
	.size	WARP_SIZE, 4
WARP_SIZE:
	.zero	4
	.globl	REGS_PER_BLOCK
	.align 4
	.type	REGS_PER_BLOCK, @object
	.size	REGS_PER_BLOCK, 4
REGS_PER_BLOCK:
	.zero	4
	.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:

/*https://cdac.in/index.aspx?id=ev_hpc_gpu-comp-nvidia-cuda-streams#hetr-cuda-prog-cuda-streams*/

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

//#define sizeOfArray 1024*1024

// 1. Execute Everything synchronously
// 2. Execute Everything asynchronously
// 3. Execute Memcpy Synchronously and kernel launch Asynchronously
// 4. Execute Memcpy asynchronously and kernel launch synchronously
// ** Measure variability across the above by chaning data size **
// ** Utilize Multiple Streams like in the example: https://devblogs.nvidia.com/gpu-pro-tip-cuda-7-streams-simplify-concurrency/ **
 
// Put global variables here
int REGS_PER_BLOCK, WARP_SIZE, MAX_THREADS_PER_BLOCK, *MAX_THREADS_DIM;
size_t TOTAL_GLOBAL_MEM, TOTAL_CONST_MEM;

__global__ void arrayAddition(int *device_a, int *device_b, int *device_result, int sizeOfArray)
{

	int threadId = threadIdx.x + blockIdx.x * blockDim.x ;

	if (threadId < sizeOfArray) 
        device_result[threadId]= device_a[threadId]+device_b[threadId]; 
} 

/*
 *checkCuda: will check to see if there is an error returned by CUDA runtime
 */
inline
void checkCuda(hipError_t errMsg, const char* errContext)
{
	if(errMsg != hipSuccess) {
		fprintf(stderr, "CUDA Runtime Error From %s: %s\n", errContext, hipGetErrorString(errMsg));
		exit(EXIT_FAILURE);
	}
}

/*
 * getCUDAInfo() - originally named "getHardwareContraints in module 3
 * 							 - this function will get CUDA information pertaining to the hardware 
 * 							   on which we are operating... the code can then reason on these reports to determine
 * 								 the best way to structure memory transfers between the host and device
 */
void getCUDAInfo() {
	//=============================Gets number of cuda devices===========================================
    int deviceCount = 0;
    checkCuda(hipGetDeviceCount(&deviceCount), "Failed deviceCount load");

    // This function call returns 0 if there are no CUDA capable devices.
    if (deviceCount == 0)
    {
        printf("There are no available device(s) that support CUDA\n");
    }
    else
    {
        printf("Detected %d CUDA Capable device(s)\n", deviceCount);
    }
//=============================Gets number of cuda devices===========================================
    
    // for each device found, store this device in some type of object
    int device;

    for (device = 0; device < deviceCount; device++) {
	
			// Sets the context of the device so that we know which device we are working with if there
			// are multiple	
			hipSetDevice(device);
  		hipDeviceProp_t deviceProp;

			// gets the "properties" struct that stores the properties of a device
			// from this property struct, we can query the limitations of this device
  		hipGetDeviceProperties(&deviceProp, device);

			printf("\nDevice: %d \"%s\"\n===========================================\n", device, deviceProp.name);
	
			TOTAL_GLOBAL_MEM = deviceProp.totalGlobalMem;
			REGS_PER_BLOCK = deviceProp.regsPerBlock;
			WARP_SIZE = deviceProp.warpSize;
			MAX_THREADS_PER_BLOCK = deviceProp.maxThreadsPerBlock;
			MAX_THREADS_DIM = deviceProp.maxThreadsDim;
			TOTAL_CONST_MEM = deviceProp.totalConstMem; 
	printf("The %s has:\n\t-%zu total bytes of global memory\n\t-%zu bytes of constant memory\n\t-%d registers per block\n\t-%d threads per warp\n\t-A maximum of %d threads per block\n\t-A maximum thread dimension of %d x %d x %d\n", deviceProp.name, TOTAL_GLOBAL_MEM,TOTAL_CONST_MEM, REGS_PER_BLOCK, WARP_SIZE, MAX_THREADS_PER_BLOCK, MAX_THREADS_DIM[0], MAX_THREADS_DIM[1], MAX_THREADS_DIM[2]); 
	// What I think we care about:
	// 1. totalGlobalMem
	// 2. regsPerBlock
	// 3. warpSize (i.e. numThreadsPerBlock (is this equal to regsPerBlock??)
	// 4. maxThreadsperBlock
	// 5. maxThreadsDim[3]
    }
}

bool verifyResult(int *host_a, int *host_b, int **host_result,
					 				int num_streams, int sizeOfArray) {
	bool testPassed = true;
	for(int i = 0; i < num_streams; i++) {
		for(int j = 0; j < sizeOfArray; j++) {
			if((host_a[j] + host_b[j]) != host_result[i][j]) {
  			testPassed = false;
  			printf("Case %d Failed on Stream %d, iteration %d: %d + %d = Serial Result: %d ParallelResult: %d\n", 0,i, j, host_a[j], host_b[j], host_a[j] + host_b[j], host_result[i][j]);
  		}
		}
	}
	
	return testPassed;				 				
}

float testStream(int **device_a, int **device_b, int **device_result,
					 int *host_a, int *host_b, int **host_result,
					 hipStream_t *streams, hipEvent_t start, hipEvent_t stop,
					 int num_streams, int sizeOfArray,int sync_test, 
					 int gridSize, int blockSize) {
	float elapsedTime = 0;
	for(int i = 0; i < num_streams; i++) {
		// Create new stream on each iteration
		checkCuda(hipStreamCreate(&streams[i]), "hipStreamCreate");
		
		// Allocate device memory for each iteration
  	hipMalloc( ( void**)& device_a[i], sizeOfArray * sizeof ( **device_a ) ); 
  	hipMalloc( ( void**)& device_b[i],sizeOfArray * sizeof ( **device_b ) ); 
  	hipMalloc( ( void**)& device_result[i], sizeOfArray * sizeof ( **device_result ) ); 
		hipEventRecord(start,0);
  	switch(sync_test) {
  		// Synchronous memcpy and kernel launch
  		case 0: 
  			checkCuda(hipMemcpy(device_a[i], host_a,sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice), "host to device async memcpy 1"); 
  			checkCuda(hipMemcpy(device_b[i], host_b, sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice), "host to device async memcpy 2"); 
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int)>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(hipMemcpy(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), hipMemcpyDeviceToHost), "device to host async memcpy");
  			break;
  		// Asynchronous memcpy and synchronous kernel launch
  		case 1:
  			checkCuda(hipMemcpyAsync(device_a[i], host_a,sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice, streams[i]), "host to device async memcpy 1"); 
  			checkCuda(hipMemcpyAsync(device_b[i], host_b, sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice, streams[i]), "host to device async memcpy 2"); 
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int)>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(hipMemcpyAsync(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), hipMemcpyDeviceToHost, streams[i]), "device to host async memcpy");
  			break;
  		// Synchronous memcpy and asynchronous kernel launch
  		case 2:
  			checkCuda(hipMemcpy(device_a[i], host_a,sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice), "host to device async memcpy 1"); 
  			checkCuda(hipMemcpy(device_b[i], host_b, sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice), "host to device async memcpy 2"); 
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int), streams[i]>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(hipMemcpy(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), hipMemcpyDeviceToHost), "device to host async memcpy");
  			break;
  		case 3: 
  			checkCuda(hipMemcpyAsync(device_a[i], host_a,sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice, streams[i]), "host to device async memcpy 1"); 
  			checkCuda(hipMemcpyAsync(device_b[i], host_b, sizeOfArray * sizeof ( int ), hipMemcpyHostToDevice, streams[i]), "host to device async memcpy 2");
  			arrayAddition <<<gridSize, blockSize, blockSize * sizeof(int), streams[i]>>>(device_a[i], device_b[i], device_result[i], sizeOfArray); 
  			checkCuda(hipMemcpyAsync(host_result[i], device_result[i], sizeOfArray * sizeof ( int ), hipMemcpyDeviceToHost, streams[i]), "device to host async memcpy");
  			break;	
  		default:
  			break;
  	}

		
	}
  hipEventRecord(stop, 0);
  hipEventSynchronize(stop);
  hipEventElapsedTime(&elapsedTime, start, stop); 
	return elapsedTime;
}


/* Check for safe return of all calls to the device */ 

int main ( int argc, char **argv ) 
{ 

	// Take block size and data size as input
	// Check block size to make sure it does not exceed the maximum number of threads per block
  int blockSize = 512;
  int sizeOfArray = 1024 * 1024;
	if(argc == 3) {
		//numRuns = atoi(argv[1]);
		blockSize = atoi(argv[1]);
		sizeOfArray = atoi(argv[2]);
	}
  const int num_streams = 10;
  int *host_a, *host_b, *host_result[num_streams]; 
  int *device_a[num_streams], *device_b[num_streams], *device_result[num_streams]; 
  getCUDAInfo();
  int gridSize =  ((sizeOfArray % blockSize) == 0) ? (sizeOfArray / blockSize) : ((sizeOfArray / blockSize) + 1);
  // Create array to store each stream:
  hipStream_t streams[num_streams]; 

  hipEvent_t start, stop; 
  float elapsedTime0, elapsedTime1 = 0, elapsedTime2 = 0, elapsedTime3 = 0 ; 

  hipEventCreate( &start ); 
  hipEventCreate( &stop ); 
	
	// Allocate host memory
	hipHostAlloc((void **)&host_a, sizeOfArray*sizeof(int), hipHostMallocDefault);
  hipHostAlloc((void **)&host_b, sizeOfArray*sizeof(int), hipHostMallocDefault);
  for(int i = 0; i < num_streams; i++) {
  	hipHostAlloc((void **)&host_result[i], num_streams*sizeOfArray*sizeof(int), hipHostMallocDefault);
  }
  
	
	// Initiailize host memory
  for(int index = 0; index < sizeOfArray; index++) 
  { 
   host_a[index] = rand()%10; 
   host_b[index] = rand()%10; 
  } 
	
	//cudaEventRecord(start,0);
	elapsedTime0 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams,  sizeOfArray, 0, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime0, start, stop); 
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  
  //cudaEventRecord(start, 0);
	elapsedTime1 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams,  sizeOfArray, 1, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime1, start, stop);
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  
  
  //cudaEventRecord(start, 0);
	elapsedTime2 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams,  sizeOfArray, 2, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime2, start, stop);
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  
  
  //cudaEventRecord(start, 0);
	elapsedTime3 = testStream(device_a, device_b, device_result, host_a, host_b, host_result, streams, start, stop, num_streams, sizeOfArray, 3, gridSize, blockSize);
  //cudaEventRecord(stop, 0);
  //cudaEventSynchronize(stop);
  //cudaEventElapsedTime(&elapsedTime3, start, stop);
  verifyResult(host_a, host_b, host_result, num_streams, sizeOfArray);
  /*cudaStream_t stream; 
  cudaStreamCreate(&stream); */
 

  //printf("*********** CDAC - Tech Workshop : hyPACK-2013 \n"); 
  printf("\n Size of array : %d \n", sizeOfArray); 
  printf("\n Time taken for synchronous memcpy and synchronous kernel launch: %f ms \n", elapsedTime0); 
  printf("\n Time taken for asynchronous memcpy and synchronous kernel launch: %f ms \n", elapsedTime1); 
  printf("\n Time taken for synchronous memcpy and asynchronous kernel launch: %f ms \n", elapsedTime2); 
  printf("\n Time taken for asynchronous memcpy and asynchronous kernel launch: %f ms \n", elapsedTime3); 
	
	for(int i = 0; i < num_streams; i++) {
		hipStreamDestroy(streams[i]);	
	}
	hipEventDestroy(stop);
	hipEventDestroy(start);
  hipHostFree(host_a); 
  hipHostFree(host_b); 
  hipHostFree(host_result); 
  hipFree(device_a); 
  hipFree(device_b); 
  hipFree(device_result); 

  return 0; 
}

	.text
	.file	"stream_example.hip"
	.globl	_Z28__device_stub__arrayAdditionPiS_S_i # -- Begin function _Z28__device_stub__arrayAdditionPiS_S_i
	.type	_Z28__device_stub__arrayAdditionPiS_S_i,@function
_Z28__device_stub__arrayAdditionPiS_S_i: # @_Z28__device_stub__arrayAdditionPiS_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%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	$_Z13arrayAdditionPiS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z28__device_stub__arrayAdditionPiS_S_i, .Lfunc_end0-_Z28__device_stub__arrayAdditionPiS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z11getCUDAInfov                # -- Begin function _Z11getCUDAInfov
	.type	_Z11getCUDAInfov,@function
_Z11getCUDAInfov:                       # @_Z11getCUDAInfov
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 1536
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	12(%rsp), %rdi
	movl	$0, (%rdi)
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.1:                                # %_Z9checkCuda10hipError_tPKc.exit
	movl	12(%rsp), %esi
	testl	%esi, %esi
	je	.LBB1_2
# %bb.3:
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_4
.LBB1_2:
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB1_4:
	cmpl	$0, 12(%rsp)
	jle	.LBB1_7
# %bb.5:                                # %.lr.ph
	leaq	340(%rsp), %r14
	leaq	16(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB1_6:                                # =>This Inner Loop Header: Depth=1
	movl	%ebp, %edi
	callq	hipSetDevice
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movl	$.L.str.3, %edi
	movl	%ebp, %esi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	printf
	movq	304(%rsp), %rdx
	movq	%rdx, TOTAL_GLOBAL_MEM(%rip)
	movl	320(%rsp), %r8d
	movl	%r8d, REGS_PER_BLOCK(%rip)
	movl	324(%rsp), %r9d
	movl	%r9d, WARP_SIZE(%rip)
	movl	336(%rsp), %r10d
	movl	%r10d, MAX_THREADS_PER_BLOCK(%rip)
	movq	%r14, MAX_THREADS_DIM(%rip)
	movq	368(%rsp), %rcx
	movq	%rcx, TOTAL_CONST_MEM(%rip)
	movl	340(%rsp), %r11d
	movl	344(%rsp), %r15d
	movl	348(%rsp), %r12d
	movl	$.L.str.4, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	pushq	%r12
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	%r11
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	printf
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	incl	%ebp
	cmpl	12(%rsp), %ebp
	jl	.LBB1_6
.LBB1_7:                                # %._crit_edge
	addq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_8:
	.cfi_def_cfa_offset 1536
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %esi
	movl	$.L.str, %edx
	movq	%rbx, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z11getCUDAInfov, .Lfunc_end1-_Z11getCUDAInfov
	.cfi_endproc
                                        # -- End function
	.globl	_Z12verifyResultPiS_PS_ii       # -- Begin function _Z12verifyResultPiS_PS_ii
	.type	_Z12verifyResultPiS_PS_ii,@function
_Z12verifyResultPiS_PS_ii:              # @_Z12verifyResultPiS_PS_ii
	.cfi_startproc
# %bb.0:
	testl	%ecx, %ecx
	jle	.LBB2_9
# %bb.1:                                # %.preheader.lr.ph
	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	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %r12
	movl	%ecx, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%r8d, %ebp
	movb	$1, %al
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	xorl	%r13d, %r13d
	movl	%r8d, 12(%rsp)                  # 4-byte Spill
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%r8d, %r8d
	jle	.LBB2_7
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	xorl	%ebx, %ebx
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r12,%rbx,4), %r8d
	movl	(%r15,%rbx,4), %r9d
	leal	(%r9,%r8), %r10d
	movq	(%r14,%r13,8), %rax
	movl	(%rax,%rbx,4), %r11d
	cmpl	%r11d, %r10d
	je	.LBB2_6
# %bb.5:                                #   in Loop: Header=BB2_4 Depth=2
	movl	$0, 8(%rsp)                     # 4-byte Folded Spill
	movl	$.L.str.5, %edi
	xorl	%esi, %esi
	movl	%r13d, %edx
	movl	%ebx, %ecx
                                        # kill: def $r8d killed $r8d killed $r8
                                        # kill: def $r9d killed $r9d killed $r9
	xorl	%eax, %eax
	pushq	%r11
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	callq	printf
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB2_6:                                #   in Loop: Header=BB2_4 Depth=2
	incq	%rbx
	cmpq	%rbx, %rbp
	jne	.LBB2_4
.LBB2_7:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%r13
	cmpq	16(%rsp), %r13                  # 8-byte Folded Reload
	movl	12(%rsp), %r8d                  # 4-byte Reload
	jne	.LBB2_2
# %bb.8:                                # %._crit_edge34.loopexit
	movl	8(%rsp), %eax                   # 4-byte Reload
	andb	$1, %al
	addq	$24, %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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
                                        # kill: def $al killed $al killed $eax
	retq
.LBB2_9:
	movb	$1, %al
                                        # kill: def $al killed $al killed $eax
	retq
.Lfunc_end2:
	.size	_Z12verifyResultPiS_PS_ii, .Lfunc_end2-_Z12verifyResultPiS_PS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii # -- Begin function _Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	.type	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii,@function
_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii: # @_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	%r9, 24(%rsp)                   # 8-byte Spill
	movq	%r8, 32(%rsp)                   # 8-byte Spill
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	movq	%rdx, 80(%rsp)                  # 8-byte Spill
	movq	%rsi, 72(%rsp)                  # 8-byte Spill
	movq	%rdi, 64(%rsp)                  # 8-byte Spill
	movl	168(%rsp), %eax
	movl	$0, 52(%rsp)
	testl	%eax, %eax
	jle	.LBB3_30
# %bb.1:                                # %.lr.ph
	movl	200(%rsp), %ecx
	movslq	176(%rsp), %r14
	shlq	$2, %r14
	movslq	%ecx, %rcx
	leaq	(,%rcx,4), %rdx
	movq	%rdx, 16(%rsp)                  # 8-byte Spill
	movl	192(%rsp), %edx
	btsq	$32, %rdx
	movq	%rdx, 8(%rsp)                   # 8-byte Spill
	movl	%ecx, %ecx
	btsq	$32, %rcx
	movq	%rcx, (%rsp)                    # 8-byte Spill
	movl	%eax, %eax
	shlq	$3, %rax
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
.LBB3_2:                                # =>This Inner Loop Header: Depth=1
	movq	144(%rsp), %rax
	leaq	(%rax,%rbx), %rbp
	movq	%rbp, %rdi
	callq	hipStreamCreate
	testl	%eax, %eax
	jne	.LBB3_3
# %bb.5:                                # %_Z9checkCuda10hipError_tPKc.exit
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	64(%rsp), %rax                  # 8-byte Reload
	leaq	(%rax,%rbx), %r15
	movq	%r15, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	72(%rsp), %rax                  # 8-byte Reload
	leaq	(%rax,%rbx), %r13
	movq	%r13, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	80(%rsp), %rax                  # 8-byte Reload
	leaq	(%rax,%rbx), %r12
	movq	%r12, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	152(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	cmpl	$3, 184(%rsp)
	ja	.LBB3_29
# %bb.6:                                # %_Z9checkCuda10hipError_tPKc.exit
                                        #   in Loop: Header=BB3_2 Depth=1
	movl	184(%rsp), %eax
	jmpq	*.LJTI3_0(,%rax,8)
.LBB3_7:                                #   in Loop: Header=BB3_2 Depth=1
	movq	(%r15), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.9:                                # %_Z9checkCuda10hipError_tPKc.exit145
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%r13), %rdi
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.11:                               # %_Z9checkCuda10hipError_tPKc.exit147
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movl	$1, %esi
	movq	(%rsp), %rdx                    # 8-byte Reload
	movl	$1, %ecx
	movq	16(%rsp), %r8                   # 8-byte Reload
	xorl	%r9d, %r9d
	jmp	.LBB3_12
.LBB3_23:                               #   in Loop: Header=BB3_2 Depth=1
	movq	(%r15), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.24:                               # %_Z9checkCuda10hipError_tPKc.exit157
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%r13), %rdi
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.25:                               # %_Z9checkCuda10hipError_tPKc.exit159
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%rbp), %r9
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movl	$1, %esi
	movq	(%rsp), %rdx                    # 8-byte Reload
	movl	$1, %ecx
	movq	16(%rsp), %r8                   # 8-byte Reload
.LBB3_12:                               # %_Z9checkCuda10hipError_tPKc.exit147
                                        #   in Loop: Header=BB3_2 Depth=1
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_14
# %bb.13:                               #   in Loop: Header=BB3_2 Depth=1
	movq	(%r15), %rdi
	movq	(%r13), %rsi
	movq	(%r12), %rdx
	movl	176(%rsp), %ecx
	callq	_Z28__device_stub__arrayAdditionPiS_S_i
.LBB3_14:                               #   in Loop: Header=BB3_2 Depth=1
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	(%rax,%rbx), %rdi
	movq	(%r12), %rsi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	jmp	.LBB3_15
.LBB3_26:                               #   in Loop: Header=BB3_2 Depth=1
	movq	(%r15), %rdi
	movq	(%rbp), %r8
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.27:                               # %_Z9checkCuda10hipError_tPKc.exit163
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%r13), %rdi
	movq	(%rbp), %r8
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.28:                               # %_Z9checkCuda10hipError_tPKc.exit165
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%rbp), %r9
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movl	$1, %esi
	movq	(%rsp), %rdx                    # 8-byte Reload
	movl	$1, %ecx
	movq	16(%rsp), %r8                   # 8-byte Reload
	jmp	.LBB3_20
.LBB3_17:                               #   in Loop: Header=BB3_2 Depth=1
	movq	(%r15), %rdi
	movq	(%rbp), %r8
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.18:                               # %_Z9checkCuda10hipError_tPKc.exit151
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	(%r13), %rdi
	movq	(%rbp), %r8
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.19:                               # %_Z9checkCuda10hipError_tPKc.exit153
                                        #   in Loop: Header=BB3_2 Depth=1
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movl	$1, %esi
	movq	(%rsp), %rdx                    # 8-byte Reload
	movl	$1, %ecx
	movq	16(%rsp), %r8                   # 8-byte Reload
	xorl	%r9d, %r9d
.LBB3_20:                               # %_Z9checkCuda10hipError_tPKc.exit153
                                        #   in Loop: Header=BB3_2 Depth=1
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_22
# %bb.21:                               #   in Loop: Header=BB3_2 Depth=1
	movq	(%r15), %rdi
	movq	(%r13), %rsi
	movq	(%r12), %rdx
	movl	176(%rsp), %ecx
	callq	_Z28__device_stub__arrayAdditionPiS_S_i
.LBB3_22:                               #   in Loop: Header=BB3_2 Depth=1
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	(%rax,%rbx), %rdi
	movq	(%r12), %rsi
	movq	(%rbp), %r8
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
.LBB3_15:                               #   in Loop: Header=BB3_2 Depth=1
	testl	%eax, %eax
	jne	.LBB3_16
.LBB3_29:                               # %_Z9checkCuda10hipError_tPKc.exit149
                                        #   in Loop: Header=BB3_2 Depth=1
	addq	$8, %rbx
	cmpq	%rbx, 56(%rsp)                  # 8-byte Folded Reload
	jne	.LBB3_2
.LBB3_30:                               # %._crit_edge
	movq	160(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbx, %rdi
	callq	hipEventSynchronize
	leaq	52(%rsp), %r14
	movq	%r14, %rdi
	movq	152(%rsp), %rsi
	movq	%rbx, %rdx
	callq	hipEventElapsedTime
	movss	(%r14), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	addq	$88, %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_3:
	.cfi_def_cfa_offset 144
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %esi
	movl	$.L.str.6, %edx
	jmp	.LBB3_4
.LBB3_10:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %esi
	movl	$.L.str.8, %edx
	jmp	.LBB3_4
.LBB3_16:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %esi
	movl	$.L.str.9, %edx
	jmp	.LBB3_4
.LBB3_8:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %esi
	movl	$.L.str.7, %edx
.LBB3_4:
	movq	%rbx, %rdi
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii, .Lfunc_end3-_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI3_0:
	.quad	.LBB3_7
	.quad	.LBB3_17
	.quad	.LBB3_23
	.quad	.LBB3_26
                                        # -- End function
	.text
	.globl	main                            # -- Begin function 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	$456, %rsp                      # imm = 0x1C8
	.cfi_def_cfa_offset 512
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jne	.LBB4_1
# %bb.2:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %ebx
	jmp	.LBB4_3
.LBB4_1:
	movl	$512, %r14d                     # imm = 0x200
	movl	$1048576, %ebx                  # imm = 0x100000
.LBB4_3:
	callq	_Z11getCUDAInfov
	movl	%ebx, %eax
	cltd
	idivl	%r14d
	movl	%eax, %r15d
	cmpl	$1, %edx
	sbbl	$-1, %r15d
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movslq	%ebx, %rbp
	leaq	(,%rbp,4), %r12
	leaq	8(%rsp), %rdi
	xorl	%r13d, %r13d
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	movq	%rsp, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	addl	%ebp, %ebp
	leal	(%rbp,%rbp,4), %eax
	movslq	%eax, %r12
	shlq	$2, %r12
.LBB4_4:                                # =>This Inner Loop Header: Depth=1
	leaq	(%rsp,%r13), %rdi
	addq	$208, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	addq	$8, %r13
	cmpq	$80, %r13
	jne	.LBB4_4
# %bb.5:                                # %.preheader
	testl	%ebx, %ebx
	jle	.LBB4_6
# %bb.10:                               # %.lr.ph.preheader
	movl	%ebx, %r12d
	xorl	%r13d, %r13d
.LBB4_11:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movq	8(%rsp), %rcx
	movl	%eax, (%rcx,%r13,4)
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movq	(%rsp), %r8
	movl	%eax, (%r8,%r13,4)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB4_11
	jmp	.LBB4_7
.LBB4_6:                                # %.preheader.._crit_edge_crit_edge
	movq	(%rsp), %r8
.LBB4_7:                                # %._crit_edge
	movq	8(%rsp), %rcx
	movl	$10, %r10d
	leaq	288(%rsp), %r13
	leaq	128(%rsp), %rdi
	leaq	48(%rsp), %rsi
	leaq	368(%rsp), %rbp
	leaq	208(%rsp), %r12
	movq	%rbp, %rdx
	movq	%r12, %r9
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	%r13
	.cfi_adjust_cfa_offset 8
	callq	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	addq	$64, %rsp
	.cfi_adjust_cfa_offset -64
	movss	%xmm0, 44(%rsp)                 # 4-byte Spill
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	%r12, %rdx
	movl	$10, %ecx
	movl	%ebx, %r8d
	callq	_Z12verifyResultPiS_PS_ii
	movq	8(%rsp), %rcx
	movq	(%rsp), %r8
	leaq	128(%rsp), %rdi
	leaq	48(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r12, %r9
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	movl	$10, %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	%r13
	.cfi_adjust_cfa_offset 8
	callq	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	addq	$64, %rsp
	.cfi_adjust_cfa_offset -64
	movss	%xmm0, 40(%rsp)                 # 4-byte Spill
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	%r12, %rdx
	movl	$10, %ecx
	movl	%ebx, %r8d
	callq	_Z12verifyResultPiS_PS_ii
	movq	8(%rsp), %rcx
	movq	(%rsp), %r8
	leaq	128(%rsp), %rdi
	leaq	48(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r12, %r9
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	$2
	.cfi_adjust_cfa_offset 8
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	movl	$10, %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	%r13
	.cfi_adjust_cfa_offset 8
	callq	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	addq	$64, %rsp
	.cfi_adjust_cfa_offset -64
	movss	%xmm0, 36(%rsp)                 # 4-byte Spill
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	%r12, %rdx
	movl	$10, %ecx
	movl	%ebx, %r8d
	callq	_Z12verifyResultPiS_PS_ii
	movq	8(%rsp), %rcx
	movq	(%rsp), %r8
	leaq	128(%rsp), %rdi
	leaq	48(%rsp), %rsi
	movq	%rbp, %rdx
	movq	%r12, %r9
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	$3
	.cfi_adjust_cfa_offset 8
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	movl	$10, %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	%r13
	.cfi_adjust_cfa_offset 8
	callq	_Z10testStreamPPiS0_S0_S_S_S0_PP12ihipStream_tP11ihipEvent_tS5_iiiii
	addq	$64, %rsp
	.cfi_adjust_cfa_offset -64
	movss	%xmm0, 32(%rsp)                 # 4-byte Spill
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	%r12, %rdx
	movl	$10, %ecx
	movl	%ebx, %r8d
	callq	_Z12verifyResultPiS_PS_ii
	xorl	%r14d, %r14d
	movl	$.L.str.10, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	44(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	40(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	36(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$.L.str.13, %edi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	32(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$.L.str.14, %edi
	movb	$1, %al
	callq	printf
.LBB4_8:                                # =>This Inner Loop Header: Depth=1
	movq	288(%rsp,%r14,8), %rdi
	callq	hipStreamDestroy
	incq	%r14
	cmpq	$10, %r14
	jne	.LBB4_8
# %bb.9:
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	movq	8(%rsp), %rdi
	callq	hipHostFree
	movq	(%rsp), %rdi
	callq	hipHostFree
	leaq	208(%rsp), %rdi
	callq	hipHostFree
	leaq	128(%rsp), %rdi
	callq	hipFree
	leaq	48(%rsp), %rdi
	callq	hipFree
	leaq	368(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$456, %rsp                      # imm = 0x1C8
	.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_end4:
	.size	main, .Lfunc_end4-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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13arrayAdditionPiS_S_i, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	REGS_PER_BLOCK,@object          # @REGS_PER_BLOCK
	.bss
	.globl	REGS_PER_BLOCK
	.p2align	2, 0x0
REGS_PER_BLOCK:
	.long	0                               # 0x0
	.size	REGS_PER_BLOCK, 4

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

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

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

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

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

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Failed deviceCount load"
	.size	.L.str, 24

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Detected %d CUDA Capable device(s)\n"
	.size	.L.str.2, 36

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"\nDevice: %d \"%s\"\n===========================================\n"
	.size	.L.str.3, 62

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"The %s has:\n\t-%zu total bytes of global memory\n\t-%zu bytes of constant memory\n\t-%d registers per block\n\t-%d threads per warp\n\t-A maximum of %d threads per block\n\t-A maximum thread dimension of %d x %d x %d\n"
	.size	.L.str.4, 207

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Case %d Failed on Stream %d, iteration %d: %d + %d = Serial Result: %d ParallelResult: %d\n"
	.size	.L.str.5, 91

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipStreamCreate"
	.size	.L.str.6, 16

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"host to device async memcpy 1"
	.size	.L.str.7, 30

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"host to device async memcpy 2"
	.size	.L.str.8, 30

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"device to host async memcpy"
	.size	.L.str.9, 28

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"\n Size of array : %d \n"
	.size	.L.str.10, 23

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"\n Time taken for synchronous memcpy and synchronous kernel launch: %f ms \n"
	.size	.L.str.11, 75

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"\n Time taken for asynchronous memcpy and synchronous kernel launch: %f ms \n"
	.size	.L.str.12, 76

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"\n Time taken for synchronous memcpy and asynchronous kernel launch: %f ms \n"
	.size	.L.str.13, 76

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"\n Time taken for asynchronous memcpy and asynchronous kernel launch: %f ms \n"
	.size	.L.str.14, 77

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"CUDA Runtime Error From %s: %s\n"
	.size	.L.str.15, 32

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13arrayAdditionPiS_S_i"
	.size	.L__unnamed_1, 25

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"There are no available device(s) that support CUDA"
	.size	.Lstr, 51

	.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 _Z28__device_stub__arrayAdditionPiS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13arrayAdditionPiS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13arrayAdditionPiS_S_i ; -- Begin function _Z13arrayAdditionPiS_S_i
	.globl	_Z13arrayAdditionPiS_S_i
	.p2align	8
	.type	_Z13arrayAdditionPiS_S_i,@function
_Z13arrayAdditionPiS_S_i:               ; @_Z13arrayAdditionPiS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v1, vcc_lo
	v_add_co_u32 v4, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[4:5], off
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v2, v3, v2
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13arrayAdditionPiS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 6
		.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	_Z13arrayAdditionPiS_S_i, .Lfunc_end0-_Z13arrayAdditionPiS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 180
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
