/*
 *  Please write your name and net ID below
 *
 *  Last name: Will
 *  First name: Peter
 *  Net ID: pcw276
 *
 */


/*
 * This file contains the code for doing the heat distribution problem.
 * You do not need to modify anything except starting  gpu_heat_dist() at the bottom
 * of this file.
 * In gpu_heat_dist() you can organize your data structure and the call to your
 * kernel(s) that you need to write too.
 *
 * You compile with:
 * 		nvcc -o heatdist heatdist.cu
 */

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

/* To index element (i,j) of a 2D array stored as 1D */
#define index(i, j, N)  ((i)*(N)) + (j)

/*****************************************************************/

// Function declarations: Feel free to add any functions you want.
void  seq_heat_dist(float *, unsigned int, unsigned int);
void  gpu_heat_dist(float *, unsigned int, unsigned int);
__global__ void  heat_dist_kernel(float * in, float * out, unsigned int N);

/*****************************************************************/

int main(int argc, char * argv[])
{
  unsigned int N; /* Dimention of NxN matrix */
  int type_of_device = 0; // CPU or GPU
  int iterations = 0;
  int i;

  /* The 2D array of points will be treated as 1D array of NxN elements */
  float * playground;

  // to measure time taken by a specific part of the code
  double time_taken;
  clock_t start, end;

  if(argc != 4)
  {
    fprintf(stderr, "usage: heatdist num  iterations  who\n");
    fprintf(stderr, "num = dimension of the square matrix (50 and up)\n");
    fprintf(stderr, "iterations = number of iterations till stopping (1 and up)\n");
    fprintf(stderr, "who = 0: sequential code on CPU, 1: GPU execution\n");
    exit(1);
  }

  type_of_device = atoi(argv[3]);
  N = (unsigned int) atoi(argv[1]);
  iterations = (unsigned int) atoi(argv[2]);


  /* Dynamically allocate NxN array of floats */
  playground = (float *)calloc(N*N, sizeof(float));
  if( !playground )
  {
   fprintf(stderr, " Cannot allocate the %u x %u array\n", N, N);
   exit(1);
  }

  /* Initialize it: calloc already initalized everything to 0 */
  // Edge elements to 80F
  for(i = 0; i < N; i++)
    playground[index(0,i,N)] = 80;

  for(i = 0; i < N; i++)
    playground[index(i,0,N)] = 80;

  for(i = 0; i < N; i++)
    playground[index(i,N-1, N)] = 80;

  for(i = 0; i < N; i++)
    playground[index(N-1,i,N)] = 80;

  // from (0,10) to (0,30) inclusive are 150F
  for(i = 10; i <= 30; i++)
    playground[index(i,0,N)] = 150;


  if( !type_of_device ) // The CPU sequential version
  {
    start = clock();
    seq_heat_dist(playground, N, iterations);
    end = clock();
  }
  else  // The GPU version
  {
     start = clock();
     gpu_heat_dist(playground, N, iterations);
     end = clock();
  }


  time_taken = ((double)(end - start))/ CLOCKS_PER_SEC;

  printf("Time taken for %s is %lf\n", type_of_device == 0? "CPU" : "GPU", time_taken);
  printf("%.5f\n", playground[index(17,37,N)]);
  printf("%.5f\n", playground[index(324,53,N)]);
  printf("%.5f\n", playground[index(52,652,N)]);
  // for(i = 0; i < N; i++)
  // {
  //   for(int j = 0; j <N; j++)
  //   {
  //     printf("%.2f, ", playground[index(i,j,N)]);
  //   }
  //   printf("\n");
  // }
  free(playground);

  return 0;

}


/*****************  The CPU sequential version (DO NOT CHANGE THAT) **************/
void  seq_heat_dist(float * playground, unsigned int N, unsigned int iterations)
{
  // Loop indices
  int i, j, k;
  int upper = N-1;

  // number of bytes to be copied between array temp and array playground
  unsigned int num_bytes = 0;

  float * temp;
  /* Dynamically allocate another array for temp values */
  /* Dynamically allocate NxN array of floats */
  temp = (float *)calloc(N*N, sizeof(float));
  if( !temp )
  {
   fprintf(stderr, " Cannot allocate temp %u x %u array\n", N, N);
   exit(1);
  }

  num_bytes = N*N*sizeof(float);

  /* Copy initial array in temp */
  memcpy((void *)temp, (void *) playground, num_bytes);

  for( k = 0; k < iterations; k++)
  {
    /* Calculate new values and store them in temp */
    for(i = 1; i < upper; i++)
      for(j = 1; j < upper; j++)
	temp[index(i,j,N)] = (playground[index(i-1,j,N)] +
	                      playground[index(i+1,j,N)] +
			      playground[index(i,j-1,N)] +
			      playground[index(i,j+1,N)])/4.0;



    /* Move new values into old values */
    memcpy((void *)playground, (void *) temp, num_bytes);
  }

}

