/*
David Ebert
Homework 1 - GPU Addition

Output:
(N=100)
Time in milliseconds= 0.053000000000000
Last Values are A[99] = 198.000000000000000  B[99] = 99.000000000000000  C[99] = 297.000000000000000

(N=600)
Time in milliseconds= 0.053000000000000
Last Values are A[599] = 1198.000000000000000  B[599] = 599.000000000000000  C[599] = 1797.000000000000000

(N=2000)
Time in milliseconds= 0.040000000000000
Last Values are A[1999] = 3998.000000000000000  B[1999] = 1999.000000000000000  C[1999] = -259257304610248209780291474315334909952.000000000000000

Oh no! It's BROKEN! What can I do about this?

*/


// To compile: nvcc EbertHW1book.cu -O3 -o temp0 -lcudart
// To run: ./temp0
#include <sys/time.h>
#include <stdio.h>

//Length of vectors to be added.
#define N 2000  //if N is greater than dimBlock.x program will break

float *A_CPU, *B_CPU, *C_CPU; //CPU pointers

float *A_GPU, *B_GPU, *C_GPU; //GPU pointers

dim3 dimBlock; //This variable will hold the Dimensions of your block

void AllocateMemory()
{					
	//Allocate Device (GPU) Memory, & allocates the value of the specific pointer/array
	cudaMalloc(&A_GPU,N*sizeof(float));
	cudaMalloc(&B_GPU,N*sizeof(float));
	cudaMalloc(&C_GPU,N*sizeof(float));

	//Allocate Host (CPU) Memory
	A_CPU = (float*)malloc(N*sizeof(float));
	B_CPU = (float*)malloc(N*sizeof(float));
	C_CPU = (float*)malloc(N*sizeof(float));

}

//Loads values into vectors that we will add.
void Innitialize()
{
	int i;
	
	for(i = 0; i < N; i++)
	{		
		A_CPU[i] = (float)2*i;	
		B_CPU[i] = (float)i;
	}
}

//Cleaning up memory after we are finished.
void CleanUp(float *A_CPU,float *B_CPU,float *C_CPU,float *A_GPU,float *B_GPU,float *C_GPU)  //free
{
	free(A_CPU); free(B_CPU); free(C_CPU);
	cudaFree(A_GPU); cudaFree(B_GPU); cudaFree(C_GPU);
}

//This is the kernel. It is the function that will run on the GPU.
//It adds vectors A and B then stores result in vector C
__global__ void Addition(float *A, float *B, float *C, int n)
{

	int id = threadIdx.x;
	
	// This is the part that neds to be completed!
	C[id] = A[id] + B[id];  // Something like this?
}

int main()
{
	int i;
	timeval start, end; //The timeval structure is defined in sys/time.h
	cudaError_t err;
	
	//Set the thread structure that you will be using on the GPU	
	// WHAT IS THIS FUNCTION?	
	//SetUpCudaDevices();

	//Partitioning off the memory that you will be using.
	AllocateMemory();

	//Loading up values to be added.
	Innitialize();
	
	//Starting the timer
	gettimeofday(&start, NULL);

	//Copy Memory from CPU to GPU		
	cudaMemcpyAsync(A_GPU, A_CPU, N*sizeof(float), cudaMemcpyHostToDevice);
	cudaMemcpyAsync(B_GPU, B_CPU, N*sizeof(float), cudaMemcpyHostToDevice);
	
	//Calling the Kernel (GPU) function.	
	Addition<<<1,N>>>(A_GPU, B_GPU, C_GPU, N);
	
	//Copy Memory from GPU to CPU	
	cudaMemcpyAsync(C_CPU, C_GPU, N*sizeof(float), cudaMemcpyDeviceToHost);

	//Stopping the timer
	gettimeofday(&end, NULL);

	//Calculating the total time used in the addition and converting it to milliseconds.
	float time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
	
	//Displaying the time 
	printf("Time in milliseconds= %.15f\n", (time/1000.0));	

	// Displaying vector info you will want to comment out the vector print line when your
	//vector becomes big. This is just to make sure everything is running correctly.	
	for(i = 0; i < N; i++)		
	{		
		//printf("A[%d] = %.15f  B[%d] = %.15f  C[%d] = %.15f\n", i, A_CPU[i], i, B_CPU[i], i, C_CPU[i]);
	}

	//Displaying the last value of the addition for a check when all vector display has been commented out.
	printf("Last Values are A[%d] = %.15f  B[%d] = %.15f  C[%d] = %.15f\n", N-1, A_CPU[N-1], N-1, B_CPU[N-1], N-1, C_CPU[N-1]);
	
	//You're done so cleanup your mess.
	CleanUp(A_CPU,B_CPU,C_CPU,A_GPU,B_GPU,C_GPU);	
	
	return(0);
}

	.file	"tmpxft_00322284_00000000-6_EbertHW1GPU.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z14AllocateMemoryv
	.type	_Z14AllocateMemoryv, @function
