// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#include <math.h>
#include <float.h>

#define CHUNK_SIZE 1024*1024
#define FULL_DATA_SIZE CHUNK_SIZE*200
#define THREAD_BLOCK_SIZE 1024


/* A simple kernel that performs some computation. In this case, the kernel computes the average of three 
	values in A and three values in B and stores this average in C */
__global__ void kernel(int *A, int *B, int *C, int num_elements)
{
    int idx = blockIdx.x*blockDim.x + threadIdx.x;
    int idx1, idx2;
    float avg1 = 0.0f;
    float avg2 = 0.0f; 

    if(idx < num_elements){
        for(int i = 0; i < 10000; i++){
            idx1 = (idx + 1) % THREAD_BLOCK_SIZE;
            idx2 = (idx + 2) % THREAD_BLOCK_SIZE;
            avg1 += (A[idx] + A[idx1] + A[idx2])/10000.0f;
            avg2 += (B[idx] + B[idx1] + B[idx2])/10000.0f;
        }
        C[idx] = (avg1 + avg2)/2;
    }
}

/* Time the execution using multiple, in this case two, CUDA streams. This implementation achieves the most overlap between 
   kernel execution and data transfer. */
float run_test_with_multiple_streams(void)
{
    /* Allocate pinned or page-locked memory on the host for the entire data set. 
       This is the memory used to stream chunks of the data set. */
    int *A, *B, *C;
    cudaHostAlloc((void **)&A, FULL_DATA_SIZE * sizeof(int), cudaHostAllocDefault);
    cudaHostAlloc((void **)&B, FULL_DATA_SIZE * sizeof(int), cudaHostAllocDefault);
    cudaHostAlloc((void **)&C, FULL_DATA_SIZE * sizeof(int), cudaHostAllocDefault);

    /* Fill arrays A and B with randomly generated integers. */
    for(int i = 0; i < FULL_DATA_SIZE; i++){
        A[i] = rand();
        B[i] = rand();
    }
	
    /* Create and initialize the streams. */
    cudaStream_t stream_0, stream_1;
    cudaStreamCreate(&stream_0);
    cudaStreamCreate(&stream_1); 
		  
    /* Allocate memory on the GPU for each stream. Note that we only need to allocate memory of 
       size CHUNK_SIZE for each stream. */
    int *A_on_device_0, *B_on_device_0, *C_on_device_0; // Space on GPU for stream 0
    cudaMalloc((void **)&A_on_device_0, CHUNK_SIZE * sizeof(int));
    cudaMalloc((void **)&B_on_device_0, CHUNK_SIZE * sizeof(int));
    cudaMalloc((void **)&C_on_device_0, CHUNK_SIZE * sizeof(int));

    int *A_on_device_1, *B_on_device_1, *C_on_device_1; // Space on GPU for stream 1
    cudaMalloc((void **)&A_on_device_1, CHUNK_SIZE * sizeof(int));
    cudaMalloc((void **)&B_on_device_1, CHUNK_SIZE * sizeof(int));
    cudaMalloc((void **)&C_on_device_1, CHUNK_SIZE * sizeof(int));

    /* Set up the execution grid for the kernel. */
    dim3 threads(THREAD_BLOCK_SIZE, 1, 1);
    dim3 grid(CHUNK_SIZE/THREAD_BLOCK_SIZE, 1);

    float elapsed_time;
    struct timeval start, stop;	
	gettimeofday(&start, NULL);

    /* Process the full data payload in chunks. */
    for(int i = 0; i < FULL_DATA_SIZE; i += 2*CHUNK_SIZE){
        /* Copy chunks of A and B from the pinned memory on the host to the device streams 0 and 1. */
        cudaMemcpyAsync(A_on_device_0, &A[i], CHUNK_SIZE * sizeof(int), cudaMemcpyHostToDevice, stream_0);
        cudaMemcpyAsync(A_on_device_1, &A[i + CHUNK_SIZE], CHUNK_SIZE * sizeof(int), cudaMemcpyHostToDevice, stream_1);
        cudaMemcpyAsync(B_on_device_0, &B[i], CHUNK_SIZE * sizeof(int), cudaMemcpyHostToDevice, stream_0);
        cudaMemcpyAsync(B_on_device_1, &B[i + CHUNK_SIZE], CHUNK_SIZE * sizeof(int), cudaMemcpyHostToDevice, stream_1);

        kernel<<<grid, threads, 0, stream_0>>>(A_on_device_0, B_on_device_0, C_on_device_0, CHUNK_SIZE);
        kernel<<<grid, threads, 0, stream_1>>>(A_on_device_1, B_on_device_1, C_on_device_1, CHUNK_SIZE);
					 
        cudaMemcpyAsync(&C[i], C_on_device_0, CHUNK_SIZE *sizeof(int), cudaMemcpyHostToDevice, stream_0);
        cudaMemcpyAsync(&C[i + CHUNK_SIZE], C_on_device_1, CHUNK_SIZE *sizeof(int), cudaMemcpyHostToDevice, stream_1);
		
    }
		  
    /* Synchronize the CUDA streams with the host. Host waits for the GPU to finish copying the 
       final chunk to the C array. */
    cudaStreamSynchronize(stream_0);
    cudaStreamSynchronize(stream_1);

    gettimeofday(&stop, NULL);
	elapsed_time = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000;

    cudaFreeHost(A);
    cudaFreeHost(B);
    cudaFreeHost(C);
    cudaFree(A_on_device_0); cudaFree(A_on_device_1); 
    cudaFree(B_on_device_0); cudaFree(B_on_device_1); 
    cudaFree(C_on_device_0); cudaFree(C_on_device_1); 
		  
		 
    /* Finally destroy the streams used to queue GPU operations. */
    cudaStreamDestroy(stream_0);
    cudaStreamDestroy(stream_1);

    return elapsed_time;
}

		  
/* Time the execution using a cuda stream. Here, the data is transferred in smaller chunks in streaming fashion to the GPU. 
   Streaming requires that pinned memory be allocated on the host side. */
