#include<iostream>
#include<chrono>
#include<memory>
#include<string>
#include<cuda_runtime.h>


class TimeIt{
private:
    std::chrono::time_point<std::chrono::system_clock> start_time;

public:
    TimeIt();
    ~TimeIt();
};

TimeIt::TimeIt() {
    this->start_time = std::chrono::system_clock::now();
}

TimeIt::~TimeIt() {
    auto end_time = std::chrono::system_clock::now();

    auto duration_time = std::chrono::duration_cast<std::chrono::microseconds>(
        end_time - this->start_time
    ).count();

    std::cout << duration_time << " us" << std::endl;
}


__global__
void vector_add(const float *X, const float *Y, float *Z, int nEle) {
    int i = blockDim.x * blockIdx.x + threadIdx.x;

    if (i < nEle) {
        Z[i] = X[i] + Y[i];
    }
}

float * initialize_host_vector(int nEle) {
    size_t mem_size = nEle * sizeof(float);

    float * h_V = (float *)malloc(mem_size);

    if (h_V == NULL) {
        fprintf(stderr, "Failed to allocate host vectors!\n");
        exit(EXIT_FAILURE);
    }

    return h_V;
}

void randomize_host_vector(float * h_V, int nEle) {
    for (int i = 0; i < nEle; ++i) {
        h_V[i] = rand()/(float)RAND_MAX;
    }
}

float * initialize_random_host_vector(int nEle) {
    float * h_V = initialize_host_vector(nEle);
    randomize_host_vector(h_V, nEle);

    return h_V;
}

