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

#define BLOCK_SIZE 256
#define STR_SIZE 256
#define DEVICE 0
#define HALO 1 // halo width along one direction when advancing to the next iteration

#define BENCH_PRINT

void run(int argc, char** argv);

int rows, cols;
int* data;
int** wall;
int* result;
#define M_SEED 9
int pyramid_height;

//#define BENCH_PRINT

void
init(int argc, char** argv)
{
  if(argc==4){
    cols = atoi(argv[1]);
    rows = atoi(argv[2]);
    pyramid_height=atoi(argv[3]);
  }else{
    printf("Usage: dynproc row_len col_len pyramid_height\n");
    exit(0);
  }
  data = new int[rows*cols];
  wall = new int*[rows];
  for(int n=0; n<rows; n++)
    wall[n]=data+cols*n;
  result = new int[cols];
	
  int seed = M_SEED;
  srand(seed);

  for (int i = 0; i < rows; i++)
    {
      for (int j = 0; j < cols; j++)
        {
          wall[i][j] = rand() % 10;
        }
    }
#ifdef BENCH_PRINT
  for (int i = 0; i < rows; i++)
    {
      for (int j = 0; j < cols; j++)
        {
          printf("%d ",wall[i][j]) ;
        }
      printf("\n") ;
    }
#endif
}

void 
fatal(char *s)
{
  fprintf(stderr, "error: %s\n", s);

}

#define IN_RANGE(x, min, max)   ((x)>=(min) && (x)<=(max))
#define CLAMP_RANGE(x, min, max) x = (x<(min)) ? min : ((x>(max)) ? max : x )
#define MIN(a, b) ((a)<=(b) ? (a) : (b))

__global__ void dynproc_kernel(
                               int iteration, 
                               int *gpuWall,
                               int *gpuSrc,
                               int *gpuResults,
                               int cols, 
                               int rows,
                               int startStep,
                               int border)
{

  __shared__ int prev[BLOCK_SIZE];
  __shared__ int result[BLOCK_SIZE];

  int bx = blockIdx.x;
  int tx=threadIdx.x;
	
  // each block finally computes result for a small block
  // after N iterations. 
  // it is the non-overlapping small blocks that cover 
  // all the input data

  // calculate the small block size
  int small_block_cols = BLOCK_SIZE-iteration*HALO*2;

  // calculate the boundary for the block according to 
  // the boundary of its small block
  int blkX = small_block_cols*bx-border;
  int blkXmax = blkX+BLOCK_SIZE-1;

  // calculate the global thread coordination
  int xidx = blkX+tx;
       
  // effective range within this block that falls within 
  // the valid range of the input data
  // used to rule out computation outside the boundary.
  int validXmin = (blkX < 0) ? -blkX : 0;
  int validXmax = (blkXmax > cols-1) ? BLOCK_SIZE-1-(blkXmax-cols+1) : BLOCK_SIZE-1;

  int W = tx-1;
  int E = tx+1;
        
  W = (W < validXmin) ? validXmin : W;
  E = (E > validXmax) ? validXmax : E;

  bool isValid = IN_RANGE(tx, validXmin, validXmax);

  if(IN_RANGE(xidx, 0, cols-1)){
    prev[tx] = gpuSrc[xidx];
  }
  __syncthreads(); // [Ronny] Added sync to avoid race on prev Aug. 14 2012
  bool computed;
  for (int i=0; i<iteration ; i++){ 
    computed = false;
    if( IN_RANGE(tx, i+1, BLOCK_SIZE-i-2) &&  \
        isValid){
      computed = true;
      int left = prev[W];
      int up = prev[tx];
      int right = prev[E];
      int shortest = MIN(left, up);
      shortest = MIN(shortest, right);
      int index = cols*(startStep+i)+xidx;
      result[tx] = shortest + gpuWall[index];
	
    }
    __syncthreads();
    if(i==iteration-1)
      break;
    if(computed)	 //Assign the computation range
      prev[tx]= result[tx];
    __syncthreads(); // [Ronny] Added sync to avoid race on prev Aug. 14 2012
  }

  // update the global memory
  // after the last iteration, only threads coordinated within the 
  // small block perform the calculation and switch on ``computed''
  if (computed){
    gpuResults[xidx]=result[tx];		
  }
}

/*
  compute N time steps
*/
int calc_path(int *gpuWall, int *gpuResult[2], int rows, int cols, \
              int pyramid_height, int blockCols, int borderCols)
{
  dim3 dimBlock(BLOCK_SIZE);
  dim3 dimGrid(blockCols);  
	
  int src = 1, dst = 0;
  for (int t = 0; t < rows-1; t+=pyramid_height) {
    int temp = src;
    src = dst;
    dst = temp;
    dynproc_kernel<<<dimGrid, dimBlock>>>(
                                          MIN(pyramid_height, rows-t-1), 
                                          gpuWall, gpuResult[src], gpuResult[dst],
                                          cols,rows, t, borderCols);
  }
  return dst;
}

int main(int argc, char** argv)
{
  int num_devices;
  cudaGetDeviceCount(&num_devices);
  if (num_devices > 1) cudaSetDevice(DEVICE);

  run(argc,argv);

  return EXIT_SUCCESS;
}

