#include<stdio.h>
#include<stdlib.h>
#include<curand_kernel.h>
#include<curand.h>
#include<sys/time.h>

unsigned int NUM_PARTICLES = 100000;
unsigned int NUM_ITERATIONS = 10;
unsigned int BLOCK_SIZE = 192;
unsigned int GRID_SIZE = ((NUM_PARTICLES/BLOCK_SIZE) + 1);

typedef struct {
	float3 posId;
}position;

typedef struct {
	float3 velId;
}velocity;

typedef struct {
	position pos;
	velocity vel;
}Particle;


void fill_data(Particle *p)
{
	for(int i=0; i< NUM_PARTICLES; i++)
	{
		p[i].pos.posId.x = 10*((float)rand()/RAND_MAX);	
		p[i].pos.posId.y = 10*((float)rand()/RAND_MAX);		
		p[i].pos.posId.z = 10*((float)rand()/RAND_MAX);
		
		p[i].vel.velId.x = 100*((float)rand()/RAND_MAX);		
		p[i].vel.velId.y = 100*((float)rand()/RAND_MAX);		
		p[i].vel.velId.z = 100*((float)rand()/RAND_MAX);		
	}
}

__global__ void particle_kernel_per_iteration(Particle *p, int Nparticles)
{
        int i = (blockIdx.x*blockDim.x)+threadIdx.x;

        if(i < Nparticles) {
		p[i].pos.posId.x += p[i].vel.velId.x;
             	p[i].pos.posId.y += p[i].vel.velId.y;
               	p[i].pos.posId.z += p[i].vel.velId.z;
        }
        __syncthreads();
}


void update_velocity_position_in_gpu(Particle *p)
{
        struct timeval start_time;
        struct timeval stop_time;

	Particle *gPar = NULL;

	cudaMalloc(&gPar, NUM_PARTICLES*sizeof(Particle));

        //Start time
        gettimeofday(&start_time, NULL);

        for(int i=0; i<NUM_ITERATIONS; i++)
        {
		// Copy Data to GPU Memory
        	cudaMemcpy(gPar, p, NUM_PARTICLES*sizeof(Particle), cudaMemcpyHostToDevice);

		//Launch kernel		
		particle_kernel_per_iteration<<<GRID_SIZE, BLOCK_SIZE>>>(gPar, NUM_PARTICLES);
		cudaDeviceSynchronize();
		
		//Copy Data back to Host
		cudaMemcpy(p, gPar, NUM_PARTICLES*sizeof(Particle), cudaMemcpyDeviceToHost);

		//Update Velocity in Host before copying data to GPU Memory
		for(int j=0; j<NUM_PARTICLES;j++)
                {
                        p[j].vel.velId.x = 100*((float)rand()/RAND_MAX);
                        p[j].vel.velId.y = 100*((float)rand()/RAND_MAX);
                        p[j].vel.velId.z = 100*((float)rand()/RAND_MAX);
                }
        }

	//Stop time
        gettimeofday(&stop_time, NULL);
	
        printf("Total time of Execution in GPU: %ld msec\n\n",
                ((stop_time.tv_sec*1000000 + stop_time.tv_usec)-(start_time.tv_sec*1000000 + start_time.tv_usec))/1000);
	cudaFree(gPar);
}

int main(int argc, char *argv[])
{
	if(argc != 3)
	{
		printf("No. of arguments to be passed should be 2 i.e. 1st as NUM_PARTICLES and 2nd as BLOCK_SIZE\n");
		exit(1);
	}

	NUM_PARTICLES = atoi(argv[1]);
	BLOCK_SIZE = atoi(argv[2]);
	
	Particle *par = NULL;
#ifdef CUDAMALLOCHOST
	cudaMallocHost(&par, NUM_PARTICLES*sizeof(Particle));
#else
	par = (Particle*)malloc(NUM_PARTICLES*sizeof(Particle));
#endif
	
	fill_data(par);

	update_velocity_position_in_gpu(par);

#ifdef CUDAMALLOCHOST	
	cudaFree(par);
#else
	free(par);
#endif
	return 0;
}


	.file	"tmpxft_0024a8fd_00000000-6_exercise_2a.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2246:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2246:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z9fill_dataP8Particle
	.type	_Z9fill_dataP8Particle, @function
