#include <stdio.h>
#include <iostream>
#include <iostream>
#include <fstream>
#include <random>


#define WIDTH 8192
#define LENGHT 8192
#define N_PARTICLES 5000
#define INF 999999.999
#define RADIO 100
#define CELLS_FOR_THREAD 8

using namespace std;

// __constant__ float x_part_dev[N_PARTICLES];
// __constant__ float y_part_dev[N_PARTICLES];

#define CUDA_CHECK(condition) \
  /* Code block avoids redefinition of cudaError_t error */ \
  do { \
    cudaError_t error = condition; \
    if (error != cudaSuccess) { \
      cout << cudaGetErrorString(error) << endl; \
    } \
  } while (0)

__global__
void minReduction(float *in, float *out)
{
  __shared__ float sharedData[256];

  unsigned int tid = threadIdx.x;
  unsigned int i = blockIdx.x*(blockDim.x*2) + tid; // blockSize = 256
  sharedData[tid] = in[i] + in[i+blockDim.x];
  __syncthreads();

  for (unsigned int  s = blockDim.x/2; s>32; s>>=1) {
    if(tid<s)
    {
      sharedData[tid] = (sharedData[tid]<sharedData[tid+s])?sharedData[tid]:sharedData[tid+s];
    }
    __syncthreads();
  }

  if (tid < 32)
  {
    sharedData[tid] = (sharedData[tid]<sharedData[tid+32])?sharedData[tid]:sharedData[tid+32];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+16])?sharedData[tid]:sharedData[tid+16];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+8])?sharedData[tid]:sharedData[tid+8];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+4])?sharedData[tid]:sharedData[tid+4];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+2])?sharedData[tid]:sharedData[tid+2];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+1])?sharedData[tid]:sharedData[tid+1];
  }

  if(tid==0)
  {
    out[blockIdx.x] = sharedData[0];
  }
}

float random_float(float min, float max) {

	return ((float)rand() / RAND_MAX) * (max - min) + min;

}


int main(int argc, char *argv[]){
  // Load data
  string input_file_name;

  /*
  if (argc > 1) {
		input_file_name = argv[1];
	} else {
		cout << "faltó un argumento" << endl;
		exit(0);
	}

	ifstream infile;
	cout << input_file_name.c_str() << endl;
    infile.open(input_file_name.c_str());
    */
  int nP = WIDTH*LENGHT;

  float *cells;

  // infile >> nP;
  // cout << "nP: "<<nP << endl;

  cells = (float *)malloc(WIDTH*LENGHT * sizeof(float));
  //cells = (float*)malloc(nP*sizeof(float));


  int target_min_pos = 1000000; 
  for (int i = 0; i<nP; i++){
    if (i != target_min_pos){
    cells[i] = 1.0f;
    } else {
    cells[i] = random_float(2.0f, 19.99f);
    }
  }

  // Get memory for structures
  float *chunk,*outData,*out2,y[128];

  // Define sizes of GPU
  int blockSize = 256; // # threads
  int gridSize = ((WIDTH*LENGHT)/256)/CELLS_FOR_THREAD; // # blocks

  cout << "gridSize: " << gridSize << endl;
  // Get memory in GPU for structures

  // data for charge function
  CUDA_CHECK(cudaMalloc(&chunk, gridSize*sizeof(float))); // 1D array representation for grid 2D

  // data for reduction function
  CUDA_CHECK(cudaMalloc(&outData, gridSize*sizeof(float)));
  CUDA_CHECK(cudaMalloc(&out2, (gridSize/blockSize)*sizeof(float)));

  float min = INF;
  float *aux;
  aux = (float*)malloc(gridSize*sizeof(float));

  // Search min load
  for (size_t i = 0; i < CELLS_FOR_THREAD; i++) {
    memcpy(aux, cells + i*gridSize, gridSize * sizeof(float));

    // Copy data from CPU to GPU
    CUDA_CHECK(cudaMemcpy(chunk, aux, gridSize*sizeof(float), cudaMemcpyHostToDevice));
    minReduction<<<gridSize,blockSize>>>(chunk,outData); // outData lenght 32.768
    cudaDeviceSynchronize();
    // check for errors
    cudaError_t error = cudaGetLastError();
    if (error != cudaSuccess) {
      fprintf(stderr, "ERROR: %s \n", cudaGetErrorString(error));
    }

    minReduction<<<gridSize/blockSize,blockSize>>>(outData,out2); // out2 lenght 128
    cudaDeviceSynchronize();
    cudaMemcpy(y, out2, 128*sizeof(float), cudaMemcpyDeviceToHost); 
    // check for errors
    error = cudaGetLastError();
    if (error != cudaSuccess) {
      fprintf(stderr, "ERROR: %s \n", cudaGetErrorString(error));
    }

    // min load
    for (size_t i = 0; i < 128; i++) {
      min = (y[i]<min)?y[i]:min;
    }
    cout << min << endl;
  }

  cudaFree(chunk);
  cudaFree(outData);
  cudaFree(out2);
  free(cells);
  free(aux);

  return 0;
}

	.file	"tmpxft_00375919_00000000-6_test.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4855:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4855:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB5569:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE5569:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.globl	_Z12random_floatff
	.type	_Z12random_floatff, @function
