// Compile: nvcc -g -G -arch=sm_61 -std=c++11 assignment5-p5.cu -o assignment5-p5

#include <cmath>
#include <cstdlib>
#include <cuda.h>
#include <iostream>
#include <sys/time.h>

#define N 512
#define THRESHOLD (0.000001)

using std::cerr;
using std::cout;
using std::endl;

// TODO: Edit the function definition as required
__global__ void kernel1(float* d_in, float* d_out) {
  int i = blockIdx.y * blockDim.y + threadIdx.y;
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  int k = blockIdx.z * blockDim.z + threadIdx.z;

  if(i>=1 and i<N-1 and j>=1 and j<N-1 and k>=1 and k<N-1){
    d_out[i*N*N + j*N + k] = 0.8 * (d_in[(i-1)*N*N + j*N + k] + d_in[(i+1)*N*N + j*N + k] 
          + d_in[i*N*N + (j-1)*N + k] + d_in[i*N*N + (j+1)*N + k] + d_in[i*N*N + j*N + (k-1)]
          + d_in[i*N*N + j*N + (k+1)]);
  }
}

// TODO: Edit the function definition as required
__global__ void kernel2(float* d_in, float* d_out) {
  int j = blockIdx.y * blockDim.y + threadIdx.y;
  int k = blockIdx.x * blockDim.x + threadIdx.x;
  int i = blockIdx.z * blockDim.z + threadIdx.z;

  if(i>=1 and i<N-1 and j>=1 and j<N-1 and k>=1 and k<N-1){
    d_out[i*N*N + j*N + k] = 0.8 * (d_in[(i-1)*N*N + j*N + k] + d_in[(i+1)*N*N + j*N + k] 
          + d_in[i*N*N + (j-1)*N + k] + d_in[i*N*N + (j+1)*N + k] + d_in[i*N*N + j*N + (k-1)]
          + d_in[i*N*N + j*N + (k+1)]);
  }
}

__global__ void kernel3(float* d_in, float* d_out) {
  int j = blockIdx.y * blockDim.y + threadIdx.y;
  int k = blockIdx.x * blockDim.x + threadIdx.x;
  int i = blockIdx.z * blockDim.z + threadIdx.z;

  int tj = threadIdx.y;
  int tk = threadIdx.x;
  int ti = threadIdx.z;

  __shared__ float mat[32][8][4];
  mat[tk][tj][ti] = d_in[i*N*N + j*N + k];

  __syncthreads();

  if(i>=1 and i<N-1 and j>=1 and j<N-1 and k>=1 and k<N-1){
    float val = 0;

    if(ti < 1)
      val += d_in[(i-1)*N*N + j*N + k];
    else
      val += mat[tk][tj][ti-1];

    if(ti + 1 > 3)
      val += d_in[(i+1)*N*N + j*N + k];
    else
      val += mat[tk][tj][ti+1];

    if(tj < 1)
      val += d_in[i*N*N + (j-1)*N + k];
    else
      val += mat[tk][tj-1][ti];

    if(tj + 1 > 7)
      val += d_in[i*N*N + (j+1)*N + k];
    else
      val += mat[tk][tj+1][ti];
    
    if(tk < 1)
      val += d_in[i*N*N + j*N + k-1];
    else
      val += mat[tk-1][tj][ti];

    if(tk + 1 > 31)
      val += d_in[i*N*N + j*N + k+1];
    else
      val += mat[tk+1][tj][ti];

    d_out[i*N*N + j*N + k] = 0.8 * val;
  }

  __syncthreads();
}

// TODO: Edit the function definition as required
__host__ void stencil(float* h_in, float* h_out) {
  for(int i = 1; i < N-1; i++){
    for(int j = 1; j < N-1; j++){
      for(int k = 1; k < N-1; k++){
        h_out[i*N*N + j*N + k] = 0.8 * (h_in[(i-1)*N*N + j*N + k] + h_in[(i+1)*N*N + j*N + k] 
          + h_in[i*N*N + (j-1)*N + k] + h_in[i*N*N + (j+1)*N + k] + h_in[i*N*N + j*N + (k-1)]
          + h_in[i*N*N + j*N + (k+1)]);
      }
    }
  }
}

__host__ void check_result(float* w_ref, float* w_opt) {
  double maxdiff = 0.0, this_diff = 0.0;
  int numdiffs = 0;

  for (uint64_t i = 0; i < N; i++) {
    for (uint64_t j = 0; j < N; j++) {
      for (uint64_t k = 0; k < N; k++) {
        this_diff = w_ref[i + N * j + N * N * k] - w_opt[i + N * j + N * N * k];
        if (std::fabs(this_diff) > THRESHOLD) {
          numdiffs++;
          if (this_diff > maxdiff) {
            maxdiff = this_diff;
          }
        }
      }
    }
  }

  if (numdiffs > 0) {
    cout << numdiffs << " Diffs found over THRESHOLD " << THRESHOLD << "; Max Diff = " << maxdiff
         << endl;
  } else {
    cout << "No differences found between base and test versions\n";
  }
}

double rtclock() { // Seconds
  struct timezone Tzp;
  struct timeval Tp;
  int stat;
  stat = gettimeofday(&Tp, &Tzp);
  if (stat != 0) {
    cout << "Error return from gettimeofday: " << stat << "\n";
  }
  return (Tp.tv_sec + Tp.tv_usec * 1.0e-6);
}

