/*
Compile using nvcc cuda_heat.cu
Author: Romit Maulik - romit.maulik@okstate.edu
*/

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

const double PI = 3.1415926535;
const double lx = 2.0*PI, ly = 2.0*PI;
const int nx = 254, ny = 254;
const double ALPHA = 0.8, STAB_PARAM = 0.8;
const double dx = lx/nx, dy = ly/ny;

/*
Host Functions
*/
void initialize_array(double *u);
void write_array(double *u);
/*
Device Functions
*/
__global__ void update_solution(double *_u, double *_utemp, double *_const_mult);
__global__ void update_periodic_boundaries(double *_u);
__global__ void copy_arrays(double *_u, double *_utemp);



int main (int argc, char** argv)
{
	double *u = new double [(nx+2)*(ny+2)];

	//double *u = malloc(sizeof(double) * (nx+2) * (ny+2)); //Pointer to host memory
	double *_u, *_utemp;			//Pointer to device memory
	double *const_mult = new double[1];
	double *_const_mult;

	initialize_array(u);      //Initialize solution on host

	// allocate storage space on the GPU
	cudaMalloc((void **)&_u, (nx+2) * (ny+2) * sizeof(double));
    cudaMalloc((void **)&_utemp, (nx+2) * (ny+2) * sizeof(double));
    cudaMalloc((void **)&_const_mult,sizeof(double));

    //Copy data to device
	cudaMemcpy(_u,u,(nx+2)*(ny+2)*sizeof(double),cudaMemcpyHostToDevice);
	cudaMemcpy(_utemp,u,(nx+2)*(ny+2)*sizeof(double),cudaMemcpyHostToDevice);

    // assign a 2D distribution of CUDA "threads" within each CUDA "block"    
    int ThreadsPerBlock=16;
    dim3 dimBlock( ThreadsPerBlock, ThreadsPerBlock );

    // calculate number of blocks along X and Y in a 2D CUDA "grid"
    dim3 dimGrid( ceil(float(nx+2)/float(dimBlock.x)), ceil(float(ny+2)/float(dimBlock.y)), 1 );
	
	double t,dt;
	const double ft=1.0;
	
	dt = STAB_PARAM*dx*dx/(4.0*ALPHA);
	((*const_mult)) = ALPHA*dt/(dx*dx);

	//Copy constant to device
	cudaMemcpy(_const_mult,const_mult,sizeof(double),cudaMemcpyHostToDevice);

	clock_t start, end;
	double cpu_time_used;

	start = clock();

	//FTCS integration - CUDA
	//Boundary conditions
	update_periodic_boundaries<<<dimGrid, dimBlock>>>(_u);
	cudaThreadSynchronize();

	update_periodic_boundaries<<<dimGrid, dimBlock>>>(_utemp);
	cudaThreadSynchronize();

	t = 0.0;
	do{
		
		//Update solution
		update_solution<<<dimGrid, dimBlock>>>(_u,_utemp,_const_mult);   // update T1 using data stored in T2
		cudaThreadSynchronize();

		//Boundary conditions
		update_periodic_boundaries<<<dimGrid, dimBlock>>>(_u);
		cudaThreadSynchronize();

		//Copy arrays
		copy_arrays<<<dimGrid, dimBlock>>>(_u,_utemp);
		cudaThreadSynchronize();

		t = t + dt;
	}while(t<ft);

	// copy final array to the CPU from the GPU 
    cudaMemcpy(u,_u,(nx+2)*(ny+2)*sizeof(double),cudaMemcpyDeviceToHost);
    cudaThreadSynchronize();

    end = clock();
	cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

	printf("CPU time used = %f\n", cpu_time_used);

    //Write temperature to disk
    write_array(u);

    // release memory on the host 
    delete u;

    // release memory on the device 
    cudaFree(_u);
    cudaFree(_utemp);


	return 0;
}

void initialize_array(double *u)
{
	double x,y;

	for (int i = 1; i < nx+1; i++)
	{
		for (int j = 1; j < ny+1; j++)
		{
			x = (double) (i-1)/nx * 2.0 * PI;
			y = (double) (j-1)/ny * 2.0 * PI;

			(*(u + (ny+2)*i + j)) = sin(x+y);
		}
	}
}


