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

#include <cuda_runtime_api.h>

#define restrict __restrict__

void check_error(cudaError_t err, const char *msg)
{
  if (err != cudaSuccess) {
    fprintf(stderr, "%s : errore %d (%s)\n",
      msg, err, cudaGetErrorString(err));
    exit(err);
  }
}

float runtime;
void PrintStats(size_t bytes, cudaEvent_t before, cudaEvent_t after, const char *msg)
{ 
  check_error(cudaEventElapsedTime(&runtime, before, after), msg);
  printf("%s %gms, %g GB/s\n", msg, runtime, bytes/runtime/(1024*1024));
}

__global__ void
init(int * restrict input,  int numels)
{
  int gid = threadIdx.x + blockIdx.x*blockDim.x;
  if (gid < numels)
      input[gid] = gid+1; 
}

 /*shared memory da utilizzare nei medoti di riduzione */
 extern __shared__ int sPartial[];

__global__ void
reduction(int* restrict input, int* restrict output, int numels)
{

  
    int gid = threadIdx.x + blockIdx.x*blockDim.x;
    int min = input[gid];
  
    //Fase 1: pre-riduzione e riempimento shared-memory
    while (gid < numels)
    {
      if(input[gid] < min)
          min = input[gid];
      
      gid += gridDim.x*blockDim.x;
    }
  
    const int lid = threadIdx.x;
    sPartial[lid] = min;
  
    //Fase 2: riduzione in shared memory
    int stride = (blockDim.x)/2;
    while (stride > 0)
    {
      __syncthreads();
      if (lid < stride && sPartial[lid + stride] < sPartial[lid]) {
        sPartial[lid] = sPartial[lid + stride];
      }
      stride /= 2;
    }
  
    /* Fase 3: salvataggio del risultato del blocco in memoria globale */
     if (lid == 0){
        output[blockIdx.x] = sPartial[0];
  }
}

bool check_result(int result, int numels)
{
    return result == 1;
}

int main(int argc, char *argv[])
{
  int numels;

  if (argc > 1) {
    numels = atoi(argv[1]);
  } else {
    fprintf(stderr, "inserire numero di elementi\n");
    exit(1);
  }
  
  int h_output;
  int* d_input, *d_output, *d_result;
  size_t numbytes = numels*sizeof(int);
  
  check_error(cudaMalloc(&d_input, numbytes), "alloc d_input");
  
  cudaEvent_t before_init, before_reduction, before_final_reduction, before_download;
  cudaEvent_t after_init, after_reduction, after_final_reduction, after_download;
  
  check_error(cudaEventCreate(&before_init), "create before_init cudaEvent");
  check_error(cudaEventCreate(&before_reduction), "create before_reduction cudaEvent");
  check_error(cudaEventCreate(&before_final_reduction), "create before_final_reduction cudaEvent");
  check_error(cudaEventCreate(&before_download), "create before_download cudaEvent");
  
  check_error(cudaEventCreate(&after_init), "create after_init cudaEvent");
  check_error(cudaEventCreate(&after_reduction), "create after_reduction cudaEvent");
  check_error(cudaEventCreate(&after_final_reduction), "create after_final_reduction cudaEvent");
  check_error(cudaEventCreate(&after_download), "create after_download cudaEvent");
  
  const int blockSize = 32; //prova a modificare con numeri potenze del 2
  int numBlocks = (numels + blockSize - 1)/blockSize; 
  
  cudaEventRecord(before_init);
  init<<<numBlocks, blockSize>>>(d_input, numels);
  cudaEventRecord(after_init);
  
  check_error(cudaMalloc(&d_output, numBlocks*sizeof(int)), "alloc d_output");
  check_error(cudaMalloc(&d_result, sizeof(int)), "alloc d_result");
  
  cudaEventRecord(before_reduction);
  reduction<<<numBlocks, blockSize, blockSize*sizeof(int)>>>(d_input, d_output, numels);
  cudaEventRecord(after_reduction);
   
  cudaEventRecord(before_final_reduction);
  reduction<<<1, blockSize, blockSize*sizeof(int)>>>(d_output, d_result, numBlocks);
  cudaEventRecord(after_final_reduction);
  
  //copy result from Device to Host (recorded)
  cudaEventRecord(before_download);
  check_error(cudaMemcpy(&h_output, d_result, sizeof(int), cudaMemcpyDeviceToHost), "copy d_result");
  cudaEventRecord(after_download);
  
  //cudaEventElapsedTime
  check_error(cudaEventSynchronize(after_download), "sync cudaEvents");
  PrintStats(numels*sizeof(int), before_init, after_init, "time init");
  PrintStats((numels+numBlocks)*sizeof(int), before_reduction, after_reduction, "time reduction");
  PrintStats((numels+1)*sizeof(int), before_final_reduction, after_final_reduction, "time final_reduction");
  PrintStats(sizeof(int), before_download, after_download, "time download");

  if(!check_result(h_output, numels))
  {
    fprintf(stderr, "SBAGLIATO!\n");
    printf("nostro: %d invece che %d\n", h_output, 1);
    exit(1);
  }
  else
  {
  	printf("risultato: %d == %d\n", h_output, 1);
  }
  
  cudaFree(d_input);
  cudaFree(d_output);
  return 0;
}


	.file	"tmpxft_0022d449_00000000-6_reduction_min.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s : errore %d (%s)\n"
	.text
	.globl	_Z11check_error9cudaErrorPKc
	.type	_Z11check_error9cudaErrorPKc, @function
