// CUDA by Example
// Ch10: page-locked (pinned) host memory

#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>

static void HandleError(cudaError_t err,
    const char *file,
    int line) {
    if (err != cudaSuccess) {
        printf("%s in %s at line %d\n", cudaGetErrorString(err),
            file, line);
        exit(EXIT_FAILURE);
    }
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

#define SIZE (10*1024*1024)

float cuda_malloc_test(int size, bool up)
{
    cudaEvent_t start, stop;
    int *a, *d_a;
    float d_t;

    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    a = (int*)malloc(size*sizeof(*a));
    cudaMalloc(&d_a, size * sizeof(*a));

    cudaEventRecord(start, 0);
    for (int i = 0; i < 100; i++) {
        if (up) {
            cudaMemcpy(d_a, a, size * sizeof(*a), cudaMemcpyHostToDevice);
        }
        else {
            cudaMemcpy(a, d_a, size * sizeof(*a), cudaMemcpyDeviceToHost);
        }
    }

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&d_t, start, stop);
    cudaEventDestroy(start);
    cudaEventDestroy(stop);
    free(a);
    cudaFree(d_a);

    return d_t;
}

float cuda_host_alloc_test(int size, bool up)
{
    cudaEvent_t start, stop;
    int *a, *d_a;
    float d_t;

    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaHostAlloc(&a, size*sizeof(*a), cudaHostAllocDefault);
    cudaMalloc(&d_a, size*sizeof(*a));

    cudaEventRecord(start, 0);
    for (int i = 0; i < 100; i++) {
        if (up) {
            cudaMemcpy(d_a, a, size * sizeof(*a), cudaMemcpyHostToDevice);
        }
        else {
            cudaMemcpy(a, d_a, size * sizeof(*a), cudaMemcpyDeviceToHost);
        }
    }

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&d_t, start, stop);
    cudaEventDestroy(start);
    cudaEventDestroy(stop);

    cudaFreeHost(a);
    cudaFree(d_a);
    return d_t;
}



int main()
{
    float elapsedTime;
    float MB = (float)100 * SIZE * sizeof(int) / 1024 / 1024;
    
    elapsedTime = cuda_malloc_test(SIZE, true);
    printf("Time using cudaMalloc: %3.1f ms\n", elapsedTime);
    printf("\t MB/s during copy up: %3.1f\n", MB/(elapsedTime/1000));

    elapsedTime = cuda_malloc_test(SIZE, false);
    printf("Time using cudaMalloc: %3.1f ms\n", elapsedTime);
    printf("\t MB/s during copy down: %3.1f\n", MB / (elapsedTime / 1000));

    elapsedTime = cuda_host_alloc_test(SIZE, true);
    printf("Time using cudaHostAlloc: %3.1f ms\n", elapsedTime);
    printf("\t MB/s during copy up: %3.1f\n", MB / (elapsedTime / 1000));

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


    return 0;
}

	.file	"tmpxft_00234c13_00000000-6_pinned_mem.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	_Z16cuda_malloc_testib
	.type	_Z16cuda_malloc_testib, @function
_Z16cuda_malloc_testib:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%esi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	$100, %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
	salq	$2, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	%rbx, %rdi
	call	malloc@PLT
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
.L5:
	movq	32(%rsp), %rdi
	testb	%r13b, %r13b
	je	.L3
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	jmp	.L9
.L3:
	movq	%rdi, %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rdi
