#include <cuda_runtime.h>
#include <device_launch_parameters.h>

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

#define X_SIZE 10240
#define Y_SIZE 16384

#define ARRAY_SIZE (X_SIZE*Y_SIZE)

#define BLOCK_SIZE_X 32
#define BLOCK_SIZE_Y 32

#define TIMESTEPS 1000

const char* input_file_name = "input.dat";
const char* output_file_name = "output.dat";

void prtdat(int nx, int ny, float *current, const char *fnam);
void inidat(int nx, int ny, float *u);

void printDevProp(cudaDeviceProp devProp)
{
	printf("Major revision number:         %d\n", devProp.major);
	printf("Minor revision number:         %d\n", devProp.minor);
	printf("Name:                          %s\n", devProp.name);
	printf("Total global memory:           %u or %uKB or %uMB\n", devProp.totalGlobalMem, devProp.totalGlobalMem/1024, devProp.totalGlobalMem / (1024*1024), devProp.totalGlobalMem / 1024 / 1024 / 1024);
	printf("Total shared memory per block: %u\n", devProp.sharedMemPerBlock);
	printf("Total registers per block:     %d\n", devProp.regsPerBlock);
	printf("Warp size:                     %d\n", devProp.warpSize);
	printf("Maximum memory pitch:          %u\n", devProp.memPitch);
	printf("Maximum threads per block:     %d\n", devProp.maxThreadsPerBlock);
	for (int i = 0; i < 3; ++i)
		printf("Maximum dimension %d of block:  %d\n", i, devProp.maxThreadsDim[i]);
	for (int i = 0; i < 3; ++i)
		printf("Maximum dimension %d of grid:   %d\n", i, devProp.maxGridSize[i]);
	printf("Clock rate:                    %d\n", devProp.clockRate);
	printf("Total constant memory:         %u\n", devProp.totalConstMem);
	printf("Texture alignment:             %u\n", devProp.textureAlignment);
	printf("Concurrent copy and execution: %s\n", (devProp.deviceOverlap ? "Yes" : "No"));
	printf("Number of multiprocessors:     %d\n", devProp.multiProcessorCount);
	printf("Kernel execution timeout:      %s\n", (devProp.kernelExecTimeoutEnabled ? "Yes" : "No"));
	return;
}

__global__ void kernelCalculateNewGenerationWithSharedMemory(float* current, float* next, int ny, int nx) {
	int ix = threadIdx.x + blockIdx.x * blockDim.x;
	int iy = threadIdx.y + blockIdx.y * blockDim.y;

	const float cx = 0.1;
	const float cy = 0.1;

	int me = ix + iy * nx,
		east = ix + 1 + iy * nx,
		west = ix - 1 + iy * nx,
		north = ix + (iy - 1) * nx,
		south = ix + (iy + 1) * nx;

	// INIT SHARED MEMORY
	__shared__ float dev_sharedMem[BLOCK_SIZE_Y][BLOCK_SIZE_X];
	dev_sharedMem[threadIdx.y][threadIdx.x] = current[me];

	__syncthreads();
	/* The point to update doesn't need an element that's "included" in this block */
	if ((threadIdx.x > 0) && (threadIdx.x < (BLOCK_SIZE_X - 1)) &&
		(threadIdx.y > 0) && (threadIdx.y < (BLOCK_SIZE_Y - 1))
		) {
		next[me] = cx * (dev_sharedMem[threadIdx.y][threadIdx.x-1] + dev_sharedMem[threadIdx.y][threadIdx.x+1] - 2.0f * dev_sharedMem[threadIdx.y][threadIdx.x]) +
			cy * (dev_sharedMem[threadIdx.y - 1][threadIdx.x] + dev_sharedMem[threadIdx.y + 1][threadIdx.x] - 2.0f * dev_sharedMem[threadIdx.y][threadIdx.x]) +
			dev_sharedMem[threadIdx.y][threadIdx.x];
	}
	else if (ix > 0 && ix < X_SIZE - 1 && iy > 0 && iy < Y_SIZE - 1) {
		next[me] =
			cx * (current[east] + current[west] - 2.0f * current[me]) +
			cy * (current[south] + current[north] - 2.0f * current[me]) +
			current[me];
	}
}

__global__ void kernelCalculateNewGeneration(float* current, float* next, int ny, int nx) {
	int ix = threadIdx.x + blockIdx.x * blockDim.x;
	int iy = threadIdx.y + blockIdx.y * blockDim.y;
	const float cx = 0.1;
	const float cy = 0.1;

	int me = ix + iy * nx,
		east = ix + 1 + iy * nx,
		west = ix - 1 + iy * nx,
		north = ix + (iy - 1) * nx,
		south = ix + (iy + 1) * nx;

	if (ix > 0 && ix < X_SIZE-1 && iy > 0 && iy < Y_SIZE-1) {
		next[me] =
			cx * (current[east] + current[west] - 2.0f * current[me]) +
			cy * (current[south] + current[north] - 2.0f * current[me]) +
			current[me];
	}
}

#define CEILDIV(a,b) (((a)+(b)-1)/(b))

