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

#define HANDLE_ERROR(apiFuncCall)                                              \
do {                                                                           \
    cudaError_t _status = apiFuncCall;                                         \
    if (_status != cudaSuccess) {                                             \
        fprintf(stderr, "%s:%d: error: function %s failed with error %d.\n",   \
                __FILE__, __LINE__, #apiFuncCall, _status);                    \
        exit(-1);                                                              \
    }                                                                          \
} while (0)

#define HANDLE_NULL(x)
#define TOTAL 1024

float cuda_malloc_test( int size, bool up ) {
    cudaEvent_t start, stop;
    int *a, *dev_a;
    float elapsedTime = 0.0f;
    HANDLE_ERROR( cudaEventCreate( &start ) );
    HANDLE_ERROR( cudaEventCreate( &stop ) );
    a = (int*)malloc( size * sizeof( *a ) );
    if (!a) {
        exit(-1);
    }
    HANDLE_ERROR( cudaMalloc( (void**)&dev_a,
    size * sizeof( *dev_a ) ) );
    HANDLE_ERROR( cudaEventRecord( start, 0 ) );
    for (int i=0; i<TOTAL; i++) {
    if (up)
        HANDLE_ERROR( cudaMemcpy( dev_a, a, size * sizeof( *dev_a ),cudaMemcpyHostToDevice ) );
    else
        HANDLE_ERROR( cudaMemcpy( a, dev_a,size * sizeof( *dev_a ),cudaMemcpyDeviceToHost ) );
    }
    HANDLE_ERROR( cudaEventRecord( stop, 0 ) );
    HANDLE_ERROR( cudaEventSynchronize( stop ) );
    HANDLE_ERROR( cudaEventElapsedTime( &elapsedTime,start, stop ) );
    free( a );
    HANDLE_ERROR( cudaFree( dev_a ) );
    HANDLE_ERROR( cudaEventDestroy( start ) );
    HANDLE_ERROR( cudaEventDestroy( stop ) );
    return elapsedTime;
}

float cuda_host_alloc_test( int size, bool up ) {
    cudaEvent_t start, stop;int *a, *dev_a;
    float elapsedTime;
    HANDLE_ERROR( cudaEventCreate( &start ) );
    HANDLE_ERROR( cudaEventCreate( &stop ) );
    HANDLE_ERROR( cudaHostAlloc( (void**)&a, size * sizeof( *a ),cudaHostAllocDefault ) );
    HANDLE_ERROR( cudaMalloc( (void**)&dev_a,size * sizeof( *dev_a ) ) );
    HANDLE_ERROR( cudaEventRecord( start, 0 ) );
    for (int i=0; i<TOTAL; i++) {
        if (up)
        HANDLE_ERROR( cudaMemcpy( dev_a, a, size * sizeof( *a ),cudaMemcpyHostToDevice ) );
        else
        HANDLE_ERROR( cudaMemcpy( a, dev_a,size * sizeof( *a ),cudaMemcpyDeviceToHost ) );
    }
    HANDLE_ERROR( cudaEventRecord( stop, 0 ) );
    HANDLE_ERROR( cudaEventSynchronize( stop ) );
    HANDLE_ERROR( cudaEventElapsedTime( &elapsedTime,start, stop ) );
    HANDLE_ERROR( cudaFreeHost( a ) );
    HANDLE_ERROR( cudaFree( dev_a ) );
    HANDLE_ERROR( cudaEventDestroy( start ) );
    HANDLE_ERROR( cudaEventDestroy( stop ) );
    return elapsedTime;
}

//#define SIZE    (10*1024*1024)
//#define SIZE    (1*1024)
//#define SIZE    (4*1024)
//#define SIZE    (16*1024)
//#define SIZE      (64*1024)
//#define SIZE    (1024*1024)
#define SIZE    (4*1024*1024)
//#define SIZE    (16*1024*1024)


int main( void ) {
    float elapsedTime;
    float MB = (float)TOTAL*SIZE*sizeof(int)/1024/1024;

    printf( "Pinned:\n" );
    elapsedTime = cuda_host_alloc_test( SIZE, true );
    printf( "Up Time using cudaHostAlloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );

    elapsedTime = cuda_host_alloc_test( SIZE, false );
    printf( "Down Time using cudaHostAlloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );

    printf("\n-------------------------------\n\n");

    printf( "Native:\n" );
    elapsedTime = cuda_malloc_test( SIZE, true );
    printf( "Up Time using cudaMalloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );
    
    elapsedTime = cuda_malloc_test( SIZE, false );
    printf( "Down Time using cudaMalloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d	 Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );
	
}
	.file	"tmpxft_002b7b66_00000000-6_pinnedMemory.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"cudaEventCreate( &start )"
.LC2:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/WeiChungChang/GpuProgramming/master/profiling/memcpyPinnedMemory/pinnedMemory.cu"
.LC3:
	.string	"%s:%d: error: function %s failed with error %d.\n"
.LC4:
	.string	"cudaEventCreate( &stop )"
.LC5:
	.string	"cudaMalloc( (void**)&dev_a, size * sizeof( *dev_a ) )"
.LC6:
	.string	"cudaEventRecord( start, 0 )"
.LC7:
	.string	"cudaMemcpy( dev_a, a, size * sizeof( *dev_a ),cudaMemcpyHostToDevice )"
.LC8:
	.string	"cudaMemcpy( a, dev_a,size * sizeof( *dev_a ),cudaMemcpyDeviceToHost )"
.LC9:
	.string	"cudaEventRecord( stop, 0 )"
.LC10:
	.string	"cudaEventSynchronize( stop )"
.LC11:
	.string	"cudaEventElapsedTime( &elapsedTime,start, stop )"
.LC12:
	.string	"cudaFree( dev_a )"
.LC13:
	.string	"cudaEventDestroy( start )"
.LC14:
	.string	"cudaEventDestroy( stop )"
	.text
	.globl	_Z16cuda_malloc_testib
	.type	_Z16cuda_malloc_testib, @function
_Z16cuda_malloc_testib:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movslq	%edi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	movl	$0x00000000, 12(%rsp)
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L3
	leaq	.LC1(%rip), %r9
	pushq	%r13
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$21, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L3:
	.cfi_restore_state
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L4
	pushq	%r12
	.cfi_def_cfa_offset 104
	leaq	.LC4(%rip), %r9
	movl	$22, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
.L28:
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rcx
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L4:
	.cfi_def_cfa_offset 96
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L5
	orl	$-1, %edi
	call	exit@PLT
.L5:
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L6
	leaq	.LC5(%rip), %r9
	pushq	%rbp
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$27, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L6:
	.cfi_restore_state
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	movl	$1024, %r13d
	call	cudaEventRecord@PLT
	testl	%eax, %eax
	je	.L7
	leaq	.LC6(%rip), %r9
	pushq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$29, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L9:
	.cfi_restore_state
	decl	%r13d
	je	.L30
.L7:
	movq	32(%rsp), %rdi
	testb	%r12b, %r12b
	je	.L8
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L9
	leaq	.LC7(%rip), %r9
	pushq	%r11
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$32, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L8:
	.cfi_restore_state
	movq	%rdi, %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L9
	leaq	.LC8(%rip), %r9
	pushq	%r10
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$34, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L30:
	.cfi_restore_state
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	testl	%eax, %eax
	je	.L10
	movl	$36, %r8d
	pushq	%r9
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	leaq	.LC9(%rip), %r9
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L10:
	.cfi_restore_state
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	testl	%eax, %eax
	je	.L11
	leaq	.LC10(%rip), %r9
	pushq	%r8
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$37, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L11:
	.cfi_restore_state
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	testl	%eax, %eax
	je	.L12
	leaq	.LC11(%rip), %r9
	pushq	%rdi
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$38, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L12:
	.cfi_restore_state
	movq	%rbp, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L13
	leaq	.LC12(%rip), %r9
	pushq	%rsi
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$40, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L13:
	.cfi_restore_state
	movq	16(%rsp), %rdi
	call	cudaEventDestroy@PLT
	testl	%eax, %eax
	je	.L14
	leaq	.LC13(%rip), %r9
	pushq	%rcx
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$41, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L14:
	.cfi_restore_state
	movq	24(%rsp), %rdi
	call	cudaEventDestroy@PLT
	testl	%eax, %eax
	je	.L15
	leaq	.LC14(%rip), %r9
	pushq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 104
	movl	$42, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 112
	jmp	.L28
.L15:
	.cfi_restore_state
	movss	12(%rsp), %xmm0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$56, %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
.LFE2027:
	.size	_Z16cuda_malloc_testib, .-_Z16cuda_malloc_testib
	.section	.rodata.str1.1
.LC15:
	.string	"cudaHostAlloc( (void**)&a, size * sizeof( *a ),cudaHostAllocDefault )"
.LC16:
	.string	"cudaMalloc( (void**)&dev_a,size * sizeof( *dev_a ) )"
.LC17:
	.string	"cudaMemcpy( dev_a, a, size * sizeof( *a ),cudaMemcpyHostToDevice )"
.LC18:
	.string	"cudaMemcpy( a, dev_a,size * sizeof( *a ),cudaMemcpyDeviceToHost )"
.LC19:
	.string	"cudaFreeHost( a )"
	.text
	.globl	_Z20cuda_host_alloc_testib
	.type	_Z20cuda_host_alloc_testib, @function
_Z20cuda_host_alloc_testib:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%edi, %rbx
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L32
	leaq	.LC1(%rip), %r9
	pushq	%rsi
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$49, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L32:
	.cfi_restore_state
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L33
	pushq	%rcx
	.cfi_def_cfa_offset 88
	leaq	.LC4(%rip), %r9
	movl	$50, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
.L58:
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rcx
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	orl	$-1, %edi
	call	exit@PLT
.L33:
	.cfi_def_cfa_offset 80
	salq	$2, %rbx
	xorl	%edx, %edx
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaHostAlloc@PLT
	testl	%eax, %eax
	je	.L34
	leaq	.LC15(%rip), %r9
	pushq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$51, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L34:
	.cfi_restore_state
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L35
	leaq	.LC16(%rip), %r9
	pushq	%r12
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$52, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L35:
	.cfi_restore_state
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	movl	$1024, %r12d
	call	cudaEventRecord@PLT
	testl	%eax, %eax
	je	.L36
	leaq	.LC6(%rip), %r9
	pushq	%rbp
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$53, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L38:
	.cfi_restore_state
	decl	%r12d
	je	.L59
.L36:
	movq	32(%rsp), %rax
	movq	24(%rsp), %rdi
	testb	%bpl, %bpl
	je	.L37
	movq	%rdi, %rsi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rdi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L38
	leaq	.LC17(%rip), %r9
	pushq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$56, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L37:
	.cfi_restore_state
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L38
	leaq	.LC18(%rip), %r9
	pushq	%r11
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$58, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L59:
	.cfi_restore_state
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	testl	%eax, %eax
	je	.L39
	leaq	.LC9(%rip), %r9
	pushq	%r10
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$60, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L39:
	.cfi_restore_state
	movq	16(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	testl	%eax, %eax
	je	.L40
	movl	$61, %r8d
	pushq	%r9
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	leaq	.LC10(%rip), %r9
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L40:
	.cfi_restore_state
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	leaq	4(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	testl	%eax, %eax
	je	.L41
	leaq	.LC11(%rip), %r9
	pushq	%r8
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$62, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L41:
	.cfi_restore_state
	movq	24(%rsp), %rdi
	call	cudaFreeHost@PLT
	testl	%eax, %eax
	je	.L42
	leaq	.LC19(%rip), %r9
	pushq	%rdi
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$63, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L42:
	.cfi_restore_state
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L43
	leaq	.LC12(%rip), %r9
	pushq	%rsi
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$64, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L43:
	.cfi_restore_state
	movq	8(%rsp), %rdi
	call	cudaEventDestroy@PLT
	testl	%eax, %eax
	je	.L44
	leaq	.LC13(%rip), %r9
	pushq	%rcx
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$65, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L44:
	.cfi_restore_state
	movq	16(%rsp), %rdi
	call	cudaEventDestroy@PLT
	testl	%eax, %eax
	je	.L45
	leaq	.LC14(%rip), %r9
	pushq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 88
	movl	$66, %r8d
	pushq	%rax
	.cfi_def_cfa_offset 96
	jmp	.L58
.L45:
	.cfi_restore_state
	movss	4(%rsp), %xmm0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	addq	$48, %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	_Z20cuda_host_alloc_testib, .-_Z20cuda_host_alloc_testib
	.section	.rodata.str1.1
.LC20:
	.string	"Pinned:\n"
.LC21:
	.string	"Up Time using cudaHostAlloc:%3.1f ms\n"
.LC24:
	.string	"\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n"
.LC25:
	.string	"Down Time using cudaHostAlloc:%3.1f ms\n"
.LC26:
	.string	"\n-------------------------------\n\n"
.LC27:
	.string	"Native:\n"
.LC28:
	.string	"Up Time using cudaMalloc:%3.1f ms\n"
.LC29:
	.string	"Down Time using cudaMalloc:%3.1f ms\n"
.LC30:
	.string	"\tTransfer %d\t Bytes;  MB/s during copy down:%3.1f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC20(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC24(%rip), %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	call	__printf_chk@PLT
	movl	$1, %esi
	movl	$4194304, %edi
	call	_Z20cuda_host_alloc_testib
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	cvtss2sd	%xmm0, %xmm0
	movss	%xmm1, 12(%rsp)
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm1
	movq	%rbx, %rsi
	movb	$1, %al
	movss	.LC23(%rip), %xmm0
	movl	$16777216, %edx
	movl	$2, %edi
	divss	.LC22(%rip), %xmm1
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	xorl	%esi, %esi
	movl	$4194304, %edi
	call	_Z20cuda_host_alloc_testib
	leaq	.LC25(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	cvtss2sd	%xmm0, %xmm0
	movss	%xmm1, 12(%rsp)
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm1
	movq	%rbx, %rsi
	movb	$1, %al
	movss	.LC23(%rip), %xmm0
	movl	$16777216, %edx
	movl	$2, %edi
	divss	.LC22(%rip), %xmm1
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC26(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %esi
	movl	$4194304, %edi
	call	_Z16cuda_malloc_testib
	leaq	.LC28(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	cvtss2sd	%xmm0, %xmm0
	movss	%xmm1, 12(%rsp)
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm1
	movq	%rbx, %rsi
	movb	$1, %al
	movss	.LC23(%rip), %xmm0
	movl	$16777216, %edx
	movl	$2, %edi
	divss	.LC22(%rip), %xmm1
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	xorl	%esi, %esi
	movl	$4194304, %edi
	call	_Z16cuda_malloc_testib
	leaq	.LC29(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	cvtss2sd	%xmm0, %xmm0
	movss	%xmm1, 12(%rsp)
	call	__printf_chk@PLT
	movss	.LC23(%rip), %xmm0
	movb	$1, %al
	movss	12(%rsp), %xmm1
	divss	.LC22(%rip), %xmm1
	movl	$16777216, %edx
	movl	$2, %edi
	leaq	.LC30(%rip), %rsi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2055:
	.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
.LC22:
	.long	1148846080
	.align 4
.LC23:
	.long	1182793728
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

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

#define HANDLE_ERROR(apiFuncCall)                                              \
do {                                                                           \
    hipError_t _status = apiFuncCall;                                         \
    if (_status != hipSuccess) {                                             \
        fprintf(stderr, "%s:%d: error: function %s failed with error %d.\n",   \
                __FILE__, __LINE__, #apiFuncCall, _status);                    \
        exit(-1);                                                              \
    }                                                                          \
} while (0)

#define HANDLE_NULL(x)
#define TOTAL 1024

float cuda_malloc_test( int size, bool up ) {
    hipEvent_t start, stop;
    int *a, *dev_a;
    float elapsedTime = 0.0f;
    HANDLE_ERROR( hipEventCreate( &start ) );
    HANDLE_ERROR( hipEventCreate( &stop ) );
    a = (int*)malloc( size * sizeof( *a ) );
    if (!a) {
        exit(-1);
    }
    HANDLE_ERROR( hipMalloc( (void**)&dev_a,
    size * sizeof( *dev_a ) ) );
    HANDLE_ERROR( hipEventRecord( start, 0 ) );
    for (int i=0; i<TOTAL; i++) {
    if (up)
        HANDLE_ERROR( hipMemcpy( dev_a, a, size * sizeof( *dev_a ),hipMemcpyHostToDevice ) );
    else
        HANDLE_ERROR( hipMemcpy( a, dev_a,size * sizeof( *dev_a ),hipMemcpyDeviceToHost ) );
    }
    HANDLE_ERROR( hipEventRecord( stop, 0 ) );
    HANDLE_ERROR( hipEventSynchronize( stop ) );
    HANDLE_ERROR( hipEventElapsedTime( &elapsedTime,start, stop ) );
    free( a );
    HANDLE_ERROR( hipFree( dev_a ) );
    HANDLE_ERROR( hipEventDestroy( start ) );
    HANDLE_ERROR( hipEventDestroy( stop ) );
    return elapsedTime;
}

float cuda_host_alloc_test( int size, bool up ) {
    hipEvent_t start, stop;int *a, *dev_a;
    float elapsedTime;
    HANDLE_ERROR( hipEventCreate( &start ) );
    HANDLE_ERROR( hipEventCreate( &stop ) );
    HANDLE_ERROR( hipHostAlloc( (void**)&a, size * sizeof( *a ),hipHostMallocDefault ) );
    HANDLE_ERROR( hipMalloc( (void**)&dev_a,size * sizeof( *dev_a ) ) );
    HANDLE_ERROR( hipEventRecord( start, 0 ) );
    for (int i=0; i<TOTAL; i++) {
        if (up)
        HANDLE_ERROR( hipMemcpy( dev_a, a, size * sizeof( *a ),hipMemcpyHostToDevice ) );
        else
        HANDLE_ERROR( hipMemcpy( a, dev_a,size * sizeof( *a ),hipMemcpyDeviceToHost ) );
    }
    HANDLE_ERROR( hipEventRecord( stop, 0 ) );
    HANDLE_ERROR( hipEventSynchronize( stop ) );
    HANDLE_ERROR( hipEventElapsedTime( &elapsedTime,start, stop ) );
    HANDLE_ERROR( hipHostFree( a ) );
    HANDLE_ERROR( hipFree( dev_a ) );
    HANDLE_ERROR( hipEventDestroy( start ) );
    HANDLE_ERROR( hipEventDestroy( stop ) );
    return elapsedTime;
}

//#define SIZE    (10*1024*1024)
//#define SIZE    (1*1024)
//#define SIZE    (4*1024)
//#define SIZE    (16*1024)
//#define SIZE      (64*1024)
//#define SIZE    (1024*1024)
#define SIZE    (4*1024*1024)
//#define SIZE    (16*1024*1024)


int main( void ) {
    float elapsedTime;
    float MB = (float)TOTAL*SIZE*sizeof(int)/1024/1024;

    printf( "Pinned:\n" );
    elapsedTime = cuda_host_alloc_test( SIZE, true );
    printf( "Up Time using cudaHostAlloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );

    elapsedTime = cuda_host_alloc_test( SIZE, false );
    printf( "Down Time using cudaHostAlloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );

    printf("\n-------------------------------\n\n");

    printf( "Native:\n" );
    elapsedTime = cuda_malloc_test( SIZE, true );
    printf( "Up Time using cudaMalloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );
    
    elapsedTime = cuda_malloc_test( SIZE, false );
    printf( "Down Time using cudaMalloc:%3.1f ms\n",elapsedTime );
    printf( "\tTransfer %d	 Bytes;  MB/s during copy down:%3.1f\n", SIZE*4, MB /(elapsedTime/1000) );
	
}
	.text
	.file	"pinnedMemory.hip"
	.globl	_Z16cuda_malloc_testib          # -- Begin function _Z16cuda_malloc_testib
	.type	_Z16cuda_malloc_testib,@function
_Z16cuda_malloc_testib:                 # @_Z16cuda_malloc_testib
	.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	%rbx
	.cfi_def_cfa_offset 40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movl	%edi, %ebx
	movl	$0, 12(%rsp)
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB0_1
# %bb.4:
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB0_5
# %bb.6:
	movslq	%ebx, %r14
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB0_3
# %bb.7:
	movq	%rax, %rbx
	leaq	32(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.9:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_14
# %bb.10:                               # %.preheader.preheader
	movl	$1024, %r15d                    # imm = 0x400
.LBB0_11:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movq	32(%rsp), %rsi
	testb	%bpl, %bpl
	je	.LBB0_15
# %bb.12:                               #   in Loop: Header=BB0_11 Depth=1
	movq	%rsi, %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB0_17
	jmp	.LBB0_13
.LBB0_15:                               #   in Loop: Header=BB0_11 Depth=1
	movq	%rbx, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB0_16
.LBB0_17:                               #   in Loop: Header=BB0_11 Depth=1
	decl	%r15d
	jne	.LBB0_11
# %bb.18:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB0_19
# %bb.20:
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB0_21
# %bb.22:
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB0_23
# %bb.24:
	movq	%rbx, %rdi
	callq	free
	movq	32(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB0_25
# %bb.26:
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB0_27
# %bb.28:
	movq	16(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB0_29
# %bb.30:
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB0_13:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.6, %r8d
	movl	$32, %ecx
	jmp	.LBB0_2
.LBB0_16:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.7, %r8d
	movl	$34, %ecx
.LBB0_2:
	movl	%eax, %r9d
	xorl	%eax, %eax
	callq	fprintf
.LBB0_3:
	movl	$-1, %edi
	callq	exit
.LBB0_1:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.2, %r8d
	movl	$21, %ecx
	jmp	.LBB0_2
.LBB0_5:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.3, %r8d
	movl	$22, %ecx
	jmp	.LBB0_2
.LBB0_8:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.4, %r8d
	movl	$28, %ecx
	jmp	.LBB0_2
.LBB0_14:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.5, %r8d
	movl	$29, %ecx
	jmp	.LBB0_2
.LBB0_19:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.8, %r8d
	movl	$36, %ecx
	jmp	.LBB0_2
.LBB0_21:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.9, %r8d
	movl	$37, %ecx
	jmp	.LBB0_2
.LBB0_23:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.10, %r8d
	movl	$38, %ecx
	jmp	.LBB0_2
.LBB0_25:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.11, %r8d
	movl	$40, %ecx
	jmp	.LBB0_2
.LBB0_27:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.12, %r8d
	movl	$41, %ecx
	jmp	.LBB0_2
.LBB0_29:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.13, %r8d
	movl	$42, %ecx
	jmp	.LBB0_2
.Lfunc_end0:
	.size	_Z16cuda_malloc_testib, .Lfunc_end0-_Z16cuda_malloc_testib
	.cfi_endproc
                                        # -- End function
	.globl	_Z20cuda_host_alloc_testib      # -- Begin function _Z20cuda_host_alloc_testib
	.type	_Z20cuda_host_alloc_testib,@function
_Z20cuda_host_alloc_testib:             # @_Z20cuda_host_alloc_testib
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movl	%edi, %ebp
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB1_1
# %bb.3:
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB1_4
# %bb.5:
	movslq	%ebp, %r14
	shlq	$2, %r14
	leaq	24(%rsp), %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	testl	%eax, %eax
	jne	.LBB1_6
# %bb.7:
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.9:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.10:                               # %.preheader.preheader
	movl	$1024, %ebp                     # imm = 0x400
.LBB1_11:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	testb	%bl, %bl
	je	.LBB1_15
# %bb.12:                               #   in Loop: Header=BB1_11 Depth=1
	movq	16(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_17
	jmp	.LBB1_13
.LBB1_15:                               #   in Loop: Header=BB1_11 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_16
.LBB1_17:                               #   in Loop: Header=BB1_11 Depth=1
	decl	%ebp
	jne	.LBB1_11
# %bb.18:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB1_19
# %bb.20:
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB1_21
# %bb.22:
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	44(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB1_23
# %bb.24:
	movq	24(%rsp), %rdi
	callq	hipHostFree
	testl	%eax, %eax
	jne	.LBB1_25
# %bb.26:
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_27
# %bb.28:
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB1_29
# %bb.30:
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB1_31
# %bb.32:
	movss	44(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_13:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.16, %r8d
	movl	$56, %ecx
	jmp	.LBB1_2
.LBB1_16:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.17, %r8d
	movl	$58, %ecx
.LBB1_2:
	movl	%eax, %r9d
	xorl	%eax, %eax
	callq	fprintf
	movl	$-1, %edi
	callq	exit
.LBB1_1:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.2, %r8d
	movl	$49, %ecx
	jmp	.LBB1_2
.LBB1_4:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.3, %r8d
	movl	$50, %ecx
	jmp	.LBB1_2
.LBB1_6:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.14, %r8d
	movl	$51, %ecx
	jmp	.LBB1_2
.LBB1_8:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.15, %r8d
	movl	$52, %ecx
	jmp	.LBB1_2
.LBB1_14:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.5, %r8d
	movl	$53, %ecx
	jmp	.LBB1_2
.LBB1_19:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.8, %r8d
	movl	$60, %ecx
	jmp	.LBB1_2
.LBB1_21:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.9, %r8d
	movl	$61, %ecx
	jmp	.LBB1_2
.LBB1_23:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.10, %r8d
	movl	$62, %ecx
	jmp	.LBB1_2
.LBB1_25:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.18, %r8d
	movl	$63, %ecx
	jmp	.LBB1_2
.LBB1_27:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.11, %r8d
	movl	$64, %ecx
	jmp	.LBB1_2
.LBB1_29:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.12, %r8d
	movl	$65, %ecx
	jmp	.LBB1_2
.LBB1_31:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movl	$.L.str.13, %r8d
	movl	$66, %ecx
	jmp	.LBB1_2
.Lfunc_end1:
	.size	_Z20cuda_host_alloc_testib, .Lfunc_end1-_Z20cuda_host_alloc_testib
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x447a0000                      # float 1000
.LCPI2_1:
	.long	0x46800000                      # float 16384
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$4194304, %edi                  # imm = 0x400000
	movl	$1, %esi
	callq	_Z20cuda_host_alloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.20, %edi
	movb	$1, %al
	callq	printf
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	divss	.LCPI2_0(%rip), %xmm1
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.21, %edi
	movl	$16777216, %esi                 # imm = 0x1000000
	movb	$1, %al
	callq	printf
	movl	$4194304, %edi                  # imm = 0x400000
	xorl	%esi, %esi
	callq	_Z20cuda_host_alloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.22, %edi
	movb	$1, %al
	callq	printf
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	divss	.LCPI2_0(%rip), %xmm1
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.21, %edi
	movl	$16777216, %esi                 # imm = 0x1000000
	movb	$1, %al
	callq	printf
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$4194304, %edi                  # imm = 0x400000
	movl	$1, %esi
	callq	_Z16cuda_malloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.25, %edi
	movb	$1, %al
	callq	printf
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	divss	.LCPI2_0(%rip), %xmm1
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.21, %edi
	movl	$16777216, %esi                 # imm = 0x1000000
	movb	$1, %al
	callq	printf
	movl	$4194304, %edi                  # imm = 0x400000
	xorl	%esi, %esi
	callq	_Z16cuda_malloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.26, %edi
	movb	$1, %al
	callq	printf
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	divss	.LCPI2_0(%rip), %xmm1
	movss	.LCPI2_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.27, %edi
	movl	$16777216, %esi                 # imm = 0x1000000
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s:%d: error: function %s failed with error %d.\n"
	.size	.L.str, 49

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/WeiChungChang/GpuProgramming/master/profiling/memcpyPinnedMemory/pinnedMemory.hip"
	.size	.L.str.1, 144

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"hipEventCreate( &start )"
	.size	.L.str.2, 25

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"hipEventCreate( &stop )"
	.size	.L.str.3, 24

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipMalloc( (void**)&dev_a, size * sizeof( *dev_a ) )"
	.size	.L.str.4, 53

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipEventRecord( start, 0 )"
	.size	.L.str.5, 27

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"hipMemcpy( dev_a, a, size * sizeof( *dev_a ),hipMemcpyHostToDevice )"
	.size	.L.str.6, 69

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"hipMemcpy( a, dev_a,size * sizeof( *dev_a ),hipMemcpyDeviceToHost )"
	.size	.L.str.7, 68

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipEventRecord( stop, 0 )"
	.size	.L.str.8, 26

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"hipEventSynchronize( stop )"
	.size	.L.str.9, 28

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"hipEventElapsedTime( &elapsedTime,start, stop )"
	.size	.L.str.10, 48

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipFree( dev_a )"
	.size	.L.str.11, 17

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"hipEventDestroy( start )"
	.size	.L.str.12, 25

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"hipEventDestroy( stop )"
	.size	.L.str.13, 24

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"hipHostAlloc( (void**)&a, size * sizeof( *a ),hipHostMallocDefault )"
	.size	.L.str.14, 69

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"hipMalloc( (void**)&dev_a,size * sizeof( *dev_a ) )"
	.size	.L.str.15, 52

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"hipMemcpy( dev_a, a, size * sizeof( *a ),hipMemcpyHostToDevice )"
	.size	.L.str.16, 65

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"hipMemcpy( a, dev_a,size * sizeof( *a ),hipMemcpyDeviceToHost )"
	.size	.L.str.17, 64

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"hipHostFree( a )"
	.size	.L.str.18, 17

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"Up Time using cudaHostAlloc:%3.1f ms\n"
	.size	.L.str.20, 38

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"\tTransfer %d Bytes;  MB/s during copy down:%3.1f\n"
	.size	.L.str.21, 50

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"Down Time using cudaHostAlloc:%3.1f ms\n"
	.size	.L.str.22, 40

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"Up Time using cudaMalloc:%3.1f ms\n"
	.size	.L.str.25, 35

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"Down Time using cudaMalloc:%3.1f ms\n"
	.size	.L.str.26, 37

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"\tTransfer %d\t Bytes;  MB/s during copy down:%3.1f\n"
	.size	.L.str.27, 51

	.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	"Pinned:"
	.size	.Lstr, 8

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\n-------------------------------\n"
	.size	.Lstr.1, 34

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Native:"
	.size	.Lstr.2, 8

	.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_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