__global__ void update_periodic_boundaries(double *_u)
{
    // compute the "i" and "j" location of the node point
    // handled by this thread

    int i = blockIdx.x * blockDim.x + threadIdx.x ;
    int j = blockIdx.y * blockDim.y + threadIdx.y ;

    // Left boundary
    if(j>0 && j<ny+1 && i == 0) 
    {
    	(*(_u + j)) = (*(_u + (ny+2)*nx + j));//Correct

    }

    // Right boundary
    if(j>0 && j<ny+1 && i == nx + 1) 
    {
    	(*(_u + (ny+2)*(nx+1) + j)) = (*(_u + (ny+2) + j));//Correct
    }

    // Bottom boundary
    if(i>=0 && i<nx+2 && j == 0)
    {
    	(*(_u + (ny+2)*i)) = (*(_u + (ny+2)*i + ny));	//Correct
    }

    // top boundary
    if(i>=0 && i<nx+2 && j == ny + 1)
    {
    	(*(_u + (ny+2)*i + ny + 1)) = (*(_u + (ny+2)*i + 1));	//Correct
    	
    }
   
}

__global__ void update_solution(double *_u, double *_utemp, double *_const_mult)
{
    // compute the "i" and "j" location of the node point
    // handled by this thread

    int i = blockIdx.x * blockDim.x + threadIdx.x ;
    int j = blockIdx.y * blockDim.y + threadIdx.y ;

    // get the natural index values of node (i,j) and its neighboring nodes
	int p = (ny+2)*i + j; 
	int n = (ny+2)*i + j + 1;
	int s = (ny+2)*i + j - 1;
	int w = (ny+2)*(i-1) + j;
	int e = (ny+2)*(i+1) + j;

    // only update "interior" node points
    if(i>0 && i<nx+1 && j>0 && j<ny+1) 
    {
        (*(_u + p)) = (*(_utemp + p)) + (*_const_mult)*(-4.0*(*(_utemp + p)) + (*(_utemp + n)) + (*(_utemp + s)) + (*(_utemp + w)) + (*(_utemp + e)));
    }
}

__global__ void copy_arrays(double *_u, double *_utemp)
{

    // compute the "i" and "j" location of the node point
    // handled by this thread

    int i = blockIdx.x * blockDim.x + threadIdx.x ;
    int j = blockIdx.y * blockDim.y + threadIdx.y ;

	(*(_utemp + (ny+2)*i + j)) = (*(_u + (ny+2)*i + j));
}

void write_array(double *u)
{
	FILE *fp;
	fp = fopen("Temperature.txt","wb");

	for(int i=0;i<nx+2;i++) {
		for(int j=0;j<ny+2;j++) {
			double value = (*(u + (ny+2)*i + j));
    		fprintf(fp,"%f ",value);
		}
		fprintf(fp,"\n");
	}
}

	.file	"tmpxft_0034698e_00000000-6_cuda_heat.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z16initialize_arrayPd
	.type	_Z16initialize_arrayPd, @function
_Z16initialize_arrayPd:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	$256, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
.L3:
	cvtsi2sdl	%ebp, %xmm0
	divsd	.LC0(%rip), %xmm0
	addsd	%xmm0, %xmm0
	mulsd	.LC1(%rip), %xmm0
	leaq	(%r12,%r13,8), %r14
	xorl	%ebx, %ebx
	movsd	%xmm0, 8(%rsp)
.L4:
	cvtsi2sdl	%ebx, %xmm0
	divsd	.LC0(%rip), %xmm0
	addsd	%xmm0, %xmm0
	mulsd	.LC1(%rip), %xmm0
	addsd	8(%rsp), %xmm0
	call	sin@PLT
	movsd	%xmm0, 8(%r14,%rbx,8)
	incq	%rbx
	cmpq	$254, %rbx
	jne	.L4
	incl	%ebp
	addq	$256, %r13
	cmpl	$254, %ebp
	jne	.L3
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z16initialize_arrayPd, .-_Z16initialize_arrayPd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"wb"
.LC3:
	.string	"Temperature.txt"
.LC4:
	.string	"%f "
.LC5:
	.string	"\n"
	.text
	.globl	_Z11write_arrayPd
	.type	_Z11write_arrayPd, @function