void run(int argc, char** argv)
{
  init(argc, argv);

  /* --------------- pyramid parameters --------------- */
  int borderCols = (pyramid_height)*HALO;
  int smallBlockCol = BLOCK_SIZE-(pyramid_height)*HALO*2;
  int blockCols = cols/smallBlockCol+((cols%smallBlockCol==0)?0:1);

  printf("pyramidHeight: %d\ngridSize: [%d]\nborder:[%d]\nblockSize: %d\nblockGrid:[%d]\ntargetBlock:[%d]\n",\
         pyramid_height, cols, borderCols, BLOCK_SIZE, blockCols, smallBlockCol);
	
  int *gpuWall, *gpuResult[2];
  int size = rows*cols;

  cudaMalloc((void**)&gpuResult[0], sizeof(int)*cols);
  cudaMalloc((void**)&gpuResult[1], sizeof(int)*cols);
  cudaMemcpy(gpuResult[0], data, sizeof(int)*cols, cudaMemcpyHostToDevice);
  cudaMalloc((void**)&gpuWall, sizeof(int)*(size-cols));
  cudaMemcpy(gpuWall, data+cols, sizeof(int)*(size-cols), cudaMemcpyHostToDevice);


  int final_ret = calc_path(gpuWall, gpuResult, rows, cols, \
                            pyramid_height, blockCols, borderCols);

  cudaMemcpy(result, gpuResult[final_ret], sizeof(int)*cols, cudaMemcpyDeviceToHost);


#ifdef BENCH_PRINT
  for (int i = 0; i < cols; i++)
    printf("%d ",data[i]) ;
  printf("\n") ;
  for (int i = 0; i < cols; i++)
    printf("%d ",result[i]) ;
  printf("\n") ;
#endif


  cudaFree(gpuWall);
  cudaFree(gpuResult[0]);
  cudaFree(gpuResult[1]);

  delete [] data;
  delete [] wall;
  delete [] result;

}


	.file	"tmpxft_002832dc_00000000-6_pathfinder.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
.LC2:
	.string	"Usage: dynproc row_len col_len pyramid_height\n"
	.text
	.globl	_Z4initiPPc
	.type	_Z4initiPPc, @function
_Z4initiPPc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rdx
	.cfi_def_cfa_offset 48
	cmpl	$4, %edi
	jne	.L3
	movq	8(%rsi), %rdi
	movq	%rsi, %rbp
	call	atoi@PLT
	movq	16(%rbp), %rdi
	movl	%eax, %ebx
	movl	%eax, cols(%rip)
	call	atoi@PLT
	movq	24(%rbp), %rdi
	movl	%eax, %r12d
	movl	%eax, rows(%rip)
	call	atoi@PLT
	imull	%r12d, %ebx
	movl	%eax, pyramid_height(%rip)
	movabsq	$2305843009213693950, %rax
	movslq	%ebx, %rbx
	cmpq	%rbx, %rax
	jb	.L4
	leaq	0(,%rbx,4), %rdi
	call	_Znam@PLT
	movslq	rows(%rip), %rdi
	movq	%rax, data(%rip)
	movabsq	$1152921504606846975, %rax
	cmpq	%rdi, %rax
	jnb	.L5
.L4:
	call	__cxa_throw_bad_array_new_length@PLT
.L5:
	salq	$3, %rdi
	call	_Znam@PLT
	movslq	cols(%rip), %rsi
	movl	rows(%rip), %r8d
	xorl	%edx, %edx
	movq	%rax, wall(%rip)
	movq	data(%rip), %rcx
	leaq	0(,%rsi,4), %rdi
.L6:
	cmpl	%edx, %r8d
	jle	.L18
	movq	%rcx, (%rax,%rdx,8)
	incq	%rdx
	addq	%rdi, %rcx
	jmp	.L6
.L18:
	movabsq	$2305843009213693950, %rax
	cmpq	%rsi, %rax
	jb	.L4
	call	_Znam@PLT
	movl	$9, %edi
	xorl	%ebp, %ebp
	movl	$10, %r12d
	movq	%rax, result(%rip)
	call	srand@PLT
.L8:
	cmpl	%ebp, rows(%rip)
	jle	.L15
	leaq	0(,%rbp,8), %r13
	xorl	%ebx, %ebx
.L11:
	cmpl	%ebx, cols(%rip)
	jle	.L19
	call	rand@PLT
	movq	wall(%rip), %rdx
	movq	(%rdx,%r13), %rcx
	cltd
	idivl	%r12d
	movl	%edx, (%rcx,%rbx,4)
	incq	%rbx
	jmp	.L11
.L19:
	incq	%rbp
	jmp	.L8
.L15:
	xorl	%ebp, %ebp
	leaq	.LC0(%rip), %r13
.L10:
	cmpl	%ebp, rows(%rip)
	jle	.L2
	leaq	0(,%rbp,8), %r12
	xorl	%ebx, %ebx
.L14:
	cmpl	%ebx, cols(%rip)
	jle	.L20
	movq	wall(%rip), %rax
	movq	%r13, %rsi
	movl	$2, %edi
	movq	(%rax,%r12), %rax
	movl	(%rax,%rbx,4), %edx
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L14
.L20:
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbp
	call	__printf_chk@PLT
	jmp	.L10
.L3:
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L2:
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z4initiPPc, .-_Z4initiPPc
	.section	.rodata.str1.1
.LC3:
	.string	"error: %s\n"
	.text
	.globl	_Z5fatalPc
	.type	_Z5fatalPc, @function
_Z5fatalPc:
.LFB2028:
	.cfi_startproc
	endbr64
	movq	%rdi, %rcx
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC3(%rip), %rdx
	jmp	__fprintf_chk@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z5fatalPc, .-_Z5fatalPc
	.globl	_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii
	.type	_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii, @function