_Z12random_floatff:
.LFB4850:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movss	%xmm0, 12(%rsp)
	movss	%xmm1, 8(%rsp)
	call	rand@PLT
	movss	12(%rsp), %xmm2
	movss	8(%rsp), %xmm1
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC0(%rip), %xmm0
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	subss	%xmm2, %xmm1
	mulss	%xmm0, %xmm1
	movaps	%xmm1, %xmm0
	addss	%xmm2, %xmm0
	ret
	.cfi_endproc
.LFE4850:
	.size	_Z12random_floatff, .-_Z12random_floatff
	.globl	_Z34__device_stub__Z12minReductionPfS_PfS_
	.type	_Z34__device_stub__Z12minReductionPfS_PfS_, @function
_Z34__device_stub__Z12minReductionPfS_PfS_:
.LFB4877:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L5
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z12minReductionPfS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L5:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4877:
	.size	_Z34__device_stub__Z12minReductionPfS_PfS_, .-_Z34__device_stub__Z12minReductionPfS_PfS_
	.globl	_Z12minReductionPfS_
	.type	_Z12minReductionPfS_, @function
_Z12minReductionPfS_:
.LFB4878:
	.cfi_startproc
	endbr64
	jmp	_Z34__device_stub__Z12minReductionPfS_PfS_
	.cfi_endproc
.LFE4878:
	.size	_Z12minReductionPfS_, .-_Z12minReductionPfS_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"gridSize: "
.LC6:
	.string	"ERROR: %s \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4851:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4851
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$268435456, %edi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$632, %rsp
	.cfi_def_cfa_offset 688
	movq	%fs:40, %rax
	movq	%rax, 616(%rsp)
	xorl	%eax, %eax
	leaq	88(%rsp), %rax
	movb	$0, 88(%rsp)
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	movq	%rax, 80(%rsp)
	call	malloc@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
.L15:
	cmpq	$1000000, %rax
	je	.L12
.L49:
	movl	$0x3f800000, (%rbx,%rax,4)
	incq	%rax
	cmpq	$67108864, %rax
	jne	.L15
	jmp	.L54
.L12:
	movss	.LC3(%rip), %xmm1
	movss	.LC4(%rip), %xmm0
	call	_Z12random_floatff
	movl	$1000001, %eax
	movss	%xmm0, 4000000(%rbx)
	jmp	.L49
.L54:
	leaq	_ZSt4cout(%rip), %rbp
	leaq	.LC5(%rip), %rsi
	movq	%rbp, %rdi
.LEHB0:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	movl	$32768, %esi
	call	_ZNSolsEi@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	leaq	24(%rsp), %rdi
	movl	$131072, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L16
.L18:
	leaq	32(%rsp), %rdi
	movl	$131072, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L19
	jmp	.L21
.L16:
	call	cudaGetErrorString@PLT
	movq	%rax, %rsi
	movq	%rbp, %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
	jmp	.L18
.L19:
	call	cudaGetErrorString@PLT
	movq	%rax, %rsi
	movq	%rbp, %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
.L21:
	leaq	40(%rsp), %rdi
	movl	$512, %esi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	movq	%rax, %rsi
	movq	%rbp, %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
.L24:
	movl	$131072, %edi
	movq	%rbx, %r12
	leaq	1048576(%rbx), %r15
	movabsq	$4294967552, %r13
	call	malloc@PLT
	movss	.LC1(%rip), %xmm2
	movq	%rax, 8(%rsp)
	movss	%xmm2, 4(%rsp)
	jmp	.L23
.L56:
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L25
.L27:
	movl	$131073, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r13, %rdx
	salq	$15, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movq	%r13, 60(%rsp)
	movl	$1, 68(%rsp)
	movq	%rdi, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L28
.L30:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L31
.L33:
	movl	$33554433, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r13, %rdx
	salq	$7, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movq	%r13, 60(%rsp)
	movl	$1, 68(%rsp)
	movq	%rdi, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L34