/***************** The GPU version: Write your code here *********************/
/* This function can call one or more kenels *********************************/
void  gpu_heat_dist(float * playground, unsigned int N, unsigned int iterations)
{

  dim3 dimGrid(ceil(N/16.0), ceil(N/16.0), 1);
  dim3 dimBlock(16, 16, 1);


  // number of bytes to be copied between array temp and array playground
  unsigned int num_bytes = N*N*sizeof(float);

  float * d_in;
  float * d_out;

  // cuda allocation in global memory with error checking
  cudaError_t err=cudaMalloc((void **) &d_in, num_bytes);
  if( err !=cudaSuccess)
  {
   fprintf(stderr, "%s in %s at line %d\n",
    cudaGetErrorString(err), __FILE__, __LINE__);
   exit(EXIT_FAILURE);
  }

  err=cudaMalloc((void **) &d_out, num_bytes);
  if( err !=cudaSuccess)
  {
   fprintf(stderr, "%s in %s at line %d\n",
    cudaGetErrorString(err), __FILE__, __LINE__);
   exit(EXIT_FAILURE);
  }

  /* Copy initial array in temp */
  cudaMemcpy(d_in, playground, num_bytes, cudaMemcpyHostToDevice);
  for (int k = 0; k < iterations; k++)
  {
    heat_dist_kernel<<<dimGrid, dimBlock>>>(d_in, d_out, N);
    cudaMemcpy(d_in, d_out, num_bytes, cudaMemcpyDeviceToDevice);
  }
  cudaMemcpy(playground, d_out, num_bytes, cudaMemcpyDeviceToHost);


}

/**************** The Kernal Function called by the GPU verison**********/
__global__
void heat_dist_kernel(float * in, float * out, unsigned int N)
{
  int Col = blockIdx.x * blockDim.x + threadIdx.x;
  int Row = blockIdx.y * blockDim.y + threadIdx.y;
  int upper = N-1;
  float temp = 0;
  int gridpoint = index(Col, Row, N);

  // test to see if we're on the borders
  if ((Col == 0) || (Row == 0) || (Col == upper) || (Row == upper)){
    temp = in[gridpoint];
    out[gridpoint] = temp;
  }
  else if ((Col < upper) && (Row < upper)){

    temp = (
      in[index(Col, Row-1, N)]+
      in[index(Col, Row+1, N)]+
      in[index(Col-1, Row, N)]+
      in[index(Col+1, Row, N)]) / 4.0;

    out[gridpoint] = temp;
  }


}

	.file	"tmpxft_003b2a30_00000000-6_heatdist.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" Cannot allocate temp %u x %u array\n"
	.text
	.globl	_Z13seq_heat_distPfjj
	.type	_Z13seq_heat_distPfjj, @function
_Z13seq_heat_distPfjj:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leal	-1(%rsi), %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	movl	%esi, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	imull	%esi, %edi
	movl	%esi, %ebx
	movl	$4, %esi
	pushq	%rcx
	.cfi_def_cfa_offset 64
	leaq	0(,%rdi,4), %r15
	call	calloc@PLT
	testq	%rax, %rax
	jne	.L3
	movq	stderr(%rip), %rdi
	movl	%ebx, %r8d
	movl	%ebx, %ecx
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L3:
	movl	%r15d, %r12d
	movq	%r15, %rcx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	movq	%r12, %rdx
	call	__memcpy_chk@PLT
	movss	.LC1(%rip), %xmm1
	movl	%r14d, %edx
	xorl	%r9d, %r9d
	movq	%rax, %r8
.L4:
	cmpq	%r9, %rdx
	je	.L12
	movl	%ebx, %eax
	movl	$1, %esi
.L7:
	cmpl	%r13d, %esi
	jge	.L13
	movl	%eax, %r10d
	leal	(%rbx,%rax), %edi
	incl	%esi
	incl	%eax
	subl	%ebx, %r10d
	movl	$1, %ecx
.L5:
	leal	(%r10,%rcx), %r14d
	leal	(%rdi,%rcx), %r11d
	incl	%ecx
	movss	0(%rbp,%r14,4), %xmm0
	leal	1(%rax), %r14d
	addss	0(%rbp,%r11,4), %xmm0
	leal	-1(%rax), %r11d
	addss	0(%rbp,%r11,4), %xmm0
	addss	0(%rbp,%r14,4), %xmm0
	movl	%eax, %r11d
	movq	%r14, %rax
	mulss	%xmm1, %xmm0
	movss	%xmm0, (%r8,%r11,4)
	cmpl	%ecx, %r13d
	jg	.L5
	movl	%edi, %eax
	jmp	.L7
.L13:
	movq	%rbp, %rdi
	movq	%r8, %rsi
	movq	%r12, %rcx
	incq	%r9
	rep movsb
	jmp	.L4
.L12:
	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
.LFE2028:
	.size	_Z13seq_heat_distPfjj, .-_Z13seq_heat_distPfjj
	.globl	_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j
	.type	_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j, @function