#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 main() {
	float *dev_heatmap, *heatmap;
	float *dev_current_map, *dev_next_map;
	int iz;

	float duration = 0;
	cudaEvent_t startEvent, endEvent;

	gpuErrchk(cudaEventCreate(&startEvent));
	gpuErrchk(cudaEventCreate(&endEvent));

	heatmap = (float*)malloc(ARRAY_SIZE*sizeof(float));

	printf("Grid is %dx%d and block is %dx%d\n", CEILDIV(X_SIZE, BLOCK_SIZE_X), CEILDIV(Y_SIZE, BLOCK_SIZE_Y), BLOCK_SIZE_X, BLOCK_SIZE_Y);

	// KERNEL CALL PARAMETRES INIT
	dim3 blockDim(BLOCK_SIZE_X, BLOCK_SIZE_Y);
	dim3 gridDim(CEILDIV(X_SIZE, BLOCK_SIZE_X), CEILDIV(Y_SIZE, BLOCK_SIZE_Y));

	// CPU ARRAY INITIALIZATION
	inidat(X_SIZE, Y_SIZE, heatmap);
	prtdat(X_SIZE, Y_SIZE, heatmap, input_file_name);

	// GPU INIT
	gpuErrchk(cudaSetDevice(0));
	cudaDeviceProp prop;
	gpuErrchk(cudaGetDeviceProperties(&prop, 0));

	// Init timer to count the GPU processing time 
	// GPU processing time = Moving data from host to device + main loop (processing elements) + moving data from device to host
	cudaEventRecord(startEvent);
	// GPU MEMORY INIT
	gpuErrchk(cudaMalloc(&dev_heatmap, 2 * sizeof(float)*ARRAY_SIZE))
	gpuErrchk(cudaMemcpy(dev_heatmap, heatmap, sizeof(float)*ARRAY_SIZE, cudaMemcpyHostToDevice));
	memset(heatmap, '\0', sizeof(float)*ARRAY_SIZE);

	// PRE LOOP INITIALIZATIONS
	iz = 0;
	dev_current_map = dev_heatmap;
	dev_next_map = dev_heatmap + ARRAY_SIZE;

	// MAIN LOOP
	for (int t = 0 ; t < TIMESTEPS ; t++) {
		dev_current_map = dev_heatmap + ARRAY_SIZE * iz;
		dev_next_map = dev_heatmap + ARRAY_SIZE * (1 - iz);

		// KERNEL CALL
		//kernelCalculateNewGeneration<<<blockDim,gridDim>>>(dev_current_map,dev_next_map,Y_SIZE,X_SIZE);
		kernelCalculateNewGenerationWithSharedMemory<<<blockDim,gridDim >>>(dev_current_map, dev_next_map, Y_SIZE, X_SIZE);
		iz = 1 - iz;
	}

	gpuErrchk(cudaMemcpy(heatmap, dev_next_map, sizeof(float)*ARRAY_SIZE, cudaMemcpyDeviceToHost));
	gpuErrchk(cudaEventRecord(endEvent));
	cudaDeviceSynchronize();

	prtdat(X_SIZE, Y_SIZE, heatmap, output_file_name);
	gpuErrchk(cudaEventElapsedTime(&duration, startEvent, endEvent));
	printf("GPU elapsed time: %f\n", duration);

	return 0;
}

void inidat(int nx, int ny, float *u) {
	int ix, iy;

	for (ix = 0; ix <= nx - 1; ix++)
		for (iy = 0; iy <= ny - 1; iy++)
			*(u + ix + nx * iy) = (float)(ix * (nx - ix - 1) * iy * (ny - iy - 1));
}

void prtdat(int nx, int ny, float *current, const char *fnam) {
	int ix, iy;
	FILE *fp;

	fp = fopen(fnam, "w");
	for (iy = 0; iy < Y_SIZE; iy++) {
		for (ix = 0; ix < nx; ix++) {
			fprintf(fp, "%6.1f", *(current + ix + nx*iy));
			if (ix != nx - 1)
				fprintf(fp, " ");
			else
				fprintf(fp, "\n");
		}
	}
	fclose(fp);
}


/*for (int t = 0; t < TIMESTEPS; t++) {
		cudaError_t cudaStatus;
		dev_current_heatmap = dev_heatmap + iz * heatmap_size;
		dev_next_heatmap	= dev_heatmap + (1-iz) * heatmap_size;
		kernelCalculateNextIteration<<<dim3BlockSizes,dim3GridSizes>>>(dev_current_heatmap, dev_next_heatmap, Y_SIZE, X_SIZE, dev_someint);
		cudaStatus = cudaGetLastError();
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
		}
		printf("Iteration %d\n", t);
		iz = 1 - iz;
	}*/
	//cudaMemcpy(&someint, dev_someint, heatmap_size* sizeof(int), cudaMemcpyDeviceToHost);
	.file	"tmpxft_0027d360_00000000-6_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Yes"
.LC1:
	.string	"No"
.LC2:
	.string	"Major revision number:         %d\n"
.LC3:
	.string	"Minor revision number:         %d\n"
.LC4:
	.string	"Name:                          %s\n"
.LC5:
	.string	"Total global memory:           %u or %uKB or %uMB\n"
.LC6:
	.string	"Total shared memory per block: %u\n"
.LC7:
	.string	"Total registers per block:     %d\n"
.LC8:
	.string	"Warp size:                     %d\n"
.LC9:
	.string	"Maximum memory pitch:          %u\n"
.LC10:
	.string	"Maximum threads per block:     %d\n"
.LC11:
	.string	"Maximum dimension %d of block:  %d\n"
.LC12:
	.string	"Maximum dimension %d of grid:   %d\n"
.LC13:
	.string	"Clock rate:                    %d\n"
.LC14:
	.string	"Total constant memory:         %u\n"
.LC15:
	.string	"Texture alignment:             %u\n"
.LC16:
	.string	"Concurrent copy and execution: %s\n"
.LC17:
	.string	"Number of multiprocessors:     %d\n"
.LC18:
	.string	"Kernel execution timeout:      %s\n"
	.text
	.globl	_Z12printDevProp14cudaDeviceProp
	.type	_Z12printDevProp14cudaDeviceProp, @function