float run_test_with_single_stream(void)
{
    /* Allocate pinned or page-locked memory on the host for the entire data set. This is the memory used to stream chunks of the data set. */
	
    int *A, *B, *C;
    cudaHostAlloc((void **)&A, FULL_DATA_SIZE * sizeof(int), cudaHostAllocDefault);
    cudaHostAlloc((void **)&B, FULL_DATA_SIZE * sizeof(int), cudaHostAllocDefault);
    cudaHostAlloc((void **)&C, FULL_DATA_SIZE * sizeof(int), cudaHostAllocDefault);

    /* Fill arrays A and B with randomly generated integers. */
    for(int i = 0; i < FULL_DATA_SIZE; i++){
        A[i] = rand();
        B[i] = rand();
    }
	
    float elapsed_time;
    struct timeval start, stop;	
	gettimeofday(&start, NULL);

    /* Allocate memory on the GPU. Note that we only need to allocate memory of size CHUNK_SIZE. */
    int *A_on_device, *B_on_device, *C_on_device;
    cudaMalloc((void **)&A_on_device, CHUNK_SIZE * sizeof(int));
    cudaMalloc((void **)&B_on_device, CHUNK_SIZE * sizeof(int));
    cudaMalloc((void **)&C_on_device, CHUNK_SIZE * sizeof(int));

    /* Create and initialize the CUDA stream. Set up the execution grid. */
    cudaStream_t stream;
    cudaStreamCreate(&stream);
	
    dim3 threads(THREAD_BLOCK_SIZE, 1, 1);
    dim3 grid(CHUNK_SIZE/THREAD_BLOCK_SIZE, 1);

    /* Process the full data payload in chunks. */
    for(int i = 0; i < FULL_DATA_SIZE; i += CHUNK_SIZE){
        /* Copy chunks of A and B from the pinned memory on the host to the device. This copy is done in asynchronous fashion. */
        cudaMemcpyAsync(A_on_device, &A[i], CHUNK_SIZE * sizeof(int), cudaMemcpyHostToDevice, stream);
        cudaMemcpyAsync(B_on_device, &B[i], CHUNK_SIZE * sizeof(int), cudaMemcpyHostToDevice, stream);
		
        kernel<<<grid, threads, 0, stream>>>(A_on_device, B_on_device, C_on_device, CHUNK_SIZE);
		
        cudaMemcpyAsync(&C[i], C_on_device, CHUNK_SIZE *sizeof(int), cudaMemcpyHostToDevice, stream);
    }
	
    /* Synchronize the CUDA stream with the host. Host waits for the GPU to finish copying the final chunk to the C array. */
    cudaStreamSynchronize(stream);

    gettimeofday(&stop, NULL);
	elapsed_time = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000;
    
   /* Clean up. */
    cudaFreeHost(A);
    cudaFreeHost(B);
    cudaFreeHost(C);
    cudaFree(A_on_device);
    cudaFree(B_on_device);
    cudaFree(C_on_device);
	
    /* Finally destroy the stream used to queue GPU operations. */
    cudaStreamDestroy(stream);
	
    return elapsed_time;
}

/* Time the execution using the cudaMalloc calls. Here the entire data set is transferred to the GPU prior to invoking the kernel. */
float run_test_with_cuda_malloc(void)
{
    /* Allocate memory on the host for the A, B, and C arrays. */
    int *A, *B, *C;
    A = (int *)malloc(FULL_DATA_SIZE * sizeof(int));
    B = (int *)malloc(FULL_DATA_SIZE * sizeof(int));
    C = (int *)malloc(FULL_DATA_SIZE * sizeof(int));

    /* Fill arrays A and B with randomly generated integers. */
    for(int i = 0; i < FULL_DATA_SIZE; i++){
        A[i] = rand();
        B[i] = rand();
    }

    float elapsed_time;
    struct timeval start, stop;	
	gettimeofday(&start, NULL);


    /* Allocate memory on the GPU for arrays A, B, and C, and transfer over A and B.	*/
    int *A_on_device, *B_on_device, *C_on_device;

    cudaMalloc((void **)&A_on_device, FULL_DATA_SIZE * sizeof(int));
    cudaMemcpy(A_on_device, A, FULL_DATA_SIZE * sizeof(int), cudaMemcpyHostToDevice);

    cudaMalloc((void **)&B_on_device, FULL_DATA_SIZE * sizeof(int));
    cudaMemcpy(B_on_device, B, FULL_DATA_SIZE * sizeof(int), cudaMemcpyHostToDevice);

    cudaMalloc((void **)&C_on_device, FULL_DATA_SIZE * sizeof(int));

    /* Set up execution grid. */
    dim3 grid(FULL_DATA_SIZE/THREAD_BLOCK_SIZE, 1);
    dim3 threads(THREAD_BLOCK_SIZE, 1, 1);

    kernel<<<grid, threads>>>(A_on_device, B_on_device, C_on_device, FULL_DATA_SIZE);

    cudaMemcpy(C, C_on_device, FULL_DATA_SIZE * sizeof(int), cudaMemcpyDeviceToHost);

    gettimeofday(&stop, NULL);
	elapsed_time = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000;

    /* Clean up. */
    free(A);
    free(B);
    free(C);
    cudaFree(A_on_device);
    cudaFree(B_on_device);
    cudaFree(C_on_device);
	
    return elapsed_time;
}

int main(void)
{
    /* Check the device properties if our device supports mapping host memory */
    cudaDeviceProp properties;
    int my_device;
    cudaGetDevice(&my_device);
    cudaGetDeviceProperties(&properties, my_device);
    if(properties.canMapHostMemory != 1){
        printf("The device cannot map host memory. \n");
        exit(0);
    }

    /* Check to see if the device supports overlaps, that is, if it can simultaneously execute a CUDA kernel while performing 
       a copy between the device and host memory. */
    if(properties.deviceOverlap != 1){
        printf("The device does not support overlaps. \n");
        exit(0);
    }
    /* Place the CUDA runtime in a state which supports mapping memory on the host. */ 
    cudaSetDeviceFlags(cudaDeviceMapHost);

    float elapsed_time;
		  
    elapsed_time = run_test_with_cuda_malloc();
    printf("Elapsed time using cudaMalloc: %3.1f s \n", elapsed_time);

    elapsed_time = run_test_with_single_stream();
    printf("Elapsed time using a single stream: %3.1f s \n", elapsed_time);

    elapsed_time = run_test_with_multiple_streams();
    printf("Elapsed time using multiple streams: %3.1f s \n", elapsed_time);

    exit(0);

}


	.file	"tmpxft_002e3360_00000000-6_cuda_streams.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
	.type	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i, @function
_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i:
.LFB2055:
	.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	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6kernelPiS_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
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i, .-_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
	.globl	_Z6kernelPiS_S_i
	.type	_Z6kernelPiS_S_i, @function
_Z6kernelPiS_S_i:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
	.cfi_endproc
.LFE2056:
	.size	_Z6kernelPiS_S_i, .-_Z6kernelPiS_S_i
	.globl	_Z30run_test_with_multiple_streamsv
	.type	_Z30run_test_with_multiple_streamsv, @function
