//
// Created by harish on 10.03.21.
//

#include "cudaData.cuh"
#include <iostream>
using namespace std;

int* cudaData::getData(int dataSize,int* hostData) {
    int* deviceVec;
    cudaMallocManaged(&deviceVec,dataSize*sizeof(int));
    cudaMemcpy(deviceVec, hostData, dataSize*sizeof (int),cudaMemcpyHostToDevice);
    return deviceVec;
}

int* cudaData::copyHostToDevice(int* deviceVec, int* hostData, int dataSize){
    cudaMemcpy(deviceVec, hostData, dataSize*sizeof (int),cudaMemcpyHostToDevice);
    return deviceVec;
}

int* cudaData::allocateGpuMemory(int dataSize, int* hostData){
    int* deviceVec;
    cudaMalloc(&deviceVec,dataSize*sizeof(int));
    return deviceVec;
}

int* cudaData::getHostData(int dataSize,int* devData) {
    int* hostData = (int*)malloc(sizeof (int)*dataSize);
    cudaMemcpy(hostData,devData, sizeof(int)*dataSize,cudaMemcpyDeviceToHost);
    return hostData;
}
	.file	"tmpxft_002c485f_00000000-6_cudaData.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3641:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3641:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.globl	_ZN8cudaData7getDataEiPi
	.type	_ZN8cudaData7getDataEiPi, @function
_ZN8cudaData7getDataEiPi:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movslq	%esi, %rsi
	movq	%rdx, %rbp
	movl	$1, %edx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	0(,%rsi,4), %rbx
	movq	%rbx, %rsi
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	cudaMallocManaged@PLT
	movq	(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L3
	call	__stack_chk_fail@PLT
.L3:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_ZN8cudaData7getDataEiPi, .-_ZN8cudaData7getDataEiPi
	.align 2
	.globl	_ZN8cudaData16copyHostToDeviceEPiS0_i
	.type	_ZN8cudaData16copyHostToDeviceEPiS0_i, @function
_ZN8cudaData16copyHostToDeviceEPiS0_i:
.LFB3636:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %rbx
	movq	%rdx, %rsi
	movslq	%ecx, %rdx
	movq	%rbx, %rdi
	salq	$2, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3636:
	.size	_ZN8cudaData16copyHostToDeviceEPiS0_i, .-_ZN8cudaData16copyHostToDeviceEPiS0_i
	.align 2
	.globl	_ZN8cudaData17allocateGpuMemoryEiPi
	.type	_ZN8cudaData17allocateGpuMemoryEiPi, @function
_ZN8cudaData17allocateGpuMemoryEiPi:
.LFB3637:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movslq	%esi, %rsi
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	salq	$2, %rsi
	movq	%rsp, %rdi
	call	cudaMalloc@PLT
	movq	(%rsp), %rax
	movq	8(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	_ZN8cudaData17allocateGpuMemoryEiPi, .-_ZN8cudaData17allocateGpuMemoryEiPi
	.align 2
	.globl	_ZN8cudaData11getHostDataEiPi
	.type	_ZN8cudaData11getHostDataEiPi, @function
_ZN8cudaData11getHostDataEiPi:
.LFB3638:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movslq	%esi, %rbx
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rdx
	movq	%r12, %rsi
	movl	$2, %ecx
	movq	%rax, %rbp
	movq	%rax, %rdi
	call	cudaMemcpy@PLT
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3638:
	.size	_ZN8cudaData11getHostDataEiPi, .-_ZN8cudaData11getHostDataEiPi
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3664:
	.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
.LFE3664:
	.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
	.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:

//
// Created by harish on 10.03.21.
//


#include <hip/hip_runtime.h>
#include "cudaData.cuh"
#include <iostream>
using namespace std;

int* cudaData::getData(int dataSize,int* hostData) {
    int* deviceVec;
    hipMallocManaged(&deviceVec,dataSize*sizeof(int));
    hipMemcpy(deviceVec, hostData, dataSize*sizeof (int),hipMemcpyHostToDevice);
    return deviceVec;
}

int* cudaData::copyHostToDevice(int* deviceVec, int* hostData, int dataSize){
    hipMemcpy(deviceVec, hostData, dataSize*sizeof (int),hipMemcpyHostToDevice);
    return deviceVec;
}

int* cudaData::allocateGpuMemory(int dataSize, int* hostData){
    int* deviceVec;
    hipMalloc(&deviceVec,dataSize*sizeof(int));
    return deviceVec;
}

int* cudaData::getHostData(int dataSize,int* devData) {
    int* hostData = (int*)malloc(sizeof (int)*dataSize);
    hipMemcpy(hostData,devData, sizeof(int)*dataSize,hipMemcpyDeviceToHost);
    return hostData;
}
	.text
	.file	"cudaData.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_ZN8cudaData7getDataEiPi        # -- Begin function _ZN8cudaData7getDataEiPi
	.p2align	1, 0x90
	.type	_ZN8cudaData7getDataEiPi,@function
_ZN8cudaData7getDataEiPi:               # @_ZN8cudaData7getDataEiPi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	movslq	%esi, %r14
	shlq	$2, %r14
	leaq	8(%rsp), %r15
	movq	%r15, %rdi
	movq	%r14, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r15), %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_ZN8cudaData7getDataEiPi, .Lfunc_end0-_ZN8cudaData7getDataEiPi
	.cfi_endproc
                                        # -- End function
	.globl	_ZN8cudaData16copyHostToDeviceEPiS0_i # -- Begin function _ZN8cudaData16copyHostToDeviceEPiS0_i
	.p2align	1, 0x90
	.type	_ZN8cudaData16copyHostToDeviceEPiS0_i,@function
_ZN8cudaData16copyHostToDeviceEPiS0_i:  # @_ZN8cudaData16copyHostToDeviceEPiS0_i
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rsi, %rbx
	movslq	%ecx, %rax
	shlq	$2, %rax
	movq	%rsi, %rdi
	movq	%rdx, %rsi
	movq	%rax, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_ZN8cudaData16copyHostToDeviceEPiS0_i, .Lfunc_end1-_ZN8cudaData16copyHostToDeviceEPiS0_i
	.cfi_endproc
                                        # -- End function
	.globl	_ZN8cudaData17allocateGpuMemoryEiPi # -- Begin function _ZN8cudaData17allocateGpuMemoryEiPi
	.p2align	1, 0x90
	.type	_ZN8cudaData17allocateGpuMemoryEiPi,@function
_ZN8cudaData17allocateGpuMemoryEiPi:    # @_ZN8cudaData17allocateGpuMemoryEiPi
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movslq	%esi, %rsi
	shlq	$2, %rsi
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_ZN8cudaData17allocateGpuMemoryEiPi, .Lfunc_end2-_ZN8cudaData17allocateGpuMemoryEiPi
	.cfi_endproc
                                        # -- End function
	.globl	_ZN8cudaData11getHostDataEiPi   # -- Begin function _ZN8cudaData11getHostDataEiPi
	.p2align	1, 0x90
	.type	_ZN8cudaData11getHostDataEiPi,@function
_ZN8cudaData11getHostDataEiPi:          # @_ZN8cudaData11getHostDataEiPi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %rbx
	movslq	%esi, %r14
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rax, %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r15, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_ZN8cudaData11getHostDataEiPi, .Lfunc_end3-_ZN8cudaData11getHostDataEiPi
	.cfi_endproc
                                        # -- End function
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
