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

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

#define THRESHOLD (0.000001)

#define SIZE1 8192
#define SIZE2 8200
#define ITER 100

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

__global__ void kernel1(double* d_k1) {
  // TODO: Fill in
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  if(j < SIZE1 - 1){
    for(int k = 0; k < ITER; k++){
      for(int i = 1; i < SIZE1 - 1; i++){
        d_k1[i*SIZE1 + (j+1)] = d_k1[(i-1)*SIZE1 + (j+1)] + d_k1[i*SIZE1 + (j+1)] + 
          d_k1[(i+1)*SIZE1 + (j+1)];
      }
    }
  }
}

__global__ void kernel2(double* d_k2) {
  // TODO: Fill in
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  if(j < SIZE2 - 1){
    for(int k = 0; k < ITER; k++){
      for(int i = 1; i < SIZE2 - 1; i++){
        d_k2[i*SIZE2 + (j+1)] = d_k2[(i-1)*SIZE2 + (j+1)] + d_k2[i*SIZE2 + (j+1)] + 
          d_k2[(i+1)*SIZE2 + (j+1)];
      }
    }
  }
}

// 2-way unrolling
__global__ void kernel3(double* d_k3) {
  // TODO: Fill in
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  if(j < SIZE2 - 1){
    for(int k = 0; k < ITER; k++){
      for(int i = 1; i < SIZE2 - 1; i += 2){
        double w, x, y, z;
        w = d_k3[(i-1)*SIZE2 + (j+1)];
        x = d_k3[(i)*SIZE2 + (j+1)];
        y = d_k3[(i+1)*SIZE2 + (j+1)];
        z = d_k3[(i+2)*SIZE2 + (j+1)];

        x = w + x + y;
        y = x + y + z;

        d_k3[(i)*SIZE2 + (j+1)] = x;
        d_k3[(i+1)*SIZE2 + (j+1)] = y;
      }
    }
  }
}