_Z11write_arrayPd:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC2(%rip), %rsi
	leaq	.LC4(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	leaq	.LC3(%rip), %rdi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rdx
	.cfi_def_cfa_offset 64
	call	fopen@PLT
	movq	%rax, %r12
.L10:
	leaq	0(%r13,%rbp,8), %r14
	xorl	%ebx, %ebx
.L11:
	movsd	(%r14,%rbx,8), %xmm0
	movq	%r15, %rdx
	movl	$2, %esi
	movb	$1, %al
	movq	%r12, %rdi
	incq	%rbx
	call	__fprintf_chk@PLT
	cmpq	$256, %rbx
	jne	.L11
	leaq	.LC5(%rip), %rdx
	movl	$2, %esi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	addq	$256, %rbp
	cmpq	$65536, %rbp
	jne	.L10
	popq	%rax
	.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
.LFE2029:
	.size	_Z11write_arrayPd, .-_Z11write_arrayPd
	.globl	_Z46__device_stub__Z26update_periodic_boundariesPdPd
	.type	_Z46__device_stub__Z26update_periodic_boundariesPdPd, @function
_Z46__device_stub__Z26update_periodic_boundariesPdPd:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z26update_periodic_boundariesPd(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L15:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z46__device_stub__Z26update_periodic_boundariesPdPd, .-_Z46__device_stub__Z26update_periodic_boundariesPdPd
	.globl	_Z26update_periodic_boundariesPd
	.type	_Z26update_periodic_boundariesPd, @function
_Z26update_periodic_boundariesPd:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z26update_periodic_boundariesPdPd
	.cfi_endproc
.LFE2055:
	.size	_Z26update_periodic_boundariesPd, .-_Z26update_periodic_boundariesPd
	.globl	_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_
	.type	_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_, @function
_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_:
.LFB2056:
	.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	.L20
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z15update_solutionPdS_S_(%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
.L20:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_, .-_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_
	.globl	_Z15update_solutionPdS_S_
	.type	_Z15update_solutionPdS_S_, @function
_Z15update_solutionPdS_S_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_
	.cfi_endproc
.LFE2057:
	.size	_Z15update_solutionPdS_S_, .-_Z15update_solutionPdS_S_
	.globl	_Z33__device_stub__Z11copy_arraysPdS_PdS_
	.type	_Z33__device_stub__Z11copy_arraysPdS_PdS_, @function
_Z33__device_stub__Z11copy_arraysPdS_PdS_:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z11copy_arraysPdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L25:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z33__device_stub__Z11copy_arraysPdS_PdS_, .-_Z33__device_stub__Z11copy_arraysPdS_PdS_
	.globl	_Z11copy_arraysPdS_
	.type	_Z11copy_arraysPdS_, @function
_Z11copy_arraysPdS_:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z11copy_arraysPdS_PdS_
	.cfi_endproc
.LFE2059:
	.size	_Z11copy_arraysPdS_, .-_Z11copy_arraysPdS_
	.section	.rodata.str1.1
.LC11:
	.string	"CPU time used = %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$524288, %edi
	movabsq	$68719476752, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$80, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	movl	$8, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	movq	%rbx, %rdi
	movq	%rax, %rbp
	call	_Z16initialize_arrayPd
	leaq	24(%rsp), %rdi
	movl	$524288, %esi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$524288, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$8, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$524288, %edx
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$524288, %edx
	call	cudaMemcpy@PLT
	movq	.LC7(%rip), %rax
	movq	40(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$8, %edx
	movq	%r12, 60(%rsp)
	movq	%rax, 0(%rbp)
	movl	$1, 68(%rsp)
	call	cudaMemcpy@PLT
	call	clock@PLT
	movq	60(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	68(%rsp), %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	movq	%rax, %rbp
	movq	%r12, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	movq	24(%rsp), %rdi
	call	_Z46__device_stub__Z26update_periodic_boundariesPdPd
.L31:
	call	cudaThreadSynchronize@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	48(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	movq	32(%rsp), %rdi
	call	_Z46__device_stub__Z26update_periodic_boundariesPdPd
.L32:
	call	cudaThreadSynchronize@PLT
	movq	$0x000000000, 8(%rsp)
.L36:
	movl	56(%rsp), %ecx
	movq	48(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	60(%rsp), %rdi
	movl	68(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z39__device_stub__Z15update_solutionPdS_S_PdS_S_
.L33:
	call	cudaThreadSynchronize@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	48(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	movq	24(%rsp), %rdi
	call	_Z46__device_stub__Z26update_periodic_boundariesPdPd
.L34:
	call	cudaThreadSynchronize@PLT
	movl	56(%rsp), %ecx
	movl	68(%rsp), %esi
	xorl	%r9d, %r9d
	movq	48(%rsp), %rdx
	movq	60(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L35
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z33__device_stub__Z11copy_arraysPdS_PdS_
.L35:
	call	cudaThreadSynchronize@PLT
	movsd	.LC8(%rip), %xmm1
	addsd	8(%rsp), %xmm1
	movsd	.LC9(%rip), %xmm0
	comisd	%xmm1, %xmm0
	movsd	%xmm1, 8(%rsp)
	ja	.L36
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movl	$524288, %edx
	movq	%rbx, %rdi
	call	cudaMemcpy@PLT
	call	cudaThreadSynchronize@PLT
	call	clock@PLT
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	subq	%rbp, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC10(%rip), %xmm0
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	_Z11write_arrayPd
	movl	$8, %esi
	movq	%rbx, %rdi
	call	_ZdlPvm@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$80, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z11copy_arraysPdS_"
.LC13:
	.string	"_Z15update_solutionPdS_S_"
.LC14:
	.string	"_Z26update_periodic_boundariesPd"
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z11copy_arraysPdS_(%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	_Z15update_solutionPdS_S_(%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
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z26update_periodic_boundariesPd(%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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1081065472
	.align 8
.LC1:
	.long	1413551940
	.long	1074340347
	.align 8
.LC7:
	.long	-1717986918
	.long	1070176665
	.align 8
.LC8:
	.long	429618330
	.long	1059327265
	.align 8
.LC9:
	.long	0
	.long	1072693248
	.align 8
.LC10:
	.long	0
	.long	1093567616
	.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:

/*
Compile using nvcc cuda_heat.cu
Author: Romit Maulik - romit.maulik@okstate.edu
*/


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

const double PI = 3.1415926535;
const double lx = 2.0*PI, ly = 2.0*PI;
const int nx = 254, ny = 254;
const double ALPHA = 0.8, STAB_PARAM = 0.8;
const double dx = lx/nx, dy = ly/ny;

/*
Host Functions
*/
void initialize_array(double *u);
void write_array(double *u);
/*
Device Functions
*/
__global__ void update_solution(double *_u, double *_utemp, double *_const_mult);
__global__ void update_periodic_boundaries(double *_u);
__global__ void copy_arrays(double *_u, double *_utemp);



int main (int argc, char** argv)
{
	double *u = new double [(nx+2)*(ny+2)];

	//double *u = malloc(sizeof(double) * (nx+2) * (ny+2)); //Pointer to host memory
	double *_u, *_utemp;			//Pointer to device memory
	double *const_mult = new double[1];
	double *_const_mult;

	initialize_array(u);      //Initialize solution on host

	// allocate storage space on the GPU
	hipMalloc((void **)&_u, (nx+2) * (ny+2) * sizeof(double));
    hipMalloc((void **)&_utemp, (nx+2) * (ny+2) * sizeof(double));
    hipMalloc((void **)&_const_mult,sizeof(double));

    //Copy data to device
	hipMemcpy(_u,u,(nx+2)*(ny+2)*sizeof(double),hipMemcpyHostToDevice);
	hipMemcpy(_utemp,u,(nx+2)*(ny+2)*sizeof(double),hipMemcpyHostToDevice);

    // assign a 2D distribution of CUDA "threads" within each CUDA "block"    
    int ThreadsPerBlock=16;
    dim3 dimBlock( ThreadsPerBlock, ThreadsPerBlock );

    // calculate number of blocks along X and Y in a 2D CUDA "grid"
    dim3 dimGrid( ceil(float(nx+2)/float(dimBlock.x)), ceil(float(ny+2)/float(dimBlock.y)), 1 );
	
	double t,dt;
	const double ft=1.0;
	
	dt = STAB_PARAM*dx*dx/(4.0*ALPHA);
	((*const_mult)) = ALPHA*dt/(dx*dx);

	//Copy constant to device
	hipMemcpy(_const_mult,const_mult,sizeof(double),hipMemcpyHostToDevice);

	clock_t start, end;
	double cpu_time_used;

	start = clock();

	//FTCS integration - CUDA
	//Boundary conditions
	update_periodic_boundaries<<<dimGrid, dimBlock>>>(_u);
	hipDeviceSynchronize();

	update_periodic_boundaries<<<dimGrid, dimBlock>>>(_utemp);
	hipDeviceSynchronize();

	t = 0.0;
	do{
		
		//Update solution
		update_solution<<<dimGrid, dimBlock>>>(_u,_utemp,_const_mult);   // update T1 using data stored in T2
		hipDeviceSynchronize();

		//Boundary conditions
		update_periodic_boundaries<<<dimGrid, dimBlock>>>(_u);
		hipDeviceSynchronize();

		//Copy arrays
		copy_arrays<<<dimGrid, dimBlock>>>(_u,_utemp);
		hipDeviceSynchronize();

		t = t + dt;
	}while(t<ft);

	// copy final array to the CPU from the GPU 
    hipMemcpy(u,_u,(nx+2)*(ny+2)*sizeof(double),hipMemcpyDeviceToHost);
    hipDeviceSynchronize();

    end = clock();
	cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

	printf("CPU time used = %f\n", cpu_time_used);

    //Write temperature to disk
    write_array(u);

    // release memory on the host 
    delete u;

    // release memory on the device 
    hipFree(_u);
    hipFree(_utemp);


	return 0;
}

void initialize_array(double *u)
{
	double x,y;

	for (int i = 1; i < nx+1; i++)
	{
		for (int j = 1; j < ny+1; j++)
		{
			x = (double) (i-1)/nx * 2.0 * PI;
			y = (double) (j-1)/ny * 2.0 * PI;

			(*(u + (ny+2)*i + j)) = sin(x+y);
		}
	}
}


__global__ void update_periodic_boundaries(double *_u)
{
    // compute the "i" and "j" location of the node point
    // handled by this thread

    int i = blockIdx.x * blockDim.x + threadIdx.x ;
    int j = blockIdx.y * blockDim.y + threadIdx.y ;

    // Left boundary
    if(j>0 && j<ny+1 && i == 0) 
    {
    	(*(_u + j)) = (*(_u + (ny+2)*nx + j));//Correct

    }

    // Right boundary
    if(j>0 && j<ny+1 && i == nx + 1) 
    {
    	(*(_u + (ny+2)*(nx+1) + j)) = (*(_u + (ny+2) + j));//Correct
    }

    // Bottom boundary
    if(i>=0 && i<nx+2 && j == 0)
    {
    	(*(_u + (ny+2)*i)) = (*(_u + (ny+2)*i + ny));	//Correct
    }

    // top boundary
    if(i>=0 && i<nx+2 && j == ny + 1)
    {
    	(*(_u + (ny+2)*i + ny + 1)) = (*(_u + (ny+2)*i + 1));	//Correct
    	
    }
   
}

__global__ void update_solution(double *_u, double *_utemp, double *_const_mult)
{
    // compute the "i" and "j" location of the node point
    // handled by this thread

    int i = blockIdx.x * blockDim.x + threadIdx.x ;
    int j = blockIdx.y * blockDim.y + threadIdx.y ;

    // get the natural index values of node (i,j) and its neighboring nodes
	int p = (ny+2)*i + j; 
	int n = (ny+2)*i + j + 1;
	int s = (ny+2)*i + j - 1;
	int w = (ny+2)*(i-1) + j;
	int e = (ny+2)*(i+1) + j;

    // only update "interior" node points
    if(i>0 && i<nx+1 && j>0 && j<ny+1) 
    {
        (*(_u + p)) = (*(_utemp + p)) + (*_const_mult)*(-4.0*(*(_utemp + p)) + (*(_utemp + n)) + (*(_utemp + s)) + (*(_utemp + w)) + (*(_utemp + e)));
    }
}

__global__ void copy_arrays(double *_u, double *_utemp)
{

    // compute the "i" and "j" location of the node point
    // handled by this thread

    int i = blockIdx.x * blockDim.x + threadIdx.x ;
    int j = blockIdx.y * blockDim.y + threadIdx.y ;

	(*(_utemp + (ny+2)*i + j)) = (*(_u + (ny+2)*i + j));
}

void write_array(double *u)
{
	FILE *fp;
	fp = fopen("Temperature.txt","wb");

	for(int i=0;i<nx+2;i++) {
		for(int j=0;j<ny+2;j++) {
			double value = (*(u + (ny+2)*i + j));
    		fprintf(fp,"%f ",value);
		}
		fprintf(fp,"\n");
	}
}

	.text
	.file	"cuda_heat.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x3f240d21199b749a              # double 1.529791741664885E-4
.LCPI0_1:
	.quad	0x3ff0000000000000              # double 1
.LCPI0_2:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$68719476752, %r14              # imm = 0x1000000010
	movl	$524288, %edi                   # imm = 0x80000
	callq	_Znam
	movq	%rax, %rbx
	movl	$8, %edi
	callq	_Znam
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	_Z16initialize_arrayPd
	leaq	8(%rsp), %r12
	movl	$524288, %esi                   # imm = 0x80000
	movq	%r12, %rdi
	callq	hipMalloc
	leaq	16(%rsp), %r13
	movl	$524288, %esi                   # imm = 0x80000
	movq	%r13, %rdi
	callq	hipMalloc
	leaq	32(%rsp), %rbp
	movl	$8, %esi
	movq	%rbp, %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	$524288, %edx                   # imm = 0x80000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	movl	$524288, %edx                   # imm = 0x80000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4596373779694328218, %rax      # imm = 0x3FC999999999999A
	movq	%rax, (%r15)
	movq	(%rbp), %rdi
	movl	$8, %edx
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, %r15
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_2
# %bb.1:
	movq	8(%rsp), %rdi
	callq	_Z41__device_stub__update_periodic_boundariesPd
.LBB0_2:
	callq	hipDeviceSynchronize
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_4
# %bb.3:
	movq	16(%rsp), %rdi
	callq	_Z41__device_stub__update_periodic_boundariesPd
.LBB0_4:
	callq	hipDeviceSynchronize
	xorpd	%xmm0, %xmm0
.LBB0_5:                                # =>This Inner Loop Header: Depth=1
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_7
# %bb.6:                                #   in Loop: Header=BB0_5 Depth=1
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	32(%rsp), %rdx
	callq	_Z30__device_stub__update_solutionPdS_S_
.LBB0_7:                                #   in Loop: Header=BB0_5 Depth=1
	callq	hipDeviceSynchronize
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_9
# %bb.8:                                #   in Loop: Header=BB0_5 Depth=1
	movq	8(%rsp), %rdi
	callq	_Z41__device_stub__update_periodic_boundariesPd
.LBB0_9:                                #   in Loop: Header=BB0_5 Depth=1
	callq	hipDeviceSynchronize
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_11
# %bb.10:                               #   in Loop: Header=BB0_5 Depth=1
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z26__device_stub__copy_arraysPdS_
.LBB0_11:                               #   in Loop: Header=BB0_5 Depth=1
	callq	hipDeviceSynchronize
	movsd	24(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	addsd	.LCPI0_0(%rip), %xmm1
	movsd	.LCPI0_1(%rip), %xmm0           # xmm0 = mem[0],zero
	ucomisd	%xmm1, %xmm0
	movapd	%xmm1, %xmm0
	ja	.LBB0_5
# %bb.12:
	movq	8(%rsp), %rsi
	movl	$524288, %edx                   # imm = 0x80000
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	callq	hipDeviceSynchronize
	callq	clock
	subq	%r15, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI0_2(%rip), %xmm0
	movl	$.L.str, %edi
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	callq	_Z11write_arrayPd
	movq	%rbx, %rdi
	callq	_ZdlPv
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z16initialize_arrayPd
.LCPI1_0:
	.quad	0x406fc00000000000              # double 254
.LCPI1_1:
	.quad	0x400921fb54411744              # double 3.1415926535000001
	.text
	.globl	_Z16initialize_arrayPd
	.type	_Z16initialize_arrayPd,@function
_Z16initialize_arrayPd:                 # @_Z16initialize_arrayPd
	.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
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	addq	$2056, %rbx                     # imm = 0x808
	movl	$1, %r14d
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI1_1(%rip), %xmm2           # xmm2 = mem[0],zero
.LBB1_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_2 Depth 2
	leal	-1(%r14), %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	addsd	%xmm0, %xmm0
	mulsd	%xmm2, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	xorl	%r15d, %r15d
.LBB1_2:                                #   Parent Loop BB1_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r15d, %xmm0
	divsd	%xmm1, %xmm0
	addsd	%xmm0, %xmm0
	mulsd	%xmm2, %xmm0
	addsd	8(%rsp), %xmm0                  # 8-byte Folded Reload
	callq	sin
	movsd	.LCPI1_1(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	%xmm0, (%rbx,%r15,8)
	incq	%r15
	cmpq	$254, %r15
	jne	.LBB1_2
# %bb.3:                                #   in Loop: Header=BB1_1 Depth=1
	incq	%r14
	addq	$2048, %rbx                     # imm = 0x800
	cmpq	$255, %r14
	jne	.LBB1_1
# %bb.4:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z16initialize_arrayPd, .Lfunc_end1-_Z16initialize_arrayPd
	.cfi_endproc
                                        # -- End function
	.globl	_Z41__device_stub__update_periodic_boundariesPd # -- Begin function _Z41__device_stub__update_periodic_boundariesPd
	.type	_Z41__device_stub__update_periodic_boundariesPd,@function
_Z41__device_stub__update_periodic_boundariesPd: # @_Z41__device_stub__update_periodic_boundariesPd
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z26update_periodic_boundariesPd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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	_Z41__device_stub__update_periodic_boundariesPd, .Lfunc_end2-_Z41__device_stub__update_periodic_boundariesPd
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__update_solutionPdS_S_ # -- Begin function _Z30__device_stub__update_solutionPdS_S_
	.type	_Z30__device_stub__update_solutionPdS_S_,@function
_Z30__device_stub__update_solutionPdS_S_: # @_Z30__device_stub__update_solutionPdS_S_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	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	$_Z15update_solutionPdS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z30__device_stub__update_solutionPdS_S_, .Lfunc_end3-_Z30__device_stub__update_solutionPdS_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__copy_arraysPdS_ # -- Begin function _Z26__device_stub__copy_arraysPdS_
	.type	_Z26__device_stub__copy_arraysPdS_,@function
_Z26__device_stub__copy_arraysPdS_:     # @_Z26__device_stub__copy_arraysPdS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z11copy_arraysPdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z26__device_stub__copy_arraysPdS_, .Lfunc_end4-_Z26__device_stub__copy_arraysPdS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z11write_arrayPd               # -- Begin function _Z11write_arrayPd
	.type	_Z11write_arrayPd,@function
_Z11write_arrayPd:                      # @_Z11write_arrayPd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$.L.str.1, %edi
	movl	$.L.str.2, %esi
	callq	fopen
	movq	%rax, %r14
	xorl	%r15d, %r15d
.LBB5_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_2 Depth 2
	xorl	%r12d, %r12d
.LBB5_2:                                #   Parent Loop BB5_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rbx,%r12,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.3, %esi
	movq	%r14, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%r12
	cmpq	$256, %r12                      # imm = 0x100
	jne	.LBB5_2
# %bb.3:                                #   in Loop: Header=BB5_1 Depth=1
	movl	$10, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	incq	%r15
	addq	$2048, %rbx                     # imm = 0x800
	cmpq	$256, %r15                      # imm = 0x100
	jne	.LBB5_1
# %bb.4:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z11write_arrayPd, .Lfunc_end5-_Z11write_arrayPd
	.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	$_Z26update_periodic_boundariesPd, %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	$_Z15update_solutionPdS_S_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11copy_arraysPdS_, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %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	_Z26update_periodic_boundariesPd,@object # @_Z26update_periodic_boundariesPd
	.section	.rodata,"a",@progbits
	.globl	_Z26update_periodic_boundariesPd
	.p2align	3, 0x0
_Z26update_periodic_boundariesPd:
	.quad	_Z41__device_stub__update_periodic_boundariesPd
	.size	_Z26update_periodic_boundariesPd, 8

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

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CPU time used = %f\n"
	.size	.L.str, 20

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Temperature.txt"
	.size	.L.str.1, 16

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

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z26update_periodic_boundariesPd"
	.size	.L__unnamed_1, 33

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

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z11copy_arraysPdS_"
	.size	.L__unnamed_3, 20

	.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 _Z41__device_stub__update_periodic_boundariesPd
	.addrsig_sym _Z30__device_stub__update_solutionPdS_S_
	.addrsig_sym _Z26__device_stub__copy_arraysPdS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z26update_periodic_boundariesPd
	.addrsig_sym _Z15update_solutionPdS_S_
	.addrsig_sym _Z11copy_arraysPdS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z26update_periodic_boundariesPd ; -- Begin function _Z26update_periodic_boundariesPd
	.globl	_Z26update_periodic_boundariesPd
	.p2align	8
	.type	_Z26update_periodic_boundariesPd,@function
_Z26update_periodic_boundariesPd:       ; @_Z26update_periodic_boundariesPd
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x14
	s_load_b64 s[2:3], s[0:1], 0x0
	v_bfe_u32 v3, v0, 10, 10
	v_and_b32_e32 v0, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s0, s4, 16
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s0, v[3:4]
	s_and_b32 s0, s4, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[3:4], null, s14, s0, v[0:1]
	v_add_nc_u32_e32 v0, -1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_u32_e32 vcc_lo, 0xfe, v0
	v_cmp_eq_u32_e64 s0, 0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, s0, vcc_lo
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 3, v[1:2]
	v_add_co_u32 v4, s0, s2, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e64 v5, s0, s3, v5, s0
	v_add_co_u32 v6, s0, 0x7f000, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, s0, 0, v5, s0
	global_load_b64 v[6:7], v[6:7], off
	s_waitcnt vmcnt(0)
	global_store_b64 v[4:5], v[6:7], off
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s1
	v_cmp_eq_u32_e64 s0, 0xff, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s1, s0, vcc_lo
	s_and_saveexec_b32 s0, s1
	s_cbranch_execz .LBB0_4
; %bb.3:
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 3, v[1:2]
	v_add_co_u32 v4, vcc_lo, s2, v4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v5, vcc_lo
	global_load_b64 v[6:7], v[4:5], off offset:2048
	v_add_co_u32 v4, vcc_lo, 0x7f000, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b64 v[4:5], v[6:7], off offset:2048
.LBB0_4:
	s_or_b32 exec_lo, exec_lo, s0
	v_cmp_gt_u32_e32 vcc_lo, 0x100, v3
	v_cmp_eq_u32_e64 s0, 0, v1
	v_lshlrev_b32_e32 v2, 8, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, vcc_lo, s0
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_6
; %bb.5:
	v_mov_b32_e32 v3, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 3, v[2:3]
	v_add_co_u32 v3, s0, s2, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v4, s0, s3, v4, s0
	global_load_b64 v[5:6], v[3:4], off offset:2032
	s_waitcnt vmcnt(0)
	global_store_b64 v[3:4], v[5:6], off
.LBB0_6:
	s_or_b32 exec_lo, exec_lo, s1
	v_cmp_eq_u32_e64 s0, 0xff, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s0, vcc_lo, s0
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_8
; %bb.7:
	v_mov_b32_e32 v3, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[2:3]
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_load_b64 v[2:3], v[0:1], off offset:8
	s_waitcnt vmcnt(0)
	global_store_b64 v[0:1], v[2:3], off offset:2040
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z26update_periodic_boundariesPd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 8
		.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	_Z26update_periodic_boundariesPd, .Lfunc_end0-_Z26update_periodic_boundariesPd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 488
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; 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	_Z15update_solutionPdS_S_ ; -- Begin function _Z15update_solutionPdS_S_
	.globl	_Z15update_solutionPdS_S_
	.p2align	8
	.type	_Z15update_solutionPdS_S_,@function
_Z15update_solutionPdS_S_:              ; @_Z15update_solutionPdS_S_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x24
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v4, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[2:3], null, s14, s2, v[1:2]
	v_mad_u64_u32 v[0:1], null, s15, s3, v[4:5]
	s_mov_b32 s2, exec_lo
	v_add_nc_u32_e32 v1, -1, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, -1, v0
	v_max_u32_e32 v1, v1, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e32 0xfe, v1
	s_cbranch_execz .LBB1_2
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_dual_mov_b32 v6, 0 :: v_dual_lshlrev_b32 v11, 8, v2
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v5, v11, v0
	v_add_co_u32 v11, s2, v11, v0
	v_add_co_ci_u32_e64 v12, null, 0, 0, s2
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[7:8], 3, v[5:6]
	v_add_nc_u32_e32 v5, 0xffffff00, v5
	v_lshlrev_b64 v[11:12], 3, v[11:12]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s6, v7
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v5, vcc_lo, s6, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v6, vcc_lo
	s_clause 0x1
	global_load_b64 v[9:10], v[1:2], off offset:8
	global_load_b128 v[1:4], v[1:2], off offset:-8
	v_add_co_u32 v11, vcc_lo, s6, v11
	global_load_b64 v[5:6], v[5:6], off
	v_add_co_ci_u32_e32 v12, vcc_lo, s7, v12, vcc_lo
	s_load_b64 s[0:1], s[0:1], 0x0
	global_load_b64 v[11:12], v[11:12], off offset:2048
	s_waitcnt vmcnt(2)
	v_fma_f64 v[9:10], v[3:4], -4.0, v[9:10]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_add_f64 v[0:1], v[9:10], v[1:2]
	v_add_co_u32 v2, vcc_lo, s4, v7
	s_waitcnt vmcnt(1)
	v_add_f64 v[0:1], v[0:1], v[5:6]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f64 v[0:1], v[0:1], v[11:12]
	s_waitcnt lgkmcnt(0)
	v_fma_f64 v[0:1], s[0:1], v[0:1], v[3:4]
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v8, vcc_lo
	global_store_b64 v[2:3], v[0:1], off
.LBB1_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15update_solutionPdS_S_
		.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 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_end1:
	.size	_Z15update_solutionPdS_S_, .Lfunc_end1-_Z15update_solutionPdS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 368
; 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 : 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	_Z11copy_arraysPdS_     ; -- Begin function _Z11copy_arraysPdS_
	.globl	_Z11copy_arraysPdS_
	.p2align	8
	.type	_Z11copy_arraysPdS_,@function
_Z11copy_arraysPdS_:                    ; @_Z11copy_arraysPdS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s4, 0xffff
	s_lshr_b32 s4, s4, 16
	s_mul_i32 s14, s14, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_lshl_u32 v1, s14, v1, 8
	v_mad_u64_u32 v[3:4], null, s15, s4, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[0:1], 3, v[1:2]
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[2:3], 3, v[3:4]
	v_add_co_u32 v4, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v1, vcc_lo
	v_add_co_u32 v4, vcc_lo, v4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, v5, v3, vcc_lo
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_load_b64 v[4:5], v[4:5], off
	v_add_co_u32 v0, vcc_lo, v0, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b64 v[0:1], v[4:5], off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11copy_arraysPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 6
		.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_end2:
	.size	_Z11copy_arraysPdS_, .Lfunc_end2-_Z11copy_arraysPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 196
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z26update_periodic_boundariesPd
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z26update_periodic_boundariesPd.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .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:           _Z15update_solutionPdS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15update_solutionPdS_S_.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
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11copy_arraysPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11copy_arraysPdS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