_Z30run_test_with_multiple_streamsv:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%edx, %edx
	movl	$838860800, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	xorl	%ebx, %ebx
	subq	$184, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	call	cudaHostAlloc@PLT
	leaq	32(%rsp), %rdi
	xorl	%edx, %edx
	movl	$838860800, %esi
	call	cudaHostAlloc@PLT
	leaq	40(%rsp), %rdi
	xorl	%edx, %edx
	movl	$838860800, %esi
	call	cudaHostAlloc@PLT
.L9:
	movq	24(%rsp), %rbp
	call	rand@PLT
	addq	%rbx, %rbp
	movl	%eax, 0(%rbp)
	movq	32(%rsp), %rbp
	addq	%rbx, %rbp
	addq	$4, %rbx
	call	rand@PLT
	movl	%eax, 0(%rbp)
	cmpq	$838860800, %rbx
	jne	.L9
	leaq	48(%rsp), %rdi
	xorl	%ebx, %ebx
	call	cudaStreamCreate@PLT
	leaq	56(%rsp), %rdi
	call	cudaStreamCreate@PLT
	leaq	64(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	72(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	80(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	88(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	96(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	104(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	movl	$4194305, %eax
	xorl	%esi, %esi
	leaq	136(%rsp), %rdi
	salq	$10, %rax
	movl	$1, 120(%rsp)
	movq	%rax, 112(%rsp)
	movq	%rax, 124(%rsp)
	movl	$1, 132(%rsp)
	call	gettimeofday@PLT
.L12:
	movq	24(%rsp), %rsi
	movq	48(%rsp), %r8
	movl	$1, %ecx
	movl	$4194304, %edx
	movq	64(%rsp), %rdi
	leaq	4194304(%rbx), %rbp
	addq	%rbx, %rsi
	call	cudaMemcpyAsync@PLT
	movq	24(%rsp), %rsi
	movq	56(%rsp), %r8
	movl	$1, %ecx
	movq	88(%rsp), %rdi
	movl	$4194304, %edx
	addq	%rbp, %rsi
	call	cudaMemcpyAsync@PLT
	movq	32(%rsp), %rsi
	movq	48(%rsp), %r8
	movl	$1, %ecx
	movq	72(%rsp), %rdi
	movl	$4194304, %edx
	addq	%rbx, %rsi
	call	cudaMemcpyAsync@PLT
	movq	32(%rsp), %rsi
	movq	56(%rsp), %r8
	movl	$1, %ecx
	movq	96(%rsp), %rdi
	movl	$4194304, %edx
	addq	%rbp, %rsi
	call	cudaMemcpyAsync@PLT
	movl	120(%rsp), %ecx
	movq	48(%rsp), %r9
	xorl	%r8d, %r8d
	movq	112(%rsp), %rdx
	movq	124(%rsp), %rdi
	movl	132(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L10
	movq	80(%rsp), %rdx
	movq	72(%rsp), %rsi
	movl	$1048576, %ecx
	movq	64(%rsp), %rdi
	call	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
.L10:
	movl	120(%rsp), %ecx
	movq	56(%rsp), %r9
	xorl	%r8d, %r8d
	movq	112(%rsp), %rdx
	movq	124(%rsp), %rdi
	movl	132(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	movq	104(%rsp), %rdx
	movq	96(%rsp), %rsi
	movl	$1048576, %ecx
	movq	88(%rsp), %rdi
	call	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
.L11:
	movq	40(%rsp), %rdi
	movq	48(%rsp), %r8
	movl	$1, %ecx
	movl	$4194304, %edx
	movq	80(%rsp), %rsi
	addq	%rbx, %rdi
	addq	$8388608, %rbx
	call	cudaMemcpyAsync@PLT
	movq	40(%rsp), %rdi
	movq	56(%rsp), %r8
	movl	$1, %ecx
	movq	104(%rsp), %rsi
	movl	$4194304, %edx
	addq	%rbp, %rdi
	call	cudaMemcpyAsync@PLT
	cmpq	$838860800, %rbx
	jne	.L12
	movq	48(%rsp), %rdi
	call	cudaStreamSynchronize@PLT
	movq	56(%rsp), %rdi
	call	cudaStreamSynchronize@PLT
	xorl	%esi, %esi
	leaq	152(%rsp), %rdi
	call	gettimeofday@PLT
	movq	160(%rsp), %rax
	movq	24(%rsp), %rdi
	subq	144(%rsp), %rax
	cvtsi2ssq	%rax, %xmm0
	movq	152(%rsp), %rax
	subq	136(%rsp), %rax
	divss	.LC0(%rip), %xmm0
	cvtsi2ssq	%rax, %xmm1
	addss	%xmm1, %xmm0
	movss	%xmm0, 12(%rsp)
	call	cudaFreeHost@PLT
	movq	32(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaStreamDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaStreamDestroy@PLT
	movss	12(%rsp), %xmm0
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	addq	$184, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z30run_test_with_multiple_streamsv, .-_Z30run_test_with_multiple_streamsv
	.globl	_Z27run_test_with_single_streamv
	.type	_Z27run_test_with_single_streamv, @function
_Z27run_test_with_single_streamv:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%edx, %edx
	movl	$838860800, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	xorl	%ebx, %ebx
	subq	$152, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	call	cudaHostAlloc@PLT
	leaq	32(%rsp), %rdi
	xorl	%edx, %edx
	movl	$838860800, %esi
	call	cudaHostAlloc@PLT
	leaq	40(%rsp), %rdi
	xorl	%edx, %edx
	movl	$838860800, %esi
	call	cudaHostAlloc@PLT
.L18:
	movq	24(%rsp), %rbp
	call	rand@PLT
	addq	%rbx, %rbp
	movl	%eax, 0(%rbp)
	movq	32(%rsp), %rbp
	addq	%rbx, %rbp
	addq	$4, %rbx
	call	rand@PLT
	movl	%eax, 0(%rbp)
	cmpq	$838860800, %rbx
	jne	.L18
	leaq	104(%rsp), %rdi
	xorl	%esi, %esi
	xorl	%ebx, %ebx
	call	gettimeofday@PLT
	leaq	48(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	64(%rsp), %rdi
	movl	$4194304, %esi
	call	cudaMalloc@PLT
	leaq	72(%rsp), %rdi
	call	cudaStreamCreate@PLT
	movl	$4194305, %eax
	movl	$1, 88(%rsp)
	salq	$10, %rax
	movl	$1, 100(%rsp)
	movq	%rax, 80(%rsp)
	movq	%rax, 92(%rsp)
.L20:
	movq	24(%rsp), %rsi
	movq	72(%rsp), %r8
	movl	$1, %ecx
	movl	$4194304, %edx
	movq	48(%rsp), %rdi
	addq	%rbx, %rsi
	call	cudaMemcpyAsync@PLT
	movq	32(%rsp), %rsi
	movq	72(%rsp), %r8
	movl	$1, %ecx
	movq	56(%rsp), %rdi
	movl	$4194304, %edx
	addq	%rbx, %rsi
	call	cudaMemcpyAsync@PLT
	movl	88(%rsp), %ecx
	movl	100(%rsp), %esi
	xorl	%r8d, %r8d
	movq	72(%rsp), %r9
	movq	80(%rsp), %rdx
	movq	92(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	movl	$1048576, %ecx
	movq	48(%rsp), %rdi
	call	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
.L19:
	movq	40(%rsp), %rdi
	movq	72(%rsp), %r8
	movl	$1, %ecx
	movl	$4194304, %edx
	movq	64(%rsp), %rsi
	addq	%rbx, %rdi
	addq	$4194304, %rbx
	call	cudaMemcpyAsync@PLT
	cmpq	$838860800, %rbx
	jne	.L20
	movq	72(%rsp), %rdi
	call	cudaStreamSynchronize@PLT
	xorl	%esi, %esi
	leaq	120(%rsp), %rdi
	call	gettimeofday@PLT
	movq	128(%rsp), %rax
	subq	112(%rsp), %rax
	cvtsi2ssq	%rax, %xmm0
	movq	120(%rsp), %rax
	subq	104(%rsp), %rax
	divss	.LC0(%rip), %xmm0
	cvtsi2ssq	%rax, %xmm1
	movq	24(%rsp), %rdi
	addss	%xmm1, %xmm0
	movss	%xmm0, 12(%rsp)
	call	cudaFreeHost@PLT
	movq	32(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	40(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaStreamDestroy@PLT
	movss	12(%rsp), %xmm0
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$152, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z27run_test_with_single_streamv, .-_Z27run_test_with_single_streamv
	.globl	_Z25run_test_with_cuda_mallocv
	.type	_Z25run_test_with_cuda_mallocv, @function
_Z25run_test_with_cuda_mallocv:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$838860800, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$120, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$838860800, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$838860800, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movq	%rax, %r13
.L26:
	call	rand@PLT
	movl	%eax, 0(%rbp,%r12)
	call	rand@PLT
	movl	%eax, (%rbx,%r12)
	addq	$4, %r12
	cmpq	$838860800, %r12
	jne	.L26
	xorl	%esi, %esi
	leaq	72(%rsp), %rdi
	call	gettimeofday@PLT
	leaq	24(%rsp), %rdi
	movl	$838860800, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$838860800, %edx
	call	cudaMemcpy@PLT
	leaq	32(%rsp), %rdi
	movl	$838860800, %esi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$838860800, %edx
	call	cudaMemcpy@PLT
	leaq	40(%rsp), %rdi
	movl	$838860800, %esi
	call	cudaMalloc@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$524313, %edi
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$13, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$209715200, %ecx
	movq	24(%rsp), %rdi
	call	_Z30__device_stub__Z6kernelPiS_S_iPiS_S_i
.L27:
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movl	$838860800, %edx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	xorl	%esi, %esi
	leaq	88(%rsp), %rdi
	call	gettimeofday@PLT
	movq	96(%rsp), %rax
	subq	80(%rsp), %rax
	movq	%rbp, %rdi
	cvtsi2ssq	%rax, %xmm0
	movq	88(%rsp), %rax
	subq	72(%rsp), %rax
	divss	.LC0(%rip), %xmm0
	cvtsi2ssq	%rax, %xmm1
	addss	%xmm1, %xmm0
	movss	%xmm0, 12(%rsp)
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movss	12(%rsp), %xmm0
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$120, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z25run_test_with_cuda_mallocv, .-_Z25run_test_with_cuda_mallocv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"The device cannot map host memory. \n"
.LC2:
	.string	"The device does not support overlaps. \n"
.LC3:
	.string	"Elapsed time using cudaMalloc: %3.1f s \n"
.LC4:
	.string	"Elapsed time using a single stream: %3.1f s \n"
.LC5:
	.string	"Elapsed time using multiple streams: %3.1f s \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$1064, %rsp
	.cfi_def_cfa_offset 1072
	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
	cmpl	$1, 416(%rsp)
	leaq	.LC1(%rip), %rsi
	jne	.L36
	cmpl	$1, 400(%rsp)
	je	.L33
	leaq	.LC2(%rip), %rsi
.L36:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L37:
	xorl	%edi, %edi
	call	exit@PLT
.L33:
	movl	$8, %edi
	call	cudaSetDeviceFlags@PLT
	call	_Z25run_test_with_cuda_mallocv
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	call	_Z27run_test_with_single_streamv
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	call	_Z30run_test_with_multiple_streamsv
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	jmp	.L37
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC6:
	.string	"_Z6kernelPiS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC6(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6kernelPiS_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
.LFE2058:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1232348160
	.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:

// includes, system

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

#define CHUNK_SIZE 1024*1024
#define FULL_DATA_SIZE CHUNK_SIZE*200
#define THREAD_BLOCK_SIZE 1024


/* A simple kernel that performs some computation. In this case, the kernel computes the average of three 
	values in A and three values in B and stores this average in C */
__global__ void kernel(int *A, int *B, int *C, int num_elements)
{
    int idx = blockIdx.x*blockDim.x + threadIdx.x;
    int idx1, idx2;
    float avg1 = 0.0f;
    float avg2 = 0.0f; 

    if(idx < num_elements){
        for(int i = 0; i < 10000; i++){
            idx1 = (idx + 1) % THREAD_BLOCK_SIZE;
            idx2 = (idx + 2) % THREAD_BLOCK_SIZE;
            avg1 += (A[idx] + A[idx1] + A[idx2])/10000.0f;
            avg2 += (B[idx] + B[idx1] + B[idx2])/10000.0f;
        }
        C[idx] = (avg1 + avg2)/2;
    }
}

/* Time the execution using multiple, in this case two, CUDA streams. This implementation achieves the most overlap between 
   kernel execution and data transfer. */
float run_test_with_multiple_streams(void)
{
    /* Allocate pinned or page-locked memory on the host for the entire data set. 
       This is the memory used to stream chunks of the data set. */
    int *A, *B, *C;
    hipHostAlloc((void **)&A, FULL_DATA_SIZE * sizeof(int), hipHostMallocDefault);
    hipHostAlloc((void **)&B, FULL_DATA_SIZE * sizeof(int), hipHostMallocDefault);
    hipHostAlloc((void **)&C, FULL_DATA_SIZE * sizeof(int), hipHostMallocDefault);

    /* Fill arrays A and B with randomly generated integers. */
    for(int i = 0; i < FULL_DATA_SIZE; i++){
        A[i] = rand();
        B[i] = rand();
    }
	
    /* Create and initialize the streams. */
    hipStream_t stream_0, stream_1;
    hipStreamCreate(&stream_0);
    hipStreamCreate(&stream_1); 
		  
    /* Allocate memory on the GPU for each stream. Note that we only need to allocate memory of 
       size CHUNK_SIZE for each stream. */
    int *A_on_device_0, *B_on_device_0, *C_on_device_0; // Space on GPU for stream 0
    hipMalloc((void **)&A_on_device_0, CHUNK_SIZE * sizeof(int));
    hipMalloc((void **)&B_on_device_0, CHUNK_SIZE * sizeof(int));
    hipMalloc((void **)&C_on_device_0, CHUNK_SIZE * sizeof(int));

    int *A_on_device_1, *B_on_device_1, *C_on_device_1; // Space on GPU for stream 1
    hipMalloc((void **)&A_on_device_1, CHUNK_SIZE * sizeof(int));
    hipMalloc((void **)&B_on_device_1, CHUNK_SIZE * sizeof(int));
    hipMalloc((void **)&C_on_device_1, CHUNK_SIZE * sizeof(int));

    /* Set up the execution grid for the kernel. */
    dim3 threads(THREAD_BLOCK_SIZE, 1, 1);
    dim3 grid(CHUNK_SIZE/THREAD_BLOCK_SIZE, 1);

    float elapsed_time;
    struct timeval start, stop;	
	gettimeofday(&start, NULL);

    /* Process the full data payload in chunks. */
    for(int i = 0; i < FULL_DATA_SIZE; i += 2*CHUNK_SIZE){
        /* Copy chunks of A and B from the pinned memory on the host to the device streams 0 and 1. */
        hipMemcpyAsync(A_on_device_0, &A[i], CHUNK_SIZE * sizeof(int), hipMemcpyHostToDevice, stream_0);
        hipMemcpyAsync(A_on_device_1, &A[i + CHUNK_SIZE], CHUNK_SIZE * sizeof(int), hipMemcpyHostToDevice, stream_1);
        hipMemcpyAsync(B_on_device_0, &B[i], CHUNK_SIZE * sizeof(int), hipMemcpyHostToDevice, stream_0);
        hipMemcpyAsync(B_on_device_1, &B[i + CHUNK_SIZE], CHUNK_SIZE * sizeof(int), hipMemcpyHostToDevice, stream_1);

        kernel<<<grid, threads, 0, stream_0>>>(A_on_device_0, B_on_device_0, C_on_device_0, CHUNK_SIZE);
        kernel<<<grid, threads, 0, stream_1>>>(A_on_device_1, B_on_device_1, C_on_device_1, CHUNK_SIZE);
					 
        hipMemcpyAsync(&C[i], C_on_device_0, CHUNK_SIZE *sizeof(int), hipMemcpyHostToDevice, stream_0);
        hipMemcpyAsync(&C[i + CHUNK_SIZE], C_on_device_1, CHUNK_SIZE *sizeof(int), hipMemcpyHostToDevice, stream_1);
		
    }
		  
    /* Synchronize the CUDA streams with the host. Host waits for the GPU to finish copying the 
       final chunk to the C array. */
    hipStreamSynchronize(stream_0);
    hipStreamSynchronize(stream_1);

    gettimeofday(&stop, NULL);
	elapsed_time = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000;

    hipHostFree(A);
    hipHostFree(B);
    hipHostFree(C);
    hipFree(A_on_device_0); hipFree(A_on_device_1); 
    hipFree(B_on_device_0); hipFree(B_on_device_1); 
    hipFree(C_on_device_0); hipFree(C_on_device_1); 
		  
		 
    /* Finally destroy the streams used to queue GPU operations. */
    hipStreamDestroy(stream_0);
    hipStreamDestroy(stream_1);

    return elapsed_time;
}

		  
/* Time the execution using a cuda stream. Here, the data is transferred in smaller chunks in streaming fashion to the GPU. 
   Streaming requires that pinned memory be allocated on the host side. */
float run_test_with_single_stream(void)
{
    /* Allocate pinned or page-locked memory on the host for the entire data set. This is the memory used to stream chunks of the data set. */
	
    int *A, *B, *C;
    hipHostAlloc((void **)&A, FULL_DATA_SIZE * sizeof(int), hipHostMallocDefault);
    hipHostAlloc((void **)&B, FULL_DATA_SIZE * sizeof(int), hipHostMallocDefault);
    hipHostAlloc((void **)&C, FULL_DATA_SIZE * sizeof(int), hipHostMallocDefault);

    /* Fill arrays A and B with randomly generated integers. */
    for(int i = 0; i < FULL_DATA_SIZE; i++){
        A[i] = rand();
        B[i] = rand();
    }
	
    float elapsed_time;
    struct timeval start, stop;	
	gettimeofday(&start, NULL);

    /* Allocate memory on the GPU. Note that we only need to allocate memory of size CHUNK_SIZE. */
    int *A_on_device, *B_on_device, *C_on_device;
    hipMalloc((void **)&A_on_device, CHUNK_SIZE * sizeof(int));
    hipMalloc((void **)&B_on_device, CHUNK_SIZE * sizeof(int));
    hipMalloc((void **)&C_on_device, CHUNK_SIZE * sizeof(int));

    /* Create and initialize the CUDA stream. Set up the execution grid. */
    hipStream_t stream;
    hipStreamCreate(&stream);
	
    dim3 threads(THREAD_BLOCK_SIZE, 1, 1);
    dim3 grid(CHUNK_SIZE/THREAD_BLOCK_SIZE, 1);

    /* Process the full data payload in chunks. */
    for(int i = 0; i < FULL_DATA_SIZE; i += CHUNK_SIZE){
        /* Copy chunks of A and B from the pinned memory on the host to the device. This copy is done in asynchronous fashion. */
        hipMemcpyAsync(A_on_device, &A[i], CHUNK_SIZE * sizeof(int), hipMemcpyHostToDevice, stream);
        hipMemcpyAsync(B_on_device, &B[i], CHUNK_SIZE * sizeof(int), hipMemcpyHostToDevice, stream);
		
        kernel<<<grid, threads, 0, stream>>>(A_on_device, B_on_device, C_on_device, CHUNK_SIZE);
		
        hipMemcpyAsync(&C[i], C_on_device, CHUNK_SIZE *sizeof(int), hipMemcpyHostToDevice, stream);
    }
	
    /* Synchronize the CUDA stream with the host. Host waits for the GPU to finish copying the final chunk to the C array. */
    hipStreamSynchronize(stream);

    gettimeofday(&stop, NULL);
	elapsed_time = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000;
    
   /* Clean up. */
    hipHostFree(A);
    hipHostFree(B);
    hipHostFree(C);
    hipFree(A_on_device);
    hipFree(B_on_device);
    hipFree(C_on_device);
	
    /* Finally destroy the stream used to queue GPU operations. */
    hipStreamDestroy(stream);
	
    return elapsed_time;
}

/* Time the execution using the cudaMalloc calls. Here the entire data set is transferred to the GPU prior to invoking the kernel. */
float run_test_with_cuda_malloc(void)
{
    /* Allocate memory on the host for the A, B, and C arrays. */
    int *A, *B, *C;
    A = (int *)malloc(FULL_DATA_SIZE * sizeof(int));
    B = (int *)malloc(FULL_DATA_SIZE * sizeof(int));
    C = (int *)malloc(FULL_DATA_SIZE * sizeof(int));

    /* Fill arrays A and B with randomly generated integers. */
    for(int i = 0; i < FULL_DATA_SIZE; i++){
        A[i] = rand();
        B[i] = rand();
    }

    float elapsed_time;
    struct timeval start, stop;	
	gettimeofday(&start, NULL);


    /* Allocate memory on the GPU for arrays A, B, and C, and transfer over A and B.	*/
    int *A_on_device, *B_on_device, *C_on_device;

    hipMalloc((void **)&A_on_device, FULL_DATA_SIZE * sizeof(int));
    hipMemcpy(A_on_device, A, FULL_DATA_SIZE * sizeof(int), hipMemcpyHostToDevice);

    hipMalloc((void **)&B_on_device, FULL_DATA_SIZE * sizeof(int));
    hipMemcpy(B_on_device, B, FULL_DATA_SIZE * sizeof(int), hipMemcpyHostToDevice);

    hipMalloc((void **)&C_on_device, FULL_DATA_SIZE * sizeof(int));

    /* Set up execution grid. */
    dim3 grid(FULL_DATA_SIZE/THREAD_BLOCK_SIZE, 1);
    dim3 threads(THREAD_BLOCK_SIZE, 1, 1);

    kernel<<<grid, threads>>>(A_on_device, B_on_device, C_on_device, FULL_DATA_SIZE);

    hipMemcpy(C, C_on_device, FULL_DATA_SIZE * sizeof(int), hipMemcpyDeviceToHost);

    gettimeofday(&stop, NULL);
	elapsed_time = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000;

    /* Clean up. */
    free(A);
    free(B);
    free(C);
    hipFree(A_on_device);
    hipFree(B_on_device);
    hipFree(C_on_device);
	
    return elapsed_time;
}

int main(void)
{
    /* Check the device properties if our device supports mapping host memory */
    hipDeviceProp_t properties;
    int my_device;
    hipGetDevice(&my_device);
    hipGetDeviceProperties(&properties, my_device);
    if(properties.canMapHostMemory != 1){
        printf("The device cannot map host memory. \n");
        exit(0);
    }

    /* Check to see if the device supports overlaps, that is, if it can simultaneously execute a CUDA kernel while performing 
       a copy between the device and host memory. */
    if(properties.deviceOverlap != 1){
        printf("The device does not support overlaps. \n");
        exit(0);
    }
    /* Place the CUDA runtime in a state which supports mapping memory on the host. */ 
    hipSetDeviceFlags(hipDeviceMapHost);

    float elapsed_time;
		  
    elapsed_time = run_test_with_cuda_malloc();
    printf("Elapsed time using cudaMalloc: %3.1f s \n", elapsed_time);

    elapsed_time = run_test_with_single_stream();
    printf("Elapsed time using a single stream: %3.1f s \n", elapsed_time);

    elapsed_time = run_test_with_multiple_streams();
    printf("Elapsed time using multiple streams: %3.1f s \n", elapsed_time);

    exit(0);

}


	.text
	.file	"cuda_streams.hip"
	.globl	_Z21__device_stub__kernelPiS_S_i # -- Begin function _Z21__device_stub__kernelPiS_S_i
	.type	_Z21__device_stub__kernelPiS_S_i,@function
_Z21__device_stub__kernelPiS_S_i:       # @_Z21__device_stub__kernelPiS_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	$_Z6kernelPiS_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	_Z21__device_stub__kernelPiS_S_i, .Lfunc_end0-_Z21__device_stub__kernelPiS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z30run_test_with_multiple_streamsv
.LCPI1_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z30run_test_with_multiple_streamsv
	.type	_Z30run_test_with_multiple_streamsv,@function
_Z30run_test_with_multiple_streamsv:    # @_Z30run_test_with_multiple_streamsv
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$136, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	32(%rsp), %rdi
	xorl	%ebx, %ebx
	movl	$838860800, %esi                # imm = 0x32000000
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	24(%rsp), %rdi
	movl	$838860800, %esi                # imm = 0x32000000
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	88(%rsp), %rdi
	movl	$838860800, %esi                # imm = 0x32000000
	xorl	%edx, %edx
	callq	hipHostAlloc
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	movq	32(%rsp), %rcx
	movl	%eax, (%rcx,%rbx,4)
	callq	rand
	movq	24(%rsp), %rcx
	movl	%eax, (%rcx,%rbx,4)
	incq	%rbx
	cmpq	$209715200, %rbx                # imm = 0xC800000
	jne	.LBB1_1
# %bb.2:
	movabsq	$4294968320, %rbx               # imm = 0x100000400
	leaq	16(%rsp), %rdi
	callq	hipStreamCreate
	leaq	8(%rsp), %rdi
	callq	hipStreamCreate
	leaq	80(%rsp), %rdi
	movl	$4194304, %r14d                 # imm = 0x400000
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	72(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	64(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	56(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	xorl	%r15d, %r15d
	leaq	104(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	$-2097152, %r12                 # imm = 0xFFE00000
.LBB1_3:                                # =>This Inner Loop Header: Depth=1
	movq	80(%rsp), %rdi
	movq	32(%rsp), %rsi
	addq	%r15, %rsi
	movq	16(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	56(%rsp), %rdi
	movq	32(%rsp), %rsi
	addq	%r15, %rsi
	addq	%r14, %rsi
	movq	8(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	72(%rsp), %rdi
	movq	24(%rsp), %rsi
	addq	%r15, %rsi
	movq	16(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	48(%rsp), %rdi
	movq	24(%rsp), %rsi
	addq	%r15, %rsi
	addq	%r14, %rsi
	movq	8(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	16(%rsp), %r9
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_5
# %bb.4:                                #   in Loop: Header=BB1_3 Depth=1
	movq	80(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdx
	movl	$1048576, %ecx                  # imm = 0x100000
	callq	_Z21__device_stub__kernelPiS_S_i
.LBB1_5:                                #   in Loop: Header=BB1_3 Depth=1
	movq	8(%rsp), %r9
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_7
# %bb.6:                                #   in Loop: Header=BB1_3 Depth=1
	movq	56(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	movl	$1048576, %ecx                  # imm = 0x100000
	callq	_Z21__device_stub__kernelPiS_S_i
.LBB1_7:                                #   in Loop: Header=BB1_3 Depth=1
	movq	88(%rsp), %rdi
	addq	%r15, %rdi
	movq	64(%rsp), %rsi
	movq	16(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	88(%rsp), %rax
	leaq	(%rax,%r15), %rdi
	addq	$4194304, %rdi                  # imm = 0x400000
	movq	40(%rsp), %rsi
	movq	8(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	addq	$2097152, %r12                  # imm = 0x200000
	addq	$8388608, %r15                  # imm = 0x800000
	cmpq	$207618048, %r12                # imm = 0xC600000
	jb	.LBB1_3
# %bb.8:
	movq	16(%rsp), %rdi
	callq	hipStreamSynchronize
	movq	8(%rsp), %rdi
	callq	hipStreamSynchronize
	leaq	120(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	subq	104(%rsp), %rax
	cvtsi2ss	%rax, %xmm0
	movq	8(%rbx), %rax
	subq	112(%rsp), %rax
	cvtsi2ss	%rax, %xmm1
	divss	.LCPI1_0(%rip), %xmm1
	addss	%xmm0, %xmm1
	movss	%xmm1, 100(%rsp)                # 4-byte Spill
	movq	32(%rsp), %rdi
	callq	hipHostFree
	movq	24(%rsp), %rdi
	callq	hipHostFree
	movq	88(%rsp), %rdi
	callq	hipHostFree
	movq	80(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	72(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipStreamDestroy
	movq	8(%rsp), %rdi
	callq	hipStreamDestroy
	movss	100(%rsp), %xmm0                # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addq	$136, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z30run_test_with_multiple_streamsv, .Lfunc_end1-_Z30run_test_with_multiple_streamsv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z27run_test_with_single_streamv
.LCPI2_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z27run_test_with_single_streamv
	.type	_Z27run_test_with_single_streamv,@function
_Z27run_test_with_single_streamv:       # @_Z27run_test_with_single_streamv
	.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	$96, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rdi
	xorl	%ebx, %ebx
	movl	$838860800, %esi                # imm = 0x32000000
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	32(%rsp), %rdi
	movl	$838860800, %esi                # imm = 0x32000000
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	56(%rsp), %rdi
	movl	$838860800, %esi                # imm = 0x32000000
	xorl	%edx, %edx
	callq	hipHostAlloc
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	movq	40(%rsp), %rcx
	movl	%eax, (%rcx,%rbx,4)
	callq	rand
	movq	32(%rsp), %rcx
	movl	%eax, (%rcx,%rbx,4)
	incq	%rbx
	cmpq	$209715200, %rbx                # imm = 0xC800000
	jne	.LBB2_1
# %bb.2:
	movabsq	$4294968320, %rbx               # imm = 0x100000400
	xorl	%r14d, %r14d
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	24(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	movq	%rsp, %rdi
	callq	hipStreamCreate
	movq	$-1048576, %r15                 # imm = 0xFFF00000
.LBB2_3:                                # =>This Inner Loop Header: Depth=1
	movq	24(%rsp), %rdi
	movq	40(%rsp), %rsi
	addq	%r14, %rsi
	movq	(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	16(%rsp), %rdi
	movq	32(%rsp), %rsi
	addq	%r14, %rsi
	movq	(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	movq	(%rsp), %r9
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_5
# %bb.4:                                #   in Loop: Header=BB2_3 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$1048576, %ecx                  # imm = 0x100000
	callq	_Z21__device_stub__kernelPiS_S_i
.LBB2_5:                                #   in Loop: Header=BB2_3 Depth=1
	movq	56(%rsp), %rdi
	addq	%r14, %rdi
	movq	8(%rsp), %rsi
	movq	(%rsp), %r8
	movl	$4194304, %edx                  # imm = 0x400000
	movl	$1, %ecx
	callq	hipMemcpyAsync
	addq	$1048576, %r15                  # imm = 0x100000
	addq	$4194304, %r14                  # imm = 0x400000
	cmpq	$208666624, %r15                # imm = 0xC700000
	jb	.LBB2_3
# %bb.6:
	movq	(%rsp), %rdi
	callq	hipStreamSynchronize
	leaq	80(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	subq	64(%rsp), %rax
	cvtsi2ss	%rax, %xmm0
	movq	8(%rbx), %rax
	subq	72(%rsp), %rax
	cvtsi2ss	%rax, %xmm1
	divss	.LCPI2_0(%rip), %xmm1
	addss	%xmm0, %xmm1
	movss	%xmm1, 52(%rsp)                 # 4-byte Spill
	movq	40(%rsp), %rdi
	callq	hipHostFree
	movq	32(%rsp), %rdi
	callq	hipHostFree
	movq	56(%rsp), %rdi
	callq	hipHostFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipStreamDestroy
	movss	52(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addq	$96, %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
.Lfunc_end2:
	.size	_Z27run_test_with_single_streamv, .Lfunc_end2-_Z27run_test_with_single_streamv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z25run_test_with_cuda_mallocv
.LCPI3_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z25run_test_with_cuda_mallocv
	.type	_Z25run_test_with_cuda_mallocv,@function
_Z25run_test_with_cuda_mallocv:         # @_Z25run_test_with_cuda_mallocv
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$838860800, %edi                # imm = 0x32000000
	callq	malloc
	movq	%rax, %rbx
	movl	$838860800, %edi                # imm = 0x32000000
	callq	malloc
	movq	%rax, %r14
	movl	$838860800, %edi                # imm = 0x32000000
	callq	malloc
	movq	%rax, %r15
	xorl	%r12d, %r12d
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, (%rbx,%r12,4)
	callq	rand
	movl	%eax, (%r14,%r12,4)
	incq	%r12
	cmpq	$209715200, %r12                # imm = 0xC800000
	jne	.LBB3_1
# %bb.2:
	leaq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	leaq	32(%rsp), %r12
	movl	$838860800, %esi                # imm = 0x32000000
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	$838860800, %edx                # imm = 0x32000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %r12
	movl	$838860800, %esi                # imm = 0x32000000
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	$838860800, %edx                # imm = 0x32000000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	8(%rsp), %rdi
	movl	$838860800, %esi                # imm = 0x32000000
	callq	hipMalloc
	movabsq	$4294968320, %rdx               # imm = 0x100000400
	leaq	203776(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_4
# %bb.3:
	movq	32(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$209715200, %ecx                # imm = 0xC800000
	callq	_Z21__device_stub__kernelPiS_S_i
.LBB3_4:
	movq	8(%rsp), %rsi
	movl	$838860800, %edx                # imm = 0x32000000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	56(%rsp), %r12
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r12), %rax
	subq	40(%rsp), %rax
	cvtsi2ss	%rax, %xmm0
	movq	8(%r12), %rax
	subq	48(%rsp), %rax
	cvtsi2ss	%rax, %xmm1
	divss	.LCPI3_0(%rip), %xmm1
	addss	%xmm0, %xmm1
	movss	%xmm1, 20(%rsp)                 # 4-byte Spill
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movss	20(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	addq	$72, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z25run_test_with_cuda_mallocv, .Lfunc_end3-_Z25run_test_with_cuda_mallocv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 1504
	.cfi_offset %rbx, -16
	leaq	12(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDevice
	movl	(%rbx), %esi
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDevicePropertiesR0600
	cmpl	$1, 400(%rbx)
	jne	.LBB4_3
# %bb.1:
	cmpl	$1, 400(%rsp)
	jne	.LBB4_4
# %bb.2:
	movl	$8, %edi
	callq	hipSetDeviceFlags
	callq	_Z25run_test_with_cuda_mallocv
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	callq	_Z27run_test_with_single_streamv
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	callq	_Z30run_test_with_multiple_streamsv
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.4, %edi
	movb	$1, %al
	callq	printf
	jmp	.LBB4_6
.LBB4_3:
	movl	$.Lstr.1, %edi
	jmp	.LBB4_5
.LBB4_4:
	movl	$.Lstr, %edi
.LBB4_5:
	callq	puts@PLT
.LBB4_6:
	xorl	%edi, %edi
	callq	exit
.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	$_Z6kernelPiS_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	_Z6kernelPiS_S_i,@object        # @_Z6kernelPiS_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z6kernelPiS_S_i
	.p2align	3, 0x0
_Z6kernelPiS_S_i:
	.quad	_Z21__device_stub__kernelPiS_S_i
	.size	_Z6kernelPiS_S_i, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"Elapsed time using cudaMalloc: %3.1f s \n"
	.size	.L.str.2, 41

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Elapsed time using a single stream: %3.1f s \n"
	.size	.L.str.3, 46

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Elapsed time using multiple streams: %3.1f s \n"
	.size	.L.str.4, 47

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6kernelPiS_S_i"
	.size	.L__unnamed_1, 17

	.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	"The device does not support overlaps. "
	.size	.Lstr, 39

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"The device cannot map host memory. "
	.size	.Lstr.1, 36

	.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 _Z21__device_stub__kernelPiS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6kernelPiS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6kernelPiS_S_i        ; -- Begin function _Z6kernelPiS_S_i
	.globl	_Z6kernelPiS_S_i
	.p2align	8
	.type	_Z6kernelPiS_S_i,@function
_Z6kernelPiS_S_i:                       ; @_Z6kernelPiS_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_4
; %bb.1:                                ; %.preheader
	v_add_nc_u32_e32 v0, 1, v1
	v_add_nc_u32_e32 v4, 2, v1
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	v_ashrrev_i32_e32 v2, 31, v0
	v_ashrrev_i32_e32 v3, 31, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshrrev_b32_e32 v2, 22, v2
	v_lshrrev_b32_e32 v3, 22, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, v0, v2
	v_add_nc_u32_e32 v3, v4, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_and_b32_e32 v5, 0xfffffc00, v2
	v_and_b32_e32 v6, 0xfffffc00, v3
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v3, v0, v5
	v_sub_nc_u32_e32 v5, v4, v6
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_ashrrev_i32_e32 v6, 31, v5
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v7, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 2, v[3:4]
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v1, vcc_lo
	v_add_co_u32 v9, vcc_lo, s6, v0
	v_lshlrev_b64 v[4:5], 2, v[5:6]
	v_add_co_ci_u32_e32 v10, vcc_lo, s7, v1, vcc_lo
	v_add_co_u32 v11, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v13, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v14, vcc_lo, s5, v5, vcc_lo
	v_add_co_u32 v2, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	v_add_co_u32 v4, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s7, v5, vcc_lo
	s_clause 0x2
	global_load_b32 v6, v[7:8], off
	global_load_b32 v7, v[11:12], off
	global_load_b32 v8, v[13:14], off
	s_clause 0x2
	global_load_b32 v9, v[9:10], off
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[4:5], off
	s_waitcnt vmcnt(3)
	v_add3_u32 v4, v7, v6, v8
	s_waitcnt vmcnt(0)
	v_add3_u32 v2, v2, v9, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_f32_i32_e32 v3, v4
	v_cvt_f32_i32_e32 v4, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_scale_f32 v2, null, 0x461c4000, 0x461c4000, v3
	v_div_scale_f32 v10, vcc_lo, v3, 0x461c4000, v3
	v_div_scale_f32 v5, null, 0x461c4000, 0x461c4000, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v6, v2
	v_rcp_f32_e32 v7, v5
	s_waitcnt_depctr 0xfff
	v_fma_f32 v8, -v2, v6, 1.0
	v_fma_f32 v9, -v5, v7, 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v6, v8, v6
	v_div_scale_f32 v8, s0, v4, 0x461c4000, v4
	v_fmac_f32_e32 v7, v9, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v9, v10, v6
	v_mul_f32_e32 v11, v8, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v12, -v2, v9, v10
	v_fma_f32 v13, -v5, v11, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v9, v12, v6
	v_fmac_f32_e32 v11, v13, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v2, -v2, v9, v10
	v_fma_f32 v5, -v5, v11, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v6, v2, v6, v9
	s_mov_b32 vcc_lo, s0
	v_mov_b32_e32 v2, 0
	v_div_fmas_f32 v5, v5, v7, v11
	s_movk_i32 s0, 0x2710
	v_div_fixup_f32 v3, v6, 0x461c4000, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_div_fixup_f32 v4, v5, 0x461c4000, v4
	v_mov_b32_e32 v5, 0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_dual_add_f32 v5, v5, v3 :: v_dual_add_f32 v2, v2, v4
	s_add_i32 s0, s0, -1
	s_cmp_eq_u32 s0, 0
	s_cbranch_scc0 .LBB0_2
; %bb.3:
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_add_f32_e32 v2, v5, v2
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	v_mul_f32_e32 v2, 0.5, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_i32_f32_e32 v2, v2
	global_store_b32 v[0:1], v2, off
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6kernelPiS_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 15
		.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	_Z6kernelPiS_S_i, .Lfunc_end0-_Z6kernelPiS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 672
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; 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:           _Z6kernelPiS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6kernelPiS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
