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

int main(void)
{
printf("Getting start CUDA excercise Now \n");
float *a_h, *b_h;    // variable declartion for host (CPU)
float *a_d, *b_d;    // variabel declaration for device (GPU)
int N = 14, nBytes, i,j ;

nBytes = N * sizeof(float);
//memory allocation for CPU
a_h = (float *)malloc(nBytes);
b_h = (float *)malloc(nBytes);

// memory allocation for GPU
cudaMalloc((void **) &a_d, nBytes);
cudaMalloc((void **) &b_d, nBytes);

printf("Value of a_h : \n");
for (i=0; i<N; i++) 
{
  a_h[i] = 100.f + i;
  printf("%f \n", a_h[i]);    // print value of a_h
}

// start using CUDA memory copy 

cudaMemcpy(a_d,a_h,nBytes,cudaMemcpyHostToDevice);    // CPU to GPU
cudaMemcpy(b_d,a_d,nBytes,cudaMemcpyDeviceToDevice);  // GPU to GPU
cudaMemcpy(b_h,b_d,nBytes,cudaMemcpyDeviceToHost);


// print value of b_h

printf ("Value of b_h : \n");
for (j=0; j<N; j++) 
{
  printf("%f \n", b_h[j]);    // print value of b_h
}

// we have not to show the values of a_h and b_h 

for(int i=0; i< N; i++) assert(a_h[i]==b_h[i]);


}

	.file	"tmpxft_00358969_00000000-6_move.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Getting start CUDA excercise Now \n"
.LC1:
	.string	"Value of a_h : \n"
.LC3:
	.string	"%f \n"
.LC4:
	.string	"Value of b_h : \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %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
	xorl	%ebx, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$56, %edi
	call	malloc@PLT
	movl	$56, %edi
	movq	%rax, %r12
	call	malloc@PLT
	leaq	8(%rsp), %rdi
	movl	$56, %esi
	movq	%rax, %rbp
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movl	$56, %esi
	call	cudaMalloc@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L3:
	cvtsi2ssl	%ebx, %xmm0
	leaq	.LC3(%rip), %r13
	movl	$2, %edi
	movb	$1, %al
	addss	.LC2(%rip), %xmm0
	movq	%r13, %rsi
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	cmpq	$14, %rbx
	jne	.L3
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%r12, %rsi
	xorl	%ebx, %ebx
	movl	$56, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$3, %ecx
	movl	$56, %edx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$56, %edx
	call	cudaMemcpy@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L4:
	cvtss2sd	0(%rbp,%rbx,4), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	incq	%rbx
	cmpq	$14, %rbx
	jne	.L4
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2053:
	.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
.LFE2053:
	.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	1120403456
	.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<hip/hip_runtime.h>
#include<stdio.h>
#include <assert.h>

int main(void)
{
printf("Getting start CUDA excercise Now \n");
float *a_h, *b_h;    // variable declartion for host (CPU)
float *a_d, *b_d;    // variabel declaration for device (GPU)
int N = 14, nBytes, i,j ;

nBytes = N * sizeof(float);
//memory allocation for CPU
a_h = (float *)malloc(nBytes);
b_h = (float *)malloc(nBytes);

// memory allocation for GPU
hipMalloc((void **) &a_d, nBytes);
hipMalloc((void **) &b_d, nBytes);

printf("Value of a_h : \n");
for (i=0; i<N; i++) 
{
  a_h[i] = 100.f + i;
  printf("%f \n", a_h[i]);    // print value of a_h
}

// start using CUDA memory copy 

hipMemcpy(a_d,a_h,nBytes,hipMemcpyHostToDevice);    // CPU to GPU
hipMemcpy(b_d,a_d,nBytes,hipMemcpyDeviceToDevice);  // GPU to GPU
hipMemcpy(b_h,b_d,nBytes,hipMemcpyDeviceToHost);


// print value of b_h

printf ("Value of b_h : \n");
for (j=0; j<N; j++) 
{
  printf("%f \n", b_h[j]);    // print value of b_h
}

// we have not to show the values of a_h and b_h 

for(int i=0; i< N; i++) assert(a_h[i]==b_h[i]);


}

	.text
	.file	"move.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x42c80000                      # float 100
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$56, %edi
	callq	malloc
	movq	%rax, %r14
	movl	$56, %edi
	callq	malloc
	movq	%rax, %rbx
	leaq	8(%rsp), %rdi
	movl	$56, %esi
	callq	hipMalloc
	movq	%rsp, %rdi
	movl	$56, %esi
	callq	hipMalloc
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	xorl	%r15d, %r15d
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	addss	.LCPI0_0(%rip), %xmm0
	movss	%xmm0, (%r14,%r15,4)
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	$14, %r15
	jne	.LBB0_1
# %bb.2:
	movq	8(%rsp), %rdi
	movl	$56, %edx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	$56, %edx
	movl	$3, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rsi
	movl	$56, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorl	%r14d, %r14d
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r14,4), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	$14, %r14
	jne	.LBB0_3
# %bb.4:                                # %.preheader.preheader
	xorl	%eax, %eax
	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	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"%f \n"
	.size	.L.str.2, 5

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Getting start CUDA excercise Now "
	.size	.Lstr, 34

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Value of a_h : "
	.size	.Lstr.1, 16

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Value of b_h : "
	.size	.Lstr.2, 16

	.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