_Z11check_error9cudaErrorPKc:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edi, %ebx
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	cudaGetErrorString@PLT
	movl	%ebx, %r8d
	movq	%rbp, %rcx
	movl	$2, %esi
	movq	stderr(%rip), %rdi
	movq	%rax, %r9
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	%ebx, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z11check_error9cudaErrorPKc, .-_Z11check_error9cudaErrorPKc
	.section	.rodata.str1.1
.LC2:
	.string	"%s %gms, %g GB/s\n"
	.text
	.globl	_Z10PrintStatsmP10CUevent_stS0_PKc
	.type	_Z10PrintStatsmP10CUevent_stS0_PKc, @function
_Z10PrintStatsmP10CUevent_stS0_PKc:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rcx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	leaq	runtime(%rip), %rdi
	pushq	%r8
	.cfi_def_cfa_offset 32
	call	cudaEventElapsedTime@PLT
	movq	%rbp, %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	movss	runtime(%rip), %xmm0
	testq	%rbx, %rbx
	js	.L9
	cvtsi2ssq	%rbx, %xmm1
	jmp	.L10
.L9:
	movq	%rbx, %rax
	andl	$1, %ebx
	shrq	%rax
	orq	%rbx, %rax
	cvtsi2ssq	%rax, %xmm1
	addss	%xmm1, %xmm1
.L10:
	divss	%xmm0, %xmm1
	movq	%rbp, %rdx
	leaq	.LC2(%rip), %rsi
	movb	$2, %al
	movl	$2, %edi
	cvtss2sd	%xmm0, %xmm0
	mulss	.LC1(%rip), %xmm1
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	cvtss2sd	%xmm1, %xmm1
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z10PrintStatsmP10CUevent_stS0_PKc, .-_Z10PrintStatsmP10CUevent_stS0_PKc
	.globl	_Z12check_resultii
	.type	_Z12check_resultii, @function
_Z12check_resultii:
.LFB2029:
	.cfi_startproc
	endbr64
	decl	%edi
	sete	%al
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z12check_resultii, .-_Z12check_resultii
	.globl	_Z24__device_stub__Z4initPiiPii
	.type	_Z24__device_stub__Z4initPiiPii, @function