.L9:
	call	cudaMemcpy@PLT
	decl	%r12d
	jne	.L5
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	16(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	24(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movss	12(%rsp), %xmm0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	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
.LFE2028:
	.size	_Z16cuda_malloc_testib, .-_Z16cuda_malloc_testib
	.globl	_Z20cuda_host_alloc_testib
	.type	_Z20cuda_host_alloc_testib, @function
_Z20cuda_host_alloc_testib:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	$100, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%edi, %rbx
	salq	$2, %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
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	xorl	%edx, %edx
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaHostAlloc@PLT
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
.L14:
	movq	32(%rsp), %rax
	movq	24(%rsp), %rdi
	testb	%r12b, %r12b
	je	.L12
	movq	%rdi, %rsi
	movl	$1, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rdi
	jmp	.L18
.L12:
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rsi
.L18:
	call	cudaMemcpy@PLT
	decl	%ebp
	jne	.L14
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	16(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	leaq	4(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	8(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	16(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	24(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movss	4(%rsp), %xmm0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	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
.LFE2029:
	.size	_Z20cuda_host_alloc_testib, .-_Z20cuda_host_alloc_testib
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Time using cudaMalloc: %3.1f ms\n"
.LC3:
	.string	"\t MB/s during copy up: %3.1f\n"
.LC4:
	.string	"\t MB/s during copy down: %3.1f\n"
.LC5:
	.string	"Time using cudaHostAlloc: %3.1f ms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$1, %esi
	movl	$10485760, %edi
	leaq	.LC5(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC3(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	.LC0(%rip), %rbx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	call	_Z16cuda_malloc_testib
	movq	%rbx, %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	%rbp, %rsi
	movb	$1, %al
	movss	.LC2(%rip), %xmm0
	divss	.LC1(%rip), %xmm1
	movl	$2, %edi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	xorl	%esi, %esi
	movl	$10485760, %edi
	call	_Z16cuda_malloc_testib
	movq	%rbx, %rsi
	movl	$2, %edi
	movb	$1, %al
	movaps	%xmm0, %xmm1
	cvtss2sd	%xmm0, %xmm0
	leaq	.LC4(%rip), %rbx
	movss	%xmm1, 12(%rsp)
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm1
	movq	%rbx, %rsi
	movb	$1, %al
	movss	.LC2(%rip), %xmm0
	divss	.LC1(%rip), %xmm1
	movl	$2, %edi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$1, %esi
	movl	$10485760, %edi
	call	_Z20cuda_host_alloc_testib
	movq	%r12, %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	%rbp, %rsi
	movb	$1, %al
	movss	.LC2(%rip), %xmm0
	divss	.LC1(%rip), %xmm1
	movl	$2, %edi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	xorl	%esi, %esi
	movl	$10485760, %edi
	call	_Z20cuda_host_alloc_testib
	movq	%r12, %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	.LC2(%rip), %xmm0
	divss	.LC1(%rip), %xmm1
	movl	$2, %edi
	divss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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
.LFE2056:
	.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
.LC1:
	.long	1148846080
	.align 4
.LC2:
	.long	1165623296
	.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:

// CUDA by Example
// Ch10: page-locked (pinned) host memory

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

static void HandleError(hipError_t err,
    const char *file,
    int line) {
    if (err != hipSuccess) {
        printf("%s in %s at line %d\n", hipGetErrorString(err),
            file, line);
        exit(EXIT_FAILURE);
    }
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

#define SIZE (10*1024*1024)

float cuda_malloc_test(int size, bool up)
{
    hipEvent_t start, stop;
    int *a, *d_a;
    float d_t;

    hipEventCreate(&start);
    hipEventCreate(&stop);

    a = (int*)malloc(size*sizeof(*a));
    hipMalloc(&d_a, size * sizeof(*a));

    hipEventRecord(start, 0);
    for (int i = 0; i < 100; i++) {
        if (up) {
            hipMemcpy(d_a, a, size * sizeof(*a), hipMemcpyHostToDevice);
        }
        else {
            hipMemcpy(a, d_a, size * sizeof(*a), hipMemcpyDeviceToHost);
        }
    }

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&d_t, start, stop);
    hipEventDestroy(start);
    hipEventDestroy(stop);
    free(a);
    hipFree(d_a);

    return d_t;
}

float cuda_host_alloc_test(int size, bool up)
{
    hipEvent_t start, stop;
    int *a, *d_a;
    float d_t;

    hipEventCreate(&start);
    hipEventCreate(&stop);
    hipHostAlloc(&a, size*sizeof(*a), hipHostMallocDefault);
    hipMalloc(&d_a, size*sizeof(*a));

    hipEventRecord(start, 0);
    for (int i = 0; i < 100; i++) {
        if (up) {
            hipMemcpy(d_a, a, size * sizeof(*a), hipMemcpyHostToDevice);
        }
        else {
            hipMemcpy(a, d_a, size * sizeof(*a), hipMemcpyDeviceToHost);
        }
    }

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);
    hipEventElapsedTime(&d_t, start, stop);
    hipEventDestroy(start);
    hipEventDestroy(stop);

    hipHostFree(a);
    hipFree(d_a);
    return d_t;
}



int main()
{
    float elapsedTime;
    float MB = (float)100 * SIZE * sizeof(int) / 1024 / 1024;
    
    elapsedTime = cuda_malloc_test(SIZE, true);
    printf("Time using cudaMalloc: %3.1f ms\n", elapsedTime);
    printf("\t MB/s during copy up: %3.1f\n", MB/(elapsedTime/1000));

    elapsedTime = cuda_malloc_test(SIZE, false);
    printf("Time using cudaMalloc: %3.1f ms\n", elapsedTime);
    printf("\t MB/s during copy down: %3.1f\n", MB / (elapsedTime / 1000));

    elapsedTime = cuda_host_alloc_test(SIZE, true);
    printf("Time using cudaHostAlloc: %3.1f ms\n", elapsedTime);
    printf("\t MB/s during copy up: %3.1f\n", MB / (elapsedTime / 1000));

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


    return 0;
}

	.text
	.file	"pinned_mem.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
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movslq	%ebx, %r14
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %rbx
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$100, %r15d
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movq	16(%rsp), %rsi
	testb	%bpl, %bpl
	je	.LBB0_3
# %bb.2:                                #   in Loop: Header=BB0_1 Depth=1
	movq	%rsi, %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	jmp	.LBB0_4
.LBB0_3:                                #   in Loop: Header=BB0_1 Depth=1
	movq	%rbx, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
.LBB0_4:                                #   in Loop: Header=BB0_1 Depth=1
	callq	hipMemcpy
	decl	%r15d
	jne	.LBB0_1
# %bb.5:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	36(%rsp), %r14
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	%rbx, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movss	(%r14), %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
.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	%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, %ebx
	movl	%edi, %ebp
	leaq	24(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movslq	%ebp, %r14
	shlq	$2, %r14
	leaq	16(%rsp), %rdi
	movq	%r14, %rsi
	xorl	%edx, %edx
	callq	hipHostAlloc
	leaq	8(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	(%r15), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$100, %ebp
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	testb	%bl, %bl
	je	.LBB1_3
# %bb.2:                                #   in Loop: Header=BB1_1 Depth=1
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	jmp	.LBB1_4
.LBB1_3:                                #   in Loop: Header=BB1_1 Depth=1
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	movq	%r14, %rdx
	movl	$2, %ecx
.LBB1_4:                                #   in Loop: Header=BB1_1 Depth=1
	callq	hipMemcpy
	decl	%ebp
	jne	.LBB1_1
# %bb.5:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	36(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movq	16(%rsp), %rdi
	callq	hipHostFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movss	(%rbx), %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
.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	0x457a0000                      # float 4000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$10485760, %edi                 # imm = 0xA00000
	movl	$1, %esi
	callq	_Z16cuda_malloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str, %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.1, %edi
	movb	$1, %al
	callq	printf
	movl	$10485760, %edi                 # imm = 0xA00000
	xorl	%esi, %esi
	callq	_Z16cuda_malloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str, %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.2, %edi
	movb	$1, %al
	callq	printf
	movl	$10485760, %edi                 # imm = 0xA00000
	movl	$1, %esi
	callq	_Z20cuda_host_alloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.3, %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.1, %edi
	movb	$1, %al
	callq	printf
	movl	$10485760, %edi                 # imm = 0xA00000
	xorl	%esi, %esi
	callq	_Z20cuda_host_alloc_testib
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.3, %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.2, %edi
	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	"Time using cudaMalloc: %3.1f ms\n"
	.size	.L.str, 33

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\t MB/s during copy up: %3.1f\n"
	.size	.L.str.1, 30

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\t MB/s during copy down: %3.1f\n"
	.size	.L.str.2, 32

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

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __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