.L36:
	call	cudaDeviceSynchronize@PLT
	leaq	104(%rsp), %r14
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movl	$512, %edx
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L37
.L39:
	xorl	%eax, %eax
.L38:
	movss	(%r14,%rax,4), %xmm0
	minss	4(%rsp), %xmm0
	incq	%rax
	movss	%xmm0, 4(%rsp)
	cmpq	$128, %rax
	jne	.L38
	movq	%rbp, %rdi
	cvtss2sd	%xmm0, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	addq	$131072, %r12
	cmpq	%r15, %r12
	je	.L55
.L23:
	movq	8(%rsp), %rdi
	movl	$32768, %ecx
	movq	%r12, %rsi
	movl	$131072, %edx
	rep movsl
	movq	8(%rsp), %rsi
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	jmp	.L56
.L25:
	call	cudaGetErrorString@PLT
	movq	%rax, %rsi
	movq	%rbp, %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
	jmp	.L27
.L28:
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z34__device_stub__Z12minReductionPfS_PfS_
	jmp	.L30
.L31:
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L33
.L34:
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z34__device_stub__Z12minReductionPfS_PfS_
	jmp	.L36
.L37:
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rax, %rcx
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L39
.L55:
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
.LEHE0:
	movq	%rbx, %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	leaq	72(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	616(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	jmp	.L52
.L45:
	endbr64
	movq	%rax, %rbx
.L41:
	leaq	72(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	616(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L52
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L52:
	call	__stack_chk_fail@PLT
.L43:
	addq	$632, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4851:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4851:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4851-.LLSDACSB4851
.LLSDACSB4851:
	.uleb128 .LEHB0-.LFB4851
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L45-.LFB4851
	.uleb128 0
	.uleb128 .LEHB1-.LFB4851
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE4851:
	.section	.text.startup
	.size	main, .-main
	.section	.rodata.str1.1
.LC7:
	.string	"_Z12minReductionPfS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4880:
	.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	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12minReductionPfS_(%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
.LFE4880:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	805306368
	.align 4
.LC1:
	.long	1232348160
	.align 4
.LC3:
	.long	1100999557
	.align 4
.LC4:
	.long	1073741824
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <iostream>
#include <iostream>
#include <fstream>
#include <random>


#define WIDTH 8192
#define LENGHT 8192
#define N_PARTICLES 5000
#define INF 999999.999
#define RADIO 100
#define CELLS_FOR_THREAD 8

using namespace std;

// __constant__ float x_part_dev[N_PARTICLES];
// __constant__ float y_part_dev[N_PARTICLES];

#define CUDA_CHECK(condition) \
  /* Code block avoids redefinition of cudaError_t error */ \
  do { \
    hipError_t error = condition; \
    if (error != hipSuccess) { \
      cout << hipGetErrorString(error) << endl; \
    } \
  } while (0)

__global__
void minReduction(float *in, float *out)
{
  __shared__ float sharedData[256];

  unsigned int tid = threadIdx.x;
  unsigned int i = blockIdx.x*(blockDim.x*2) + tid; // blockSize = 256
  sharedData[tid] = in[i] + in[i+blockDim.x];
  __syncthreads();

  for (unsigned int  s = blockDim.x/2; s>32; s>>=1) {
    if(tid<s)
    {
      sharedData[tid] = (sharedData[tid]<sharedData[tid+s])?sharedData[tid]:sharedData[tid+s];
    }
    __syncthreads();
  }

  if (tid < 32)
  {
    sharedData[tid] = (sharedData[tid]<sharedData[tid+32])?sharedData[tid]:sharedData[tid+32];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+16])?sharedData[tid]:sharedData[tid+16];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+8])?sharedData[tid]:sharedData[tid+8];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+4])?sharedData[tid]:sharedData[tid+4];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+2])?sharedData[tid]:sharedData[tid+2];
    sharedData[tid] = (sharedData[tid]<sharedData[tid+1])?sharedData[tid]:sharedData[tid+1];
  }

  if(tid==0)
  {
    out[blockIdx.x] = sharedData[0];
  }
}

float random_float(float min, float max) {

	return ((float)rand() / RAND_MAX) * (max - min) + min;

}


