/*
KAM PUI SO
CS510 GPU
Homework 4

Pre 12.1 problem. No const memory for kernel
*/

#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUMATOM 32 
#define DIMX 64
#define DIMY 64
#define DIMZ 64
#define MAXW 10
#define SPACE 2
#define TILESIZE 16

// data structure
typedef struct {
	float w;	// charge
  float x;
	float y;
	float z;
} AtomInfo;


// global variable
AtomInfo atominfo[NUMATOM];


// __constant__ AtomInfo atominfo[NUMATOM];



// kernal
__global__ void cenergy_kernel(float *energygrid, dim3 grid, float gridspacing, float z, AtomInfo *atominfo, int numatoms) {

	int xindex = blockIdx.x * blockDim.x + threadIdx.x;
	int yindex = blockIdx.y * blockDim.y + threadIdx.y;
	int k = z / gridspacing;
	int outaddr = grid.x * grid.y * k + grid.x * yindex + xindex;

	float curenergy = energygrid[outaddr];
	float coorx = gridspacing * (float) xindex;
	float coory = gridspacing * (float) yindex;
	int atomid;
	float energyval = 0.0f;

	for (atomid = 0; atomid < numatoms; ++atomid) {
		float dx = coorx - atominfo[atomid].x;
		float dy = coory - atominfo[atomid].y;
//		float dz = z - atominfo[atomid].z;
		energyval += atominfo[atomid].w / sqrtf(dx*dx + dy*dy + atominfo[atomid].z);
	}

	energygrid[outaddr] = curenergy + energyval;
}


// host
void cenergy_dev(float *energygrid, dim3 grid, float gridspacing, float z, AtomInfo *atominfo, int numatoms) {

	// Step 1: allocate memory
	float * dev_energygrid;
	AtomInfo * dev_atominfo;
	int gridSize = grid.x * grid.y * grid.z;

	cudaMalloc((void **) &dev_energygrid, sizeof(float) * gridSize);
	cudaMalloc((void **) &dev_atominfo, sizeof(AtomInfo) * numatoms);

	// Step 2: copy the input vector to the device
	cudaMemcpy(dev_atominfo, atominfo, sizeof(AtomInfo) * numatoms, cudaMemcpyHostToDevice);
	
	// Step 3: Invoke the kernel
	dim3 dimGrid(TILESIZE, TILESIZE, 1);
	dim3 dimBlock(ceil(grid.x / (float) TILESIZE), ceil(grid.y / (float) TILESIZE), 1);
	cenergy_kernel<<<dimGrid, dimBlock>>>(dev_energygrid, grid, gridspacing, z, dev_atominfo, numatoms);

	// Step 4: Retrieve the results
	cudaMemcpy(energygrid, dev_energygrid, sizeof(float) * gridSize, cudaMemcpyDeviceToHost);

	// Step 5: Free device memory
	cudaFree(dev_energygrid);
	cudaFree(dev_atominfo);
}


// initialize atominfo
void initialize() {
	for (int i = 0; i < NUMATOM; ++i) {
		atominfo[i].w = rand() % MAXW;
		atominfo[i].x = rand() % DIMX;
		atominfo[i].y = rand() % DIMY;
		atominfo[i].z = rand() % DIMZ;
	}
}

/*
// uniform charge
void uniformCharge() {
	for (int i = 0; i < NUMATOM; ++i) {
		atominfo[i].w = 1.0f;
		atominfo[i].x = rand() % DIMX;
		atominfo[i].y = rand() % DIMY;
		atominfo[i].z = rand() % DIMZ;
	}
}
*/

// print atoms
void printAtoms() {
	for (int i = 0; i < NUMATOM; ++i) {
		printf("index=%d, charge=%.2f, x=%.2f, y=%.2f, z=%.2f\n", i, atominfo[i].w, atominfo[i].x, atominfo[i].y, atominfo[i].z);
	}
}


// serial energy calculation
void serial(float *energygrid, dim3 grid, float gridspacing, float z, int numatom) {
	int i, j, n;
	int k = z / gridspacing;
	float x, y, energy;

	for (j = 0; j < grid.y; ++j) {
		y = gridspacing * (float) j;
		for (i = 0; i < grid.x; ++i) {
			x = gridspacing * (float) i;
			energy = 0.0f;
			for (n = 0; n < numatom; ++n) {
				float	dx = x - atominfo[n].x;
				float dy = y - atominfo[n].y;
				float dz = z - atominfo[n].z;
				energy += atominfo[n].w / sqrtf(dx*dx + dy*dy + dz*dz);
			}
			energygrid[grid.x * grid.y * k + grid.x * j + i] = energy;
		}
	}
}


// print energy grid
void printEnergy(float *energygrid, dim3 grid, float gridspacing) {
	for (int z = 0; z < grid.z; ++z) {
		for (int y = 0; y < grid.y; ++y) {
			for (int x = 0; x < grid.x; ++x) {
				printf("x=%d, y=%d, z=%d, potential=%.2f\n", x, y, z, energygrid[grid.x *grid.y * z + grid.x * y + x]);
			}
		}
	}
}