_Z24__device_stub__Z4initPiiPii:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movl	%esi, 12(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rax
	movq	%rdi, 16(%rsp)
	leaq	40(%rsp), %rdi
	movq	%rax, 88(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movl	$1, 48(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z4initPii(%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
.L13:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z24__device_stub__Z4initPiiPii, .-_Z24__device_stub__Z4initPiiPii
	.globl	_Z4initPii
	.type	_Z4initPii, @function
_Z4initPii:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z24__device_stub__Z4initPiiPii
	.cfi_endproc
.LFE2056:
	.size	_Z4initPii, .-_Z4initPii
	.globl	_Z31__device_stub__Z9reductionPiS_iPiS_i
	.type	_Z31__device_stub__Z9reductionPiS_iPiS_i, @function
_Z31__device_stub__Z9reductionPiS_iPiS_i:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rcx
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rax
	movq	%rdi, 16(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rax, 96(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rsi, 24(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movl	$1, 56(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L18
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z9reductionPiS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L18:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z31__device_stub__Z9reductionPiS_iPiS_i, .-_Z31__device_stub__Z9reductionPiS_iPiS_i
	.globl	_Z9reductionPiS_i
	.type	_Z9reductionPiS_i, @function
_Z9reductionPiS_i:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z9reductionPiS_iPiS_i
	.cfi_endproc
.LFE2058:
	.size	_Z9reductionPiS_i, .-_Z9reductionPiS_i
	.section	.rodata.str1.1
.LC3:
	.string	"alloc d_input"
.LC4:
	.string	"create before_init cudaEvent"
.LC5:
	.string	"create before_reduction cudaEvent"
.LC6:
	.string	"create before_final_reduction cudaEvent"
.LC7:
	.string	"create before_download cudaEvent"
.LC8:
	.string	"create after_init cudaEvent"
.LC9:
	.string	"create after_reduction cudaEvent"
.LC10:
	.string	"create after_final_reduction cudaEvent"
.LC11:
	.string	"create after_download cudaEvent"
.LC12:
	.string	"inserire numero di elementi\n"
.LC13:
	.string	"alloc d_output"
.LC14:
	.string	"alloc d_result"
.LC15:
	.string	"copy d_result"
.LC16:
	.string	"sync cudaEvents"
.LC17:
	.string	"time init"
.LC18:
	.string	"time reduction"
.LC19:
	.string	"time final_reduction"
.LC20:
	.string	"time download"
.LC21:
	.string	"SBAGLIATO!\n"
.LC22:
	.string	"nostro: %d invece che %d\n"
.LC23:
	.string	"risultato: %d == %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	addq	$-128, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	decl	%edi
	jle	.L24
	movq	8(%rsi), %rdi
	call	atoi@PLT
	leaq	8(%rsp), %rdi
	movslq	%eax, %r12
	movq	%r12, %rbx
	salq	$2, %r12
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	.LC3(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC4(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC5(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	48(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC6(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	56(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC7(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	64(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC8(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	72(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC9(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	80(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC10(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	88(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	.LC11(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leal	31(%rbx), %eax
	movl	$32, %ecx
	xorl	%esi, %esi
	cltd
	movq	32(%rsp), %rdi
	idivl	%ecx
	movl	%eax, %ebp
	call	cudaEventRecord@PLT
	movl	%ebp, 96(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	$134217729, %edx
	movl	$1, %ecx
	movl	$1, 116(%rsp)
	movq	%rax, 100(%rsp)
	movq	96(%rsp), %rdi
	salq	$5, %rdx
	movl	104(%rsp), %esi
	movq	%rdx, 108(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	8(%rsp), %rdi
	movl	%ebx, %esi
	call	_Z24__device_stub__Z4initPiiPii
	jmp	.L25
.L24:
	movq	stderr(%rip), %rdi
	leaq	.LC12(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L33
.L25:
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movslq	%ebp, %rsi
	leaq	16(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	leaq	.LC13(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	leaq	.LC14(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%ebp, 96(%rsp)
	movl	$134217729, %edx
	movabsq	$4294967297, %rax
	movq	%rax, 100(%rsp)
	movq	96(%rsp), %rdi
	salq	$5, %rdx
	xorl	%r9d, %r9d
	movl	104(%rsp), %esi
	movl	$128, %r8d
	movl	$1, %ecx
	movq	%rdx, 108(%rsp)
	movl	$1, 116(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L27
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	%ebx, %edx
	call	_Z31__device_stub__Z9reductionPiS_iPiS_i
.L27:
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$134217729, %edx
	xorl	%r9d, %r9d
	movabsq	$4294967297, %rdi
	salq	$5, %rdx
	movl	$128, %r8d
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rdx, 108(%rsp)
	movl	$1, 116(%rsp)
	movq	%rdi, 96(%rsp)
	movl	$1, 104(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebp, %edx
	call	_Z31__device_stub__Z9reductionPiS_iPiS_i
.L28:
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	movl	$4, %edx
	leaq	108(%rsp), %rdi
	call	cudaMemcpy@PLT
	leaq	.LC15(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	movq	88(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	88(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	leaq	.LC16(%rip), %rsi
	movl	%eax, %edi
	call	_Z11check_error9cudaErrorPKc
	movq	64(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	%r12, %rdi
	leaq	.LC17(%rip), %rcx
	call	_Z10PrintStatsmP10CUevent_stS0_PKc
	leal	(%rbx,%rbp), %edi
	movq	72(%rsp), %rdx
	movq	40(%rsp), %rsi
	movslq	%edi, %rdi
	leaq	.LC18(%rip), %rcx
	salq	$2, %rdi
	call	_Z10PrintStatsmP10CUevent_stS0_PKc
	movq	80(%rsp), %rdx
	movq	48(%rsp), %rsi
	leaq	4(%r12), %rdi
	leaq	.LC19(%rip), %rcx
	call	_Z10PrintStatsmP10CUevent_stS0_PKc
	movq	88(%rsp), %rdx
	movq	56(%rsp), %rsi
	leaq	.LC20(%rip), %rcx
	movl	$4, %edi
	call	_Z10PrintStatsmP10CUevent_stS0_PKc
	cmpl	$1, 108(%rsp)
	je	.L29
	movq	stderr(%rip), %rdi
	leaq	.LC21(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	108(%rsp), %edx
	movl	$1, %ecx
	xorl	%eax, %eax
	leaq	.LC22(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
.L33:
	movl	$1, %edi
	call	exit@PLT
.L29:
	movl	$1, %ecx
	movl	$1, %edx
	leaq	.LC23(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	subq	$-128, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC24:
	.string	"_Z9reductionPiS_i"
.LC25:
	.string	"_Z4initPii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC24(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z9reductionPiS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC25(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z4initPii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	runtime
	.bss
	.align 4
	.type	runtime, @object
	.size	runtime, 4
runtime:
	.zero	4
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC1:
	.long	897581056
	.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 <hip/hip_runtime_api.h>

#define restrict __restrict__

void check_error(hipError_t err, const char *msg)
{
  if (err != hipSuccess) {
    fprintf(stderr, "%s : errore %d (%s)\n",
      msg, err, hipGetErrorString(err));
    exit(err);
  }
}

float runtime;
void PrintStats(size_t bytes, hipEvent_t before, hipEvent_t after, const char *msg)
{ 
  check_error(hipEventElapsedTime(&runtime, before, after), msg);
  printf("%s %gms, %g GB/s\n", msg, runtime, bytes/runtime/(1024*1024));
}

__global__ void
init(int * restrict input,  int numels)
{
  int gid = threadIdx.x + blockIdx.x*blockDim.x;
  if (gid < numels)
      input[gid] = gid+1; 
}

 /*shared memory da utilizzare nei medoti di riduzione */
 extern __shared__ int sPartial[];

__global__ void
reduction(int* restrict input, int* restrict output, int numels)
{

  
    int gid = threadIdx.x + blockIdx.x*blockDim.x;
    int min = input[gid];
  
    //Fase 1: pre-riduzione e riempimento shared-memory
    while (gid < numels)
    {
      if(input[gid] < min)
          min = input[gid];
      
      gid += gridDim.x*blockDim.x;
    }
  
    const int lid = threadIdx.x;
    sPartial[lid] = min;
  
    //Fase 2: riduzione in shared memory
    int stride = (blockDim.x)/2;
    while (stride > 0)
    {
      __syncthreads();
      if (lid < stride && sPartial[lid + stride] < sPartial[lid]) {
        sPartial[lid] = sPartial[lid + stride];
      }
      stride /= 2;
    }
  
    /* Fase 3: salvataggio del risultato del blocco in memoria globale */
     if (lid == 0){
        output[blockIdx.x] = sPartial[0];
  }
}

bool check_result(int result, int numels)
{
    return result == 1;
}

int main(int argc, char *argv[])
{
  int numels;

  if (argc > 1) {
    numels = atoi(argv[1]);
  } else {
    fprintf(stderr, "inserire numero di elementi\n");
    exit(1);
  }
  
  int h_output;
  int* d_input, *d_output, *d_result;
  size_t numbytes = numels*sizeof(int);
  
  check_error(hipMalloc(&d_input, numbytes), "alloc d_input");
  
  hipEvent_t before_init, before_reduction, before_final_reduction, before_download;
  hipEvent_t after_init, after_reduction, after_final_reduction, after_download;
  
  check_error(hipEventCreate(&before_init), "create before_init cudaEvent");
  check_error(hipEventCreate(&before_reduction), "create before_reduction cudaEvent");
  check_error(hipEventCreate(&before_final_reduction), "create before_final_reduction cudaEvent");
  check_error(hipEventCreate(&before_download), "create before_download cudaEvent");
  
  check_error(hipEventCreate(&after_init), "create after_init cudaEvent");
  check_error(hipEventCreate(&after_reduction), "create after_reduction cudaEvent");
  check_error(hipEventCreate(&after_final_reduction), "create after_final_reduction cudaEvent");
  check_error(hipEventCreate(&after_download), "create after_download cudaEvent");
  
  const int blockSize = 32; //prova a modificare con numeri potenze del 2
  int numBlocks = (numels + blockSize - 1)/blockSize; 
  
  hipEventRecord(before_init);
  init<<<numBlocks, blockSize>>>(d_input, numels);
  hipEventRecord(after_init);
  
  check_error(hipMalloc(&d_output, numBlocks*sizeof(int)), "alloc d_output");
  check_error(hipMalloc(&d_result, sizeof(int)), "alloc d_result");
  
  hipEventRecord(before_reduction);
  reduction<<<numBlocks, blockSize, blockSize*sizeof(int)>>>(d_input, d_output, numels);
  hipEventRecord(after_reduction);
   
  hipEventRecord(before_final_reduction);
  reduction<<<1, blockSize, blockSize*sizeof(int)>>>(d_output, d_result, numBlocks);
  hipEventRecord(after_final_reduction);
  
  //copy result from Device to Host (recorded)
  hipEventRecord(before_download);
  check_error(hipMemcpy(&h_output, d_result, sizeof(int), hipMemcpyDeviceToHost), "copy d_result");
  hipEventRecord(after_download);
  
  //cudaEventElapsedTime
  check_error(hipEventSynchronize(after_download), "sync cudaEvents");
  PrintStats(numels*sizeof(int), before_init, after_init, "time init");
  PrintStats((numels+numBlocks)*sizeof(int), before_reduction, after_reduction, "time reduction");
  PrintStats((numels+1)*sizeof(int), before_final_reduction, after_final_reduction, "time final_reduction");
  PrintStats(sizeof(int), before_download, after_download, "time download");

  if(!check_result(h_output, numels))
  {
    fprintf(stderr, "SBAGLIATO!\n");
    printf("nostro: %d invece che %d\n", h_output, 1);
    exit(1);
  }
  else
  {
  	printf("risultato: %d == %d\n", h_output, 1);
  }
  
  hipFree(d_input);
  hipFree(d_output);
  return 0;
}


	.text
	.file	"reduction_min.hip"
	.globl	_Z11check_error10hipError_tPKc  # -- Begin function _Z11check_error10hipError_tPKc
	.type	_Z11check_error10hipError_tPKc,@function
_Z11check_error10hipError_tPKc:         # @_Z11check_error10hipError_tPKc
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r14
	movl	%edi, %ebx
	movq	stderr(%rip), %r15
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movq	%r15, %rdi
	movq	%r14, %rdx
	movl	%ebx, %ecx
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	%ebx, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z11check_error10hipError_tPKc, .Lfunc_end0-_Z11check_error10hipError_tPKc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z10PrintStatsmP11ihipEvent_tS0_PKc
.LCPI1_0:
	.long	0x35800000                      # float 9.53674316E-7
	.text
	.globl	_Z10PrintStatsmP11ihipEvent_tS0_PKc
	.type	_Z10PrintStatsmP11ihipEvent_tS0_PKc,@function
_Z10PrintStatsmP11ihipEvent_tS0_PKc:    # @_Z10PrintStatsmP11ihipEvent_tS0_PKc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rcx, %rbx
	movq	%rdi, %r14
	movl	$runtime, %edi
	callq	hipEventElapsedTime
	movl	%eax, %edi
	movq	%rbx, %rsi
	callq	_Z11check_error10hipError_tPKc
	movss	runtime(%rip), %xmm1            # xmm1 = mem[0],zero,zero,zero
	cvtss2sd	%xmm1, %xmm0
	testq	%r14, %r14
	js	.LBB1_1
# %bb.2:
	cvtsi2ss	%r14, %xmm2
	jmp	.LBB1_3
.LBB1_1:
	movq	%r14, %rax
	shrq	%rax
	andl	$1, %r14d
	orq	%rax, %r14
	cvtsi2ss	%r14, %xmm2
	addss	%xmm2, %xmm2
.LBB1_3:
	divss	%xmm1, %xmm2
	mulss	.LCPI1_0(%rip), %xmm2
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm2, %xmm1
	movl	$.L.str.1, %edi
	movq	%rbx, %rsi
	movb	$2, %al
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.Lfunc_end1:
	.size	_Z10PrintStatsmP11ihipEvent_tS0_PKc, .Lfunc_end1-_Z10PrintStatsmP11ihipEvent_tS0_PKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__initPii      # -- Begin function _Z19__device_stub__initPii
	.type	_Z19__device_stub__initPii,@function
_Z19__device_stub__initPii:             # @_Z19__device_stub__initPii
	.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	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z4initPii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z19__device_stub__initPii, .Lfunc_end2-_Z19__device_stub__initPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__reductionPiS_i # -- Begin function _Z24__device_stub__reductionPiS_i
	.type	_Z24__device_stub__reductionPiS_i,@function
_Z24__device_stub__reductionPiS_i:      # @_Z24__device_stub__reductionPiS_i
	.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), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z9reductionPiS_i, %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_end3:
	.size	_Z24__device_stub__reductionPiS_i, .Lfunc_end3-_Z24__device_stub__reductionPiS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z12check_resultii              # -- Begin function _Z12check_resultii
	.type	_Z12check_resultii,@function
_Z12check_resultii:                     # @_Z12check_resultii
	.cfi_startproc
# %bb.0:
	cmpl	$1, %edi
	sete	%al
	retq
.Lfunc_end4:
	.size	_Z12check_resultii, .Lfunc_end4-_Z12check_resultii
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jl	.LBB5_9
# %bb.1:
	movabsq	$4294967328, %r14               # imm = 0x100000020
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebp
	movslq	%eax, %r13
	leaq	(,%r13,4), %rbx
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movl	$.L.str.3, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	96(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	movl	$.L.str.4, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	80(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.5, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	72(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.6, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	64(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.7, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	56(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.8, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	48(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.9, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.10, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movl	$.L.str.11, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leal	31(%r13), %eax
	leal	62(%r13), %r15d
	testl	%eax, %eax
	cmovnsl	%eax, %r15d
	sarl	$5, %r15d
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	(%r15,%r14), %r12
	addq	$-32, %r12
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_3
# %bb.2:
	movq	24(%rsp), %rdi
	movl	%ebp, %esi
	callq	_Z19__device_stub__initPii
.LBB5_3:
	movq	56(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movslq	%r15d, %rsi
	shlq	$2, %rsi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	$.L.str.12, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	leaq	88(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	movl	$.L.str.13, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	movq	80(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movl	$128, %r8d
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_5
# %bb.4:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	%ebp, %edx
	callq	_Z24__device_stub__reductionPiS_i
.LBB5_5:
	movq	48(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	72(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	leaq	-31(%r14), %rdi
	movl	$128, %r8d
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_7
# %bb.6:
	movq	16(%rsp), %rdi
	movq	88(%rsp), %rsi
	movl	%r15d, %edx
	callq	_Z24__device_stub__reductionPiS_i
.LBB5_7:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	64(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	88(%rsp), %rsi
	leaq	36(%rsp), %r14
	movl	$4, %edx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.14, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movl	$.L.str.15, %esi
	movl	%eax, %edi
	callq	_Z11check_error10hipError_tPKc
	movq	96(%rsp), %rsi
	movq	56(%rsp), %rdx
	movl	$.L.str.16, %ecx
	movq	%rbx, %rdi
	callq	_Z10PrintStatsmP11ihipEvent_tS0_PKc
	addl	%r13d, %r15d
	movslq	%r15d, %rdi
	shlq	$2, %rdi
	movq	80(%rsp), %rsi
	movq	48(%rsp), %rdx
	movl	$.L.str.17, %ecx
	callq	_Z10PrintStatsmP11ihipEvent_tS0_PKc
	leaq	4(,%r13,4), %rdi
	movq	72(%rsp), %rsi
	movq	40(%rsp), %rdx
	movl	$.L.str.18, %ecx
	callq	_Z10PrintStatsmP11ihipEvent_tS0_PKc
	movq	64(%rsp), %rsi
	movq	8(%rsp), %rdx
	movl	$4, %edi
	movl	$.L.str.19, %ecx
	callq	_Z10PrintStatsmP11ihipEvent_tS0_PKc
	cmpl	$1, (%r14)
	jne	.LBB5_11
# %bb.8:
	movl	$.L.str.22, %edi
	movl	$1, %esi
	movl	$1, %edx
	xorl	%eax, %eax
	callq	printf
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$104, %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
.LBB5_9:
	.cfi_def_cfa_offset 160
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$28, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB5_10
.LBB5_11:
	movq	stderr(%rip), %rcx
	movl	$.L.str.20, %edi
	movl	$11, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	36(%rsp), %esi
	movl	$.L.str.21, %edi
	movl	$1, %edx
	xorl	%eax, %eax
	callq	printf
.LBB5_10:
	movl	$1, %edi
	callq	exit
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4initPii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9reductionPiS_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s : errore %d (%s)\n"
	.size	.L.str, 21

	.type	runtime,@object                 # @runtime
	.bss
	.globl	runtime
	.p2align	2, 0x0
runtime:
	.long	0x00000000                      # float 0
	.size	runtime, 4

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%s %gms, %g GB/s\n"
	.size	.L.str.1, 18

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

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

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"inserire numero di elementi\n"
	.size	.L.str.2, 29

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"alloc d_input"
	.size	.L.str.3, 14

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"create before_init cudaEvent"
	.size	.L.str.4, 29

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"create before_reduction cudaEvent"
	.size	.L.str.5, 34

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"create before_final_reduction cudaEvent"
	.size	.L.str.6, 40

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"create before_download cudaEvent"
	.size	.L.str.7, 33

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"create after_init cudaEvent"
	.size	.L.str.8, 28

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"create after_reduction cudaEvent"
	.size	.L.str.9, 33

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"create after_final_reduction cudaEvent"
	.size	.L.str.10, 39

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"create after_download cudaEvent"
	.size	.L.str.11, 32

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"alloc d_output"
	.size	.L.str.12, 15

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"alloc d_result"
	.size	.L.str.13, 15

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"copy d_result"
	.size	.L.str.14, 14

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"sync cudaEvents"
	.size	.L.str.15, 16

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"time init"
	.size	.L.str.16, 10

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"time reduction"
	.size	.L.str.17, 15

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"time final_reduction"
	.size	.L.str.18, 21

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"time download"
	.size	.L.str.19, 14

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"SBAGLIATO!\n"
	.size	.L.str.20, 12

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"nostro: %d invece che %d\n"
	.size	.L.str.21, 26

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"risultato: %d == %d\n"
	.size	.L.str.22, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4initPii"
	.size	.L__unnamed_1, 11

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z9reductionPiS_i"
	.size	.L__unnamed_2, 18

	.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 _Z19__device_stub__initPii
	.addrsig_sym _Z24__device_stub__reductionPiS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym runtime
	.addrsig_sym _Z4initPii
	.addrsig_sym _Z9reductionPiS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4initPii              ; -- Begin function _Z4initPii
	.globl	_Z4initPii
	.p2align	8
	.type	_Z4initPii,@function
_Z4initPii:                             ; @_Z4initPii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b32 s3, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b64 s[0:1], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	v_add_nc_u32_e32 v0, 1, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	global_store_b32 v[2:3], v0, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4initPii
		.amdhsa_group_segment_fixed_size 0
		.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 4
		.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	_Z4initPii, .Lfunc_end0-_Z4initPii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 128
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z9reductionPiS_i       ; -- Begin function _Z9reductionPiS_i
	.globl	_Z9reductionPiS_i
	.p2align	8
	.type	_Z9reductionPiS_i,@function
_Z9reductionPiS_i:                      ; @_Z9reductionPiS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_add_u32 s8, s0, 24
	s_mov_b32 s2, s15
	s_addc_u32 s9, s1, 0
	s_load_b32 s0, s[0:1], 0x10
	s_mov_b32 s1, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b32 v3, v[2:3], off
	v_cmpx_gt_i32_e64 s0, v1
	s_cbranch_execz .LBB1_4
; %bb.1:                                ; %.lr.ph
	s_load_b32 s9, s[8:9], 0x0
	s_mov_b32 s8, 0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s9, s9, s3
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[4:5], 2, v[1:2]
	v_add_nc_u32_e32 v1, s9, v1
	v_add_co_u32 v4, vcc_lo, s4, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v5, vcc_lo
	v_cmp_le_i32_e32 vcc_lo, s0, v1
	global_load_b32 v2, v[4:5], off
	s_or_b32 s8, vcc_lo, s8
	s_waitcnt vmcnt(0)
	v_min_i32_e32 v3, v2, v3
	s_and_not1_b32 exec_lo, exec_lo, s8
	s_cbranch_execnz .LBB1_2
; %bb.3:                                ; %Flow40
	s_or_b32 exec_lo, exec_lo, s8
.LBB1_4:                                ; %Flow41
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s1
	v_lshl_add_u32 v1, v0, 2, 0
	s_cmp_lt_u32 s3, 2
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v3
	s_cbranch_scc1 .LBB1_9
.LBB1_5:                                ; %.lr.ph36
                                        ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s0, s3
	s_lshr_b32 s3, s3, 1
	s_mov_b32 s1, exec_lo
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	v_cmpx_gt_u32_e64 s3, v0
	s_cbranch_execz .LBB1_8
; %bb.6:                                ;   in Loop: Header=BB1_5 Depth=1
	v_lshl_add_u32 v2, s3, 2, v1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	s_waitcnt lgkmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, v2, v3
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_8
; %bb.7:                                ;   in Loop: Header=BB1_5 Depth=1
	ds_store_b32 v1, v2
.LBB1_8:                                ;   in Loop: Header=BB1_5 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_cmp_gt_u32 s0, 3
	s_cbranch_scc1 .LBB1_5
.LBB1_9:                                ; %._crit_edge37
	s_mov_b32 s0, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_11
; %bb.10:
	v_mov_b32_e32 v0, 0
	s_mov_b32 s3, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_lshl_b64 s[0:1], s[2:3], 2
	s_add_u32 s0, s6, s0
	ds_load_b32 v1, v0
	s_addc_u32 s1, s7, s1
	s_waitcnt lgkmcnt(0)
	global_store_b32 v0, v1, s[0:1]
.LBB1_11:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9reductionPiS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 6
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z9reductionPiS_i, .Lfunc_end1-_Z9reductionPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 416
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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:
      - .actual_access:  write_only
        .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4initPii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4initPii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .actual_access:  read_only
        .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  write_only
        .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9reductionPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9reductionPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