int main(int argc, char *argv[]){
  // Load data
  string input_file_name;

  /*
  if (argc > 1) {
		input_file_name = argv[1];
	} else {
		cout << "faltó un argumento" << endl;
		exit(0);
	}

	ifstream infile;
	cout << input_file_name.c_str() << endl;
    infile.open(input_file_name.c_str());
    */
  int nP = WIDTH*LENGHT;

  float *cells;

  // infile >> nP;
  // cout << "nP: "<<nP << endl;

  cells = (float *)malloc(WIDTH*LENGHT * sizeof(float));
  //cells = (float*)malloc(nP*sizeof(float));


  int target_min_pos = 1000000; 
  for (int i = 0; i<nP; i++){
    if (i != target_min_pos){
    cells[i] = 1.0f;
    } else {
    cells[i] = random_float(2.0f, 19.99f);
    }
  }

  // Get memory for structures
  float *chunk,*outData,*out2,y[128];

  // Define sizes of GPU
  int blockSize = 256; // # threads
  int gridSize = ((WIDTH*LENGHT)/256)/CELLS_FOR_THREAD; // # blocks

  cout << "gridSize: " << gridSize << endl;
  // Get memory in GPU for structures

  // data for charge function
  CUDA_CHECK(hipMalloc(&chunk, gridSize*sizeof(float))); // 1D array representation for grid 2D

  // data for reduction function
  CUDA_CHECK(hipMalloc(&outData, gridSize*sizeof(float)));
  CUDA_CHECK(hipMalloc(&out2, (gridSize/blockSize)*sizeof(float)));

  float min = INF;
  float *aux;
  aux = (float*)malloc(gridSize*sizeof(float));

  // Search min load
  for (size_t i = 0; i < CELLS_FOR_THREAD; i++) {
    memcpy(aux, cells + i*gridSize, gridSize * sizeof(float));

    // Copy data from CPU to GPU
    CUDA_CHECK(hipMemcpy(chunk, aux, gridSize*sizeof(float), hipMemcpyHostToDevice));
    minReduction<<<gridSize,blockSize>>>(chunk,outData); // outData lenght 32.768
    hipDeviceSynchronize();
    // check for errors
    hipError_t error = hipGetLastError();
    if (error != hipSuccess) {
      fprintf(stderr, "ERROR: %s \n", hipGetErrorString(error));
    }

    minReduction<<<gridSize/blockSize,blockSize>>>(outData,out2); // out2 lenght 128
    hipDeviceSynchronize();
    hipMemcpy(y, out2, 128*sizeof(float), hipMemcpyDeviceToHost); 
    // check for errors
    error = hipGetLastError();
    if (error != hipSuccess) {
      fprintf(stderr, "ERROR: %s \n", hipGetErrorString(error));
    }

    // min load
    for (size_t i = 0; i < 128; i++) {
      min = (y[i]<min)?y[i]:min;
    }
    cout << min << endl;
  }

  hipFree(chunk);
  hipFree(outData);
  hipFree(out2);
  free(cells);
  free(aux);

  return 0;
}

	.text
	.file	"test.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z27__device_stub__minReductionPfS_ # -- Begin function _Z27__device_stub__minReductionPfS_
	.type	_Z27__device_stub__minReductionPfS_,@function
_Z27__device_stub__minReductionPfS_:    # @_Z27__device_stub__minReductionPfS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z12minReductionPfS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z27__device_stub__minReductionPfS_, .Lfunc_end0-_Z27__device_stub__minReductionPfS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z12random_floatff
.LCPI1_0:
	.long	0x30000000                      # float 4.65661287E-10
	.text
	.globl	_Z12random_floatff
	.type	_Z12random_floatff,@function
_Z12random_floatff:                     # @_Z12random_floatff
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movss	%xmm1, 4(%rsp)                  # 4-byte Spill
	movss	%xmm0, (%rsp)                   # 4-byte Spill
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2ss	%eax, %xmm1
	mulss	.LCPI1_0(%rip), %xmm1
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	(%rsp), %xmm2                   # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	subss	%xmm2, %xmm0
	mulss	%xmm1, %xmm0
	addss	%xmm2, %xmm0
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z12random_floatff, .Lfunc_end1-_Z12random_floatff
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI2_1:
	.long	0x418feb85                      # float 17.9899998
.LCPI2_2:
	.long	0x40000000                      # float 2
.LCPI2_3:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$584, %rsp                      # imm = 0x248
	.cfi_def_cfa_offset 640
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	48(%rsp), %rax
	movq	%rax, -16(%rax)
	movq	$0, -8(%rax)
	movb	$0, (%rax)
	movl	$268435456, %edi                # imm = 0x10000000
	callq	malloc
	movq	%rax, %rbx
	xorl	%r14d, %r14d
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	cmpq	$1000000, %r14                  # imm = 0xF4240
	jne	.LBB2_2
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI2_0(%rip), %xmm0
	mulss	.LCPI2_1(%rip), %xmm0
	addss	.LCPI2_2(%rip), %xmm0
	movss	%xmm0, 4000000(%rbx)
	jmp	.LBB2_4