_Z12printDevProp14cudaDeviceProp:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	.LC11(%rip), %rbp
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 32
	movl	392(%rsp), %edx
	call	__printf_chk@PLT
	movl	396(%rsp), %edx
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdx
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	320(%rsp), %rdx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	movq	%rdx, %rcx
	movq	%rdx, %r9
	movq	%rdx, %r8
	shrq	$10, %rcx
	shrq	$30, %r9
	shrq	$20, %r8
	call	__printf_chk@PLT
	movq	328(%rsp), %rdx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	336(%rsp), %edx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	340(%rsp), %edx
	leaq	.LC8(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	344(%rsp), %rdx
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	352(%rsp), %edx
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
.L3:
	movl	356(%rsp,%rbx,4), %ecx
	movl	%ebx, %edx
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$3, %rbx
	jne	.L3
	xorl	%ebx, %ebx
	leaq	.LC12(%rip), %rbp
.L4:
	movl	368(%rsp,%rbx,4), %ecx
	movl	%ebx, %edx
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$3, %rbx
	jne	.L4
	movl	380(%rsp), %edx
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rbp
	leaq	.LC1(%rip), %rbx
	call	__printf_chk@PLT
	movq	384(%rsp), %rdx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	400(%rsp), %rdx
	leaq	.LC15(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpl	$0, 416(%rsp)
	movq	%rbp, %rdx
	leaq	.LC16(%rip), %rsi
	cmove	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	420(%rsp), %edx
	leaq	.LC17(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	cmpl	$0, 424(%rsp)
	movq	%rbp, %rdx
	leaq	.LC18(%rip), %rsi
	cmove	%rbx, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12printDevProp14cudaDeviceProp, .-_Z12printDevProp14cudaDeviceProp
	.section	.rodata._Z9gpuAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC19:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z9gpuAssert9cudaErrorPKcib,"axG",@progbits,_Z9gpuAssert9cudaErrorPKcib,comdat
	.weak	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB2028:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L19
	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	.LC19(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L13
	movl	%ebx, %edi
	call	exit@PLT
.L13:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L19:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.text
	.globl	_Z6inidatiiPf
	.type	_Z6inidatiiPf, @function
_Z6inidatiiPf:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movslq	%edi, %r11
	movq	%rdx, %r9
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r11, %rcx
	leal	-1(%rsi), %r12d
	salq	$2, %r11
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leal	-1(%rcx), %ebp
.L23:
	cmpl	%eax, %ecx
	jle	.L22
	movl	%ebp, %r10d
	leaq	(%r9,%rax,4), %r8
	xorl	%edi, %edi
	xorl	%edx, %edx
	subl	%eax, %r10d
	imull	%eax, %r10d
.L26:
	cmpl	%esi, %edx
	jge	.L28
	movl	%r12d, %ebx
	subl	%edx, %ebx
	incl	%edx
	imull	%edi, %ebx
	addl	%r10d, %edi
	cvtsi2ssl	%ebx, %xmm0
	movss	%xmm0, (%r8)
	addq	%r11, %r8
	jmp	.L26
.L28:
	incq	%rax
	jmp	.L23
.L22:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z6inidatiiPf, .-_Z6inidatiiPf
	.section	.rodata.str1.1
.LC20:
	.string	"w"
.LC21:
	.string	"%6.1f"
.LC22:
	.string	" "
.LC23:
	.string	"\n"
	.text
	.globl	_Z6prtdatiiPfPKc
	.type	_Z6prtdatiiPfPKc, @function
_Z6prtdatiiPfPKc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC20(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	$16384, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	movq	%rcx, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	fopen@PLT
	movq	%rax, 8(%rsp)
.L30:
	movslq	%r13d, %rax
	xorl	%ebx, %ebx
	leaq	(%r12,%rax,4), %r15
.L35:
	cmpl	%ebx, %ebp
	jle	.L38
	movq	8(%rsp), %rdi
	leaq	.LC21(%rip), %rdx
	movl	$2, %esi
	movb	$1, %al
	cvtss2sd	(%r15,%rbx,4), %xmm0
	call	__fprintf_chk@PLT
	leal	-1(%rbp), %eax
	leaq	.LC22(%rip), %rdx
	cmpl	%ebx, %eax
	jne	.L37
	leaq	.LC23(%rip), %rdx
.L37:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	incq	%rbx
	call	__fprintf_chk@PLT
	jmp	.L35
.L38:
	addl	%ebp, %r13d
	decl	%r14d
	jne	.L30
	movq	8(%rsp), %rdi
	addq	$24, %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
	jmp	fclose@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z6prtdatiiPfPKc, .-_Z6prtdatiiPfPKc
	.globl	_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii
	.type	_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii, @function
_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii:
.LFB2056:
	.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
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%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	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%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	.L39
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii(%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
.L39:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii, .-_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii
	.globl	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.type	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii, @function
_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii
	.cfi_endproc
.LFE2057:
	.size	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii, .-_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.section	.rodata.str1.1
.LC25:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/chrissamouchos/2d-heat-parallel-decomp/master/CUDA/kernel.cu"
.LC26:
	.string	"Grid is %dx%d and block is %dx%d\n"
.LC27:
	.string	"GPU elapsed time: %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	$1000, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$1112, %rsp
	.cfi_def_cfa_offset 1168
	movq	%fs:40, %rax
	movq	%rax, 1096(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rdi
	movl	$0x00000000, 12(%rsp)
	call	cudaEventCreate@PLT
	movl	$1, %ecx
	movl	$123, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$1, %ecx
	movl	$124, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$671088640, %edi
	call	malloc@PLT
	movl	$32, %r9d
	movl	$32, %r8d
	movl	$512, %ecx
	movq	%rax, %rbp
	movl	$320, %edx
	leaq	.LC26(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$16384, %esi
	movq	%rbp, %rdx
	movabsq	$137438953504, %rax
	movq	%rax, 40(%rsp)
	movl	$10240, %edi
	movabsq	$2199023255872, %rax
	movq	%rax, 52(%rsp)
	movl	$1, 48(%rsp)
	movl	$1, 60(%rsp)
	call	_Z6inidatiiPf
	movq	input_file_name(%rip), %rcx
	movq	%rbp, %rdx
	movl	$10240, %edi
	call	_Z6prtdatiiPfPKc
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	$1, %ecx
	movl	$139, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	$1, %ecx
	movl	$141, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	leaq	16(%rsp), %rdi
	movl	$1342177280, %esi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$147, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$671088640, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$148, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$167772160, %ecx
	xorl	%eax, %eax
	movq	%rbp, %rdi
	rep stosl
.L46:
	movl	%r13d, %r12d
	xorl	$1, %r13d
	movq	16(%rsp), %rbx
	movl	60(%rsp), %ecx
	movl	%r13d, %eax
	movq	52(%rsp), %rdx
	movq	40(%rsp), %rdi
	xorl	%r9d, %r9d
	negl	%eax
	movl	48(%rsp), %esi
	xorl	%r8d, %r8d
	andl	$167772160, %eax
	leaq	(%rbx,%rax,4), %r15
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L45
	imull	$167772160, %r12d, %r12d
	movl	$10240, %ecx
	movl	$16384, %edx
	movq	%r15, %rsi
	movslq	%r12d, %r12
	leaq	(%rbx,%r12,4), %rdi
	call	_Z68__device_stub__Z44kernelCalculateNewGenerationWithSharedMemoryPfS_iiPfS_ii
.L45:
	decl	%r14d
	jne	.L46
	movl	$2, %ecx
	movl	$671088640, %edx
	movq	%r15, %rsi
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$167, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$1, %ecx
	movl	$168, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	call	cudaDeviceSynchronize@PLT
	movq	output_file_name(%rip), %rcx
	movq	%rbp, %rdx
	movl	$16384, %esi
	movl	$10240, %edi
	call	_Z6prtdatiiPfPKc
	movq	32(%rsp), %rdx
	movq	24(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	$1, %ecx
	movl	$172, %edx
	leaq	.LC25(%rip), %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	.LC27(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	1096(%rsp), %rax
	subq	%fs:40, %rax
	je	.L47
	call	__stack_chk_fail@PLT
.L47:
	addq	$1112, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE2029:
	.size	main, .-main
	.text
	.globl	_Z52__device_stub__Z28kernelCalculateNewGenerationPfS_iiPfS_ii
	.type	_Z52__device_stub__Z28kernelCalculateNewGenerationPfS_iiPfS_ii, @function
_Z52__device_stub__Z28kernelCalculateNewGenerationPfS_iiPfS_ii:
.LFB2058:
	.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
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%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	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%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	.L50
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z28kernelCalculateNewGenerationPfS_ii(%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
.L50:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z52__device_stub__Z28kernelCalculateNewGenerationPfS_iiPfS_ii, .-_Z52__device_stub__Z28kernelCalculateNewGenerationPfS_iiPfS_ii
	.globl	_Z28kernelCalculateNewGenerationPfS_ii
	.type	_Z28kernelCalculateNewGenerationPfS_ii, @function
_Z28kernelCalculateNewGenerationPfS_ii:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z52__device_stub__Z28kernelCalculateNewGenerationPfS_iiPfS_ii
	.cfi_endproc
.LFE2059:
	.size	_Z28kernelCalculateNewGenerationPfS_ii, .-_Z28kernelCalculateNewGenerationPfS_ii
	.section	.rodata.str1.1
.LC28:
	.string	"_Z28kernelCalculateNewGenerationPfS_ii"
.LC29:
	.string	"_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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	.LC28(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z28kernelCalculateNewGenerationPfS_ii(%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	.LC29(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii(%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
.LFE2061:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	output_file_name
	.section	.rodata.str1.1
.LC30:
	.string	"output.dat"
	.section	.data.rel.local,"aw"
	.align 8
	.type	output_file_name, @object
	.size	output_file_name, 8
output_file_name:
	.quad	.LC30
	.globl	input_file_name
	.section	.rodata.str1.1
.LC31:
	.string	"input.dat"
	.section	.data.rel.local
	.align 8
	.type	input_file_name, @object
	.size	input_file_name, 8
input_file_name:
	.quad	.LC31
	.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 <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define X_SIZE 10240
#define Y_SIZE 16384

#define ARRAY_SIZE (X_SIZE*Y_SIZE)

#define BLOCK_SIZE_X 32
#define BLOCK_SIZE_Y 32

#define TIMESTEPS 1000

const char* input_file_name = "input.dat";
const char* output_file_name = "output.dat";

void prtdat(int nx, int ny, float *current, const char *fnam);
void inidat(int nx, int ny, float *u);

void printDevProp(hipDeviceProp_t devProp)
{
	printf("Major revision number:         %d\n", devProp.major);
	printf("Minor revision number:         %d\n", devProp.minor);
	printf("Name:                          %s\n", devProp.name);
	printf("Total global memory:           %u or %uKB or %uMB\n", devProp.totalGlobalMem, devProp.totalGlobalMem/1024, devProp.totalGlobalMem / (1024*1024), devProp.totalGlobalMem / 1024 / 1024 / 1024);
	printf("Total shared memory per block: %u\n", devProp.sharedMemPerBlock);
	printf("Total registers per block:     %d\n", devProp.regsPerBlock);
	printf("Warp size:                     %d\n", devProp.warpSize);
	printf("Maximum memory pitch:          %u\n", devProp.memPitch);
	printf("Maximum threads per block:     %d\n", devProp.maxThreadsPerBlock);
	for (int i = 0; i < 3; ++i)
		printf("Maximum dimension %d of block:  %d\n", i, devProp.maxThreadsDim[i]);
	for (int i = 0; i < 3; ++i)
		printf("Maximum dimension %d of grid:   %d\n", i, devProp.maxGridSize[i]);
	printf("Clock rate:                    %d\n", devProp.clockRate);
	printf("Total constant memory:         %u\n", devProp.totalConstMem);
	printf("Texture alignment:             %u\n", devProp.textureAlignment);
	printf("Concurrent copy and execution: %s\n", (devProp.deviceOverlap ? "Yes" : "No"));
	printf("Number of multiprocessors:     %d\n", devProp.multiProcessorCount);
	printf("Kernel execution timeout:      %s\n", (devProp.kernelExecTimeoutEnabled ? "Yes" : "No"));
	return;
}

__global__ void kernelCalculateNewGenerationWithSharedMemory(float* current, float* next, int ny, int nx) {
	int ix = threadIdx.x + blockIdx.x * blockDim.x;
	int iy = threadIdx.y + blockIdx.y * blockDim.y;

	const float cx = 0.1;
	const float cy = 0.1;

	int me = ix + iy * nx,
		east = ix + 1 + iy * nx,
		west = ix - 1 + iy * nx,
		north = ix + (iy - 1) * nx,
		south = ix + (iy + 1) * nx;

	// INIT SHARED MEMORY
	__shared__ float dev_sharedMem[BLOCK_SIZE_Y][BLOCK_SIZE_X];
	dev_sharedMem[threadIdx.y][threadIdx.x] = current[me];

	__syncthreads();
	/* The point to update doesn't need an element that's "included" in this block */
	if ((threadIdx.x > 0) && (threadIdx.x < (BLOCK_SIZE_X - 1)) &&
		(threadIdx.y > 0) && (threadIdx.y < (BLOCK_SIZE_Y - 1))
		) {
		next[me] = cx * (dev_sharedMem[threadIdx.y][threadIdx.x-1] + dev_sharedMem[threadIdx.y][threadIdx.x+1] - 2.0f * dev_sharedMem[threadIdx.y][threadIdx.x]) +
			cy * (dev_sharedMem[threadIdx.y - 1][threadIdx.x] + dev_sharedMem[threadIdx.y + 1][threadIdx.x] - 2.0f * dev_sharedMem[threadIdx.y][threadIdx.x]) +
			dev_sharedMem[threadIdx.y][threadIdx.x];
	}
	else if (ix > 0 && ix < X_SIZE - 1 && iy > 0 && iy < Y_SIZE - 1) {
		next[me] =
			cx * (current[east] + current[west] - 2.0f * current[me]) +
			cy * (current[south] + current[north] - 2.0f * current[me]) +
			current[me];
	}
}

__global__ void kernelCalculateNewGeneration(float* current, float* next, int ny, int nx) {
	int ix = threadIdx.x + blockIdx.x * blockDim.x;
	int iy = threadIdx.y + blockIdx.y * blockDim.y;
	const float cx = 0.1;
	const float cy = 0.1;

	int me = ix + iy * nx,
		east = ix + 1 + iy * nx,
		west = ix - 1 + iy * nx,
		north = ix + (iy - 1) * nx,
		south = ix + (iy + 1) * nx;

	if (ix > 0 && ix < X_SIZE-1 && iy > 0 && iy < Y_SIZE-1) {
		next[me] =
			cx * (current[east] + current[west] - 2.0f * current[me]) +
			cy * (current[south] + current[north] - 2.0f * current[me]) +
			current[me];
	}
}

#define CEILDIV(a,b) (((a)+(b)-1)/(b))

#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 main() {
	float *dev_heatmap, *heatmap;
	float *dev_current_map, *dev_next_map;
	int iz;

	float duration = 0;
	hipEvent_t startEvent, endEvent;

	gpuErrchk(hipEventCreate(&startEvent));
	gpuErrchk(hipEventCreate(&endEvent));

	heatmap = (float*)malloc(ARRAY_SIZE*sizeof(float));

	printf("Grid is %dx%d and block is %dx%d\n", CEILDIV(X_SIZE, BLOCK_SIZE_X), CEILDIV(Y_SIZE, BLOCK_SIZE_Y), BLOCK_SIZE_X, BLOCK_SIZE_Y);

	// KERNEL CALL PARAMETRES INIT
	dim3 blockDim(BLOCK_SIZE_X, BLOCK_SIZE_Y);
	dim3 gridDim(CEILDIV(X_SIZE, BLOCK_SIZE_X), CEILDIV(Y_SIZE, BLOCK_SIZE_Y));

	// CPU ARRAY INITIALIZATION
	inidat(X_SIZE, Y_SIZE, heatmap);
	prtdat(X_SIZE, Y_SIZE, heatmap, input_file_name);

	// GPU INIT
	gpuErrchk(hipSetDevice(0));
	hipDeviceProp_t prop;
	gpuErrchk(hipGetDeviceProperties(&prop, 0));

	// Init timer to count the GPU processing time 
	// GPU processing time = Moving data from host to device + main loop (processing elements) + moving data from device to host
	hipEventRecord(startEvent);
	// GPU MEMORY INIT
	gpuErrchk(hipMalloc(&dev_heatmap, 2 * sizeof(float)*ARRAY_SIZE))
	gpuErrchk(hipMemcpy(dev_heatmap, heatmap, sizeof(float)*ARRAY_SIZE, hipMemcpyHostToDevice));
	memset(heatmap, '\0', sizeof(float)*ARRAY_SIZE);

	// PRE LOOP INITIALIZATIONS
	iz = 0;
	dev_current_map = dev_heatmap;
	dev_next_map = dev_heatmap + ARRAY_SIZE;

	// MAIN LOOP
	for (int t = 0 ; t < TIMESTEPS ; t++) {
		dev_current_map = dev_heatmap + ARRAY_SIZE * iz;
		dev_next_map = dev_heatmap + ARRAY_SIZE * (1 - iz);

		// KERNEL CALL
		//kernelCalculateNewGeneration<<<blockDim,gridDim>>>(dev_current_map,dev_next_map,Y_SIZE,X_SIZE);
		kernelCalculateNewGenerationWithSharedMemory<<<blockDim,gridDim >>>(dev_current_map, dev_next_map, Y_SIZE, X_SIZE);
		iz = 1 - iz;
	}

	gpuErrchk(hipMemcpy(heatmap, dev_next_map, sizeof(float)*ARRAY_SIZE, hipMemcpyDeviceToHost));
	gpuErrchk(hipEventRecord(endEvent));
	hipDeviceSynchronize();

	prtdat(X_SIZE, Y_SIZE, heatmap, output_file_name);
	gpuErrchk(hipEventElapsedTime(&duration, startEvent, endEvent));
	printf("GPU elapsed time: %f\n", duration);

	return 0;
}

void inidat(int nx, int ny, float *u) {
	int ix, iy;

	for (ix = 0; ix <= nx - 1; ix++)
		for (iy = 0; iy <= ny - 1; iy++)
			*(u + ix + nx * iy) = (float)(ix * (nx - ix - 1) * iy * (ny - iy - 1));
}

void prtdat(int nx, int ny, float *current, const char *fnam) {
	int ix, iy;
	FILE *fp;

	fp = fopen(fnam, "w");
	for (iy = 0; iy < Y_SIZE; iy++) {
		for (ix = 0; ix < nx; ix++) {
			fprintf(fp, "%6.1f", *(current + ix + nx*iy));
			if (ix != nx - 1)
				fprintf(fp, " ");
			else
				fprintf(fp, "\n");
		}
	}
	fclose(fp);
}


/*for (int t = 0; t < TIMESTEPS; t++) {
		cudaError_t cudaStatus;
		dev_current_heatmap = dev_heatmap + iz * heatmap_size;
		dev_next_heatmap	= dev_heatmap + (1-iz) * heatmap_size;
		kernelCalculateNextIteration<<<dim3BlockSizes,dim3GridSizes>>>(dev_current_heatmap, dev_next_heatmap, Y_SIZE, X_SIZE, dev_someint);
		cudaStatus = cudaGetLastError();
		if (cudaStatus != cudaSuccess) {
			fprintf(stderr, "addKernel launch failed: %s\n", cudaGetErrorString(cudaStatus));
		}
		printf("Iteration %d\n", t);
		iz = 1 - iz;
	}*/
	//cudaMemcpy(&someint, dev_someint, heatmap_size* sizeof(int), cudaMemcpyDeviceToHost);
	.text
	.file	"kernel.hip"
	.globl	_Z12printDevProp20hipDeviceProp_tR0600 # -- Begin function _Z12printDevProp20hipDeviceProp_tR0600
	.type	_Z12printDevProp20hipDeviceProp_tR0600,@function
_Z12printDevProp20hipDeviceProp_tR0600: # @_Z12printDevProp20hipDeviceProp_tR0600
	.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
	leaq	32(%rsp), %rbx
	movl	360(%rbx), %esi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	movl	364(%rbx), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.4, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	288(%rbx), %rsi
	movq	%rsi, %rdx
	shrq	$10, %rdx
	movq	%rsi, %rcx
	shrq	$20, %rcx
	movq	%rsi, %r8
	shrq	$30, %r8
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movq	296(%rbx), %rsi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	304(%rbx), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	movl	308(%rbx), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movq	312(%rbx), %rsi
	movl	$.L.str.9, %edi
	xorl	%eax, %eax
	callq	printf
	movl	320(%rbx), %esi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%r14d, %r14d
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movl	324(%rbx,%r14,4), %edx
	movl	$.L.str.11, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r14
	cmpq	$3, %r14
	jne	.LBB0_1
# %bb.2:                                # %.preheader.preheader
	xorl	%r14d, %r14d
.LBB0_3:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	336(%rbx,%r14,4), %edx
	movl	$.L.str.12, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r14
	cmpq	$3, %r14
	jne	.LBB0_3
# %bb.4:
	movl	348(%rbx), %esi
	movl	$.L.str.13, %edi
	xorl	%eax, %eax
	callq	printf
	movq	352(%rbx), %rsi
	movl	$.L.str.14, %edi
	xorl	%eax, %eax
	callq	printf
	movq	368(%rbx), %rsi
	movl	$.L.str.15, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 384(%rbx)
	movl	$.L.str.18, %r15d
	movl	$.L.str.17, %r14d
	movl	$.L.str.17, %esi
	cmoveq	%r15, %rsi
	movl	$.L.str.16, %edi
	xorl	%eax, %eax
	callq	printf
	movl	388(%rbx), %esi
	movl	$.L.str.19, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, 392(%rbx)
	cmoveq	%r15, %r14
	movl	$.L.str.20, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z12printDevProp20hipDeviceProp_tR0600, .Lfunc_end0-_Z12printDevProp20hipDeviceProp_tR0600
	.cfi_endproc
                                        # -- End function
	.globl	_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii # -- Begin function _Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.type	_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii,@function
_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii: # @_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.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	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii, %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_end1:
	.size	_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii, .Lfunc_end1-_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z43__device_stub__kernelCalculateNewGenerationPfS_ii # -- Begin function _Z43__device_stub__kernelCalculateNewGenerationPfS_ii
	.type	_Z43__device_stub__kernelCalculateNewGenerationPfS_ii,@function
_Z43__device_stub__kernelCalculateNewGenerationPfS_ii: # @_Z43__device_stub__kernelCalculateNewGenerationPfS_ii
	.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	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z28kernelCalculateNewGenerationPfS_ii, %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_end2:
	.size	_Z43__device_stub__kernelCalculateNewGenerationPfS_ii, .Lfunc_end2-_Z43__device_stub__kernelCalculateNewGenerationPfS_ii
	.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	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$1512, %rsp                     # imm = 0x5E8
	.cfi_def_cfa_offset 1568
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$0, 4(%rsp)
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_1
# %bb.3:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB3_4
# %bb.5:                                # %_Z9gpuAssert10hipError_tPKcib.exit22
	movl	$671088640, %edi                # imm = 0x28000000
	callq	malloc
	movq	%rax, %rbx
	xorl	%r14d, %r14d
	movl	$.L.str.22, %edi
	movl	$320, %esi                      # imm = 0x140
	movl	$512, %edx                      # imm = 0x200
	movl	$32, %ecx
	movl	$32, %r8d
	xorl	%eax, %eax
	callq	printf
	movl	$10238, %eax                    # imm = 0x27FE
	movq	%rbx, %rcx
	xorl	%edx, %edx
.LBB3_6:                                # %.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_7 Depth 2
	movl	$16383, %esi                    # imm = 0x3FFF
	xorl	%edi, %edi
	xorl	%r8d, %r8d
.LBB3_7:                                #   Parent Loop BB3_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%esi, %r9d
	imull	%edi, %r9d
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r9d, %xmm0
	movss	%xmm0, (%rcx,%r8)
	addq	$40960, %r8                     # imm = 0xA000
	decl	%esi
	addl	%r14d, %edi
	cmpq	$671088640, %r8                 # imm = 0x28000000
	jne	.LBB3_7
# %bb.8:                                # %._crit_edge.i
                                        #   in Loop: Header=BB3_6 Depth=1
	incq	%rdx
	addq	$4, %rcx
	addl	%eax, %r14d
	addl	$-2, %eax
	cmpq	$10240, %rdx                    # imm = 0x2800
	jne	.LBB3_6
# %bb.9:                                # %_Z6inidatiiPf.exit
	movq	input_file_name(%rip), %rcx
	movl	$10240, %edi                    # imm = 0x2800
	movq	%rbx, %rdx
	callq	_Z6prtdatiiPfPKc
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.12:                               # %_Z9gpuAssert10hipError_tPKcib.exit24
	leaq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipGetDevicePropertiesR0600
	testl	%eax, %eax
	jne	.LBB3_13
# %bb.14:                               # %_Z9gpuAssert10hipError_tPKcib.exit26
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	24(%rsp), %rdi
	movl	$1342177280, %esi               # imm = 0x50000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB3_15
# %bb.16:                               # %_Z9gpuAssert10hipError_tPKcib.exit28
	movq	24(%rsp), %rdi
	movl	$671088640, %edx                # imm = 0x28000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_17
# %bb.25:                               # %_Z9gpuAssert10hipError_tPKcib.exit30
	xorl	%r13d, %r13d
	movl	$671088640, %edx                # imm = 0x28000000
	movq	%rbx, 32(%rsp)                  # 8-byte Spill
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$1000, %ebp                     # imm = 0x3E8
	movabsq	$2199023255872, %r15            # imm = 0x20000000140
.LBB3_26:                               # =>This Inner Loop Header: Depth=1
	movq	24(%rsp), %r14
	movl	$1, %ebx
	subl	%r13d, %ebx
	movl	%ebx, %eax
	shll	$25, %eax
	leal	(%rax,%rax,4), %eax
	leaq	(%r14,%rax,4), %r12
	movabsq	$137438953504, %rdi             # imm = 0x2000000020
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_28
# %bb.27:                               #   in Loop: Header=BB3_26 Depth=1
	shll	$25, %r13d
	leal	(%r13,%r13,4), %eax
	leaq	(%r14,%rax,4), %rdi
	movq	%r12, %rsi
	movl	$16384, %edx                    # imm = 0x4000
	movl	$10240, %ecx                    # imm = 0x2800
	callq	_Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii
.LBB3_28:                               #   in Loop: Header=BB3_26 Depth=1
	movl	%ebx, %r13d
	decl	%ebp
	jne	.LBB3_26
# %bb.18:
	movl	$671088640, %edx                # imm = 0x28000000
	movq	32(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r12, %rsi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB3_19
# %bb.20:                               # %_Z9gpuAssert10hipError_tPKcib.exit32
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB3_21
# %bb.22:                               # %_Z9gpuAssert10hipError_tPKcib.exit34
	callq	hipDeviceSynchronize
	movq	output_file_name(%rip), %rcx
	movl	$10240, %edi                    # imm = 0x2800
	movq	%rbx, %rdx
	callq	_Z6prtdatiiPfPKc
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	4(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB3_23
# %bb.24:                               # %_Z9gpuAssert10hipError_tPKcib.exit36
	cvtss2sd	4(%rsp), %xmm0
	movl	$.L.str.23, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$1512, %rsp                     # imm = 0x5E8
	.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
.LBB3_1:
	.cfi_def_cfa_offset 1568
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$123, %r8d
	jmp	.LBB3_2
.LBB3_4:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$124, %r8d
	jmp	.LBB3_2
.LBB3_10:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$139, %r8d
	jmp	.LBB3_11
.LBB3_13:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$141, %r8d
	jmp	.LBB3_11
.LBB3_15:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$147, %r8d
	jmp	.LBB3_11
.LBB3_17:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$148, %r8d
	jmp	.LBB3_11
.LBB3_19:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$167, %r8d
	jmp	.LBB3_11
.LBB3_21:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$168, %r8d
.LBB3_11:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebp, %edi
	callq	exit
.LBB3_23:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.28, %esi
	movl	$.L.str.21, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$172, %r8d
.LBB3_2:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z6inidatiiPf                   # -- Begin function _Z6inidatiiPf
	.type	_Z6inidatiiPf,@function
_Z6inidatiiPf:                          # @_Z6inidatiiPf
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jle	.LBB4_7
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbp
	.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 %rbp, -16
	movl	%edi, %eax
	movl	%esi, %ecx
	leaq	(,%rax,4), %r8
	addl	$-2, %edi
	xorl	%r9d, %r9d
	xorl	%r10d, %r10d
.LBB4_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_4 Depth 2
	testl	%esi, %esi
	jle	.LBB4_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB4_2 Depth=1
	xorl	%r11d, %r11d
	movq	%rcx, %rbx
	movq	%rdx, %r14
.LBB4_4:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	decq	%rbx
	movl	%ebx, %ebp
	imull	%r11d, %ebp
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebp, %xmm0
	movss	%xmm0, (%r14)
	addq	%r8, %r14
	addl	%r9d, %r11d
	testq	%rbx, %rbx
	jne	.LBB4_4
.LBB4_5:                                # %._crit_edge
                                        #   in Loop: Header=BB4_2 Depth=1
	incq	%r10
	addq	$4, %rdx
	addl	%edi, %r9d
	addl	$-2, %edi
	cmpq	%rax, %r10
	jne	.LBB4_2
# %bb.6:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %rbp
.LBB4_7:                                # %._crit_edge21
	retq
.Lfunc_end4:
	.size	_Z6inidatiiPf, .Lfunc_end4-_Z6inidatiiPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z6prtdatiiPfPKc                # -- Begin function _Z6prtdatiiPfPKc
	.type	_Z6prtdatiiPfPKc,@function
_Z6prtdatiiPfPKc:                       # @_Z6prtdatiiPfPKc
	.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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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	%rdx, %rbx
	movl	%edi, %r14d
	movl	$.L.str.24, %esi
	movq	%rcx, %rdi
	callq	fopen
	movq	%rax, %r15
	leal	-1(%r14), %r12d
	movq	%r14, 8(%rsp)                   # 8-byte Spill
	movslq	%r14d, %rax
	movl	%eax, %ebp
	shlq	$2, %rax
	movq	%rax, (%rsp)                    # 8-byte Spill
	xorl	%eax, %eax
	movl	$10, %r13d
.LBB5_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_3 Depth 2
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	cmpl	$0, 8(%rsp)                     # 4-byte Folded Reload
	jle	.LBB5_4
# %bb.2:                                # %.lr.ph
                                        #   in Loop: Header=BB5_1 Depth=1
	xorl	%r14d, %r14d
.LBB5_3:                                #   Parent Loop BB5_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r14,4), %xmm0
	movl	$.L.str.25, %esi
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	cmpq	%r14, %r12
	movl	$32, %edi
	cmovel	%r13d, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	incq	%r14
	cmpq	%r14, %rbp
	jne	.LBB5_3
.LBB5_4:                                # %._crit_edge
                                        #   in Loop: Header=BB5_1 Depth=1
	movq	16(%rsp), %rax                  # 8-byte Reload
	incq	%rax
	addq	(%rsp), %rbx                    # 8-byte Folded Reload
	cmpq	$16384, %rax                    # imm = 0x4000
	jne	.LBB5_1
# %bb.5:
	movq	%r15, %rdi
	addq	$24, %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
	jmp	fclose                          # TAILCALL
.Lfunc_end5:
	.size	_Z6prtdatiiPfPKc, .Lfunc_end5-_Z6prtdatiiPfPKc
	.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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii, %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	$_Z28kernelCalculateNewGenerationPfS_ii, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"input.dat"
	.size	.L.str, 10

	.type	input_file_name,@object         # @input_file_name
	.data
	.globl	input_file_name
	.p2align	3, 0x0
input_file_name:
	.quad	.L.str
	.size	input_file_name, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"output.dat"
	.size	.L.str.1, 11

	.type	output_file_name,@object        # @output_file_name
	.data
	.globl	output_file_name
	.p2align	3, 0x0
output_file_name:
	.quad	.L.str.1
	.size	output_file_name, 8

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"Major revision number:         %d\n"
	.size	.L.str.2, 35

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Minor revision number:         %d\n"
	.size	.L.str.3, 35

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Name:                          %s\n"
	.size	.L.str.4, 35

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Total global memory:           %u or %uKB or %uMB\n"
	.size	.L.str.5, 51

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Total shared memory per block: %u\n"
	.size	.L.str.6, 35

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Total registers per block:     %d\n"
	.size	.L.str.7, 35

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Warp size:                     %d\n"
	.size	.L.str.8, 35

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Maximum memory pitch:          %u\n"
	.size	.L.str.9, 35

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Maximum threads per block:     %d\n"
	.size	.L.str.10, 35

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Maximum dimension %d of block:  %d\n"
	.size	.L.str.11, 36

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Maximum dimension %d of grid:   %d\n"
	.size	.L.str.12, 36

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Clock rate:                    %d\n"
	.size	.L.str.13, 35

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Total constant memory:         %u\n"
	.size	.L.str.14, 35

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Texture alignment:             %u\n"
	.size	.L.str.15, 35

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Concurrent copy and execution: %s\n"
	.size	.L.str.16, 35

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Yes"
	.size	.L.str.17, 4

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

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"Number of multiprocessors:     %d\n"
	.size	.L.str.19, 35

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"Kernel execution timeout:      %s\n"
	.size	.L.str.20, 35

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

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

	.type	.L.str.21,@object               # @.str.21
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.21:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/chrissamouchos/2d-heat-parallel-decomp/master/CUDA/kernel.hip"
	.size	.L.str.21, 124

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"Grid is %dx%d and block is %dx%d\n"
	.size	.L.str.22, 34

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"GPU elapsed time: %f\n"
	.size	.L.str.23, 22

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

	.type	.L.str.25,@object               # @.str.25
.L.str.25:
	.asciz	"%6.1f"
	.size	.L.str.25, 6

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii"
	.size	.L__unnamed_1, 55

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z28kernelCalculateNewGenerationPfS_ii"
	.size	.L__unnamed_2, 39

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z59__device_stub__kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.addrsig_sym _Z43__device_stub__kernelCalculateNewGenerationPfS_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.addrsig_sym _Z28kernelCalculateNewGenerationPfS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii ; -- Begin function _Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.globl	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
	.p2align	8
	.type	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii,@function
_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii: ; @_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x24
	s_load_b32 s2, s[0:1], 0x14
	v_bfe_u32 v4, v0, 10, 10
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v11, -1, v4
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s3, 16
	s_and_b32 s3, s3, 0xffff
	v_mad_u64_u32 v[7:8], null, s15, s4, v[4:5]
	v_and_b32_e32 v8, 0x3ff, v0
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mov_b32 s0, 0
	s_mov_b32 s1, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mad_u64_u32 v[5:6], null, s14, s3, v[8:9]
	v_mul_lo_u32 v9, v7, s2
	v_add_nc_u32_e32 v10, -1, v8
	v_lshlrev_b32_e32 v8, 2, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_max_u32_e32 v11, v10, v11
	v_lshl_add_u32 v10, v4, 7, v8
	v_add_nc_u32_e32 v0, v9, v5
                                        ; implicit-def: $vgpr4
                                        ; implicit-def: $vgpr8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v6, v[2:3], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v10, v6
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
                                        ; implicit-def: $vgpr6
	v_cmpx_lt_u32_e32 29, v11
	s_xor_b32 s1, exec_lo, s1
	s_cbranch_execz .LBB0_4
; %bb.1:
	v_add_nc_u32_e32 v10, -1, v5
	v_add_nc_u32_e32 v4, -1, v7
                                        ; implicit-def: $vgpr6
                                        ; implicit-def: $vgpr8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, 0x27fe, v10
	v_cmp_gt_u32_e64 s0, 0x3ffe, v4
                                        ; implicit-def: $vgpr4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s3, vcc_lo, s0
	s_mov_b32 s0, 0
	s_and_saveexec_b32 s8, s3
	s_xor_b32 s3, exec_lo, s8
	s_cbranch_execz .LBB0_3
; %bb.2:
	v_subrev_nc_u32_e32 v4, s2, v9
	v_add_nc_u32_e32 v6, v9, v10
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v4, v4, v5
	v_ashrrev_i32_e32 v7, 31, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshl_add_u32 v8, s2, 1, v4
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	v_ashrrev_i32_e32 v5, 31, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v6, vcc_lo, s4, v6
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v8, vcc_lo, s4, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s5, v9, vcc_lo
	v_add_co_u32 v4, vcc_lo, s4, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	s_clause 0x3
	global_load_b64 v[2:3], v[2:3], off
	global_load_b32 v6, v[6:7], off
	global_load_b32 v7, v[8:9], off
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(2)
	v_add_f32_e32 v6, v3, v6
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v8, v7, v4
	v_mov_b32_e32 v4, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v6, -2.0, v2
	v_fmac_f32_e32 v8, -2.0, v2
.LBB0_3:                                ; %Flow65
	s_or_b32 exec_lo, exec_lo, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s0, s0, exec_lo
                                        ; implicit-def: $vgpr10
.LBB0_4:                                ; %Flow
	s_and_not1_saveexec_b32 s1, s1
	s_cbranch_execz .LBB0_6
; %bb.5:
	v_add_nc_u32_e32 v2, -4, v10
	v_add_nc_u32_e32 v5, 0xffffff80, v10
	s_or_b32 s0, s0, exec_lo
	ds_load_2addr_b32 v[6:7], v10 offset0:1 offset1:32
	ds_load_2addr_b32 v[3:4], v2 offset1:1
	ds_load_b32 v2, v5
	s_waitcnt lgkmcnt(1)
	v_add_f32_e32 v6, v3, v6
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v8, v2, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v6, -2.0, v4
	v_fmac_f32_e32 v8, -2.0, v4
.LBB0_6:                                ; %Flow66
	s_or_b32 exec_lo, exec_lo, s1
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_8
; %bb.7:                                ; %.sink.split
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_mul_f32_e32 v2, 0x3dcccccd, v8
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	v_fmac_f32_e32 v2, 0x3dcccccd, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f32_e32 v2, v4, v2
	global_store_b32 v[0:1], v2, off
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
		.amdhsa_group_segment_fixed_size 4096
		.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 12
		.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	_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii, .Lfunc_end0-_Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 616
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z28kernelCalculateNewGenerationPfS_ii ; -- Begin function _Z28kernelCalculateNewGenerationPfS_ii
	.globl	_Z28kernelCalculateNewGenerationPfS_ii
	.p2align	8
	.type	_Z28kernelCalculateNewGenerationPfS_ii,@function
_Z28kernelCalculateNewGenerationPfS_ii: ; @_Z28kernelCalculateNewGenerationPfS_ii
; %bb.0:
	s_load_b32 s2, s[0:1], 0x24
	v_and_b32_e32 v2, 0x3ff, v0
	v_bfe_u32 v3, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[0:1], null, s14, s2, v[2:3]
	v_mad_u64_u32 v[1:2], null, s15, s3, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, -1, v0
	v_add_nc_u32_e32 v3, -1, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_gt_u32_e32 vcc_lo, 0x27fe, v2
	v_cmp_gt_u32_e64 s2, 0x3ffe, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB1_2
; %bb.1:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x14
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_mul_lo_u32 v3, v1, s4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v4, s4, v3
	s_lshl_b32 s4, s4, 1
	v_add_nc_u32_e32 v1, v3, v0
	v_add_nc_u32_e32 v3, v3, v2
	v_subrev_nc_u32_e32 v7, s4, v4
	v_add_nc_u32_e32 v5, v4, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v2, 31, v1
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_nc_u32_e32 v0, v7, v0
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[7:8], 2, v[1:2]
	v_lshlrev_b64 v[2:3], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[4:5], 2, v[5:6]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v9, vcc_lo, s0, v7
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_ci_u32_e32 v10, vcc_lo, s1, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	v_add_co_u32 v2, vcc_lo, s0, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	s_clause 0x3
	global_load_b32 v4, v[4:5], off
	global_load_b32 v5, v[0:1], off
	global_load_b64 v[0:1], v[9:10], off
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(2)
	v_add_f32_e32 v3, v4, v5
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v1, v1, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v3, -2.0, v0
	v_dual_fmac_f32 v1, -2.0, v0 :: v_dual_mul_f32 v2, 0x3dcccccd, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v2, 0x3dcccccd, v1
	v_add_f32_e32 v2, v0, v2
	v_add_co_u32 v0, vcc_lo, s2, v7
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v8, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB1_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z28kernelCalculateNewGenerationPfS_ii
		.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	_Z28kernelCalculateNewGenerationPfS_ii, .Lfunc_end1-_Z28kernelCalculateNewGenerationPfS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 416
; NumSgprs: 18
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .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: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z44kernelCalculateNewGenerationWithSharedMemoryPfS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .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
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .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:           _Z28kernelCalculateNewGenerationPfS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z28kernelCalculateNewGenerationPfS_ii.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