float * initialize_device_vector(int nEle) {
    size_t mem_size = nEle * sizeof(float);

    cudaError_t err = cudaSuccess;
    float * d_V = nullptr;
    err = cudaMalloc((void **)&d_V, mem_size);
    if (err != cudaSuccess) {
        fprintf(
            stderr,
            "Failed to allocate device vector (error code %s)!\n",
            cudaGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return d_V;
}

float * host_vector_to_device(float * h_V, int nEle) {
    size_t mem_size = nEle * sizeof(float);

    float * d_V = initialize_device_vector(nEle);

    cudaError_t err = cudaSuccess;
    {
        std::cout << "Host to device copy ";
        auto tmr = TimeIt();
        err = cudaMemcpy(d_V, h_V, mem_size, cudaMemcpyHostToDevice);
    }
    if (err != cudaSuccess) {
        fprintf(
            stderr,
            "Failed to copy vector from host to device (error code %s)!\n",
            cudaGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return d_V;
}

float * device_vector_to_host(float * d_V, int nEle) {
    size_t mem_size = nEle * sizeof(float);

    float * h_V = initialize_host_vector(nEle);

    cudaError_t err = cudaSuccess;
    {
        std::cout << "Device to host copy ";
        auto tmr = TimeIt();
        err = cudaMemcpy(h_V, d_V, mem_size, cudaMemcpyDeviceToHost);
    }
    if (err != cudaSuccess) {
        fprintf(
            stderr,
            "Failed to copy vector from device to host (error code %s)!\n",
            cudaGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return h_V;
}

int getBlocksPerGrid(int nEle, int threadsPerBlock) {
    return (nEle + threadsPerBlock - 1) / threadsPerBlock;
}

float * add_device_vectors(
    const float * d_X, const float * d_Y, int nEle, int threadsPerBlock
) {
    float * d_Z = initialize_device_vector(nEle);
    int blocksPerGrid = getBlocksPerGrid(nEle, threadsPerBlock);
    {
        std::cout << "Vector addition on device ";
        auto tmr = TimeIt();
        vector_add<<<blocksPerGrid, threadsPerBlock>>>(d_X, d_Y, d_Z, nEle);
    }
    cudaError_t err = cudaSuccess;
    err = cudaGetLastError();
    if (err != cudaSuccess) {
        fprintf(
            stderr,
            "Failed to launch vector_add kernel (error code %s)!\n",
            cudaGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return d_Z;
}

float * add_host_vectors(const float * h_X, const float * h_Y, int nEle) {
    float * hZ_ = initialize_host_vector(nEle);
    {
        std::cout << "Vector addition on host ";
        auto tmr = TimeIt();
        for (int i=0; i < nEle; i++) {
            hZ_[i] = h_X[i] + h_Y[i];
        }
    }
    return hZ_;
}

void freeCudaVector(float * d_V) {
    cudaError_t err = cudaSuccess;
    cudaFree(d_V);
    if (err != cudaSuccess) {
        fprintf(
            stderr,
            "Failed to free device vector (error code %s)!\n",
            cudaGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }
}

bool match_host_and_device_results(
    const float * h_Z, const float * hZ_, int nEle
) {
    bool verified = true;
    for (int i=0; i < nEle; i++) {
        if (fabs(h_Z[i] - hZ_[i]) > 1e-5) {
            verified = false;
        }
    }
    return verified;
}

void print_host_vector(const float * h_V, const int nEle, std::string mesg) {
    std::cout << mesg << ": ";

    for (int i=0; i < nEle; i++) {
        std::cout << h_V[i] << ",";
    }

    std::cout << std::endl;
}

int main(void) {
    std::cout << "Vector addition code using CUDA!" << std::endl;

    int nEle = 10000000;
    int threadsPerBlock = 256;

    float * h_X = initialize_random_host_vector(nEle);
    float * h_Y = initialize_random_host_vector(nEle);

    float * d_X = host_vector_to_device(h_X, nEle);
    float * d_Y = host_vector_to_device(h_Y, nEle);

    float * d_Z = add_device_vectors(d_X, d_Y, nEle, threadsPerBlock);

    float * h_Z = device_vector_to_host(d_Z, nEle);
    float * hZ_ = add_host_vectors(h_X, h_Y, nEle);

    bool verified = match_host_and_device_results(h_Z, hZ_, nEle);
    if (verified) {
        std::cout << "Results matched on host and device" << std::endl;
    } else {
        std::cerr << "Results did NOT match on host and device" << std::endl;
    }

#if defined(DEBUG)
    print_host_vector(h_X, nEle, "h_X");
    print_host_vector(h_Y, nEle, "h_Y");
    print_host_vector(h_Z, nEle, "h_Z");
    print_host_vector(hZ_, nEle, "hZ_");
#endif

    free(h_X);
    free(h_Y);
    free(h_Z);
    free(hZ_);

    freeCudaVector(d_X);
    freeCudaVector(d_Y);
    freeCudaVector(d_Z);

    return 0;
}

	.file	"tmpxft_002a9ab9_00000000-6_vector_add.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4400:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4400:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5133:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5133:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.align 2
	.globl	_ZN6TimeItC2Ev
	.type	_ZN6TimeItC2Ev, @function
_ZN6TimeItC2Ev:
.LFB4380:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	movq	%rax, (%rdi)
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	%rax, (%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4380:
	.size	_ZN6TimeItC2Ev, .-_ZN6TimeItC2Ev
	.globl	_ZN6TimeItC1Ev
	.set	_ZN6TimeItC1Ev,_ZN6TimeItC2Ev
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" us"
	.text
	.align 2
	.globl	_ZN6TimeItD2Ev
	.type	_ZN6TimeItD2Ev, @function
_ZN6TimeItD2Ev:
.LFB4383:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4383
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	subq	(%rbx), %rax
	movl	$1000, %ecx
	leaq	_ZSt4cout(%rip), %rdi
	cqto
	idivq	%rcx
	movq	%rax, %rsi
	call	_ZNSo9_M_insertIlEERSoT_@PLT
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4383:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4383:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4383-.LLSDACSB4383
.LLSDACSB4383:
.LLSDACSE4383:
	.text
	.size	_ZN6TimeItD2Ev, .-_ZN6TimeItD2Ev
	.globl	_ZN6TimeItD1Ev
	.set	_ZN6TimeItD1Ev,_ZN6TimeItD2Ev
	.section	.rodata.str1.1
.LC1:
	.string	"Failed to allocate host vectors!\n"
	.text
	.globl	_Z22initialize_host_vectori
	.type	_Z22initialize_host_vectori, @function
_Z22initialize_host_vectori:
.LFB4385:
	.cfi_startproc
	endbr64
	pushq	%rcx
	.cfi_def_cfa_offset 16
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	testq	%rax, %rax
	jne	.L7
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L7:
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4385:
	.size	_Z22initialize_host_vectori, .-_Z22initialize_host_vectori
	.globl	_Z21randomize_host_vectorPfi
	.type	_Z21randomize_host_vectorPfi, @function
_Z21randomize_host_vectorPfi:
.LFB4386:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	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
	xorl	%ebx, %ebx
.L12:
	cmpl	%ebx, %ebp
	jle	.L15
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	jmp	.L12
.L15:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4386:
	.size	_Z21randomize_host_vectorPfi, .-_Z21randomize_host_vectorPfi
	.globl	_Z29initialize_random_host_vectori
	.type	_Z29initialize_random_host_vectori, @function
_Z29initialize_random_host_vectori:
.LFB4387:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%edi, %ebp
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	call	_Z22initialize_host_vectori
	movl	%ebp, %esi
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	_Z21randomize_host_vectorPfi
	movq	8(%rsp), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4387:
	.size	_Z29initialize_random_host_vectori, .-_Z29initialize_random_host_vectori
	.section	.rodata.str1.1
.LC3:
	.string	"Failed to allocate device vector (error code %s)!\n"
	.text
	.globl	_Z24initialize_device_vectori
	.type	_Z24initialize_device_vectori, @function
_Z24initialize_device_vectori:
.LFB4388:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movslq	%edi, %rsi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	salq	$2, %rsi
	xorl	%eax, %eax
	movq	%rsp, %rdi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L19
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC3(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L19:
	movq	(%rsp), %rax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4388:
	.size	_Z24initialize_device_vectori, .-_Z24initialize_device_vectori
	.section	.rodata.str1.1
.LC4:
	.string	"Host to device copy "
.LC5:
	.string	"Failed to copy vector from host to device (error code %s)!\n"
	.text
	.globl	_Z21host_vector_to_devicePfi
	.type	_Z21host_vector_to_devicePfi, @function
_Z21host_vector_to_devicePfi:
.LFB4389:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4389
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r13
	movl	%esi, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%esi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
.LEHB0:
	call	_Z24initialize_device_vectori
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rax, %rbp
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.LEHE0:
	movq	%r12, %rdi
	call	_ZN6TimeItC1Ev
	movslq	%ebx, %rdx
	movl	$1, %ecx
	movq	%r13, %rsi
	salq	$2, %rdx
	movq	%rbp, %rdi
.LEHB1:
	call	cudaMemcpy@PLT
.LEHE1:
	movl	%eax, %ebx
	movq	%r12, %rdi
	call	_ZN6TimeItD1Ev
	testl	%ebx, %ebx
	je	.L22
	movl	%ebx, %edi
.LEHB2:
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L27:
	endbr64
	movq	%rax, %rbx
.L24:
	movq	%r12, %rdi
	call	_ZN6TimeItD1Ev
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	movq	%rbx, %rdi
	call	_Unwind_Resume@PLT
.LEHE2:
.L22:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
.L29:
	call	__stack_chk_fail@PLT
.L26:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	movq	%rbp, %rax
	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
.LFE4389:
	.section	.gcc_except_table
.LLSDA4389:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4389-.LLSDACSB4389
.LLSDACSB4389:
	.uleb128 .LEHB0-.LFB4389
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB4389
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L27-.LFB4389
	.uleb128 0
	.uleb128 .LEHB2-.LFB4389
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE4389:
	.text
	.size	_Z21host_vector_to_devicePfi, .-_Z21host_vector_to_devicePfi
	.section	.rodata.str1.1
.LC6:
	.string	"Device to host copy "
.LC7:
	.string	"Failed to copy vector from device to host (error code %s)!\n"
	.text
	.globl	_Z21device_vector_to_hostPfi
	.type	_Z21device_vector_to_hostPfi, @function
_Z21device_vector_to_hostPfi:
.LFB4390:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4390
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r13
	movl	%esi, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%esi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
.LEHB3:
	call	_Z22initialize_host_vectori
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rax, %rbp
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.LEHE3:
	movq	%r12, %rdi
	call	_ZN6TimeItC1Ev
	movslq	%ebx, %rdx
	movl	$2, %ecx
	movq	%r13, %rsi
	salq	$2, %rdx
	movq	%rbp, %rdi
.LEHB4:
	call	cudaMemcpy@PLT
.LEHE4:
	movl	%eax, %ebx
	movq	%r12, %rdi
	call	_ZN6TimeItD1Ev
	testl	%ebx, %ebx
	je	.L30
	movl	%ebx, %edi
.LEHB5:
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L35:
	endbr64
	movq	%rax, %rbx
.L32:
	movq	%r12, %rdi
	call	_ZN6TimeItD1Ev
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L37
	movq	%rbx, %rdi
	call	_Unwind_Resume@PLT
.LEHE5:
.L30:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L34
.L37:
	call	__stack_chk_fail@PLT
.L34:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	movq	%rbp, %rax
	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
.LFE4390:
	.section	.gcc_except_table
.LLSDA4390:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4390-.LLSDACSB4390
.LLSDACSB4390:
	.uleb128 .LEHB3-.LFB4390
	.uleb128 .LEHE3-.LEHB3
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB4-.LFB4390
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L35-.LFB4390
	.uleb128 0
	.uleb128 .LEHB5-.LFB4390
	.uleb128 .LEHE5-.LEHB5
	.uleb128 0
	.uleb128 0
.LLSDACSE4390:
	.text
	.size	_Z21device_vector_to_hostPfi, .-_Z21device_vector_to_hostPfi
	.globl	_Z16getBlocksPerGridii
	.type	_Z16getBlocksPerGridii, @function
_Z16getBlocksPerGridii:
.LFB4391:
	.cfi_startproc
	endbr64
	leal	-1(%rsi,%rdi), %eax
	cltd
	idivl	%esi
	ret
	.cfi_endproc
.LFE4391:
	.size	_Z16getBlocksPerGridii, .-_Z16getBlocksPerGridii
	.section	.rodata.str1.1
.LC8:
	.string	"Vector addition on host "
	.text
	.globl	_Z16add_host_vectorsPKfS0_i
	.type	_Z16add_host_vectorsPKfS0_i, @function
_Z16add_host_vectorsPKfS0_i:
.LFB4393:
	.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	%rsi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	movl	%edx, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r14
	call	_Z22initialize_host_vectori
	leaq	.LC8(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rax, %rbx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%r14, %rdi
	call	_ZN6TimeItC1Ev
	xorl	%eax, %eax
.L40:
	cmpl	%eax, %ebp
	jle	.L44
	movss	(%r12,%rax,4), %xmm0
	addss	0(%r13,%rax,4), %xmm0
	movss	%xmm0, (%rbx,%rax,4)
	incq	%rax
	jmp	.L40
.L44:
	movq	%r14, %rdi
	call	_ZN6TimeItD1Ev
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	call	__stack_chk_fail@PLT
.L42:
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%rbx, %rax
	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
.LFE4393:
	.size	_Z16add_host_vectorsPKfS0_i, .-_Z16add_host_vectorsPKfS0_i
	.globl	_Z14freeCudaVectorPf
	.type	_Z14freeCudaVectorPf, @function
_Z14freeCudaVectorPf:
.LFB4394:
	.cfi_startproc
	endbr64
	jmp	cudaFree@PLT
	.cfi_endproc
.LFE4394:
	.size	_Z14freeCudaVectorPf, .-_Z14freeCudaVectorPf
	.globl	_Z29match_host_and_device_resultsPKfS0_i
	.type	_Z29match_host_and_device_resultsPKfS0_i, @function
_Z29match_host_and_device_resultsPKfS0_i:
.LFB4395:
	.cfi_startproc
	endbr64
	movsd	.LC10(%rip), %xmm2
	xorl	%eax, %eax
	movb	$1, %cl
	xorl	%r8d, %r8d
	movss	.LC9(%rip), %xmm1
.L47:
	cmpl	%eax, %edx
	jle	.L51
	movss	(%rdi,%rax,4), %xmm0
	subss	(%rsi,%rax,4), %xmm0
	andps	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	ucomisd	%xmm2, %xmm0
	cmova	%r8d, %ecx
	incq	%rax
	jmp	.L47
.L51:
	movl	%ecx, %eax
	ret
	.cfi_endproc
.LFE4395:
	.size	_Z29match_host_and_device_resultsPKfS0_i, .-_Z29match_host_and_device_resultsPKfS0_i
	.section	.rodata.str1.1
.LC11:
	.string	": "
.LC12:
	.string	","
	.text
	.globl	_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
	.type	_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE, @function
_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE:
.LFB4396:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC12(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%esi, %r12d
	movq	%rdx, %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	leaq	_ZSt4cout(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rbp, %rdi
	xorl	%ebx, %ebx
	call	_ZStlsIcSt11char_traitsIcESaIcEERSt13basic_ostreamIT_T0_ES7_RKNSt7__cxx1112basic_stringIS4_S5_T1_EE@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L53:
	cmpl	%ebx, %r12d
	jle	.L56
	movq	%rbp, %rdi
	cvtss2sd	0(%r13,%rbx,4), %xmm0
	incq	%rbx
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r14, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	jmp	.L53
.L56:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 40
	movq	%rbp, %rdi
	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
	jmp	_ZNSolsEPFRSoS_E.isra.0
	.cfi_endproc
.LFE4396:
	.size	_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE, .-_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
	.globl	_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi
	.type	_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi, @function
_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi:
.LFB4422:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L57
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10vector_addPKfS0_Pfi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L57:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L59
	call	__stack_chk_fail@PLT
.L59:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4422:
	.size	_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi, .-_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi
	.globl	_Z10vector_addPKfS0_Pfi
	.type	_Z10vector_addPKfS0_Pfi, @function
_Z10vector_addPKfS0_Pfi:
.LFB4423:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi
	.cfi_endproc
.LFE4423:
	.size	_Z10vector_addPKfS0_Pfi, .-_Z10vector_addPKfS0_Pfi
	.section	.rodata.str1.1
.LC13:
	.string	"Vector addition on device "
.LC14:
	.string	"Failed to launch vector_add kernel (error code %s)!\n"
	.text
	.globl	_Z18add_device_vectorsPKfS0_ii
	.type	_Z18add_device_vectorsPKfS0_ii, @function
_Z18add_device_vectorsPKfS0_ii:
.LFB4392:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4392
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	movl	%edx, %edi
	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	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %r13
.LEHB6:
	call	_Z24initialize_device_vectori
	leaq	.LC13(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movq	%rax, 8(%rsp)
	leal	-1(%rbp,%rbx), %eax
	cltd
	idivl	%ebx
	movl	%eax, %r12d
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.LEHE6:
	movq	%r13, %rdi
	call	_ZN6TimeItC1Ev
	movl	%ebx, 44(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r12d, 32(%rsp)
	movq	%rax, 48(%rsp)
	movl	52(%rsp), %ecx
	movq	%rax, 36(%rsp)
	movq	44(%rsp), %rdx
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
.LEHB7:
	call	__cudaPushCallConfiguration@PLT
.LEHE7:
	testl	%eax, %eax
	je	.L63
.L66:
	movq	%r13, %rdi
	call	_ZN6TimeItD1Ev
.LEHB8:
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L71
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.LEHE8:
	movl	$1, %edi
	call	exit@PLT
.L63:
	movq	8(%rsp), %rdx
	movl	%ebp, %ecx
	movq	%r15, %rsi
	movq	%r14, %rdi
.LEHB9:
	call	_Z37__device_stub__Z10vector_addPKfS0_PfiPKfS0_Pfi
.LEHE9:
	jmp	.L66
.L70:
	endbr64
	movq	%rax, %rbx
.L67:
	movq	%r13, %rdi
	call	_ZN6TimeItD1Ev
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L73
	movq	%rbx, %rdi
.LEHB10:
	call	_Unwind_Resume@PLT
.LEHE10:
.L71:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L69
.L73:
	call	__stack_chk_fail@PLT
.L69:
	movq	8(%rsp), %rax
	addq	$72, %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
.LFE4392:
	.section	.gcc_except_table
.LLSDA4392:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4392-.LLSDACSB4392
.LLSDACSB4392:
	.uleb128 .LEHB6-.LFB4392
	.uleb128 .LEHE6-.LEHB6
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB7-.LFB4392
	.uleb128 .LEHE7-.LEHB7
	.uleb128 .L70-.LFB4392
	.uleb128 0
	.uleb128 .LEHB8-.LFB4392
	.uleb128 .LEHE8-.LEHB8
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB9-.LFB4392
	.uleb128 .LEHE9-.LEHB9
	.uleb128 .L70-.LFB4392
	.uleb128 0
	.uleb128 .LEHB10-.LFB4392
	.uleb128 .LEHE10-.LEHB10
	.uleb128 0
	.uleb128 0
.LLSDACSE4392:
	.text
	.size	_Z18add_device_vectorsPKfS0_ii, .-_Z18add_device_vectorsPKfS0_ii
	.section	.rodata.str1.1
.LC15:
	.string	"Vector addition code using CUDA!"
.LC16:
	.string	"Results matched on host and device"
.LC17:
	.string	"Results did NOT match on host and device"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4397:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	_ZSt4cout(%rip), %r15
	leaq	.LC15(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r15, %rdi
	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
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$10000000, %edi
	call	_Z29initialize_random_host_vectori
	movl	$10000000, %edi
	movq	%rax, %rbp
	call	_Z29initialize_random_host_vectori
	movl	$10000000, %esi
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	_Z21host_vector_to_devicePfi
	movl	$10000000, %esi
	movq	%rbx, %rdi
	movq	%rax, %r12
	call	_Z21host_vector_to_devicePfi
	movl	$256, %ecx
	movl	$10000000, %edx
	movq	%r12, %rdi
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	_Z18add_device_vectorsPKfS0_ii
	movl	$10000000, %esi
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	_Z21device_vector_to_hostPfi
	movl	$10000000, %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	movq	%rax, %r14
	call	_Z16add_host_vectorsPKfS0_i
	movq	%r14, %rdi
	movl	$10000000, %edx
	movq	%rax, %rsi
	movq	%rax, %r13
	call	_Z29match_host_and_device_resultsPKfS0_i
	leaq	.LC16(%rip), %rsi
	movq	%r15, %rdi
	testb	%al, %al
	jne	.L78
	leaq	.LC17(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
.L78:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	cudaFree@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	addq	$24, %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
.LFE4397:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z10vector_addPKfS0_Pfi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4425:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10vector_addPKfS0_Pfi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4425:
	.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
.LC2:
	.long	805306368
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC9:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC10:
	.long	-1998362383
	.long	1055193269
	.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:

#include<iostream>
#include<chrono>
#include<memory>
#include<string>
#include<hip/hip_runtime.h>


class TimeIt{
private:
    std::chrono::time_point<std::chrono::system_clock> start_time;

public:
    TimeIt();
    ~TimeIt();
};

TimeIt::TimeIt() {
    this->start_time = std::chrono::system_clock::now();
}

TimeIt::~TimeIt() {
    auto end_time = std::chrono::system_clock::now();

    auto duration_time = std::chrono::duration_cast<std::chrono::microseconds>(
        end_time - this->start_time
    ).count();

    std::cout << duration_time << " us" << std::endl;
}


__global__
void vector_add(const float *X, const float *Y, float *Z, int nEle) {
    int i = blockDim.x * blockIdx.x + threadIdx.x;

    if (i < nEle) {
        Z[i] = X[i] + Y[i];
    }
}

float * initialize_host_vector(int nEle) {
    size_t mem_size = nEle * sizeof(float);

    float * h_V = (float *)malloc(mem_size);

    if (h_V == NULL) {
        fprintf(stderr, "Failed to allocate host vectors!\n");
        exit(EXIT_FAILURE);
    }

    return h_V;
}

void randomize_host_vector(float * h_V, int nEle) {
    for (int i = 0; i < nEle; ++i) {
        h_V[i] = rand()/(float)RAND_MAX;
    }
}

float * initialize_random_host_vector(int nEle) {
    float * h_V = initialize_host_vector(nEle);
    randomize_host_vector(h_V, nEle);

    return h_V;
}

float * initialize_device_vector(int nEle) {
    size_t mem_size = nEle * sizeof(float);

    hipError_t err = hipSuccess;
    float * d_V = nullptr;
    err = hipMalloc((void **)&d_V, mem_size);
    if (err != hipSuccess) {
        fprintf(
            stderr,
            "Failed to allocate device vector (error code %s)!\n",
            hipGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return d_V;
}

float * host_vector_to_device(float * h_V, int nEle) {
    size_t mem_size = nEle * sizeof(float);

    float * d_V = initialize_device_vector(nEle);

    hipError_t err = hipSuccess;
    {
        std::cout << "Host to device copy ";
        auto tmr = TimeIt();
        err = hipMemcpy(d_V, h_V, mem_size, hipMemcpyHostToDevice);
    }
    if (err != hipSuccess) {
        fprintf(
            stderr,
            "Failed to copy vector from host to device (error code %s)!\n",
            hipGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return d_V;
}

float * device_vector_to_host(float * d_V, int nEle) {
    size_t mem_size = nEle * sizeof(float);

    float * h_V = initialize_host_vector(nEle);

    hipError_t err = hipSuccess;
    {
        std::cout << "Device to host copy ";
        auto tmr = TimeIt();
        err = hipMemcpy(h_V, d_V, mem_size, hipMemcpyDeviceToHost);
    }
    if (err != hipSuccess) {
        fprintf(
            stderr,
            "Failed to copy vector from device to host (error code %s)!\n",
            hipGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return h_V;
}

int getBlocksPerGrid(int nEle, int threadsPerBlock) {
    return (nEle + threadsPerBlock - 1) / threadsPerBlock;
}

float * add_device_vectors(
    const float * d_X, const float * d_Y, int nEle, int threadsPerBlock
) {
    float * d_Z = initialize_device_vector(nEle);
    int blocksPerGrid = getBlocksPerGrid(nEle, threadsPerBlock);
    {
        std::cout << "Vector addition on device ";
        auto tmr = TimeIt();
        vector_add<<<blocksPerGrid, threadsPerBlock>>>(d_X, d_Y, d_Z, nEle);
    }
    hipError_t err = hipSuccess;
    err = hipGetLastError();
    if (err != hipSuccess) {
        fprintf(
            stderr,
            "Failed to launch vector_add kernel (error code %s)!\n",
            hipGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }

    return d_Z;
}

float * add_host_vectors(const float * h_X, const float * h_Y, int nEle) {
    float * hZ_ = initialize_host_vector(nEle);
    {
        std::cout << "Vector addition on host ";
        auto tmr = TimeIt();
        for (int i=0; i < nEle; i++) {
            hZ_[i] = h_X[i] + h_Y[i];
        }
    }
    return hZ_;
}

void freeCudaVector(float * d_V) {
    hipError_t err = hipSuccess;
    hipFree(d_V);
    if (err != hipSuccess) {
        fprintf(
            stderr,
            "Failed to free device vector (error code %s)!\n",
            hipGetErrorString(err)
        );
        exit(EXIT_FAILURE);
    }
}

bool match_host_and_device_results(
    const float * h_Z, const float * hZ_, int nEle
) {
    bool verified = true;
    for (int i=0; i < nEle; i++) {
        if (fabs(h_Z[i] - hZ_[i]) > 1e-5) {
            verified = false;
        }
    }
    return verified;
}

void print_host_vector(const float * h_V, const int nEle, std::string mesg) {
    std::cout << mesg << ": ";

    for (int i=0; i < nEle; i++) {
        std::cout << h_V[i] << ",";
    }

    std::cout << std::endl;
}

int main(void) {
    std::cout << "Vector addition code using CUDA!" << std::endl;

    int nEle = 10000000;
    int threadsPerBlock = 256;

    float * h_X = initialize_random_host_vector(nEle);
    float * h_Y = initialize_random_host_vector(nEle);

    float * d_X = host_vector_to_device(h_X, nEle);
    float * d_Y = host_vector_to_device(h_Y, nEle);

    float * d_Z = add_device_vectors(d_X, d_Y, nEle, threadsPerBlock);

    float * h_Z = device_vector_to_host(d_Z, nEle);
    float * hZ_ = add_host_vectors(h_X, h_Y, nEle);

    bool verified = match_host_and_device_results(h_Z, hZ_, nEle);
    if (verified) {
        std::cout << "Results matched on host and device" << std::endl;
    } else {
        std::cerr << "Results did NOT match on host and device" << std::endl;
    }

#if defined(DEBUG)
    print_host_vector(h_X, nEle, "h_X");
    print_host_vector(h_Y, nEle, "h_Y");
    print_host_vector(h_Z, nEle, "h_Z");
    print_host_vector(hZ_, nEle, "hZ_");
#endif

    free(h_X);
    free(h_Y);
    free(h_Z);
    free(hZ_);

    freeCudaVector(d_X);
    freeCudaVector(d_Y);
    freeCudaVector(d_Z);

    return 0;
}

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

                                        # End of file scope inline assembly
	.globl	_ZN6TimeItC2Ev                  # -- Begin function _ZN6TimeItC2Ev
	.p2align	1, 0x90
	.type	_ZN6TimeItC2Ev,@function
_ZN6TimeItC2Ev:                         # @_ZN6TimeItC2Ev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	$0, (%rdi)
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, (%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_ZN6TimeItC2Ev, .Lfunc_end0-_ZN6TimeItC2Ev
	.cfi_endproc
                                        # -- End function
	.globl	_ZN6TimeItD2Ev                  # -- Begin function _ZN6TimeItD2Ev
	.p2align	1, 0x90
	.type	_ZN6TimeItD2Ev,@function
_ZN6TimeItD2Ev:                         # @_ZN6TimeItD2Ev
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	(%rbx), %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
.Ltmp0:
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIlEERSoT_
.Ltmp1:
# %bb.1:                                # %_ZNSolsEl.exit
.Ltmp2:
	movq	%rax, %rbx
	movl	$.L.str, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp3:
# %bb.2:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
.Ltmp4:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp5:
# %bb.3:                                # %.noexc
.Ltmp6:
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
.Ltmp7:
# %bb.4:                                # %.noexc1
.Ltmp8:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp9:
# %bb.5:                                # %_ZNSolsEPFRSoS_E.exit
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB1_6:
	.cfi_def_cfa_offset 16
.Ltmp10:
	movq	%rax, %rdi
	callq	__clang_call_terminate
.Lfunc_end1:
	.size	_ZN6TimeItD2Ev, .Lfunc_end1-_ZN6TimeItD2Ev
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table1:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	3                               # @TType Encoding = udata4
	.uleb128 .Lttbase0-.Lttbaseref0
.Lttbaseref0:
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp9-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp9
	.uleb128 .Ltmp10-.Lfunc_begin0          #     jumps to .Ltmp10
	.byte	1                               #   On action: 1
.Lcst_end0:
	.byte	1                               # >> Action Record 1 <<
                                        #   Catch TypeInfo 1
	.byte	0                               #   No further actions
	.p2align	2, 0x0
                                        # >> Catch TypeInfos <<
	.long	0                               # TypeInfo 1
.Lttbase0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text.__clang_call_terminate,"axG",@progbits,__clang_call_terminate,comdat
	.hidden	__clang_call_terminate          # -- Begin function __clang_call_terminate
	.weak	__clang_call_terminate
	.type	__clang_call_terminate,@function
__clang_call_terminate:                 # @__clang_call_terminate
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__cxa_begin_catch
	callq	_ZSt9terminatev
.Lfunc_end2:
	.size	__clang_call_terminate, .Lfunc_end2-__clang_call_terminate
	.cfi_endproc
                                        # -- End function
	.text
	.globl	_Z25__device_stub__vector_addPKfS0_Pfi # -- Begin function _Z25__device_stub__vector_addPKfS0_Pfi
	.type	_Z25__device_stub__vector_addPKfS0_Pfi,@function
_Z25__device_stub__vector_addPKfS0_Pfi: # @_Z25__device_stub__vector_addPKfS0_Pfi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10vector_addPKfS0_Pfi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z25__device_stub__vector_addPKfS0_Pfi, .Lfunc_end3-_Z25__device_stub__vector_addPKfS0_Pfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z22initialize_host_vectori     # -- Begin function _Z22initialize_host_vectori
	.type	_Z22initialize_host_vectori,@function
_Z22initialize_host_vectori:            # @_Z22initialize_host_vectori
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rdi
	shlq	$2, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB4_2
# %bb.1:
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.LBB4_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$33, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	_Z22initialize_host_vectori, .Lfunc_end4-_Z22initialize_host_vectori
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z21randomize_host_vectorPfi
.LCPI5_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z21randomize_host_vectorPfi
	.type	_Z21randomize_host_vectorPfi,@function
_Z21randomize_host_vectorPfi:           # @_Z21randomize_host_vectorPfi
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB5_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI5_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB5_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB5_4:                                # %._crit_edge
	retq
.Lfunc_end5:
	.size	_Z21randomize_host_vectorPfi, .Lfunc_end5-_Z21randomize_host_vectorPfi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z29initialize_random_host_vectori
.LCPI6_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z29initialize_random_host_vectori
	.type	_Z29initialize_random_host_vectori,@function
_Z29initialize_random_host_vectori:     # @_Z29initialize_random_host_vectori
	.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
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edi, %ebp
	callq	_Z22initialize_host_vectori
	movq	%rax, %rbx
	testl	%ebp, %ebp
	jle	.LBB6_3
# %bb.1:                                # %.lr.ph.preheader.i
	movl	%ebp, %r14d
	xorl	%r15d, %r15d
.LBB6_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI6_0(%rip), %xmm0
	movss	%xmm0, (%rbx,%r15,4)
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB6_2
.LBB6_3:                                # %_Z21randomize_host_vectorPfi.exit
	movq	%rbx, %rax
	addq	$8, %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_end6:
	.size	_Z29initialize_random_host_vectori, .Lfunc_end6-_Z29initialize_random_host_vectori
	.cfi_endproc
                                        # -- End function
	.globl	_Z24initialize_device_vectori   # -- Begin function _Z24initialize_device_vectori
	.type	_Z24initialize_device_vectori,@function
_Z24initialize_device_vectori:          # @_Z24initialize_device_vectori
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movslq	%edi, %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %rdi
	movq	$0, (%rdi)
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB7_2
# %bb.1:
	movq	8(%rsp), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB7_2:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end7:
	.size	_Z24initialize_device_vectori, .Lfunc_end7-_Z24initialize_device_vectori
	.cfi_endproc
                                        # -- End function
	.globl	_Z21host_vector_to_devicePfi    # -- Begin function _Z21host_vector_to_devicePfi
	.type	_Z21host_vector_to_devicePfi,@function
_Z21host_vector_to_devicePfi:           # @_Z21host_vector_to_devicePfi
.Lfunc_begin1:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception1
# %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
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %r14
	movslq	%esi, %rdi
	leaq	(,%rdi,4), %r15
                                        # kill: def $edi killed $edi killed $rdi
	callq	_Z24initialize_device_vectori
	movq	%rax, %rbx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, (%rsp)
.Ltmp11:
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp12:
# %bb.1:
	movl	%eax, %ebp
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	testl	%ebp, %ebp
	jne	.LBB8_2
# %bb.4:
	movq	%rbx, %rax
	addq	$8, %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
.LBB8_2:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rbx
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB8_3:
.Ltmp13:
	movq	%rax, %rbx
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end8:
	.size	_Z21host_vector_to_devicePfi, .Lfunc_end8-_Z21host_vector_to_devicePfi
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table8:
.Lexception1:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end1-.Lcst_begin1
.Lcst_begin1:
	.uleb128 .Lfunc_begin1-.Lfunc_begin1    # >> Call Site 1 <<
	.uleb128 .Ltmp11-.Lfunc_begin1          #   Call between .Lfunc_begin1 and .Ltmp11
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin1          # >> Call Site 2 <<
	.uleb128 .Ltmp12-.Ltmp11                #   Call between .Ltmp11 and .Ltmp12
	.uleb128 .Ltmp13-.Lfunc_begin1          #     jumps to .Ltmp13
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin1          # >> Call Site 3 <<
	.uleb128 .Lfunc_end8-.Ltmp12            #   Call between .Ltmp12 and .Lfunc_end8
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end1:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z21device_vector_to_hostPfi    # -- Begin function _Z21device_vector_to_hostPfi
	.type	_Z21device_vector_to_hostPfi,@function
_Z21device_vector_to_hostPfi:           # @_Z21device_vector_to_hostPfi
.Lfunc_begin2:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception2
# %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
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %r14
	movslq	%esi, %rdi
	leaq	(,%rdi,4), %r15
                                        # kill: def $edi killed $edi killed $rdi
	callq	_Z22initialize_host_vectori
	movq	%rax, %rbx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, (%rsp)
.Ltmp14:
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp15:
# %bb.1:
	movl	%eax, %ebp
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	testl	%ebp, %ebp
	jne	.LBB9_2
# %bb.4:
	movq	%rbx, %rax
	addq	$8, %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
.LBB9_2:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rbx
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str.6, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB9_3:
.Ltmp16:
	movq	%rax, %rbx
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end9:
	.size	_Z21device_vector_to_hostPfi, .Lfunc_end9-_Z21device_vector_to_hostPfi
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table9:
.Lexception2:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end2-.Lcst_begin2
.Lcst_begin2:
	.uleb128 .Lfunc_begin2-.Lfunc_begin2    # >> Call Site 1 <<
	.uleb128 .Ltmp14-.Lfunc_begin2          #   Call between .Lfunc_begin2 and .Ltmp14
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp14-.Lfunc_begin2          # >> Call Site 2 <<
	.uleb128 .Ltmp15-.Ltmp14                #   Call between .Ltmp14 and .Ltmp15
	.uleb128 .Ltmp16-.Lfunc_begin2          #     jumps to .Ltmp16
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp15-.Lfunc_begin2          # >> Call Site 3 <<
	.uleb128 .Lfunc_end9-.Ltmp15            #   Call between .Ltmp15 and .Lfunc_end9
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end2:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z16getBlocksPerGridii          # -- Begin function _Z16getBlocksPerGridii
	.type	_Z16getBlocksPerGridii,@function
_Z16getBlocksPerGridii:                 # @_Z16getBlocksPerGridii
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
                                        # kill: def $edi killed $edi def $rdi
	leal	(%rdi,%rsi), %eax
	decl	%eax
	cltd
	idivl	%esi
	retq
.Lfunc_end10:
	.size	_Z16getBlocksPerGridii, .Lfunc_end10-_Z16getBlocksPerGridii
	.cfi_endproc
                                        # -- End function
	.globl	_Z18add_device_vectorsPKfS0_ii  # -- Begin function _Z18add_device_vectorsPKfS0_ii
	.type	_Z18add_device_vectorsPKfS0_ii,@function
_Z18add_device_vectorsPKfS0_ii:         # @_Z18add_device_vectorsPKfS0_ii
.Lfunc_begin3:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception3
# %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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%ecx, %r13d
	movl	%edx, %r14d
	movq	%rsi, %r15
	movq	%rdi, %r12
	movl	%edx, %edi
	callq	_Z24initialize_device_vectori
	movq	%rax, %rbx
	leal	(%r14,%r13), %eax
	decl	%eax
	cltd
	idivl	%r13d
	movl	%eax, %ebp
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$26, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, (%rsp)
	btsq	$32, %rbp
	movl	%r13d, %edx
	btsq	$32, %rdx
.Ltmp17:
	movq	%rbp, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp18:
# %bb.1:
	testl	%eax, %eax
	jne	.LBB11_3
# %bb.2:
.Ltmp19:
	movq	%r12, %rdi
	movq	%r15, %rsi
	movq	%rbx, %rdx
	movl	%r14d, %ecx
	callq	_Z25__device_stub__vector_addPKfS0_Pfi
.Ltmp20:
.LBB11_3:
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB11_6
# %bb.4:
	movq	%rbx, %rax
	addq	$8, %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
.LBB11_6:
	.cfi_def_cfa_offset 64
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB11_5:
.Ltmp21:
	movq	%rax, %rbx
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end11:
	.size	_Z18add_device_vectorsPKfS0_ii, .Lfunc_end11-_Z18add_device_vectorsPKfS0_ii
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table11:
.Lexception3:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end3-.Lcst_begin3
.Lcst_begin3:
	.uleb128 .Lfunc_begin3-.Lfunc_begin3    # >> Call Site 1 <<
	.uleb128 .Ltmp17-.Lfunc_begin3          #   Call between .Lfunc_begin3 and .Ltmp17
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp17-.Lfunc_begin3          # >> Call Site 2 <<
	.uleb128 .Ltmp20-.Ltmp17                #   Call between .Ltmp17 and .Ltmp20
	.uleb128 .Ltmp21-.Lfunc_begin3          #     jumps to .Ltmp21
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp20-.Lfunc_begin3          # >> Call Site 3 <<
	.uleb128 .Lfunc_end11-.Ltmp20           #   Call between .Ltmp20 and .Lfunc_end11
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end3:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z16add_host_vectorsPKfS0_i     # -- Begin function _Z16add_host_vectorsPKfS0_i
	.type	_Z16add_host_vectorsPKfS0_i,@function
_Z16add_host_vectorsPKfS0_i:            # @_Z16add_host_vectorsPKfS0_i
	.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
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	%edx, %edi
	callq	_Z22initialize_host_vectori
	movq	%rax, %rbx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$24, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, (%rsp)
	testl	%ebp, %ebp
	jle	.LBB12_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %eax
	xorl	%ecx, %ecx
.LBB12_2:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%r15,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	addss	(%r14,%rcx,4), %xmm0
	movss	%xmm0, (%rbx,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB12_2
.LBB12_3:                               # %._crit_edge
	movq	%rsp, %rdi
	callq	_ZN6TimeItD2Ev
	movq	%rbx, %rax
	addq	$8, %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_end12:
	.size	_Z16add_host_vectorsPKfS0_i, .Lfunc_end12-_Z16add_host_vectorsPKfS0_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z14freeCudaVectorPf            # -- Begin function _Z14freeCudaVectorPf
	.type	_Z14freeCudaVectorPf,@function
_Z14freeCudaVectorPf:                   # @_Z14freeCudaVectorPf
	.cfi_startproc
# %bb.0:
	jmp	hipFree                         # TAILCALL
.Lfunc_end13:
	.size	_Z14freeCudaVectorPf, .Lfunc_end13-_Z14freeCudaVectorPf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z29match_host_and_device_resultsPKfS0_i
.LCPI14_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI14_1:
	.quad	0x3ee4f8b588e368f1              # double 1.0000000000000001E-5
	.text
	.globl	_Z29match_host_and_device_resultsPKfS0_i
	.type	_Z29match_host_and_device_resultsPKfS0_i,@function
_Z29match_host_and_device_resultsPKfS0_i: # @_Z29match_host_and_device_resultsPKfS0_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB14_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%edx, %ecx
	movb	$1, %al
	xorl	%edx, %edx
	movaps	.LCPI14_0(%rip), %xmm0          # xmm0 = [NaN,NaN,NaN,NaN]
	movsd	.LCPI14_1(%rip), %xmm1          # xmm1 = mem[0],zero
.LBB14_4:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rdx,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%rsi,%rdx,4), %xmm2
	andps	%xmm0, %xmm2
	cvtss2sd	%xmm2, %xmm2
	ucomisd	%xmm1, %xmm2
	movl	$0, %r8d
	ja	.LBB14_6
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB14_4 Depth=1
	movzbl	%al, %r8d
.LBB14_6:                               # %.lr.ph
                                        #   in Loop: Header=BB14_4 Depth=1
	movl	%r8d, %eax
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB14_4
# %bb.7:                                # %._crit_edge.loopexit
	andb	$1, %al
	retq
.LBB14_1:
	movb	$1, %al
	retq
.Lfunc_end14:
	.size	_Z29match_host_and_device_resultsPKfS0_i, .Lfunc_end14-_Z29match_host_and_device_resultsPKfS0_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE # -- Begin function _Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
	.type	_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE,@function
_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE: # @_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movq	(%rdx), %rsi
	movq	8(%rdx), %rdx
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$.L.str.11, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	testl	%ebp, %ebp
	jle	.LBB15_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB15_2:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r12,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.12, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB15_2
.LBB15_3:                               # %._crit_edge
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	_ZNSo5flushEv                   # TAILCALL
.Lfunc_end15:
	.size	_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE, .Lfunc_end15-_Z17print_host_vectorPKfiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI16_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI16_1:
	.quad	0x3ee4f8b588e368f1              # double 1.0000000000000001E-5
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$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
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.13, %esi
	movl	$32, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$10000000, %edi                 # imm = 0x989680
	callq	_Z29initialize_random_host_vectori
	movq	%rax, %r14
	movl	$10000000, %edi                 # imm = 0x989680
	callq	_Z29initialize_random_host_vectori
	movq	%rax, %r12
	movq	%r14, %rdi
	movl	$10000000, %esi                 # imm = 0x989680
	callq	_Z21host_vector_to_devicePfi
	movq	%rax, %rbx
	movq	%r12, %rdi
	movl	$10000000, %esi                 # imm = 0x989680
	callq	_Z21host_vector_to_devicePfi
	movq	%rbx, 16(%rsp)                  # 8-byte Spill
	movq	%rbx, %rdi
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	%rax, %rsi
	movl	$10000000, %edx                 # imm = 0x989680
	movl	$256, %ecx                      # imm = 0x100
	callq	_Z18add_device_vectorsPKfS0_ii
	movq	%rax, %r13
	movq	%rax, %rdi
	movl	$10000000, %esi                 # imm = 0x989680
	callq	_Z21device_vector_to_hostPfi
	movq	%rax, %rbp
	movq	%r14, %rdi
	movq	%r12, %rsi
	movl	$10000000, %edx                 # imm = 0x989680
	callq	_Z16add_host_vectorsPKfS0_i
	movq	%rax, %rbx
	movb	$1, %cl
	xorl	%eax, %eax
	movaps	.LCPI16_0(%rip), %xmm0          # xmm0 = [NaN,NaN,NaN,NaN]
	movsd	.LCPI16_1(%rip), %xmm1          # xmm1 = mem[0],zero
.LBB16_1:                               # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rbp,%rax,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	subss	(%rbx,%rax,4), %xmm2
	andps	%xmm0, %xmm2
	cvtss2sd	%xmm2, %xmm2
	ucomisd	%xmm1, %xmm2
	movl	$0, %edx
	ja	.LBB16_3
# %bb.2:                                # %.lr.ph.i
                                        #   in Loop: Header=BB16_1 Depth=1
	movzbl	%cl, %edx
.LBB16_3:                               # %.lr.ph.i
                                        #   in Loop: Header=BB16_1 Depth=1
	movl	%edx, %ecx
	incq	%rax
	cmpq	$10000000, %rax                 # imm = 0x989680
	jne	.LBB16_1
# %bb.4:                                # %_Z29match_host_and_device_resultsPKfS0_i.exit
	testb	$1, %cl
	jne	.LBB16_5
# %bb.6:
	movl	$_ZSt4cerr, %r15d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.15, %esi
	movl	$40, %edx
	jmp	.LBB16_7
.LBB16_5:
	movl	$_ZSt4cout, %r15d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.14, %esi
	movl	$34, %edx
.LBB16_7:
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%r14, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	%rbp, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	16(%rsp), %rdi                  # 8-byte Reload
	callq	hipFree
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	hipFree
	movq	%r13, %rdi
	callq	hipFree
	xorl	%eax, %eax
	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_end16:
	.size	main, .Lfunc_end16-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB17_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB17_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10vector_addPKfS0_Pfi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end17:
	.size	__hip_module_ctor, .Lfunc_end17-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB18_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB18_2:
	retq
.Lfunc_end18:
	.size	__hip_module_dtor, .Lfunc_end18-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	" us"
	.size	.L.str, 4

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

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Failed to allocate host vectors!\n"
	.size	.L.str.1, 34

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Failed to allocate device vector (error code %s)!\n"
	.size	.L.str.2, 51

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Host to device copy "
	.size	.L.str.3, 21

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Failed to copy vector from host to device (error code %s)!\n"
	.size	.L.str.4, 60

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Device to host copy "
	.size	.L.str.5, 21

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Failed to copy vector from device to host (error code %s)!\n"
	.size	.L.str.6, 60

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Vector addition on device "
	.size	.L.str.7, 27

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Failed to launch vector_add kernel (error code %s)!\n"
	.size	.L.str.8, 53

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Vector addition on host "
	.size	.L.str.9, 25

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	": "
	.size	.L.str.11, 3

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

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Vector addition code using CUDA!"
	.size	.L.str.13, 33

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Results matched on host and device"
	.size	.L.str.14, 35

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Results did NOT match on host and device"
	.size	.L.str.15, 41

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10vector_addPKfS0_Pfi"
	.size	.L__unnamed_1, 24

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

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

	.globl	_ZN6TimeItC1Ev
	.type	_ZN6TimeItC1Ev,@function
.set _ZN6TimeItC1Ev, _ZN6TimeItC2Ev
	.globl	_ZN6TimeItD1Ev
	.type	_ZN6TimeItD1Ev,@function
.set _ZN6TimeItD1Ev, _ZN6TimeItD2Ev
	.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 _Z25__device_stub__vector_addPKfS0_Pfi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt4cout
	.addrsig_sym _Z10vector_addPKfS0_Pfi
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10vector_addPKfS0_Pfi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10vector_addPKfS0_Pfi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