_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j:
.LFB2054:
	.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
	movl	%edx, 12(%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	12(%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	.L14
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z16heat_dist_kernelPfS_j(%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
.L14:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j, .-_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j
	.globl	_Z16heat_dist_kernelPfS_j
	.type	_Z16heat_dist_kernelPfS_j, @function
_Z16heat_dist_kernelPfS_j:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j
	.cfi_endproc
.LFE2055:
	.size	_Z16heat_dist_kernelPfS_j, .-_Z16heat_dist_kernelPfS_j
	.section	.rodata.str1.1
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/petercwill/CUDA/master/Lab_1/heatdist.cu"
.LC4:
	.string	"%s in %s at line %d\n"
	.text
	.globl	_Z13gpu_heat_distPfjj
	.type	_Z13gpu_heat_distPfjj, @function
_Z13gpu_heat_distPfjj:
.LFB2029:
	.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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	%esi, %ebx
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movl	%esi, %eax
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC2(%rip), %xmm0
	call	ceil@PLT
	movq	%rsp, %rdi
	movl	$1, 24(%rsp)
	cvttsd2siq	%xmm0, %rax
	movl	$1, 36(%rsp)
	movl	%eax, 16(%rsp)
	movl	%eax, 20(%rsp)
	movabsq	$68719476752, %rax
	movq	%rax, 28(%rsp)
	movl	%ebx, %eax
	imull	%ebx, %eax
	leal	0(,%rax,4), %ebp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L22
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$192, %r9d
	movq	%rax, %rcx
	jmp	.L29
.L22:
	leaq	8(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	movl	$200, %r9d
	movq	%rax, %rcx
.L29:
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %r8
	leaq	.LC4(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L23:
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rsi
	xorl	%r14d, %r14d
	call	cudaMemcpy@PLT
.L24:
	cmpq	%r12, %r14
	je	.L30
	movl	36(%rsp), %ecx
	movq	28(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	16(%rsp), %rdi
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z39__device_stub__Z16heat_dist_kernelPfS_jPfS_j
.L25:
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movq	%rbp, %rdx
	incq	%r14
	movl	$3, %ecx
	call	cudaMemcpy@PLT
	jmp	.L24
.L30:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$48, %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
.LFE2029:
	.size	_Z13gpu_heat_distPfjj, .-_Z13gpu_heat_distPfjj
	.section	.rodata.str1.1
.LC5:
	.string	"CPU"
.LC6:
	.string	"GPU"
.LC7:
	.string	"usage: heatdist num  iterations  who\n"
.LC8:
	.string	"num = dimension of the square matrix (50 and up)\n"
.LC9:
	.string	"iterations = number of iterations till stopping (1 and up)\n"
.LC10:
	.string	"who = 0: sequential code on CPU, 1: GPU execution\n"
.LC11:
	.string	" Cannot allocate the %u x %u array\n"
.LC15:
	.string	"Time taken for %s is %lf\n"
.LC16:
	.string	"%.5f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.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
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	cmpl	$4, %edi
	je	.L32
	movq	stderr(%rip), %rdi
	leaq	.LC7(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC8(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC9(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC10(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L51
.L32:
	movq	24(%rsi), %rdi
	movq	%rsi, %rbp
	call	atoi@PLT
	movq	8(%rbp), %rdi
	movl	%eax, %r13d
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	movl	%ebx, %edi
	movl	$4, %esi
	imull	%ebx, %edi
	movl	%eax, %r14d
	call	calloc@PLT
	movss	.LC12(%rip), %xmm0
	movq	%rax, %rbp
	xorl	%eax, %eax
	testq	%rbp, %rbp
	jne	.L33
	movq	stderr(%rip), %rdi
	movl	%ebx, %r8d
	movl	%ebx, %ecx
	leaq	.LC11(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
.L51:
	movl	$1, %edi
	call	exit@PLT
.L33:
	cmpl	%ebx, %eax
	jnb	.L52
	movss	%xmm0, 0(%rbp,%rax,4)
	incq	%rax
	jmp	.L33
.L52:
	movss	.LC12(%rip), %xmm0
	xorl	%edx, %edx
	xorl	%eax, %eax
.L35:
	cmpl	%eax, %ebx
	je	.L53
	movl	%edx, %ecx
	incl	%eax
	addl	%ebx, %edx
	movss	%xmm0, 0(%rbp,%rcx,4)
	jmp	.L35
.L53:
	leal	-1(%rbx), %edx
	movss	.LC12(%rip), %xmm0
	xorl	%ecx, %ecx
	movl	%edx, %esi
.L37:
	cmpl	%ecx, %eax
	je	.L54
	movl	%esi, %edi
	incl	%ecx
	addl	%ebx, %esi
	movss	%xmm0, 0(%rbp,%rdi,4)
	jmp	.L37
.L54:
	movl	%edx, %ecx
	movss	.LC12(%rip), %xmm0
	xorl	%edx, %edx
	imull	%ebx, %ecx
.L39:
	cmpl	%edx, %eax
	je	.L55
	leal	(%rdx,%rcx), %esi
	incl	%edx
	movss	%xmm0, 0(%rbp,%rsi,4)
	jmp	.L39
.L55:
	imull	$10, %ebx, %edx
	movss	.LC13(%rip), %xmm0
	movl	$21, %eax
.L41:
	movl	%edx, %ecx
	addl	%ebx, %edx
	movss	%xmm0, 0(%rbp,%rcx,4)
	decl	%eax
	jne	.L41
	testl	%r13d, %r13d
	jne	.L42
	call	clock@PLT
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%rbp, %rdi
	movq	%rax, %r12
	call	_Z13seq_heat_distPfjj
	jmp	.L50
.L42:
	call	clock@PLT
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%rbp, %rdi
	movq	%rax, %r12
	call	_Z13gpu_heat_distPfjj
.L50:
	call	clock@PLT
	leaq	.LC6(%rip), %rdx
	movl	$2, %edi
	leaq	.LC15(%rip), %rsi
	subq	%r12, %rax
	testl	%r13d, %r13d
	leaq	.LC16(%rip), %r12
	cvtsi2sdq	%rax, %xmm0
	leaq	.LC5(%rip), %rax
	divsd	.LC14(%rip), %xmm0
	cmove	%rax, %rdx
	movb	$1, %al
	call	__printf_chk@PLT
	imull	$17, %ebx, %eax
	movq	%r12, %rsi
	movl	$2, %edi
	addl	$37, %eax
	cvtss2sd	0(%rbp,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	imull	$324, %ebx, %eax
	movq	%r12, %rsi
	movl	$2, %edi
	imull	$52, %ebx, %ebx
	addl	$53, %eax
	cvtss2sd	0(%rbp,%rax,4), %xmm0
	movb	$1, %al
	addl	$652, %ebx
	call	__printf_chk@PLT
	movq	%r12, %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	0(%rbp,%rbx,4), %xmm0
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	popq	%rbx
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z16heat_dist_kernelPfS_j"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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	.LC17(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z16heat_dist_kernelPfS_j(%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
.LFE2057:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	1048576000
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	0
	.long	1068498944
	.section	.rodata.cst4
	.align 4
.LC12:
	.long	1117782016
	.align 4
.LC13:
	.long	1125515264
	.section	.rodata.cst8
	.align 8
.LC14:
	.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:

/*
 *  Please write your name and net ID below
 *
 *  Last name: Will
 *  First name: Peter
 *  Net ID: pcw276
 *
 */


/*
 * This file contains the code for doing the heat distribution problem.
 * You do not need to modify anything except starting  gpu_heat_dist() at the bottom
 * of this file.
 * In gpu_heat_dist() you can organize your data structure and the call to your
 * kernel(s) that you need to write too.
 *
 * You compile with:
 * 		nvcc -o heatdist heatdist.cu
 */

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

/* To index element (i,j) of a 2D array stored as 1D */
#define index(i, j, N)  ((i)*(N)) + (j)

/*****************************************************************/

// Function declarations: Feel free to add any functions you want.
void  seq_heat_dist(float *, unsigned int, unsigned int);
void  gpu_heat_dist(float *, unsigned int, unsigned int);
__global__ void  heat_dist_kernel(float * in, float * out, unsigned int N);

/*****************************************************************/

int main(int argc, char * argv[])
{
  unsigned int N; /* Dimention of NxN matrix */
  int type_of_device = 0; // CPU or GPU
  int iterations = 0;
  int i;

  /* The 2D array of points will be treated as 1D array of NxN elements */
  float * playground;

  // to measure time taken by a specific part of the code
  double time_taken;
  clock_t start, end;

  if(argc != 4)
  {
    fprintf(stderr, "usage: heatdist num  iterations  who\n");
    fprintf(stderr, "num = dimension of the square matrix (50 and up)\n");
    fprintf(stderr, "iterations = number of iterations till stopping (1 and up)\n");
    fprintf(stderr, "who = 0: sequential code on CPU, 1: GPU execution\n");
    exit(1);
  }

  type_of_device = atoi(argv[3]);
  N = (unsigned int) atoi(argv[1]);
  iterations = (unsigned int) atoi(argv[2]);


  /* Dynamically allocate NxN array of floats */
  playground = (float *)calloc(N*N, sizeof(float));
  if( !playground )
  {
   fprintf(stderr, " Cannot allocate the %u x %u array\n", N, N);
   exit(1);
  }

  /* Initialize it: calloc already initalized everything to 0 */
  // Edge elements to 80F
  for(i = 0; i < N; i++)
    playground[index(0,i,N)] = 80;

  for(i = 0; i < N; i++)
    playground[index(i,0,N)] = 80;

  for(i = 0; i < N; i++)
    playground[index(i,N-1, N)] = 80;

  for(i = 0; i < N; i++)
    playground[index(N-1,i,N)] = 80;

  // from (0,10) to (0,30) inclusive are 150F
  for(i = 10; i <= 30; i++)
    playground[index(i,0,N)] = 150;


  if( !type_of_device ) // The CPU sequential version
  {
    start = clock();
    seq_heat_dist(playground, N, iterations);
    end = clock();
  }
  else  // The GPU version
  {
     start = clock();
     gpu_heat_dist(playground, N, iterations);
     end = clock();
  }


  time_taken = ((double)(end - start))/ CLOCKS_PER_SEC;

  printf("Time taken for %s is %lf\n", type_of_device == 0? "CPU" : "GPU", time_taken);
  printf("%.5f\n", playground[index(17,37,N)]);
  printf("%.5f\n", playground[index(324,53,N)]);
  printf("%.5f\n", playground[index(52,652,N)]);
  // for(i = 0; i < N; i++)
  // {
  //   for(int j = 0; j <N; j++)
  //   {
  //     printf("%.2f, ", playground[index(i,j,N)]);
  //   }
  //   printf("\n");
  // }
  free(playground);

  return 0;

}


/*****************  The CPU sequential version (DO NOT CHANGE THAT) **************/
void  seq_heat_dist(float * playground, unsigned int N, unsigned int iterations)
{
  // Loop indices
  int i, j, k;
  int upper = N-1;

  // number of bytes to be copied between array temp and array playground
  unsigned int num_bytes = 0;

  float * temp;
  /* Dynamically allocate another array for temp values */
  /* Dynamically allocate NxN array of floats */
  temp = (float *)calloc(N*N, sizeof(float));
  if( !temp )
  {
   fprintf(stderr, " Cannot allocate temp %u x %u array\n", N, N);
   exit(1);
  }

  num_bytes = N*N*sizeof(float);

  /* Copy initial array in temp */
  memcpy((void *)temp, (void *) playground, num_bytes);

  for( k = 0; k < iterations; k++)
  {
    /* Calculate new values and store them in temp */
    for(i = 1; i < upper; i++)
      for(j = 1; j < upper; j++)
	temp[index(i,j,N)] = (playground[index(i-1,j,N)] +
	                      playground[index(i+1,j,N)] +
			      playground[index(i,j-1,N)] +
			      playground[index(i,j+1,N)])/4.0;



    /* Move new values into old values */
    memcpy((void *)playground, (void *) temp, num_bytes);
  }

}

/***************** The GPU version: Write your code here *********************/
/* This function can call one or more kenels *********************************/
void  gpu_heat_dist(float * playground, unsigned int N, unsigned int iterations)
{

  dim3 dimGrid(ceil(N/16.0), ceil(N/16.0), 1);
  dim3 dimBlock(16, 16, 1);


  // number of bytes to be copied between array temp and array playground
  unsigned int num_bytes = N*N*sizeof(float);

  float * d_in;
  float * d_out;

  // cuda allocation in global memory with error checking
  hipError_t err=hipMalloc((void **) &d_in, num_bytes);
  if( err !=hipSuccess)
  {
   fprintf(stderr, "%s in %s at line %d\n",
    hipGetErrorString(err), __FILE__, __LINE__);
   exit(EXIT_FAILURE);
  }

  err=hipMalloc((void **) &d_out, num_bytes);
  if( err !=hipSuccess)
  {
   fprintf(stderr, "%s in %s at line %d\n",
    hipGetErrorString(err), __FILE__, __LINE__);
   exit(EXIT_FAILURE);
  }

  /* Copy initial array in temp */
  hipMemcpy(d_in, playground, num_bytes, hipMemcpyHostToDevice);
  for (int k = 0; k < iterations; k++)
  {
    heat_dist_kernel<<<dimGrid, dimBlock>>>(d_in, d_out, N);
    hipMemcpy(d_in, d_out, num_bytes, hipMemcpyDeviceToDevice);
  }
  hipMemcpy(playground, d_out, num_bytes, hipMemcpyDeviceToHost);


}

/**************** The Kernal Function called by the GPU verison**********/
__global__
void heat_dist_kernel(float * in, float * out, unsigned int N)
{
  int Col = blockIdx.x * blockDim.x + threadIdx.x;
  int Row = blockIdx.y * blockDim.y + threadIdx.y;
  int upper = N-1;
  float temp = 0;
  int gridpoint = index(Col, Row, N);

  // test to see if we're on the borders
  if ((Col == 0) || (Row == 0) || (Col == upper) || (Row == upper)){
    temp = in[gridpoint];
    out[gridpoint] = temp;
  }
  else if ((Col < upper) && (Row < upper)){

    temp = (
      in[index(Col, Row-1, N)]+
      in[index(Col, Row+1, N)]+
      in[index(Col-1, Row, N)]+
      in[index(Col+1, Row, N)]) / 4.0;

    out[gridpoint] = temp;
  }


}

	.text
	.file	"heatdist.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$4, %edi
	jne	.LBB0_20
# %bb.1:
	movq	%rsi, %r14
	movq	24(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	8(%r14), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %r15d
	movl	%ebx, %edi
	imull	%edi, %edi
	movl	$4, %esi
	callq	calloc
	testq	%rax, %rax
	je	.LBB0_21
# %bb.2:                                # %.preheader66
	movq	%rax, %r14
	testl	%ebx, %ebx
	je	.LBB0_14
# %bb.3:                                # %.lr.ph.preheader
	movl	%ebx, %eax
	xorl	%ecx, %ecx
.LBB0_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$1117782016, (%r14,%rcx,4)      # imm = 0x42A00000
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB0_4
# %bb.5:                                # %.preheader65
	testl	%ebx, %ebx
	je	.LBB0_14
# %bb.6:                                # %.lr.ph69.preheader
	xorl	%ecx, %ecx
	movq	%rax, %rdx
.LBB0_7:                                # %.lr.ph69
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %esi
	movl	$1117782016, (%r14,%rsi,4)      # imm = 0x42A00000
	addl	%ebx, %ecx
	decq	%rdx
	jne	.LBB0_7
# %bb.8:                                # %.preheader64
	testl	%ebx, %ebx
	je	.LBB0_14
# %bb.9:                                # %.lr.ph71
	leal	-1(%rbx), %ecx
	movq	%rax, %rdx
.LBB0_10:                               # =>This Inner Loop Header: Depth=1
	movl	%ecx, %esi
	movl	$1117782016, (%r14,%rsi,4)      # imm = 0x42A00000
	addl	%ebx, %ecx
	decq	%rdx
	jne	.LBB0_10
# %bb.11:                               # %.preheader63
	testl	%ebx, %ebx
	je	.LBB0_14
# %bb.12:                               # %.lr.ph73
	leal	-1(%rbx), %ecx
	imull	%ebx, %ecx
.LBB0_13:                               # =>This Inner Loop Header: Depth=1
	movl	%ecx, %edx
	movl	$1117782016, (%r14,%rdx,4)      # imm = 0x42A00000
	incl	%ecx
	decq	%rax
	jne	.LBB0_13
.LBB0_14:                               # %.preheader.preheader
	leal	(%rbx,%rbx), %eax
	leal	(%rax,%rax,4), %eax
	movl	$21, %ecx
.LBB0_15:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %edx
	movl	$1125515264, (%r14,%rdx,4)      # imm = 0x43160000
	addl	%ebx, %eax
	decq	%rcx
	jne	.LBB0_15
# %bb.16:
	callq	clock
	movq	%rax, %r12
	movq	%r14, %rdi
	movl	%ebx, %esi
	movl	%r15d, %edx
	testl	%ebp, %ebp
	je	.LBB0_18
# %bb.17:
	callq	_Z13gpu_heat_distPfjj
	movl	$.L.str.7, %r15d
	jmp	.LBB0_19
.LBB0_18:
	callq	_Z13seq_heat_distPfjj
	movl	$.L.str.6, %r15d
.LBB0_19:
	callq	clock
	subq	%r12, %rax
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI0_0(%rip), %xmm0
	movl	$.L.str.5, %edi
	movq	%r15, %rsi
	movb	$1, %al
	callq	printf
	movl	%ebx, %eax
	shll	$4, %eax
	addl	%ebx, %eax
	addl	$37, %eax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	imull	$324, %ebx, %eax                # imm = 0x144
	addl	$53, %eax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	imull	$52, %ebx, %eax
	addl	$652, %eax                      # imm = 0x28C
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rax,4), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
.LBB0_20:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rcx
	movl	$.L.str, %edi
	movl	$37, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$49, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$59, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rcx
	movl	$.L.str.3, %edi
	movl	$50, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB0_22
.LBB0_21:
	movq	stderr(%rip), %rdi
	movl	$.L.str.4, %esi
	movl	%ebx, %edx
	movl	%ebx, %ecx
	xorl	%eax, %eax
	callq	fprintf
.LBB0_22:
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z13seq_heat_distPfjj
.LCPI1_0:
	.long	0x3e800000                      # float 0.25
	.text
	.globl	_Z13seq_heat_distPfjj
	.type	_Z13seq_heat_distPfjj,@function
_Z13seq_heat_distPfjj:                  # @_Z13seq_heat_distPfjj
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
                                        # kill: def $esi killed $esi def $rsi
	movq	%rdi, %r14
	movq	%rsi, %rbx
	movl	%esi, %r15d
	imull	%r15d, %r15d
	movl	$4, %esi
	movq	%r15, %rdi
	callq	calloc
	testq	%rax, %rax
	je	.LBB1_10
# %bb.1:
	movq	%rax, %r12
	shll	$2, %r15d
	movq	%rax, %rdi
	movq	%r14, %rsi
	movq	%r15, 16(%rsp)                  # 8-byte Spill
	movq	%r15, %rdx
	callq	memcpy@PLT
	movl	%ebp, 4(%rsp)                   # 4-byte Spill
	testl	%ebp, %ebp
	je	.LBB1_9
# %bb.2:                                # %.preheader46.lr.ph
	movq	%rbx, %rax
	leal	-1(%rbx), %r13d
	movl	%r13d, %ebx
	movl	%eax, %ebp
	addl	%eax, %eax
	orq	$1, %rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	decq	%rbx
	xorl	%r15d, %r15d
	movss	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB1_3:                                # %.preheader46
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
                                        #       Child Loop BB1_6 Depth 3
	cmpl	$2, %r13d
	jl	.LBB1_8
# %bb.4:                                # %.preheader.preheader
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	$1, %eax
	xorl	%ecx, %ecx
	movq	8(%rsp), %rdx                   # 8-byte Reload
	movq	%rbp, %rsi
.LBB1_5:                                # %.preheader
                                        #   Parent Loop BB1_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_6 Depth 3
	incl	%eax
	xorl	%edi, %edi
.LBB1_6:                                #   Parent Loop BB1_3 Depth=1
                                        #     Parent Loop BB1_5 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	leal	(%rcx,%rdi), %r8d
	incl	%r8d
	movss	(%r14,%r8,4), %xmm0             # xmm0 = mem[0],zero,zero,zero
	leal	(%rdx,%rdi), %r8d
	addss	(%r14,%r8,4), %xmm0
	leal	(%rsi,%rdi), %r8d
	addss	(%r14,%r8,4), %xmm0
	leal	2(%rsi,%rdi), %r8d
	addss	(%r14,%r8,4), %xmm0
	mulss	%xmm1, %xmm0
	leal	(%rsi,%rdi), %r8d
	incl	%r8d
	movss	%xmm0, (%r12,%r8,4)
	incq	%rdi
	cmpq	%rdi, %rbx
	jne	.LBB1_6
# %bb.7:                                # %._crit_edge
                                        #   in Loop: Header=BB1_5 Depth=2
	addq	%rbp, %rsi
	addq	%rbp, %rdx
	addq	%rbp, %rcx
	cmpl	%r13d, %eax
	jne	.LBB1_5
.LBB1_8:                                # %._crit_edge49
                                        #   in Loop: Header=BB1_3 Depth=1
	movq	%r14, %rdi
	movq	%r12, %rsi
	movq	16(%rsp), %rdx                  # 8-byte Reload
	callq	memcpy@PLT
	movss	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	incl	%r15d
	cmpl	4(%rsp), %r15d                  # 4-byte Folded Reload
	jne	.LBB1_3
.LBB1_9:                                # %._crit_edge51
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_10:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rdi
	movl	$.L.str.9, %esi
	movq	%rbx, %rcx
	movl	%ecx, %edx
                                        # kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z13seq_heat_distPfjj, .Lfunc_end1-_Z13seq_heat_distPfjj
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13gpu_heat_distPfjj
.LCPI2_0:
	.quad	0x3fb0000000000000              # double 0.0625
	.text
	.globl	_Z13gpu_heat_distPfjj
	.type	_Z13gpu_heat_distPfjj,@function
_Z13gpu_heat_distPfjj:                  # @_Z13gpu_heat_distPfjj
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movl	%esi, %r14d
	movq	%rdi, %rbx
	movl	%esi, %eax
	cvtsi2sd	%rax, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	callq	ceil@PLT
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movl	%r14d, %r15d
	imull	%r15d, %r15d
	shll	$2, %r15d
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_1
# %bb.3:
	movq	%rsp, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.5:
	movq	8(%rsp), %rdi
	movq	%rbx, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%ebp, %ebp
	je	.LBB2_10
# %bb.6:
	cvttsd2si	16(%rsp), %r12          # 8-byte Folded Reload
	movl	%r12d, %eax
	shlq	$32, %r12
	orq	%rax, %r12
	movabsq	$68719476752, %r13              # imm = 0x1000000010
.LBB2_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_9
# %bb.8:                                #   in Loop: Header=BB2_7 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	%r14d, %edx
	callq	_Z31__device_stub__heat_dist_kernelPfS_j
.LBB2_9:                                #   in Loop: Header=BB2_7 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movq	%r15, %rdx
	movl	$3, %ecx
	callq	hipMemcpy
	decl	%ebp
	jne	.LBB2_7
.LBB2_10:                               # %._crit_edge
	movq	(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_1:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str.11, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$192, %r8d
	jmp	.LBB2_2
.LBB2_4:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	movl	$.L.str.11, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$200, %r8d
.LBB2_2:
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z13gpu_heat_distPfjj, .Lfunc_end2-_Z13gpu_heat_distPfjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__heat_dist_kernelPfS_j # -- Begin function _Z31__device_stub__heat_dist_kernelPfS_j
	.type	_Z31__device_stub__heat_dist_kernelPfS_j,@function
_Z31__device_stub__heat_dist_kernelPfS_j: # @_Z31__device_stub__heat_dist_kernelPfS_j
	.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	12(%rsp), %rsi
	movl	%edx, (%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	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16heat_dist_kernelPfS_j, %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	_Z31__device_stub__heat_dist_kernelPfS_j, .Lfunc_end3-_Z31__device_stub__heat_dist_kernelPfS_j
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16heat_dist_kernelPfS_j, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"usage: heatdist num  iterations  who\n"
	.size	.L.str, 38

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"num = dimension of the square matrix (50 and up)\n"
	.size	.L.str.1, 50

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"iterations = number of iterations till stopping (1 and up)\n"
	.size	.L.str.2, 60

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"who = 0: sequential code on CPU, 1: GPU execution\n"
	.size	.L.str.3, 51

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	" Cannot allocate the %u x %u array\n"
	.size	.L.str.4, 36

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Time taken for %s is %lf\n"
	.size	.L.str.5, 26

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"CPU"
	.size	.L.str.6, 4

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%.5f\n"
	.size	.L.str.8, 6

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	" Cannot allocate temp %u x %u array\n"
	.size	.L.str.9, 37

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"%s in %s at line %d\n"
	.size	.L.str.10, 21

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/petercwill/CUDA/master/Lab_1/heatdist.hip"
	.size	.L.str.11, 104

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

	.type	.L__unnamed_1,@object           # @0
	.section	.rodata.str1.1,"aMS",@progbits,1
.L__unnamed_1:
	.asciz	"_Z16heat_dist_kernelPfS_j"
	.size	.L__unnamed_1, 26

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

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

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

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16heat_dist_kernelPfS_j ; -- Begin function _Z16heat_dist_kernelPfS_j
	.globl	_Z16heat_dist_kernelPfS_j
	.p2align	8
	.type	_Z16heat_dist_kernelPfS_j,@function
_Z16heat_dist_kernelPfS_j:              ; @_Z16heat_dist_kernelPfS_j
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s3, s[0:1], 0x10
	s_load_b128 s[4:7], 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 s1, s2, 0xffff
	s_lshr_b32 s0, s2, 16
	v_mad_u64_u32 v[3:4], null, s14, s1, v[1:2]
	v_mad_u64_u32 v[1:2], null, s15, s0, v[0:1]
	s_add_i32 s8, s3, -1
                                        ; implicit-def: $vgpr2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_lo_u32 v4, v3, s3
	v_cmp_ne_u32_e32 vcc_lo, 0, v3
	v_cmp_ne_u32_e64 s0, 0, v1
	v_cmp_ne_u32_e64 s1, s8, v3
	v_cmp_ne_u32_e64 s2, s8, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	s_and_b32 s0, vcc_lo, s0
	v_add_nc_u32_e32 v0, v4, v1
	s_and_b32 s0, s1, s0
	s_mov_b32 s1, 0
	s_and_b32 s0, s2, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s2, s0
	s_xor_b32 s0, exec_lo, s2
	s_cbranch_execz .LBB0_4
; %bb.1:
	v_max_i32_e32 v2, v3, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_i32_e32 vcc_lo, s8, v2
                                        ; implicit-def: $vgpr2
	s_and_saveexec_b32 s2, vcc_lo
	s_xor_b32 s2, exec_lo, s2
	s_cbranch_execz .LBB0_3
; %bb.2:
	v_dual_mov_b32 v3, 0 :: v_dual_add_nc_u32 v2, -1, v0
	v_subrev_nc_u32_e32 v4, s3, v4
	s_mov_b32 s1, exec_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[2:3]
	v_add_nc_u32_e32 v2, 1, v0
	v_lshlrev_b64 v[7:8], 2, v[2:3]
	v_add_nc_u32_e32 v2, v4, v1
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_co_u32 v4, vcc_lo, s4, v5
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v6, vcc_lo
	v_lshlrev_b64 v[9:10], 2, v[2:3]
	v_lshl_add_u32 v2, s3, 1, v2
	v_add_co_u32 v6, vcc_lo, s4, v7
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_3)
	v_lshlrev_b64 v[1:2], 2, v[2:3]
	v_add_co_u32 v3, vcc_lo, s4, v9
	s_clause 0x1
	global_load_b32 v5, v[4:5], off
	global_load_b32 v6, v[6:7], off
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v10, vcc_lo
	v_add_co_u32 v1, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v2, vcc_lo
	s_clause 0x1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v1, v[1:2], off
	s_waitcnt vmcnt(2)
	v_add_f32_e32 v2, v5, v6
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v2, v2, v3
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v1, v2, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f32_e32 v2, 0x3e800000, v1
	v_ashrrev_i32_e32 v1, 31, v0
.LBB0_3:                                ; %Flow57
	s_or_b32 exec_lo, exec_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s1, s1, exec_lo
.LBB0_4:                                ; %Flow
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB0_6
; %bb.5:
	v_ashrrev_i32_e32 v1, 31, v0
	s_or_b32 s1, s1, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[0:1]
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v2, v[2:3], off
.LBB0_6:                                ; %Flow58
	s_or_b32 exec_lo, exec_lo, s0
	s_and_saveexec_b32 s0, s1
	s_cbranch_execz .LBB0_8
; %bb.7:                                ; %.sink.split
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b32 v[0:1], v2, off
.LBB0_8:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16heat_dist_kernelPfS_j
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 11
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z16heat_dist_kernelPfS_j, .Lfunc_end0-_Z16heat_dist_kernelPfS_j
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 516
; NumSgprs: 18
; NumVgprs: 11
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 11
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         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:           _Z16heat_dist_kernelPfS_j
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16heat_dist_kernelPfS_j.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     11
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