// energy main
void energy() {
	dim3 grid(DIMX/SPACE, DIMY/SPACE, DIMZ/SPACE);
	float gridspacing = (float) SPACE;
	float energygrid[DIMX/SPACE * DIMY/SPACE * DIMZ/SPACE];
	float	z = 0.0f;	

	for (int i = 0; i < grid.z; ++i) {
		z = gridspacing * (float) i;

		cenergy_dev(energygrid, grid, gridspacing, z, atominfo, NUMATOM);
//		serial(energygrid, grid, gridspacing, z, NUMATOM);
	}
	printEnergy(energygrid, grid, gridspacing);
}

// main
int main(void) {
	
	// initialize
	srand(time(NULL));
	initialize();		

	printAtoms();
  energy();

	return 0;
}







	.file	"tmpxft_0027795f_00000000-6_hw4_no_const_mem.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2036:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2036:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z10initializev
	.type	_Z10initializev, @function
_Z10initializev:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	$10, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	atominfo(%rip), %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 48
	leaq	512(%rbx), %r13
.L3:
	call	rand@PLT
	movl	$64, %ebp
	addq	$16, %rbx
	cltd
	idivl	%r12d
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -16(%rbx)
	call	rand@PLT
	cltd
	idivl	%ebp
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -12(%rbx)
	call	rand@PLT
	cltd
	idivl	%ebp
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -8(%rbx)
	call	rand@PLT
	cltd
	idivl	%ebp
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, -4(%rbx)
	cmpq	%r13, %rbx
	jne	.L3
	popq	%rax
	.cfi_def_cfa_offset 40
	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
.LFE2028:
	.size	_Z10initializev, .-_Z10initializev
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"index=%d, charge=%.2f, x=%.2f, y=%.2f, z=%.2f\n"
	.text
	.globl	_Z10printAtomsv
	.type	_Z10printAtomsv, @function
_Z10printAtomsv:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	atominfo(%rip), %rbx
.L8:
	movl	%ebp, %edx
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$4, %al
	incl	%ebp
	cvtss2sd	(%rbx), %xmm0
	cvtss2sd	12(%rbx), %xmm3
	cvtss2sd	8(%rbx), %xmm2
	cvtss2sd	4(%rbx), %xmm1
	call	__printf_chk@PLT
	addq	$16, %rbx
	cmpl	$32, %ebp
	jne	.L8
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z10printAtomsv, .-_Z10printAtomsv
	.globl	_Z6serialPf4dim3ffi
	.type	_Z6serialPf4dim3ffi, @function
_Z6serialPf4dim3ffi:
.LFB2030:
	.cfi_startproc
	endbr64
	movaps	%xmm0, %xmm2
	movaps	%xmm1, %xmm0
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%ecx, %r15d
	divss	%xmm2, %xmm0
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %edx
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%esi, %eax
	xorl	%r13d, %r13d
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%rsi, 48(%rsp)
	movl	52(%rsp), %ecx
	imull	%ecx, %edx
	cvttss2sil	%xmm0, %ebp
	imull	%edx, %ebp
.L12:
	cmpl	%ecx, %r13d
	je	.L19
	cvtsi2ssl	%r13d, %xmm5
	xorl	%r12d, %r12d
	mulss	%xmm2, %xmm5
.L13:
	cmpl	%eax, %r12d
	je	.L20
	cvtsi2ssl	%r12d, %xmm7
	leaq	atominfo(%rip), %rbx
	xorps	%xmm6, %xmm6
	xorl	%edx, %edx
	mulss	%xmm2, %xmm7
.L14:
	cmpl	%r15d, %edx
	jge	.L21
	movaps	%xmm7, %xmm0
	movaps	%xmm5, %xmm4
	subss	4(%rbx), %xmm0
	movss	(%rbx), %xmm8
	subss	8(%rbx), %xmm4
	movaps	%xmm1, %xmm3
	movl	%eax, 44(%rsp)
	addq	$16, %rbx
	subss	-4(%rbx), %xmm3
	movl	%ecx, 36(%rsp)
	mulss	%xmm0, %xmm0
	movl	%edx, 28(%rsp)
	mulss	%xmm4, %xmm4
	movss	%xmm2, 40(%rsp)
	mulss	%xmm3, %xmm3
	movss	%xmm6, 32(%rsp)
	movss	%xmm7, 24(%rsp)
	movss	%xmm5, 20(%rsp)
	movss	%xmm1, 16(%rsp)
	addss	%xmm4, %xmm0
	movss	%xmm8, 12(%rsp)
	addss	%xmm3, %xmm0
	call	sqrtf@PLT
	movss	12(%rsp), %xmm8
	movss	32(%rsp), %xmm6
	movaps	%xmm0, %xmm3
	movl	28(%rsp), %edx
	movl	44(%rsp), %eax
	movaps	%xmm8, %xmm0
	movss	40(%rsp), %xmm2
	movl	36(%rsp), %ecx
	divss	%xmm3, %xmm0
	movss	24(%rsp), %xmm7
	movss	20(%rsp), %xmm5
	incl	%edx
	movss	16(%rsp), %xmm1
	addss	%xmm0, %xmm6
	jmp	.L14