.LBB2_2:                                #   in Loop: Header=BB2_1 Depth=1
	movl	$1065353216, (%rbx,%r14,4)      # imm = 0x3F800000
.LBB2_4:                                #   in Loop: Header=BB2_1 Depth=1
	incq	%r14
	cmpq	$67108864, %r14                 # imm = 0x4000000
	jne	.LBB2_1
# %bb.5:
.Ltmp0:
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$10, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp1:
# %bb.6:                                # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
.Ltmp2:
	movl	$_ZSt4cout, %edi
	movl	$32768, %esi                    # imm = 0x8000
	callq	_ZNSolsEi
.Ltmp3:
# %bb.7:
	movq	%rax, %r14
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
.Ltmp4:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp5:
# %bb.8:                                # %.noexc116
.Ltmp6:
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
.Ltmp7:
# %bb.9:                                # %.noexc117
.Ltmp8:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp9:
# %bb.10:                               # %_ZNSolsEPFRSoS_E.exit
.Ltmp11:
	leaq	24(%rsp), %rdi
	movl	$131072, %esi                   # imm = 0x20000
	callq	hipMalloc
.Ltmp12:
# %bb.11:                               # %_ZL9hipMallocIfE10hipError_tPPT_m.exit
	testl	%eax, %eax
	je	.LBB2_19
# %bb.12:
.Ltmp13:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp14:
# %bb.13:
	movq	%rax, %r14
	testq	%rax, %rax
	je	.LBB2_14
# %bb.15:
	movq	%r14, %rdi
	callq	strlen
.Ltmp15:
	movl	$_ZSt4cout, %edi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp16:
	jmp	.LBB2_16
