#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <unistd.h>

#define NUM_ELEMENTS 1<<20
#define BLOCK_SIZE 1024

#define CUDA_ERROR_CHECK(func) { gpuAssert((func), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true){
   if (code != cudaSuccess) {
      fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

__global__ void reduce(volatile bool *timeout, bool *executedBlocks, int *input, int *output) {

  __shared__ unsigned int block_timeout;

  /*Calculate block ID in grid */
  unsigned long long int bid = blockIdx.x + gridDim.x *
                               (blockIdx.y + gridDim.z * blockIdx.z);

  /* Copy timeout signal from host to local block variable */
  if(threadIdx.x == 0 && threadIdx.y == 0 && threadIdx.z == 0){
    block_timeout = *timeout;
  }

  /* Return if block was previously executed */
  if(executedBlocks[bid]){
    return;
  }

  /* Preventy any warps from proceeding until timeout is copied */
  __syncthreads();

  /* Return if block_timeout is true */
  if(block_timeout){
    return;
  }

  /* Mark block as executed */
  executedBlocks[bid] = true;

  extern __shared__ int sdata[];
  unsigned int tid = threadIdx.x;
  unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
  sdata[tid] = input[i];

  __syncthreads();

  for (unsigned int s = 1; s < blockDim.x; s *= 2) {
    if (tid % (2 * s) == 0) {
      sdata[tid] += sdata[tid + s];
    }

    __syncthreads();
  }

  if (tid == 0){
    output[blockIdx.x] = sdata[0];
  }
}

int main(){
  size_t elems = NUM_ELEMENTS;
  size_t grid_size = (size_t)(ceill((long double)elems/(long double)BLOCK_SIZE)); 

  size_t input_size = elems * sizeof(int);
  size_t output_size = grid_size * sizeof(int);

  int *deviceInput = NULL;
  int *deviceOutput = NULL;
  int *hostInput = NULL; 
  int *hostOutput = NULL; 

  hostInput = (int *)malloc(input_size);
  hostOutput = (int *)malloc(output_size);

  if(hostInput == NULL){
    fprintf(stderr, "Failed to allocate %zu bytes for input!\n", input_size);
    exit(EXIT_FAILURE);
  }

  if(hostOutput == NULL){
    fprintf(stderr, "Failed to allocate %zu bytes for output!\n", output_size);
    exit(EXIT_FAILURE);
  }

  CUDA_ERROR_CHECK(cudaMalloc((void **)&deviceInput, input_size));
  CUDA_ERROR_CHECK(cudaMalloc((void **)&deviceOutput, output_size));

  size_t i = 0;

  for(i = 0; i < elems; i++){
      hostInput[i] = 1;
  }

  volatile bool *timeout = NULL;
  bool complete = false;
  bool *executedBlocks = NULL;

  cudaMallocManaged((void **)&timeout, sizeof(volatile bool), cudaMemAttachGlobal);
  cudaMallocManaged((void **)&executedBlocks, grid_size * sizeof(bool), cudaMemAttachGlobal);

  memset(executedBlocks, 0, grid_size * sizeof(bool));

  *timeout = false;
  size_t interrupt_count = 0;

  CUDA_ERROR_CHECK(cudaMemcpy(deviceInput, hostInput, input_size, cudaMemcpyHostToDevice));

  while(!complete){
    reduce<<<grid_size, BLOCK_SIZE, BLOCK_SIZE*sizeof(int)>>>(timeout, executedBlocks, deviceInput, deviceOutput);
    CUDA_ERROR_CHECK(cudaPeekAtLastError());

    usleep(0.001);
    *timeout = true;
    CUDA_ERROR_CHECK(cudaDeviceSynchronize());

    /* Check if kernel is complete */
    size_t i = 0;
    for(i = 0; i < grid_size; i++){
      if(executedBlocks[i] == false){
       break;
      } 
    }
    interrupt_count++;

    if(i == grid_size){
      complete = true;
    }else{
      *timeout = false;
    }
  }
  fprintf(stdout, "Interrupt count: %zu\n", interrupt_count);

  CUDA_ERROR_CHECK(cudaMemcpy(hostOutput, deviceOutput, output_size, cudaMemcpyDeviceToHost));

  for(i = 1; i < grid_size; i++){
    hostOutput[0] += hostOutput[i];
  }

  fprintf(stdout, "Result: "); 

  if(hostOutput[0] == NUM_ELEMENTS){
    fprintf(stdout, "PASS\n");
  }else{
    fprintf(stderr, "FAIL\n");
  }

  fprintf(stdout, "Sum = %d\n", hostOutput[0]);

  free(hostInput);
  free(hostOutput);

  CUDA_ERROR_CHECK(cudaFree(deviceInput));
  CUDA_ERROR_CHECK(cudaFree(deviceOutput));
  CUDA_ERROR_CHECK(cudaFree(executedBlocks));
  CUDA_ERROR_CHECK(cudaFree((void *)timeout));

  CUDA_ERROR_CHECK(cudaDeviceReset());
  return EXIT_SUCCESS;
}

	.file	"tmpxft_002c3b15_00000000-6_reduction_interrupt.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2044:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2044:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata._Z9gpuAssert9cudaErrorPKcib.str1.1,"aMS",@progbits,1
.LC0:
	.string	"GPUassert: %s %s %d\n"
	.section	.text._Z9gpuAssert9cudaErrorPKcib,"axG",@progbits,_Z9gpuAssert9cudaErrorPKcib,comdat
	.weak	_Z9gpuAssert9cudaErrorPKcib
	.type	_Z9gpuAssert9cudaErrorPKcib, @function
_Z9gpuAssert9cudaErrorPKcib:
.LFB2040:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L8
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%ecx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movl	%edx, 12(%rsp)
	movq	%rsi, (%rsp)
	call	cudaGetErrorString@PLT
	movl	12(%rsp), %r9d
	movq	(%rsp), %r8
	leaq	.LC0(%rip), %rdx
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	testb	%bpl, %bpl
	je	.L2
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L8:
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z9gpuAssert9cudaErrorPKcib, .-_Z9gpuAssert9cudaErrorPKcib
	.text
	.globl	_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_
	.type	_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_, @function
_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6reducePVbPbPiS2_(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L12:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_, .-_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_
	.globl	_Z6reducePVbPbPiS2_
	.type	_Z6reducePVbPbPiS2_, @function
_Z6reducePVbPbPiS2_:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_
	.cfi_endproc
.LFE2067:
	.size	_Z6reducePVbPbPiS2_, .-_Z6reducePVbPbPiS2_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Failed to allocate %zu bytes for input!\n"
.LC2:
	.string	"Failed to allocate %zu bytes for output!\n"
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/maxbaird/appendix/master/a2/reduction_interrupt.cu"
.LC4:
	.string	"Interrupt count: %zu\n"
.LC5:
	.string	"Result: "
.LC6:
	.string	"PASS\n"
.LC7:
	.string	"FAIL\n"
.LC8:
	.string	"Sum = %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%edx, %edx
	movl	$4194304, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	movq	%rdx, (%rsp)
	movq	%rdx, 8(%rsp)
	call	malloc@PLT
	movl	$4096, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	$4194304, %ecx
	leaq	.LC1(%rip), %rdx
	testq	%r12, %r12
	je	.L35
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L19
	movl	$4096, %ecx
	leaq	.LC2(%rip), %rdx
.L35:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L19:
	movq	%rsp, %rdi
	movl	$4194304, %esi
	leaq	.LC3(%rip), %rbx
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$92, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	leaq	8(%rsp), %rdi
	movl	$4096, %esi
	call	cudaMalloc@PLT
	movl	$1, %ecx
	movl	$93, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	xorl	%eax, %eax
.L20:
	movl	$1, (%r12,%rax,4)
	incq	%rax
	cmpq	$1048576, %rax
	jne	.L20
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	movl	$1, %edx
	xorl	%r14d, %r14d
	movl	$1, %esi
	movq	%rax, 16(%rsp)
	movabsq	$4294968320, %r13
	movq	%rax, 24(%rsp)
	call	cudaMallocManaged@PLT
	leaq	24(%rsp), %rdi
	movl	$1, %edx
	movl	$1024, %esi
	call	cudaMallocManaged@PLT
	movq	24(%rsp), %rdi
	xorl	%eax, %eax
	movq	%r12, %rsi
	movl	$256, %ecx
	movl	$4194304, %edx
	rep stosl
	movq	16(%rsp), %rax
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movb	$0, (%rax)
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$113, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
.L26:
	xorl	%r9d, %r9d
	movl	$4096, %r8d
	movq	%r13, %rdx
	movq	%r13, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movq	%r13, 44(%rsp)
	movl	$1, 52(%rsp)
	movq	%r13, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	movq	8(%rsp), %rcx
	movq	(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	call	_Z33__device_stub__Z6reducePVbPbPiS2_PVbPbPiS2_
.L21:
	call	cudaPeekAtLastError@PLT
	movl	$1, %ecx
	movl	$117, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	xorl	%edi, %edi
	call	usleep@PLT
	movq	16(%rsp), %rax
	movb	$1, (%rax)
	call	cudaDeviceSynchronize@PLT
	movl	$121, %edx
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	24(%rsp), %rdx
	xorl	%eax, %eax
.L23:
	cmpb	$0, (%rdx,%rax)
	je	.L22
	incq	%rax
	cmpq	$1024, %rax
	jne	.L23
.L22:
	incq	%r14
	cmpq	$1024, %rax
	jne	.L24
	movq	stdout(%rip), %rdi
	movq	%r14, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	movl	$4096, %edx
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$140, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movl	$1, %eax
	jmp	.L25
.L24:
	movq	16(%rsp), %rax
	movb	$0, (%rax)
	jmp	.L26
.L25:
	movl	0(%rbp,%rax,4), %edx
	incq	%rax
	addl	%edx, 0(%rbp)
	cmpq	$1024, %rax
	jne	.L25
	movq	stdout(%rip), %rdi
	xorl	%eax, %eax
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
	call	__fprintf_chk@PLT
	cmpl	$1048576, 0(%rbp)
	jne	.L27
	movq	stdout(%rip), %rdi
	leaq	.LC6(%rip), %rdx
	movl	$2, %esi
	jmp	.L34
.L27:
	movq	stderr(%rip), %rdi
	leaq	.LC7(%rip), %rdx
	movl	$2, %esi
.L34:
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	0(%rbp), %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	stdout(%rip), %rdi
	leaq	.LC8(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$159, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$160, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$161, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	$1, %ecx
	movl	$162, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	call	cudaDeviceReset@PLT
	movl	$1, %ecx
	movl	$164, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaErrorPKcib
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2041:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z6reducePVbPbPiS2_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6reducePVbPbPiS2_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2069:
	.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
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <unistd.h>

#define NUM_ELEMENTS 1<<20
#define BLOCK_SIZE 1024

#define CUDA_ERROR_CHECK(func) { gpuAssert((func), __FILE__, __LINE__); }
inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=true){
   if (code != hipSuccess) {
      fprintf(stderr,"GPUassert: %s %s %d\n", hipGetErrorString(code), file, line);
      if (abort) exit(code);
   }
}

__global__ void reduce(volatile bool *timeout, bool *executedBlocks, int *input, int *output) {

  __shared__ unsigned int block_timeout;

  /*Calculate block ID in grid */
  unsigned long long int bid = blockIdx.x + gridDim.x *
                               (blockIdx.y + gridDim.z * blockIdx.z);

  /* Copy timeout signal from host to local block variable */
  if(threadIdx.x == 0 && threadIdx.y == 0 && threadIdx.z == 0){
    block_timeout = *timeout;
  }

  /* Return if block was previously executed */
  if(executedBlocks[bid]){
    return;
  }

  /* Preventy any warps from proceeding until timeout is copied */
  __syncthreads();

  /* Return if block_timeout is true */
  if(block_timeout){
    return;
  }

  /* Mark block as executed */
  executedBlocks[bid] = true;

  extern __shared__ int sdata[];
  unsigned int tid = threadIdx.x;
  unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
  sdata[tid] = input[i];

  __syncthreads();

  for (unsigned int s = 1; s < blockDim.x; s *= 2) {
    if (tid % (2 * s) == 0) {
      sdata[tid] += sdata[tid + s];
    }

    __syncthreads();
  }

  if (tid == 0){
    output[blockIdx.x] = sdata[0];
  }
}

int main(){
  size_t elems = NUM_ELEMENTS;
  size_t grid_size = (size_t)(ceill((long double)elems/(long double)BLOCK_SIZE)); 

  size_t input_size = elems * sizeof(int);
  size_t output_size = grid_size * sizeof(int);

  int *deviceInput = NULL;
  int *deviceOutput = NULL;
  int *hostInput = NULL; 
  int *hostOutput = NULL; 

  hostInput = (int *)malloc(input_size);
  hostOutput = (int *)malloc(output_size);

  if(hostInput == NULL){
    fprintf(stderr, "Failed to allocate %zu bytes for input!\n", input_size);
    exit(EXIT_FAILURE);
  }

  if(hostOutput == NULL){
    fprintf(stderr, "Failed to allocate %zu bytes for output!\n", output_size);
    exit(EXIT_FAILURE);
  }

  CUDA_ERROR_CHECK(hipMalloc((void **)&deviceInput, input_size));
  CUDA_ERROR_CHECK(hipMalloc((void **)&deviceOutput, output_size));

  size_t i = 0;

  for(i = 0; i < elems; i++){
      hostInput[i] = 1;
  }

  volatile bool *timeout = NULL;
  bool complete = false;
  bool *executedBlocks = NULL;

  hipMallocManaged((void **)&timeout, sizeof(volatile bool), hipMemAttachGlobal);
  hipMallocManaged((void **)&executedBlocks, grid_size * sizeof(bool), hipMemAttachGlobal);

  memset(executedBlocks, 0, grid_size * sizeof(bool));

  *timeout = false;
  size_t interrupt_count = 0;

  CUDA_ERROR_CHECK(hipMemcpy(deviceInput, hostInput, input_size, hipMemcpyHostToDevice));

  while(!complete){
    reduce<<<grid_size, BLOCK_SIZE, BLOCK_SIZE*sizeof(int)>>>(timeout, executedBlocks, deviceInput, deviceOutput);
    CUDA_ERROR_CHECK(hipPeekAtLastError());

    usleep(0.001);
    *timeout = true;
    CUDA_ERROR_CHECK(hipDeviceSynchronize());

    /* Check if kernel is complete */
    size_t i = 0;
    for(i = 0; i < grid_size; i++){
      if(executedBlocks[i] == false){
       break;
      } 
    }
    interrupt_count++;

    if(i == grid_size){
      complete = true;
    }else{
      *timeout = false;
    }
  }
  fprintf(stdout, "Interrupt count: %zu\n", interrupt_count);

  CUDA_ERROR_CHECK(hipMemcpy(hostOutput, deviceOutput, output_size, hipMemcpyDeviceToHost));

  for(i = 1; i < grid_size; i++){
    hostOutput[0] += hostOutput[i];
  }

  fprintf(stdout, "Result: "); 

  if(hostOutput[0] == NUM_ELEMENTS){
    fprintf(stdout, "PASS\n");
  }else{
    fprintf(stderr, "FAIL\n");
  }

  fprintf(stdout, "Sum = %d\n", hostOutput[0]);

  free(hostInput);
  free(hostOutput);

  CUDA_ERROR_CHECK(hipFree(deviceInput));
  CUDA_ERROR_CHECK(hipFree(deviceOutput));
  CUDA_ERROR_CHECK(hipFree(executedBlocks));
  CUDA_ERROR_CHECK(hipFree((void *)timeout));

  CUDA_ERROR_CHECK(hipDeviceReset());
  return EXIT_SUCCESS;
}

	.text
	.file	"reduction_interrupt.hip"
	.globl	_Z21__device_stub__reducePVbPbPiS2_ # -- Begin function _Z21__device_stub__reducePVbPbPiS2_
	.type	_Z21__device_stub__reducePVbPbPiS2_,@function
_Z21__device_stub__reducePVbPbPiS2_:    # @_Z21__device_stub__reducePVbPbPiS2_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z6reducePVbPbPiS2_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z21__device_stub__reducePVbPbPiS2_, .Lfunc_end0-_Z21__device_stub__reducePVbPbPiS2_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%eax, %eax
	movq	%rax, 16(%rsp)
	movq	%rax, 8(%rsp)
	movl	$4194304, %edi                  # imm = 0x400000
	callq	malloc
	movq	%rax, %rbx
	movl	$4096, %edi                     # imm = 0x1000
	callq	malloc
	testq	%rbx, %rbx
	je	.LBB1_1
# %bb.3:
	movq	%rax, %r14
	testq	%rax, %rax
	je	.LBB1_4
# %bb.5:
	leaq	16(%rsp), %rdi
	movl	$4194304, %esi                  # imm = 0x400000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_6
# %bb.8:                                # %_Z9gpuAssert10hipError_tPKcib.exit
	leaq	8(%rsp), %rdi
	movl	$4096, %esi                     # imm = 0x1000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_47
# %bb.9:                                # %_Z9gpuAssert10hipError_tPKcib.exit51.preheader
	movl	$1024, %r12d                    # imm = 0x400
	xorl	%eax, %eax
.LBB1_10:                               # %_Z9gpuAssert10hipError_tPKcib.exit51
                                        # =>This Inner Loop Header: Depth=1
	movl	$1, (%rbx,%rax,4)
	incq	%rax
	cmpq	$1048576, %rax                  # imm = 0x100000
	jne	.LBB1_10
# %bb.11:
	xorl	%eax, %eax
	movq	%rsp, %r15
	movq	%rax, (%r15)
	leaq	24(%rsp), %r13
	movq	%rax, (%r13)
	movl	$1, %esi
	movq	%r15, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movl	$1024, %esi                     # imm = 0x400
	movq	%r13, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r13), %rdi
	movl	$1024, %edx                     # imm = 0x400
	xorl	%esi, %esi
	callq	memset@PLT
	movq	(%r15), %rax
	movb	$0, (%rax)
	movq	16(%rsp), %rdi
	movl	$4194304, %edx                  # imm = 0x400000
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_48
# %bb.12:                               # %_Z9gpuAssert10hipError_tPKcib.exit53.preheader
	movabsq	$4294967296, %rax               # imm = 0x100000000
	movl	$1024, %r13d                    # imm = 0x400
	btsq	$32, %r13
	xorl	%r15d, %r15d
	addq	$1024, %rax                     # imm = 0x400
	movq	%rax, 32(%rsp)                  # 8-byte Spill
.LBB1_13:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_24 Depth 2
	movl	$4096, %r8d                     # imm = 0x1000
	movq	%r13, %rdi
	movl	$1, %esi
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.14:                               #   in Loop: Header=BB1_13 Depth=1
	movq	(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rcx
	callq	_Z21__device_stub__reducePVbPbPiS2_
.LBB1_15:                               #   in Loop: Header=BB1_13 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	jne	.LBB1_16
# %bb.17:                               # %_Z9gpuAssert10hipError_tPKcib.exit55
                                        #   in Loop: Header=BB1_13 Depth=1
	xorl	%edi, %edi
	callq	usleep
	movq	(%rsp), %rax
	movb	$1, (%rax)
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	jne	.LBB1_22
# %bb.18:                               # %_Z9gpuAssert10hipError_tPKcib.exit57.preheader
                                        #   in Loop: Header=BB1_13 Depth=1
	testq	%r12, %r12
	je	.LBB1_19
# %bb.23:                               # %.lr.ph
                                        #   in Loop: Header=BB1_13 Depth=1
	movq	24(%rsp), %rcx
	xorl	%eax, %eax
.LBB1_24:                               #   Parent Loop BB1_13 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpb	$0, (%rcx,%rax)
	je	.LBB1_20
# %bb.25:                               # %_Z9gpuAssert10hipError_tPKcib.exit57
                                        #   in Loop: Header=BB1_24 Depth=2
	incq	%rax
	cmpq	%rax, %r12
	jne	.LBB1_24
	jmp	.LBB1_26
.LBB1_19:                               #   in Loop: Header=BB1_13 Depth=1
	xorl	%eax, %eax
.LBB1_20:                               # %._crit_edge
                                        #   in Loop: Header=BB1_13 Depth=1
	incq	%r15
	cmpq	%r12, %rax
	je	.LBB1_27
# %bb.21:                               # %_Z9gpuAssert10hipError_tPKcib.exit53
                                        #   in Loop: Header=BB1_13 Depth=1
	movq	(%rsp), %rax
	movb	$0, (%rax)
	jmp	.LBB1_13
.LBB1_26:                               # %._crit_edge.thread
	incq	%r15
.LBB1_27:                               # %_Z9gpuAssert10hipError_tPKcib.exit53.thread
	movq	stdout(%rip), %rdi
	movl	$.L.str.3, %esi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	8(%rsp), %rsi
	movl	$4096, %edx                     # imm = 0x1000
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_49
# %bb.28:                               # %_Z9gpuAssert10hipError_tPKcib.exit59.preheader
	cmpl	$2, %r12d
	jb	.LBB1_32
# %bb.29:                               # %.lr.ph83
	movl	(%r14), %eax
	movl	$1, %ecx
.LBB1_30:                               # %_Z9gpuAssert10hipError_tPKcib.exit59
                                        # =>This Inner Loop Header: Depth=1
	addl	(%r14,%rcx,4), %eax
	incq	%rcx
	cmpq	%rcx, %r12
	jne	.LBB1_30
# %bb.31:                               # %_Z9gpuAssert10hipError_tPKcib.exit59._crit_edge
	movl	%eax, (%r14)
.LBB1_32:
	movq	stdout(%rip), %rcx
	movl	$.L.str.4, %edi
	movl	$8, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	cmpl	$1048576, (%r14)                # imm = 0x100000
	jne	.LBB1_34
# %bb.33:
	movq	stdout(%rip), %rcx
	movl	$.L.str.5, %edi
.LBB1_35:
	movl	$5, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stdout(%rip), %rdi
	movl	(%r14), %edx
	movl	$.L.str.7, %esi
	xorl	%eax, %eax
	callq	fprintf
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_36
# %bb.38:                               # %_Z9gpuAssert10hipError_tPKcib.exit61
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_39
# %bb.40:                               # %_Z9gpuAssert10hipError_tPKcib.exit63
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_41
# %bb.42:                               # %_Z9gpuAssert10hipError_tPKcib.exit65
	movq	(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_43
# %bb.44:                               # %_Z9gpuAssert10hipError_tPKcib.exit67
	callq	hipDeviceReset
	testl	%eax, %eax
	jne	.LBB1_45
# %bb.46:                               # %_Z9gpuAssert10hipError_tPKcib.exit69
	xorl	%eax, %eax
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_34:
	.cfi_def_cfa_offset 96
	movq	stderr(%rip), %rcx
	movl	$.L.str.6, %edi
	jmp	.LBB1_35
.LBB1_16:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$119, %r8d
	jmp	.LBB1_7
.LBB1_22:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$123, %r8d
	jmp	.LBB1_7
.LBB1_1:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$4194304, %edx                  # imm = 0x400000
	jmp	.LBB1_2
.LBB1_4:
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	movl	$4096, %edx                     # imm = 0x1000
.LBB1_2:
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB1_6:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$94, %r8d
	jmp	.LBB1_7
.LBB1_47:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$95, %r8d
	jmp	.LBB1_7
.LBB1_48:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$115, %r8d
	jmp	.LBB1_7
.LBB1_49:
	movl	%eax, %ebp
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%rbx, %rdi
	movq	%rax, %rdx
	movl	$142, %r8d
.LBB1_7:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebp, %edi
	callq	exit
.LBB1_36:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$161, %r8d
	jmp	.LBB1_37
.LBB1_39:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$162, %r8d
	jmp	.LBB1_37
.LBB1_41:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$163, %r8d
	jmp	.LBB1_37
.LBB1_43:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$164, %r8d
	jmp	.LBB1_37
.LBB1_45:
	movl	%eax, %ebx
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	movl	$.L.str.2, %ecx
	movq	%r14, %rdi
	movq	%rax, %rdx
	movl	$166, %r8d
.LBB1_37:
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6reducePVbPbPiS2_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6reducePVbPbPiS2_,@object     # @_Z6reducePVbPbPiS2_
	.section	.rodata,"a",@progbits
	.globl	_Z6reducePVbPbPiS2_
	.p2align	3, 0x0
_Z6reducePVbPbPiS2_:
	.quad	_Z21__device_stub__reducePVbPbPiS2_
	.size	_Z6reducePVbPbPiS2_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Failed to allocate %zu bytes for input!\n"
	.size	.L.str, 41

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Failed to allocate %zu bytes for output!\n"
	.size	.L.str.1, 42

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/maxbaird/appendix/master/a2/reduction_interrupt.hip"
	.size	.L.str.2, 114

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Interrupt count: %zu\n"
	.size	.L.str.3, 22

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

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"FAIL\n"
	.size	.L.str.6, 6

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Sum = %d\n"
	.size	.L.str.7, 10

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"GPUassert: %s %s %d\n"
	.size	.L.str.8, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6reducePVbPbPiS2_"
	.size	.L__unnamed_1, 20

	.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 _Z21__device_stub__reducePVbPbPiS2_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6reducePVbPbPiS2_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6reducePVbPbPiS2_     ; -- Begin function _Z6reducePVbPbPiS2_
	.globl	_Z6reducePVbPbPiS2_
	.p2align	8
	.type	_Z6reducePVbPbPiS2_,@function
_Z6reducePVbPbPiS2_:                    ; @_Z6reducePVbPbPiS2_
; %bb.0:
	s_mov_b32 s12, s13
	s_clause 0x2
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b32 s3, s[0:1], 0x20
	s_load_b32 s13, s[0:1], 0x28
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v2, v0, 20, 10
	v_bfe_u32 v0, v0, 10, 10
	s_add_u32 s0, s0, 32
	s_addc_u32 s1, s1, 0
	v_cmp_eq_u32_e64 s2, 0, v1
	s_mov_b32 s16, exec_lo
	v_or3_b32 v0, v1, v0, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v2, s4 :: v_dual_mov_b32 v3, s5
	flat_load_u8 v0, v[2:3] glc dlc
	s_waitcnt vmcnt(0)
	v_mov_b32_e32 v2, 0
	s_waitcnt lgkmcnt(0)
	ds_store_b32 v2, v0
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s16
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s4, s13, s15
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s4, s4, s14
	s_mul_i32 s3, s4, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s3, s3, s12
	v_mov_b32_e32 v0, s3
	s_add_u32 s4, s6, s3
	s_addc_u32 s5, s7, 0
	global_load_u8 v0, v0, s[6:7]
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, 0, v0
	s_cbranch_vccz .LBB0_4
.LBB0_3:
	s_endpgm
.LBB0_4:
	v_mov_b32_e32 v0, 0
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v2, v0
	s_waitcnt lgkmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 0, v2
	s_cbranch_vccnz .LBB0_3
; %bb.5:
	v_mov_b32_e32 v2, 1
	global_store_b8 v0, v2, s[4:5]
	s_load_b32 s0, s[0:1], 0xc
	s_mov_b32 s1, 1
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s0, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[2:3], null, s12, s0, v[1:2]
	v_mov_b32_e32 v3, v0
	v_lshl_add_u32 v0, v1, 2, 4
	s_cmp_lt_u32 s0, 2
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s8, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v3, vcc_lo
	global_load_b32 v2, v[2:3], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v0, v2
	s_waitcnt lgkmcnt(0)
	s_waitcnt_vscnt null, 0x0
	s_barrier
.LBB0_6:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_10
; %bb.7:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_6 Depth=1
	s_lshl_b32 s3, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s4, s3, -1
	v_and_b32_e32 v2, s4, v1
	s_mov_b32 s4, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v2
	s_cbranch_execz .LBB0_9
; %bb.8:                                ;   in Loop: Header=BB0_6 Depth=1
	v_lshl_add_u32 v2, s1, 2, v0
	ds_load_b32 v2, v2
	ds_load_b32 v3, v0
	s_waitcnt lgkmcnt(0)
	v_add_nc_u32_e32 v2, v3, v2
	ds_store_b32 v0, v2
.LBB0_9:                                ;   in Loop: Header=BB0_6 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_ge_u32 s3, s0
	s_mov_b32 s1, s3
	s_branch .LBB0_6
.LBB0_10:                               ; %._crit_edge
	s_and_saveexec_b32 s0, s2
	s_cbranch_execz .LBB0_3
; %bb.11:
	v_dual_mov_b32 v0, 4 :: v_dual_mov_b32 v1, 0
	s_mov_b32 s13, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[12:13], 2
	ds_load_b32 v0, v0
	s_add_u32 s0, s10, s0
	s_addc_u32 s1, s11, s1
	s_waitcnt lgkmcnt(0)
	global_store_b32 v1, v0, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6reducePVbPbPiS2_
		.amdhsa_group_segment_fixed_size 4
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 4
		.amdhsa_next_free_sgpr 17
		.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	_Z6reducePVbPbPiS2_, .Lfunc_end0-_Z6reducePVbPbPiS2_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 536
; NumSgprs: 19
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 4 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 4
; 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
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         152
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 4
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6reducePVbPbPiS2_
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z6reducePVbPbPiS2_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