.L21:
	leal	(%r12,%rbp), %edx
	incl	%r12d
	movss	%xmm6, (%r14,%rdx,4)
	jmp	.L13
.L20:
	incl	%r13d
	addl	%eax, %ebp
	jmp	.L12
.L19:
	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
.LFE2030:
	.size	_Z6serialPf4dim3ffi, .-_Z6serialPf4dim3ffi
	.section	.rodata.str1.1
.LC2:
	.string	"x=%d, y=%d, z=%d, potential=%.2f\n"
	.text
	.globl	_Z11printEnergyPf4dim3f
	.type	_Z11printEnergyPf4dim3f, @function
_Z11printEnergyPf4dim3f:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%esi, %r11d
	movl	%esi, %r9d
	xorl	%r8d, %r8d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	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	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%rsi, 16(%rsp)
	movl	20(%rsp), %r15d
	movl	%edx, 24(%rsp)
	imull	%r15d, %r11d
.L23:
	cmpl	24(%rsp), %r8d
	jnb	.L22
	movl	%r13d, %r12d
	xorl	%ebp, %ebp
.L28:
	cmpl	%r15d, %ebp
	je	.L25
	xorl	%ebx, %ebx
.L26:
	cmpl	%r9d, %ebx
	je	.L30
	leal	(%rbx,%r12), %eax
	movl	%ebx, %edx
	movl	%ebp, %ecx
	movl	$2, %edi
	cvtss2sd	(%r14,%rax,4), %xmm0
	leaq	.LC2(%rip), %rsi
	movb	$1, %al
	movl	%r9d, 12(%rsp)
	movl	%r11d, 8(%rsp)
	incl	%ebx
	movl	%r8d, 4(%rsp)
	call	__printf_chk@PLT
	movl	12(%rsp), %r9d
	movl	8(%rsp), %r11d
	movl	4(%rsp), %r8d
	jmp	.L26
.L30:
	incl	%ebp
	addl	%r9d, %r12d
	jmp	.L28
.L25:
	incl	%r8d
	addl	%r11d, %r13d
	jmp	.L23
.L22:
	addq	$40, %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
.LFE2031:
	.size	_Z11printEnergyPf4dim3f, .-_Z11printEnergyPf4dim3f
	.globl	_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi
	.type	_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi, @function
