/* 
	@author Jack Clark

	Simple program to simulate 2D advection using the finite volume approach, with naive averaging at cell boundaries. 
	
	Compile with nvcc -O3 advection.cu -o gpu_advection
*/


#include <fstream>
#include <sstream>
#include <math.h>
#include <assert.h>
#include <cuda.h>


#define NUM_CELLS_X 40
#define NUM_CELLS_Y 40
#define TIMESTEP 0.001
#define NUM_TIMESTEPS 100000
#define DELTA_X 1
#define DELTA_Y 1
#define PLOT_FREQUENCY 100

// CPU data
double h_flux_x[NUM_CELLS_X*NUM_CELLS_Y];
double h_flux_y[NUM_CELLS_X*NUM_CELLS_Y];
double h_q[NUM_CELLS_X*NUM_CELLS_Y];
double h_velocities[2];
double h_max_velocity;

// GPU data
double * d_flux_x;
double * d_flux_y;
double * d_q;
double * d_max_velocity;

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }

inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
   if (code != cudaSuccess) 
   {
      fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

int getIndex(int row, int col) {
	return row * NUM_CELLS_X + col;
}

void printCSVFile(int counter) {
  std::stringstream filename;
  filename << "result-" << counter <<  ".csv";
  std::ofstream out( filename.str().c_str() );

  out << "x, y, z" << std::endl;

  for (int i=0; i<NUM_CELLS_Y; i++) {
  	for(int j=0; j<NUM_CELLS_X; j++) {
	    out << i
	        << ","
	        << j
	 	    << ","
	        << h_q[i*NUM_CELLS_X+j]
	        << std::endl;
	}
  }
}

void printResult(int timestep) {

	printf("\nTimestep %d \n", timestep);
	printf("Q: ");
	for (int i=0; i<NUM_CELLS_Y; i++) {
		printf("\n");
  		for(int j=0; j<NUM_CELLS_X; j++) {
  			printf("%f ", h_q[getIndex(i,j)]);
  		}
  	}
	printf("\n");
	printf("Flux_X: ");
	for (int i=0; i<NUM_CELLS_Y; i++) {
		printf("\n");
  		for(int j=0; j<NUM_CELLS_X; j++) {
  			printf("%f ", h_flux_x[getIndex(i,j)]);
  		}
  	}
	printf("\n");
	printf("Flux_Y: ");
	for (int i=0; i<NUM_CELLS_Y; i++) {
		printf("\n");
  		for(int j=0; j<NUM_CELLS_X; j++) {
  			printf("%f ", h_flux_y[getIndex(i,j)]);
  		}
  	}
	printf("\n");
}

void setup() {
	for (int i=1; i<4; i++) {
  		for(int j=1; j<4; j++) {
  			int index = getIndex(i,j);
  			h_q[index] = 5.0;
  		}
  	}
	h_velocities[0] = 0.5;
	h_velocities[1] = 0.5;
	h_max_velocity = 0.0;
	int i;
	for(i = 0; i<sizeof(h_velocities)/sizeof(double); i++) {
		h_max_velocity += h_velocities[i] * h_velocities[i];
	}
	h_max_velocity = sqrt(h_max_velocity);
}

void reconstruction() {
	for(int i=0; i<NUM_CELLS_Y; i++) {
		for(int j=0; j<NUM_CELLS_X; j++) {
			int index = getIndex(i,j);
			if(j != 0) {
				h_flux_x[index] = ((h_q[index] + h_q[index-1]) / 2) - (h_max_velocity/2 * (h_q[index] - h_q[index-1]));
			}
			if(i != 0) {
				h_flux_y[index] = ((h_q[index] + h_q[index-NUM_CELLS_X]) / 2) - (h_max_velocity/2 * (h_q[index] - h_q[index-NUM_CELLS_X]));
			}
		}
	}
}

__global__ void reconstruction_kernel(const double * const d_q, double * d_flux_x, double * d_flux_y, const double * const d_max_velocity) {
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;

	if (row >= NUM_CELLS_Y || col >= NUM_CELLS_X)
		return;

	int self = row * NUM_CELLS_X + col;

	if(col != 0) {
		d_flux_x[self] = ((d_q[self] + d_q[self-1]) / 2) - (*d_max_velocity/2 * (d_q[self] - d_q[self-1]));
	}

	if(row != 0) {
		d_flux_y[self] = ((d_q[self] + d_q[self-NUM_CELLS_X]) / 2) - (*d_max_velocity/2 * (d_q[self] - d_q[self-NUM_CELLS_X]));
	}
}

__global__ void update_kernel(double * d_q, const double * const d_flux_x, const double * const d_flux_y) {  
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;

	if (row >= NUM_CELLS_Y || col >= NUM_CELLS_X)
		return;

	int self = row * NUM_CELLS_X + col;

	if(self > ((NUM_CELLS_X-1) * (NUM_CELLS_Y-1) - 1))
		return;

	double temp = d_q[self] + ((TIMESTEP/DELTA_X) * (d_flux_x[self] - d_flux_x[self+1]));

	if(row < NUM_CELLS_X-1)
		temp += (TIMESTEP/DELTA_Y) * (d_flux_y[self] - d_flux_y[self+NUM_CELLS_X]);

	// 0 limiter to remove numerical artefacts 
	if(temp <= 0.0) {
		d_q[self] = 0.0;
	} else {
		d_q[self] = temp;
	}

}

void update_cells() {
	double temp;
	for(int i=0; i<NUM_CELLS_Y-1; i++) {
		for(int j=0; j<NUM_CELLS_X-1; j++) {
			int index = getIndex(i,j);
			assert(index >= 0);
			assert(index < NUM_CELLS_X * NUM_CELLS_Y);
			temp = h_q[index] + ((TIMESTEP/DELTA_X) * (h_flux_x[index] - h_flux_x[index+1])) + ((TIMESTEP/DELTA_Y) * (h_flux_y[index] - h_flux_y[index+NUM_CELLS_X]));
			if(temp < 0) {
				h_q[index] = 0;
			} else {
				h_q[index] = temp;
			}
		}
	}
}


int main() {
	setup();
	printCSVFile(0);
	//printResult(0);

	// Allocate memory for GPU data - Naive assumption that our GPU can fit all our data in memory at once
	gpuErrchk(cudaMalloc((void **) &d_flux_x, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(cudaMalloc((void **) &d_flux_y, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(cudaMalloc((void **) &d_q, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(cudaMalloc((void **) &d_max_velocity, sizeof(double)));

	gpuErrchk(cudaMemset(d_flux_x, 0, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(cudaMemset(d_flux_y, 0, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(cudaMemcpy(d_max_velocity, &h_max_velocity, sizeof(double), cudaMemcpyHostToDevice));
	gpuErrchk(cudaMemcpy(d_q, h_q, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, cudaMemcpyHostToDevice));
	float time;
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	cudaEventRecord(start, 0);

	dim3 block(32, 32);

	for(int i=0; i<NUM_TIMESTEPS; i++) {
		reconstruction_kernel<<<3, block>>>(d_q, d_flux_x, d_flux_y, d_max_velocity);
		gpuErrchk( cudaPeekAtLastError() );
		update_kernel<<<3, block>>>(d_q, d_flux_x, d_flux_y);
		gpuErrchk( cudaPeekAtLastError() );

		// Copy GPU data back to GPU for recording - TODO: Improve this so that we only copy data back when we need it.
		gpuErrchk(cudaMemcpy(h_q, d_q, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, cudaMemcpyDeviceToHost));
		gpuErrchk(cudaMemcpy(h_flux_x, d_flux_x, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, cudaMemcpyDeviceToHost));
		gpuErrchk(cudaMemcpy(h_flux_y, d_flux_y, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, cudaMemcpyDeviceToHost));

		if (i%PLOT_FREQUENCY==0) {
      		printCSVFile(i/PLOT_FREQUENCY+1); // Please switch off all IO if you do performance tests.
      		//printResult(i+1);
    	}
	}

	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	cudaEventElapsedTime(&time, start, stop);
	printf ("Time for the program: %f ms\n", time);

	cudaFree(d_flux_x);
	cudaFree(d_flux_y);
	cudaFree(d_q);
	cudaFree(d_max_velocity);

	return 0;
}
	.file	"tmpxft_002bb142_00000000-6_cuda_advection.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3833:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3833:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z9gpuAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC0:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z9gpuAssert9cudaErrorPKcib,"axG",@progbits,_Z9gpuAssert9cudaErrorPKcib,comdat
	.weak	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB3823:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L8
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L2
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE3823:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.text
	.globl	_Z8getIndexii
	.type	_Z8getIndexii, @function
_Z8getIndexii:
.LFB3824:
	.cfi_startproc
	endbr64
	imull	$40, %edi, %edi
	leal	(%rdi,%rsi), %eax
	ret
	.cfi_endproc
.LFE3824:
	.size	_Z8getIndexii, .-_Z8getIndexii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"\nTimestep %d \n"
.LC2:
	.string	"Q: "
.LC3:
	.string	"\n"
.LC4:
	.string	"%f "
.LC5:
	.string	"Flux_X: "
.LC6:
	.string	"Flux_Y: "
	.text
	.globl	_Z11printResulti
	.type	_Z11printResulti, @function
_Z11printResulti:
.LFB3826:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	%edi, %edx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%eax, %eax
	leaq	h_q(%rip), %r14
	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
	leaq	.LC3(%rip), %rbx
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L15:
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %r13
.L14:
	movsd	(%r14,%rbp,8), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$40, %rbp
	jne	.L14
	addl	$40, %r12d
	addq	$320, %r14
	cmpl	$1600, %r12d
	jne	.L15
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	h_flux_x(%rip), %r14
.L17:
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
.L16:
	movsd	(%r14,%rbp,8), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$40, %rbp
	jne	.L16
	addl	$40, %r12d
	addq	$320, %r14
	cmpl	$1600, %r12d
	jne	.L17
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	call	__printf_chk@PLT
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	h_flux_y(%rip), %r14
.L19:
	movq	%rbx, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
.L18:
	movsd	(%r14,%rbp,8), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$1, %al
	incq	%rbp
	call	__printf_chk@PLT
	cmpq	$40, %rbp
	jne	.L18
	addl	$40, %r12d
	addq	$320, %r14
	cmpl	$1600, %r12d
	jne	.L19
	movq	%rbx, %rsi
	movl	$2, %edi
	popq	%rbx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE3826:
	.size	_Z11printResulti, .-_Z11printResulti
	.globl	_Z5setupv
	.type	_Z5setupv, @function
_Z5setupv:
.LFB3827:
	.cfi_startproc
	endbr64
	movsd	.LC7(%rip), %xmm0
	movq	.LC9(%rip), %rax
	movsd	%xmm0, 328+h_q(%rip)
	movsd	%xmm0, 336+h_q(%rip)
	movsd	%xmm0, 344+h_q(%rip)
	movsd	%xmm0, 648+h_q(%rip)
	movsd	%xmm0, 656+h_q(%rip)
	movsd	%xmm0, 664+h_q(%rip)
	movsd	%xmm0, 968+h_q(%rip)
	movsd	%xmm0, 976+h_q(%rip)
	movsd	%xmm0, 984+h_q(%rip)
	movsd	.LC8(%rip), %xmm0
	movq	%rax, h_max_velocity(%rip)
	movsd	%xmm0, h_velocities(%rip)
	movsd	%xmm0, 8+h_velocities(%rip)
	ret
	.cfi_endproc
.LFE3827:
	.size	_Z5setupv, .-_Z5setupv
	.globl	_Z14reconstructionv
	.type	_Z14reconstructionv, @function
_Z14reconstructionv:
.LFB3828:
	.cfi_startproc
	endbr64
	leaq	-320+h_q(%rip), %rsi
	movsd	h_max_velocity(%rip), %xmm4
	xorl	%ecx, %ecx
	movsd	.LC8(%rip), %xmm2
	leaq	320(%rsi), %rdi
	leaq	h_flux_x(%rip), %r8
	leaq	h_flux_y(%rip), %r9
.L29:
	imulq	$320, %rcx, %rdx
	xorl	%eax, %eax
.L32:
	testq	%rax, %rax
	je	.L30
	movsd	312(%rsi,%rax,8), %xmm5
	movsd	(%rdi,%rdx), %xmm1
	movaps	%xmm1, %xmm0
	movaps	%xmm1, %xmm3
	movaps	%xmm4, %xmm1
	mulsd	%xmm2, %xmm1
	addsd	%xmm5, %xmm0
	subsd	%xmm5, %xmm3
	mulsd	%xmm2, %xmm0
	mulsd	%xmm3, %xmm1
	subsd	%xmm1, %xmm0
	movsd	%xmm0, (%r8,%rdx)
.L30:
	testq	%rcx, %rcx
	je	.L31
	movsd	(%rdi,%rdx), %xmm1
	movsd	(%rsi,%rax,8), %xmm5
	movaps	%xmm1, %xmm0
	movaps	%xmm1, %xmm3
	movaps	%xmm4, %xmm1
	mulsd	%xmm2, %xmm1
	addsd	%xmm5, %xmm0
	subsd	%xmm5, %xmm3
	mulsd	%xmm2, %xmm0
	mulsd	%xmm3, %xmm1
	subsd	%xmm1, %xmm0
	movsd	%xmm0, (%r9,%rdx)
.L31:
	incq	%rax
	addq	$8, %rdx
	cmpq	$40, %rax
	jne	.L32
	incq	%rcx
	addq	$320, %rsi
	cmpq	$40, %rcx
	jne	.L29
	ret
	.cfi_endproc
.LFE3828:
	.size	_Z14reconstructionv, .-_Z14reconstructionv
	.globl	_Z12update_cellsv
	.type	_Z12update_cellsv, @function
_Z12update_cellsv:
.LFB3829:
	.cfi_startproc
	endbr64
	leaq	h_flux_x(%rip), %rdi
	leaq	h_flux_y(%rip), %r9
	xorps	%xmm3, %xmm3
	xorl	%edx, %edx
	movsd	.LC11(%rip), %xmm2
	leaq	8(%rdi), %r8
	leaq	h_q(%rip), %rsi
	leaq	320(%r9), %r10
.L42:
	movq	%rdx, %rax
	xorl	%ecx, %ecx
.L45:
	movsd	(%r9,%rax), %xmm1
	subsd	(%r10,%rax), %xmm1
	movsd	(%rdi,%rax), %xmm0
	subsd	(%r8,%rax), %xmm0
	mulsd	%xmm2, %xmm1
	mulsd	%xmm2, %xmm0
	addsd	(%rsi,%rax), %xmm0
	addsd	%xmm1, %xmm0
	comisd	%xmm0, %xmm3
	jbe	.L43
	xorps	%xmm0, %xmm0
.L43:
	incl	%ecx
	movsd	%xmm0, (%rsi,%rax)
	addq	$8, %rax
	cmpl	$39, %ecx
	jne	.L45
	addq	$320, %rdx
	cmpq	$12480, %rdx
	jne	.L42
	ret
	.cfi_endproc
.LFE3829:
	.size	_Z12update_cellsv, .-_Z12update_cellsv
	.globl	_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_
	.type	_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_, @function
_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_:
.LFB3855:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L49
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z21reconstruction_kernelPKdPdS1_S0_(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L49:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L51
	call	__stack_chk_fail@PLT
.L51:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3855:
	.size	_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_, .-_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_
	.globl	_Z21reconstruction_kernelPKdPdS1_S0_
	.type	_Z21reconstruction_kernelPKdPdS1_S0_, @function
_Z21reconstruction_kernelPKdPdS1_S0_:
.LFB3856:
	.cfi_startproc
	endbr64
	jmp	_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_
	.cfi_endproc
.LFE3856:
	.size	_Z21reconstruction_kernelPKdPdS1_S0_, .-_Z21reconstruction_kernelPKdPdS1_S0_
	.globl	_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_
	.type	_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_, @function
_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_:
.LFB3857:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z13update_kernelPdPKdS1_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L54:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3857:
	.size	_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_, .-_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_
	.globl	_Z13update_kernelPdPKdS1_
	.type	_Z13update_kernelPdPKdS1_, @function
_Z13update_kernelPdPKdS1_:
.LFB3858:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_
	.cfi_endproc
.LFE3858:
	.size	_Z13update_kernelPdPKdS1_, .-_Z13update_kernelPdPKdS1_
	.section	.rodata.str1.1
.LC12:
	.string	"_Z13update_kernelPdPKdS1_"
.LC13:
	.string	"_Z21reconstruction_kernelPKdPdS1_S0_"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3860:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z13update_kernelPdPKdS1_(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z21reconstruction_kernelPKdPdS1_S0_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3860:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.rodata.str1.1
.LC14:
	.string	"result-"
.LC15:
	.string	".csv"
.LC16:
	.string	"x, y, z"
.LC17:
	.string	","
	.text
	.globl	_Z12printCSVFilei
	.type	_Z12printCSVFilei, @function
_Z12printCSVFilei:
.LFB3825:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3825
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	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
	movl	%edi, %ebx
	subq	$968, %rsp
	.cfi_def_cfa_offset 1024
	movq	%fs:40, %rax
	movq	%rax, 952(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
.LEHB0:
	call	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1Ev@PLT
.LEHE0:
	leaq	64(%rsp), %rdi
	leaq	.LC14(%rip), %rsi
.LEHB1:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%ebx, %esi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	leaq	.LC15(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	16(%rsp), %rbp
	leaq	72(%rsp), %rsi
	movq	%rbp, %rdi
	call	_ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE3strEv@PLT
.LEHE1:
	leaq	440(%rsp), %rbx
	movq	16(%rsp), %rsi
	movl	$16, %edx
	movq	%rbx, %rdi
.LEHB2:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE2:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	leaq	.LC16(%rip), %rsi
	movq	%rbx, %rdi
.LEHB3:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	h_q(%rip), %r13
	xorl	%r12d, %r12d
	leaq	.LC17(%rip), %r14
.L62:
	xorl	%ebp, %ebp
.L63:
	movl	%r12d, %esi
	movq	%rbx, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	movq	%r14, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	%ebp, %esi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	movq	%r14, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	0(%r13,%rbp,8), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.LEHE3:
	incq	%rbp
	cmpq	$40, %rbp
	jne	.L63
	incl	%r12d
	addq	$320, %r13
	cmpl	$40, %r12d
	jne	.L62
	movq	%rbx, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	8(%rsp), %rdi
	call	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev@PLT
	movq	952(%rsp), %rax
	subq	%fs:40, %rax
	je	.L69
	jmp	.L74
.L71:
	endbr64
	movq	%rax, %rbx
.L65:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L66
.L72:
	endbr64
	movq	%rax, %rbp
.L67:
	movq	%rbx, %rdi
	movq	%rbp, %rbx
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	jmp	.L66
.L70:
	endbr64
	movq	%rax, %rbx
.L66:
	movq	8(%rsp), %rdi
	call	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev@PLT
	movq	952(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L74
	movq	%rbx, %rdi
.LEHB4:
	call	_Unwind_Resume@PLT
.LEHE4:
.L74:
	call	__stack_chk_fail@PLT
.L69:
	addq	$968, %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
.LFE3825:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3825:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3825-.LLSDACSB3825
.LLSDACSB3825:
	.uleb128 .LEHB0-.LFB3825
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3825
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L70-.LFB3825
	.uleb128 0
	.uleb128 .LEHB2-.LFB3825
	.uleb128 .LEHE2-.LEHB2
	.uleb128 .L71-.LFB3825
	.uleb128 0
	.uleb128 .LEHB3-.LFB3825
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L72-.LFB3825
	.uleb128 0
	.uleb128 .LEHB4-.LFB3825
	.uleb128 .LEHE4-.LEHB4
	.uleb128 0
	.uleb128 0
.LLSDACSE3825:
	.text
	.size	_Z12printCSVFilei, .-_Z12printCSVFilei
	.section	.rodata.str1.1
.LC18:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/Jack-Clark/cuda-exahype/master/advection/cuda_advection.cu"
.LC19:
	.string	"Time for the program: %f ms\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3830:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%edi, %edi
	leaq	h_q(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movabsq	$4294967299, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	.LC18(%rip), %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	_Z5setupv
	call	_Z12printCSVFilei
	movl	$12800, %esi
	leaq	d_flux_x(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$200, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$12800, %esi
	leaq	d_flux_y(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$201, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$12800, %esi
	leaq	d_q(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$202, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$8, %esi
	leaq	d_max_velocity(%rip), %rdi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$203, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	d_flux_x(%rip), %rdi
	movl	$12800, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	$1, %ecx
	movl	$205, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	d_flux_y(%rip), %rdi
	movl	$12800, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	$1, %ecx
	movl	$206, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$1, %ecx
	movq	d_max_velocity(%rip), %rdi
	movl	$8, %edx
	leaq	h_max_velocity(%rip), %rsi
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$207, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	d_q(%rip), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	movl	$12800, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$208, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	%rsp, %rdi
	call	cudaEventCreate@PLT
	leaq	8(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$1, 24(%rsp)
	movabsq	$137438953504, %rax
	movq	%rax, 16(%rsp)
.L80:
	movl	24(%rsp), %ecx
	movq	16(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r12, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L77
	movq	d_max_velocity(%rip), %rcx
	movq	d_flux_y(%rip), %rdx
	movq	d_flux_x(%rip), %rsi
	movq	d_q(%rip), %rdi
	call	_Z50__device_stub__Z21reconstruction_kernelPKdPdS1_S0_PKdPdS1_S0_
.L77:
	call	cudaPeekAtLastError@PLT
	movl	$1, %ecx
	movl	$219, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	24(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	16(%rsp), %rdx
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r12, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L78
	movq	d_flux_y(%rip), %rdx
	movq	d_flux_x(%rip), %rsi
	movq	d_q(%rip), %rdi
	call	_Z39__device_stub__Z13update_kernelPdPKdS1_PdPKdS1_
.L78:
	call	cudaPeekAtLastError@PLT
	movl	$1, %ecx
	movl	$221, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	d_q(%rip), %rsi
	movl	$2, %ecx
	movq	%r13, %rdi
	movl	$12800, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$224, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$2, %ecx
	movq	d_flux_x(%rip), %rsi
	movl	$12800, %edx
	leaq	h_flux_x(%rip), %rdi
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$225, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$2, %ecx
	movq	d_flux_y(%rip), %rsi
	movl	$12800, %edx
	leaq	h_flux_y(%rip), %rdi
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$226, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	%ebp, %eax
	movl	$100, %ecx
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L79
	leal	1(%rax), %edi
	call	_Z12printCSVFilei
.L79:
	incl	%ebp
	cmpl	$100000, %ebp
	jne	.L80
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	8(%rsp), %rdx
	movq	(%rsp), %rsi
	leaq	28(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	28(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	d_flux_x(%rip), %rdi
	call	cudaFree@PLT
	movq	d_flux_y(%rip), %rdi
	call	cudaFree@PLT
	movq	d_q(%rip), %rdi
	call	cudaFree@PLT
	movq	d_max_velocity(%rip), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L81
	call	__stack_chk_fail@PLT
.L81:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3830:
	.size	main, .-main
	.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	d_max_velocity
	.bss
	.align 8
	.type	d_max_velocity, @object
	.size	d_max_velocity, 8
d_max_velocity:
	.zero	8
	.globl	d_q
	.align 8
	.type	d_q, @object
	.size	d_q, 8
d_q:
	.zero	8
	.globl	d_flux_y
	.align 8
	.type	d_flux_y, @object
	.size	d_flux_y, 8
d_flux_y:
	.zero	8
	.globl	d_flux_x
	.align 8
	.type	d_flux_x, @object
	.size	d_flux_x, 8
d_flux_x:
	.zero	8
	.globl	h_max_velocity
	.align 8
	.type	h_max_velocity, @object
	.size	h_max_velocity, 8
h_max_velocity:
	.zero	8
	.globl	h_velocities
	.align 16
	.type	h_velocities, @object
	.size	h_velocities, 16
h_velocities:
	.zero	16
	.globl	h_q
	.align 32
	.type	h_q, @object
	.size	h_q, 12800
h_q:
	.zero	12800
	.globl	h_flux_y
	.align 32
	.type	h_flux_y, @object
	.size	h_flux_y, 12800
h_flux_y:
	.zero	12800
	.globl	h_flux_x
	.align 32
	.type	h_flux_x, @object
	.size	h_flux_x, 12800
h_flux_x:
	.zero	12800
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC7:
	.long	0
	.long	1075052544
	.align 8
.LC8:
	.long	0
	.long	1071644672
	.align 8
.LC9:
	.long	1719614413
	.long	1072079006
	.align 8
.LC11:
	.long	-755914244
	.long	1062232653
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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:

/* 
	@author Jack Clark

	Simple program to simulate 2D advection using the finite volume approach, with naive averaging at cell boundaries. 
	
	Compile with nvcc -O3 advection.cu -o gpu_advection
*/


#include <fstream>
#include <sstream>
#include <math.h>
#include <assert.h>
#include <hip/hip_runtime.h>


#define NUM_CELLS_X 40
#define NUM_CELLS_Y 40
#define TIMESTEP 0.001
#define NUM_TIMESTEPS 100000
#define DELTA_X 1
#define DELTA_Y 1
#define PLOT_FREQUENCY 100

// CPU data
double h_flux_x[NUM_CELLS_X*NUM_CELLS_Y];
double h_flux_y[NUM_CELLS_X*NUM_CELLS_Y];
double h_q[NUM_CELLS_X*NUM_CELLS_Y];
double h_velocities[2];
double h_max_velocity;

// GPU data
double * d_flux_x;
double * d_flux_y;
double * d_q;
double * d_max_velocity;

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }

inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=true)
{
   if (code != hipSuccess) 
   {
      fprintf(stderr,"GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

int getIndex(int row, int col) {
	return row * NUM_CELLS_X + col;
}

void printCSVFile(int counter) {
  std::stringstream filename;
  filename << "result-" << counter <<  ".csv";
  std::ofstream out( filename.str().c_str() );

  out << "x, y, z" << std::endl;

  for (int i=0; i<NUM_CELLS_Y; i++) {
  	for(int j=0; j<NUM_CELLS_X; j++) {
	    out << i
	        << ","
	        << j
	 	    << ","
	        << h_q[i*NUM_CELLS_X+j]
	        << std::endl;
	}
  }
}

void printResult(int timestep) {

	printf("\nTimestep %d \n", timestep);
	printf("Q: ");
	for (int i=0; i<NUM_CELLS_Y; i++) {
		printf("\n");
  		for(int j=0; j<NUM_CELLS_X; j++) {
  			printf("%f ", h_q[getIndex(i,j)]);
  		}
  	}
	printf("\n");
	printf("Flux_X: ");
	for (int i=0; i<NUM_CELLS_Y; i++) {
		printf("\n");
  		for(int j=0; j<NUM_CELLS_X; j++) {
  			printf("%f ", h_flux_x[getIndex(i,j)]);
  		}
  	}
	printf("\n");
	printf("Flux_Y: ");
	for (int i=0; i<NUM_CELLS_Y; i++) {
		printf("\n");
  		for(int j=0; j<NUM_CELLS_X; j++) {
  			printf("%f ", h_flux_y[getIndex(i,j)]);
  		}
  	}
	printf("\n");
}

void setup() {
	for (int i=1; i<4; i++) {
  		for(int j=1; j<4; j++) {
  			int index = getIndex(i,j);
  			h_q[index] = 5.0;
  		}
  	}
	h_velocities[0] = 0.5;
	h_velocities[1] = 0.5;
	h_max_velocity = 0.0;
	int i;
	for(i = 0; i<sizeof(h_velocities)/sizeof(double); i++) {
		h_max_velocity += h_velocities[i] * h_velocities[i];
	}
	h_max_velocity = sqrt(h_max_velocity);
}

void reconstruction() {
	for(int i=0; i<NUM_CELLS_Y; i++) {
		for(int j=0; j<NUM_CELLS_X; j++) {
			int index = getIndex(i,j);
			if(j != 0) {
				h_flux_x[index] = ((h_q[index] + h_q[index-1]) / 2) - (h_max_velocity/2 * (h_q[index] - h_q[index-1]));
			}
			if(i != 0) {
				h_flux_y[index] = ((h_q[index] + h_q[index-NUM_CELLS_X]) / 2) - (h_max_velocity/2 * (h_q[index] - h_q[index-NUM_CELLS_X]));
			}
		}
	}
}

__global__ void reconstruction_kernel(const double * const d_q, double * d_flux_x, double * d_flux_y, const double * const d_max_velocity) {
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;

	if (row >= NUM_CELLS_Y || col >= NUM_CELLS_X)
		return;

	int self = row * NUM_CELLS_X + col;

	if(col != 0) {
		d_flux_x[self] = ((d_q[self] + d_q[self-1]) / 2) - (*d_max_velocity/2 * (d_q[self] - d_q[self-1]));
	}

	if(row != 0) {
		d_flux_y[self] = ((d_q[self] + d_q[self-NUM_CELLS_X]) / 2) - (*d_max_velocity/2 * (d_q[self] - d_q[self-NUM_CELLS_X]));
	}
}

__global__ void update_kernel(double * d_q, const double * const d_flux_x, const double * const d_flux_y) {  
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;

	if (row >= NUM_CELLS_Y || col >= NUM_CELLS_X)
		return;

	int self = row * NUM_CELLS_X + col;

	if(self > ((NUM_CELLS_X-1) * (NUM_CELLS_Y-1) - 1))
		return;

	double temp = d_q[self] + ((TIMESTEP/DELTA_X) * (d_flux_x[self] - d_flux_x[self+1]));

	if(row < NUM_CELLS_X-1)
		temp += (TIMESTEP/DELTA_Y) * (d_flux_y[self] - d_flux_y[self+NUM_CELLS_X]);

	// 0 limiter to remove numerical artefacts 
	if(temp <= 0.0) {
		d_q[self] = 0.0;
	} else {
		d_q[self] = temp;
	}

}

void update_cells() {
	double temp;
	for(int i=0; i<NUM_CELLS_Y-1; i++) {
		for(int j=0; j<NUM_CELLS_X-1; j++) {
			int index = getIndex(i,j);
			assert(index >= 0);
			assert(index < NUM_CELLS_X * NUM_CELLS_Y);
			temp = h_q[index] + ((TIMESTEP/DELTA_X) * (h_flux_x[index] - h_flux_x[index+1])) + ((TIMESTEP/DELTA_Y) * (h_flux_y[index] - h_flux_y[index+NUM_CELLS_X]));
			if(temp < 0) {
				h_q[index] = 0;
			} else {
				h_q[index] = temp;
			}
		}
	}
}


int main() {
	setup();
	printCSVFile(0);
	//printResult(0);

	// Allocate memory for GPU data - Naive assumption that our GPU can fit all our data in memory at once
	gpuErrchk(hipMalloc((void **) &d_flux_x, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(hipMalloc((void **) &d_flux_y, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(hipMalloc((void **) &d_q, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(hipMalloc((void **) &d_max_velocity, sizeof(double)));

	gpuErrchk(hipMemset(d_flux_x, 0, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(hipMemset(d_flux_y, 0, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y));
	gpuErrchk(hipMemcpy(d_max_velocity, &h_max_velocity, sizeof(double), hipMemcpyHostToDevice));
	gpuErrchk(hipMemcpy(d_q, h_q, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, hipMemcpyHostToDevice));
	float time;
	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);
	hipEventRecord(start, 0);

	dim3 block(32, 32);

	for(int i=0; i<NUM_TIMESTEPS; i++) {
		reconstruction_kernel<<<3, block>>>(d_q, d_flux_x, d_flux_y, d_max_velocity);
		gpuErrchk( hipPeekAtLastError() );
		update_kernel<<<3, block>>>(d_q, d_flux_x, d_flux_y);
		gpuErrchk( hipPeekAtLastError() );

		// Copy GPU data back to GPU for recording - TODO: Improve this so that we only copy data back when we need it.
		gpuErrchk(hipMemcpy(h_q, d_q, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, hipMemcpyDeviceToHost));
		gpuErrchk(hipMemcpy(h_flux_x, d_flux_x, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, hipMemcpyDeviceToHost));
		gpuErrchk(hipMemcpy(h_flux_y, d_flux_y, sizeof(double) * NUM_CELLS_X * NUM_CELLS_Y, hipMemcpyDeviceToHost));

		if (i%PLOT_FREQUENCY==0) {
      		printCSVFile(i/PLOT_FREQUENCY+1); // Please switch off all IO if you do performance tests.
      		//printResult(i+1);
    	}
	}

	hipEventRecord(stop, 0);
	hipEventSynchronize(stop);
	hipEventElapsedTime(&time, start, stop);
	printf ("Time for the program: %f ms\n", time);

	hipFree(d_flux_x);
	hipFree(d_flux_y);
	hipFree(d_q);
	hipFree(d_max_velocity);

	return 0;
}
	.text
	.file	"cuda_advection.hip"
	.globl	_Z8getIndexii                   # -- Begin function _Z8getIndexii
	.type	_Z8getIndexii,@function
_Z8getIndexii:                          # @_Z8getIndexii
	.cfi_startproc
# %bb.0:
                                        # kill: def $esi killed $esi def $rsi
                                        # kill: def $edi killed $edi def $rdi
	leal	(%rdi,%rdi,4), %eax
	leal	(%rsi,%rax,8), %eax
	retq
.Lfunc_end0:
	.size	_Z8getIndexii, .Lfunc_end0-_Z8getIndexii
	.cfi_endproc
                                        # -- End function
	.globl	_Z12printCSVFilei               # -- Begin function _Z12printCSVFilei
	.type	_Z12printCSVFilei,@function
_Z12printCSVFilei:                      # @_Z12printCSVFilei
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$944, %rsp                      # imm = 0x3B0
	.cfi_def_cfa_offset 992
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edi, %ebx
	leaq	40(%rsp), %rdi
	callq	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1Ev
	leaq	56(%rsp), %r14
.Ltmp0:
	movl	$.L.str, %esi
	movl	$7, %edx
	movq	%r14, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp1:
# %bb.1:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
.Ltmp2:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_ZNSolsEi
.Ltmp3:
# %bb.2:
.Ltmp4:
	movl	$.L.str.1, %esi
	movl	$4, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp5:
# %bb.3:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit21
	leaq	64(%rsp), %rsi
.Ltmp7:
	leaq	8(%rsp), %rdi
	callq	_ZNKSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEE3strEv
.Ltmp8:
# %bb.4:                                # %_ZNKSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEE3strEv.exit
	movq	8(%rsp), %rsi
.Ltmp10:
	leaq	432(%rsp), %rdi
	movl	$16, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
.Ltmp11:
# %bb.5:
	leaq	24(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB1_7
# %bb.6:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB1_7:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
.Ltmp13:
	leaq	432(%rsp), %rbx
	movl	$.L.str.2, %esi
	movl	$7, %edx
	movq	%rbx, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp14:
# %bb.8:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit22
	movq	432(%rsp), %rax
	addq	-24(%rax), %rbx
.Ltmp15:
	movq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp16:
# %bb.9:                                # %.noexc
.Ltmp17:
	movsbl	%al, %esi
	leaq	432(%rsp), %rdi
	callq	_ZNSo3putEc
.Ltmp18:
# %bb.10:                               # %.noexc29
.Ltmp19:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp20:
# %bb.11:                               # %.preheader.preheader
	movl	$h_q, %r13d
	xorl	%ebx, %ebx
	leaq	432(%rsp), %r14
.LBB1_12:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_13 Depth 2
	xorl	%r15d, %r15d
.LBB1_13:                               #   Parent Loop BB1_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
.Ltmp22:
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	_ZNSolsEi
.Ltmp23:
# %bb.14:                               #   in Loop: Header=BB1_13 Depth=2
.Ltmp24:
	movq	%rax, %r12
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp25:
# %bb.15:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit26
                                        #   in Loop: Header=BB1_13 Depth=2
.Ltmp26:
	movq	%r12, %rdi
	movl	%r15d, %esi
	callq	_ZNSolsEi
.Ltmp27:
# %bb.16:                               #   in Loop: Header=BB1_13 Depth=2
.Ltmp28:
	movq	%rax, %r12
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp29:
# %bb.17:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit27
                                        #   in Loop: Header=BB1_13 Depth=2
	movsd	(%r13,%r15,8), %xmm0            # xmm0 = mem[0],zero
.Ltmp30:
	movq	%r12, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp31:
# %bb.18:                               # %_ZNSolsEd.exit
                                        #   in Loop: Header=BB1_13 Depth=2
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
.Ltmp32:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp33:
# %bb.19:                               # %.noexc31
                                        #   in Loop: Header=BB1_13 Depth=2
.Ltmp34:
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
.Ltmp35:
# %bb.20:                               # %.noexc32
                                        #   in Loop: Header=BB1_13 Depth=2
.Ltmp36:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp37:
# %bb.21:                               # %_ZNSolsEPFRSoS_E.exit28
                                        #   in Loop: Header=BB1_13 Depth=2
	incq	%r15
	cmpq	$40, %r15
	jne	.LBB1_13
# %bb.22:                               # %_ZNSolsEPFRSoS_E.exit
                                        #   in Loop: Header=BB1_12 Depth=1
	incq	%rbx
	addq	$320, %r13                      # imm = 0x140
	cmpq	$40, %rbx
	jne	.LBB1_12
# %bb.23:
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE(%rip), %rax
	leaq	440(%rsp), %rdi
	movq	%rax, -8(%rdi)
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE+24(%rip), %rcx
	movq	-24(%rax), %rax
	movq	%rcx, 432(%rsp,%rax)
	callq	_ZNSt13basic_filebufIcSt11char_traitsIcEED2Ev
	leaq	680(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	leaq	40(%rsp), %rdi
	movl	$_ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE, %esi
	callq	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED2Ev
	leaq	168(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	addq	$944, %rsp                      # imm = 0x3B0
	.cfi_def_cfa_offset 48
	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
.LBB1_24:
	.cfi_def_cfa_offset 992
.Ltmp12:
	movq	%rax, %rbx
	leaq	24(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB1_32
# %bb.25:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i23
	callq	_ZdlPv
	jmp	.LBB1_32
.LBB1_26:
.Ltmp9:
	jmp	.LBB1_28
.LBB1_27:
.Ltmp6:
.LBB1_28:
	movq	%rax, %rbx
	jmp	.LBB1_32
.LBB1_29:
.Ltmp21:
	jmp	.LBB1_31
.LBB1_30:
.Ltmp38:
.LBB1_31:
	movq	%rax, %rbx
	leaq	432(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
.LBB1_32:
	leaq	40(%rsp), %rdi
	movl	$_ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE, %esi
	callq	_ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEED2Ev
	leaq	168(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end1:
	.size	_Z12printCSVFilei, .Lfunc_end1-_Z12printCSVFilei
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table1:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp5-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp5
	.uleb128 .Ltmp6-.Lfunc_begin0           #     jumps to .Ltmp6
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp8-.Ltmp7                  #   Call between .Ltmp7 and .Ltmp8
	.uleb128 .Ltmp9-.Lfunc_begin0           #     jumps to .Ltmp9
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp10-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp11-.Ltmp10                #   Call between .Ltmp10 and .Ltmp11
	.uleb128 .Ltmp12-.Lfunc_begin0          #     jumps to .Ltmp12
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp13-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp20-.Ltmp13                #   Call between .Ltmp13 and .Ltmp20
	.uleb128 .Ltmp21-.Lfunc_begin0          #     jumps to .Ltmp21
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp22-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp37-.Ltmp22                #   Call between .Ltmp22 and .Ltmp37
	.uleb128 .Ltmp38-.Lfunc_begin0          #     jumps to .Ltmp38
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp37-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Lfunc_end1-.Ltmp37            #   Call between .Ltmp37 and .Lfunc_end1
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.globl	_Z11printResulti                # -- Begin function _Z11printResulti
	.type	_Z11printResulti,@function
_Z11printResulti:                       # @_Z11printResulti
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edi, %esi
	xorl	%ebx, %ebx
	movl	$.L.str.4, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$h_q, %r14d
.LBB2_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_2 Depth 2
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%r15d, %r15d
.LBB2_2:                                #   Parent Loop BB2_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	$40, %r15
	jne	.LBB2_2
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	incq	%rbx
	addq	$320, %r14                      # imm = 0x140
	cmpq	$40, %rbx
	jne	.LBB2_1
# %bb.4:
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%ebx, %ebx
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$h_flux_x, %r14d
.LBB2_5:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_6 Depth 2
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%r15d, %r15d
.LBB2_6:                                #   Parent Loop BB2_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	$40, %r15
	jne	.LBB2_6
# %bb.7:                                #   in Loop: Header=BB2_5 Depth=1
	incq	%rbx
	addq	$320, %r14                      # imm = 0x140
	cmpq	$40, %rbx
	jne	.LBB2_5
# %bb.8:
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%ebx, %ebx
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$h_flux_y, %r14d
.LBB2_9:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_10 Depth 2
	movl	$10, %edi
	callq	putchar@PLT
	xorl	%r15d, %r15d
.LBB2_10:                               #   Parent Loop BB2_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%r15,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	incq	%r15
	cmpq	$40, %r15
	jne	.LBB2_10
# %bb.11:                               #   in Loop: Header=BB2_9 Depth=1
	incq	%rbx
	addq	$320, %r14                      # imm = 0x140
	cmpq	$40, %rbx
	jne	.LBB2_9
# %bb.12:
	movl	$10, %edi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end2:
	.size	_Z11printResulti, .Lfunc_end2-_Z11printResulti
	.cfi_endproc
                                        # -- End function
	.globl	_Z5setupv                       # -- Begin function _Z5setupv
	.type	_Z5setupv,@function
_Z5setupv:                              # @_Z5setupv
	.cfi_startproc
# %bb.0:
	movl	$1, %eax
	movl	$h_q+328, %ecx
	movabsq	$4617315517961601024, %rdx      # imm = 0x4014000000000000
.LBB3_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
	xorl	%esi, %esi
.LBB3_2:                                #   Parent Loop BB3_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rdx, (%rcx,%rsi,8)
	incq	%rsi
	cmpq	$3, %rsi
	jne	.LBB3_2
# %bb.3:                                #   in Loop: Header=BB3_1 Depth=1
	incq	%rax
	addq	$320, %rcx                      # imm = 0x140
	cmpq	$4, %rax
	jne	.LBB3_1
# %bb.4:
	movabsq	$4602678819172646912, %rax      # imm = 0x3FE0000000000000
	movq	%rax, h_velocities(%rip)
	movq	%rax, h_velocities+8(%rip)
	movabsq	$4604544271217802189, %rax      # imm = 0x3FE6A09E667F3BCD
	movq	%rax, h_max_velocity(%rip)
	retq
.Lfunc_end3:
	.size	_Z5setupv, .Lfunc_end3-_Z5setupv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z14reconstructionv
.LCPI4_0:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	_Z14reconstructionv
	.type	_Z14reconstructionv,@function
_Z14reconstructionv:                    # @_Z14reconstructionv
	.cfi_startproc
# %bb.0:
	movsd	h_max_velocity(%rip), %xmm0     # xmm0 = mem[0],zero
	mulsd	.LCPI4_0(%rip), %xmm0
	movq	$-320, %rax                     # imm = 0xFEC0
	xorl	%ecx, %ecx
	movsd	.LCPI4_0(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB4_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_2 Depth 2
	movq	$-40, %rdx
.LBB4_2:                                #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpq	$-40, %rdx
	je	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=2
	movsd	h_q+640(%rax,%rdx,8), %xmm2     # xmm2 = mem[0],zero
	movsd	h_q+632(%rax,%rdx,8), %xmm3     # xmm3 = mem[0],zero
	movapd	%xmm2, %xmm4
	addsd	%xmm3, %xmm4
	mulsd	%xmm1, %xmm4
	subsd	%xmm3, %xmm2
	mulsd	%xmm0, %xmm2
	subsd	%xmm2, %xmm4
	movsd	%xmm4, h_flux_x+640(%rax,%rdx,8)
.LBB4_4:                                #   in Loop: Header=BB4_2 Depth=2
	testq	%rcx, %rcx
	je	.LBB4_6
# %bb.5:                                #   in Loop: Header=BB4_2 Depth=2
	movsd	h_q+640(%rax,%rdx,8), %xmm2     # xmm2 = mem[0],zero
	movsd	h_q+320(%rax,%rdx,8), %xmm3     # xmm3 = mem[0],zero
	movapd	%xmm2, %xmm4
	addsd	%xmm3, %xmm4
	mulsd	%xmm1, %xmm4
	subsd	%xmm3, %xmm2
	mulsd	%xmm0, %xmm2
	subsd	%xmm2, %xmm4
	movsd	%xmm4, h_flux_y+640(%rax,%rdx,8)
.LBB4_6:                                #   in Loop: Header=BB4_2 Depth=2
	incq	%rdx
	jne	.LBB4_2
# %bb.7:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%rcx
	addq	$320, %rax                      # imm = 0x140
	cmpq	$40, %rcx
	jne	.LBB4_1
# %bb.8:
	retq
.Lfunc_end4:
	.size	_Z14reconstructionv, .Lfunc_end4-_Z14reconstructionv
	.cfi_endproc
                                        # -- End function
	.globl	_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_ # -- Begin function _Z36__device_stub__reconstruction_kernelPKdPdS1_S0_
	.type	_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_,@function
_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_: # @_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z21reconstruction_kernelPKdPdS1_S0_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_, .Lfunc_end5-_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__update_kernelPdPKdS1_ # -- Begin function _Z28__device_stub__update_kernelPdPKdS1_
	.type	_Z28__device_stub__update_kernelPdPKdS1_,@function
_Z28__device_stub__update_kernelPdPKdS1_: # @_Z28__device_stub__update_kernelPdPKdS1_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z13update_kernelPdPKdS1_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z28__device_stub__update_kernelPdPKdS1_, .Lfunc_end6-_Z28__device_stub__update_kernelPdPKdS1_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12update_cellsv
.LCPI7_0:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.text
	.globl	_Z12update_cellsv
	.type	_Z12update_cellsv,@function
_Z12update_cellsv:                      # @_Z12update_cellsv
	.cfi_startproc
# %bb.0:
	movl	$320, %eax                      # imm = 0x140
	xorl	%ecx, %ecx
	movsd	.LCPI7_0(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB7_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_2 Depth 2
	movq	$-39, %rdx
.LBB7_2:                                #   Parent Loop BB7_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	h_flux_x-8(%rax,%rdx,8), %xmm1  # xmm1 = mem[0],zero
	subsd	h_flux_x(%rax,%rdx,8), %xmm1
	mulsd	%xmm0, %xmm1
	addsd	h_q-8(%rax,%rdx,8), %xmm1
	movsd	h_flux_y-8(%rax,%rdx,8), %xmm2  # xmm2 = mem[0],zero
	subsd	h_flux_y+312(%rax,%rdx,8), %xmm2
	mulsd	%xmm0, %xmm2
	addsd	%xmm1, %xmm2
	xorpd	%xmm1, %xmm1
	maxsd	%xmm2, %xmm1
	movsd	%xmm1, h_q-8(%rax,%rdx,8)
	incq	%rdx
	jne	.LBB7_2
# %bb.3:                                #   in Loop: Header=BB7_1 Depth=1
	incq	%rcx
	addq	$320, %rax                      # imm = 0x140
	cmpq	$39, %rcx
	jne	.LBB7_1
# %bb.4:
	retq
.Lfunc_end7:
	.size	_Z12update_cellsv, .Lfunc_end7-_Z12update_cellsv
	.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	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$1, %eax
	movl	$h_q+328, %ecx
	movabsq	$4617315517961601024, %rdx      # imm = 0x4014000000000000
.LBB8_1:                                # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB8_2 Depth 2
	xorl	%esi, %esi
.LBB8_2:                                #   Parent Loop BB8_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rdx, (%rcx,%rsi,8)
	incq	%rsi
	cmpq	$3, %rsi
	jne	.LBB8_2
# %bb.3:                                #   in Loop: Header=BB8_1 Depth=1
	incq	%rax
	addq	$320, %rcx                      # imm = 0x140
	cmpq	$4, %rax
	jne	.LBB8_1
# %bb.4:                                # %_Z5setupv.exit
	movabsq	$4602678819172646912, %rax      # imm = 0x3FE0000000000000
	movq	%rax, h_velocities(%rip)
	movq	%rax, h_velocities+8(%rip)
	movabsq	$4604544271217802189, %rax      # imm = 0x3FE6A09E667F3BCD
	movq	%rax, h_max_velocity(%rip)
	xorl	%edi, %edi
	callq	_Z12printCSVFilei
	movl	$d_flux_x, %edi
	movl	$12800, %esi                    # imm = 0x3200
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB8_5
# %bb.7:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	movl	$d_flux_y, %edi
	movl	$12800, %esi                    # imm = 0x3200
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB8_8
# %bb.9:                                # %_Z9gpuAssert10hipError_tPKcib.exit16
	movl	$d_q, %edi
	movl	$12800, %esi                    # imm = 0x3200
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB8_10
# %bb.11:                               # %_Z9gpuAssert10hipError_tPKcib.exit18
	movl	$d_max_velocity, %edi
	movl	$8, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB8_12
# %bb.13:                               # %_Z9gpuAssert10hipError_tPKcib.exit20
	movq	d_flux_x(%rip), %rdi
	movl	$12800, %edx                    # imm = 0x3200
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB8_14
# %bb.15:                               # %_Z9gpuAssert10hipError_tPKcib.exit22
	movq	d_flux_y(%rip), %rdi
	movl	$12800, %edx                    # imm = 0x3200
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	jne	.LBB8_16
# %bb.17:                               # %_Z9gpuAssert10hipError_tPKcib.exit24
	movq	d_max_velocity(%rip), %rdi
	movl	$h_max_velocity, %esi
	movl	$8, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB8_18
# %bb.19:                               # %_Z9gpuAssert10hipError_tPKcib.exit26
	movq	d_q(%rip), %rdi
	movl	$h_q, %esi
	movl	$12800, %edx                    # imm = 0x3200
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB8_20
# %bb.21:                               # %_Z9gpuAssert10hipError_tPKcib.exit28
	movabsq	$137438953504, %rbx             # imm = 0x2000000020
	movabsq	$4294967299, %r14               # imm = 0x100000003
	leaq	8(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r15), %rdi
	xorl	%r15d, %r15d
	xorl	%esi, %esi
	callq	hipEventRecord
.LBB8_22:                               # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_24
# %bb.23:                               #   in Loop: Header=BB8_22 Depth=1
	movq	d_q(%rip), %rdi
	movq	d_flux_x(%rip), %rsi
	movq	d_flux_y(%rip), %rdx
	movq	d_max_velocity(%rip), %rcx
	callq	_Z36__device_stub__reconstruction_kernelPKdPdS1_S0_
.LBB8_24:                               #   in Loop: Header=BB8_22 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB8_25
# %bb.27:                               # %_Z9gpuAssert10hipError_tPKcib.exit30
                                        #   in Loop: Header=BB8_22 Depth=1
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB8_29
# %bb.28:                               #   in Loop: Header=BB8_22 Depth=1
	movq	d_q(%rip), %rdi
	movq	d_flux_x(%rip), %rsi
	movq	d_flux_y(%rip), %rdx
	callq	_Z28__device_stub__update_kernelPdPKdS1_
.LBB8_29:                               #   in Loop: Header=BB8_22 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB8_30
# %bb.31:                               # %_Z9gpuAssert10hipError_tPKcib.exit32
                                        #   in Loop: Header=BB8_22 Depth=1
	movq	d_q(%rip), %rsi
	movl	$h_q, %edi
	movl	$12800, %edx                    # imm = 0x3200
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB8_32
# %bb.33:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
                                        #   in Loop: Header=BB8_22 Depth=1
	movq	d_flux_x(%rip), %rsi
	movl	$h_flux_x, %edi
	movl	$12800, %edx                    # imm = 0x3200
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB8_34
# %bb.35:                               # %_Z9gpuAssert10hipError_tPKcib.exit36
                                        #   in Loop: Header=BB8_22 Depth=1
	movq	d_flux_y(%rip), %rsi
	movl	$h_flux_y, %edi
	movl	$12800, %edx                    # imm = 0x3200
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB8_36
# %bb.37:                               # %_Z9gpuAssert10hipError_tPKcib.exit38
                                        #   in Loop: Header=BB8_22 Depth=1
	movl	%r15d, %eax
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	shrq	$37, %rcx
	imull	$100, %ecx, %ecx
	cmpl	%r15d, %ecx
	jne	.LBB8_39
# %bb.38:                               #   in Loop: Header=BB8_22 Depth=1
	imulq	$1374389535, %rax, %rdi         # imm = 0x51EB851F
	shrq	$37, %rdi
	incl	%edi
                                        # kill: def $edi killed $edi killed $rdi
	callq	_Z12printCSVFilei
.LBB8_39:                               #   in Loop: Header=BB8_22 Depth=1
	incl	%r15d
	cmpl	$100000, %r15d                  # imm = 0x186A0
	jne	.LBB8_22
# %bb.40:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	20(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipEventElapsedTime
	cvtss2sd	(%rbx), %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movq	d_flux_x(%rip), %rdi
	callq	hipFree
	movq	d_flux_y(%rip), %rdi
	callq	hipFree
	movq	d_q(%rip), %rdi
	callq	hipFree
	movq	d_max_velocity(%rip), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB8_36:
	.cfi_def_cfa_offset 64
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$226, %r8d
	jmp	.LBB8_26
.LBB8_34:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$225, %r8d
	jmp	.LBB8_26
.LBB8_32:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$224, %r8d
	jmp	.LBB8_26
.LBB8_30:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$221, %r8d
	jmp	.LBB8_26
.LBB8_25:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$219, %r8d
.LBB8_26:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebp, %edi
	callq	exit
.LBB8_5:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$200, %r8d
	jmp	.LBB8_6
.LBB8_8:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$201, %r8d
	jmp	.LBB8_6
.LBB8_10:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$202, %r8d
	jmp	.LBB8_6
.LBB8_12:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$203, %r8d
	jmp	.LBB8_6
.LBB8_14:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$205, %r8d
	jmp	.LBB8_6
.LBB8_16:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$206, %r8d
	jmp	.LBB8_6
.LBB8_18:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$207, %r8d
	jmp	.LBB8_6
.LBB8_20:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movl	$.L.str.10, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$208, %r8d
.LBB8_6:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end8:
	.size	main, .Lfunc_end8-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB9_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB9_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21reconstruction_kernelPKdPdS1_S0_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13update_kernelPdPKdS1_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end9:
	.size	__hip_module_ctor, .Lfunc_end9-__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	.LBB10_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
.LBB10_2:
	retq
.Lfunc_end10:
	.size	__hip_module_dtor, .Lfunc_end10-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	h_flux_x,@object                # @h_flux_x
	.bss
	.globl	h_flux_x
	.p2align	4, 0x0
h_flux_x:
	.zero	12800
	.size	h_flux_x, 12800

	.type	h_flux_y,@object                # @h_flux_y
	.globl	h_flux_y
	.p2align	4, 0x0
h_flux_y:
	.zero	12800
	.size	h_flux_y, 12800

	.type	h_q,@object                     # @h_q
	.globl	h_q
	.p2align	4, 0x0
h_q:
	.zero	12800
	.size	h_q, 12800

	.type	h_velocities,@object            # @h_velocities
	.globl	h_velocities
	.p2align	4, 0x0
h_velocities:
	.zero	16
	.size	h_velocities, 16

	.type	h_max_velocity,@object          # @h_max_velocity
	.globl	h_max_velocity
	.p2align	3, 0x0
h_max_velocity:
	.quad	0x0000000000000000              # double 0
	.size	h_max_velocity, 8

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

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

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

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"result-"
	.size	.L.str, 8

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	".csv"
	.size	.L.str.1, 5

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"x, y, z"
	.size	.L.str.2, 8

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	","
	.size	.L.str.3, 2

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\nTimestep %d \n"
	.size	.L.str.4, 15

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Q: "
	.size	.L.str.5, 4

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%f "
	.size	.L.str.7, 4

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Flux_X: "
	.size	.L.str.8, 9

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Flux_Y: "
	.size	.L.str.9, 9

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

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

	.type	.L.str.10,@object               # @.str.10
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.10:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/Jack-Clark/cuda-exahype/master/advection/cuda_advection.hip"
	.size	.L.str.10, 122

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Time for the program: %f ms\n"
	.size	.L.str.11, 29

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str.12, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21reconstruction_kernelPKdPdS1_S0_"
	.size	.L__unnamed_1, 37

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z13update_kernelPdPKdS1_"
	.size	.L__unnamed_2, 26

	.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 __gxx_personality_v0
	.addrsig_sym _Z36__device_stub__reconstruction_kernelPKdPdS1_S0_
	.addrsig_sym _Z28__device_stub__update_kernelPdPKdS1_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym h_flux_x
	.addrsig_sym h_flux_y
	.addrsig_sym h_q
	.addrsig_sym h_max_velocity
	.addrsig_sym d_flux_x
	.addrsig_sym d_flux_y
	.addrsig_sym d_q
	.addrsig_sym d_max_velocity
	.addrsig_sym _Z21reconstruction_kernelPKdPdS1_S0_
	.addrsig_sym _Z13update_kernelPdPKdS1_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21reconstruction_kernelPKdPdS1_S0_ ; -- Begin function _Z21reconstruction_kernelPKdPdS1_S0_
	.globl	_Z21reconstruction_kernelPKdPdS1_S0_
	.p2align	8
	.type	_Z21reconstruction_kernelPKdPdS1_S0_,@function
_Z21reconstruction_kernelPKdPdS1_S0_:   ; @_Z21reconstruction_kernelPKdPdS1_S0_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x2c
	v_bfe_u32 v2, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[0:1], null, s15, s3, v[2:3]
	v_mad_u64_u32 v[3:4], null, s14, s2, v[5:6]
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_i32_e32 v1, v0, v3
	v_cmpx_gt_i32_e32 40, v1
	s_cbranch_execz .LBB0_5
; %bb.1:
	s_load_b256 s[0:7], s[0:1], 0x0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, v0, 40, v[3:4]
	s_mov_b32 s8, exec_lo
	v_ashrrev_i32_e32 v2, 31, v1
	v_cmpx_ne_u32_e32 0, v3
	s_cbranch_execz .LBB0_3
; %bb.2:
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[7:8], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_load_b64 s[10:11], s[6:7], 0x0
	v_add_co_u32 v3, vcc_lo, s0, v7
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v8, vcc_lo
	global_load_b128 v[3:6], v[3:4], off offset:-8
	s_waitcnt lgkmcnt(0)
	v_mul_f64 v[9:10], s[10:11], 0.5
	s_waitcnt vmcnt(0)
	v_add_f64 v[11:12], v[5:6], -v[3:4]
	v_add_f64 v[3:4], v[5:6], v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[5:6], v[11:12], v[9:10]
	v_fma_f64 v[3:4], v[3:4], 0.5, -v[5:6]
	v_add_co_u32 v5, vcc_lo, s2, v7
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v8, vcc_lo
	global_store_b64 v[5:6], v[3:4], off
.LBB0_3:
	s_or_b32 exec_lo, exec_lo, s8
	v_cmp_ne_u32_e32 vcc_lo, 0, v0
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.4:
	v_lshlrev_b64 v[0:1], 3, v[1:2]
	v_mov_b32_e32 v4, 0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v2, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s4, v0
	global_load_b64 v[4:5], v4, s[6:7]
	s_clause 0x1
	global_load_b64 v[6:7], v[2:3], off
	global_load_b64 v[2:3], v[2:3], off offset:-320
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_waitcnt vmcnt(2)
	v_mul_f64 v[4:5], v[4:5], 0.5
	s_waitcnt vmcnt(0)
	v_add_f64 v[8:9], v[6:7], -v[2:3]
	v_add_f64 v[2:3], v[6:7], v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[4:5], v[8:9], v[4:5]
	v_fma_f64 v[2:3], v[2:3], 0.5, -v[4:5]
	global_store_b64 v[0:1], v[2:3], off
.LBB0_5:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21reconstruction_kernelPKdPdS1_S0_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 13
		.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	_Z21reconstruction_kernelPKdPdS1_S0_, .Lfunc_end0-_Z21reconstruction_kernelPKdPdS1_S0_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 392
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; Occupancy: 16
; WaveLimiterHint : 1
; 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
	.protected	_Z13update_kernelPdPKdS1_ ; -- Begin function _Z13update_kernelPdPKdS1_
	.globl	_Z13update_kernelPdPKdS1_
	.p2align	8
	.type	_Z13update_kernelPdPKdS1_,@function
_Z13update_kernelPdPKdS1_:              ; @_Z13update_kernelPdPKdS1_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x24
	v_bfe_u32 v2, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[0:1], null, s15, s3, v[2:3]
	v_mad_u64_u32 v[3:4], null, s14, s2, v[5:6]
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_i32_e32 v1, v0, v3
	v_cmpx_gt_i32_e32 40, v1
	s_cbranch_execz .LBB1_5
; %bb.1:
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, v0, 40, v[3:4]
	v_cmp_gt_i32_e32 vcc_lo, 0x5f1, v1
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_5
; %bb.2:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_mov_b32 s2, 0xd2f1a9fc
	s_mov_b32 s3, 0x3f50624d
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v4, vcc_lo
	global_load_b128 v[5:8], v[1:2], off
	v_add_co_u32 v1, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v4, vcc_lo
	s_mov_b32 s4, exec_lo
	global_load_b64 v[9:10], v[1:2], off
	s_waitcnt vmcnt(1)
	v_add_f64 v[5:6], v[5:6], -v[7:8]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_fma_f64 v[5:6], v[5:6], s[2:3], v[9:10]
	v_cmpx_gt_i32_e32 39, v0
	s_cbranch_execz .LBB1_4
; %bb.3:
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s0, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	s_clause 0x1
	global_load_b64 v[7:8], v[3:4], off
	global_load_b64 v[3:4], v[3:4], off offset:320
	s_waitcnt vmcnt(0)
	v_add_f64 v[3:4], v[7:8], -v[3:4]
	s_delay_alu instid0(VALU_DEP_1)
	v_fma_f64 v[5:6], v[3:4], s[2:3], v[5:6]
.LBB1_4:
	s_or_b32 exec_lo, exec_lo, s4
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_nge_f64_e32 vcc_lo, 0, v[5:6]
	v_dual_cndmask_b32 v4, 0, v6 :: v_dual_cndmask_b32 v3, 0, v5
	global_store_b64 v[1:2], v[3:4], off
.LBB1_5:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13update_kernelPdPKdS1_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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_end1:
	.size	_Z13update_kernelPdPKdS1_, .Lfunc_end1-_Z13update_kernelPdPKdS1_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; 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 : 1
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21reconstruction_kernelPKdPdS1_S0_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z21reconstruction_kernelPKdPdS1_S0_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13update_kernelPdPKdS1_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13update_kernelPdPKdS1_.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