_Z14AllocateMemoryv:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$8000, %esi
	leaq	A_GPU(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$8000, %esi
	leaq	B_GPU(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$8000, %esi
	leaq	C_GPU(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$8000, %edi
	call	malloc@PLT
	movl	$8000, %edi
	movq	%rax, A_CPU(%rip)
	call	malloc@PLT
	movl	$8000, %edi
	movq	%rax, B_CPU(%rip)
	call	malloc@PLT
	movq	%rax, C_CPU(%rip)
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14AllocateMemoryv, .-_Z14AllocateMemoryv
	.globl	_Z11Innitializev
	.type	_Z11Innitializev, @function
_Z11Innitializev:
.LFB2028:
	.cfi_startproc
	endbr64
	movq	A_CPU(%rip), %rcx
	movq	B_CPU(%rip), %rdx
	xorl	%eax, %eax
.L5:
	cvtsi2ssl	%eax, %xmm0
	movaps	%xmm0, %xmm1
	addss	%xmm0, %xmm1
	movss	%xmm1, (%rcx,%rax,4)
	movss	%xmm0, (%rdx,%rax,4)
	incq	%rax
	cmpq	$2000, %rax
	jne	.L5
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z11Innitializev, .-_Z11Innitializev
	.globl	_Z7CleanUpPfS_S_S_S_S_
	.type	_Z7CleanUpPfS_S_S_S_S_, @function
_Z7CleanUpPfS_S_S_S_S_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%r8, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%r9, %rbx
	call	free@PLT
	movq	%r14, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	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
	jmp	cudaFree@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z7CleanUpPfS_S_S_S_S_, .-_Z7CleanUpPfS_S_S_S_S_
	.globl	_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i
	.type	_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i, @function
_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i:
.LFB2055:
	.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	.L10
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z8AdditionPfS_S_i(%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
.L10:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i, .-_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i
	.globl	_Z8AdditionPfS_S_i
	.type	_Z8AdditionPfS_S_i, @function
_Z8AdditionPfS_S_i:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i
	.cfi_endproc
.LFE2056:
	.size	_Z8AdditionPfS_S_i, .-_Z8AdditionPfS_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Time in milliseconds= %.15f\n"
.LC2:
	.string	"Last Values are A[%d] = %.15f  B[%d] = %.15f  C[%d] = %.15f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	subq	$72, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z14AllocateMemoryv
	xorl	%esi, %esi
	leaq	24(%rsp), %rdi
	call	_Z11Innitializev
	call	gettimeofday@PLT
	movq	A_CPU(%rip), %rsi
	xorl	%r8d, %r8d
	movq	A_GPU(%rip), %rdi
	movl	$1, %ecx
	movl	$8000, %edx
	call	cudaMemcpyAsync@PLT
	movq	B_CPU(%rip), %rsi
	xorl	%r8d, %r8d
	movq	B_GPU(%rip), %rdi
	movl	$1, %ecx
	movl	$8000, %edx
	call	cudaMemcpyAsync@PLT
	movl	$268435581, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$4, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdx, 40(%rsp)
	movl	$1, 48(%rsp)
	movq	%rdi, 12(%rsp)
	movl	$1, 20(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L16
	movq	C_GPU(%rip), %rdx
	movq	B_GPU(%rip), %rsi
	movl	$2000, %ecx
	movq	A_GPU(%rip), %rdi
	call	_Z32__device_stub__Z8AdditionPfS_S_iPfS_S_i
.L16:
	movq	C_GPU(%rip), %rsi
	movq	C_CPU(%rip), %rdi
	xorl	%r8d, %r8d
	movl	$2, %ecx
	movl	$8000, %edx
	call	cudaMemcpyAsync@PLT
	xorl	%esi, %esi
	leaq	40(%rsp), %rdi
	call	gettimeofday@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	imulq	$1000000, 40(%rsp), %rax
	addq	48(%rsp), %rax
	imulq	$1000000, 24(%rsp), %rdx
	addq	32(%rsp), %rdx
	subq	%rdx, %rax
	cvtsi2ssq	%rax, %xmm0
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	divsd	.LC0(%rip), %xmm0
	call	__printf_chk@PLT
	movq	A_CPU(%rip), %rax
	movl	$1999, %r8d
	movl	$1999, %ecx
	movl	$1999, %edx
	movl	$2, %edi
	cvtss2sd	7996(%rax), %xmm0
	movq	C_CPU(%rip), %rax
	leaq	.LC2(%rip), %rsi
	cvtss2sd	7996(%rax), %xmm2
	movq	B_CPU(%rip), %rax
	cvtss2sd	7996(%rax), %xmm1
	movb	$3, %al
	call	__printf_chk@PLT
	movq	C_GPU(%rip), %r9
	movq	B_GPU(%rip), %r8
	movq	A_GPU(%rip), %rcx
	movq	C_CPU(%rip), %rdx
	movq	B_CPU(%rip), %rsi
	movq	A_CPU(%rip), %rdi
	call	_Z7CleanUpPfS_S_S_S_S_
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	xorl	%eax, %eax
	addq	$72, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC3:
	.string	"_Z8AdditionPfS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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	.LC3(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z8AdditionPfS_S_i(%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
.LFE2058:
	.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
	.globl	dimBlock
	.data
	.align 8
	.type	dimBlock, @object
	.size	dimBlock, 12
dimBlock:
	.long	1
	.long	1
	.long	1
	.globl	C_GPU
	.bss
	.align 8
	.type	C_GPU, @object
	.size	C_GPU, 8
C_GPU:
	.zero	8
	.globl	B_GPU
	.align 8
	.type	B_GPU, @object
	.size	B_GPU, 8
B_GPU:
	.zero	8
	.globl	A_GPU
	.align 8
	.type	A_GPU, @object
	.size	A_GPU, 8
A_GPU:
	.zero	8
	.globl	C_CPU
	.align 8
	.type	C_CPU, @object
	.size	C_CPU, 8
C_CPU:
	.zero	8
	.globl	B_CPU
	.align 8
	.type	B_CPU, @object
	.size	B_CPU, 8
B_CPU:
	.zero	8
	.globl	A_CPU
	.align 8
	.type	A_CPU, @object
	.size	A_CPU, 8
A_CPU:
	.zero	8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1083129856
	.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:

/*
David Ebert
Homework 1 - GPU Addition

Output:
(N=100)
Time in milliseconds= 0.053000000000000
Last Values are A[99] = 198.000000000000000  B[99] = 99.000000000000000  C[99] = 297.000000000000000

(N=600)
Time in milliseconds= 0.053000000000000
Last Values are A[599] = 1198.000000000000000  B[599] = 599.000000000000000  C[599] = 1797.000000000000000

(N=2000)
Time in milliseconds= 0.040000000000000
Last Values are A[1999] = 3998.000000000000000  B[1999] = 1999.000000000000000  C[1999] = -259257304610248209780291474315334909952.000000000000000

Oh no! It's BROKEN! What can I do about this?

*/


// To compile: nvcc EbertHW1book.cu -O3 -o temp0 -lcudart
// To run: ./temp0

#include <hip/hip_runtime.h>
#include <sys/time.h>
#include <stdio.h>

//Length of vectors to be added.
#define N 2000  //if N is greater than dimBlock.x program will break

float *A_CPU, *B_CPU, *C_CPU; //CPU pointers

float *A_GPU, *B_GPU, *C_GPU; //GPU pointers

dim3 dimBlock; //This variable will hold the Dimensions of your block

void AllocateMemory()
{					
	//Allocate Device (GPU) Memory, & allocates the value of the specific pointer/array
	hipMalloc(&A_GPU,N*sizeof(float));
	hipMalloc(&B_GPU,N*sizeof(float));
	hipMalloc(&C_GPU,N*sizeof(float));

	//Allocate Host (CPU) Memory
	A_CPU = (float*)malloc(N*sizeof(float));
	B_CPU = (float*)malloc(N*sizeof(float));
	C_CPU = (float*)malloc(N*sizeof(float));

}

//Loads values into vectors that we will add.
void Innitialize()
{
	int i;
	
	for(i = 0; i < N; i++)
	{		
		A_CPU[i] = (float)2*i;	
		B_CPU[i] = (float)i;
	}
}

//Cleaning up memory after we are finished.
void CleanUp(float *A_CPU,float *B_CPU,float *C_CPU,float *A_GPU,float *B_GPU,float *C_GPU)  //free
{
	free(A_CPU); free(B_CPU); free(C_CPU);
	hipFree(A_GPU); hipFree(B_GPU); hipFree(C_GPU);
}

//This is the kernel. It is the function that will run on the GPU.
//It adds vectors A and B then stores result in vector C
__global__ void Addition(float *A, float *B, float *C, int n)
{

	int id = threadIdx.x;
	
	// This is the part that neds to be completed!
	C[id] = A[id] + B[id];  // Something like this?
}

int main()
{
	int i;
	timeval start, end; //The timeval structure is defined in sys/time.h
	hipError_t err;
	
	//Set the thread structure that you will be using on the GPU	
	// WHAT IS THIS FUNCTION?	
	//SetUpCudaDevices();

	//Partitioning off the memory that you will be using.
	AllocateMemory();

	//Loading up values to be added.
	Innitialize();
	
	//Starting the timer
	gettimeofday(&start, NULL);

	//Copy Memory from CPU to GPU		
	hipMemcpyAsync(A_GPU, A_CPU, N*sizeof(float), hipMemcpyHostToDevice);
	hipMemcpyAsync(B_GPU, B_CPU, N*sizeof(float), hipMemcpyHostToDevice);
	
	//Calling the Kernel (GPU) function.	
	Addition<<<1,N>>>(A_GPU, B_GPU, C_GPU, N);
	
	//Copy Memory from GPU to CPU	
	hipMemcpyAsync(C_CPU, C_GPU, N*sizeof(float), hipMemcpyDeviceToHost);

	//Stopping the timer
	gettimeofday(&end, NULL);

	//Calculating the total time used in the addition and converting it to milliseconds.
	float time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
	
	//Displaying the time 
	printf("Time in milliseconds= %.15f\n", (time/1000.0));	

	// Displaying vector info you will want to comment out the vector print line when your
	//vector becomes big. This is just to make sure everything is running correctly.	
	for(i = 0; i < N; i++)		
	{		
		//printf("A[%d] = %.15f  B[%d] = %.15f  C[%d] = %.15f\n", i, A_CPU[i], i, B_CPU[i], i, C_CPU[i]);
	}

	//Displaying the last value of the addition for a check when all vector display has been commented out.
	printf("Last Values are A[%d] = %.15f  B[%d] = %.15f  C[%d] = %.15f\n", N-1, A_CPU[N-1], N-1, B_CPU[N-1], N-1, C_CPU[N-1]);
	
	//You're done so cleanup your mess.
	CleanUp(A_CPU,B_CPU,C_CPU,A_GPU,B_GPU,C_GPU);	
	
	return(0);
}

	.text
	.file	"EbertHW1GPU.hip"
	.globl	_Z14AllocateMemoryv             # -- Begin function _Z14AllocateMemoryv
	.type	_Z14AllocateMemoryv,@function
_Z14AllocateMemoryv:                    # @_Z14AllocateMemoryv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$A_GPU, %edi
	movl	$8000, %esi                     # imm = 0x1F40
	callq	hipMalloc
	movl	$B_GPU, %edi
	movl	$8000, %esi                     # imm = 0x1F40
	callq	hipMalloc
	movl	$C_GPU, %edi
	movl	$8000, %esi                     # imm = 0x1F40
	callq	hipMalloc
	movl	$8000, %edi                     # imm = 0x1F40
	callq	malloc
	movq	%rax, A_CPU(%rip)
	movl	$8000, %edi                     # imm = 0x1F40
	callq	malloc
	movq	%rax, B_CPU(%rip)
	movl	$8000, %edi                     # imm = 0x1F40
	callq	malloc
	movq	%rax, C_CPU(%rip)
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z14AllocateMemoryv, .Lfunc_end0-_Z14AllocateMemoryv
	.cfi_endproc
                                        # -- End function
	.globl	_Z11Innitializev                # -- Begin function _Z11Innitializev
	.type	_Z11Innitializev,@function
_Z11Innitializev:                       # @_Z11Innitializev
	.cfi_startproc
# %bb.0:
	movq	A_CPU(%rip), %rax
	movq	B_CPU(%rip), %rcx
	xorl	%edx, %edx
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edx, %xmm0
	movaps	%xmm0, %xmm1
	addss	%xmm0, %xmm1
	movss	%xmm1, (%rax,%rdx,4)
	movss	%xmm0, (%rcx,%rdx,4)
	incq	%rdx
	cmpq	$2000, %rdx                     # imm = 0x7D0
	jne	.LBB1_1
# %bb.2:
	retq
.Lfunc_end1:
	.size	_Z11Innitializev, .Lfunc_end1-_Z11Innitializev
	.cfi_endproc
                                        # -- End function
	.globl	_Z7CleanUpPfS_S_S_S_S_          # -- Begin function _Z7CleanUpPfS_S_S_S_S_
	.type	_Z7CleanUpPfS_S_S_S_S_,@function
_Z7CleanUpPfS_S_S_S_S_:                 # @_Z7CleanUpPfS_S_S_S_S_
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%r9, %rbx
	movq	%r8, %r14
	movq	%rcx, %r15
	movq	%rdx, %r12
	movq	%rsi, %r13
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	movq	%r15, %rdi
	callq	hipFree
	movq	%r14, %rdi
	callq	hipFree
	movq	%rbx, %rdi
	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
	jmp	hipFree                         # TAILCALL
.Lfunc_end2:
	.size	_Z7CleanUpPfS_S_S_S_S_, .Lfunc_end2-_Z7CleanUpPfS_S_S_S_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z23__device_stub__AdditionPfS_S_i # -- Begin function _Z23__device_stub__AdditionPfS_S_i
	.type	_Z23__device_stub__AdditionPfS_S_i,@function
_Z23__device_stub__AdditionPfS_S_i:     # @_Z23__device_stub__AdditionPfS_S_i
	.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	$_Z8AdditionPfS_S_i, %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	_Z23__device_stub__AdditionPfS_S_i, .Lfunc_end3-_Z23__device_stub__AdditionPfS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI4_0:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	callq	_Z14AllocateMemoryv
	movq	A_CPU(%rip), %rax
	xorl	%ecx, %ecx
	movq	B_CPU(%rip), %rdx
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ecx, %xmm0
	movaps	%xmm0, %xmm1
	addss	%xmm0, %xmm1
	movss	%xmm1, (%rax,%rcx,4)
	movss	%xmm0, (%rdx,%rcx,4)
	incq	%rcx
	cmpq	$2000, %rcx                     # imm = 0x7D0
	jne	.LBB4_1
# %bb.2:                                # %_Z11Innitializev.exit
	movq	%rsp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	A_GPU(%rip), %rdi
	movq	A_CPU(%rip), %rsi
	movl	$8000, %edx                     # imm = 0x1F40
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	hipMemcpyAsync
	movq	B_GPU(%rip), %rdi
	movq	B_CPU(%rip), %rsi
	movl	$8000, %edx                     # imm = 0x1F40
	movl	$1, %ecx
	xorl	%r8d, %r8d
	callq	hipMemcpyAsync
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	1999(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_4
# %bb.3:
	movq	A_GPU(%rip), %rdi
	movq	B_GPU(%rip), %rsi
	movq	C_GPU(%rip), %rdx
	movl	$2000, %ecx                     # imm = 0x7D0
	callq	_Z23__device_stub__AdditionPfS_S_i
.LBB4_4:
	movq	C_CPU(%rip), %rdi
	movq	C_GPU(%rip), %rsi
	movl	$8000, %edx                     # imm = 0x1F40
	movl	$2, %ecx
	xorl	%r8d, %r8d
	callq	hipMemcpyAsync
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	subq	(%rsp), %rax
	movq	8(%rbx), %rcx
	imulq	$1000000, %rax, %rax            # imm = 0xF4240
	subq	8(%rsp), %rcx
	addq	%rax, %rcx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rcx, %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	.LCPI4_0(%rip), %xmm0
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	movq	A_CPU(%rip), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	7996(%rax), %xmm0
	movq	B_CPU(%rip), %rax
	xorps	%xmm1, %xmm1
	cvtss2sd	7996(%rax), %xmm1
	movq	C_CPU(%rip), %rax
	cvtss2sd	7996(%rax), %xmm2
	movl	$.L.str.1, %edi
	movl	$1999, %esi                     # imm = 0x7CF
	movl	$1999, %edx                     # imm = 0x7CF
	movl	$1999, %ecx                     # imm = 0x7CF
	movb	$3, %al
	callq	printf
	movq	A_CPU(%rip), %rdi
	movq	B_CPU(%rip), %rsi
	movq	C_CPU(%rip), %rdx
	movq	A_GPU(%rip), %rcx
	movq	B_GPU(%rip), %r8
	movq	C_GPU(%rip), %r9
	callq	_Z7CleanUpPfS_S_S_S_S_
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	main, .Lfunc_end4-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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8AdditionPfS_S_i, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	A_CPU,@object                   # @A_CPU
	.bss
	.globl	A_CPU
	.p2align	3, 0x0
A_CPU:
	.quad	0
	.size	A_CPU, 8

	.type	B_CPU,@object                   # @B_CPU
	.globl	B_CPU
	.p2align	3, 0x0
B_CPU:
	.quad	0
	.size	B_CPU, 8

	.type	C_CPU,@object                   # @C_CPU
	.globl	C_CPU
	.p2align	3, 0x0
C_CPU:
	.quad	0
	.size	C_CPU, 8

	.type	A_GPU,@object                   # @A_GPU
	.globl	A_GPU
	.p2align	3, 0x0
A_GPU:
	.quad	0
	.size	A_GPU, 8

	.type	B_GPU,@object                   # @B_GPU
	.globl	B_GPU
	.p2align	3, 0x0
B_GPU:
	.quad	0
	.size	B_GPU, 8

	.type	C_GPU,@object                   # @C_GPU
	.globl	C_GPU
	.p2align	3, 0x0
C_GPU:
	.quad	0
	.size	C_GPU, 8

	.type	dimBlock,@object                # @dimBlock
	.data
	.globl	dimBlock
	.p2align	2, 0x0
dimBlock:
	.long	1                               # 0x1
	.long	1                               # 0x1
	.long	1                               # 0x1
	.size	dimBlock, 12

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Time in milliseconds= %.15f\n"
	.size	.L.str, 29

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Last Values are A[%d] = %.15f  B[%d] = %.15f  C[%d] = %.15f\n"
	.size	.L.str.1, 61

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8AdditionPfS_S_i"
	.size	.L__unnamed_1, 19

	.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

	.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 _Z23__device_stub__AdditionPfS_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym A_GPU
	.addrsig_sym B_GPU
	.addrsig_sym C_GPU
	.addrsig_sym _Z8AdditionPfS_S_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8AdditionPfS_S_i      ; -- Begin function _Z8AdditionPfS_S_i
	.globl	_Z8AdditionPfS_S_i
	.p2align	8
	.type	_Z8AdditionPfS_S_i,@function
_Z8AdditionPfS_S_i:                     ; @_Z8AdditionPfS_S_i
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshlrev_b32_e32 v0, 2, v0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_clause 0x1
	global_load_b32 v1, v0, s[4:5]
	global_load_b32 v2, v0, s[6:7]
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v1, v1, v2
	global_store_b32 v0, v1, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8AdditionPfS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 3
		.amdhsa_next_free_sgpr 8
		.amdhsa_reserve_vcc 0
		.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	_Z8AdditionPfS_S_i, .Lfunc_end0-_Z8AdditionPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 72
; NumSgprs: 8
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 8
; NumVGPRsForWavesPerEU: 3
; 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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8AdditionPfS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     8
    .sgpr_spill_count: 0
    .symbol:         _Z8AdditionPfS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