_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movss	%xmm0, 20(%rsp)
	movss	%xmm1, 16(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movq	%rsi, 112(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rax, 104(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movl	$1, 64(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	pushq	48(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 192
	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 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L31:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi, .-_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi
	.globl	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi
	.type	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi, @function
_Z14cenergy_kernelPf4dim3ffP8AtomInfoi:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	%edx, %eax
	movq	%rcx, %rdx
	movl	%r8d, %ecx
	movq	%rsi, (%rsp)
	movq	%rsp, %rsi
	movl	%eax, 8(%rsp)
	call	_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi, .-_Z14cenergy_kernelPf4dim3ffP8AtomInfoi
	.globl	_Z11cenergy_devPf4dim3ffP8AtomInfoi
	.type	_Z11cenergy_devPf4dim3ffP8AtomInfoi, @function
_Z11cenergy_devPf4dim3ffP8AtomInfoi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%edx, %eax
	movslq	%r8d, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r15, %rbp
	salq	$4, %r15
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%rsi, 16(%rsp)
	movl	20(%rsp), %r12d
	movq	%rdi, (%rsp)
	leaq	32(%rsp), %rdi
	movl	%r12d, %ebx
	movl	%edx, 24(%rsp)
	imull	%r14d, %ebx
	movss	%xmm1, 12(%rsp)
	movss	%xmm0, 8(%rsp)
	movq	%fs:40, %rdx
	movq	%rdx, 88(%rsp)
	xorl	%edx, %edx
	imull	%eax, %ebx
	movslq	%ebx, %rbx
	salq	$2, %rbx
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movq	%r15, %rsi
	call	cudaMalloc@PLT
	movq	40(%rsp), %rdi
	movq	%r13, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%r12d, %r8d
	cvtsi2ssq	%r8, %xmm0
	mulss	.LC3(%rip), %xmm0
	call	ceilf@PLT
	movd	%xmm0, %r13d
	cvtsi2ssq	%r14, %xmm0
	mulss	.LC3(%rip), %xmm0
	call	ceilf@PLT
	movd	%r13d, %xmm2
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttss2siq	%xmm0, %rax
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$68719476752, %rdi
	movl	%eax, 64(%rsp)
	cvttss2siq	%xmm2, %rax
	movl	%eax, 68(%rsp)
	movq	64(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	movss	12(%rsp), %xmm1
	testl	%eax, %eax
	jne	.L42
	movq	16(%rsp), %rax
	movq	40(%rsp), %rdx
	leaq	76(%rsp), %rsi
	movl	%ebp, %ecx
	movss	8(%rsp), %xmm0
	movq	32(%rsp), %rdi
	movq	%rax, 76(%rsp)
	movl	24(%rsp), %eax
	movl	%eax, 84(%rsp)
	call	_Z52__device_stub__Z14cenergy_kernelPf4dim3ffP8AtomInfoiPfR4dim3ffP8AtomInfoi
.L42:
	movq	32(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	$2, %ecx
	movq	%rbx, %rdx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$104, %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
.LFE2027:
	.size	_Z11cenergy_devPf4dim3ffP8AtomInfoi, .-_Z11cenergy_devPf4dim3ffP8AtomInfoi
	.globl	_Z6energyv
	.type	_Z6energyv, @function
_Z6energyv:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	-131072(%rsp), %r11
	.cfi_def_cfa 11, 131104
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$32, %rsp
	.cfi_def_cfa_offset 131136
	xorl	%ebx, %ebx
	leaq	atominfo(%rip), %r12
	movq	%fs:40, %rax
	movq	%rax, 131096(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 12(%rsp)
.L46:
	cvtsi2ssl	%ebx, %xmm1
	movq	12(%rsp), %rsi
	movq	%r12, %rcx
	incl	%ebx
	leaq	24(%rsp), %rbp
	movl	$32, %r8d
	movss	.LC4(%rip), %xmm0
	movl	$32, %edx
	movq	%rbp, %rdi
	movl	$32, 20(%rsp)
	addss	%xmm1, %xmm1
	call	_Z11cenergy_devPf4dim3ffP8AtomInfoi
	cmpl	$32, %ebx
	jne	.L46
	movss	.LC4(%rip), %xmm0
	movq	12(%rsp), %rsi
	movq	%rbp, %rdi
	movl	20(%rsp), %edx
	call	_Z11printEnergyPf4dim3f
	movq	131096(%rsp), %rax
	subq	%fs:40, %rax
	je	.L47
	call	__stack_chk_fail@PLT
.L47:
	addq	$131104, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z6energyv, .-_Z6energyv
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	call	_Z10initializev
	call	_Z10printAtomsv
	call	_Z6energyv
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z14cenergy_kernelPf4dim3ffP8AtomInfoi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi(%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
.LFE2061:
	.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	atominfo
	.bss
	.align 32
	.type	atominfo, @object
	.size	atominfo, 512
atominfo:
	.zero	512
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1031798784
	.align 4
.LC4:
	.long	1073741824
	.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:

/*
KAM PUI SO
CS510 GPU
Homework 4

Pre 12.1 problem. No const memory for kernel
*/


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

#define NUMATOM 32 
#define DIMX 64
#define DIMY 64
#define DIMZ 64
#define MAXW 10
#define SPACE 2
#define TILESIZE 16

// data structure
typedef struct {
	float w;	// charge
  float x;
	float y;
	float z;
} AtomInfo;


// global variable
AtomInfo atominfo[NUMATOM];


// __constant__ AtomInfo atominfo[NUMATOM];



// kernal
__global__ void cenergy_kernel(float *energygrid, dim3 grid, float gridspacing, float z, AtomInfo *atominfo, int numatoms) {

	int xindex = blockIdx.x * blockDim.x + threadIdx.x;
	int yindex = blockIdx.y * blockDim.y + threadIdx.y;
	int k = z / gridspacing;
	int outaddr = grid.x * grid.y * k + grid.x * yindex + xindex;

	float curenergy = energygrid[outaddr];
	float coorx = gridspacing * (float) xindex;
	float coory = gridspacing * (float) yindex;
	int atomid;
	float energyval = 0.0f;

	for (atomid = 0; atomid < numatoms; ++atomid) {
		float dx = coorx - atominfo[atomid].x;
		float dy = coory - atominfo[atomid].y;
//		float dz = z - atominfo[atomid].z;
		energyval += atominfo[atomid].w / sqrtf(dx*dx + dy*dy + atominfo[atomid].z);
	}

	energygrid[outaddr] = curenergy + energyval;
}


// host
void cenergy_dev(float *energygrid, dim3 grid, float gridspacing, float z, AtomInfo *atominfo, int numatoms) {

	// Step 1: allocate memory
	float * dev_energygrid;
	AtomInfo * dev_atominfo;
	int gridSize = grid.x * grid.y * grid.z;

	hipMalloc((void **) &dev_energygrid, sizeof(float) * gridSize);
	hipMalloc((void **) &dev_atominfo, sizeof(AtomInfo) * numatoms);

	// Step 2: copy the input vector to the device
	hipMemcpy(dev_atominfo, atominfo, sizeof(AtomInfo) * numatoms, hipMemcpyHostToDevice);
	
	// Step 3: Invoke the kernel
	dim3 dimGrid(TILESIZE, TILESIZE, 1);
	dim3 dimBlock(ceil(grid.x / (float) TILESIZE), ceil(grid.y / (float) TILESIZE), 1);
	cenergy_kernel<<<dimGrid, dimBlock>>>(dev_energygrid, grid, gridspacing, z, dev_atominfo, numatoms);

	// Step 4: Retrieve the results
	hipMemcpy(energygrid, dev_energygrid, sizeof(float) * gridSize, hipMemcpyDeviceToHost);

	// Step 5: Free device memory
	hipFree(dev_energygrid);
	hipFree(dev_atominfo);
}


// initialize atominfo
void initialize() {
	for (int i = 0; i < NUMATOM; ++i) {
		atominfo[i].w = rand() % MAXW;
		atominfo[i].x = rand() % DIMX;
		atominfo[i].y = rand() % DIMY;
		atominfo[i].z = rand() % DIMZ;
	}
}

/*
// uniform charge
void uniformCharge() {
	for (int i = 0; i < NUMATOM; ++i) {
		atominfo[i].w = 1.0f;
		atominfo[i].x = rand() % DIMX;
		atominfo[i].y = rand() % DIMY;
		atominfo[i].z = rand() % DIMZ;
	}
}
*/

// print atoms
void printAtoms() {
	for (int i = 0; i < NUMATOM; ++i) {
		printf("index=%d, charge=%.2f, x=%.2f, y=%.2f, z=%.2f\n", i, atominfo[i].w, atominfo[i].x, atominfo[i].y, atominfo[i].z);
	}
}


// serial energy calculation
void serial(float *energygrid, dim3 grid, float gridspacing, float z, int numatom) {
	int i, j, n;
	int k = z / gridspacing;
	float x, y, energy;

	for (j = 0; j < grid.y; ++j) {
		y = gridspacing * (float) j;
		for (i = 0; i < grid.x; ++i) {
			x = gridspacing * (float) i;
			energy = 0.0f;
			for (n = 0; n < numatom; ++n) {
				float	dx = x - atominfo[n].x;
				float dy = y - atominfo[n].y;
				float dz = z - atominfo[n].z;
				energy += atominfo[n].w / sqrtf(dx*dx + dy*dy + dz*dz);
			}
			energygrid[grid.x * grid.y * k + grid.x * j + i] = energy;
		}
	}
}


// print energy grid
void printEnergy(float *energygrid, dim3 grid, float gridspacing) {
	for (int z = 0; z < grid.z; ++z) {
		for (int y = 0; y < grid.y; ++y) {
			for (int x = 0; x < grid.x; ++x) {
				printf("x=%d, y=%d, z=%d, potential=%.2f\n", x, y, z, energygrid[grid.x *grid.y * z + grid.x * y + x]);
			}
		}
	}
}



// energy main
void energy() {
	dim3 grid(DIMX/SPACE, DIMY/SPACE, DIMZ/SPACE);
	float gridspacing = (float) SPACE;
	float energygrid[DIMX/SPACE * DIMY/SPACE * DIMZ/SPACE];
	float	z = 0.0f;	

	for (int i = 0; i < grid.z; ++i) {
		z = gridspacing * (float) i;

		cenergy_dev(energygrid, grid, gridspacing, z, atominfo, NUMATOM);
//		serial(energygrid, grid, gridspacing, z, NUMATOM);
	}
	printEnergy(energygrid, grid, gridspacing);
}

// main
int main(void) {
	
	// initialize
	srand(time(NULL));
	initialize();		

	printAtoms();
  energy();

	return 0;
}







	.text
	.file	"hw4_no_const_mem.hip"
	.globl	_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi # -- Begin function _Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi
	.type	_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi,@function
_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi: # @_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	80(%rsp), %rax
	movq	%rsi, (%rax)
	movl	%edx, 8(%rax)
	leaq	40(%rsp), %rdx
	movq	%rdi, (%rdx)
	leaq	12(%rsp), %rsi
	movss	%xmm0, (%rsi)
	leaq	8(%rsp), %rdi
	movss	%xmm1, (%rdi)
	leaq	32(%rsp), %r9
	movq	%rcx, (%r9)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rdx, (%rbx)
	movq	%rax, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdi, 24(%rbx)
	movq	%r9, 32(%rbx)
	movq	%rcx, 40(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z14cenergy_kernelPf4dim3ffP8AtomInfoi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end0:
	.size	_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi, .Lfunc_end0-_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z11cenergy_devPf4dim3ffP8AtomInfoi
.LCPI1_0:
	.long	0x3d800000                      # float 0.0625
	.text
	.globl	_Z11cenergy_devPf4dim3ffP8AtomInfoi
	.type	_Z11cenergy_devPf4dim3ffP8AtomInfoi,@function
_Z11cenergy_devPf4dim3ffP8AtomInfoi:    # @_Z11cenergy_devPf4dim3ffP8AtomInfoi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r8d, %ebx
	movq	%rcx, %r13
	movss	%xmm1, 16(%rsp)                 # 4-byte Spill
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	movq	%rsi, %r15
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	movq	%rsi, %r12
	shrq	$32, %r12
	movl	%r15d, %eax
	movl	%edx, 8(%rsp)                   # 4-byte Spill
	imull	%edx, %eax
	imull	%r12d, %eax
	movslq	%eax, %r14
	shlq	$2, %r14
	movq	%rsp, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movl	%ebx, 20(%rsp)                  # 4-byte Spill
	movslq	%ebx, %rbx
	shlq	$4, %rbx
	leaq	24(%rsp), %rbp
	movq	%rbp, %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	(%rbp), %rdi
	movq	%r13, %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%r15d, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %rbx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12, %xmm0
	mulss	.LCPI1_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %rdx
	movl	%ebx, %eax
	shlq	$32, %rdx
	orq	%rax, %rdx
	movabsq	$68719476752, %rdi              # imm = 0x1000000010
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_2
# %bb.1:
	movq	(%rsp), %rdi
	movq	24(%rsp), %rcx
	movq	%r15, %rsi
	movl	8(%rsp), %edx                   # 4-byte Reload
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	16(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movl	20(%rsp), %r8d                  # 4-byte Reload
	callq	_Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi
.LBB1_2:
	movq	(%rsp), %rsi
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z11cenergy_devPf4dim3ffP8AtomInfoi, .Lfunc_end1-_Z11cenergy_devPf4dim3ffP8AtomInfoi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10initializev                 # -- Begin function _Z10initializev
	.type	_Z10initializev,@function
_Z10initializev:                        # @_Z10initializev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	$-512, %rbx                     # imm = 0xFE00
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, atominfo+512(%rbx)
	callq	rand
                                        # kill: def $eax killed $eax def $rax
	leal	63(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-64, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, atominfo+516(%rbx)
	callq	rand
                                        # kill: def $eax killed $eax def $rax
	leal	63(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-64, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, atominfo+520(%rbx)
	callq	rand
                                        # kill: def $eax killed $eax def $rax
	leal	63(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-64, %ecx
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, atominfo+524(%rbx)
	addq	$16, %rbx
	jne	.LBB2_1
# %bb.2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z10initializev, .Lfunc_end2-_Z10initializev
	.cfi_endproc
                                        # -- End function
	.globl	_Z10printAtomsv                 # -- Begin function _Z10printAtomsv
	.type	_Z10printAtomsv,@function
_Z10printAtomsv:                        # @_Z10printAtomsv
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$atominfo+12, %r14d
	xorl	%ebx, %ebx
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	-12(%r14), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	-8(%r14), %xmm1
	xorps	%xmm2, %xmm2
	cvtss2sd	-4(%r14), %xmm2
	xorps	%xmm3, %xmm3
	cvtss2sd	(%r14), %xmm3
	movl	$.L.str, %edi
	movl	%ebx, %esi
	movb	$4, %al
	callq	printf
	incq	%rbx
	addq	$16, %r14
	cmpq	$32, %rbx
	jne	.LBB3_1
# %bb.2:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z10printAtomsv, .Lfunc_end3-_Z10printAtomsv
	.cfi_endproc
                                        # -- End function
	.globl	_Z6serialPf4dim3ffi             # -- Begin function _Z6serialPf4dim3ffi
	.type	_Z6serialPf4dim3ffi,@function
_Z6serialPf4dim3ffi:                    # @_Z6serialPf4dim3ffi
	.cfi_startproc
# %bb.0:
	movq	%rsi, %rax
	shrq	$32, %rax
	je	.LBB4_11
# %bb.1:                                # %.lr.ph46
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movaps	%xmm1, %xmm2
	divss	%xmm0, %xmm2
	cvttss2si	%xmm2, %edx
	imull	%eax, %edx
	movl	%esi, %r8d
	movl	%ecx, %r9d
	shlq	$4, %r9
	xorl	%r10d, %r10d
.LBB4_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
                                        #       Child Loop BB4_7 Depth 3
	testl	%esi, %esi
	je	.LBB4_9
# %bb.3:                                # %.lr.ph42
                                        #   in Loop: Header=BB4_2 Depth=1
	xorps	%xmm2, %xmm2
	cvtsi2ss	%r10d, %xmm2
	mulss	%xmm0, %xmm2
	leal	(%r10,%rdx), %r11d
	imull	%esi, %r11d
	xorl	%ebx, %ebx
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_7 Depth 3
	testl	%ecx, %ecx
	jle	.LBB4_5
# %bb.6:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB4_4 Depth=2
	xorps	%xmm4, %xmm4
	cvtsi2ss	%ebx, %xmm4
	mulss	%xmm0, %xmm4
	xorps	%xmm3, %xmm3
	xorl	%r14d, %r14d
.LBB4_7:                                # %.lr.ph
                                        #   Parent Loop BB4_2 Depth=1
                                        #     Parent Loop BB4_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movaps	%xmm4, %xmm5
	subss	atominfo+4(%r14), %xmm5
	movaps	%xmm2, %xmm6
	subss	atominfo+8(%r14), %xmm6
	movaps	%xmm1, %xmm7
	subss	atominfo+12(%r14), %xmm7
	mulss	%xmm5, %xmm5
	mulss	%xmm6, %xmm6
	addss	%xmm5, %xmm6
	mulss	%xmm7, %xmm7
	addss	%xmm6, %xmm7
	xorps	%xmm5, %xmm5
	sqrtss	%xmm7, %xmm5
	movss	atominfo(%r14), %xmm6           # xmm6 = mem[0],zero,zero,zero
	divss	%xmm5, %xmm6
	addss	%xmm6, %xmm3
	addq	$16, %r14
	cmpq	%r14, %r9
	jne	.LBB4_7
	jmp	.LBB4_8
.LBB4_5:                                #   in Loop: Header=BB4_4 Depth=2
	xorps	%xmm3, %xmm3
.LBB4_8:                                # %._crit_edge
                                        #   in Loop: Header=BB4_4 Depth=2
	leal	(%r11,%rbx), %r14d
	movss	%xmm3, (%rdi,%r14,4)
	incq	%rbx
	cmpq	%r8, %rbx
	jne	.LBB4_4
.LBB4_9:                                # %._crit_edge43
                                        #   in Loop: Header=BB4_2 Depth=1
	incl	%r10d
	cmpl	%eax, %r10d
	jne	.LBB4_2
# %bb.10:
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
.LBB4_11:                               # %._crit_edge47
	retq
.Lfunc_end4:
	.size	_Z6serialPf4dim3ffi, .Lfunc_end4-_Z6serialPf4dim3ffi
	.cfi_endproc
                                        # -- End function
	.globl	_Z11printEnergyPf4dim3f         # -- Begin function _Z11printEnergyPf4dim3f
	.type	_Z11printEnergyPf4dim3f,@function
_Z11printEnergyPf4dim3f:                # @_Z11printEnergyPf4dim3f
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, 12(%rsp)                  # 4-byte Spill
	testl	%edx, %edx
	je	.LBB5_9
# %bb.1:                                # %.preheader18.lr.ph
	movq	%rdi, %r15
	movq	%rsi, %rax
	shrq	$32, %rax
	movl	%esi, %ebx
	movl	%esi, %ecx
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	imull	%eax, %ecx
	movq	%rcx, 24(%rsp)                  # 8-byte Spill
	xorl	%eax, %eax
	movq	%rax, (%rsp)                    # 8-byte Spill
	xorl	%ebp, %ebp
	movq	%rsi, 32(%rsp)                  # 8-byte Spill
.LBB5_2:                                # %.preheader18
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_4 Depth 2
                                        #       Child Loop BB5_6 Depth 3
	cmpl	$0, 16(%rsp)                    # 4-byte Folded Reload
	je	.LBB5_8
# %bb.3:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB5_2 Depth=1
	xorl	%r12d, %r12d
	movq	(%rsp), %r14                    # 8-byte Reload
.LBB5_4:                                # %.preheader
                                        #   Parent Loop BB5_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB5_6 Depth 3
	testl	%esi, %esi
	je	.LBB5_7
# %bb.5:                                # %.lr.ph
                                        #   in Loop: Header=BB5_4 Depth=2
	xorl	%r13d, %r13d
.LBB5_6:                                #   Parent Loop BB5_2 Depth=1
                                        #     Parent Loop BB5_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	leal	(%r14,%r13), %eax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r15,%rax,4), %xmm0
	movl	$.L.str.1, %edi
	movl	%r13d, %esi
	movl	%r12d, %edx
	movl	%ebp, %ecx
	movb	$1, %al
	callq	printf
	incq	%r13
	cmpq	%r13, %rbx
	jne	.LBB5_6
.LBB5_7:                                # %._crit_edge
                                        #   in Loop: Header=BB5_4 Depth=2
	incl	%r12d
	movq	32(%rsp), %rsi                  # 8-byte Reload
	addq	%rsi, %r14
	cmpl	16(%rsp), %r12d                 # 4-byte Folded Reload
	jne	.LBB5_4
.LBB5_8:                                # %._crit_edge21
                                        #   in Loop: Header=BB5_2 Depth=1
	incl	%ebp
	movq	(%rsp), %rax                    # 8-byte Reload
	addq	24(%rsp), %rax                  # 8-byte Folded Reload
	movq	%rax, (%rsp)                    # 8-byte Spill
	cmpl	12(%rsp), %ebp                  # 4-byte Folded Reload
	jne	.LBB5_2
.LBB5_9:                                # %._crit_edge23
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z11printEnergyPf4dim3f, .Lfunc_end5-_Z11printEnergyPf4dim3f
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z6energyv
.LCPI6_0:
	.long	0x40000000                      # float 2
	.text
	.globl	_Z6energyv
	.type	_Z6energyv,@function
_Z6energyv:                             # @_Z6energyv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$131072, %rsp                   # imm = 0x20000
	.cfi_def_cfa_offset 131104
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movabsq	$137438953504, %rbx             # imm = 0x2000000020
	xorl	%ebp, %ebp
	movq	%rsp, %r14
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ebp, %xmm1
	addss	%xmm1, %xmm1
	movl	$atominfo, %ecx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	$32, %edx
	movss	.LCPI6_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movl	$32, %r8d
	callq	_Z11cenergy_devPf4dim3ffP8AtomInfoi
	incl	%ebp
	cmpl	$32, %ebp
	jne	.LBB6_1
# %bb.2:
	movq	%rsp, %rdi
	movq	%rbx, %rsi
	movl	$32, %edx
	callq	_Z11printEnergyPf4dim3f
	addq	$131072, %rsp                   # imm = 0x20000
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z6energyv, .Lfunc_end6-_Z6energyv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	callq	_Z10initializev
	callq	_Z10printAtomsv
	callq	_Z6energyv
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	main, .Lfunc_end7-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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14cenergy_kernelPf4dim3ffP8AtomInfoi, %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_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	atominfo,@object                # @atominfo
	.bss
	.globl	atominfo
	.p2align	4, 0x0
atominfo:
	.zero	512
	.size	atominfo, 512

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"index=%d, charge=%.2f, x=%.2f, y=%.2f, z=%.2f\n"
	.size	.L.str, 47

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"x=%d, y=%d, z=%d, potential=%.2f\n"
	.size	.L.str.1, 34

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14cenergy_kernelPf4dim3ffP8AtomInfoi"
	.size	.L__unnamed_1, 39

	.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 _Z29__device_stub__cenergy_kernelPf4dim3ffP8AtomInfoi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym atominfo
	.addrsig_sym _Z14cenergy_kernelPf4dim3ffP8AtomInfoi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi ; -- Begin function _Z14cenergy_kernelPf4dim3ffP8AtomInfoi
	.globl	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi
	.p2align	8
	.type	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi,@function
_Z14cenergy_kernelPf4dim3ffP8AtomInfoi: ; @_Z14cenergy_kernelPf4dim3ffP8AtomInfoi
; %bb.0:
	s_clause 0x2
	s_load_b64 s[2:3], s[0:1], 0x14
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b32 s8, s[0:1], 0x3c
	s_waitcnt lgkmcnt(0)
	v_div_scale_f32 v1, null, s2, s2, s3
	v_div_scale_f32 v4, vcc_lo, s3, s2, s3
	s_lshr_b32 s9, s8, 16
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v2, v1
	s_waitcnt_depctr 0xfff
	v_fma_f32 v3, -v1, v2, 1.0
	v_fmac_f32_e32 v2, v3, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v3, v4, v2
	v_fma_f32 v5, -v1, v3, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v3, v5, v2
	v_fma_f32 v1, -v1, v3, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v2, v1, v2, v3
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	v_div_fixup_f32 v4, v2, s2, s3
	s_and_b32 s3, s8, 0xffff
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[2:3], null, s15, s9, v[1:2]
	v_cvt_i32_f32_e32 v5, v4
	v_mad_u64_u32 v[3:4], null, s14, s3, v[0:1]
	s_load_b32 s3, s[0:1], 0x28
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[0:1], null, s7, v5, v[2:3]
	v_mad_u64_u32 v[4:5], null, v0, s6, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s3, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[0:1], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b64 s[4:5], s[0:1], 0x20
	v_cvt_f32_i32_e32 v3, v3
	v_cvt_f32_i32_e32 v2, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mul_f32 v3, s2, v3 :: v_dual_mul_f32 v4, s2, v2
	v_mov_b32_e32 v2, 0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s1, s4, 8
	s_addc_u32 s2, s5, 0
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_add_u32 s4, s1, -8
	s_addc_u32 s5, s2, -1
	s_add_i32 s3, s3, -1
	s_load_b128 s[4:7], s[4:5], 0x0
	s_add_u32 s1, s1, 16
	s_addc_u32 s2, s2, 0
	s_cmp_lg_u32 s3, 0
	s_waitcnt lgkmcnt(0)
	v_dual_subrev_f32 v5, s6, v4 :: v_dual_subrev_f32 v6, s5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v5, v5, v5
	v_fmac_f32_e32 v5, v6, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v5, s7, v5
	v_mul_f32_e32 v6, 0x4f800000, v5
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v5, v5, v6, vcc_lo
	v_sqrt_f32_e32 v6, v5
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v7, -1, v6
	v_add_nc_u32_e32 v8, 1, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v9, -v7, v6, v5
	v_fma_f32 v10, -v8, v6, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_f32_e64 s0, 0, v9
	v_cndmask_b32_e64 v6, v6, v7, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e64 s0, 0, v10
	v_cndmask_b32_e64 v6, v6, v8, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v7, 0x37800000, v6
	v_cndmask_b32_e32 v6, v6, v7, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v5, 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v5, v6, v5, vcc_lo
	v_div_scale_f32 v6, null, v5, v5, s4
	v_div_scale_f32 v9, vcc_lo, s4, v5, s4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v7, v6
	s_waitcnt_depctr 0xfff
	v_fma_f32 v8, -v6, v7, 1.0
	v_fmac_f32_e32 v7, v8, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v8, v9, v7
	v_fma_f32 v10, -v6, v8, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v8, v10, v7
	v_fma_f32 v6, -v6, v8, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v6, v6, v7, v8
	v_div_fixup_f32 v5, v6, v5, s4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v2, v2, v5
	s_cbranch_scc1 .LBB0_2
	s_branch .LBB0_4
.LBB0_3:
	v_mov_b32_e32 v2, 0
.LBB0_4:                                ; %Flow59
	global_load_b32 v3, v[0:1], off
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v2, v3, v2
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14cenergy_kernelPf4dim3ffP8AtomInfoi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 11
		.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	_Z14cenergy_kernelPf4dim3ffP8AtomInfoi, .Lfunc_end0-_Z14cenergy_kernelPf4dim3ffP8AtomInfoi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 640
; NumSgprs: 18
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.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
      - .offset:         8
        .size:           12
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14cenergy_kernelPf4dim3ffP8AtomInfoi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14cenergy_kernelPf4dim3ffP8AtomInfoi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