_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movl	%edi, 44(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 40(%rsp)
	movl	%r9d, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	208(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	216(%rsp), %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	pushq	64(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z14dynproc_kerneliPiS_S_iiii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 224
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L22:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii, .-_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii
	.globl	_Z14dynproc_kerneliPiS_S_iiii
	.type	_Z14dynproc_kerneliPiS_S_iiii, @function
_Z14dynproc_kerneliPiS_S_iiii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii
	.cfi_endproc
.LFE2057:
	.size	_Z14dynproc_kerneliPiS_S_iiii, .-_Z14dynproc_kerneliPiS_S_iiii
	.globl	_Z9calc_pathPiPS_iiiii
	.type	_Z9calc_pathPiPS_iiiii, @function
_Z9calc_pathPiPS_iiiii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$16777217, %eax
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	salq	$8, %rax
	movl	$1, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leal	-1(%rdx), %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%r8d, %ebx
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%rax, 40(%rsp)
	subq	$255, %rax
	movq	%rdi, 16(%rsp)
	movl	%edx, 12(%rsp)
	movl	%ecx, 24(%rsp)
	movl	$1, 48(%rsp)
	movl	%r9d, 52(%rsp)
	movq	%rax, 56(%rsp)
	movl	%r13d, 28(%rsp)
.L28:
	cmpl	%r15d, 28(%rsp)
	jle	.L34
	movl	48(%rsp), %ecx
	movq	40(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	52(%rsp), %rdi
	movl	60(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	movslq	%r14d, %rax
	movl	%r13d, %edi
	movq	(%r12,%rax,8), %rcx
	movslq	%ebp, %rax
	movq	(%r12,%rax,8), %rdx
	leal	1(%r13), %eax
	cmpl	%eax, %ebx
	movl	128(%rsp), %eax
	cmovl	%ebx, %edi
	pushq	%rax
	.cfi_def_cfa_offset 136
	pushq	%r15
	.cfi_def_cfa_offset 144
	movl	28(%rsp), %r9d
	movl	40(%rsp), %r8d
	movq	32(%rsp), %rsi
	call	_Z43__device_stub__Z14dynproc_kerneliPiS_S_iiiiiPiS_S_iiii
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L29:
	addl	%ebx, %r15d
	subl	%ebx, %r13d
	xchgl	%ebp, %r14d
	jmp	.L28
.L34:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movl	%ebp, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z9calc_pathPiPS_iiiii, .-_Z9calc_pathPiPS_iiiii
	.section	.rodata.str1.1
.LC4:
	.string	"pyramidHeight: %d\ngridSize: [%d]\nborder:[%d]\nblockSize: %d\nblockGrid:[%d]\ntargetBlock:[%d]\n"
	.text
	.globl	_Z3runiPPc
	.type	_Z3runiPPc, @function
_Z3runiPPc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	_Z4initiPPc
	movl	cols(%rip), %ecx
	movl	$128, %esi
	movl	pyramid_height(%rip), %r13d
	movl	$256, %r9d
	movl	$2, %edi
	movl	%ecx, %eax
	subl	%r13d, %esi
	movl	%r13d, %r8d
	addl	%esi, %esi
	cltd
	idivl	%esi
	pushq	%rsi
	.cfi_def_cfa_offset 88
	leaq	.LC4(%rip), %rsi
	cmpl	$1, %edx
	movl	%r13d, %edx
	sbbl	$-1, %eax
	pushq	%rax
	.cfi_def_cfa_offset 96
	movl	%eax, %ebp
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rax
	.cfi_def_cfa_offset 88
	popq	%rdx
	.cfi_def_cfa_offset 80
	movslq	cols(%rip), %rsi
	movl	rows(%rip), %ebx
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	imull	%esi, %ebx
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	cols(%rip), %rsi
	leaq	16(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movslq	cols(%rip), %rdx
	movq	data(%rip), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	%ebx, %esi
	subl	cols(%rip), %esi
	movq	%rsp, %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movslq	cols(%rip), %rax
	movq	data(%rip), %rcx
	movq	(%rsp), %rdi
	subl	%eax, %ebx
	leaq	(%rcx,%rax,4), %rsi
	movl	$1, %ecx
	movslq	%ebx, %rdx
	xorl	%ebx, %ebx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	pyramid_height(%rip), %r8d
	movl	%ebp, %r9d
	movq	%r12, %rsi
	pushq	%rcx
	.cfi_def_cfa_offset 88
	movl	rows(%rip), %edx
	leaq	.LC0(%rip), %rbp
	pushq	%r13
	.cfi_def_cfa_offset 96
	movl	cols(%rip), %ecx
	movq	16(%rsp), %rdi
	call	_Z9calc_pathPiPS_iiiii
	movslq	cols(%rip), %rdx
	popq	%rsi
	.cfi_def_cfa_offset 88
	movl	$2, %ecx
	cltq
	popq	%rdi
	.cfi_def_cfa_offset 80
	movq	result(%rip), %rdi
	movq	8(%rsp,%rax,8), %rsi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
.L36:
	cmpl	%ebx, cols(%rip)
	jle	.L54
	movq	data(%rip), %rax
	movq	%rbp, %rsi
	movl	$2, %edi
	movl	(%rax,%rbx,4), %edx
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L36
.L54:
	leaq	.LC1(%rip), %rbp
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	movq	%rbp, %rsi
	leaq	.LC0(%rip), %r12
	call	__printf_chk@PLT
.L38:
	cmpl	%ebx, cols(%rip)
	jle	.L55
	movq	result(%rip), %rax
	movq	%r12, %rsi
	movl	$2, %edi
	movl	(%rax,%rbx,4), %edx
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L38
.L55:
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	data(%rip), %rdi
	testq	%rdi, %rdi
	je	.L40
	call	_ZdaPv@PLT
.L40:
	movq	wall(%rip), %rdi
	testq	%rdi, %rdi
	je	.L41
	call	_ZdaPv@PLT
.L41:
	movq	result(%rip), %rdi
	testq	%rdi, %rdi
	je	.L35
	call	_ZdaPv@PLT
.L35:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z3runiPPc, .-_Z3runiPPc
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	cmpl	$1, 4(%rsp)
	jle	.L57
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
.L57:
	movq	%rbp, %rsi
	movl	%ebx, %edi
	call	_Z3runiPPc
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z14dynproc_kerneliPiS_S_iiii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z14dynproc_kerneliPiS_S_iiii(%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
.LFE2059:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	pyramid_height
	.bss
	.align 4
	.type	pyramid_height, @object
	.size	pyramid_height, 4
pyramid_height:
	.zero	4
	.globl	result
	.align 8
	.type	result, @object
	.size	result, 8
result:
	.zero	8
	.globl	wall
	.align 8
	.type	wall, @object
	.size	wall, 8
wall:
	.zero	8
	.globl	data
	.align 8
	.type	data, @object
	.size	data, 8
data:
	.zero	8
	.globl	cols
	.align 4
	.type	cols, @object
	.size	cols, 4
cols:
	.zero	4
	.globl	rows
	.align 4
	.type	rows, @object
	.size	rows, 4
rows:
	.zero	4
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


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

#define BLOCK_SIZE 256
#define STR_SIZE 256
#define DEVICE 0
#define HALO 1 // halo width along one direction when advancing to the next iteration

#define BENCH_PRINT

void run(int argc, char** argv);

int rows, cols;
int* data;
int** wall;
int* result;
#define M_SEED 9
int pyramid_height;

//#define BENCH_PRINT

void
init(int argc, char** argv)
{
  if(argc==4){
    cols = atoi(argv[1]);
    rows = atoi(argv[2]);
    pyramid_height=atoi(argv[3]);
  }else{
    printf("Usage: dynproc row_len col_len pyramid_height\n");
    exit(0);
  }
  data = new int[rows*cols];
  wall = new int*[rows];
  for(int n=0; n<rows; n++)
    wall[n]=data+cols*n;
  result = new int[cols];
	
  int seed = M_SEED;
  srand(seed);

  for (int i = 0; i < rows; i++)
    {
      for (int j = 0; j < cols; j++)
        {
          wall[i][j] = rand() % 10;
        }
    }
#ifdef BENCH_PRINT
  for (int i = 0; i < rows; i++)
    {
      for (int j = 0; j < cols; j++)
        {
          printf("%d ",wall[i][j]) ;
        }
      printf("\n") ;
    }
#endif
}

void 
fatal(char *s)
{
  fprintf(stderr, "error: %s\n", s);

}

#define IN_RANGE(x, min, max)   ((x)>=(min) && (x)<=(max))
#define CLAMP_RANGE(x, min, max) x = (x<(min)) ? min : ((x>(max)) ? max : x )
#define MIN(a, b) ((a)<=(b) ? (a) : (b))

__global__ void dynproc_kernel(
                               int iteration, 
                               int *gpuWall,
                               int *gpuSrc,
                               int *gpuResults,
                               int cols, 
                               int rows,
                               int startStep,
                               int border)
{

  __shared__ int prev[BLOCK_SIZE];
  __shared__ int result[BLOCK_SIZE];

  int bx = blockIdx.x;
  int tx=threadIdx.x;
	
  // each block finally computes result for a small block
  // after N iterations. 
  // it is the non-overlapping small blocks that cover 
  // all the input data

  // calculate the small block size
  int small_block_cols = BLOCK_SIZE-iteration*HALO*2;

  // calculate the boundary for the block according to 
  // the boundary of its small block
  int blkX = small_block_cols*bx-border;
  int blkXmax = blkX+BLOCK_SIZE-1;

  // calculate the global thread coordination
  int xidx = blkX+tx;
       
  // effective range within this block that falls within 
  // the valid range of the input data
  // used to rule out computation outside the boundary.
  int validXmin = (blkX < 0) ? -blkX : 0;
  int validXmax = (blkXmax > cols-1) ? BLOCK_SIZE-1-(blkXmax-cols+1) : BLOCK_SIZE-1;

  int W = tx-1;
  int E = tx+1;
        
  W = (W < validXmin) ? validXmin : W;
  E = (E > validXmax) ? validXmax : E;

  bool isValid = IN_RANGE(tx, validXmin, validXmax);

  if(IN_RANGE(xidx, 0, cols-1)){
    prev[tx] = gpuSrc[xidx];
  }
  __syncthreads(); // [Ronny] Added sync to avoid race on prev Aug. 14 2012
  bool computed;
  for (int i=0; i<iteration ; i++){ 
    computed = false;
    if( IN_RANGE(tx, i+1, BLOCK_SIZE-i-2) &&  \
        isValid){
      computed = true;
      int left = prev[W];
      int up = prev[tx];
      int right = prev[E];
      int shortest = MIN(left, up);
      shortest = MIN(shortest, right);
      int index = cols*(startStep+i)+xidx;
      result[tx] = shortest + gpuWall[index];
	
    }
    __syncthreads();
    if(i==iteration-1)
      break;
    if(computed)	 //Assign the computation range
      prev[tx]= result[tx];
    __syncthreads(); // [Ronny] Added sync to avoid race on prev Aug. 14 2012
  }

  // update the global memory
  // after the last iteration, only threads coordinated within the 
  // small block perform the calculation and switch on ``computed''
  if (computed){
    gpuResults[xidx]=result[tx];		
  }
}

/*
  compute N time steps
*/
int calc_path(int *gpuWall, int *gpuResult[2], int rows, int cols, \
              int pyramid_height, int blockCols, int borderCols)
{
  dim3 dimBlock(BLOCK_SIZE);
  dim3 dimGrid(blockCols);  
	
  int src = 1, dst = 0;
  for (int t = 0; t < rows-1; t+=pyramid_height) {
    int temp = src;
    src = dst;
    dst = temp;
    dynproc_kernel<<<dimGrid, dimBlock>>>(
                                          MIN(pyramid_height, rows-t-1), 
                                          gpuWall, gpuResult[src], gpuResult[dst],
                                          cols,rows, t, borderCols);
  }
  return dst;
}

int main(int argc, char** argv)
{
  int num_devices;
  hipGetDeviceCount(&num_devices);
  if (num_devices > 1) hipSetDevice(DEVICE);

  run(argc,argv);

  return EXIT_SUCCESS;
}

void run(int argc, char** argv)
{
  init(argc, argv);

  /* --------------- pyramid parameters --------------- */
  int borderCols = (pyramid_height)*HALO;
  int smallBlockCol = BLOCK_SIZE-(pyramid_height)*HALO*2;
  int blockCols = cols/smallBlockCol+((cols%smallBlockCol==0)?0:1);

  printf("pyramidHeight: %d\ngridSize: [%d]\nborder:[%d]\nblockSize: %d\nblockGrid:[%d]\ntargetBlock:[%d]\n",\
         pyramid_height, cols, borderCols, BLOCK_SIZE, blockCols, smallBlockCol);
	
  int *gpuWall, *gpuResult[2];
  int size = rows*cols;

  hipMalloc((void**)&gpuResult[0], sizeof(int)*cols);
  hipMalloc((void**)&gpuResult[1], sizeof(int)*cols);
  hipMemcpy(gpuResult[0], data, sizeof(int)*cols, hipMemcpyHostToDevice);
  hipMalloc((void**)&gpuWall, sizeof(int)*(size-cols));
  hipMemcpy(gpuWall, data+cols, sizeof(int)*(size-cols), hipMemcpyHostToDevice);


  int final_ret = calc_path(gpuWall, gpuResult, rows, cols, \
                            pyramid_height, blockCols, borderCols);

  hipMemcpy(result, gpuResult[final_ret], sizeof(int)*cols, hipMemcpyDeviceToHost);


#ifdef BENCH_PRINT
  for (int i = 0; i < cols; i++)
    printf("%d ",data[i]) ;
  printf("\n") ;
  for (int i = 0; i < cols; i++)
    printf("%d ",result[i]) ;
  printf("\n") ;
#endif


  hipFree(gpuWall);
  hipFree(gpuResult[0]);
  hipFree(gpuResult[1]);

  delete [] data;
  delete [] wall;
  delete [] result;

}


	.text
	.file	"pathfinder.hip"
	.globl	_Z4initiPPc                     # -- Begin function _Z4initiPPc
	.type	_Z4initiPPc,@function
_Z4initiPPc:                            # @_Z4initiPPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$4, %edi
	jne	.LBB0_18
# %bb.1:
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebx
	movl	%eax, cols(%rip)
	movq	16(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%eax, rows(%rip)
	movq	24(%r14), %rdi
	callq	atoi
	movl	%eax, pyramid_height(%rip)
	movl	%ebp, %eax
	imull	%ebx, %eax
	cltq
	leaq	(,%rax,4), %rdi
	testl	%eax, %eax
	movq	$-1, %r14
	cmovsq	%r14, %rdi
	callq	_Znam
	movq	%rax, data(%rip)
	movslq	%ebp, %r15
	leaq	(,%r15,8), %rdi
	testl	%r15d, %r15d
	cmovsq	%r14, %rdi
	callq	_Znam
	movq	%rax, wall(%rip)
	movslq	%ebx, %rax
	testl	%r15d, %r15d
	jle	.LBB0_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%ebp, %ecx
	leaq	(,%rax,4), %rdx
	xorl	%esi, %esi
	xorl	%edi, %edi
.LBB0_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	data(%rip), %r8
	addq	%rsi, %r8
	movq	wall(%rip), %r9
	movq	%r8, (%r9,%rdi,8)
	incq	%rdi
	addq	%rdx, %rsi
	cmpq	%rdi, %rcx
	jne	.LBB0_3
.LBB0_4:                                # %._crit_edge
	leaq	(,%rax,4), %rdi
	testl	%eax, %eax
	cmovsq	%r14, %rdi
	callq	_Znam
	movq	%rax, result(%rip)
	movl	$9, %edi
	callq	srand
	movl	rows(%rip), %ecx
	testl	%ecx, %ecx
	jle	.LBB0_17
# %bb.5:                                # %.preheader25.preheader
	movl	cols(%rip), %eax
	xorl	%ebx, %ebx
.LBB0_6:                                # %.preheader25
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_8 Depth 2
	testl	%eax, %eax
	jle	.LBB0_10
# %bb.7:                                # %.lr.ph28.preheader
                                        #   in Loop: Header=BB0_6 Depth=1
	xorl	%r14d, %r14d
.LBB0_8:                                # %.lr.ph28
                                        #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	movq	wall(%rip), %rcx
	movq	(%rcx,%rbx,8), %rcx
	movl	%eax, (%rcx,%r14,4)
	incq	%r14
	movslq	cols(%rip), %rax
	cmpq	%rax, %r14
	jl	.LBB0_8
# %bb.9:                                # %._crit_edge29.loopexit
                                        #   in Loop: Header=BB0_6 Depth=1
	movl	rows(%rip), %ecx
.LBB0_10:                               # %._crit_edge29
                                        #   in Loop: Header=BB0_6 Depth=1
	incq	%rbx
	movslq	%ecx, %rdx
	cmpq	%rdx, %rbx
	jl	.LBB0_6
# %bb.11:                               # %.preheader24
	testl	%ecx, %ecx
	jle	.LBB0_17
# %bb.12:                               # %.preheader.preheader
	xorl	%ebx, %ebx
.LBB0_13:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_15 Depth 2
	cmpl	$0, cols(%rip)
	jle	.LBB0_16
# %bb.14:                               # %.lr.ph32.preheader
                                        #   in Loop: Header=BB0_13 Depth=1
	xorl	%r14d, %r14d
.LBB0_15:                               # %.lr.ph32
                                        #   Parent Loop BB0_13 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	wall(%rip), %rax
	movq	(%rax,%rbx,8), %rax
	movl	(%rax,%r14,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r14
	movslq	cols(%rip), %rax
	cmpq	%rax, %r14
	jl	.LBB0_15
.LBB0_16:                               # %._crit_edge33
                                        #   in Loop: Header=BB0_13 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%rbx
	movslq	rows(%rip), %rax
	cmpq	%rax, %rbx
	jl	.LBB0_13
.LBB0_17:                               # %._crit_edge35
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB0_18:
	.cfi_def_cfa_offset 48
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%edi, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z4initiPPc, .Lfunc_end0-_Z4initiPPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z5fatalPc                      # -- Begin function _Z5fatalPc
	.type	_Z5fatalPc,@function
_Z5fatalPc:                             # @_Z5fatalPc
	.cfi_startproc
# %bb.0:
	movq	%rdi, %rdx
	movq	stderr(%rip), %rdi
	movl	$.L.str.3, %esi
	xorl	%eax, %eax
	jmp	fprintf                         # TAILCALL
.Lfunc_end1:
	.size	_Z5fatalPc, .Lfunc_end1-_Z5fatalPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__dynproc_kerneliPiS_S_iiii # -- Begin function _Z29__device_stub__dynproc_kerneliPiS_S_iiii
	.type	_Z29__device_stub__dynproc_kerneliPiS_S_iiii,@function
_Z29__device_stub__dynproc_kerneliPiS_S_iiii: # @_Z29__device_stub__dynproc_kerneliPiS_S_iiii
	.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	20(%rsp), %rax
	movl	%edi, (%rax)
	leaq	56(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	48(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	16(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	12(%rsp), %r8
	movl	%r9d, (%r8)
	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)
	leaq	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	216(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z14dynproc_kerneliPiS_S_iiii, %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_end2:
	.size	_Z29__device_stub__dynproc_kerneliPiS_S_iiii, .Lfunc_end2-_Z29__device_stub__dynproc_kerneliPiS_S_iiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9calc_pathPiPS_iiiii          # -- Begin function _Z9calc_pathPiPS_iiiii
	.type	_Z9calc_pathPiPS_iiiii,@function
_Z9calc_pathPiPS_iiiii:                 # @_Z9calc_pathPiPS_iiiii
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	%ecx, 12(%rsp)                  # 4-byte Spill
                                        # kill: def $edx killed $edx def $rdx
	movq	%rsi, 32(%rsp)                  # 8-byte Spill
	movq	%rdi, 24(%rsp)                  # 8-byte Spill
	xorl	%r12d, %r12d
	movq	%rdx, 16(%rsp)                  # 8-byte Spill
	cmpl	$2, %edx
	jl	.LBB3_5
# %bb.1:                                # %.lr.ph.preheader
	movl	%r8d, %ebx
	movabsq	$4294967296, %rcx               # imm = 0x100000000
	movl	%r9d, %eax
	btsq	$32, %rax
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movq	16(%rsp), %rax                  # 8-byte Reload
	leal	-1(%rax), %r14d
	xorl	%r15d, %r15d
	movl	$1, %eax
	addq	$256, %rcx                      # imm = 0x100
	movq	%rcx, 40(%rsp)                  # 8-byte Spill
	movl	%r14d, %r13d
	xorl	%ebp, %ebp
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %r12d
	movq	48(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	40(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_4
# %bb.3:                                #   in Loop: Header=BB3_2 Depth=1
	cmpl	%ebx, %r14d
	movl	%ebx, %edi
	cmovll	%r14d, %edi
	movl	%r15d, %eax
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movq	(%rcx,%rax,8), %rdx
	movl	%r12d, %eax
	movq	(%rcx,%rax,8), %rcx
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movl	12(%rsp), %r8d                  # 4-byte Reload
	movq	16(%rsp), %r9                   # 8-byte Reload
                                        # kill: def $r9d killed $r9d killed $r9
	movl	112(%rsp), %eax
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%rbp
	.cfi_adjust_cfa_offset 8
	callq	_Z29__device_stub__dynproc_kerneliPiS_S_iiii
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB3_4:                                #   in Loop: Header=BB3_2 Depth=1
	addl	%ebx, %ebp
	subl	%ebx, %r14d
	movl	%r15d, %eax
	movl	%r12d, %r15d
	cmpl	%r13d, %ebp
	jl	.LBB3_2
.LBB3_5:                                # %._crit_edge
	movl	%r12d, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z9calc_pathPiPS_iiiii, .Lfunc_end3-_Z9calc_pathPiPS_iiiii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	leaq	12(%rsp), %r14
	movq	%r14, %rdi
	callq	hipGetDeviceCount
	cmpl	$2, (%r14)
	jl	.LBB4_2
# %bb.1:
	xorl	%edi, %edi
	callq	hipSetDevice
.LBB4_2:
	movl	%ebp, %edi
	movq	%rbx, %rsi
	callq	_Z3runiPPc
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z3runiPPc                      # -- Begin function _Z3runiPPc
	.type	_Z3runiPPc,@function
_Z3runiPPc:                             # @_Z3runiPPc
	.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
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	callq	_Z4initiPPc
	movl	pyramid_height(%rip), %ebx
	movl	$256, %esi                      # imm = 0x100
	subl	%ebx, %esi
	subl	%ebx, %esi
	movl	cols(%rip), %ecx
	movl	%ecx, %eax
	cltd
	idivl	%esi
	movl	%eax, %ebp
	cmpl	$1, %edx
	sbbl	$-1, %ebp
	movl	%esi, (%rsp)
	movl	$.L.str.4, %edi
	movl	%ebx, %esi
	movl	%ecx, %edx
	movl	%ebx, %ecx
	movl	$256, %r8d                      # imm = 0x100
	movl	%ebp, %r9d
	xorl	%eax, %eax
	callq	printf
	movslq	rows(%rip), %r12
	movslq	cols(%rip), %rsi
	imulq	%rsi, %r12
	shlq	$2, %rsi
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	callq	hipMalloc
	leaq	24(%rsp), %r15
	movslq	cols(%rip), %rsi
	shlq	$2, %rsi
	movq	%r15, %rdi
	callq	hipMalloc
	movq	-8(%r15), %rdi
	movq	data(%rip), %rsi
	movslq	cols(%rip), %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	cols(%rip), %rax
	movq	%r12, %rsi
	subq	%rax, %rsi
	shlq	$2, %rsi
	leaq	40(%rsp), %r15
	movq	%r15, %rdi
	callq	hipMalloc
	movslq	cols(%rip), %rax
	leaq	(,%rax,4), %rsi
	addq	data(%rip), %rsi
	movq	(%r15), %rdi
	movslq	%r12d, %rdx
	subq	%rax, %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r15), %rdi
	movl	rows(%rip), %edx
	movl	cols(%rip), %ecx
	movl	pyramid_height(%rip), %r8d
	movl	%ebx, (%rsp)
	movq	%r14, %rsi
	movl	%ebp, %r9d
	callq	_Z9calc_pathPiPS_iiiii
	movq	result(%rip), %rdi
	movl	%eax, %eax
	movq	16(%rsp,%rax,8), %rsi
	movslq	cols(%rip), %rdx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cmpl	$0, cols(%rip)
	jle	.LBB5_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%ebx, %ebx
.LBB5_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	data(%rip), %rax
	movl	(%rax,%rbx,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%rbx
	movslq	cols(%rip), %rax
	cmpq	%rax, %rbx
	jl	.LBB5_2
.LBB5_3:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	cmpl	$0, cols(%rip)
	jle	.LBB5_6
# %bb.4:                                # %.lr.ph25.preheader
	xorl	%ebx, %ebx
.LBB5_5:                                # %.lr.ph25
                                        # =>This Inner Loop Header: Depth=1
	movq	result(%rip), %rax
	movl	(%rax,%rbx,4), %esi
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%rbx
	movslq	cols(%rip), %rax
	cmpq	%rax, %rbx
	jl	.LBB5_5
.LBB5_6:                                # %._crit_edge26
	movl	$10, %edi
	callq	putchar@PLT
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	data(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_8
# %bb.7:
	callq	_ZdaPv
.LBB5_8:
	movq	wall(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_10
# %bb.9:
	callq	_ZdaPv
.LBB5_10:
	movq	result(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_12
# %bb.11:
	callq	_ZdaPv
.LBB5_12:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	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
.Lfunc_end5:
	.size	_Z3runiPPc, .Lfunc_end5-_Z3runiPPc
	.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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14dynproc_kerneliPiS_S_iiii, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	rows,@object                    # @rows
	.bss
	.globl	rows
	.p2align	2, 0x0
rows:
	.long	0                               # 0x0
	.size	rows, 4

	.type	cols,@object                    # @cols
	.globl	cols
	.p2align	2, 0x0
cols:
	.long	0                               # 0x0
	.size	cols, 4

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

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

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

	.type	pyramid_height,@object          # @pyramid_height
	.globl	pyramid_height
	.p2align	2, 0x0
pyramid_height:
	.long	0                               # 0x0
	.size	pyramid_height, 4

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%d "
	.size	.L.str.1, 4

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"error: %s\n"
	.size	.L.str.3, 11

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

	.type	.L.str.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"pyramidHeight: %d\ngridSize: [%d]\nborder:[%d]\nblockSize: %d\nblockGrid:[%d]\ntargetBlock:[%d]\n"
	.size	.L.str.4, 92

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z14dynproc_kerneliPiS_S_iiii"
	.size	.L__unnamed_1, 30

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Usage: dynproc row_len col_len pyramid_height"
	.size	.Lstr, 46

	.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 _Z29__device_stub__dynproc_kerneliPiS_S_iiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z14dynproc_kerneliPiS_S_iiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z14dynproc_kerneliPiS_S_iiii ; -- Begin function _Z14dynproc_kerneliPiS_S_iiii
	.globl	_Z14dynproc_kerneliPiS_S_iiii
	.p2align	8
	.type	_Z14dynproc_kerneliPiS_S_iiii,@function
_Z14dynproc_kerneliPiS_S_iiii:          ; @_Z14dynproc_kerneliPiS_S_iiii
; %bb.0:
	s_clause 0x4
	s_load_b32 s11, s[0:1], 0x0
	s_load_b64 s[8:9], s[0:1], 0x28
	s_load_b32 s10, s[0:1], 0x20
	s_load_b128 s[4:7], s[0:1], 0x8
	s_load_b64 s[2:3], s[0:1], 0x18
	v_lshlrev_b32_e32 v4, 2, v0
	s_waitcnt lgkmcnt(0)
	s_lshl_b32 s12, s11, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_sub_i32 s1, 0x100, s12
	s_mul_i32 s1, s1, s15
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_sub_i32 s12, s1, s9
	v_add_nc_u32_e32 v1, s12, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, -1, v1
	v_cmp_gt_i32_e64 s0, s10, v1
	s_and_b32 s13, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s0, s13
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s6, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v3, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v4, v2
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s0
	s_cmp_lt_i32 s11, 1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_12
; %bb.3:                                ; %.lr.ph
	s_add_i32 s0, s12, 0xff
	s_sub_i32 s6, 0, s12
	s_ashr_i32 s7, s12, 31
	s_not_b32 s12, s12
	s_and_b32 s6, s7, s6
	s_add_i32 s12, s12, s10
	v_add_nc_u32_e32 v2, -1, v0
	v_add_nc_u32_e32 v3, 1, v0
	s_cmp_ge_i32 s0, s10
	s_mul_i32 s7, s8, s10
	s_cselect_b32 s0, s12, 0xff
	v_max_i32_e32 v2, s6, v2
	v_min_i32_e32 v3, s0, v3
	v_add3_u32 v9, s1, s7, v0
	v_cmp_gt_i32_e32 vcc_lo, s6, v0
	v_cmp_lt_i32_e64 s0, s0, v0
	v_sub_nc_u32_e32 v5, 0xfe, v0
	v_lshlrev_b32_e32 v6, 2, v2
	v_lshlrev_b32_e32 v7, 2, v3
	v_add_nc_u32_e32 v8, 0x400, v4
	v_subrev_nc_u32_e32 v2, s9, v9
	s_mov_b32 s7, 0
	s_or_b32 s1, vcc_lo, s0
	s_add_i32 s6, s11, -1
.LBB0_4:                                ; =>This Inner Loop Header: Depth=1
	v_cmp_ge_u32_e32 vcc_lo, s7, v0
	v_cmp_gt_i32_e64 s0, s7, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s0, vcc_lo, s0
	s_or_b32 s0, s0, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s0, s0, -1
	s_and_saveexec_b32 s8, s0
	s_cbranch_execz .LBB0_6
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[9:10], 2, v[2:3]
	v_add_co_u32 v9, vcc_lo, s4, v9
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	global_load_b32 v3, v[9:10], off
	ds_load_b32 v9, v4
	ds_load_b32 v10, v6
	ds_load_b32 v11, v7
	s_waitcnt lgkmcnt(0)
	v_min3_i32 v9, v10, v9, v11
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v3, v9, v3
	ds_store_b32 v8, v3
.LBB0_6:                                ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	s_cmp_eq_u32 s6, s7
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_10
; %bb.7:                                ;   in Loop: Header=BB0_4 Depth=1
	s_and_saveexec_b32 s8, s0
	s_cbranch_execz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_4 Depth=1
	ds_load_b32 v3, v8
	s_waitcnt lgkmcnt(0)
	ds_store_b32 v4, v3
.LBB0_9:                                ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	v_add_nc_u32_e32 v2, s10, v2
	s_add_i32 s7, s7, 1
	s_mov_b32 s8, 0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_branch .LBB0_11
.LBB0_10:                               ;   in Loop: Header=BB0_4 Depth=1
	s_mov_b32 s8, -1
                                        ; implicit-def: $sgpr7
                                        ; implicit-def: $vgpr2
.LBB0_11:                               ; %Flow
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 vcc_lo, exec_lo, s8
	s_cbranch_vccz .LBB0_4
	s_branch .LBB0_13
.LBB0_12:
                                        ; implicit-def: $sgpr0
.LBB0_13:
	s_and_saveexec_b32 s1, s0
	s_cbranch_execz .LBB0_15
; %bb.14:
	ds_load_b32 v3, v4 offset:1024
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v3, off
.LBB0_15:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14dynproc_kerneliPiS_S_iiii
		.amdhsa_group_segment_fixed_size 2048
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 48
		.amdhsa_user_sgpr_count 15
		.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 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 12
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z14dynproc_kerneliPiS_S_iiii, .Lfunc_end0-_Z14dynproc_kerneliPiS_S_iiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 636
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 2048 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .offset:         44
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 2048
    .kernarg_segment_align: 8
    .kernarg_segment_size: 48
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14dynproc_kerneliPiS_S_iiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z14dynproc_kerneliPiS_S_iiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