int main() {
  uint64_t SIZE = N * N * N;

  float*h_in, *h_cpu_out, *h_gpu1_out, *h_gpu2_out, *h_gpu3_out;

  h_in = (float*)malloc(SIZE * sizeof(float));
  h_cpu_out = (float*)malloc(SIZE * sizeof(float));
  h_gpu1_out = (float*)malloc(SIZE * sizeof(float));
  h_gpu2_out = (float*)malloc(SIZE * sizeof(float));
  h_gpu3_out = (float*)malloc(SIZE * sizeof(float));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        h_in[i * N * N + j * N + k] = rand() % 64;
        h_cpu_out[i * N * N + j * N + k] = 0;
        h_gpu1_out[i * N * N + j * N + k] = 0;
        h_gpu2_out[i * N * N + j * N + k] = 0;
        h_gpu3_out[i * N * N + j * N + k] = 0;
      }
    }
  }

  double clkbegin = rtclock();
  stencil(h_in, h_cpu_out);
  double clkend = rtclock();
  double cpu_time = clkend - clkbegin;
  cout << "Stencil time on CPU: " << cpu_time * 1000 << " msec" << endl;

  cudaError_t status;
  cudaEvent_t start, end;
  // TODO: Fill in kernel1
  // TODO: Adapt check_result() and invoke
  float *d_in, *d_out1;
  dim3 threadsPerBlock(32,32,1);
  dim3 numBlocks(N/threadsPerBlock.x, N/threadsPerBlock.y, N/threadsPerBlock.z);

  status = cudaMalloc(&d_in, SIZE * sizeof(float));
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }
  status = cudaMalloc(&d_out1, SIZE * sizeof(float));
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

  cudaEventCreate(&start);
  cudaEventCreate(&end);

  cudaEventRecord(start, 0);

  status = cudaMemcpy(d_in, h_in, SIZE * sizeof(float), cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }
  status = cudaMemcpy(d_out1, h_gpu1_out, SIZE * sizeof(float), cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel1<<<numBlocks, threadsPerBlock>>>(d_in, d_out1);

  status = cudaMemcpy(h_gpu1_out, d_out1, SIZE * sizeof(float), cudaMemcpyDeviceToHost);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  cudaEventRecord(end, 0);
  cudaEventSynchronize(end);

  float kernel_time;
  cudaEventElapsedTime(&kernel_time, start, end);
  cudaEventDestroy(start);
  cudaEventDestroy(end);

  check_result(h_cpu_out, h_gpu1_out);
  std::cout << "Kernel 1 time (ms): " << kernel_time << "\n";

  // TODO: Fill in kernel2
  // TODO: Adapt check_result() and invoke
  float *d_out2;

  status = cudaMalloc(&d_out2, SIZE * sizeof(float));
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

  cudaEventCreate(&start);
  cudaEventCreate(&end);

  cudaEventRecord(start, 0);

  status = cudaMemcpy(d_in, h_in, SIZE * sizeof(float), cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }
  status = cudaMemcpy(d_out2, h_gpu2_out, SIZE * sizeof(float), cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel2<<<numBlocks, threadsPerBlock>>>(d_in, d_out2);

  status = cudaMemcpy(h_gpu2_out, d_out2, SIZE * sizeof(float), cudaMemcpyDeviceToHost);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  cudaEventRecord(end, 0);
  cudaEventSynchronize(end);

  cudaEventElapsedTime(&kernel_time, start, end);
  cudaEventDestroy(start);
  cudaEventDestroy(end);

  check_result(h_cpu_out, h_gpu2_out);
  std::cout << "Kernel 2 time (ms): " << kernel_time << "\n";

  // kernel 3
  float *d_out3;
  threadsPerBlock = dim3(32,8,4);
  numBlocks = dim3(N/threadsPerBlock.x, N/threadsPerBlock.y, N/threadsPerBlock.z);

  status = cudaMalloc(&d_out3, SIZE * sizeof(float));
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

  cudaEventCreate(&start);
  cudaEventCreate(&end);

  cudaEventRecord(start, 0);

  status = cudaMemcpy(d_in, h_in, SIZE * sizeof(float), cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }
  status = cudaMemcpy(d_out3, h_gpu3_out, SIZE * sizeof(float), cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel3<<<numBlocks, threadsPerBlock>>>(d_in, d_out3);

  status = cudaMemcpy(h_gpu3_out, d_out3, SIZE * sizeof(float), cudaMemcpyDeviceToHost);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  cudaEventRecord(end, 0);
  cudaEventSynchronize(end);

  cudaEventElapsedTime(&kernel_time, start, end);
  cudaEventDestroy(start);
  cudaEventDestroy(end);

  check_result(h_cpu_out, h_gpu3_out);
  std::cout << "Kernel 3 time (ms): " << kernel_time << "\n";

  // TODO: Free memory
  cudaFree(d_in);
  cudaFree(d_out1);
  cudaFree(d_out2);
  cudaFree(d_out3);

  free(h_in);
  free(h_cpu_out);
  free(h_gpu1_out);
  free(h_gpu2_out);
  free(h_gpu3_out);

  return EXIT_SUCCESS;
}

	.file	"tmpxft_003a1606_00000000-6_assignment5-p5.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3641:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3641:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7stencilPfS_
	.type	_Z7stencilPfS_, @function
_Z7stencilPfS_:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	$2048, %r11d
	movq	%rdi, %rcx
	movq	%rsi, %r10
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	1048576(%rdi), %r8
	movl	$512, %r9d
	subq	%rdi, %r11
	movsd	.LC0(%rip), %xmm1
.L3:
	addl	$512, %r9d
	movq	%r8, %rax
	movl	$1, %edi
.L7:
	incl	%edi
	leaq	(%r11,%rax), %rsi
	movl	$1, %edx
	leaq	1050624(%rax), %rbp
	leaq	4096(%rax), %rbx
.L4:
	movss	-1046528(%rax,%rdx,4), %xmm0
	addss	0(%rbp,%rdx,4), %xmm0
	addss	(%rax,%rdx,4), %xmm0
	addss	(%rbx,%rdx,4), %xmm0
	incq	%rdx
	addss	(%rcx,%rsi), %xmm0
	addss	8(%rcx,%rsi), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 4(%r10,%rsi)
	addq	$4, %rsi
	cmpq	$511, %rdx
	jne	.L4
	addq	$2048, %rax
	cmpl	$511, %edi
	jne	.L7
	addq	$1048576, %r8
	cmpl	$261632, %r9d
	jne	.L3
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z7stencilPfS_, .-_Z7stencilPfS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	" Diffs found over THRESHOLD "
.LC5:
	.string	"; Max Diff = "
.LC6:
	.string	"No differences found between base and test versions\n"
	.text
	.globl	_Z12check_resultPfS_
	.type	_Z12check_resultPfS_, @function
_Z12check_resultPfS_:
.LFB3636:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rsi, %r9
	xorl	%eax, %eax
	xorl	%esi, %esi
	movq	.LC2(%rip), %xmm2
	xorps	%xmm1, %xmm1
.L12:
	leaq	0(,%rax,4), %r8
	xorl	%ecx, %ecx
.L18:
	movq	%r8, %rdx
	xorl	%r10d, %r10d
.L15:
	movss	(%rdi,%rdx), %xmm0
	subss	(%r9,%rdx), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movaps	%xmm0, %xmm3
	andps	%xmm2, %xmm3
	comisd	.LC3(%rip), %xmm3
	jbe	.L13
	maxsd	%xmm1, %xmm0
	incl	%esi
	movaps	%xmm0, %xmm1
.L13:
	incq	%r10
	addq	$1048576, %rdx
	cmpq	$512, %r10
	jne	.L15
	incq	%rcx
	addq	$2048, %r8
	cmpq	$512, %rcx
	jne	.L18
	incq	%rax
	cmpq	$512, %rax
	jne	.L12
	testl	%esi, %esi
	movsd	%xmm1, 8(%rsp)
	leaq	_ZSt4cout(%rip), %rdi
	jle	.L19
	call	_ZNSolsEi@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	.LC3(%rip), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC5(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm1
	movq	%rax, %rdi
	movaps	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	movq	%rax, %rdi
	jmp	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L19:
	.cfi_restore_state
	leaq	.LC6(%rip), %rsi
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	jmp	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	.cfi_endproc
.LFE3636:
	.size	_Z12check_resultPfS_, .-_Z12check_resultPfS_
	.section	.rodata.str1.1
.LC7:
	.string	"Error return from gettimeofday: "
.LC8:
	.string	"\n"
	.text
	.globl	_Z7rtclockv
	.type	_Z7rtclockv, @function
_Z7rtclockv:
.LFB3637:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	testl	%eax, %eax
	je	.L25
	leaq	.LC7(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movl	%eax, %ebx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L25:
	cvtsi2sdq	16(%rsp), %xmm0
	mulsd	.LC3(%rip), %xmm0
	cvtsi2sdq	8(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z7rtclockv, .-_Z7rtclockv
	.globl	_Z28__device_stub__Z7kernel1PfS_PfS_
	.type	_Z28__device_stub__Z7kernel1PfS_PfS_, @function
_Z28__device_stub__Z7kernel1PfS_PfS_:
.LFB3663:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L31
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7kernel1PfS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L31:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z28__device_stub__Z7kernel1PfS_PfS_, .-_Z28__device_stub__Z7kernel1PfS_PfS_
	.globl	_Z7kernel1PfS_
	.type	_Z7kernel1PfS_, @function
_Z7kernel1PfS_:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z7kernel1PfS_PfS_
	.cfi_endproc
.LFE3664:
	.size	_Z7kernel1PfS_, .-_Z7kernel1PfS_
	.globl	_Z28__device_stub__Z7kernel2PfS_PfS_
	.type	_Z28__device_stub__Z7kernel2PfS_PfS_, @function
_Z28__device_stub__Z7kernel2PfS_PfS_:
.LFB3665:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7kernel2PfS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L36:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L38:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3665:
	.size	_Z28__device_stub__Z7kernel2PfS_PfS_, .-_Z28__device_stub__Z7kernel2PfS_PfS_
	.globl	_Z7kernel2PfS_
	.type	_Z7kernel2PfS_, @function
_Z7kernel2PfS_:
.LFB3666:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z7kernel2PfS_PfS_
	.cfi_endproc
.LFE3666:
	.size	_Z7kernel2PfS_, .-_Z7kernel2PfS_
	.globl	_Z28__device_stub__Z7kernel3PfS_PfS_
	.type	_Z28__device_stub__Z7kernel3PfS_PfS_, @function
_Z28__device_stub__Z7kernel3PfS_PfS_:
.LFB3667:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z7kernel3PfS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L41:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3667:
	.size	_Z28__device_stub__Z7kernel3PfS_PfS_, .-_Z28__device_stub__Z7kernel3PfS_PfS_
	.globl	_Z7kernel3PfS_
	.type	_Z7kernel3PfS_, @function
_Z7kernel3PfS_:
.LFB3668:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z7kernel3PfS_PfS_
	.cfi_endproc
.LFE3668:
	.size	_Z7kernel3PfS_, .-_Z7kernel3PfS_
	.section	.rodata.str1.1
.LC10:
	.string	"Stencil time on CPU: "
.LC12:
	.string	" msec"
.LC13:
	.string	"cudaMalloc() failed"
.LC14:
	.string	"cudaMemcpy() failed"
.LC15:
	.string	"Kernel 1 time (ms): "
.LC16:
	.string	"Kernel 2 time (ms): "
.LC17:
	.string	"Kernel 3 time (ms): "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3638:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$536870912, %edi
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %r13
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rax, (%rsp)
.L47:
	movq	%r15, %rax
	xorl	%r14d, %r14d
	salq	$20, %rax
	movq	%rax, 8(%rsp)
.L51:
	movq	8(%rsp), %rax
	movq	%r14, %rcx
	movl	$512, %esi
	salq	$11, %rcx
	addq	%rax, %rcx
.L48:
	movl	%esi, 28(%rsp)
	movq	%rcx, 16(%rsp)
	call	rand@PLT
	movl	$64, %ecx
	movl	28(%rsp), %esi
	cltd
	idivl	%ecx
	movq	16(%rsp), %rcx
	movq	(%rsp), %rax
	movl	$0x00000000, (%rbx,%rcx)
	movl	$0x00000000, 0(%r13,%rcx)
	movl	$0x00000000, (%r12,%rcx)
	movl	$0x00000000, (%rax,%rcx)
	cvtsi2ssl	%edx, %xmm0
	movss	%xmm0, 0(%rbp,%rcx)
	addq	$4, %rcx
	decl	%esi
	jne	.L48
	incq	%r14
	cmpq	$512, %r14
	jne	.L51
	incq	%r15
	cmpq	$512, %r15
	jne	.L47
	call	_Z7rtclockv
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	movsd	%xmm0, 8(%rsp)
	call	_Z7stencilPfS_
	call	_Z7rtclockv
	subsd	8(%rsp), %xmm0
	leaq	.LC10(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movsd	%xmm0, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	8(%rsp), %xmm0
	mulsd	.LC11(%rip), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	64(%rsp), %rdi
	movabsq	$68719476752, %rax
	movl	$536870912, %esi
	movq	%rax, 108(%rsp)
	movl	$512, 116(%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L73
	leaq	72(%rsp), %rdi
	movl	$536870912, %esi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L54
.L73:
	leaq	.LC13(%rip), %rdx
.L74:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L46
.L54:
	leaq	48(%rsp), %r14
	leaq	56(%rsp), %r15
	movq	%r14, %rdi
	call	cudaEventCreate@PLT
	movq	%r15, %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	movl	$536870912, %edx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movq	108(%rsp), %rdi
	movl	116(%rsp), %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$137438953504, %rdx
	movl	$1, %ecx
	movl	$1, 104(%rsp)
	movq	%rdx, 96(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L58
	movq	72(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z28__device_stub__Z7kernel1PfS_PfS_
.L58:
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movl	$536870912, %edx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	44(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	%r13, %rsi
	movq	%rbx, %rdi
	call	_Z12check_resultPfS_
	leaq	.LC15(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	44(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	80(%rsp), %rdi
	movl	$536870912, %esi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L73
	movq	%r14, %rdi
	call	cudaEventCreate@PLT
	movq	%r15, %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	movl	$536870912, %edx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movl	104(%rsp), %ecx
	movq	96(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	108(%rsp), %rdi
	movl	116(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L63
	movq	80(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z28__device_stub__Z7kernel2PfS_PfS_
.L63:
	movq	80(%rsp), %rsi
	movl	$2, %ecx
	movl	$536870912, %edx
	movq	%r12, %rdi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	%r12, %rsi
	movq	%rbx, %rdi
	call	_Z12check_resultPfS_
	leaq	.LC16(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	44(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	88(%rsp), %rdi
	movl	$536870912, %esi
	movabsq	$549755813952, %rax
	movq	%rax, 112(%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L73
	movq	%r14, %rdi
	call	cudaEventCreate@PLT
	movq	%r15, %rdi
	call	cudaEventCreate@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movq	(%rsp), %rsi
	movq	88(%rsp), %rdi
	movl	$1, %ecx
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L75
	movl	$2147483649, %eax
	movq	108(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$3, %rax
	movl	116(%rsp), %esi
	movq	%rax, 100(%rsp)
	movl	104(%rsp), %ecx
	movq	96(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L68
	movq	88(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	_Z28__device_stub__Z7kernel3PfS_PfS_
.L68:
	movq	88(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	$2, %ecx
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L69
.L75:
	leaq	.LC14(%rip), %rdx
	jmp	.L74
.L69:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	56(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	56(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z12check_resultPfS_
	leaq	.LC17(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	44(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	xorl	%eax, %eax
.L46:
	movq	120(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L70
	call	__stack_chk_fail@PLT
.L70:
	addq	$136, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3638:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z7kernel3PfS_"
.LC19:
	.string	"_Z7kernel2PfS_"
.LC20:
	.string	"_Z7kernel1PfS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3670:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC18(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7kernel3PfS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC19(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z7kernel2PfS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC20(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z7kernel1PfS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3670:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	-1717986918
	.long	1072273817
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC2:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC3:
	.long	-1598689907
	.long	1051772663
	.align 8
.LC11:
	.long	0
	.long	1083129856
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

// Compile: nvcc -g -G -arch=sm_61 -std=c++11 assignment5-p5.cu -o assignment5-p5

#include <cmath>
#include <cstdlib>
#include <hip/hip_runtime.h>
#include <iostream>
#include <sys/time.h>

#define N 512
#define THRESHOLD (0.000001)

using std::cerr;
using std::cout;
using std::endl;

// TODO: Edit the function definition as required
__global__ void kernel1(float* d_in, float* d_out) {
  int i = blockIdx.y * blockDim.y + threadIdx.y;
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  int k = blockIdx.z * blockDim.z + threadIdx.z;

  if(i>=1 and i<N-1 and j>=1 and j<N-1 and k>=1 and k<N-1){
    d_out[i*N*N + j*N + k] = 0.8 * (d_in[(i-1)*N*N + j*N + k] + d_in[(i+1)*N*N + j*N + k] 
          + d_in[i*N*N + (j-1)*N + k] + d_in[i*N*N + (j+1)*N + k] + d_in[i*N*N + j*N + (k-1)]
          + d_in[i*N*N + j*N + (k+1)]);
  }
}

// TODO: Edit the function definition as required
__global__ void kernel2(float* d_in, float* d_out) {
  int j = blockIdx.y * blockDim.y + threadIdx.y;
  int k = blockIdx.x * blockDim.x + threadIdx.x;
  int i = blockIdx.z * blockDim.z + threadIdx.z;

  if(i>=1 and i<N-1 and j>=1 and j<N-1 and k>=1 and k<N-1){
    d_out[i*N*N + j*N + k] = 0.8 * (d_in[(i-1)*N*N + j*N + k] + d_in[(i+1)*N*N + j*N + k] 
          + d_in[i*N*N + (j-1)*N + k] + d_in[i*N*N + (j+1)*N + k] + d_in[i*N*N + j*N + (k-1)]
          + d_in[i*N*N + j*N + (k+1)]);
  }
}

__global__ void kernel3(float* d_in, float* d_out) {
  int j = blockIdx.y * blockDim.y + threadIdx.y;
  int k = blockIdx.x * blockDim.x + threadIdx.x;
  int i = blockIdx.z * blockDim.z + threadIdx.z;

  int tj = threadIdx.y;
  int tk = threadIdx.x;
  int ti = threadIdx.z;

  __shared__ float mat[32][8][4];
  mat[tk][tj][ti] = d_in[i*N*N + j*N + k];

  __syncthreads();

  if(i>=1 and i<N-1 and j>=1 and j<N-1 and k>=1 and k<N-1){
    float val = 0;

    if(ti < 1)
      val += d_in[(i-1)*N*N + j*N + k];
    else
      val += mat[tk][tj][ti-1];

    if(ti + 1 > 3)
      val += d_in[(i+1)*N*N + j*N + k];
    else
      val += mat[tk][tj][ti+1];

    if(tj < 1)
      val += d_in[i*N*N + (j-1)*N + k];
    else
      val += mat[tk][tj-1][ti];

    if(tj + 1 > 7)
      val += d_in[i*N*N + (j+1)*N + k];
    else
      val += mat[tk][tj+1][ti];
    
    if(tk < 1)
      val += d_in[i*N*N + j*N + k-1];
    else
      val += mat[tk-1][tj][ti];

    if(tk + 1 > 31)
      val += d_in[i*N*N + j*N + k+1];
    else
      val += mat[tk+1][tj][ti];

    d_out[i*N*N + j*N + k] = 0.8 * val;
  }

  __syncthreads();
}

// TODO: Edit the function definition as required
__host__ void stencil(float* h_in, float* h_out) {
  for(int i = 1; i < N-1; i++){
    for(int j = 1; j < N-1; j++){
      for(int k = 1; k < N-1; k++){
        h_out[i*N*N + j*N + k] = 0.8 * (h_in[(i-1)*N*N + j*N + k] + h_in[(i+1)*N*N + j*N + k] 
          + h_in[i*N*N + (j-1)*N + k] + h_in[i*N*N + (j+1)*N + k] + h_in[i*N*N + j*N + (k-1)]
          + h_in[i*N*N + j*N + (k+1)]);
      }
    }
  }
}

__host__ void check_result(float* w_ref, float* w_opt) {
  double maxdiff = 0.0, this_diff = 0.0;
  int numdiffs = 0;

  for (uint64_t i = 0; i < N; i++) {
    for (uint64_t j = 0; j < N; j++) {
      for (uint64_t k = 0; k < N; k++) {
        this_diff = w_ref[i + N * j + N * N * k] - w_opt[i + N * j + N * N * k];
        if (std::fabs(this_diff) > THRESHOLD) {
          numdiffs++;
          if (this_diff > maxdiff) {
            maxdiff = this_diff;
          }
        }
      }
    }
  }

  if (numdiffs > 0) {
    cout << numdiffs << " Diffs found over THRESHOLD " << THRESHOLD << "; Max Diff = " << maxdiff
         << endl;
  } else {
    cout << "No differences found between base and test versions\n";
  }
}

double rtclock() { // Seconds
  struct timezone Tzp;
  struct timeval Tp;
  int stat;
  stat = gettimeofday(&Tp, &Tzp);
  if (stat != 0) {
    cout << "Error return from gettimeofday: " << stat << "\n";
  }
  return (Tp.tv_sec + Tp.tv_usec * 1.0e-6);
}

int main() {
  uint64_t SIZE = N * N * N;

  float*h_in, *h_cpu_out, *h_gpu1_out, *h_gpu2_out, *h_gpu3_out;

  h_in = (float*)malloc(SIZE * sizeof(float));
  h_cpu_out = (float*)malloc(SIZE * sizeof(float));
  h_gpu1_out = (float*)malloc(SIZE * sizeof(float));
  h_gpu2_out = (float*)malloc(SIZE * sizeof(float));
  h_gpu3_out = (float*)malloc(SIZE * sizeof(float));

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        h_in[i * N * N + j * N + k] = rand() % 64;
        h_cpu_out[i * N * N + j * N + k] = 0;
        h_gpu1_out[i * N * N + j * N + k] = 0;
        h_gpu2_out[i * N * N + j * N + k] = 0;
        h_gpu3_out[i * N * N + j * N + k] = 0;
      }
    }
  }

  double clkbegin = rtclock();
  stencil(h_in, h_cpu_out);
  double clkend = rtclock();
  double cpu_time = clkend - clkbegin;
  cout << "Stencil time on CPU: " << cpu_time * 1000 << " msec" << endl;

  hipError_t status;
  hipEvent_t start, end;
  // TODO: Fill in kernel1
  // TODO: Adapt check_result() and invoke
  float *d_in, *d_out1;
  dim3 threadsPerBlock(32,32,1);
  dim3 numBlocks(N/threadsPerBlock.x, N/threadsPerBlock.y, N/threadsPerBlock.z);

  status = hipMalloc(&d_in, SIZE * sizeof(float));
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }
  status = hipMalloc(&d_out1, SIZE * sizeof(float));
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

  hipEventCreate(&start);
  hipEventCreate(&end);

  hipEventRecord(start, 0);

  status = hipMemcpy(d_in, h_in, SIZE * sizeof(float), hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }
  status = hipMemcpy(d_out1, h_gpu1_out, SIZE * sizeof(float), hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel1<<<numBlocks, threadsPerBlock>>>(d_in, d_out1);

  status = hipMemcpy(h_gpu1_out, d_out1, SIZE * sizeof(float), hipMemcpyDeviceToHost);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  hipEventRecord(end, 0);
  hipEventSynchronize(end);

  float kernel_time;
  hipEventElapsedTime(&kernel_time, start, end);
  hipEventDestroy(start);
  hipEventDestroy(end);

  check_result(h_cpu_out, h_gpu1_out);
  std::cout << "Kernel 1 time (ms): " << kernel_time << "\n";

  // TODO: Fill in kernel2
  // TODO: Adapt check_result() and invoke
  float *d_out2;

  status = hipMalloc(&d_out2, SIZE * sizeof(float));
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

  hipEventCreate(&start);
  hipEventCreate(&end);

  hipEventRecord(start, 0);

  status = hipMemcpy(d_in, h_in, SIZE * sizeof(float), hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }
  status = hipMemcpy(d_out2, h_gpu2_out, SIZE * sizeof(float), hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel2<<<numBlocks, threadsPerBlock>>>(d_in, d_out2);

  status = hipMemcpy(h_gpu2_out, d_out2, SIZE * sizeof(float), hipMemcpyDeviceToHost);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  hipEventRecord(end, 0);
  hipEventSynchronize(end);

  hipEventElapsedTime(&kernel_time, start, end);
  hipEventDestroy(start);
  hipEventDestroy(end);

  check_result(h_cpu_out, h_gpu2_out);
  std::cout << "Kernel 2 time (ms): " << kernel_time << "\n";

  // kernel 3
  float *d_out3;
  threadsPerBlock = dim3(32,8,4);
  numBlocks = dim3(N/threadsPerBlock.x, N/threadsPerBlock.y, N/threadsPerBlock.z);

  status = hipMalloc(&d_out3, SIZE * sizeof(float));
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

  hipEventCreate(&start);
  hipEventCreate(&end);

  hipEventRecord(start, 0);

  status = hipMemcpy(d_in, h_in, SIZE * sizeof(float), hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }
  status = hipMemcpy(d_out3, h_gpu3_out, SIZE * sizeof(float), hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel3<<<numBlocks, threadsPerBlock>>>(d_in, d_out3);

  status = hipMemcpy(h_gpu3_out, d_out3, SIZE * sizeof(float), hipMemcpyDeviceToHost);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  hipEventRecord(end, 0);
  hipEventSynchronize(end);

  hipEventElapsedTime(&kernel_time, start, end);
  hipEventDestroy(start);
  hipEventDestroy(end);

  check_result(h_cpu_out, h_gpu3_out);
  std::cout << "Kernel 3 time (ms): " << kernel_time << "\n";

  // TODO: Free memory
  hipFree(d_in);
  hipFree(d_out1);
  hipFree(d_out2);
  hipFree(d_out3);

  free(h_in);
  free(h_cpu_out);
  free(h_gpu1_out);
  free(h_gpu2_out);
  free(h_gpu3_out);

  return EXIT_SUCCESS;
}

	.text
	.file	"assignment5-p5.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z22__device_stub__kernel1PfS_  # -- Begin function _Z22__device_stub__kernel1PfS_
	.type	_Z22__device_stub__kernel1PfS_,@function
_Z22__device_stub__kernel1PfS_:         # @_Z22__device_stub__kernel1PfS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7kernel1PfS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22__device_stub__kernel1PfS_, .Lfunc_end0-_Z22__device_stub__kernel1PfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__kernel2PfS_  # -- Begin function _Z22__device_stub__kernel2PfS_
	.type	_Z22__device_stub__kernel2PfS_,@function
_Z22__device_stub__kernel2PfS_:         # @_Z22__device_stub__kernel2PfS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7kernel2PfS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z22__device_stub__kernel2PfS_, .Lfunc_end1-_Z22__device_stub__kernel2PfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__kernel3PfS_  # -- Begin function _Z22__device_stub__kernel3PfS_
	.type	_Z22__device_stub__kernel3PfS_,@function
_Z22__device_stub__kernel3PfS_:         # @_Z22__device_stub__kernel3PfS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7kernel3PfS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z22__device_stub__kernel3PfS_, .Lfunc_end2-_Z22__device_stub__kernel3PfS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7stencilPfS_
.LCPI3_0:
	.quad	0x3fe999999999999a              # double 0.80000000000000004
	.text
	.globl	_Z7stencilPfS_
	.type	_Z7stencilPfS_,@function
_Z7stencilPfS_:                         # @_Z7stencilPfS_
	.cfi_startproc
# %bb.0:
	addq	$2099204, %rdi                  # imm = 0x200804
	addq	$1050628, %rsi                  # imm = 0x100804
	movl	$1, %eax
	movsd	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$2048, %ecx                     # imm = 0x800
	movl	$1048576, %edx                  # imm = 0x100000
.LBB3_1:                                # %.preheader35
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
                                        #       Child Loop BB3_3 Depth 3
	movq	%rsi, %r8
	movq	%rdi, %r9
	movl	$1, %r10d
.LBB3_2:                                # %.preheader
                                        #   Parent Loop BB3_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_3 Depth 3
	xorl	%r11d, %r11d
.LBB3_3:                                #   Parent Loop BB3_1 Depth=1
                                        #     Parent Loop BB3_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	-2097152(%r9,%r11,4), %xmm1     # xmm1 = mem[0],zero,zero,zero
	addss	(%r9,%r11,4), %xmm1
	addss	-1050624(%r9,%r11,4), %xmm1
	addss	-1046528(%r9,%r11,4), %xmm1
	addss	-1048580(%r9,%r11,4), %xmm1
	addss	-1048572(%r9,%r11,4), %xmm1
	cvtss2sd	%xmm1, %xmm1
	mulsd	%xmm0, %xmm1
	cvtsd2ss	%xmm1, %xmm1
	movss	%xmm1, (%r8,%r11,4)
	incq	%r11
	cmpq	$510, %r11                      # imm = 0x1FE
	jne	.LBB3_3
# %bb.4:                                #   in Loop: Header=BB3_2 Depth=2
	incq	%r10
	addq	%rcx, %r9
	addq	%rcx, %r8
	cmpq	$511, %r10                      # imm = 0x1FF
	jne	.LBB3_2
# %bb.5:                                #   in Loop: Header=BB3_1 Depth=1
	incq	%rax
	addq	%rdx, %rdi
	addq	%rdx, %rsi
	cmpq	$511, %rax                      # imm = 0x1FF
	jne	.LBB3_1
# %bb.6:
	retq
.Lfunc_end3:
	.size	_Z7stencilPfS_, .Lfunc_end3-_Z7stencilPfS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z12check_resultPfS_
.LCPI4_0:
	.quad	0x7fffffffffffffff              # double NaN
	.quad	0x7fffffffffffffff              # double NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI4_1:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	_Z12check_resultPfS_
	.type	_Z12check_resultPfS_,@function
_Z12check_resultPfS_:                   # @_Z12check_resultPfS_
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	xorpd	%xmm4, %xmm4
	xorl	%ecx, %ecx
	movaps	.LCPI4_0(%rip), %xmm0           # xmm0 = [NaN,NaN]
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	movl	$2048, %edx                     # imm = 0x800
	xorl	%eax, %eax
.LBB4_1:                                # %.preheader29
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_2 Depth 2
                                        #       Child Loop BB4_3 Depth 3
	movq	%rsi, %r8
	movq	%rdi, %r9
	xorl	%r10d, %r10d
.LBB4_2:                                # %.preheader
                                        #   Parent Loop BB4_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_3 Depth 3
	xorl	%r11d, %r11d
.LBB4_3:                                #   Parent Loop BB4_1 Depth=1
                                        #     Parent Loop BB4_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	(%r9,%r11), %xmm2               # xmm2 = mem[0],zero,zero,zero
	subss	(%r8,%r11), %xmm2
	cvtss2sd	%xmm2, %xmm2
	movaps	%xmm2, %xmm3
	andps	%xmm0, %xmm3
	ucomisd	%xmm1, %xmm3
	jbe	.LBB4_6
# %bb.4:                                #   in Loop: Header=BB4_3 Depth=3
	incl	%eax
	ucomisd	%xmm4, %xmm2
	jbe	.LBB4_6
# %bb.5:                                #   in Loop: Header=BB4_3 Depth=3
	movapd	%xmm2, %xmm4
.LBB4_6:                                #   in Loop: Header=BB4_3 Depth=3
	addq	$1048576, %r11                  # imm = 0x100000
	cmpq	$536870912, %r11                # imm = 0x20000000
	jne	.LBB4_3
# %bb.7:                                #   in Loop: Header=BB4_2 Depth=2
	incq	%r10
	addq	%rdx, %r9
	addq	%rdx, %r8
	cmpq	$512, %r10                      # imm = 0x200
	jne	.LBB4_2
# %bb.8:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%rcx
	addq	$4, %rdi
	addq	$4, %rsi
	cmpq	$512, %rcx                      # imm = 0x200
	jne	.LBB4_1
# %bb.9:
	movl	$_ZSt4cout, %edi
	testl	%eax, %eax
	jle	.LBB4_11
# %bb.10:
	movl	%eax, %esi
	movsd	%xmm4, 8(%rsp)                  # 8-byte Spill
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movl	$.L.str, %esi
	movl	$28, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	.LCPI4_1(%rip), %xmm0           # xmm0 = mem[0],zero
	movq	%rbx, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.1, %esi
	movl	$13, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%rbx, %rdi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_ZNSo5flushEv                   # TAILCALL
.LBB4_11:
	.cfi_def_cfa_offset 32
	movl	$.L.str.2, %esi
	movl	$52, %edx
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l # TAILCALL
.Lfunc_end4:
	.size	_Z12check_resultPfS_, .Lfunc_end4-_Z12check_resultPfS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7rtclockv
.LCPI5_0:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	_Z7rtclockv
	.type	_Z7rtclockv,@function
_Z7rtclockv:                            # @_Z7rtclockv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	leaq	8(%rsp), %rdi
	leaq	24(%rsp), %rsi
	callq	gettimeofday
	testl	%eax, %eax
	je	.LBB5_2
# %bb.1:
	movl	%eax, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$32, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%ebx, %esi
	callq	_ZNSolsEi
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB5_2:
	cvtsi2sdq	8(%rsp), %xmm1
	cvtsi2sdq	16(%rsp), %xmm0
	mulsd	.LCPI5_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z7rtclockv, .Lfunc_end5-_Z7rtclockv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI6_0:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	.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	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %rbx
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r14
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r15
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r12
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, %r13
	movq	%rbx, 96(%rsp)                  # 8-byte Spill
	movq	%r14, 88(%rsp)                  # 8-byte Spill
	movq	%r15, 80(%rsp)                  # 8-byte Spill
	movq	%r12, 64(%rsp)                  # 8-byte Spill
	movq	%r12, %rcx
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	xorl	%edx, %edx
.LBB6_1:                                # %.preheader158
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_2 Depth 2
                                        #       Child Loop BB6_3 Depth 3
	movq	%rdx, 104(%rsp)                 # 8-byte Spill
	movq	%rbx, 144(%rsp)                 # 8-byte Spill
	movq	%rbx, %r12
	movq	%r14, 136(%rsp)                 # 8-byte Spill
	movq	%r15, 128(%rsp)                 # 8-byte Spill
	movq	%r15, %rbx
	movq	%rcx, 120(%rsp)                 # 8-byte Spill
	movq	%r13, 112(%rsp)                 # 8-byte Spill
	xorl	%r9d, %r9d
.LBB6_2:                                # %.preheader
                                        #   Parent Loop BB6_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB6_3 Depth 3
	movq	%r9, 24(%rsp)                   # 8-byte Spill
	xorl	%r15d, %r15d
.LBB6_3:                                #   Parent Loop BB6_1 Depth=1
                                        #     Parent Loop BB6_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movq	%rcx, %rbp
	callq	rand
	xorl	%r9d, %r9d
                                        # kill: def $eax killed $eax def $rax
	leal	63(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-64, %ecx
	subl	%ecx, %eax
	movq	%rbp, %rcx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%r12,%r15)
	movl	%r9d, (%r14,%r15)
	movl	%r9d, (%rbx,%r15)
	movl	%r9d, (%rbp,%r15)
	movl	%r9d, (%r13,%r15)
	addq	$4, %r15
	cmpq	$2048, %r15                     # imm = 0x800
	jne	.LBB6_3
# %bb.4:                                #   in Loop: Header=BB6_2 Depth=2
	movq	24(%rsp), %r9                   # 8-byte Reload
	incq	%r9
	movl	$2048, %eax                     # imm = 0x800
	addq	%rax, %r13
	addq	%rax, %rcx
	addq	%rax, %rbx
	addq	%rax, %r14
	addq	%rax, %r12
	cmpq	$512, %r9                       # imm = 0x200
	jne	.LBB6_2
# %bb.5:                                #   in Loop: Header=BB6_1 Depth=1
	movq	104(%rsp), %rdx                 # 8-byte Reload
	incq	%rdx
	movl	$1048576, %eax                  # imm = 0x100000
	movq	112(%rsp), %r13                 # 8-byte Reload
	addq	%rax, %r13
	movq	120(%rsp), %rcx                 # 8-byte Reload
	addq	%rax, %rcx
	movq	128(%rsp), %r15                 # 8-byte Reload
	addq	%rax, %r15
	movq	136(%rsp), %r14                 # 8-byte Reload
	addq	%rax, %r14
	movq	144(%rsp), %rbx                 # 8-byte Reload
	addq	%rax, %rbx
	cmpq	$512, %rdx                      # imm = 0x200
	jne	.LBB6_1
# %bb.6:
	callq	_Z7rtclockv
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movq	96(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movq	88(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	callq	_Z7stencilPfS_
	callq	_Z7rtclockv
	subsd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	mulsd	.LCPI6_0(%rip), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.6, %esi
	movl	$5, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r13), %rax
	movq	-24(%rax), %rdi
	addq	%r13, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r13, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	leaq	16(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.9:
	leaq	56(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.10:
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.12:
	movq	56(%rsp), %rdi
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	80(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.13:
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movabsq	$68719476752, %r13              # imm = 0x1000000010
	movq	%r13, %rdi
	movl	$512, %esi                      # imm = 0x200
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_15
# %bb.14:
	movq	16(%rsp), %rdi
	movq	56(%rsp), %rsi
	callq	_Z22__device_stub__kernel1PfS_
.LBB6_15:
	movq	56(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	movq	64(%rsp), %r12                  # 8-byte Reload
	jne	.LBB6_16
# %bb.17:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	36(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventElapsedTime
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movq	%r14, %rdi
	movq	%r15, %rsi
	callq	_Z12check_resultPfS_
	movl	$_ZSt4cout, %edi
	movl	$.L.str.9, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%rbp), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	48(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.18:
	leaq	8(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%rbp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.19:
	movq	48(%rsp), %rdi
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.20:
	movq	%r13, %rdi
	movl	$512, %esi                      # imm = 0x200
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_22
# %bb.21:
	movq	16(%rsp), %rdi
	movq	48(%rsp), %rsi
	callq	_Z22__device_stub__kernel2PfS_
.LBB6_22:
	movq	48(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_16
# %bb.23:
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	36(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	_Z12check_resultPfS_
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%r13), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	40(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.24:
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.25:
	movq	40(%rsp), %rdi
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	72(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.26:
	movabsq	$274877906960, %rdi             # imm = 0x4000000010
	movabsq	$34359738400, %rdx              # imm = 0x800000020
	movl	$128, %esi
	movl	$4, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.27:
	movq	16(%rsp), %rdi
	movq	40(%rsp), %rsi
	callq	_Z22__device_stub__kernel3PfS_
.LBB6_28:
	movq	40(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.29:
	movq	(%rsp), %rdi
	xorl	%ebp, %ebp
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	36(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movq	%r14, %rdi
	movq	%r12, %rsi
	callq	_Z12check_resultPfS_
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%r13), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.4, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	64(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	%r12, %rdi
	callq	free
	jmp	.LBB6_30
.LBB6_11:
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
	movl	$19, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB6_30
.LBB6_7:
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	jmp	.LBB6_8
.LBB6_16:
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
.LBB6_8:
	movl	$19, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %ebp
.LBB6_30:
	movl	%ebp, %eax
	addq	$152, %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_end6:
	.size	main, .Lfunc_end6-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7kernel1PfS_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7kernel2PfS_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7kernel3PfS_, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z7kernel1PfS_,@object          # @_Z7kernel1PfS_
	.section	.rodata,"a",@progbits
	.globl	_Z7kernel1PfS_
	.p2align	3, 0x0
_Z7kernel1PfS_:
	.quad	_Z22__device_stub__kernel1PfS_
	.size	_Z7kernel1PfS_, 8

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

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	" Diffs found over THRESHOLD "
	.size	.L.str, 29

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"; Max Diff = "
	.size	.L.str.1, 14

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"No differences found between base and test versions\n"
	.size	.L.str.2, 53

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Error return from gettimeofday: "
	.size	.L.str.3, 33

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Stencil time on CPU: "
	.size	.L.str.5, 22

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"cudaMalloc() failed"
	.size	.L.str.7, 20

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"cudaMemcpy() failed"
	.size	.L.str.8, 20

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Kernel 1 time (ms): "
	.size	.L.str.9, 21

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Kernel 2 time (ms): "
	.size	.L.str.10, 21

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Kernel 3 time (ms): "
	.size	.L.str.11, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7kernel1PfS_"
	.size	.L__unnamed_1, 15

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7kernel2PfS_"
	.size	.L__unnamed_2, 15

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z7kernel3PfS_"
	.size	.L__unnamed_3, 15

	.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 _Z22__device_stub__kernel1PfS_
	.addrsig_sym _Z22__device_stub__kernel2PfS_
	.addrsig_sym _Z22__device_stub__kernel3PfS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7kernel1PfS_
	.addrsig_sym _Z7kernel2PfS_
	.addrsig_sym _Z7kernel3PfS_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7kernel1PfS_          ; -- Begin function _Z7kernel1PfS_
	.globl	_Z7kernel1PfS_
	.p2align	8
	.type	_Z7kernel1PfS_,@function
_Z7kernel1PfS_:                         ; @_Z7kernel1PfS_
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x1c
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	v_bfe_u32 v6, v0, 20, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s3, s3, 0xffff
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s14, s4, v[1:2]
	v_mad_u64_u32 v[3:4], null, s13, s2, v[5:6]
	v_mad_u64_u32 v[0:1], null, s15, s3, v[6:7]
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v4, -1, v2
	v_add_nc_u32_e32 v5, -1, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, -1, v0
	v_max3_u32 v4, v4, v5, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e32 0x1fe, v4
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_lshlrev_b32_e32 v2, 18, v2
	s_load_b128 s[0:3], s[0:1], 0x0
	v_mov_b32_e32 v4, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v13, v3, 9, v2
	v_add_nc_u32_e32 v2, v13, v0
	v_add_co_u32 v7, s4, v13, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v8, null, 0, 0, s4
	v_add_nc_u32_e32 v3, 0xfffc0000, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	v_lshlrev_b64 v[5:6], 2, v[3:4]
	v_add_nc_u32_e32 v3, 0x40000, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[9:10], 2, v[3:4]
	v_add_nc_u32_e32 v3, 0xfffffe00, v2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v5, vcc_lo, s0, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[11:12], 2, v[3:4]
	v_add_co_u32 v0, vcc_lo, s0, v9
	v_add_nc_u32_e32 v3, v13, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v10, vcc_lo
	v_add_co_u32 v9, vcc_lo, s0, v11
	v_add_co_ci_u32_e32 v10, vcc_lo, s1, v12, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_lshlrev_b64 v[11:12], 2, v[3:4]
	s_clause 0x2
	global_load_b32 v3, v[5:6], off
	global_load_b32 v13, v[0:1], off
	global_load_b32 v9, v[9:10], off
	v_add_co_u32 v0, vcc_lo, s0, v7
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v8, vcc_lo
	v_add_co_u32 v5, vcc_lo, s0, v11
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v12, vcc_lo
	s_clause 0x2
	global_load_b32 v7, v[0:1], off offset:2048
	global_load_b32 v5, v[5:6], off
	global_load_b32 v0, v[0:1], off offset:4
	s_mov_b32 s0, 0x9999999a
	s_mov_b32 s1, 0x3fe99999
	s_waitcnt vmcnt(4)
	v_add_f32_e32 v1, v3, v13
	v_mov_b32_e32 v3, v4
	s_waitcnt vmcnt(3)
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v1, v1, v9
	s_waitcnt vmcnt(2)
	v_add_f32_e32 v1, v1, v7
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v1, v1, v5
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v0, v1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f64_f32_e32 v[0:1], v0
	v_mul_f64 v[0:1], v[0:1], s[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_f64_e32 v5, v[0:1]
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	v_add_co_u32 v0, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_store_b32 v[0:1], v5, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7kernel1PfS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 13
		.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 1
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 2
		.amdhsa_next_free_vgpr 14
		.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	_Z7kernel1PfS_, .Lfunc_end0-_Z7kernel1PfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 520
; NumSgprs: 18
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 13
; 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: 1
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 2
	.text
	.protected	_Z7kernel2PfS_          ; -- Begin function _Z7kernel2PfS_
	.globl	_Z7kernel2PfS_
	.p2align	8
	.type	_Z7kernel2PfS_,@function
_Z7kernel2PfS_:                         ; @_Z7kernel2PfS_
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x1c
	v_bfe_u32 v1, v0, 10, 10
	v_and_b32_e32 v5, 0x3ff, v0
	v_bfe_u32 v0, v0, 20, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s3, s3, 0xffff
	s_and_b32 s2, s2, 0xffff
	v_mad_u64_u32 v[2:3], null, s14, s4, v[1:2]
	v_mad_u64_u32 v[3:4], null, s15, s3, v[0:1]
	v_mad_u64_u32 v[0:1], null, s13, s2, v[5:6]
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v5, -1, v2
	v_add_nc_u32_e32 v4, -1, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, -1, v0
	v_max3_u32 v4, v1, v5, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e32 0x1fe, v4
	s_cbranch_execz .LBB1_2
; %bb.1:
	v_dual_mov_b32 v3, 0 :: v_dual_lshlrev_b32 v12, 18, v3
	v_lshlrev_b32_e32 v13, 9, v2
	s_load_b128 s[0:3], s[0:1], 0x0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add3_u32 v10, v13, v0, v12
	v_add_co_u32 v6, s4, v13, v0
	v_add_co_ci_u32_e64 v7, null, 0, 0, s4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v2, 0xfffc0000, v10
	v_add_co_u32 v6, vcc_lo, v6, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v7, vcc_lo
	v_lshlrev_b64 v[4:5], 2, v[2:3]
	v_add_nc_u32_e32 v2, 0x40000, v10
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	v_lshlrev_b64 v[8:9], 2, v[2:3]
	v_add_nc_u32_e32 v2, 0xfffffe00, v10
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_u32 v8, vcc_lo, s0, v8
	v_lshlrev_b64 v[10:11], 2, v[2:3]
	v_add_co_ci_u32_e32 v9, vcc_lo, s1, v9, vcc_lo
	s_clause 0x1
	global_load_b32 v14, v[4:5], off
	global_load_b32 v15, v[8:9], off
	v_add_co_u32 v4, vcc_lo, s0, v10
	v_add_nc_u32_e32 v10, v12, v13
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v11, vcc_lo
	v_add_co_u32 v6, vcc_lo, s0, v6
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v2, v10, v1
	v_add_co_u32 v8, s4, v0, v10
	v_add_co_ci_u32_e64 v9, null, 0, 0, s4
	v_add_co_ci_u32_e32 v7, vcc_lo, s1, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_4)
	v_lshlrev_b64 v[1:2], 2, v[2:3]
	s_clause 0x1
	global_load_b32 v11, v[4:5], off
	global_load_b32 v6, v[6:7], off offset:2048
	v_lshlrev_b64 v[4:5], 2, v[8:9]
	v_add_co_u32 v1, vcc_lo, s0, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	s_clause 0x1
	global_load_b32 v1, v[1:2], off
	global_load_b32 v2, v[4:5], off offset:4
	s_mov_b32 s0, 0x9999999a
	s_mov_b32 s1, 0x3fe99999
	s_waitcnt vmcnt(4)
	v_add_f32_e32 v4, v14, v15
	s_waitcnt vmcnt(3)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v4, v4, v11
	s_waitcnt vmcnt(2)
	v_add_f32_e32 v4, v4, v6
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v1, v4, v1
	s_waitcnt vmcnt(0)
	v_add_f32_e32 v1, v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f64_f32_e32 v[1:2], v1
	v_mul_f64 v[1:2], v[1:2], s[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_f64_e32 v4, v[1:2]
	v_add_nc_u32_e32 v2, v10, v0
	v_lshlrev_b64 v[0:1], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_store_b32 v[0:1], v4, off
.LBB1_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7kernel2PfS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 13
		.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 1
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 2
		.amdhsa_next_free_vgpr 16
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z7kernel2PfS_, .Lfunc_end1-_Z7kernel2PfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 584
; NumSgprs: 18
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 16
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 13
; 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: 1
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 2
	.text
	.protected	_Z7kernel3PfS_          ; -- Begin function _Z7kernel3PfS_
	.globl	_Z7kernel3PfS_
	.p2align	8
	.type	_Z7kernel3PfS_,@function
_Z7kernel3PfS_:                         ; @_Z7kernel3PfS_
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x1c
	v_bfe_u32 v8, v0, 20, 10
	v_bfe_u32 v7, v0, 10, 10
	v_and_b32_e32 v2, 0x3ff, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b32_e32 v13, 4, v7
	v_lshlrev_b32_e32 v14, 7, v2
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_lshr_b32 s4, s2, 16
	v_mad_u64_u32 v[9:10], null, s15, s3, v[8:9]
	v_mad_u64_u32 v[10:11], null, s14, s4, v[7:8]
	s_and_b32 s2, s2, 0xffff
	s_mov_b32 s4, exec_lo
	v_mad_u64_u32 v[11:12], null, s13, s2, v[2:3]
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b32_e32 v0, 18, v9
	s_load_b128 s[0:3], s[0:1], 0x0
	v_lshlrev_b32_e32 v1, 9, v10
	v_lshlrev_b32_e32 v12, 2, v8
	v_add_nc_u32_e32 v9, -1, v9
	v_add_nc_u32_e32 v10, -1, v10
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add3_u32 v5, v11, v1, v0
	v_add_nc_u32_e32 v11, -1, v11
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_max3_u32 v9, v11, v10, v9
	v_add3_u32 v11, v14, v13, v12
	v_lshlrev_b64 v[0:1], 2, v[5:6]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v6, v[3:4], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v11, v6
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e32 0x1fe, v9
	s_cbranch_execz .LBB2_18
; %bb.1:
	s_mov_b32 s5, exec_lo
                                        ; implicit-def: $vgpr9_vgpr10
	v_cmpx_ne_u32_e32 0, v8
	s_xor_b32 s5, exec_lo, s5
; %bb.2:
	v_add_nc_u32_e32 v6, -4, v11
	s_mov_b64 s[6:7], src_shared_base
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v6
	v_cndmask_b32_e32 v9, 0, v6, vcc_lo
	v_cndmask_b32_e64 v10, 0, s7, vcc_lo
; %bb.3:                                ; %Flow112
	s_and_not1_saveexec_b32 s5, s5
; %bb.4:
	v_add_nc_u32_e32 v9, 0xfffc0000, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v10, 31, v9
	v_lshlrev_b64 v[9:10], 2, v[9:10]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v9, vcc_lo, s0, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s1, v10, vcc_lo
; %bb.5:
	s_or_b32 exec_lo, exec_lo, s5
	flat_load_b32 v10, v[9:10]
	v_cmp_gt_u32_e32 vcc_lo, 3, v8
                                        ; implicit-def: $vgpr8_vgpr9
	s_and_saveexec_b32 s5, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s5, exec_lo, s5
; %bb.6:
	v_add_nc_u32_e32 v6, 4, v11
	s_mov_b64 s[6:7], src_shared_base
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v6
	v_cndmask_b32_e32 v8, 0, v6, vcc_lo
	v_cndmask_b32_e64 v9, 0, s7, vcc_lo
; %bb.7:                                ; %Flow111
	s_and_not1_saveexec_b32 s5, s5
; %bb.8:
	v_add_nc_u32_e32 v8, 0x40000, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s0, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s1, v9, vcc_lo
; %bb.9:
	s_or_b32 exec_lo, exec_lo, s5
	flat_load_b32 v12, v[8:9]
	s_mov_b32 s5, exec_lo
                                        ; implicit-def: $vgpr8_vgpr9
	v_cmpx_ne_u32_e32 0, v7
	s_xor_b32 s5, exec_lo, s5
; %bb.10:
	v_add_nc_u32_e32 v6, -16, v11
	s_mov_b64 s[6:7], src_shared_base
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v6
	v_cndmask_b32_e32 v8, 0, v6, vcc_lo
	v_cndmask_b32_e64 v9, 0, s7, vcc_lo
; %bb.11:                               ; %Flow110
	s_and_not1_saveexec_b32 s5, s5
; %bb.12:
	v_add_nc_u32_e32 v8, 0xfffffe00, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s0, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s1, v9, vcc_lo
; %bb.13:
	s_or_b32 exec_lo, exec_lo, s5
	flat_load_b32 v9, v[8:9]
	v_cmp_gt_u32_e32 vcc_lo, 7, v7
                                        ; implicit-def: $vgpr7_vgpr8
	s_and_saveexec_b32 s5, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s5, exec_lo, s5
; %bb.14:
	v_add_nc_u32_e32 v5, 16, v11
	s_mov_b64 s[6:7], src_shared_base
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, -1, v5
	v_cndmask_b32_e32 v7, 0, v5, vcc_lo
	v_cndmask_b32_e64 v8, 0, s7, vcc_lo
                                        ; implicit-def: $vgpr5_vgpr6
; %bb.15:                               ; %Flow
	s_and_not1_saveexec_b32 s5, s5
; %bb.16:
	v_add_nc_u32_e32 v5, 0x200, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v6, 31, v5
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v7, vcc_lo, s0, v5
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v6, vcc_lo
; %bb.17:
	s_or_b32 exec_lo, exec_lo, s5
	v_add_co_u32 v13, s0, v3, -4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v6, s0, -1, v4, s0
	v_add_nc_u32_e32 v5, 0xffffff80, v11
	s_mov_b64 s[0:1], src_shared_base
	flat_load_b32 v7, v[7:8]
	v_cmp_ne_u32_e32 vcc_lo, -1, v5
	v_cndmask_b32_e32 v5, 0, v5, vcc_lo
	v_cndmask_b32_e64 v14, 0, s1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, 0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_cndmask_b32 v6, v14, v6 :: v_dual_cndmask_b32 v5, v5, v13
	v_add_co_u32 v8, vcc_lo, v3, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v4, vcc_lo
	v_cmp_lt_u32_e32 vcc_lo, 30, v2
	v_add_nc_u32_e32 v11, 0x80, v11
	flat_load_b32 v5, v[5:6]
	v_cmp_ne_u32_e64 s0, -1, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v4, 0, v11, s0
	v_cndmask_b32_e64 v11, 0, s1, s0
	s_mov_b32 s0, 0x9999999a
	s_mov_b32 s1, 0x3fe99999
	v_dual_cndmask_b32 v2, v4, v8 :: v_dual_cndmask_b32 v3, v11, v3
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	flat_load_b32 v2, v[2:3]
	s_waitcnt vmcnt(5) lgkmcnt(5)
	v_add_f32_e32 v3, 0, v10
	s_waitcnt vmcnt(4) lgkmcnt(4)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v3, v3, v12
	s_waitcnt vmcnt(3) lgkmcnt(3)
	v_add_f32_e32 v3, v3, v9
	s_waitcnt vmcnt(2) lgkmcnt(2)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f32_e32 v3, v3, v7
	s_waitcnt vmcnt(1) lgkmcnt(1)
	v_add_f32_e32 v3, v3, v5
	s_waitcnt vmcnt(0) lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v2, v3, v2
	v_cvt_f64_f32_e32 v[2:3], v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[2:3], v[2:3], s[0:1]
	v_cvt_f32_f64_e32 v2, v[2:3]
	global_store_b32 v[0:1], v2, off
.LBB2_18:                               ; %Flow113
	s_or_b32 exec_lo, exec_lo, s4
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7kernel3PfS_
		.amdhsa_group_segment_fixed_size 4096
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 13
		.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 1
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 2
		.amdhsa_next_free_vgpr 15
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end2:
	.size	_Z7kernel3PfS_, .Lfunc_end2-_Z7kernel3PfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 916
; NumSgprs: 18
; NumVgprs: 15
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4096 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 15
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 13
; 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: 1
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 2
	.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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7kernel1PfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7kernel1PfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7kernel2PfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7kernel2PfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 4096
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7kernel3PfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7kernel3PfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     15
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