__host__ void serial(double** h_ser) {
  for (int k = 0; k < ITER; k++) {
    for (int i = 1; i < (SIZE1 - 1); i++) {
      for (int j = 0; j < (SIZE1 - 1); j++) {
        h_ser[i][j + 1] = (h_ser[i - 1][j + 1] + h_ser[i][j + 1] + h_ser[i + 1][j + 1]);
      }
    }
  }
}

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

  for (uint64_t i = 0; i < size; i++) {
    for (uint64_t j = 0; j < size; j++) {
      this_diff = w_ref[i][j] - w_opt[i][j];
      if (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";
  }
}

__host__ 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() {
  double** h_ser = new double*[SIZE1];

  double** h_k1 = new double*[SIZE1];
  double** h_k2 = new double*[SIZE2];
  double** h_k3 = new double*[SIZE2];

  for(int i = 0; i < SIZE1; i++){
    h_ser[i] = new double[SIZE1];
  }

  h_k1[0] = new double[SIZE1 * SIZE1];
  h_k2[0] = new double[SIZE2 * SIZE2];
  h_k3[0] = new double[SIZE2 * SIZE2];
  for (int i = 1; i < SIZE1; i++) {
    h_k1[i] = h_k1[i-1] + SIZE1;
  }

  for (int i = 0; i < SIZE1; i++) {
    for (int j = 0; j < SIZE1; j++) {
      h_ser[i][j] = 1;
      h_k1[i][j] = 1;
    }
  }

  for (int i = 1; i < SIZE2; i++) {
    h_k2[i] = h_k2[i-1] + SIZE2;
    h_k3[i] = h_k3[i-1] + SIZE2;
  }

  for (int i = 0; i < SIZE2; i++) {
    for (int j = 0; j < SIZE2; j++) {
      h_k2[i][j] = 1;
      h_k3[i][j] = 1;
    }
  }

  double clkbegin = rtclock();
  serial(h_ser);
  double clkend = rtclock();
  double time = clkend - clkbegin; // seconds
  cout << "Serial code on CPU: " << ((2.0 * SIZE1 * SIZE1 * ITER) / time)
       << " GFLOPS; Time = " << time * 1000 << " msec" << endl;

  cudaError_t status;
  cudaEvent_t start, end;
  float k1_time, k2_time, k3_time; // ms

  double* d_k1;
  // TODO: Fill in
  size_t size = SIZE1 * SIZE1 * sizeof(double);
  dim3 threadsPerBlock(1024);
  dim3 numBlocks((SIZE1+threadsPerBlock.x-1)/threadsPerBlock.x);

  status = cudaMalloc(&d_k1, size);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

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

  cudaEventRecord(start, 0);

  status = cudaMemcpy(d_k1, h_k1[0], size, cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel1<<<numBlocks, threadsPerBlock>>>(d_k1);

  status = cudaMemcpy(h_k1[0], d_k1, size, cudaMemcpyDeviceToHost);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

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

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


  check_result(h_ser, h_k1, SIZE1);
  cout << "Kernel 1 on GPU: " << ((2.0 * SIZE1 * SIZE1 * ITER) / (k1_time * 1.0e-3))
       << " GFLOPS; Time = " << k1_time << " msec" << endl;

  double* d_k2;
  // TODO: Fill in
  size = SIZE2 * SIZE2 * sizeof(double);
  threadsPerBlock = dim3(32);
  numBlocks = dim3((SIZE2+threadsPerBlock.x-1)/threadsPerBlock.x);

  status = cudaMalloc(&d_k2, size);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

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

  cudaEventRecord(start, 0);

  status = cudaMemcpy(d_k2, h_k2[0], size, cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel2<<<numBlocks, threadsPerBlock>>>(d_k2);

  status = cudaMemcpy(h_k2[0], d_k2, size, cudaMemcpyDeviceToHost);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

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

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


  cout << "Kernel 2 on GPU: " << ((2.0 * SIZE2 * SIZE2 * ITER) / (k2_time * 1.0e-3))
       << " GFLOPS; Time = " << k2_time << " msec" << endl;

  // kernel 3
  double* d_k3;
  // TODO: Fill in
  size = SIZE2 * SIZE2 * sizeof(double);
  threadsPerBlock = dim3(32);
  numBlocks = dim3((SIZE2+threadsPerBlock.x-1)/threadsPerBlock.x);

  status = cudaMalloc(&d_k3, size);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

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

  cudaEventRecord(start, 0);

  status = cudaMemcpy(d_k3, h_k3[0], size, cudaMemcpyHostToDevice);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel3<<<numBlocks, threadsPerBlock>>>(d_k3);

  status = cudaMemcpy(h_k3[0], d_k3, size, cudaMemcpyDeviceToHost);
  if (status != cudaSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

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

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

  // checking whether kernel2 and kernel3 produce same result
  check_result(h_k2, h_k3, SIZE2);
  cout << "Kernel 3 on GPU: " << ((2.0 * SIZE2 * SIZE2 * ITER) / (k3_time * 1.0e-3))
       << " GFLOPS; Time = " << k3_time << " msec" << endl;

  cudaFree(d_k1);
  cudaFree(d_k2);
  cudaFree(d_k3);

  for(int i = 0; i < SIZE1; i++){
    delete[] h_ser[i];
  }

  delete[] h_k1[0];

  delete[] h_ser;
  delete[] h_k1;

  delete[] h_k2[0];
  delete[] h_k3[0];
  
  delete[] h_k2;
  delete[] h_k3;

  return EXIT_SUCCESS;
}

	.file	"tmpxft_003584a9_00000000-6_assignment5-p1.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
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4302:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4302:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z6serialPPd
	.type	_Z6serialPPd, @function
_Z6serialPPd:
.LFB3635:
	.cfi_startproc
	endbr64
	movl	$100, %ecx
.L4:
	xorl	%edx, %edx
.L8:
	movq	(%rdi,%rdx,8), %r9
	movq	8(%rdi,%rdx,8), %rsi
	movl	$8, %eax
	movq	16(%rdi,%rdx,8), %r8
.L5:
	movsd	(%r9,%rax), %xmm0
	addsd	(%rsi,%rax), %xmm0
	addsd	(%r8,%rax), %xmm0
	movsd	%xmm0, (%rsi,%rax)
	addq	$8, %rax
	cmpq	$65536, %rax
	jne	.L5
	incq	%rdx
	cmpq	$8190, %rdx
	jne	.L8
	decl	%ecx
	jne	.L4
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z6serialPPd, .-_Z6serialPPd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC3:
	.string	" Diffs found over THRESHOLD "
.LC4:
	.string	"; Max Diff = "
.LC5:
	.string	"No differences found between base and test versions\n"
	.text
	.globl	_Z12check_resultPPdS0_m
	.type	_Z12check_resultPPdS0_m, @function
_Z12check_resultPPdS0_m:
.LFB3636:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rsi, %r8
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	movq	.LC1(%rip), %xmm2
	movsd	.LC2(%rip), %xmm3
	xorps	%xmm1, %xmm1
.L12:
	cmpq	%rdx, %rcx
	je	.L16
	movq	(%rdi,%rcx,8), %r10
	movq	(%r8,%rcx,8), %r9
	xorl	%eax, %eax
.L15:
	movsd	(%r10,%rax,8), %xmm0
	subsd	(%r9,%rax,8), %xmm0
	movaps	%xmm0, %xmm4
	andps	%xmm2, %xmm4
	comisd	%xmm3, %xmm4
	jbe	.L13
	maxsd	%xmm1, %xmm0
	incl	%esi
	movaps	%xmm0, %xmm1
.L13:
	incq	%rax
	cmpq	%rax, %rdx
	jne	.L15
	incq	%rcx
	jmp	.L12
.L16:
	testl	%esi, %esi
	movsd	%xmm1, 8(%rsp)
	leaq	_ZSt4cout(%rip), %rdi
	jle	.L17
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	.LC2(%rip), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC4(%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
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	movq	%rax, %rdi
	jmp	_ZNSolsEPFRSoS_E.isra.0
.L17:
	.cfi_restore_state
	leaq	.LC5(%rip), %rsi
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	jmp	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	.cfi_endproc
.LFE3636:
	.size	_Z12check_resultPPdS0_m, .-_Z12check_resultPPdS0_m
	.section	.rodata.str1.1
.LC6:
	.string	"Error return from gettimeofday: "
.LC7:
	.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	.L23
	leaq	.LC6(%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	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L23:
	cvtsi2sdq	16(%rsp), %xmm0
	mulsd	.LC2(%rip), %xmm0
	cvtsi2sdq	8(%rsp), %xmm1
	addsd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3637:
	.size	_Z7rtclockv, .-_Z7rtclockv
	.globl	_Z26__device_stub__Z7kernel1PdPd
	.type	_Z26__device_stub__Z7kernel1PdPd, @function
_Z26__device_stub__Z7kernel1PdPd:
.LFB3663:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z7kernel1Pd(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L29:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3663:
	.size	_Z26__device_stub__Z7kernel1PdPd, .-_Z26__device_stub__Z7kernel1PdPd
	.globl	_Z7kernel1Pd
	.type	_Z7kernel1Pd, @function
_Z7kernel1Pd:
.LFB3664:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z7kernel1PdPd
	.cfi_endproc
.LFE3664:
	.size	_Z7kernel1Pd, .-_Z7kernel1Pd
	.globl	_Z26__device_stub__Z7kernel2PdPd
	.type	_Z26__device_stub__Z7kernel2PdPd, @function
_Z26__device_stub__Z7kernel2PdPd:
.LFB3665:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z7kernel2Pd(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L34:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3665:
	.size	_Z26__device_stub__Z7kernel2PdPd, .-_Z26__device_stub__Z7kernel2PdPd
	.globl	_Z7kernel2Pd
	.type	_Z7kernel2Pd, @function
_Z7kernel2Pd:
.LFB3666:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z7kernel2PdPd
	.cfi_endproc
.LFE3666:
	.size	_Z7kernel2Pd, .-_Z7kernel2Pd
	.globl	_Z26__device_stub__Z7kernel3PdPd
	.type	_Z26__device_stub__Z7kernel3PdPd, @function
_Z26__device_stub__Z7kernel3PdPd:
.LFB3667:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z7kernel3Pd(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L39:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3667:
	.size	_Z26__device_stub__Z7kernel3PdPd, .-_Z26__device_stub__Z7kernel3PdPd
	.globl	_Z7kernel3Pd
	.type	_Z7kernel3Pd, @function
_Z7kernel3Pd:
.LFB3668:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z7kernel3PdPd
	.cfi_endproc
.LFE3668:
	.size	_Z7kernel3Pd, .-_Z7kernel3Pd
	.section	.rodata.str1.1
.LC9:
	.string	"Serial code on CPU: "
.LC11:
	.string	" GFLOPS; Time = "
.LC13:
	.string	" msec"
.LC14:
	.string	"cudaMalloc() failed"
.LC15:
	.string	"cudaMemcpy() failed"
.LC16:
	.string	"Kernel 1 on GPU: "
.LC18:
	.string	"Kernel 2 on GPU: "
.LC20:
	.string	"Kernel 3 on GPU: "
	.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	$65536, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	xorl	%r14d, %r14d
	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	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	_Znam@PLT
	movl	$65536, %edi
	movq	%rax, %r13
	call	_Znam@PLT
	movl	$65600, %edi
	movq	%rax, %r12
	call	_Znam@PLT
	movl	$65600, %edi
	movq	%rax, %rbp
	call	_Znam@PLT
	movq	%rax, %rbx
.L45:
	movl	$65536, %edi
	call	_Znam@PLT
	movq	%rax, 0(%r13,%r14,8)
	incq	%r14
	cmpq	$8192, %r14
	jne	.L45
	movl	$536870912, %edi
	call	_Znam@PLT
	movl	$537920000, %edi
	movq	%rax, (%r12)
	call	_Znam@PLT
	movl	$537920000, %edi
	movq	%rax, 0(%rbp)
	call	_Znam@PLT
	movq	%rax, (%rbx)
	xorl	%eax, %eax
.L46:
	movq	(%r12,%rax), %rcx
	leaq	65536(%rcx), %rdx
	movq	%rdx, 8(%r12,%rax)
	addq	$8, %rax
	cmpq	$65528, %rax
	jne	.L46
	movsd	.LC8(%rip), %xmm0
	xorl	%edx, %edx
.L47:
	movq	0(%r13,%rdx), %rsi
	movq	(%r12,%rdx), %rcx
	xorl	%eax, %eax
.L48:
	movsd	%xmm0, (%rsi,%rax)
	movsd	%xmm0, (%rcx,%rax)
	addq	$8, %rax
	cmpq	$65536, %rax
	jne	.L48
	addq	$8, %rdx
	cmpq	$65536, %rdx
	jne	.L47
	xorl	%eax, %eax
.L49:
	movq	0(%rbp,%rax), %rcx
	leaq	65600(%rcx), %rdx
	movq	(%rbx,%rax), %rcx
	movq	%rdx, 8(%rbp,%rax)
	leaq	65600(%rcx), %rdx
	movq	%rdx, 8(%rbx,%rax)
	addq	$8, %rax
	cmpq	$65592, %rax
	jne	.L49
	xorl	%edx, %edx
.L50:
	movq	0(%rbp,%rdx), %rsi
	movq	(%rbx,%rdx), %rcx
	xorl	%eax, %eax
.L51:
	movsd	%xmm0, (%rsi,%rax)
	movsd	%xmm0, (%rcx,%rax)
	addq	$8, %rax
	cmpq	$65600, %rax
	jne	.L51
	addq	$8, %rdx
	cmpq	$65600, %rdx
	jne	.L50
	call	_Z7rtclockv
	movq	%r13, %rdi
	movsd	%xmm0, (%rsp)
	call	_Z6serialPPd
	call	_Z7rtclockv
	subsd	(%rsp), %xmm0
	leaq	.LC9(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	movsd	%xmm0, (%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	.LC10(%rip), %xmm0
	divsd	(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	(%rsp), %xmm0
	mulsd	.LC12(%rip), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	56(%rsp), %rdi
	movabsq	$4294967297, %rax
	movl	$536870912, %esi
	movq	%rax, 84(%rsp)
	addq	$7, %rax
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L96
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	(%r12), %rax
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movl	$536870912, %edx
	movq	%rax, %rsi
	movq	%rax, (%rsp)
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L55
.L94:
	leaq	.LC15(%rip), %rdx
.L93:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L44
.L55:
	movl	88(%rsp), %ecx
	movq	92(%rsp), %rdi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1024, 80(%rsp)
	movl	100(%rsp), %esi
	movq	80(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L57
	movq	56(%rsp), %rdi
	call	_Z26__device_stub__Z7kernel1PdPd
.L57:
	movq	56(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	$2, %ecx
	movl	$536870912, %edx
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L94
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	28(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	$8192, %edx
	movq	%r12, %rsi
	movq	%r13, %rdi
	call	_Z12check_resultPPdS0_m
	leaq	.LC16(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	28(%rsp), %xmm1
	mulsd	.LC17(%rip), %xmm1
	movsd	.LC10(%rip), %xmm0
	movq	%rax, %rdi
	divsd	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	28(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	64(%rsp), %rdi
	movl	$537920000, %esi
	movl	$32, 80(%rsp)
	movl	$257, 92(%rsp)
	call	cudaMalloc@PLT
	testl	%eax, %eax
	jne	.L96
	movq	%r14, %rdi
	leaq	48(%rsp), %r14
	call	cudaEventCreate@PLT
	movq	%r14, %rdi
	call	cudaEventCreate@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	0(%rbp), %r15
	movq	64(%rsp), %rdi
	movl	$1, %ecx
	movl	$537920000, %edx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L94
	movl	88(%rsp), %ecx
	movq	80(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	92(%rsp), %rdi
	movl	100(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L61
	movq	64(%rsp), %rdi
	call	_Z26__device_stub__Z7kernel2PdPd
.L61:
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movl	$537920000, %edx
	movq	%r15, %rdi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L94
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	32(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	leaq	.LC18(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	32(%rsp), %xmm0
	mulsd	.LC17(%rip), %xmm0
	movsd	.LC19(%rip), %xmm1
	movq	%rax, %rdi
	divsd	%xmm0, %xmm1
	movaps	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	32(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	72(%rsp), %rdi
	movl	$537920000, %esi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L63
.L96:
	leaq	.LC14(%rip), %rdx
	jmp	.L93
.L63:
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	%r14, %rdi
	call	cudaEventCreate@PLT
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	(%rbx), %r14
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	movl	$537920000, %edx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L94
	movl	88(%rsp), %ecx
	movq	80(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	92(%rsp), %rdi
	movl	100(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	movq	72(%rsp), %rdi
	call	_Z26__device_stub__Z7kernel3PdPd
.L65:
	movq	72(%rsp), %rsi
	movl	$2, %ecx
	movl	$537920000, %edx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	jne	.L94
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	48(%rsp), %rdx
	movq	40(%rsp), %rsi
	leaq	36(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	40(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movq	48(%rsp), %rdi
	call	cudaEventDestroy@PLT
	movl	$8200, %edx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	call	_Z12check_resultPPdS0_m
	leaq	.LC20(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	36(%rsp), %xmm1
	mulsd	.LC17(%rip), %xmm1
	movsd	.LC19(%rip), %xmm0
	movq	%rax, %rdi
	divsd	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	36(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L68:
	movq	0(%r13,%rax,8), %rdi
	testq	%rdi, %rdi
	je	.L67
	movq	%rax, 8(%rsp)
	call	_ZdaPv@PLT
	movq	8(%rsp), %rax
.L67:
	incq	%rax
	cmpq	$8192, %rax
	jne	.L68
	cmpq	$0, (%rsp)
	je	.L69
	movq	(%rsp), %rdi
	call	_ZdaPv@PLT
.L69:
	movq	%r13, %rdi
	call	_ZdaPv@PLT
	movq	%r12, %rdi
	call	_ZdaPv@PLT
	testq	%r15, %r15
	je	.L70
	movq	%r15, %rdi
	call	_ZdaPv@PLT
.L70:
	testq	%r14, %r14
	je	.L71
	movq	%r14, %rdi
	call	_ZdaPv@PLT
.L71:
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	xorl	%eax, %eax
.L44:
	movq	104(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L72
	call	__stack_chk_fail@PLT
.L72:
	addq	$120, %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
.LC21:
	.string	"_Z7kernel3Pd"
.LC22:
	.string	"_Z7kernel2Pd"
.LC23:
	.string	"_Z7kernel1Pd"
	.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	.LC21(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7kernel3Pd(%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	.LC22(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z7kernel2Pd(%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	.LC23(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z7kernel1Pd(%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.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	-1
	.long	2147483647
	.long	0
	.long	0
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC2:
	.long	-1598689907
	.long	1051772663
	.align 8
.LC8:
	.long	0
	.long	1072693248
	.align 8
.LC10:
	.long	0
	.long	1107886080
	.align 8
.LC12:
	.long	0
	.long	1083129856
	.align 8
.LC17:
	.long	-755914244
	.long	1062232653
	.align 8
.LC19:
	.long	-1879048192
	.long	1107889281
	.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-p1.cu -o assignment5-p1
// Execute: ./assignment5-p1

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

#define THRESHOLD (0.000001)

#define SIZE1 8192
#define SIZE2 8200
#define ITER 100

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

__global__ void kernel1(double* d_k1) {
  // TODO: Fill in
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  if(j < SIZE1 - 1){
    for(int k = 0; k < ITER; k++){
      for(int i = 1; i < SIZE1 - 1; i++){
        d_k1[i*SIZE1 + (j+1)] = d_k1[(i-1)*SIZE1 + (j+1)] + d_k1[i*SIZE1 + (j+1)] + 
          d_k1[(i+1)*SIZE1 + (j+1)];
      }
    }
  }
}

__global__ void kernel2(double* d_k2) {
  // TODO: Fill in
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  if(j < SIZE2 - 1){
    for(int k = 0; k < ITER; k++){
      for(int i = 1; i < SIZE2 - 1; i++){
        d_k2[i*SIZE2 + (j+1)] = d_k2[(i-1)*SIZE2 + (j+1)] + d_k2[i*SIZE2 + (j+1)] + 
          d_k2[(i+1)*SIZE2 + (j+1)];
      }
    }
  }
}

// 2-way unrolling
__global__ void kernel3(double* d_k3) {
  // TODO: Fill in
  int j = blockIdx.x * blockDim.x + threadIdx.x;
  if(j < SIZE2 - 1){
    for(int k = 0; k < ITER; k++){
      for(int i = 1; i < SIZE2 - 1; i += 2){
        double w, x, y, z;
        w = d_k3[(i-1)*SIZE2 + (j+1)];
        x = d_k3[(i)*SIZE2 + (j+1)];
        y = d_k3[(i+1)*SIZE2 + (j+1)];
        z = d_k3[(i+2)*SIZE2 + (j+1)];

        x = w + x + y;
        y = x + y + z;

        d_k3[(i)*SIZE2 + (j+1)] = x;
        d_k3[(i+1)*SIZE2 + (j+1)] = y;
      }
    }
  }
}

__host__ void serial(double** h_ser) {
  for (int k = 0; k < ITER; k++) {
    for (int i = 1; i < (SIZE1 - 1); i++) {
      for (int j = 0; j < (SIZE1 - 1); j++) {
        h_ser[i][j + 1] = (h_ser[i - 1][j + 1] + h_ser[i][j + 1] + h_ser[i + 1][j + 1]);
      }
    }
  }
}

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

  for (uint64_t i = 0; i < size; i++) {
    for (uint64_t j = 0; j < size; j++) {
      this_diff = w_ref[i][j] - w_opt[i][j];
      if (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";
  }
}

__host__ 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() {
  double** h_ser = new double*[SIZE1];

  double** h_k1 = new double*[SIZE1];
  double** h_k2 = new double*[SIZE2];
  double** h_k3 = new double*[SIZE2];

  for(int i = 0; i < SIZE1; i++){
    h_ser[i] = new double[SIZE1];
  }

  h_k1[0] = new double[SIZE1 * SIZE1];
  h_k2[0] = new double[SIZE2 * SIZE2];
  h_k3[0] = new double[SIZE2 * SIZE2];
  for (int i = 1; i < SIZE1; i++) {
    h_k1[i] = h_k1[i-1] + SIZE1;
  }

  for (int i = 0; i < SIZE1; i++) {
    for (int j = 0; j < SIZE1; j++) {
      h_ser[i][j] = 1;
      h_k1[i][j] = 1;
    }
  }

  for (int i = 1; i < SIZE2; i++) {
    h_k2[i] = h_k2[i-1] + SIZE2;
    h_k3[i] = h_k3[i-1] + SIZE2;
  }

  for (int i = 0; i < SIZE2; i++) {
    for (int j = 0; j < SIZE2; j++) {
      h_k2[i][j] = 1;
      h_k3[i][j] = 1;
    }
  }

  double clkbegin = rtclock();
  serial(h_ser);
  double clkend = rtclock();
  double time = clkend - clkbegin; // seconds
  cout << "Serial code on CPU: " << ((2.0 * SIZE1 * SIZE1 * ITER) / time)
       << " GFLOPS; Time = " << time * 1000 << " msec" << endl;

  hipError_t status;
  hipEvent_t start, end;
  float k1_time, k2_time, k3_time; // ms

  double* d_k1;
  // TODO: Fill in
  size_t size = SIZE1 * SIZE1 * sizeof(double);
  dim3 threadsPerBlock(1024);
  dim3 numBlocks((SIZE1+threadsPerBlock.x-1)/threadsPerBlock.x);

  status = hipMalloc(&d_k1, size);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

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

  hipEventRecord(start, 0);

  status = hipMemcpy(d_k1, h_k1[0], size, hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel1<<<numBlocks, threadsPerBlock>>>(d_k1);

  status = hipMemcpy(h_k1[0], d_k1, size, hipMemcpyDeviceToHost);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

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

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


  check_result(h_ser, h_k1, SIZE1);
  cout << "Kernel 1 on GPU: " << ((2.0 * SIZE1 * SIZE1 * ITER) / (k1_time * 1.0e-3))
       << " GFLOPS; Time = " << k1_time << " msec" << endl;

  double* d_k2;
  // TODO: Fill in
  size = SIZE2 * SIZE2 * sizeof(double);
  threadsPerBlock = dim3(32);
  numBlocks = dim3((SIZE2+threadsPerBlock.x-1)/threadsPerBlock.x);

  status = hipMalloc(&d_k2, size);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

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

  hipEventRecord(start, 0);

  status = hipMemcpy(d_k2, h_k2[0], size, hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel2<<<numBlocks, threadsPerBlock>>>(d_k2);

  status = hipMemcpy(h_k2[0], d_k2, size, hipMemcpyDeviceToHost);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

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

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


  cout << "Kernel 2 on GPU: " << ((2.0 * SIZE2 * SIZE2 * ITER) / (k2_time * 1.0e-3))
       << " GFLOPS; Time = " << k2_time << " msec" << endl;

  // kernel 3
  double* d_k3;
  // TODO: Fill in
  size = SIZE2 * SIZE2 * sizeof(double);
  threadsPerBlock = dim3(32);
  numBlocks = dim3((SIZE2+threadsPerBlock.x-1)/threadsPerBlock.x);

  status = hipMalloc(&d_k3, size);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMalloc() failed");
    return EXIT_FAILURE;
  }

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

  hipEventRecord(start, 0);

  status = hipMemcpy(d_k3, h_k3[0], size, hipMemcpyHostToDevice);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

  kernel3<<<numBlocks, threadsPerBlock>>>(d_k3);

  status = hipMemcpy(h_k3[0], d_k3, size, hipMemcpyDeviceToHost);
  if (status != hipSuccess) {
    fprintf(stderr, "cudaMemcpy() failed");
    return EXIT_FAILURE;
  }

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

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

  // checking whether kernel2 and kernel3 produce same result
  check_result(h_k2, h_k3, SIZE2);
  cout << "Kernel 3 on GPU: " << ((2.0 * SIZE2 * SIZE2 * ITER) / (k3_time * 1.0e-3))
       << " GFLOPS; Time = " << k3_time << " msec" << endl;

  hipFree(d_k1);
  hipFree(d_k2);
  hipFree(d_k3);

  for(int i = 0; i < SIZE1; i++){
    delete[] h_ser[i];
  }

  delete[] h_k1[0];

  delete[] h_ser;
  delete[] h_k1;

  delete[] h_k2[0];
  delete[] h_k3[0];
  
  delete[] h_k2;
  delete[] h_k3;

  return EXIT_SUCCESS;
}

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

                                        # End of file scope inline assembly
	.globl	_Z22__device_stub__kernel1Pd    # -- Begin function _Z22__device_stub__kernel1Pd
	.type	_Z22__device_stub__kernel1Pd,@function
_Z22__device_stub__kernel1Pd:           # @_Z22__device_stub__kernel1Pd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7kernel1Pd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z22__device_stub__kernel1Pd, .Lfunc_end0-_Z22__device_stub__kernel1Pd
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__kernel2Pd    # -- Begin function _Z22__device_stub__kernel2Pd
	.type	_Z22__device_stub__kernel2Pd,@function
_Z22__device_stub__kernel2Pd:           # @_Z22__device_stub__kernel2Pd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7kernel2Pd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z22__device_stub__kernel2Pd, .Lfunc_end1-_Z22__device_stub__kernel2Pd
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__kernel3Pd    # -- Begin function _Z22__device_stub__kernel3Pd
	.type	_Z22__device_stub__kernel3Pd,@function
_Z22__device_stub__kernel3Pd:           # @_Z22__device_stub__kernel3Pd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z7kernel3Pd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z22__device_stub__kernel3Pd, .Lfunc_end2-_Z22__device_stub__kernel3Pd
	.cfi_endproc
                                        # -- End function
	.globl	_Z6serialPPd                    # -- Begin function _Z6serialPPd
	.type	_Z6serialPPd,@function
_Z6serialPPd:                           # @_Z6serialPPd
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
.LBB3_1:                                # %.preheader19
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
                                        #       Child Loop BB3_3 Depth 3
	movl	$1, %ecx
.LBB3_2:                                # %.preheader
                                        #   Parent Loop BB3_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB3_3 Depth 3
	movq	-8(%rdi,%rcx,8), %rdx
	movq	(%rdi,%rcx,8), %rsi
	movq	8(%rdi,%rcx,8), %r8
	movl	$1, %r9d
.LBB3_3:                                #   Parent Loop BB3_1 Depth=1
                                        #     Parent Loop BB3_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rdx,%r9,8), %xmm0             # xmm0 = mem[0],zero
	addsd	(%rsi,%r9,8), %xmm0
	addsd	(%r8,%r9,8), %xmm0
	movsd	%xmm0, (%rsi,%r9,8)
	incq	%r9
	cmpq	$8192, %r9                      # imm = 0x2000
	jne	.LBB3_3
# %bb.4:                                #   in Loop: Header=BB3_2 Depth=2
	incq	%rcx
	cmpq	$8191, %rcx                     # imm = 0x1FFF
	jne	.LBB3_2
# %bb.5:                                #   in Loop: Header=BB3_1 Depth=1
	incl	%eax
	cmpl	$100, %eax
	jne	.LBB3_1
# %bb.6:
	retq
.Lfunc_end3:
	.size	_Z6serialPPd, .Lfunc_end3-_Z6serialPPd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z12check_resultPPdS0_m
.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_resultPPdS0_m
	.type	_Z12check_resultPPdS0_m,@function
_Z12check_resultPPdS0_m:                # @_Z12check_resultPPdS0_m
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	testq	%rdx, %rdx
	je	.LBB4_10
# %bb.1:                                # %.preheader.preheader
	xorpd	%xmm4, %xmm4
	xorl	%ecx, %ecx
	movapd	.LCPI4_0(%rip), %xmm0           # xmm0 = [NaN,NaN]
	movsd	.LCPI4_1(%rip), %xmm1           # xmm1 = mem[0],zero
	xorl	%eax, %eax
.LBB4_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_3 Depth 2
	movq	(%rdi,%rcx,8), %r8
	movq	(%rsi,%rcx,8), %r9
	xorl	%r10d, %r10d
.LBB4_3:                                #   Parent Loop BB4_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r8,%r10,8), %xmm2             # xmm2 = mem[0],zero
	subsd	(%r9,%r10,8), %xmm2
	movapd	%xmm2, %xmm3
	andpd	%xmm0, %xmm3
	ucomisd	%xmm1, %xmm3
	jbe	.LBB4_6
# %bb.4:                                #   in Loop: Header=BB4_3 Depth=2
	incl	%eax
	ucomisd	%xmm4, %xmm2
	jbe	.LBB4_6
# %bb.5:                                #   in Loop: Header=BB4_3 Depth=2
	movapd	%xmm2, %xmm4
.LBB4_6:                                #   in Loop: Header=BB4_3 Depth=2
	incq	%r10
	cmpq	%r10, %rdx
	jne	.LBB4_3
# %bb.7:                                #   in Loop: Header=BB4_2 Depth=1
	incq	%rcx
	cmpq	%rdx, %rcx
	jne	.LBB4_2
# %bb.8:                                # %._crit_edge
	testl	%eax, %eax
	jle	.LBB4_10
# %bb.9:
	movl	$_ZSt4cout, %edi
	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_10:                               # %._crit_edge.thread
	.cfi_def_cfa_offset 32
	movl	$_ZSt4cout, %edi
	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_resultPPdS0_m, .Lfunc_end4-_Z12check_resultPPdS0_m
	.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	0x4209000000000000              # double 13421772800
.LCPI6_1:
	.quad	0x408f400000000000              # double 1000
.LCPI6_2:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
.LCPI6_3:
	.quad	0x42090c8190000000              # double 1.3448E+10
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	$65536, %edi                    # imm = 0x10000
	callq	_Znam
	movq	%rax, %r15
	movl	$65536, %edi                    # imm = 0x10000
	callq	_Znam
	movq	%rax, %r12
	movl	$65600, %edi                    # imm = 0x10040
	callq	_Znam
	movq	%rax, %rbx
	movl	$65600, %edi                    # imm = 0x10040
	callq	_Znam
	movq	%rax, %r14
	xorl	%r13d, %r13d
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movl	$65536, %edi                    # imm = 0x10000
	callq	_Znam
	movq	%rax, (%r15,%r13,8)
	incq	%r13
	cmpq	$8192, %r13                     # imm = 0x2000
	jne	.LBB6_1
# %bb.2:
	movl	$536870912, %edi                # imm = 0x20000000
	callq	_Znam
	movq	%rax, %r13
	movq	%rax, (%r12)
	movl	$537920000, %edi                # imm = 0x20100200
	callq	_Znam
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	%rax, (%rbx)
	movl	$537920000, %edi                # imm = 0x20100200
	callq	_Znam
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movq	%rax, (%r14)
	addq	$65536, %r13                    # imm = 0x10000
	movl	$1, %eax
.LBB6_3:                                # =>This Inner Loop Header: Depth=1
	movq	%r13, (%r12,%rax,8)
	incq	%rax
	addq	$65536, %r13                    # imm = 0x10000
	cmpq	$8192, %rax                     # imm = 0x2000
	jne	.LBB6_3
# %bb.4:                                # %.preheader189.preheader
	xorl	%ecx, %ecx
	movabsq	$4607182418800017408, %rax      # imm = 0x3FF0000000000000
.LBB6_5:                                # %.preheader189
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_6 Depth 2
	movq	(%r15,%rcx,8), %rdx
	movq	(%r12,%rcx,8), %rsi
	xorl	%edi, %edi
.LBB6_6:                                #   Parent Loop BB6_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rax, (%rdx,%rdi,8)
	movq	%rax, (%rsi,%rdi,8)
	incq	%rdi
	cmpq	$8192, %rdi                     # imm = 0x2000
	jne	.LBB6_6
# %bb.7:                                #   in Loop: Header=BB6_5 Depth=1
	incq	%rcx
	cmpq	$8192, %rcx                     # imm = 0x2000
	jne	.LBB6_5
# %bb.8:                                # %.preheader188.preheader
	movl	$65600, %esi                    # imm = 0x10040
	movq	24(%rsp), %rcx                  # 8-byte Reload
	addq	%rsi, %rcx
	movq	32(%rsp), %rdx                  # 8-byte Reload
	addq	%rsi, %rdx
	movl	$8, %esi
	xorl	%edi, %edi
.LBB6_9:                                # %.preheader188
                                        # =>This Inner Loop Header: Depth=1
	leaq	(%rdx,%rdi), %r8
	movq	%r8, (%rbx,%rsi)
	leaq	(%rcx,%rdi), %r8
	movq	%r8, (%r14,%rsi)
	addq	$65600, %rdi                    # imm = 0x10040
	addq	$8, %rsi
	cmpq	$537854400, %rdi                # imm = 0x200F01C0
	jne	.LBB6_9
# %bb.10:                               # %.preheader.preheader
	xorl	%ecx, %ecx
.LBB6_11:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_12 Depth 2
	movq	(%rbx,%rcx,8), %rdx
	movq	(%r14,%rcx,8), %rsi
	xorl	%edi, %edi
.LBB6_12:                               #   Parent Loop BB6_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rax, (%rdx,%rdi,8)
	movq	%rax, (%rsi,%rdi,8)
	incq	%rdi
	cmpq	$8200, %rdi                     # imm = 0x2008
	jne	.LBB6_12
# %bb.13:                               #   in Loop: Header=BB6_11 Depth=1
	incq	%rcx
	cmpq	$8200, %rcx                     # imm = 0x2008
	jne	.LBB6_11
# %bb.14:
	callq	_Z7rtclockv
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movq	%r15, %rdi
	callq	_Z6serialPPd
	callq	_Z7rtclockv
	subsd	16(%rsp), %xmm0                 # 8-byte Folded Reload
	movsd	%xmm0, 16(%rsp)                 # 8-byte Spill
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	.LCPI6_0(%rip), %xmm0           # xmm0 = mem[0],zero
	divsd	16(%rsp), %xmm0                 # 8-byte Folded Reload
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.6, %esi
	movl	$16, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	mulsd	.LCPI6_1(%rip), %xmm0
	movq	%r13, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.7, %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	56(%rsp), %rdi
	movl	$536870912, %esi                # imm = 0x20000000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_15
# %bb.17:
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	56(%rsp), %rdi
	movq	(%r12), %r13
	movl	$1, %ebp
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_18
# %bb.19:
	movabsq	$4294967328, %rax               # imm = 0x100000020
	leaq	-24(%rax), %rdi
	leaq	992(%rax), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_21
# %bb.20:
	movq	56(%rsp), %rdi
	callq	_Z22__device_stub__kernel1Pd
.LBB6_21:
	movq	56(%rsp), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movq	%r13, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_22
# %bb.23:
	movq	%r13, 16(%rsp)                  # 8-byte Spill
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	84(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventElapsedTime
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movl	$8192, %edx                     # imm = 0x2000
	movq	%r15, %rdi
	movq	%r12, %rsi
	callq	_Z12check_resultPPdS0_m
	movl	$_ZSt4cout, %edi
	movl	$.L.str.10, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%r13), %xmm1
	mulsd	.LCPI6_2(%rip), %xmm1
	movsd	.LCPI6_0(%rip), %xmm0           # xmm0 = mem[0],zero
	divsd	%xmm1, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbp
	movl	$.L.str.6, %esi
	movl	$16, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r13), %xmm0
	movq	%rbp, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.7, %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	48(%rsp), %rdi
	movl	$537920000, %esi                # imm = 0x20100200
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_15
# %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	48(%rsp), %rdi
	movl	$1, %ebp
	movl	$537920000, %edx                # imm = 0x20100200
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_18
# %bb.25:
	movabsq	$4294967328, %rdx               # imm = 0x100000020
	leaq	225(%rdx), %r13
	movq	%r13, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_27
# %bb.26:
	movq	48(%rsp), %rdi
	callq	_Z22__device_stub__kernel2Pd
.LBB6_27:
	movq	48(%rsp), %rsi
	movl	$537920000, %edx                # imm = 0x20100200
	movq	32(%rsp), %rdi                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_22
# %bb.28:
	movq	%r13, 72(%rsp)                  # 8-byte Spill
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	80(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipEventElapsedTime
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movl	$_ZSt4cout, %edi
	movl	$.L.str.11, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%rbp), %xmm1
	mulsd	.LCPI6_2(%rip), %xmm1
	movsd	.LCPI6_3(%rip), %xmm0           # xmm0 = mem[0],zero
	divsd	%xmm1, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.6, %esi
	movl	$16, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbp), %xmm0
	movq	%r13, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.7, %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	40(%rsp), %rdi
	movl	$537920000, %esi                # imm = 0x20100200
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_15
# %bb.29:
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipEventCreate
	movq	%rsp, %rdi
	callq	hipEventCreate
	movq	(%r13), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	40(%rsp), %rdi
	movl	$1, %ebp
	movl	$537920000, %edx                # imm = 0x20100200
	movq	24(%rsp), %rsi                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_18
# %bb.30:
	movq	72(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movabsq	$4294967328, %rdx               # imm = 0x100000020
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_32
# %bb.31:
	movq	40(%rsp), %rdi
	callq	_Z22__device_stub__kernel3Pd
.LBB6_32:
	movq	40(%rsp), %rsi
	movl	$537920000, %edx                # imm = 0x20100200
	movq	24(%rsp), %rdi                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_22
# %bb.33:
	movq	(%rsp), %rdi
	xorl	%ebp, %ebp
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	callq	hipEventSynchronize
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdx
	leaq	68(%rsp), %rdi
	movq	%rdi, %r13
	callq	hipEventElapsedTime
	movq	8(%rsp), %rdi
	callq	hipEventDestroy
	movq	(%rsp), %rdi
	callq	hipEventDestroy
	movl	$8200, %edx                     # imm = 0x2008
	movq	%rbx, %rdi
	movq	%r14, %rsi
	callq	_Z12check_resultPPdS0_m
	movl	$_ZSt4cout, %edi
	movl	$.L.str.12, %esi
	movl	$17, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	cvtss2sd	(%r13), %xmm1
	mulsd	.LCPI6_2(%rip), %xmm1
	movsd	.LCPI6_3(%rip), %xmm0           # xmm0 = mem[0],zero
	divsd	%xmm1, %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.6, %esi
	movl	$16, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leaq	68(%rsp), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax), %xmm0
	movq	%r13, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r13
	movl	$.L.str.7, %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
	movq	56(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %r13                  # 8-byte Reload
.LBB6_34:                               # =>This Inner Loop Header: Depth=1
	movq	(%r15,%rbp,8), %rdi
	testq	%rdi, %rdi
	je	.LBB6_36
# %bb.35:                               #   in Loop: Header=BB6_34 Depth=1
	callq	_ZdaPv
.LBB6_36:                               #   in Loop: Header=BB6_34 Depth=1
	incq	%rbp
	cmpq	$8192, %rbp                     # imm = 0x2000
	jne	.LBB6_34
# %bb.37:
	testq	%r13, %r13
	je	.LBB6_39
# %bb.38:
	movq	%r13, %rdi
	callq	_ZdaPv
.LBB6_39:
	movq	%r15, %rdi
	callq	_ZdaPv
	movq	%r12, %rdi
	callq	_ZdaPv
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	_ZdaPv
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	_ZdaPv
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r14, %rdi
	callq	_ZdaPv
	xorl	%ebp, %ebp
	jmp	.LBB6_40
.LBB6_15:
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
	jmp	.LBB6_16
.LBB6_18:
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
	movl	$19, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB6_40
.LBB6_22:
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
.LBB6_16:
	movl	$19, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %ebp
.LBB6_40:
	movl	%ebp, %eax
	addq	$88, %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	$_Z7kernel1Pd, %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	$_Z7kernel2Pd, %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	$_Z7kernel3Pd, %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	_Z7kernel1Pd,@object            # @_Z7kernel1Pd
	.section	.rodata,"a",@progbits
	.globl	_Z7kernel1Pd
	.p2align	3, 0x0
_Z7kernel1Pd:
	.quad	_Z22__device_stub__kernel1Pd
	.size	_Z7kernel1Pd, 8

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

	.type	_Z7kernel3Pd,@object            # @_Z7kernel3Pd
	.globl	_Z7kernel3Pd
	.p2align	3, 0x0
_Z7kernel3Pd:
	.quad	_Z22__device_stub__kernel3Pd
	.size	_Z7kernel3Pd, 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	"Serial code on CPU: "
	.size	.L.str.5, 21

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	" GFLOPS; Time = "
	.size	.L.str.6, 17

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

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

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Kernel 1 on GPU: "
	.size	.L.str.10, 18

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Kernel 2 on GPU: "
	.size	.L.str.11, 18

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Kernel 3 on GPU: "
	.size	.L.str.12, 18

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7kernel1Pd"
	.size	.L__unnamed_1, 13

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z7kernel2Pd"
	.size	.L__unnamed_2, 13

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z7kernel3Pd"
	.size	.L__unnamed_3, 13

	.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__kernel1Pd
	.addrsig_sym _Z22__device_stub__kernel2Pd
	.addrsig_sym _Z22__device_stub__kernel3Pd
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7kernel1Pd
	.addrsig_sym _Z7kernel2Pd
	.addrsig_sym _Z7kernel3Pd
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7kernel1Pd            ; -- Begin function _Z7kernel1Pd
	.globl	_Z7kernel1Pd
	.p2align	8
	.type	_Z7kernel1Pd,@function
_Z7kernel1Pd:                           ; @_Z7kernel1Pd
; %bb.0:
	s_load_b32 s2, s[0:1], 0x14
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e32 0x1fff, v1
	s_cbranch_execz .LBB0_5
; %bb.1:                                ; %.preheader19
	s_load_b64 s[0:1], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	v_add_nc_u32_e32 v4, 0x2001, v1
	s_mov_b32 s4, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, v2, s0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	v_add_co_u32 v2, vcc_lo, 0x20008, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
.LBB0_2:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	v_mov_b32_e32 v0, v4
	s_mov_b64 s[2:3], 0
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, 0xffffe000, v0
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[7:8], 3, v[0:1]
	v_add_nc_u32_e32 v0, 0x2000, v0
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, s0, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v5, vcc_lo, s0, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	v_add_co_u32 v11, vcc_lo, v2, s2
	v_add_co_ci_u32_e32 v12, vcc_lo, s3, v3, vcc_lo
	s_clause 0x1
	global_load_b64 v[5:6], v[5:6], off
	global_load_b64 v[9:10], v[7:8], off
	s_add_u32 s2, s2, 0x10000
	s_addc_u32 s3, s3, 0
	global_load_b64 v[11:12], v[11:12], off
	s_cmp_eq_u32 s2, 0x1ffe0000
	s_waitcnt vmcnt(1)
	v_add_f64 v[5:6], v[5:6], v[9:10]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[5:6], v[5:6], v[11:12]
	global_store_b64 v[7:8], v[5:6], off
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s4, s4, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_eq_i32 s4, 0x64
	s_cbranch_scc0 .LBB0_2
.LBB0_5:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7kernel1Pd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 13
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z7kernel1Pd, .Lfunc_end0-_Z7kernel1Pd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 340
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z7kernel2Pd            ; -- Begin function _Z7kernel2Pd
	.globl	_Z7kernel2Pd
	.p2align	8
	.type	_Z7kernel2Pd,@function
_Z7kernel2Pd:                           ; @_Z7kernel2Pd
; %bb.0:
	s_load_b32 s2, s[0:1], 0x14
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e32 0x2007, v1
	s_cbranch_execz .LBB1_5
; %bb.1:                                ; %.preheader19
	s_load_b64 s[0:1], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	v_add_nc_u32_e32 v4, 0x2009, v1
	s_mov_b32 s4, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
.LBB1_2:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_3 Depth 2
	v_mov_b32_e32 v0, v4
	s_mov_b64 s[2:3], 0x20088
.LBB1_3:                                ;   Parent Loop BB1_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, 0xffffdff8, v0
	v_ashrrev_i32_e32 v1, 31, v0
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[7:8], 3, v[0:1]
	v_add_nc_u32_e32 v0, 0x2008, v0
	v_lshlrev_b64 v[5:6], 3, v[5:6]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, s0, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v5, vcc_lo, s0, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s1, v6, vcc_lo
	v_add_co_u32 v11, vcc_lo, v2, s2
	v_add_co_ci_u32_e32 v12, vcc_lo, s3, v3, vcc_lo
	s_clause 0x1
	global_load_b64 v[5:6], v[5:6], off
	global_load_b64 v[9:10], v[7:8], off
	s_add_u32 s2, s2, 0x10040
	s_addc_u32 s3, s3, 0
	global_load_b64 v[11:12], v[11:12], off
	s_cmp_eq_u32 s2, 0x20100208
	s_waitcnt vmcnt(1)
	v_add_f64 v[5:6], v[5:6], v[9:10]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[5:6], v[5:6], v[11:12]
	global_store_b64 v[7:8], v[5:6], off
	s_cbranch_scc0 .LBB1_3
; %bb.4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_add_i32 s4, s4, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_eq_i32 s4, 0x64
	s_cbranch_scc0 .LBB1_2
.LBB1_5:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7kernel2Pd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 13
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z7kernel2Pd, .Lfunc_end1-_Z7kernel2Pd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 324
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z7kernel3Pd            ; -- Begin function _Z7kernel3Pd
	.globl	_Z7kernel3Pd
	.p2align	8
	.type	_Z7kernel3Pd,@function
_Z7kernel3Pd:                           ; @_Z7kernel3Pd
; %bb.0:
	s_load_b32 s2, s[0:1], 0x14
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e32 0x2007, v2
	s_cbranch_execz .LBB2_5
; %bb.1:                                ; %.preheader33
	s_load_b64 s[0:1], s[0:1], 0x0
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_nc_u32_e32 v6, 0x4011, v2
	s_mov_b32 s2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, v0, s0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, 0x300c8, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
.LBB2_2:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB2_3 Depth 2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_dual_mov_b32 v2, v6 :: v_dual_mov_b32 v5, v1
	v_mov_b32_e32 v4, v0
	s_mov_b32 s3, -1
.LBB2_3:                                ;   Parent Loop BB2_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v7, 0xffffbff0, v2
	v_add_nc_u32_e32 v9, 0xffffdff8, v2
	v_ashrrev_i32_e32 v3, 31, v2
	s_add_i32 s3, s3, 2
	s_cmpk_gt_u32 s3, 0x2004
	v_ashrrev_i32_e32 v8, 31, v7
	v_ashrrev_i32_e32 v10, 31, v9
	v_lshlrev_b64 v[13:14], 3, v[2:3]
	v_add_nc_u32_e32 v2, 0x4010, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[7:8], 3, v[7:8]
	v_lshlrev_b64 v[9:10], 3, v[9:10]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v7, vcc_lo, s0, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s1, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v9, vcc_lo, s0, v9
	v_add_co_ci_u32_e32 v10, vcc_lo, s1, v10, vcc_lo
	s_clause 0x1
	global_load_b64 v[7:8], v[7:8], off
	global_load_b64 v[11:12], v[9:10], off
	v_add_co_u32 v13, vcc_lo, s0, v13
	v_add_co_ci_u32_e32 v14, vcc_lo, s1, v14, vcc_lo
	global_load_b64 v[15:16], v[13:14], off
	global_load_b64 v[17:18], v[4:5], off
	v_add_co_u32 v4, vcc_lo, 0x20080, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	s_waitcnt vmcnt(2)
	v_add_f64 v[7:8], v[7:8], v[11:12]
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[7:8], v[7:8], v[15:16]
	v_add_f64 v[11:12], v[15:16], v[7:8]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[11:12], v[17:18], v[11:12]
	s_clause 0x1
	global_store_b64 v[9:10], v[7:8], off
	global_store_b64 v[13:14], v[11:12], off
	s_cbranch_scc0 .LBB2_3
; %bb.4:                                ;   in Loop: Header=BB2_2 Depth=1
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_eq_i32 s2, 0x64
	s_cbranch_scc0 .LBB2_2
.LBB2_5:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7kernel3Pd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 19
		.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	_Z7kernel3Pd, .Lfunc_end2-_Z7kernel3Pd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 420
; NumSgprs: 18
; NumVgprs: 19
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 19
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
