/* Copyright (c) 1993-2015, NVIDIA CORPORATION. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  * Neither the name of NVIDIA CORPORATION nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <assert.h>
#include <vector>
#include <utility>
#include <iostream>

// Convenience function for checking CUDA runtime API results
// can be wrapped around any runtime API call. No-op in release builds.
inline
cudaError_t checkCuda(cudaError_t result)
{
#if defined(DEBUG) || defined(_DEBUG)
    if (result != cudaSuccess) {
      fprintf(stderr, "CUDA Runtime Error: %s\n", cudaGetErrorString(result));
      assert(result == cudaSuccess);
    }
#endif
    return result;
}

std::pair<float,float> profileCopies(float* h_a,
        float* h_b,
        float* d,
        unsigned int n)
{
    unsigned int bytes = n*sizeof(float);

    // events for timing
    cudaEvent_t startEvent, stopEvent;

    checkCuda(cudaEventCreate(&startEvent));
    checkCuda(cudaEventCreate(&stopEvent));

    checkCuda(cudaEventRecord(startEvent, 0));
    checkCuda(cudaMemcpy(d, h_a, bytes, cudaMemcpyHostToDevice));
    checkCuda(cudaEventRecord(stopEvent, 0));
    checkCuda(cudaEventSynchronize(stopEvent));
	
    //times are in miliseconds
    float timeh2d, timed2h;
    checkCuda(cudaEventElapsedTime(&timeh2d, startEvent, stopEvent));

    checkCuda(cudaEventRecord(startEvent, 0));
    checkCuda(cudaMemcpy(h_b, d, bytes, cudaMemcpyDeviceToHost));
    checkCuda(cudaEventRecord(stopEvent, 0));
    checkCuda(cudaEventSynchronize(stopEvent));

    checkCuda(cudaEventElapsedTime(&timed2h, startEvent, stopEvent));

    for (int i = 0; i<n; ++i) {
        if (h_a[i]!=h_b[i]) {
            printf("*** transfers failed ***");
            break;
        }
    }

    // clean up events
    checkCuda(cudaEventDestroy(startEvent));
    checkCuda(cudaEventDestroy(stopEvent));
    return std::make_pair(timeh2d,timed2h);
}

int main()
{
    size_t kb = 1024;
    size_t GB = kb*kb*kb;
    std::vector<size_t> sizes;
    for (size_t current = kb; current<=GB; current *= 2)
        sizes.push_back(current/sizeof(float));

    std::cout << "#Size; H2DPage; H2DPin; D2HPage; D2HPin" << std::endl;

    for (unsigned int nElements: sizes) {
        const unsigned int bytes = nElements*sizeof(float);

        // host arrays
        float* h_aPageable, * h_bPageable;
        float* h_aPinned, * h_bPinned;

        // device array
        float* d_a;

        // allocate and initialize
        h_aPageable = (float*) malloc(bytes);                    // host pageable
        h_bPageable = (float*) malloc(bytes);                    // host pageable
        checkCuda(cudaMallocHost((void**) &h_aPinned, bytes)); // host pinned
        checkCuda(cudaMallocHost((void**) &h_bPinned, bytes)); // host pinned
        checkCuda(cudaMalloc((void**) &d_a, bytes));           // device

        for (int i = 0; i<nElements; ++i) h_aPageable[i] = i;
        memcpy(h_aPinned, h_aPageable, bytes);
        memset(h_bPageable, 0, bytes);
        memset(h_bPinned, 0, bytes);

        // output device info and transfer size
        cudaDeviceProp prop;
        checkCuda(cudaGetDeviceProperties(&prop, 0));


        // perform copies and report bandwidth
        auto tPage = profileCopies(h_aPageable, h_bPageable, d_a, nElements);
        auto tPinned = profileCopies(h_aPinned, h_bPinned, d_a, nElements);

        std::cout << bytes << ";"
                  << tPage.first << ";"
                  << tPinned.first << ";"
                  << tPage.second << ";"
                  << tPinned.second << std::endl;


        // cleanup
        cudaFree(d_a);
        cudaFreeHost(h_aPinned);
        cudaFreeHost(h_bPinned);
        free(h_aPageable);
        free(h_bPageable);
    }
    return 0;
}

	.file	"tmpxft_00296a9e_00000000-6_memory_modnvidia.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4023:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4023:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"*** transfers failed ***"
	.text
	.globl	_Z13profileCopiesPfS_S_j
	.type	_Z13profileCopiesPfS_S_j, @function
_Z13profileCopiesPfS_S_j:
.LFB4000:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	%ecx, %ebx
	leal	0(,%rbx,4), %r14d
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$1, %ecx
	movq	%r14, %rdx
	movq	%rbp, %rsi
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	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
	movq	%rsp, %rdi
	call	cudaEventElapsedTime@PLT
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$2, %ecx
	movq	%r14, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	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
	xorl	%eax, %eax
.L3:
	cmpl	%ebx, %eax
	jnb	.L5
	movss	0(%rbp,%rax,4), %xmm0
	incq	%rax
	ucomiss	-4(%r12,%rax,4), %xmm0
	jp	.L8
	je	.L3
.L8:
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L5:
	movq	8(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	16(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	4(%rsp), %edx
	movl	(%rsp), %eax
	salq	$32, %rdx
	orq	%rdx, %rax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	addq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%rax, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4000:
	.size	_Z13profileCopiesPfS_S_j, .-_Z13profileCopiesPfS_S_j
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4046:
	.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
.LFE4046:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZNSt6vectorImSaImEED2Ev,"axG",@progbits,_ZNSt6vectorImSaImEED5Ev,comdat
	.align 2
	.weak	_ZNSt6vectorImSaImEED2Ev
	.type	_ZNSt6vectorImSaImEED2Ev, @function
_ZNSt6vectorImSaImEED2Ev:
.LFB4356:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	testq	%rax, %rax
	je	.L14
	movq	16(%rdi), %rsi
	movq	%rax, %rdi
	subq	%rax, %rsi
	jmp	_ZdlPvm@PLT
.L14:
	ret
	.cfi_endproc
.LFE4356:
	.size	_ZNSt6vectorImSaImEED2Ev, .-_ZNSt6vectorImSaImEED2Ev
	.weak	_ZNSt6vectorImSaImEED1Ev
	.set	_ZNSt6vectorImSaImEED1Ev,_ZNSt6vectorImSaImEED2Ev
	.section	.rodata._ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_.str1.1,"aMS",@progbits,1
.LC1:
	.string	"vector::_M_realloc_insert"
	.section	.text._ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_,"axG",@progbits,_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_,comdat
	.align 2
	.weak	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
	.type	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_, @function
_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_:
.LFB4625:
	.cfi_startproc
	endbr64
	movabsq	$1152921504606846975, %rcx
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	8(%rdi), %rax
	movq	(%rdi), %r14
	movq	%rax, %rbx
	movq	%rax, (%rsp)
	subq	%r14, %rbx
	sarq	$3, %rbx
	cmpq	%rcx, %rbx
	jne	.L17
	leaq	.LC1(%rip), %rdi
	call	_ZSt20__throw_length_errorPKc@PLT
.L17:
	cmpq	%r14, (%rsp)
	movl	$1, %eax
	movq	%rsi, %r15
	movq	%rdi, %r13
	cmovne	%rbx, %rax
	movq	%rsi, %rbp
	addq	%rax, %rbx
	setc	%al
	subq	%r14, %r15
	movzbl	%al, %eax
	testq	%rax, %rax
	jne	.L27
	xorl	%r12d, %r12d
	testq	%rbx, %rbx
	je	.L22
	movabsq	$1152921504606846975, %rax
	cmpq	%rax, %rbx
	cmova	%rax, %rbx
	jmp	.L21
.L27:
	movq	%rcx, %rbx
.L21:
	leaq	0(,%rbx,8), %rdi
	movq	%rdx, 8(%rsp)
	call	_Znwm@PLT
	movq	8(%rsp), %rdx
	movq	%rax, %r12
.L22:
	movq	(%rdx), %rax
	movq	%rax, (%r12,%r15)
	testq	%r15, %r15
	jle	.L23
	movq	%r15, %rdx
	movq	%r14, %rsi
	movq	%r12, %rdi
	call	memmove@PLT
.L23:
	movq	(%rsp), %rax
	leaq	8(%r12,%r15), %rdx
	subq	%rbp, %rax
	testq	%rax, %rax
	jle	.L24
	movq	%rdx, %rdi
	movq	%rbp, %rsi
	movq	%rax, %rcx
	rep movsb
.L24:
	leaq	(%rdx,%rax), %rbp
	testq	%r14, %r14
	je	.L25
	movq	16(%r13), %rsi
	movq	%r14, %rdi
	subq	%r14, %rsi
	call	_ZdlPvm@PLT
.L25:
	leaq	(%r12,%rbx,8), %rax
	movq	%r12, 0(%r13)
	movq	%rbp, 8(%r13)
	movq	%rax, 16(%r13)
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4625:
	.size	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_, .-_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
	.section	.rodata.str1.1
.LC2:
	.string	"#Size; H2DPage; H2DPin; D2HPage; D2HPin"
.LC3:
	.string	";"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4010:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4010
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	$21, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$1024, %ebx
	subq	$1112, %rsp
	.cfi_def_cfa_offset 1168
	movq	%fs:40, %rax
	movq	%rax, 1096(%rsp)
	xorl	%eax, %eax
	xorl	%eax, %eax
	leaq	32(%rsp), %r12
	movq	%rax, 40(%rsp)
	movq	%rax, 48(%rsp)
	movq	%rax, 56(%rsp)
.L37:
	movq	%rbx, %rax
	movq	48(%rsp), %rsi
	shrq	$2, %rax
	movq	%rax, 32(%rsp)
	cmpq	56(%rsp), %rsi
	je	.L35
	movq	%rax, (%rsi)
	addq	$8, %rsi
	movq	%rsi, 48(%rsp)
	jmp	.L36
.L35:
	leaq	40(%rsp), %rdi
	movq	%r12, %rdx
.LEHB0:
	call	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
.L36:
	addq	%rbx, %rbx
	decl	%ebp
	jne	.L37
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	48(%rsp), %r15
	movq	40(%rsp), %r14
.L38:
	cmpq	%r14, %r15
	je	.L51
	movq	(%r14), %rax
	leal	0(,%rax,4), %ebx
	movl	%eax, %ebp
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	leaq	16(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMallocHost@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMallocHost@PLT
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	xorl	%eax, %eax
.L39:
	cmpl	%ebp, %eax
	jnb	.L52
	cvtsi2ssl	%eax, %xmm0
	movss	%xmm0, 0(%r13,%rax,4)
	incq	%rax
	jmp	.L39
.L52:
	movq	16(%rsp), %rdi
	movq	%r13, %rsi
	movq	%rbx, %rcx
	movq	%rbx, %rdx
	rep movsb
	movq	8(%rsp), %rdi
	movq	%rbx, %rcx
	xorl	%esi, %esi
	call	__memset_chk@PLT
	movq	24(%rsp), %rdi
	xorl	%eax, %eax
	movq	%rbx, %rcx
	xorl	%esi, %esi
	rep stosb
	leaq	64(%rsp), %rdi
	call	cudaGetDeviceProperties_v2@PLT
	movq	32(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	%ebp, %ecx
	movq	%r13, %rdi
	call	_Z13profileCopiesPfS_S_j
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	movl	%ebp, %ecx
	movq	%xmm0, %r12
	movq	16(%rsp), %rdi
	call	_Z13profileCopiesPfS_S_j
	movq	%rbx, %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%xmm0, %rbp
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC3(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%r12d, %xmm0
	movq	%rax, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC3(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%ebp, %xmm0
	movq	%rax, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC3(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	shrq	$32, %r12
	movq	%rax, %rdi
	movd	%r12d, %xmm1
	cvtss2sd	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC3(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	shrq	$32, %rbp
	movq	%rax, %rdi
	movd	%ebp, %xmm2
	cvtss2sd	%xmm2, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	24(%rsp), %rdi
	call	cudaFreeHost@PLT
.LEHE0:
	movq	%r13, %rdi
	addq	$8, %r14
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	jmp	.L38
.L51:
	leaq	40(%rsp), %rdi
	call	_ZNSt6vectorImSaImEED1Ev
	movq	1096(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	jmp	.L49
.L46:
	endbr64
	movq	%rax, %rbx
.L42:
	leaq	40(%rsp), %rdi
	call	_ZNSt6vectorImSaImEED1Ev
	movq	1096(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L49
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L49:
	call	__stack_chk_fail@PLT
.L44:
	addq	$1112, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4010:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4010:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4010-.LLSDACSB4010
.LLSDACSB4010:
	.uleb128 .LEHB0-.LFB4010
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L46-.LFB4010
	.uleb128 0
	.uleb128 .LEHB1-.LFB4010
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE4010:
	.section	.text.startup
	.size	main, .-main
	.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
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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:

/* Copyright (c) 1993-2015, NVIDIA CORPORATION. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  * Neither the name of NVIDIA CORPORATION nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <assert.h>
#include <vector>
#include <utility>
#include <iostream>

// Convenience function for checking CUDA runtime API results
// can be wrapped around any runtime API call. No-op in release builds.
inline
hipError_t checkCuda(hipError_t result)
{
#if defined(DEBUG) || defined(_DEBUG)
    if (result != hipSuccess) {
      fprintf(stderr, "CUDA Runtime Error: %s\n", hipGetErrorString(result));
      assert(result == hipSuccess);
    }
#endif
    return result;
}

std::pair<float,float> profileCopies(float* h_a,
        float* h_b,
        float* d,
        unsigned int n)
{
    unsigned int bytes = n*sizeof(float);

    // events for timing
    hipEvent_t startEvent, stopEvent;

    checkCuda(hipEventCreate(&startEvent));
    checkCuda(hipEventCreate(&stopEvent));

    checkCuda(hipEventRecord(startEvent, 0));
    checkCuda(hipMemcpy(d, h_a, bytes, hipMemcpyHostToDevice));
    checkCuda(hipEventRecord(stopEvent, 0));
    checkCuda(hipEventSynchronize(stopEvent));
	
    //times are in miliseconds
    float timeh2d, timed2h;
    checkCuda(hipEventElapsedTime(&timeh2d, startEvent, stopEvent));

    checkCuda(hipEventRecord(startEvent, 0));
    checkCuda(hipMemcpy(h_b, d, bytes, hipMemcpyDeviceToHost));
    checkCuda(hipEventRecord(stopEvent, 0));
    checkCuda(hipEventSynchronize(stopEvent));

    checkCuda(hipEventElapsedTime(&timed2h, startEvent, stopEvent));

    for (int i = 0; i<n; ++i) {
        if (h_a[i]!=h_b[i]) {
            printf("*** transfers failed ***");
            break;
        }
    }

    // clean up events
    checkCuda(hipEventDestroy(startEvent));
    checkCuda(hipEventDestroy(stopEvent));
    return std::make_pair(timeh2d,timed2h);
}

int main()
{
    size_t kb = 1024;
    size_t GB = kb*kb*kb;
    std::vector<size_t> sizes;
    for (size_t current = kb; current<=GB; current *= 2)
        sizes.push_back(current/sizeof(float));

    std::cout << "#Size; H2DPage; H2DPin; D2HPage; D2HPin" << std::endl;

    for (unsigned int nElements: sizes) {
        const unsigned int bytes = nElements*sizeof(float);

        // host arrays
        float* h_aPageable, * h_bPageable;
        float* h_aPinned, * h_bPinned;

        // device array
        float* d_a;

        // allocate and initialize
        h_aPageable = (float*) malloc(bytes);                    // host pageable
        h_bPageable = (float*) malloc(bytes);                    // host pageable
        checkCuda(hipHostMalloc((void**) &h_aPinned, bytes, hipHostMallocDefault)); // host pinned
        checkCuda(hipHostMalloc((void**) &h_bPinned, bytes, hipHostMallocDefault)); // host pinned
        checkCuda(hipMalloc((void**) &d_a, bytes));           // device

        for (int i = 0; i<nElements; ++i) h_aPageable[i] = i;
        memcpy(h_aPinned, h_aPageable, bytes);
        memset(h_bPageable, 0, bytes);
        memset(h_bPinned, 0, bytes);

        // output device info and transfer size
        hipDeviceProp_t prop;
        checkCuda(hipGetDeviceProperties(&prop, 0));


        // perform copies and report bandwidth
        auto tPage = profileCopies(h_aPageable, h_bPageable, d_a, nElements);
        auto tPinned = profileCopies(h_aPinned, h_bPinned, d_a, nElements);

        std::cout << bytes << ";"
                  << tPage.first << ";"
                  << tPinned.first << ";"
                  << tPage.second << ";"
                  << tPinned.second << std::endl;


        // cleanup
        hipFree(d_a);
        hipHostFree(h_aPinned);
        hipHostFree(h_bPinned);
        free(h_aPageable);
        free(h_bPageable);
    }
    return 0;
}

	.text
	.file	"memory_modnvidia.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z13profileCopiesPfS_S_j        # -- Begin function _Z13profileCopiesPfS_S_j
	.type	_Z13profileCopiesPfS_S_j,@function
_Z13profileCopiesPfS_S_j:               # @_Z13profileCopiesPfS_S_j
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
                                        # kill: def $ecx killed $ecx def $rcx
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	movq	%rdx, %rbp
	movq	%rsi, %rbx
	movq	%rdi, %r14
	leal	(,%rcx,4), %r15d
	leaq	32(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	24(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbp, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rsi
	movq	(%r13), %rdx
	leaq	12(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	%rbx, %rdi
	movq	%rbp, %rsi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r13), %rdi
	callq	hipEventSynchronize
	movq	(%r12), %rsi
	movq	(%r13), %rdx
	leaq	8(%rsp), %rdi
	callq	hipEventElapsedTime
	movq	16(%rsp), %rax                  # 8-byte Reload
	testl	%eax, %eax
	je	.LBB0_5
# %bb.1:                                # %.lr.ph.preheader
	movl	%eax, %eax
	xorl	%ecx, %ecx
.LBB0_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r14,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	(%rbx,%rcx,4), %xmm0
	jne	.LBB0_4
	jp	.LBB0_4
# %bb.2:                                #   in Loop: Header=BB0_3 Depth=1
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB0_3
	jmp	.LBB0_5
.LBB0_4:
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
.LBB0_5:                                # %.loopexit
	movq	32(%rsp), %rdi
	callq	hipEventDestroy
	movq	24(%rsp), %rdi
	callq	hipEventDestroy
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	8(%rsp), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	unpcklps	%xmm1, %xmm0                    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z13profileCopiesPfS_S_j, .Lfunc_end0-_Z13profileCopiesPfS_S_j
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$1576, %rsp                     # imm = 0x628
	.cfi_def_cfa_offset 1632
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorps	%xmm0, %xmm0
	leaq	32(%rsp), %rbx
	movaps	%xmm0, (%rbx)
	movq	$0, 16(%rbx)
	movl	$1024, %r15d                    # imm = 0x400
	leaq	104(%rsp), %r14
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rax
	shrq	$2, %rax
	movq	%rax, 104(%rsp)
	movq	40(%rsp), %rsi
	cmpq	48(%rsp), %rsi
	je	.LBB1_3
# %bb.2:                                #   in Loop: Header=BB1_1 Depth=1
	movq	%rax, (%rsi)
	addq	$8, %rsi
	movq	%rsi, 40(%rsp)
	jmp	.LBB1_4
.LBB1_3:                                #   in Loop: Header=BB1_1 Depth=1
.Ltmp0:
	movq	%rbx, %rdi
	movq	%r14, %rdx
	callq	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
.Ltmp1:
.LBB1_4:                                # %_ZNSt6vectorImSaImEE9push_backEOm.exit
                                        #   in Loop: Header=BB1_1 Depth=1
	leaq	(%r15,%r15), %rax
	cmpq	$536870913, %r15                # imm = 0x20000001
	movq	%rax, %r15
	jb	.LBB1_1
# %bb.5:
.Ltmp3:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$39, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp4:
# %bb.6:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movq	_ZSt4cout(%rip), %rax
	addq	-24(%rax), %rbx
.Ltmp5:
	movq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp6:
# %bb.7:                                # %.noexc70
.Ltmp7:
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp8:
# %bb.8:                                # %.noexc71
.Ltmp9:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp10:
# %bb.9:                                # %_ZNSolsEPFRSoS_E.exit
	movq	32(%rsp), %rbx
	movq	40(%rsp), %r13
	cmpq	%r13, %rbx
	je	.LBB1_36
.LBB1_10:                               # %.lr.ph84
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_15 Depth 2
	movq	(%rbx), %r12
	leal	(,%r12,4), %r15d
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %rbp
	movq	%r15, %rdi
	callq	malloc
	movq	%rax, %r14
.Ltmp12:
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
.Ltmp13:
# %bb.11:                               #   in Loop: Header=BB1_10 Depth=1
.Ltmp14:
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
.Ltmp15:
# %bb.12:                               #   in Loop: Header=BB1_10 Depth=1
.Ltmp16:
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
.Ltmp17:
# %bb.13:                               # %.preheader
                                        #   in Loop: Header=BB1_10 Depth=1
	testl	%r12d, %r12d
	je	.LBB1_16
# %bb.14:                               # %.lr.ph.preheader
                                        #   in Loop: Header=BB1_10 Depth=1
	movl	%r12d, %eax
	xorl	%ecx, %ecx
.LBB1_15:                               # %.lr.ph
                                        #   Parent Loop BB1_10 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	movss	%xmm0, (%rbp,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB1_15
.LBB1_16:                               # %._crit_edge
                                        #   in Loop: Header=BB1_10 Depth=1
	movq	24(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%r15, %rdx
	callq	memcpy@PLT
	movq	%r14, %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
.Ltmp19:
	leaq	104(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
.Ltmp20:
# %bb.17:                               #   in Loop: Header=BB1_10 Depth=1
	movq	8(%rsp), %rdx
.Ltmp22:
	movq	%rbp, %rdi
	movq	%r14, %rsi
	movl	%r12d, %ecx
	callq	_Z13profileCopiesPfS_S_j
	movaps	%xmm0, 80(%rsp)                 # 16-byte Spill
.Ltmp23:
# %bb.18:                               #   in Loop: Header=BB1_10 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
.Ltmp25:
	movl	%r12d, %ecx
	callq	_Z13profileCopiesPfS_S_j
	movaps	%xmm0, 64(%rsp)                 # 16-byte Spill
.Ltmp26:
# %bb.19:                               #   in Loop: Header=BB1_10 Depth=1
.Ltmp27:
	movl	$_ZSt4cout, %edi
	movq	%r15, %rsi
	callq	_ZNSo9_M_insertImEERSoT_
.Ltmp28:
# %bb.20:                               # %_ZNSolsEj.exit
                                        #   in Loop: Header=BB1_10 Depth=1
.Ltmp29:
	movq	%rax, %r15
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp30:
# %bb.21:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit52
                                        #   in Loop: Header=BB1_10 Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	80(%rsp), %xmm0                 # 16-byte Folded Reload
.Ltmp31:
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp32:
# %bb.22:                               # %_ZNSolsEf.exit
                                        #   in Loop: Header=BB1_10 Depth=1
.Ltmp33:
	movq	%rax, %r15
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp34:
# %bb.23:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit55
                                        #   in Loop: Header=BB1_10 Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	64(%rsp), %xmm0                 # 16-byte Folded Reload
.Ltmp35:
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp36:
# %bb.24:                               # %_ZNSolsEf.exit57
                                        #   in Loop: Header=BB1_10 Depth=1
.Ltmp37:
	movq	%rax, %r15
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp38:
# %bb.25:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit59
                                        #   in Loop: Header=BB1_10 Depth=1
	movaps	80(%rsp), %xmm0                 # 16-byte Reload
	shufps	$85, %xmm0, %xmm0               # xmm0 = xmm0[1,1,1,1]
	cvtss2sd	%xmm0, %xmm0
.Ltmp39:
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp40:
# %bb.26:                               # %_ZNSolsEf.exit61
                                        #   in Loop: Header=BB1_10 Depth=1
.Ltmp41:
	movq	%rax, %r15
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp42:
# %bb.27:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit63
                                        #   in Loop: Header=BB1_10 Depth=1
	movaps	64(%rsp), %xmm0                 # 16-byte Reload
	shufps	$85, %xmm0, %xmm0               # xmm0 = xmm0[1,1,1,1]
	cvtss2sd	%xmm0, %xmm0
.Ltmp43:
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp44:
# %bb.28:                               # %_ZNSolsEf.exit65
                                        #   in Loop: Header=BB1_10 Depth=1
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
.Ltmp45:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp46:
# %bb.29:                               # %.noexc73
                                        #   in Loop: Header=BB1_10 Depth=1
.Ltmp47:
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
.Ltmp48:
# %bb.30:                               # %.noexc74
                                        #   in Loop: Header=BB1_10 Depth=1
.Ltmp49:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp50:
# %bb.31:                               # %_ZNSolsEPFRSoS_E.exit67
                                        #   in Loop: Header=BB1_10 Depth=1
	movq	8(%rsp), %rdi
.Ltmp51:
	callq	hipFree
.Ltmp52:
# %bb.32:                               #   in Loop: Header=BB1_10 Depth=1
	movq	24(%rsp), %rdi
.Ltmp53:
	callq	hipHostFree
.Ltmp54:
# %bb.33:                               #   in Loop: Header=BB1_10 Depth=1
	movq	16(%rsp), %rdi
.Ltmp55:
	callq	hipHostFree
.Ltmp56:
# %bb.34:                               #   in Loop: Header=BB1_10 Depth=1
	movq	%rbp, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	addq	$8, %rbx
	cmpq	%r13, %rbx
	jne	.LBB1_10
# %bb.35:                               # %._crit_edge85.loopexit
	movq	32(%rsp), %rbx
.LBB1_36:                               # %._crit_edge85
	testq	%rbx, %rbx
	je	.LBB1_38
# %bb.37:
	movq	%rbx, %rdi
	callq	_ZdlPv
.LBB1_38:                               # %_ZNSt6vectorImSaImEED2Ev.exit
	xorl	%eax, %eax
	addq	$1576, %rsp                     # imm = 0x628
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_39:
	.cfi_def_cfa_offset 1632
.Ltmp11:
	jmp	.LBB1_44
.LBB1_47:
.Ltmp2:
	jmp	.LBB1_44
.LBB1_41:
.Ltmp21:
	jmp	.LBB1_44
.LBB1_42:
.Ltmp24:
	jmp	.LBB1_44
.LBB1_40:
.Ltmp18:
	jmp	.LBB1_44
.LBB1_43:
.Ltmp57:
.LBB1_44:
	movq	%rax, %rbx
	movq	32(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB1_46
# %bb.45:
	callq	_ZdlPv
.LBB1_46:                               # %_ZNSt6vectorImSaImEED2Ev.exit69
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table1:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp10-.Ltmp3                 #   Call between .Ltmp3 and .Ltmp10
	.uleb128 .Ltmp11-.Lfunc_begin0          #     jumps to .Ltmp11
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin0          # >> Call Site 3 <<
	.uleb128 .Ltmp17-.Ltmp12                #   Call between .Ltmp12 and .Ltmp17
	.uleb128 .Ltmp18-.Lfunc_begin0          #     jumps to .Ltmp18
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp17-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp19-.Ltmp17                #   Call between .Ltmp17 and .Ltmp19
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp19-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp20-.Ltmp19                #   Call between .Ltmp19 and .Ltmp20
	.uleb128 .Ltmp21-.Lfunc_begin0          #     jumps to .Ltmp21
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp22-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp23-.Ltmp22                #   Call between .Ltmp22 and .Ltmp23
	.uleb128 .Ltmp24-.Lfunc_begin0          #     jumps to .Ltmp24
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp25-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp56-.Ltmp25                #   Call between .Ltmp25 and .Ltmp56
	.uleb128 .Ltmp57-.Lfunc_begin0          #     jumps to .Ltmp57
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp56-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Lfunc_end1-.Ltmp56            #   Call between .Ltmp56 and .Lfunc_end1
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_,"axG",@progbits,_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_,comdat
	.weak	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_ # -- Begin function _ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
	.p2align	1, 0x90
	.type	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_,@function
_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_: # @_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, (%rsp)                    # 8-byte Spill
	movq	%rsi, %r12
	movq	%rdi, %rbx
	movl	$1, %esi
	movl	$.L.str.3, %edx
	callq	_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc
	movq	(%rbx), %r13
	movq	8(%rbx), %r15
	movq	%r12, 8(%rsp)                   # 8-byte Spill
	subq	%r13, %r12
	movq	%r12, %r14
	sarq	$3, %r14
	testq	%rax, %rax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	je	.LBB2_1
# %bb.2:
	movq	%rbx, %rdi
	movq	%rax, %rsi
	xorl	%edx, %edx
	callq	_ZNSt15__new_allocatorImE8allocateEmPKv
	movq	%rax, %rbp
	jmp	.LBB2_3
.LBB2_1:
	xorl	%ebp, %ebp
.LBB2_3:                                # %_ZNSt12_Vector_baseImSaImEE11_M_allocateEm.exit
	movq	(%rsp), %rax                    # 8-byte Reload
	movq	(%rax), %rax
	movq	%rax, (%rbp,%r14,8)
	testq	%r12, %r12
	jle	.LBB2_5
# %bb.4:
	movq	%rbp, %rdi
	movq	%r13, %rsi
	movq	%r12, %rdx
	callq	memmove@PLT
.LBB2_5:                                # %_ZNSt6vectorImSaImEE11_S_relocateEPmS2_S2_RS0_.exit
	addq	%rbp, %r12
	addq	$8, %r12
	movq	8(%rsp), %rsi                   # 8-byte Reload
	subq	%rsi, %r15
	testq	%r15, %r15
	jle	.LBB2_7
# %bb.6:
	movq	%r12, %rdi
	movq	%r15, %rdx
	callq	memmove@PLT
.LBB2_7:                                # %_ZNSt6vectorImSaImEE11_S_relocateEPmS2_S2_RS0_.exit16
	testq	%r13, %r13
	je	.LBB2_9
# %bb.8:
	movq	%r13, %rdi
	callq	_ZdlPv
.LBB2_9:                                # %_ZNSt12_Vector_baseImSaImEE13_M_deallocateEPmm.exit
	addq	%r15, %r12
	movq	%rbp, (%rbx)
	movq	%r12, 8(%rbx)
	movq	16(%rsp), %rax                  # 8-byte Reload
	leaq	(,%rax,8), %rax
	addq	%rbp, %rax
	movq	%rax, 16(%rbx)
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_, .Lfunc_end2-_ZNSt6vectorImSaImEE17_M_realloc_insertIJmEEEvN9__gnu_cxx17__normal_iteratorIPmS1_EEDpOT_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNKSt6vectorImSaImEE12_M_check_lenEmPKc,"axG",@progbits,_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc,comdat
	.weak	_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc # -- Begin function _ZNKSt6vectorImSaImEE12_M_check_lenEmPKc
	.p2align	1, 0x90
	.type	_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc,@function
_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc: # @_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc
	.cfi_startproc
# %bb.0:
	movabsq	$1152921504606846975, %rcx      # imm = 0xFFFFFFFFFFFFFFF
	movq	8(%rdi), %r8
	subq	(%rdi), %r8
	sarq	$3, %r8
	movq	%rcx, %rax
	subq	%r8, %rax
	cmpq	%rsi, %rax
	jb	.LBB3_2
# %bb.1:
	cmpq	%rsi, %r8
	cmovaq	%r8, %rsi
	leaq	(%rsi,%r8), %rax
	cmpq	%rcx, %rax
	cmovaeq	%rcx, %rax
	addq	%r8, %rsi
	cmovbq	%rcx, %rax
	retq
.LBB3_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rdx, %rdi
	callq	_ZSt20__throw_length_errorPKc
.Lfunc_end3:
	.size	_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc, .Lfunc_end3-_ZNKSt6vectorImSaImEE12_M_check_lenEmPKc
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt15__new_allocatorImE8allocateEmPKv,"axG",@progbits,_ZNSt15__new_allocatorImE8allocateEmPKv,comdat
	.weak	_ZNSt15__new_allocatorImE8allocateEmPKv # -- Begin function _ZNSt15__new_allocatorImE8allocateEmPKv
	.p2align	1, 0x90
	.type	_ZNSt15__new_allocatorImE8allocateEmPKv,@function
_ZNSt15__new_allocatorImE8allocateEmPKv: # @_ZNSt15__new_allocatorImE8allocateEmPKv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rsi, %rax
	shrq	$60, %rax
	jne	.LBB4_1
# %bb.3:
	shlq	$3, %rsi
	movq	%rsi, %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	_Znwm                           # TAILCALL
.LBB4_1:
	.cfi_def_cfa_offset 16
	shrq	$61, %rsi
	je	.LBB4_2
# %bb.4:
	callq	_ZSt28__throw_bad_array_new_lengthv
.LBB4_2:
	callq	_ZSt17__throw_bad_allocv
.Lfunc_end4:
	.size	_ZNSt15__new_allocatorImE8allocateEmPKv, .Lfunc_end4-_ZNSt15__new_allocatorImE8allocateEmPKv
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"*** transfers failed ***"
	.size	.L.str, 25

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"#Size; H2DPage; H2DPin; D2HPage; D2HPin"
	.size	.L.str.1, 40

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	";"
	.size	.L.str.2, 2

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"vector::_M_realloc_insert"
	.size	.L.str.3, 26

	.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 __gxx_personality_v0
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt4cout
	.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
