#include<iostream>
#include<iomanip>
#include<fstream>
#include<vector>
#include<utility>
#include<chrono>

#include<cstdlib>
#include<cstdio>
#include<cmath>

/*Not sure where the memory allocater resides*/
#include<cuda.h>

#define pi 4.0*atan(1.0)
#define blockDim_x 128
#define blockDim_y 8

using namespace std;
using namespace std::chrono;

/*
__global__ void add(int N, float *x, float *y){

  int index = blockIdx.x*blockDim.x + threadIdx.x;
  int stride = blockDim.x*gridDim.x;
  for(int i=index; i<N; i+=stride){
    y[i] = x[i] + y[i];
  }
}
*/

//monolithic kernel
__global__  void  cuda_diffusion2d_0
(
   float    *f,         /* dependent variable                        */
   float    *fn,        /* dependent variable                        */
   int      nx,         /* grid number in the x-direction            */
   int      ny,         /* grid number in the x-direction            */
   float    c0,         /* coefficient no.0                          */
   float    c1,         /* coefficient no.1                          */
   float    c2          /* coefficient no.2                          */
)
{
   int    j,    jx,   jy;
   float  fcc,  fce,  fcw,  fcs,  fcn;

   jy = blockDim.y*blockIdx.y + threadIdx.y;
   jx = blockDim.x*blockIdx.x + threadIdx.x;

   //Dirichilet BC
if(jx > 0  && jx < nx-1){
if(jy > 0 && jy < ny-1){
   j = nx*jy + jx;
   fcc = f[j];
   fcw = f[j - 1];
   fce = f[j+1];
   fcs = f[j-nx];
   fcn = f[j+nx];

   fn[j] = c0*(fce + fcw)
         + c1*(fcn + fcs)
         + c2*fcc;
 }
 }
   
}

int main()
{

  int nx;
  int ny;
  cout<<"Enter nx, ny "<<endl;
  cin>>nx;
  cin>>ny;
  
  float dx = 1.0/(float)(nx-1);
  float dy = 1.0/(float)(ny-1);
  float dt = 0.01*(dx*dx);

  //allocate arrays and initial condition
  //using unified memory
  float *Told, *Tnew;
  cudaMallocManaged(&Told,(nx*ny)*sizeof(float));
  cudaMallocManaged(&Tnew,(nx*ny)*sizeof(float));

  for(int i=0; i<nx; i++){
    for(int j=0; j<ny; j++){
      int id = i*ny + j;
      Told[id] = sin((float)i*dx*pi)*sin((float)j*dy*pi);
      Tnew[id] = 0.0f;
    }
  }

  float kappa = 1.0;
  float c0 = kappa*dt/(dx*dx),
        c1 = kappa*dt/(dy*dy),
        c2 = 1.0 - 2.0*(c0 + c1);
  
  int gridX = nx/blockDim_x;
  int gridY = ny/blockDim_y;

  //CUDA specific object type
  dim3 grid(gridX,gridY,1), threads(blockDim_x,blockDim_y,1);

  //time loop
  int iter = 0;
  int itermax = 10000;
  int steps =1000;
  double operation = 0.0;

  high_resolution_clock::time_point t1 =
    high_resolution_clock::now();
  
  do{

    //Updated 2017/7/26
    for(int i = 0; i<steps; ++i){
  //run kernel on gpu
  cuda_diffusion2d_0<<<grid,threads>>>(Told,Tnew,nx,ny,c0,c1,c2);
  swap(Told,Tnew);
    }

  cout<<"Step dum: "<<iter+steps<<endl;
  operation += 7.0*(double)ny *(double)nx*(double)steps;
  iter +=steps;
    
  }while(iter<itermax-steps+1);

  high_resolution_clock::time_point t2 =
    high_resolution_clock::now();

  duration<double> elapsed_time = duration_cast<duration<double> >(t2-t1);

  cout<<"Operations : "<<operation<<endl;
  cout<<"Elapsed time : "<<elapsed_time.count()<<" secs."<<endl;
  double flops = operation /(elapsed_time.count()*1e9);
  cout<<"Performance : "<<flops<<" GFLOPS"<<endl;
  
  //synchronize host-gpu memory for file output
  cudaDeviceSynchronize();
  
  //ouput result to .csv file
  ofstream fileOut;
  fileOut.open("/mnt/RAM_disk/cudaUnifiedMemHeatEq.csv");
  fileOut<<"x,y,z,T\n";
  for(int i=0; i<nx; ++i){
    for(int j=0; j<ny; ++j){
      int id = i*ny + j;
      float xg = (float)i*dx;
      float yg = (float)j*dy;
      fileOut<<setprecision(8);
      fileOut<<fixed;
      fileOut<<xg<<","
	     <<yg<<","
	     <<Told[id]<<","
	     <<Told[id]<<"\n";
    }
  }
  fileOut.close();


  //free memory
  cudaFree(Told);
  cudaFree(Tnew);

  return 0;
  
}

	.file	"tmpxft_003a199e_00000000-6_Heat2D-UnifiedMemory.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4474:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4474:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5236:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5236:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff
	.type	_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff, @function