.LBB2_14:
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cout(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
.Ltmp17:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp18:
.LBB2_16:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit85
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %edi
	addq	-24(%rax), %rdi
.Ltmp19:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp20:
# %bb.17:                               # %.noexc119
.Ltmp21:
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp22:
# %bb.18:                               # %.noexc120
.Ltmp23:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp24:
.LBB2_19:                               # %_ZNSolsEPFRSoS_E.exit87
.Ltmp26:
	leaq	16(%rsp), %rdi
	movl	$131072, %esi                   # imm = 0x20000
	callq	hipMalloc
.Ltmp27:
# %bb.20:                               # %_ZL9hipMallocIfE10hipError_tPPT_m.exit89
	testl	%eax, %eax
	je	.LBB2_30
# %bb.21:
.Ltmp28:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp29:
# %bb.22:
	movq	%rax, %r14
	testq	%rax, %rax
	je	.LBB2_23
# %bb.26:
	movq	%r14, %rdi
	callq	strlen
.Ltmp30:
	movl	$_ZSt4cout, %edi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp31:
	jmp	.LBB2_27
.LBB2_23:
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cout(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
.Ltmp32:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp33:
.LBB2_27:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit93
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %edi
	addq	-24(%rax), %rdi
.Ltmp34:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp35:
# %bb.28:                               # %.noexc123
.Ltmp36:
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp37:
# %bb.29:                               # %.noexc124
.Ltmp38:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp39:
.LBB2_30:                               # %_ZNSolsEPFRSoS_E.exit95
.Ltmp41:
	leaq	8(%rsp), %rdi
	movl	$512, %esi                      # imm = 0x200
	callq	hipMalloc
.Ltmp42:
# %bb.31:                               # %_ZL9hipMallocIfE10hipError_tPPT_m.exit97
	testl	%eax, %eax
	je	.LBB2_39
# %bb.32:
.Ltmp43:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp44:
# %bb.33:
	movq	%rax, %r14
	testq	%rax, %rax
	je	.LBB2_34
# %bb.35:
	movq	%r14, %rdi
	callq	strlen
.Ltmp45:
	movl	$_ZSt4cout, %edi
	movq	%r14, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp46:
	jmp	.LBB2_36
.LBB2_34:
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cout(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
.Ltmp47:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp48:
.LBB2_36:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit101
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %edi
	addq	-24(%rax), %rdi
.Ltmp49:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp50:
# %bb.37:                               # %.noexc127
.Ltmp51:
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp52:
# %bb.38:                               # %.noexc128
.Ltmp53:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp54:
.LBB2_39:                               # %_ZNSolsEPFRSoS_E.exit103
	movl	$131072, %edi                   # imm = 0x20000
	callq	malloc
	movq	%rax, %r14
	movss	.LCPI2_3(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movabsq	$4294967552, %r12               # imm = 0x100000100
	leaq	64(%rsp), %rbp
	xorl	%r13d, %r13d
.LBB2_40:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_65 Depth 2
	movq	%r13, %rsi
	shlq	$17, %rsi
	addq	%rbx, %rsi
	movl	$131072, %edx                   # imm = 0x20000
	movq	%r14, %rdi
	callq	memcpy@PLT
	movq	24(%rsp), %rdi
.Ltmp56:
	movl	$131072, %edx                   # imm = 0x20000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp57:
# %bb.41:                               #   in Loop: Header=BB2_40 Depth=1
	testl	%eax, %eax
	je	.LBB2_49
# %bb.42:                               #   in Loop: Header=BB2_40 Depth=1
.Ltmp58:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp59:
# %bb.43:                               #   in Loop: Header=BB2_40 Depth=1
	movq	%rax, %r15
	testq	%rax, %rax
	je	.LBB2_44
# %bb.45:                               #   in Loop: Header=BB2_40 Depth=1
	movq	%r15, %rdi
	callq	strlen
.Ltmp60:
	movl	$_ZSt4cout, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp61:
	jmp	.LBB2_46
.LBB2_44:                               #   in Loop: Header=BB2_40 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cout(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
.Ltmp62:
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.Ltmp63:
.LBB2_46:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit107
                                        #   in Loop: Header=BB2_40 Depth=1
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	movl	$_ZSt4cout, %eax
	addq	%rax, %rdi
.Ltmp64:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp65:
# %bb.47:                               # %.noexc131
                                        #   in Loop: Header=BB2_40 Depth=1
.Ltmp66:
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp67:
# %bb.48:                               # %.noexc132
                                        #   in Loop: Header=BB2_40 Depth=1
.Ltmp68:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp69:
.LBB2_49:                               # %_ZNSolsEPFRSoS_E.exit109
                                        #   in Loop: Header=BB2_40 Depth=1
.Ltmp71:
	movabsq	$4295000064, %rdi               # imm = 0x100008000
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp72:
# %bb.50:                               #   in Loop: Header=BB2_40 Depth=1
	testl	%eax, %eax
	jne	.LBB2_52
# %bb.51:                               #   in Loop: Header=BB2_40 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
.Ltmp73:
	callq	_Z27__device_stub__minReductionPfS_
.Ltmp74:
.LBB2_52:                               #   in Loop: Header=BB2_40 Depth=1
.Ltmp75:
	callq	hipDeviceSynchronize
.Ltmp76:
# %bb.53:                               #   in Loop: Header=BB2_40 Depth=1
.Ltmp78:
	callq	hipGetLastError
.Ltmp79:
# %bb.54:                               #   in Loop: Header=BB2_40 Depth=1
	testl	%eax, %eax
	jne	.LBB2_55
.LBB2_57:                               #   in Loop: Header=BB2_40 Depth=1
.Ltmp82:
	movabsq	$4294967424, %rdi               # imm = 0x100000080
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp83:
# %bb.58:                               #   in Loop: Header=BB2_40 Depth=1
	testl	%eax, %eax
	jne	.LBB2_60
# %bb.59:                               #   in Loop: Header=BB2_40 Depth=1
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
.Ltmp84:
	callq	_Z27__device_stub__minReductionPfS_
.Ltmp85:
.LBB2_60:                               #   in Loop: Header=BB2_40 Depth=1
.Ltmp86:
	callq	hipDeviceSynchronize
.Ltmp87:
# %bb.61:                               #   in Loop: Header=BB2_40 Depth=1
	movq	8(%rsp), %rsi
.Ltmp88:
	movl	$512, %edx                      # imm = 0x200
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp89:
# %bb.62:                               #   in Loop: Header=BB2_40 Depth=1
.Ltmp90:
	callq	hipGetLastError
.Ltmp91:
# %bb.63:                               #   in Loop: Header=BB2_40 Depth=1
	testl	%eax, %eax
	jne	.LBB2_77
.LBB2_64:                               # %.preheader
                                        #   in Loop: Header=BB2_40 Depth=1
	xorl	%eax, %eax
	movss	4(%rsp), %xmm1                  # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
.LBB2_65:                               #   Parent Loop BB2_40 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movaps	%xmm1, %xmm0
	movss	64(%rsp,%rax,4), %xmm1          # xmm1 = mem[0],zero,zero,zero
	minss	%xmm0, %xmm1
	incq	%rax
	cmpq	$128, %rax
	jne	.LBB2_65
# %bb.66:                               #   in Loop: Header=BB2_40 Depth=1
	movss	%xmm1, 4(%rsp)                  # 4-byte Spill
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
.Ltmp94:
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp95:
# %bb.67:                               # %_ZNSolsEf.exit
                                        #   in Loop: Header=BB2_40 Depth=1
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
.Ltmp96:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp97:
# %bb.68:                               # %.noexc135
                                        #   in Loop: Header=BB2_40 Depth=1
.Ltmp98:
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
.Ltmp99:
# %bb.69:                               # %.noexc136
                                        #   in Loop: Header=BB2_40 Depth=1
.Ltmp100:
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp101:
# %bb.70:                               # %_ZNSolsEPFRSoS_E.exit112
                                        #   in Loop: Header=BB2_40 Depth=1
	incq	%r13
	cmpq	$8, %r13
	jne	.LBB2_40
	jmp	.LBB2_71
.LBB2_55:                               #   in Loop: Header=BB2_40 Depth=1
	movq	stderr(%rip), %r15
.Ltmp80:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp81:
# %bb.56:                               #   in Loop: Header=BB2_40 Depth=1
	movl	$.L.str.1, %esi
	movq	%r15, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB2_57
.LBB2_77:                               #   in Loop: Header=BB2_40 Depth=1
	movq	stderr(%rip), %r15
.Ltmp92:
	movl	%eax, %edi
	callq	hipGetErrorString
.Ltmp93:
# %bb.78:                               #   in Loop: Header=BB2_40 Depth=1
	movl	$.L.str.1, %esi
	movq	%r15, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB2_64
.LBB2_71:
	movq	24(%rsp), %rdi
.Ltmp103:
	callq	hipFree
.Ltmp104:
# %bb.72:
	movq	16(%rsp), %rdi
.Ltmp105:
	callq	hipFree
.Ltmp106:
# %bb.73:
	movq	8(%rsp), %rdi
.Ltmp107:
	callq	hipFree
.Ltmp108:
# %bb.74:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	32(%rsp), %rdi
	leaq	48(%rsp), %rax
	cmpq	%rax, %rdi
	je	.LBB2_76
# %bb.75:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB2_76:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	xorl	%eax, %eax
	addq	$584, %rsp                      # imm = 0x248
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_79:
	.cfi_def_cfa_offset 640
.Ltmp109:
	jmp	.LBB2_80
.LBB2_84:
.Ltmp55:
	jmp	.LBB2_80
.LBB2_83:
.Ltmp40:
	jmp	.LBB2_80
.LBB2_25:
.Ltmp25:
	jmp	.LBB2_80
.LBB2_24:
.Ltmp10:
	jmp	.LBB2_80
.LBB2_86:
.Ltmp77:
	jmp	.LBB2_80
.LBB2_85:
.Ltmp70:
	jmp	.LBB2_80
.LBB2_87:
.Ltmp102:
.LBB2_80:
	movq	%rax, %rbx
	movq	32(%rsp), %rdi
	leaq	48(%rsp), %rax
	cmpq	%rax, %rdi
	je	.LBB2_82
# %bb.81:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i113
	callq	_ZdlPv
.LBB2_82:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit115
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp9-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp9
	.uleb128 .Ltmp10-.Lfunc_begin0          #     jumps to .Ltmp10
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp11-.Lfunc_begin0          # >> Call Site 2 <<
	.uleb128 .Ltmp24-.Ltmp11                #   Call between .Ltmp11 and .Ltmp24
	.uleb128 .Ltmp25-.Lfunc_begin0          #     jumps to .Ltmp25
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp26-.Lfunc_begin0          # >> Call Site 3 <<
	.uleb128 .Ltmp39-.Ltmp26                #   Call between .Ltmp26 and .Ltmp39
	.uleb128 .Ltmp40-.Lfunc_begin0          #     jumps to .Ltmp40
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp41-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp54-.Ltmp41                #   Call between .Ltmp41 and .Ltmp54
	.uleb128 .Ltmp55-.Lfunc_begin0          #     jumps to .Ltmp55
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp54-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp56-.Ltmp54                #   Call between .Ltmp54 and .Ltmp56
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp56-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp69-.Ltmp56                #   Call between .Ltmp56 and .Ltmp69
	.uleb128 .Ltmp70-.Lfunc_begin0          #     jumps to .Ltmp70
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp71-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp76-.Ltmp71                #   Call between .Ltmp71 and .Ltmp76
	.uleb128 .Ltmp77-.Lfunc_begin0          #     jumps to .Ltmp77
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp78-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Ltmp93-.Ltmp78                #   Call between .Ltmp78 and .Ltmp93
	.uleb128 .Ltmp102-.Lfunc_begin0         #     jumps to .Ltmp102
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp103-.Lfunc_begin0         # >> Call Site 9 <<
	.uleb128 .Ltmp108-.Ltmp103              #   Call between .Ltmp103 and .Ltmp108
	.uleb128 .Ltmp109-.Lfunc_begin0         #     jumps to .Ltmp109
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp108-.Lfunc_begin0         # >> Call Site 10 <<
	.uleb128 .Lfunc_end2-.Ltmp108           #   Call between .Ltmp108 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.text
	.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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12minReductionPfS_, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12minReductionPfS_,@object    # @_Z12minReductionPfS_
	.section	.rodata,"a",@progbits
	.globl	_Z12minReductionPfS_
	.p2align	3, 0x0
_Z12minReductionPfS_:
	.quad	_Z27__device_stub__minReductionPfS_
	.size	_Z12minReductionPfS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"gridSize: "
	.size	.L.str, 11

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"ERROR: %s \n"
	.size	.L.str.1, 12

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12minReductionPfS_"
	.size	.L__unnamed_1, 21

	.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 _Z27__device_stub__minReductionPfS_
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z12minReductionPfS_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12minReductionPfS_    ; -- Begin function _Z12minReductionPfS_
	.globl	_Z12minReductionPfS_
	.p2align	8
	.type	_Z12minReductionPfS_,@function
_Z12minReductionPfS_:                   ; @_Z12minReductionPfS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s5, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_mov_b32 s4, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s5, s5, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_mul_i32 s6, s15, s5
	s_cmpk_lt_u32 s5, 0x42
	v_lshl_add_u32 v1, s6, 1, v0
	v_mov_b32_e32 v2, 0
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_nc_u32_e32 v1, s5, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	s_clause 0x1
	global_load_b32 v3, v[3:4], off
	global_load_b32 v2, v[1:2], off
	s_waitcnt vmcnt(0)
	v_dual_add_f32 v2, v3, v2 :: v_dual_lshlrev_b32 v1, 2, v0
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB0_5
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_lshr_b32 s0, s5, 1
	s_mov_b32 s1, exec_lo
	v_cmpx_gt_u32_e64 s0, v0
	s_cbranch_execz .LBB0_4
; %bb.3:                                ;   in Loop: Header=BB0_1 Depth=1
	v_lshl_add_u32 v2, s0, 2, v1
	ds_load_b32 v3, v1
	ds_load_b32 v2, v2
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_f32_e32 vcc_lo, v3, v2
	v_cndmask_b32_e32 v2, v2, v3, vcc_lo
	ds_store_b32 v1, v2
.LBB0_4:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmpk_lt_u32 s5, 0x84
	s_mov_b32 s5, s0
	s_branch .LBB0_1
.LBB0_5:                                ; %._crit_edge
	s_mov_b32 s0, exec_lo
	v_cmpx_gt_u32_e32 32, v0
	s_cbranch_execz .LBB0_7
; %bb.6:
	ds_load_2addr_b32 v[2:3], v1 offset1:1
	ds_load_b32 v8, v1 offset:128
	ds_load_2addr_b32 v[4:5], v1 offset0:8 offset1:16
	ds_load_2addr_b32 v[6:7], v1 offset0:2 offset1:4
	s_waitcnt lgkmcnt(2)
	v_cmp_lt_f32_e32 vcc_lo, v2, v8
	v_cndmask_b32_e32 v2, v8, v2, vcc_lo
	s_waitcnt lgkmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e32 vcc_lo, v2, v5
	v_cndmask_b32_e32 v2, v5, v2, vcc_lo
	v_cmp_lt_f32_e32 vcc_lo, v2, v4
	v_cndmask_b32_e32 v2, v4, v2, vcc_lo
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_lt_f32_e32 vcc_lo, v2, v7
	v_cndmask_b32_e32 v2, v7, v2, vcc_lo
	v_cmp_lt_f32_e32 vcc_lo, v2, v6
	v_cndmask_b32_e32 v2, v6, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_f32_e32 vcc_lo, v2, v3
	v_cndmask_b32_e32 v2, v3, v2, vcc_lo
	ds_store_b32 v1, v2
.LBB0_7:
	s_or_b32 exec_lo, exec_lo, s0
	s_mov_b32 s5, 0
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB0_9
; %bb.8:
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[0:1], s[4:5], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s2, s0
	s_addc_u32 s1, s3, s1
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12minReductionPfS_
		.amdhsa_group_segment_fixed_size 1024
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 9
		.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	_Z12minReductionPfS_, .Lfunc_end0-_Z12minReductionPfS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 460
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12minReductionPfS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12minReductionPfS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