_Z9fill_dataP8Particle:
.LFB2241:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 32
.L3:
	cmpl	NUM_PARTICLES(%rip), %ebp
	jnb	.L7
	call	rand@PLT
	incl	%ebp
	addq	$24, %rbx
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	movss	%xmm0, -24(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	movss	%xmm0, -20(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC1(%rip), %xmm0
	movss	%xmm0, -16(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, -12(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, -8(%rbx)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, -4(%rbx)
	jmp	.L3
.L7:
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2241:
	.size	_Z9fill_dataP8Particle, .-_Z9fill_dataP8Particle
	.globl	_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei
	.type	_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei, @function
_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei:
.LFB2268:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z29particle_kernel_per_iterationP8Particlei(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L8:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2268:
	.size	_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei, .-_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei
	.globl	_Z29particle_kernel_per_iterationP8Particlei
	.type	_Z29particle_kernel_per_iterationP8Particlei, @function
_Z29particle_kernel_per_iterationP8Particlei:
.LFB2269:
	.cfi_startproc
	endbr64
	jmp	_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei
	.cfi_endproc
.LFE2269:
	.size	_Z29particle_kernel_per_iterationP8Particlei, .-_Z29particle_kernel_per_iterationP8Particlei
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	"Total time of Execution in GPU: %ld msec\n\n"
	.text
	.globl	_Z31update_velocity_position_in_gpuP8Particle
	.type	_Z31update_velocity_position_in_gpuP8Particle, @function
_Z31update_velocity_position_in_gpuP8Particle:
.LFB2242:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movabsq	$4294967297, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdi, %rbx
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movl	NUM_PARTICLES(%rip), %esi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	xorl	%eax, %eax
	imulq	$24, %rsi, %rsi
	movq	%rax, (%rsp)
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
.L14:
	cmpl	NUM_ITERATIONS(%rip), %r12d
	jnb	.L21
	movl	NUM_PARTICLES(%rip), %edx
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	imulq	$24, %rdx, %rdx
	call	cudaMemcpy@PLT
	movq	%r13, 44(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	BLOCK_SIZE(%rip), %eax
	movl	48(%rsp), %ecx
	movq	%r13, 16(%rsp)
	movl	20(%rsp), %esi
	movl	%eax, 40(%rsp)
	movl	GRID_SIZE(%rip), %eax
	movq	40(%rsp), %rdx
	movl	%eax, 12(%rsp)
	movq	12(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	movl	NUM_PARTICLES(%rip), %esi
	movq	(%rsp), %rdi
	call	_Z58__device_stub__Z29particle_kernel_per_iterationP8ParticleiP8Particlei
.L15:
	call	cudaDeviceSynchronize@PLT
	movq	(%rsp), %rsi
	movq	%rbx, %rdi
	leaq	12(%rbx), %rbp
	movl	NUM_PARTICLES(%rip), %edx
	movl	$2, %ecx
	xorl	%r14d, %r14d
	imulq	$24, %rdx, %rdx
	call	cudaMemcpy@PLT
.L16:
	cmpl	NUM_PARTICLES(%rip), %r14d
	jnb	.L22
	call	rand@PLT
	incl	%r14d
	addq	$24, %rbp
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, -24(%rbp)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, -20(%rbp)
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	mulss	.LC2(%rip), %xmm0
	movss	%xmm0, -16(%rbp)
	jmp	.L16
.L22:
	incl	%r12d
	jmp	.L14
.L21:
	xorl	%esi, %esi
	leaq	40(%rsp), %rdi
	call	gettimeofday@PLT
	movl	$1000, %ecx
	imulq	$1000000, 40(%rsp), %rax
	addq	48(%rsp), %rax
	imulq	$1000000, 24(%rsp), %rdx
	addq	32(%rsp), %rdx
	movl	$2, %edi
	subq	%rdx, %rax
	leaq	.LC3(%rip), %rsi
	cqto
	idivq	%rcx
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2242:
	.size	_Z31update_velocity_position_in_gpuP8Particle, .-_Z31update_velocity_position_in_gpuP8Particle
	.section	.rodata.str1.1
.LC4:
	.string	"No. of arguments to be passed should be 2 i.e. 1st as NUM_PARTICLES and 2nd as BLOCK_SIZE\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2243:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rcx
	.cfi_def_cfa_offset 32
	cmpl	$3, %edi
	je	.L24
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L24:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbp
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movl	%eax, %ebx
	movl	%eax, NUM_PARTICLES(%rip)
	call	atoi@PLT
	movl	%ebx, %edi
	imulq	$24, %rdi, %rdi
	movl	%eax, BLOCK_SIZE(%rip)
	call	malloc@PLT
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	_Z9fill_dataP8Particle
	movq	%rbx, %rdi
	call	_Z31update_velocity_position_in_gpuP8Particle
	movq	%rbx, %rdi
	call	free@PLT
	popq	%rdx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2243:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z29particle_kernel_per_iterationP8Particlei"
.LC6:
	.string	"precalc_xorwow_matrix"
.LC7:
	.string	"precalc_xorwow_offset_matrix"
.LC8:
	.string	"mrg32k3aM1"
.LC9:
	.string	"mrg32k3aM2"
.LC10:
	.string	"mrg32k3aM1SubSeq"
.LC11:
	.string	"mrg32k3aM2SubSeq"
.LC12:
	.string	"mrg32k3aM1Seq"
.LC13:
	.string	"mrg32k3aM2Seq"
.LC14:
	.string	"__cr_lgamma_table"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2271:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z29particle_kernel_per_iterationP8Particlei(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC6(%rip), %rdx
	movl	$102400, %r9d
	leaq	_ZL21precalc_xorwow_matrix(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC7(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$102400, %r9d
	leaq	_ZL28precalc_xorwow_offset_matrix(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM1(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM1SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC11(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM2SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC12(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM1Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM2Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$72, %r9d
	movq	%rdx, %rcx
	leaq	_ZL17__cr_lgamma_table(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2271:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text.startup
	.type	_GLOBAL__sub_I_NUM_PARTICLES, @function
_GLOBAL__sub_I_NUM_PARTICLES:
.LFB2389:
	.cfi_startproc
	endbr64
	movl	NUM_PARTICLES(%rip), %eax
	xorl	%edx, %edx
	divl	BLOCK_SIZE(%rip)
	incl	%eax
	movl	%eax, GRID_SIZE(%rip)
	ret
	.cfi_endproc
.LFE2389:
	.size	_GLOBAL__sub_I_NUM_PARTICLES, .-_GLOBAL__sub_I_NUM_PARTICLES
	.section	.init_array
	.align 8
	.quad	_GLOBAL__sub_I_NUM_PARTICLES
	.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	GRID_SIZE
	.bss
	.align 4
	.type	GRID_SIZE, @object
	.size	GRID_SIZE, 4
GRID_SIZE:
	.zero	4
	.globl	BLOCK_SIZE
	.data
	.align 4
	.type	BLOCK_SIZE, @object
	.size	BLOCK_SIZE, 4
BLOCK_SIZE:
	.long	192
	.globl	NUM_ITERATIONS
	.align 4
	.type	NUM_ITERATIONS, @object
	.size	NUM_ITERATIONS, 4
NUM_ITERATIONS:
	.long	10
	.globl	NUM_PARTICLES
	.align 4
	.type	NUM_PARTICLES, @object
	.size	NUM_PARTICLES, 4
NUM_PARTICLES:
	.long	100000
	.local	_ZL17__cr_lgamma_table
	.comm	_ZL17__cr_lgamma_table,72,32
	.local	_ZL13mrg32k3aM2Seq
	.comm	_ZL13mrg32k3aM2Seq,2304,32
	.local	_ZL13mrg32k3aM1Seq
	.comm	_ZL13mrg32k3aM1Seq,2304,32
	.local	_ZL16mrg32k3aM2SubSeq
	.comm	_ZL16mrg32k3aM2SubSeq,2016,32
	.local	_ZL16mrg32k3aM1SubSeq
	.comm	_ZL16mrg32k3aM1SubSeq,2016,32
	.local	_ZL10mrg32k3aM2
	.comm	_ZL10mrg32k3aM2,2304,32
	.local	_ZL10mrg32k3aM1
	.comm	_ZL10mrg32k3aM1,2304,32
	.local	_ZL28precalc_xorwow_offset_matrix
	.comm	_ZL28precalc_xorwow_offset_matrix,102400,32
	.local	_ZL21precalc_xorwow_matrix
	.comm	_ZL21precalc_xorwow_matrix,102400,32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC1:
	.long	1092616192
	.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<stdlib.h>
#include<hiprand/hiprand_kernel.h>
#include<hiprand/hiprand.h>
#include<sys/time.h>

unsigned int NUM_PARTICLES = 100000;
unsigned int NUM_ITERATIONS = 10;
unsigned int BLOCK_SIZE = 192;
unsigned int GRID_SIZE = ((NUM_PARTICLES/BLOCK_SIZE) + 1);

typedef struct {
	float3 posId;
}position;

typedef struct {
	float3 velId;
}velocity;

typedef struct {
	position pos;
	velocity vel;
}Particle;


void fill_data(Particle *p)
{
	for(int i=0; i< NUM_PARTICLES; i++)
	{
		p[i].pos.posId.x = 10*((float)rand()/RAND_MAX);	
		p[i].pos.posId.y = 10*((float)rand()/RAND_MAX);		
		p[i].pos.posId.z = 10*((float)rand()/RAND_MAX);
		
		p[i].vel.velId.x = 100*((float)rand()/RAND_MAX);		
		p[i].vel.velId.y = 100*((float)rand()/RAND_MAX);		
		p[i].vel.velId.z = 100*((float)rand()/RAND_MAX);		
	}
}

__global__ void particle_kernel_per_iteration(Particle *p, int Nparticles)
{
        int i = (blockIdx.x*blockDim.x)+threadIdx.x;

        if(i < Nparticles) {
		p[i].pos.posId.x += p[i].vel.velId.x;
             	p[i].pos.posId.y += p[i].vel.velId.y;
               	p[i].pos.posId.z += p[i].vel.velId.z;
        }
        __syncthreads();
}


void update_velocity_position_in_gpu(Particle *p)
{
        struct timeval start_time;
        struct timeval stop_time;

	Particle *gPar = NULL;

	hipMalloc(&gPar, NUM_PARTICLES*sizeof(Particle));

        //Start time
        gettimeofday(&start_time, NULL);

        for(int i=0; i<NUM_ITERATIONS; i++)
        {
		// Copy Data to GPU Memory
        	hipMemcpy(gPar, p, NUM_PARTICLES*sizeof(Particle), hipMemcpyHostToDevice);

		//Launch kernel		
		particle_kernel_per_iteration<<<GRID_SIZE, BLOCK_SIZE>>>(gPar, NUM_PARTICLES);
		hipDeviceSynchronize();
		
		//Copy Data back to Host
		hipMemcpy(p, gPar, NUM_PARTICLES*sizeof(Particle), hipMemcpyDeviceToHost);

		//Update Velocity in Host before copying data to GPU Memory
		for(int j=0; j<NUM_PARTICLES;j++)
                {
                        p[j].vel.velId.x = 100*((float)rand()/RAND_MAX);
                        p[j].vel.velId.y = 100*((float)rand()/RAND_MAX);
                        p[j].vel.velId.z = 100*((float)rand()/RAND_MAX);
                }
        }

	//Stop time
        gettimeofday(&stop_time, NULL);
	
        printf("Total time of Execution in GPU: %ld msec\n\n",
                ((stop_time.tv_sec*1000000 + stop_time.tv_usec)-(start_time.tv_sec*1000000 + start_time.tv_usec))/1000);
	hipFree(gPar);
}

int main(int argc, char *argv[])
{
	if(argc != 3)
	{
		printf("No. of arguments to be passed should be 2 i.e. 1st as NUM_PARTICLES and 2nd as BLOCK_SIZE\n");
		exit(1);
	}

	NUM_PARTICLES = atoi(argv[1]);
	BLOCK_SIZE = atoi(argv[2]);
	
	Particle *par = NULL;
#ifdef CUDAMALLOCHOST
	hipHostMalloc(&par, NUM_PARTICLES*sizeof(Particle), hipHostMallocDefault);
#else
	par = (Particle*)malloc(NUM_PARTICLES*sizeof(Particle));
#endif
	
	fill_data(par);

	update_velocity_position_in_gpu(par);

#ifdef CUDAMALLOCHOST	
	hipFree(par);
#else
	free(par);
#endif
	return 0;
}


	.text
	.file	"exercise_2a.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z9fill_dataP8Particle
.LCPI0_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI0_1:
	.long	0x41200000                      # float 10
.LCPI0_2:
	.long	0x42c80000                      # float 100
	.text
	.globl	_Z9fill_dataP8Particle
	.type	_Z9fill_dataP8Particle,@function
_Z9fill_dataP8Particle:                 # @_Z9fill_dataP8Particle
	.cfi_startproc
# %bb.0:
	cmpl	$0, NUM_PARTICLES(%rip)
	je	.LBB0_4
# %bb.1:                                # %.lr.ph.preheader
	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
	movq	%rdi, %rbx
	addq	$20, %rbx
	xorl	%r14d, %r14d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	.LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	%xmm0, -20(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	mulss	.LCPI0_1(%rip), %xmm0
	movss	%xmm0, -16(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	mulss	.LCPI0_1(%rip), %xmm0
	movss	%xmm0, -12(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	movss	.LCPI0_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	%xmm0, -8(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	mulss	.LCPI0_2(%rip), %xmm0
	movss	%xmm0, -4(%rbx)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI0_0(%rip), %xmm0
	mulss	.LCPI0_2(%rip), %xmm0
	movss	%xmm0, (%rbx)
	incq	%r14
	movl	NUM_PARTICLES(%rip), %eax
	addq	$24, %rbx
	cmpq	%rax, %r14
	jb	.LBB0_2
# %bb.3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
.LBB0_4:                                # %._crit_edge
	retq
.Lfunc_end0:
	.size	_Z9fill_dataP8Particle, .Lfunc_end0-_Z9fill_dataP8Particle
	.cfi_endproc
                                        # -- End function
	.globl	_Z44__device_stub__particle_kernel_per_iterationP8Particlei # -- Begin function _Z44__device_stub__particle_kernel_per_iterationP8Particlei
	.type	_Z44__device_stub__particle_kernel_per_iterationP8Particlei,@function
_Z44__device_stub__particle_kernel_per_iterationP8Particlei: # @_Z44__device_stub__particle_kernel_per_iterationP8Particlei
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z29particle_kernel_per_iterationP8Particlei, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end1:
	.size	_Z44__device_stub__particle_kernel_per_iterationP8Particlei, .Lfunc_end1-_Z44__device_stub__particle_kernel_per_iterationP8Particlei
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z31update_velocity_position_in_gpuP8Particle
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI2_1:
	.long	0x42c80000                      # float 100
	.text
	.globl	_Z31update_velocity_position_in_gpuP8Particle
	.type	_Z31update_velocity_position_in_gpuP8Particle,@function
_Z31update_velocity_position_in_gpuP8Particle: # @_Z31update_velocity_position_in_gpuP8Particle
	.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
	movq	%rdi, %rbx
	movq	%rsp, %rdi
	movq	$0, (%rdi)
	movl	NUM_PARTICLES(%rip), %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rsi
	callq	hipMalloc
	xorl	%r14d, %r14d
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpl	$0, NUM_ITERATIONS(%rip)
	je	.LBB2_7
# %bb.1:                                # %.lr.ph22.preheader
	movabsq	$4294967296, %r15               # imm = 0x100000000
	movl	NUM_PARTICLES(%rip), %eax
	leaq	20(%rbx), %r12
.LBB2_2:                                # %.lr.ph22
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_9 Depth 2
	movq	(%rsp), %rdi
	movl	%eax, %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rdx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	GRID_SIZE(%rip), %edi
	movl	BLOCK_SIZE(%rip), %edx
	orq	%r15, %rdi
	orq	%r15, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movq	(%rsp), %rdi
	movl	NUM_PARTICLES(%rip), %esi
	callq	_Z44__device_stub__particle_kernel_per_iterationP8Particlei
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
	callq	hipDeviceSynchronize
	movq	(%rsp), %rsi
	movl	NUM_PARTICLES(%rip), %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rdx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, NUM_PARTICLES(%rip)
	je	.LBB2_5
# %bb.8:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_2 Depth=1
	movq	%r12, %r13
	xorl	%ebp, %ebp
.LBB2_9:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	mulss	.LCPI2_1(%rip), %xmm0
	movss	%xmm0, -8(%r13)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	mulss	.LCPI2_1(%rip), %xmm0
	movss	%xmm0, -4(%r13)
	callq	rand
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	%xmm1, %xmm0
	movss	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%r13)
	incq	%rbp
	movl	NUM_PARTICLES(%rip), %eax
	addq	$24, %r13
	cmpq	%rax, %rbp
	jb	.LBB2_9
	jmp	.LBB2_6
.LBB2_5:                                #   in Loop: Header=BB2_2 Depth=1
	xorl	%eax, %eax
.LBB2_6:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incl	%r14d
	cmpl	NUM_ITERATIONS(%rip), %r14d
	jb	.LBB2_2
.LBB2_7:                                # %._crit_edge23
	leaq	24(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rcx
	movq	8(%rbx), %rax
	subq	8(%rsp), %rcx
	imulq	$1000000, %rcx, %rcx            # imm = 0xF4240
	subq	16(%rsp), %rax
	addq	%rcx, %rax
	movabsq	$2361183241434822607, %rcx      # imm = 0x20C49BA5E353F7CF
	imulq	%rcx
	movq	%rdx, %rsi
	shrq	$63, %rsi
	sarq	$7, %rdx
	addq	%rdx, %rsi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movq	(%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_end2:
	.size	_Z31update_velocity_position_in_gpuP8Particle, .Lfunc_end2-_Z31update_velocity_position_in_gpuP8Particle
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	cmpl	$3, %edi
	jne	.LBB3_2
# %bb.1:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%eax, NUM_PARTICLES(%rip)
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, BLOCK_SIZE(%rip)
	movl	%ebp, %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	_Z9fill_dataP8Particle
	movq	%rbx, %rdi
	callq	_Z31update_velocity_position_in_gpuP8Particle
	movq	%rbx, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_2:
	.cfi_def_cfa_offset 32
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-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	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z29particle_kernel_per_iterationP8Particlei, %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_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	NUM_PARTICLES,@object           # @NUM_PARTICLES
	.data
	.globl	NUM_PARTICLES
	.p2align	2, 0x0
NUM_PARTICLES:
	.long	100000                          # 0x186a0
	.size	NUM_PARTICLES, 4

	.type	NUM_ITERATIONS,@object          # @NUM_ITERATIONS
	.globl	NUM_ITERATIONS
	.p2align	2, 0x0
NUM_ITERATIONS:
	.long	10                              # 0xa
	.size	NUM_ITERATIONS, 4

	.type	BLOCK_SIZE,@object              # @BLOCK_SIZE
	.globl	BLOCK_SIZE
	.p2align	2, 0x0
BLOCK_SIZE:
	.long	192                             # 0xc0
	.size	BLOCK_SIZE, 4

	.type	GRID_SIZE,@object               # @GRID_SIZE
	.globl	GRID_SIZE
	.p2align	2, 0x0
GRID_SIZE:
	.long	521                             # 0x209
	.size	GRID_SIZE, 4

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Total time of Execution in GPU: %ld msec\n\n"
	.size	.L.str, 43

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z29particle_kernel_per_iterationP8Particlei"
	.size	.L__unnamed_1, 45

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"No. of arguments to be passed should be 2 i.e. 1st as NUM_PARTICLES and 2nd as BLOCK_SIZE"
	.size	.Lstr, 90

	.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 _Z44__device_stub__particle_kernel_per_iterationP8Particlei
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z29particle_kernel_per_iterationP8Particlei
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z29particle_kernel_per_iterationP8Particlei ; -- Begin function _Z29particle_kernel_per_iterationP8Particlei
	.globl	_Z29particle_kernel_per_iterationP8Particlei
	.p2align	8
	.type	_Z29particle_kernel_per_iterationP8Particlei,@function
_Z29particle_kernel_per_iterationP8Particlei: ; @_Z29particle_kernel_per_iterationP8Particlei
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b32 s3, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_mad_i64_i32 v[4:5], null, v1, 24, s[0:1]
	s_clause 0x1
	global_load_b128 v[0:3], v[4:5], off
	global_load_b64 v[6:7], v[4:5], off offset:16
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v0, v3, v0 :: v_dual_add_f32 v1, v6, v1
	v_add_f32_e32 v2, v7, v2
	global_store_b96 v[4:5], v[0:2], off
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s2
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z29particle_kernel_per_iterationP8Particlei
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 8
		.amdhsa_next_free_sgpr 16
		.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	_Z29particle_kernel_per_iterationP8Particlei, .Lfunc_end0-_Z29particle_kernel_per_iterationP8Particlei
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 148
; NumSgprs: 16
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 16
; NumVGPRsForWavesPerEU: 8
; 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
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z29particle_kernel_per_iterationP8Particlei
    .private_segment_fixed_size: 0
    .sgpr_count:     16
    .sgpr_spill_count: 0
    .symbol:         _Z29particle_kernel_per_iterationP8Particlei.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