_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff:
.LFB4496:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 28(%rsp)
	leaq	48(%rsp), %rdx
	movl	%ecx, 24(%rsp)
	leaq	56(%rsp), %rcx
	movss	%xmm0, 20(%rsp)
	movss	%xmm1, 16(%rsp)
	movss	%xmm2, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L3
	pushq	56(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z18cuda_diffusion2d_0PfS_iifff(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 208
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L3:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4496:
	.size	_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff, .-_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff
	.globl	_Z18cuda_diffusion2d_0PfS_iifff
	.type	_Z18cuda_diffusion2d_0PfS_iifff, @function
_Z18cuda_diffusion2d_0PfS_iifff:
.LFB4497:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff
	.cfi_endproc
.LFE4497:
	.size	_Z18cuda_diffusion2d_0PfS_iifff, .-_Z18cuda_diffusion2d_0PfS_iifff
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"_Z18cuda_diffusion2d_0PfS_iifff"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4499:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC0(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z18cuda_diffusion2d_0PfS_iifff(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4499:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.rodata.str1.1
.LC2:
	.string	"Enter nx, ny "
.LC9:
	.string	"Step dum: "
.LC13:
	.string	"Operations : "
.LC14:
	.string	"Elapsed time : "
.LC15:
	.string	" secs."
.LC16:
	.string	"Performance : "
.LC17:
	.string	" GFLOPS"
.LC18:
	.string	"/mnt/RAM_disk/cudaUnifiedMemHeatEq.csv"
.LC19:
	.string	"x,y,z,T\n"
.LC20:
	.string	","
.LC21:
	.string	"\n"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4467:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4467
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	_ZSt3cin(%rip), %rbx
	subq	$632, %rsp
	.cfi_def_cfa_offset 688
	movq	%fs:40, %rax
	movq	%rax, 616(%rsp)
	xorl	%eax, %eax
.LEHB0:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	%rbx, %rdi
	leaq	56(%rsp), %rsi
	call	_ZNSirsERi@PLT
	movq	%rbx, %rdi
	leaq	60(%rsp), %rsi
	call	_ZNSirsERi@PLT
	movl	56(%rsp), %esi
	leaq	64(%rsp), %rdi
	movss	.LC3(%rip), %xmm0
	leal	-1(%rsi), %eax
	movaps	%xmm0, %xmm3
	cvtsi2ssl	%eax, %xmm1
	movl	60(%rsp), %eax
	imull	%eax, %esi
	leal	-1(%rax), %edx
	divss	%xmm1, %xmm3
	cvtsi2ssl	%edx, %xmm1
	movl	$1, %edx
	movslq	%esi, %rsi
	salq	$2, %rsi
	divss	%xmm1, %xmm0
	movaps	%xmm3, %xmm4
	movss	%xmm3, 12(%rsp)
	mulss	%xmm3, %xmm4
	movss	%xmm4, (%rsp)
	movss	%xmm0, 24(%rsp)
	cvtss2sd	%xmm4, %xmm0
	mulsd	.LC4(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm2
	movss	%xmm2, 28(%rsp)
	call	cudaMallocManaged@PLT
	movl	56(%rsp), %esi
	imull	60(%rsp), %esi
	movl	$1, %edx
	leaq	72(%rsp), %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMallocManaged@PLT
	movl	56(%rsp), %eax
	movl	60(%rsp), %r14d
	xorl	%edx, %edx
	movq	64(%rsp), %r13
	movq	72(%rsp), %rbx
	movl	%eax, 16(%rsp)
	xorl	%eax, %eax
.L12:
	cmpl	%eax, 16(%rsp)
	jle	.L14
	movslq	%edx, %rbp
	xorl	%r15d, %r15d
	salq	$2, %rbp
	leaq	0(%r13,%rbp), %r12
	addq	%rbx, %rbp
.L15:
	cmpl	%r15d, %r14d
	jle	.L33
	cvtsi2ssl	%eax, %xmm0
	mulss	12(%rsp), %xmm0
	movl	%edx, 44(%rsp)
	movl	%eax, 40(%rsp)
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC5(%rip), %xmm0
	mulsd	.LC6(%rip), %xmm0
	call	sin@PLT
	movsd	%xmm0, 32(%rsp)
	cvtsi2ssl	%r15d, %xmm0
	mulss	24(%rsp), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC5(%rip), %xmm0
	mulsd	.LC6(%rip), %xmm0
	call	sin@PLT
	mulsd	32(%rsp), %xmm0
	movl	44(%rsp), %edx
	movl	40(%rsp), %eax
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%r15,4)
	movl	$0x00000000, 0(%rbp,%r15,4)
	incq	%r15
	jmp	.L15
.L33:
	incl	%eax
	addl	%r14d, %edx
	jmp	.L12
.L14:
	movl	16(%rsp), %eax
	movl	$128, %ecx
	xorl	%ebp, %ebp
	movss	24(%rsp), %xmm0
	movss	28(%rsp), %xmm6
	movss	28(%rsp), %xmm5
	divss	(%rsp), %xmm5
	movl	$1, 88(%rsp)
	cltd
	movsd	.LC8(%rip), %xmm1
	movl	$1, 100(%rsp)
	idivl	%ecx
	movss	%xmm5, 32(%rsp)
	mulss	%xmm0, %xmm0
	movl	$8, %ecx
	divss	%xmm0, %xmm6
	movaps	%xmm5, %xmm0
	movl	%eax, 80(%rsp)
	movl	%r14d, %eax
	leaq	.LC9(%rip), %r14
	cltd
	idivl	%ecx
	movss	%xmm6, 28(%rsp)
	addss	%xmm6, %xmm0
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm0
	subsd	%xmm0, %xmm1
	cvtsd2ss	%xmm1, %xmm7
	movd	%xmm7, %ebx
	movl	%eax, 84(%rsp)
	movl	$268435457, %eax
	salq	$7, %rax
	movq	%rax, 92(%rsp)
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	$0x000000000, (%rsp)
	movq	%rax, %r13
.L18:
	movl	$1000, %r15d
.L17:
	movl	100(%rsp), %ecx
	movq	92(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L16
	movss	28(%rsp), %xmm1
	movss	32(%rsp), %xmm0
	movd	%ebx, %xmm2
	movl	60(%rsp), %ecx
	movl	56(%rsp), %edx
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z45__device_stub__Z18cuda_diffusion2d_0PfS_iifffPfS_iifff
.L16:
	movq	64(%rsp), %rax
	movq	72(%rsp), %rdx
	movq	%rax, 72(%rsp)
	movq	%rdx, 64(%rsp)
	decl	%r15d
	jne	.L17
	movq	%r14, %rsi
	leaq	_ZSt4cout(%rip), %rdi
	addl	$1000, %ebp
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	cvtsi2sdl	60(%rsp), %xmm0
	mulsd	.LC10(%rip), %xmm0
	cvtsi2sdl	56(%rsp), %xmm1
	mulsd	%xmm1, %xmm0
	mulsd	.LC11(%rip), %xmm0
	addsd	(%rsp), %xmm0
	movsd	%xmm0, (%rsp)
	cmpl	$10000, %ebp
	jne	.L18
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	leaq	.LC13(%rip), %rsi
	leaq	104(%rsp), %rbp
	subq	%r13, %rax
	leaq	_ZSt4cout(%rip), %rdi
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC12(%rip), %xmm0
	movsd	%xmm0, 16(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	.LC14(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	16(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC15(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movsd	.LC12(%rip), %xmm1
	mulsd	16(%rsp), %xmm1
	leaq	.LC16(%rip), %rsi
	movsd	(%rsp), %xmm0
	leaq	_ZSt4cout(%rip), %rdi
	divsd	%xmm1, %xmm0
	movsd	%xmm0, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC17(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	call	cudaDeviceSynchronize@PLT
	movq	%rbp, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev@PLT
.LEHE0:
	movl	$16, %edx
	leaq	.LC18(%rip), %rsi
	movq	%rbp, %rdi
.LEHB1:
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode@PLT
	leaq	.LC19(%rip), %rsi
	movq	%rbp, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	xorl	%r12d, %r12d
	leaq	.LC20(%rip), %r15
.L19:
	cmpl	%r12d, 56(%rsp)
	jle	.L34
	xorl	%r13d, %r13d
.L21:
	movl	60(%rsp), %ebx
	cmpl	%r13d, %ebx
	jle	.L35
	movq	104(%rsp), %rax
	cvtsi2ssl	%r13d, %xmm0
	mulss	24(%rsp), %xmm0
	movq	%rbp, %rdi
	imull	%r12d, %ebx
	movq	-24(%rax), %rdx
	movq	$8, 112(%rsp,%rdx)
	movq	-24(%rax), %rdx
	addl	%r13d, %ebx
	movd	%xmm0, %r14d
	cvtsi2ssl	%r12d, %xmm0
	mulss	12(%rsp), %xmm0
	addq	%rbp, %rdx
	movl	24(%rdx), %eax
	andl	$-261, %eax
	orl	$4, %eax
	movl	%eax, 24(%rdx)
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	movq	%r15, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movd	%r14d, %xmm6
	movq	%rax, %rdi
	cvtss2sd	%xmm6, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	movq	%r15, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movq	64(%rsp), %rax
	movslq	%ebx, %rbx
	cvtss2sd	(%rax,%rbx,4), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	movq	%r15, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movq	64(%rsp), %rax
	cvtss2sd	(%rax,%rbx,4), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC21(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	incl	%r13d
	jmp	.L21
.L35:
	incl	%r12d
	jmp	.L19
.L34:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
.LEHE1:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	616(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	jmp	.L31
.L27:
	endbr64
	movq	%rax, %rbx
.L22:
	movq	%rbp, %rdi
	call	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	616(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L31
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L31:
	call	__stack_chk_fail@PLT
.L24:
	addq	$632, %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
.LFE4467:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4467:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4467-.LLSDACSB4467
.LLSDACSB4467:
	.uleb128 .LEHB0-.LFB4467
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB4467
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L27-.LFB4467
	.uleb128 0
	.uleb128 .LEHB2-.LFB4467
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE4467:
	.section	.text.startup
	.size	main, .-main
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC3:
	.long	1065353216
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	1202590843
	.long	1065646817
	.align 8
.LC5:
	.long	0
	.long	1074790400
	.align 8
.LC6:
	.long	1413754136
	.long	1072243195
	.align 8
.LC8:
	.long	0
	.long	1072693248
	.align 8
.LC10:
	.long	0
	.long	1075576832
	.align 8
.LC11:
	.long	0
	.long	1083129856
	.align 8
.LC12:
	.long	0
	.long	1104006501
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include<iostream>
#include<iomanip>
#include<fstream>
#include<vector>
#include<utility>
#include<chrono>

#include<cstdlib>
#include<cstdio>
#include<cmath>

/*Not sure where the memory allocater resides*/
#include<hip/hip_runtime.h>

#define pi 4.0*atan(1.0)
#define blockDim_x 128
#define blockDim_y 8

using namespace std;
using namespace std::chrono;

/*
__global__ void add(int N, float *x, float *y){

  int index = blockIdx.x*blockDim.x + threadIdx.x;
  int stride = blockDim.x*gridDim.x;
  for(int i=index; i<N; i+=stride){
    y[i] = x[i] + y[i];
  }
}
*/

//monolithic kernel
__global__  void  cuda_diffusion2d_0
(
   float    *f,         /* dependent variable                        */
   float    *fn,        /* dependent variable                        */
   int      nx,         /* grid number in the x-direction            */
   int      ny,         /* grid number in the x-direction            */
   float    c0,         /* coefficient no.0                          */
   float    c1,         /* coefficient no.1                          */
   float    c2          /* coefficient no.2                          */
)
{
   int    j,    jx,   jy;
   float  fcc,  fce,  fcw,  fcs,  fcn;

   jy = blockDim.y*blockIdx.y + threadIdx.y;
   jx = blockDim.x*blockIdx.x + threadIdx.x;

   //Dirichilet BC
if(jx > 0  && jx < nx-1){
if(jy > 0 && jy < ny-1){
   j = nx*jy + jx;
   fcc = f[j];
   fcw = f[j - 1];
   fce = f[j+1];
   fcs = f[j-nx];
   fcn = f[j+nx];

   fn[j] = c0*(fce + fcw)
         + c1*(fcn + fcs)
         + c2*fcc;
 }
 }
   
}

int main()
{

  int nx;
  int ny;
  cout<<"Enter nx, ny "<<endl;
  cin>>nx;
  cin>>ny;
  
  float dx = 1.0/(float)(nx-1);
  float dy = 1.0/(float)(ny-1);
  float dt = 0.01*(dx*dx);

  //allocate arrays and initial condition
  //using unified memory
  float *Told, *Tnew;
  hipMallocManaged(&Told,(nx*ny)*sizeof(float));
  hipMallocManaged(&Tnew,(nx*ny)*sizeof(float));

  for(int i=0; i<nx; i++){
    for(int j=0; j<ny; j++){
      int id = i*ny + j;
      Told[id] = sin((float)i*dx*pi)*sin((float)j*dy*pi);
      Tnew[id] = 0.0f;
    }
  }

  float kappa = 1.0;
  float c0 = kappa*dt/(dx*dx),
        c1 = kappa*dt/(dy*dy),
        c2 = 1.0 - 2.0*(c0 + c1);
  
  int gridX = nx/blockDim_x;
  int gridY = ny/blockDim_y;

  //CUDA specific object type
  dim3 grid(gridX,gridY,1), threads(blockDim_x,blockDim_y,1);

  //time loop
  int iter = 0;
  int itermax = 10000;
  int steps =1000;
  double operation = 0.0;

  high_resolution_clock::time_point t1 =
    high_resolution_clock::now();
  
  do{

    //Updated 2017/7/26
    for(int i = 0; i<steps; ++i){
  //run kernel on gpu
  cuda_diffusion2d_0<<<grid,threads>>>(Told,Tnew,nx,ny,c0,c1,c2);
  swap(Told,Tnew);
    }

  cout<<"Step dum: "<<iter+steps<<endl;
  operation += 7.0*(double)ny *(double)nx*(double)steps;
  iter +=steps;
    
  }while(iter<itermax-steps+1);

  high_resolution_clock::time_point t2 =
    high_resolution_clock::now();

  duration<double> elapsed_time = duration_cast<duration<double> >(t2-t1);

  cout<<"Operations : "<<operation<<endl;
  cout<<"Elapsed time : "<<elapsed_time.count()<<" secs."<<endl;
  double flops = operation /(elapsed_time.count()*1e9);
  cout<<"Performance : "<<flops<<" GFLOPS"<<endl;
  
  //synchronize host-gpu memory for file output
  hipDeviceSynchronize();
  
  //ouput result to .csv file
  ofstream fileOut;
  fileOut.open("/mnt/RAM_disk/cudaUnifiedMemHeatEq.csv");
  fileOut<<"x,y,z,T\n";
  for(int i=0; i<nx; ++i){
    for(int j=0; j<ny; ++j){
      int id = i*ny + j;
      float xg = (float)i*dx;
      float yg = (float)j*dy;
      fileOut<<setprecision(8);
      fileOut<<fixed;
      fileOut<<xg<<","
	     <<yg<<","
	     <<Told[id]<<","
	     <<Told[id]<<"\n";
    }
  }
  fileOut.close();


  //free memory
  hipFree(Told);
  hipFree(Tnew);

  return 0;
  
}

	.text
	.file	"Heat2D-UnifiedMemory.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z33__device_stub__cuda_diffusion2d_0PfS_iifff # -- Begin function _Z33__device_stub__cuda_diffusion2d_0PfS_iifff
	.type	_Z33__device_stub__cuda_diffusion2d_0PfS_iifff,@function
_Z33__device_stub__cuda_diffusion2d_0PfS_iifff: # @_Z33__device_stub__cuda_diffusion2d_0PfS_iifff
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	28(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	24(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	20(%rsp), %rcx
	movss	%xmm0, (%rcx)
	leaq	16(%rsp), %r8
	movss	%xmm1, (%r8)
	leaq	12(%rsp), %r9
	movss	%xmm2, (%r9)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	movq	%r9, 48(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	40(%rsp), %r12
	leaq	32(%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	$_Z18cuda_diffusion2d_0PfS_iifff, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z33__device_stub__cuda_diffusion2d_0PfS_iifff, .Lfunc_end0-_Z33__device_stub__cuda_diffusion2d_0PfS_iifff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x3f800000                      # float 1
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_1:
	.quad	0x3f847ae147ae147b              # double 0.01
.LCPI1_2:
	.quad	0x4010000000000000              # double 4
.LCPI1_3:
	.quad	0x3fe921fb54442d18              # double 0.78539816339744828
.LCPI1_4:
	.quad	0x3ff0000000000000              # double 1
.LCPI1_5:
	.quad	0x401c000000000000              # double 7
.LCPI1_6:
	.quad	0x408f400000000000              # double 1000
.LCPI1_7:
	.quad	0x41cdcd6500000000              # double 1.0E+9
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$584, %rsp                      # imm = 0x248
	.cfi_def_cfa_offset 640
	.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	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	leaq	12(%rsp), %rbx
	movl	$_ZSt3cin, %edi
	movq	%rbx, %rsi
	callq	_ZNSirsERi
	leaq	8(%rsp), %r14
	movl	$_ZSt3cin, %edi
	movq	%r14, %rsi
	callq	_ZNSirsERi
	movl	(%rbx), %eax
	leal	-1(%rax), %ecx
	cvtsi2ss	%ecx, %xmm0
	movss	.LCPI1_0(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movaps	%xmm2, %xmm3
	movl	(%r14), %ecx
	leal	-1(%rcx), %edx
	cvtsi2ss	%edx, %xmm1
	divss	%xmm0, %xmm3
	movss	%xmm3, 60(%rsp)                 # 4-byte Spill
	mulss	%xmm3, %xmm3
	movss	%xmm3, 16(%rsp)                 # 4-byte Spill
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm3, %xmm0
	mulsd	.LCPI1_1(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 44(%rsp)                 # 4-byte Spill
	divss	%xmm1, %xmm2
	movss	%xmm2, 4(%rsp)                  # 4-byte Spill
	imull	%eax, %ecx
	movslq	%ecx, %rsi
	shlq	$2, %rsi
	leaq	32(%rsp), %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movslq	(%rbx), %rax
	movslq	(%r14), %rsi
	imulq	%rax, %rsi
	shlq	$2, %rsi
	leaq	48(%rsp), %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movl	(%rbx), %eax
	movl	(%r14), %r14d
	testl	%eax, %eax
	jle	.LBB1_1
# %bb.2:                                # %.preheader94.preheader
	xorl	%ebx, %ebx
	movsd	.LCPI1_2(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI1_3(%rip), %xmm2           # xmm2 = mem[0],zero
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
.LBB1_3:                                # %.preheader94
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
	testl	%r14d, %r14d
	jle	.LBB1_7
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB1_3 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebx, %xmm0
	mulss	60(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm0
	mulsd	%xmm2, %xmm0
	movsd	%xmm0, 64(%rsp)                 # 8-byte Spill
	xorl	%r15d, %r15d
.LBB1_5:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	64(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r15d, %xmm0
	mulss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI1_2(%rip), %xmm0
	mulsd	.LCPI1_3(%rip), %xmm0
	callq	sin
	mulsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	cvtsd2ss	%xmm0, %xmm0
	movq	32(%rsp), %rax
	imull	%ebx, %r14d
	movslq	%r14d, %rcx
	addq	%r15, %rcx
	movss	%xmm0, (%rax,%rcx,4)
	movq	48(%rsp), %rax
	movl	$0, (%rax,%rcx,4)
	movl	8(%rsp), %r14d
	incq	%r15
	cmpl	%r14d, %r15d
	jl	.LBB1_5
# %bb.6:                                # %._crit_edge.loopexit
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	12(%rsp), %eax
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movsd	.LCPI1_2(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI1_3(%rip), %xmm2           # xmm2 = mem[0],zero
.LBB1_7:                                # %._crit_edge
                                        #   in Loop: Header=BB1_3 Depth=1
	incl	%ebx
	cmpl	%eax, %ebx
	jl	.LBB1_3
	jmp	.LBB1_8
.LBB1_1:
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
.LBB1_8:                                # %._crit_edge98
	movss	44(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movaps	%xmm1, %xmm2
	divss	16(%rsp), %xmm2                 # 4-byte Folded Reload
	mulss	%xmm0, %xmm0
	divss	%xmm0, %xmm1
	movss	%xmm2, 24(%rsp)                 # 4-byte Spill
	movaps	%xmm2, %xmm0
	movss	%xmm1, 44(%rsp)                 # 4-byte Spill
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm0, %xmm0
	movsd	.LCPI1_4(%rip), %xmm1           # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtsd2ss	%xmm1, %xmm0
	movss	%xmm0, 64(%rsp)                 # 4-byte Spill
	leal	127(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	sarl	$7, %ecx
	leal	7(%r14), %ebx
	testl	%r14d, %r14d
	cmovnsl	%r14d, %ebx
	sarl	$3, %ebx
	shlq	$32, %rbx
	orq	%rcx, %rbx
	xorl	%r13d, %r13d
	xorps	%xmm0, %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r14
	movabsq	$34359738496, %r15              # imm = 0x800000080
.LBB1_9:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_10 Depth 2
	movl	$1000, %ebp                     # imm = 0x3E8
.LBB1_10:                               #   Parent Loop BB1_9 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.11:                               #   in Loop: Header=BB1_10 Depth=2
	movq	32(%rsp), %rdi
	movq	48(%rsp), %rsi
	movl	12(%rsp), %edx
	movl	8(%rsp), %ecx
	movss	24(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	44(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movss	64(%rsp), %xmm2                 # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	callq	_Z33__device_stub__cuda_diffusion2d_0PfS_iifff
.LBB1_12:                               #   in Loop: Header=BB1_10 Depth=2
	movq	32(%rsp), %rax
	movq	48(%rsp), %rcx
	movq	%rcx, 32(%rsp)
	movq	%rax, 48(%rsp)
	decl	%ebp
	jne	.LBB1_10
# %bb.13:                               #   in Loop: Header=BB1_9 Depth=1
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leal	1000(%r13), %ebp
	movl	$_ZSt4cout, %edi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movq	%rax, %r12
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r12, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r12, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorps	%xmm0, %xmm0
	cvtsi2sdl	8(%rsp), %xmm0
	mulsd	.LCPI1_5(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdl	12(%rsp), %xmm1
	mulsd	%xmm0, %xmm1
	mulsd	.LCPI1_6(%rip), %xmm1
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	cmpl	$8001, %r13d                    # imm = 0x1F41
	movl	%ebp, %r13d
	jb	.LBB1_9
# %bb.14:
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%r14, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI1_7(%rip), %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$13, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$15, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.4, %esi
	movl	$6, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	mulsd	.LCPI1_7(%rip), %xmm0
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$14, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.6, %esi
	movl	$7, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	callq	hipDeviceSynchronize
	leaq	72(%rsp), %rbx
	movq	%rbx, %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1Ev
.Ltmp0:
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movl	$16, %edx
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE4openEPKcSt13_Ios_Openmode
.Ltmp1:
# %bb.15:
.Ltmp2:
	leaq	72(%rsp), %rdi
	movl	$.L.str.8, %esi
	movl	$8, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp3:
# %bb.16:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit.preheader
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.LBB1_31
# %bb.17:                               # %.preheader.lr.ph
	xorl	%ebp, %ebp
	movl	8(%rsp), %r13d
	movl	$-261, %r15d                    # imm = 0xFEFB
	leaq	72(%rsp), %rbx
.LBB1_18:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_20 Depth 2
	testl	%r13d, %r13d
	jle	.LBB1_30
# %bb.19:                               # %.lr.ph103
                                        #   in Loop: Header=BB1_18 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%ebp, %xmm0
	mulss	60(%rsp), %xmm0                 # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	xorl	%r12d, %r12d
.LBB1_20:                               #   Parent Loop BB1_18 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	72(%rsp), %rax
	movq	-24(%rax), %rcx
	movq	$8, 80(%rsp,%rcx)
	movq	-24(%rax), %rax
	movl	96(%rsp,%rax), %ecx
	andl	%r15d, %ecx
	orl	$4, %ecx
	movl	%ecx, 96(%rsp,%rax)
.Ltmp4:
	movq	%rbx, %rdi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp5:
# %bb.21:                               # %_ZNSolsEf.exit
                                        #   in Loop: Header=BB1_20 Depth=2
.Ltmp6:
	movq	%rax, %r14
	movl	$.L.str.9, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp7:
# %bb.22:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit80
                                        #   in Loop: Header=BB1_20 Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%r12d, %xmm0
	mulss	4(%rsp), %xmm0                  # 4-byte Folded Reload
	cvtss2sd	%xmm0, %xmm0
.Ltmp8:
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp9:
# %bb.23:                               # %_ZNSolsEf.exit81
                                        #   in Loop: Header=BB1_20 Depth=2
.Ltmp10:
	movq	%rax, %r14
	movl	$.L.str.9, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp11:
# %bb.24:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit82
                                        #   in Loop: Header=BB1_20 Depth=2
	imull	%ebp, %r13d
	addl	%r12d, %r13d
	movq	32(%rsp), %rax
	movslq	%r13d, %r13
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax,%r13,4), %xmm0
.Ltmp12:
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp13:
# %bb.25:                               # %_ZNSolsEf.exit83
                                        #   in Loop: Header=BB1_20 Depth=2
.Ltmp14:
	movq	%rax, %r14
	movl	$.L.str.9, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp15:
# %bb.26:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit84
                                        #   in Loop: Header=BB1_20 Depth=2
	movq	32(%rsp), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax,%r13,4), %xmm0
.Ltmp16:
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp17:
# %bb.27:                               # %_ZNSolsEf.exit85
                                        #   in Loop: Header=BB1_20 Depth=2
.Ltmp18:
	movl	$.L.str.10, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp19:
# %bb.28:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit86
                                        #   in Loop: Header=BB1_20 Depth=2
	incl	%r12d
	movl	8(%rsp), %r13d
	cmpl	%r13d, %r12d
	jl	.LBB1_20
# %bb.29:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit.loopexit
                                        #   in Loop: Header=BB1_18 Depth=1
	movl	12(%rsp), %eax
.LBB1_30:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
                                        #   in Loop: Header=BB1_18 Depth=1
	incl	%ebp
	cmpl	%eax, %ebp
	jl	.LBB1_18
.LBB1_31:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit._crit_edge
.Ltmp21:
	leaq	72(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEE5closeEv
.Ltmp22:
# %bb.32:
	movq	32(%rsp), %rdi
.Ltmp23:
	callq	hipFree
.Ltmp24:
# %bb.33:
	movq	48(%rsp), %rdi
.Ltmp25:
	callq	hipFree
.Ltmp26:
# %bb.34:
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE(%rip), %rax
	leaq	80(%rsp), %rdi
	movq	%rax, -8(%rdi)
	movq	_ZTTSt14basic_ofstreamIcSt11char_traitsIcEE+24(%rip), %rcx
	movq	-24(%rax), %rax
	movq	%rcx, 72(%rsp,%rax)
	callq	_ZNSt13basic_filebufIcSt11char_traitsIcEED2Ev
	leaq	320(%rsp), %rdi
	callq	_ZNSt8ios_baseD2Ev
	xorl	%eax, %eax
	addq	$584, %rsp                      # imm = 0x248
	.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
.LBB1_35:
	.cfi_def_cfa_offset 640
.Ltmp27:
	jmp	.LBB1_36
.LBB1_37:
.Ltmp20:
.LBB1_36:
	movq	%rax, %rbx
	leaq	72(%rsp), %rdi
	callq	_ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table1:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp3-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp3
	.uleb128 .Ltmp27-.Lfunc_begin0          #     jumps to .Ltmp27
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp4-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp19-.Ltmp4                 #   Call between .Ltmp4 and .Ltmp19
	.uleb128 .Ltmp20-.Lfunc_begin0          #     jumps to .Ltmp20
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp21-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp26-.Ltmp21                #   Call between .Ltmp21 and .Ltmp26
	.uleb128 .Ltmp27-.Lfunc_begin0          #     jumps to .Ltmp27
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp26-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Lfunc_end1-.Ltmp26            #   Call between .Ltmp26 and .Lfunc_end1
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18cuda_diffusion2d_0PfS_iifff, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z18cuda_diffusion2d_0PfS_iifff,@object # @_Z18cuda_diffusion2d_0PfS_iifff
	.section	.rodata,"a",@progbits
	.globl	_Z18cuda_diffusion2d_0PfS_iifff
	.p2align	3, 0x0
_Z18cuda_diffusion2d_0PfS_iifff:
	.quad	_Z33__device_stub__cuda_diffusion2d_0PfS_iifff
	.size	_Z18cuda_diffusion2d_0PfS_iifff, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Enter nx, ny "
	.size	.L.str, 14

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Step dum: "
	.size	.L.str.1, 11

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Elapsed time : "
	.size	.L.str.3, 16

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Performance : "
	.size	.L.str.5, 15

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	" GFLOPS"
	.size	.L.str.6, 8

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"/mnt/RAM_disk/cudaUnifiedMemHeatEq.csv"
	.size	.L.str.7, 39

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"x,y,z,T\n"
	.size	.L.str.8, 9

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"\n"
	.size	.L.str.10, 2

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18cuda_diffusion2d_0PfS_iifff"
	.size	.L__unnamed_1, 32

	.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 _Z33__device_stub__cuda_diffusion2d_0PfS_iifff
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z18cuda_diffusion2d_0PfS_iifff
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZSt3cin
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18cuda_diffusion2d_0PfS_iifff ; -- Begin function _Z18cuda_diffusion2d_0PfS_iifff
	.globl	_Z18cuda_diffusion2d_0PfS_iifff
	.p2align	8
	.type	_Z18cuda_diffusion2d_0PfS_iifff,@function
_Z18cuda_diffusion2d_0PfS_iifff:        ; @_Z18cuda_diffusion2d_0PfS_iifff
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b128 s[8:11], s[0:1], 0x10
	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_add_i32 s2, s8, -1
	s_add_i32 s3, s9, -1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cmp_gt_i32_e32 vcc_lo, s2, v0
	v_cmp_lt_i32_e64 s4, 0, v0
	v_cmp_gt_i32_e64 s2, s3, v1
	v_cmp_lt_i32_e64 s3, 0, v1
	s_delay_alu instid0(VALU_DEP_2)
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, s4, s2
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_mad_u64_u32 v[2:3], null, v1, s8, v[0:1]
	s_load_b128 s[4:7], s[0:1], 0x0
	s_ashr_i32 s9, s8, 31
	s_load_b32 s0, s[0:1], 0x20
	s_lshl_b64 s[2:3], s[8:9], 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v0, s8, v2
	v_ashrrev_i32_e32 v3, 31, v2
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, v5, s2
	v_add_co_ci_u32_e32 v8, vcc_lo, s3, v6, vcc_lo
	s_clause 0x2
	global_load_b32 v9, v[0:1], off
	global_load_b32 v7, v[7:8], off
	global_load_b96 v[0:2], v[5:6], off offset:-4
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v5, v9, v7 :: v_dual_add_f32 v0, v0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v2, s11, v5
	v_fmac_f32_e32 v2, s10, v0
	v_add_co_u32 v0, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_fmac_f32_e32 v2, s0, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v4, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18cuda_diffusion2d_0PfS_iifff
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 10
		.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	_Z18cuda_diffusion2d_0PfS_iifff, .Lfunc_end0-_Z18cuda_diffusion2d_0PfS_iifff
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 356
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; 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:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18cuda_diffusion2d_0PfS_iifff
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18cuda_diffusion2d_0PfS_iifff.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
