#include <iostream>
#include <numeric>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#include <cuda.h>
#include <cuda_runtime.h>
#include <cooperative_groups.h>

/* INT_MAX < LONG_MAX < ULONG_MAX < LLONG_MAX < ULLONG_MAX*/
typedef unsigned vector_t;
typedef unsigned int histogram_t;
typedef int atomic_t;
#define MIL 1000
#define MILLON MIL*MIL
#define N 100*MIL
#define M 8       //Tamaño histograma
#define SIZE_BYTES sizeof(vector_t);
#define R 106     //Repeticiones

static void CheckCudaErrorAux (const char *file, unsigned line, const char *statement, cudaError_t err)
{
	if (err == cudaSuccess)
		return;
	std::cerr << statement<<" returned " << cudaGetErrorString(err) << "("<<err<< ") at "<<file<<":"<<line << std::endl;
	exit (1);
}

static void CheckCudaErrorAux (const char *, unsigned, const char *, cudaError_t);
#define CUDA_CHECK_RETURN(value) CheckCudaErrorAux(__FILE__,__LINE__, #value, value)

__global__ void inicializar_histograma(histogram_t * h, size_t n){
  size_t thread_id = threadIdx.x + blockDim.x * blockIdx.x;
  if(thread_id >= n) return;
  h[thread_id] = 0;
}
__global__ void calcular_histograma(vector_t* v, histogram_t* h, 
    size_t n, size_t m){

  size_t id = threadIdx.x + blockDim.x * blockIdx.x;
  if(id >= n) return;
  atomicAdd(&h[v[id]%m], 1);
}

float tiempo_kernel(histogram_t * h_device, vector_t * v_device, unsigned kernel);

int main(void){
  srand(time(NULL));

  size_t sizeV = N * sizeof(vector_t);
  vector_t * v = (vector_t *)malloc(sizeV);
  for (size_t i = 0; i < N; i++)
    v[i] = rand()%M;
  
  vector_t * v_device;
  CUDA_CHECK_RETURN(cudaMalloc(&v_device, sizeV)); 
  CUDA_CHECK_RETURN(cudaMemcpy(v_device, v, sizeV, cudaMemcpyHostToDevice));

  size_t sizeH = M * sizeof(histogram_t);
  histogram_t * h = (histogram_t *)malloc(sizeH);

  histogram_t * h_device;
  CUDA_CHECK_RETURN(cudaMalloc(&h_device, sizeH)); 

  printf("Llamando kernel con M = %i N = %i y P = %i\n", M, N, 1);

  float totalTime = tiempo_kernel(h_device, v_device, 1); 

  CUDA_CHECK_RETURN(cudaMemcpy(h, h_device, sizeH, cudaMemcpyDeviceToHost));

  printf("Tiempo transcurrido: %f ms\n", totalTime);
  printf("Histograma: ");
  size_t suma = 0;
  for (int i = 0; i < M; i++){
    printf("%u ", h[i]);
    suma += h[i];
  }
  printf("\n");
  printf("Elementos del vector: %i\n", N);
  printf("Suma de elementos : %lu\n", suma);

  free(v);
  free(h);
  CUDA_CHECK_RETURN(cudaFree(v_device));
  CUDA_CHECK_RETURN(cudaFree(h_device));
}

float tiempo_kernel(histogram_t * h_device, vector_t * v_device, unsigned kernel){
  size_t threadsPerBlock = 1024;
  size_t blocksPerGridM = ((unsigned)M + threadsPerBlock - 1) / threadsPerBlock;
  size_t blocksPerGridN = ((unsigned)N + threadsPerBlock - 1) / threadsPerBlock;
  
  cudaEvent_t start,stop;
  cudaEventCreate(&start);
  cudaEventCreate(&stop);
  double totalTime = 0;


  for(int i = 0; i < R; i++){
    cudaEventRecord(start, 0);

    switch(kernel){
      case 1:
        inicializar_histograma<<<blocksPerGridM, threadsPerBlock>>>(h_device, M);
        if(cudaPeekAtLastError() != cudaSuccess) printf("inicializar_histograma<<<%lu, %lu>>> falla.\n", blocksPerGridM, threadsPerBlock);
        calcular_histograma <<<blocksPerGridN, threadsPerBlock>>>(v_device, h_device, N, M);
        if(cudaPeekAtLastError() != cudaSuccess) printf("calcular_histograma<<<%lu, %lu>>> falla.\n", blocksPerGridN, threadsPerBlock);
        break;
      default:
        printf("Cuidado! No se selecciona ningún kernel\n");
        break;
    }

    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);

    float elapsedTime;
    cudaEventElapsedTime(&elapsedTime, start, stop);
    if(i > 5) totalTime += (double)elapsedTime;
  }

  return totalTime / (R-6);
}

	.file	"tmpxft_0033a6ed_00000000-6_main.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB6876:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE6876:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" returned "
.LC1:
	.string	"("
.LC2:
	.string	") at "
.LC3:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/mbdaso/cuda/master/histograma-primera-implementacion/main.cu"
.LC4:
	.string	":"
	.text
	.type	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0, @function
_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0:
.LFB7763:
	.cfi_startproc
	testl	%edx, %edx
	je	.L4
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edx, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edi, %ebx
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC0(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %r12
	call	cudaGetErrorString@PLT
	movq	%r12, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$1, %edi
	call	exit@PLT
.L4:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	.cfi_restore 12
	ret
	.cfi_endproc
.LFE7763:
	.size	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0, .-_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	.globl	_Z43__device_stub__Z22inicializar_histogramaPjmPjm
	.type	_Z43__device_stub__Z22inicializar_histogramaPjmPjm, @function
_Z43__device_stub__Z22inicializar_histogramaPjmPjm:
.LFB6898:
	.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	.L9
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z22inicializar_histogramaPjm(%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
.L9:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6898:
	.size	_Z43__device_stub__Z22inicializar_histogramaPjmPjm, .-_Z43__device_stub__Z22inicializar_histogramaPjmPjm
	.globl	_Z22inicializar_histogramaPjm
	.type	_Z22inicializar_histogramaPjm, @function
_Z22inicializar_histogramaPjm:
.LFB6899:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z22inicializar_histogramaPjmPjm
	.cfi_endproc
.LFE6899:
	.size	_Z22inicializar_histogramaPjm, .-_Z22inicializar_histogramaPjm
	.globl	_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm
	.type	_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm, @function
_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm:
.LFB6900:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, (%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	movq	%rsp, %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z19calcular_histogramaPjS_mm(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L14:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6900:
	.size	_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm, .-_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm
	.globl	_Z19calcular_histogramaPjS_mm
	.type	_Z19calcular_histogramaPjS_mm, @function
_Z19calcular_histogramaPjS_mm:
.LFB6901:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm
	.cfi_endproc
.LFE6901:
	.size	_Z19calcular_histogramaPjS_mm, .-_Z19calcular_histogramaPjS_mm
	.section	.rodata.str1.1
.LC6:
	.string	"inicializar_histograma<<<%lu, %lu>>> falla.\n"
.LC7:
	.string	"calcular_histograma<<<%lu, %lu>>> falla.\n"
.LC8:
	.string	"Cuidado! No se selecciona ning\303\272n kernel\n"
	.text
	.globl	_Z13tiempo_kernelPjS_j
	.type	_Z13tiempo_kernelPjS_j, @function
_Z13tiempo_kernelPjS_j:
.LFB6873:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC8(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	xorl	%ebx, %ebx
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	24(%rsp), %rdi
	call	cudaEventCreate@PLT
	movq	$0x000000000, 8(%rsp)
.L26:
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	cmpl	$1, %r13d
	jne	.L20
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	salq	$10, %rdx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, 52(%rsp)
	movq	%rdx, 44(%rsp)
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	movl	$8, %esi
	movq	%rbp, %rdi
	call	_Z43__device_stub__Z22inicializar_histogramaPjmPjm
.L21:
	call	cudaPeekAtLastError@PLT
	testl	%eax, %eax
	je	.L22
	movl	$1024, %ecx
	movl	$1, %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
.L22:
	movl	$4194305, %edx
	movl	$2147483697, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$10, %rdx
	addq	%rdi, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movq	%rdx, 44(%rsp)
	movl	$1, 52(%rsp)
	movq	%rdi, 32(%rsp)
	movl	$1, 40(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	movl	$8, %ecx
	movl	$100000, %edx
	movq	%rbp, %rsi
	movq	%r12, %rdi
	call	_Z43__device_stub__Z19calcular_histogramaPjS_mmPjS_mm
.L23:
	call	cudaPeekAtLastError@PLT
	testl	%eax, %eax
	je	.L24
	movl	$1024, %ecx
	movl	$98, %edx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L24
.L20:
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L24:
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	24(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rsi
	leaq	44(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	cmpl	$5, %ebx
	jle	.L25
	cvtss2sd	44(%rsp), %xmm0
	addsd	8(%rsp), %xmm0
	movsd	%xmm0, 8(%rsp)
.L25:
	incl	%ebx
	cmpl	$106, %ebx
	jne	.L26
	movsd	8(%rsp), %xmm0
	divsd	.LC9(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6873:
	.size	_Z13tiempo_kernelPjS_j, .-_Z13tiempo_kernelPjS_j
	.section	.rodata.str1.1
.LC10:
	.string	"cudaMalloc(&v_device, sizeV)"
.LC11:
	.string	"cudaMemcpy(v_device, v, sizeV, cudaMemcpyHostToDevice)"
.LC12:
	.string	"cudaMalloc(&h_device, sizeH)"
.LC13:
	.string	"Llamando kernel con M = %i N = %i y P = %i\n"
.LC14:
	.string	"cudaMemcpy(h, h_device, sizeH, cudaMemcpyDeviceToHost)"
.LC15:
	.string	"Tiempo transcurrido: %f ms\n"
.LC16:
	.string	"Histograma: "
.LC17:
	.string	"%u "
.LC18:
	.string	"\n"
.LC19:
	.string	"Elementos del vector: %i\n"
.LC20:
	.string	"Suma de elementos : %lu\n"
.LC21:
	.string	"cudaFree(v_device)"
.LC22:
	.string	"cudaFree(h_device)"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB6872:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%edi, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	$8, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	xorl	%ebx, %ebx
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movl	$400000, %edi
	call	malloc@PLT
	movq	%rax, %rbp
.L37:
	call	rand@PLT
	cltd
	idivl	%r12d
	movl	%edx, 0(%rbp,%rbx,4)
	incq	%rbx
	cmpq	$100000, %rbx
	jne	.L37
	leaq	24(%rsp), %rdi
	movl	$400000, %esi
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
	call	cudaMalloc@PLT
	leaq	.LC10(%rip), %rsi
	movl	$57, %edi
	leaq	.LC17(%rip), %r14
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$400000, %edx
	call	cudaMemcpy@PLT
	leaq	.LC11(%rip), %rsi
	movl	$58, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movl	$32, %edi
	call	malloc@PLT
	leaq	32(%rsp), %rdi
	movl	$32, %esi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	leaq	.LC12(%rip), %rsi
	movl	$64, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movl	$1, %r8d
	xorl	%eax, %eax
	movl	$100000, %ecx
	movl	$8, %edx
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	movl	$1, %edx
	call	_Z13tiempo_kernelPjS_j
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$32, %edx
	movss	%xmm0, 12(%rsp)
	call	cudaMemcpy@PLT
	leaq	.LC14(%rip), %rsi
	movl	$70, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movss	12(%rsp), %xmm0
	leaq	.LC15(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC16(%rip), %rsi
	call	__printf_chk@PLT
.L38:
	movl	(%rbx,%r12,4), %edx
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	(%rbx,%r12,4), %eax
	incq	%r12
	addq	%rax, %r13
	cmpq	$8, %r12
	jne	.L38
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$100000, %edx
	leaq	.LC19(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r13, %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC20(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC21(%rip), %rsi
	movl	$85, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC22(%rip), %rsi
	movl	$86, %edi
	movl	%eax, %edx
	call	_ZL17CheckCudaErrorAuxPKcjS0_9cudaError.constprop.0
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L39
	call	__stack_chk_fail@PLT
.L39:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE6872:
	.size	main, .-main
	.section	.rodata.str1.1
.LC23:
	.string	"_Z19calcular_histogramaPjS_mm"
.LC24:
	.string	"_Z22inicializar_histogramaPjm"
.LC25:
	.string	"_ZN37_INTERNAL_df3990d6_7_main_cu_ac8204b54cuda3std3__419piecewise_constructE"
.LC26:
	.string	"_ZN37_INTERNAL_df3990d6_7_main_cu_ac8204b54cuda3std6ranges3__45__cpo4swapE"
.LC27:
	.string	"_ZN37_INTERNAL_df3990d6_7_main_cu_ac8204b54cuda3std6ranges3__45__cpo9iter_moveE"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB6903:
	.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	.LC23(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z19calcular_histogramaPjS_mm(%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	.LC24(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z22inicializar_histogramaPjm(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC25(%rip), %rdx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__419piecewise_constructE(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC26(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std6ranges3__45__cpo4swapE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC27(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$1, %r9d
	movq	%rdx, %rcx
	leaq	_ZN4cuda3std6ranges3__45__cpo9iter_moveE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r8
	.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
.LFE6903:
	.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
	.weak	_ZN4cuda3std3__419piecewise_constructE
	.section	.rodata._ZN4cuda3std3__419piecewise_constructE,"aG",@progbits,_ZN4cuda3std3__419piecewise_constructE,comdat
	.type	_ZN4cuda3std3__419piecewise_constructE, @gnu_unique_object
	.size	_ZN4cuda3std3__419piecewise_constructE, 1
_ZN4cuda3std3__419piecewise_constructE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo9iter_moveE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo9iter_moveE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo9iter_moveE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo9iter_moveE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo9iter_moveE, 1
_ZN4cuda3std6ranges3__45__cpo9iter_moveE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo4swapE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo4swapE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo4swapE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo4swapE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo4swapE, 1
_ZN4cuda3std6ranges3__45__cpo4swapE:
	.zero	1
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC9:
	.long	0
	.long	1079574528
	.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 <iostream>
#include <numeric>
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

#include <hip/hip_runtime.h>

#include <hip/hip_cooperative_groups.h>

/* INT_MAX < LONG_MAX < ULONG_MAX < LLONG_MAX < ULLONG_MAX*/
typedef unsigned vector_t;
typedef unsigned int histogram_t;
typedef int atomic_t;
#define MIL 1000
#define MILLON MIL*MIL
#define N 100*MIL
#define M 8       //Tamaño histograma
#define SIZE_BYTES sizeof(vector_t);
#define R 106     //Repeticiones

static void CheckCudaErrorAux (const char *file, unsigned line, const char *statement, hipError_t err)
{
	if (err == hipSuccess)
		return;
	std::cerr << statement<<" returned " << hipGetErrorString(err) << "("<<err<< ") at "<<file<<":"<<line << std::endl;
	exit (1);
}

static void CheckCudaErrorAux (const char *, unsigned, const char *, hipError_t);
#define CUDA_CHECK_RETURN(value) CheckCudaErrorAux(__FILE__,__LINE__, #value, value)

__global__ void inicializar_histograma(histogram_t * h, size_t n){
  size_t thread_id = threadIdx.x + blockDim.x * blockIdx.x;
  if(thread_id >= n) return;
  h[thread_id] = 0;
}
__global__ void calcular_histograma(vector_t* v, histogram_t* h, 
    size_t n, size_t m){

  size_t id = threadIdx.x + blockDim.x * blockIdx.x;
  if(id >= n) return;
  atomicAdd(&h[v[id]%m], 1);
}

float tiempo_kernel(histogram_t * h_device, vector_t * v_device, unsigned kernel);

int main(void){
  srand(time(NULL));

  size_t sizeV = N * sizeof(vector_t);
  vector_t * v = (vector_t *)malloc(sizeV);
  for (size_t i = 0; i < N; i++)
    v[i] = rand()%M;
  
  vector_t * v_device;
  CUDA_CHECK_RETURN(hipMalloc(&v_device, sizeV)); 
  CUDA_CHECK_RETURN(hipMemcpy(v_device, v, sizeV, hipMemcpyHostToDevice));

  size_t sizeH = M * sizeof(histogram_t);
  histogram_t * h = (histogram_t *)malloc(sizeH);

  histogram_t * h_device;
  CUDA_CHECK_RETURN(hipMalloc(&h_device, sizeH)); 

  printf("Llamando kernel con M = %i N = %i y P = %i\n", M, N, 1);

  float totalTime = tiempo_kernel(h_device, v_device, 1); 

  CUDA_CHECK_RETURN(hipMemcpy(h, h_device, sizeH, hipMemcpyDeviceToHost));

  printf("Tiempo transcurrido: %f ms\n", totalTime);
  printf("Histograma: ");
  size_t suma = 0;
  for (int i = 0; i < M; i++){
    printf("%u ", h[i]);
    suma += h[i];
  }
  printf("\n");
  printf("Elementos del vector: %i\n", N);
  printf("Suma de elementos : %lu\n", suma);

  free(v);
  free(h);
  CUDA_CHECK_RETURN(hipFree(v_device));
  CUDA_CHECK_RETURN(hipFree(h_device));
}

float tiempo_kernel(histogram_t * h_device, vector_t * v_device, unsigned kernel){
  size_t threadsPerBlock = 1024;
  size_t blocksPerGridM = ((unsigned)M + threadsPerBlock - 1) / threadsPerBlock;
  size_t blocksPerGridN = ((unsigned)N + threadsPerBlock - 1) / threadsPerBlock;
  
  hipEvent_t start,stop;
  hipEventCreate(&start);
  hipEventCreate(&stop);
  double totalTime = 0;


  for(int i = 0; i < R; i++){
    hipEventRecord(start, 0);

    switch(kernel){
      case 1:
        inicializar_histograma<<<blocksPerGridM, threadsPerBlock>>>(h_device, M);
        if(hipPeekAtLastError() != hipSuccess) printf("inicializar_histograma<<<%lu, %lu>>> falla.\n", blocksPerGridM, threadsPerBlock);
        calcular_histograma <<<blocksPerGridN, threadsPerBlock>>>(v_device, h_device, N, M);
        if(hipPeekAtLastError() != hipSuccess) printf("calcular_histograma<<<%lu, %lu>>> falla.\n", blocksPerGridN, threadsPerBlock);
        break;
      default:
        printf("Cuidado! No se selecciona ningún kernel\n");
        break;
    }

    hipEventRecord(stop, 0);
    hipEventSynchronize(stop);

    float elapsedTime;
    hipEventElapsedTime(&elapsedTime, start, stop);
    if(i > 5) totalTime += (double)elapsedTime;
  }

  return totalTime / (R-6);
}

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

                                        # End of file scope inline assembly
	.globl	_Z37__device_stub__inicializar_histogramaPjm # -- Begin function _Z37__device_stub__inicializar_histogramaPjm
	.type	_Z37__device_stub__inicializar_histogramaPjm,@function
_Z37__device_stub__inicializar_histogramaPjm: # @_Z37__device_stub__inicializar_histogramaPjm
	.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	$_Z22inicializar_histogramaPjm, %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	_Z37__device_stub__inicializar_histogramaPjm, .Lfunc_end0-_Z37__device_stub__inicializar_histogramaPjm
	.cfi_endproc
                                        # -- End function
	.globl	_Z34__device_stub__calcular_histogramaPjS_mm # -- Begin function _Z34__device_stub__calcular_histogramaPjS_mm
	.type	_Z34__device_stub__calcular_histogramaPjS_mm,@function
_Z34__device_stub__calcular_histogramaPjS_mm: # @_Z34__device_stub__calcular_histogramaPjS_mm
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	16(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z19calcular_histogramaPjS_mm, %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_end1:
	.size	_Z34__device_stub__calcular_histogramaPjS_mm, .Lfunc_end1-_Z34__device_stub__calcular_histogramaPjS_mm
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	xorl	%r14d, %r14d
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	$400000, %edi                   # imm = 0x61A80
	callq	malloc
	movq	%rax, %rbx
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
                                        # kill: def $eax killed $eax def $rax
	leal	7(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	andl	$-8, %ecx
	subl	%ecx, %eax
	movl	%eax, (%rbx,%r14,4)
	incq	%r14
	cmpq	$100000, %r14                   # imm = 0x186A0
	jne	.LBB2_1
# %bb.2:
	leaq	16(%rsp), %r15
	movl	$400000, %esi                   # imm = 0x61A80
	movq	%r15, %rdi
	callq	hipMalloc
	movl	$.L.str.1, %esi
	movl	$57, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movq	(%r15), %rdi
	movl	$400000, %edx                   # imm = 0x61A80
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.2, %esi
	movl	$58, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movl	$32, %edi
	callq	malloc
	movq	%rax, %r14
	leaq	8(%rsp), %r12
	movl	$32, %esi
	movq	%r12, %rdi
	callq	hipMalloc
	movl	$.L.str.3, %esi
	movl	$64, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movl	$.L.str.4, %edi
	movl	$8, %esi
	movl	$100000, %edx                   # imm = 0x186A0
	movl	$1, %ecx
	xorl	%eax, %eax
	callq	printf
	movq	(%r12), %rdi
	movq	(%r15), %rsi
	movl	$1, %edx
	callq	_Z13tiempo_kernelPjS_j
	movss	%xmm0, 4(%rsp)                  # 4-byte Spill
	movq	(%r12), %rsi
	movl	$32, %edx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.5, %esi
	movl	$70, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%rsp), %xmm0                  # 4-byte Folded Reload
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%r12d, %r12d
	xorl	%r15d, %r15d
.LBB2_3:                                # =>This Inner Loop Header: Depth=1
	movl	(%r14,%r12,4), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	(%r14,%r12,4), %eax
	addq	%rax, %r15
	incq	%r12
	cmpq	$8, %r12
	jne	.LBB2_3
# %bb.4:
	movl	$10, %edi
	callq	putchar@PLT
	movl	$.L.str.10, %edi
	movl	$100000, %esi                   # imm = 0x186A0
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.11, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.12, %esi
	movl	$85, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	$.L.str.13, %esi
	movl	$86, %edi
	movl	%eax, %edx
	callq	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.type	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t,@function # -- Begin function _ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t: # @_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jne	.LBB3_2
# %bb.1:
	retq
.LBB3_2:
	pushq	%rbp
	.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 %rbp, -16
	movl	%edx, %ebp
	movl	%edi, %ebx
	movl	$_ZSt4cerr, %edi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.17, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.18, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%ebp, %esi
	callq	_ZNSolsEi
	movl	$.L.str.19, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.20, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	%ebx, %esi
	callq	_ZNSolsEj
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t, .Lfunc_end3-_ZL17CheckCudaErrorAuxPKcjS0_10hipError_t
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13tiempo_kernelPjS_j
.LCPI4_0:
	.quad	0x8000000000000000              # double -0
.LCPI4_1:
	.quad	0x4059000000000000              # double 100
	.text
	.globl	_Z13tiempo_kernelPjS_j
	.type	_Z13tiempo_kernelPjS_j,@function
_Z13tiempo_kernelPjS_j:                 # @_Z13tiempo_kernelPjS_j
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movq	%rsi, 40(%rsp)                  # 8-byte Spill
	movq	%rdi, 24(%rsp)                  # 8-byte Spill
	movabsq	$4294968320, %r12               # imm = 0x100000400
	leaq	32(%rsp), %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	xorpd	%xmm0, %xmm0
	leaq	-1023(%r12), %r13
	leaq	-926(%r12), %rbp
	leaq	20(%rsp), %r14
	xorl	%r15d, %r15d
.LBB4_1:                                # =>This Inner Loop Header: Depth=1
	movsd	%xmm0, 48(%rsp)                 # 8-byte Spill
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	cmpl	$1, %ebx
	jne	.LBB4_10
# %bb.2:                                #   in Loop: Header=BB4_1 Depth=1
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$8, %esi
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	_Z37__device_stub__inicializar_histogramaPjm
.LBB4_4:                                #   in Loop: Header=BB4_1 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	je	.LBB4_6
# %bb.5:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$.L.str.14, %edi
	movl	$1, %esi
	movl	$1024, %edx                     # imm = 0x400
	xorl	%eax, %eax
	callq	printf
.LBB4_6:                                #   in Loop: Header=BB4_1 Depth=1
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_8
# %bb.7:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$100000, %edx                   # imm = 0x186A0
	movl	$8, %ecx
	movq	40(%rsp), %rdi                  # 8-byte Reload
	movq	24(%rsp), %rsi                  # 8-byte Reload
	callq	_Z34__device_stub__calcular_histogramaPjS_mm
.LBB4_8:                                #   in Loop: Header=BB4_1 Depth=1
	callq	hipPeekAtLastError
	testl	%eax, %eax
	je	.LBB4_11
# %bb.9:                                #   in Loop: Header=BB4_1 Depth=1
	movl	$.L.str.15, %edi
	movl	$98, %esi
	movl	$1024, %edx                     # imm = 0x400
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB4_11
.LBB4_10:                               #   in Loop: Header=BB4_1 Depth=1
	movl	$.Lstr, %edi
	callq	puts@PLT
.LBB4_11:                               #   in Loop: Header=BB4_1 Depth=1
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	32(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	%r14, %rdi
	callq	hipEventElapsedTime
	cmpl	$6, %r15d
	jae	.LBB4_12
# %bb.13:                               #   in Loop: Header=BB4_1 Depth=1
	movsd	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero
	jmp	.LBB4_14
.LBB4_12:                               #   in Loop: Header=BB4_1 Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	20(%rsp), %xmm0
.LBB4_14:                               #   in Loop: Header=BB4_1 Depth=1
	movsd	48(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	addsd	%xmm0, %xmm1
	movapd	%xmm1, %xmm0
	incl	%r15d
	cmpl	$106, %r15d
	jne	.LBB4_1
# %bb.15:
	divsd	.LCPI4_1(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z13tiempo_kernelPjS_j, .Lfunc_end4-_Z13tiempo_kernelPjS_j
	.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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z22inicializar_histogramaPjm, %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	$_Z19calcular_histogramaPjS_mm, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z22inicializar_histogramaPjm,@object # @_Z22inicializar_histogramaPjm
	.section	.rodata,"a",@progbits
	.globl	_Z22inicializar_histogramaPjm
	.p2align	3, 0x0
_Z22inicializar_histogramaPjm:
	.quad	_Z37__device_stub__inicializar_histogramaPjm
	.size	_Z22inicializar_histogramaPjm, 8

	.type	_Z19calcular_histogramaPjS_mm,@object # @_Z19calcular_histogramaPjS_mm
	.globl	_Z19calcular_histogramaPjS_mm
	.p2align	3, 0x0
_Z19calcular_histogramaPjS_mm:
	.quad	_Z34__device_stub__calcular_histogramaPjS_mm
	.size	_Z19calcular_histogramaPjS_mm, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/mbdaso/cuda/master/histograma-primera-implementacion/main.hip"
	.size	.L.str, 124

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"hipMalloc(&v_device, sizeV)"
	.size	.L.str.1, 28

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"hipMemcpy(v_device, v, sizeV, hipMemcpyHostToDevice)"
	.size	.L.str.2, 53

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"hipMalloc(&h_device, sizeH)"
	.size	.L.str.3, 28

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Llamando kernel con M = %i N = %i y P = %i\n"
	.size	.L.str.4, 44

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"hipMemcpy(h, h_device, sizeH, hipMemcpyDeviceToHost)"
	.size	.L.str.5, 53

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Tiempo transcurrido: %f ms\n"
	.size	.L.str.6, 28

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Histograma: "
	.size	.L.str.7, 13

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%u "
	.size	.L.str.8, 4

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Elementos del vector: %i\n"
	.size	.L.str.10, 26

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Suma de elementos : %lu\n"
	.size	.L.str.11, 25

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"hipFree(v_device)"
	.size	.L.str.12, 18

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"hipFree(h_device)"
	.size	.L.str.13, 18

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"inicializar_histograma<<<%lu, %lu>>> falla.\n"
	.size	.L.str.14, 45

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"calcular_histograma<<<%lu, %lu>>> falla.\n"
	.size	.L.str.15, 42

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	" returned "
	.size	.L.str.17, 11

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"("
	.size	.L.str.18, 2

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	") at "
	.size	.L.str.19, 6

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	":"
	.size	.L.str.20, 2

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z22inicializar_histogramaPjm"
	.size	.L__unnamed_1, 30

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z19calcular_histogramaPjS_mm"
	.size	.L__unnamed_2, 30

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Cuidado! No se selecciona ning\303\272n kernel"
	.size	.Lstr, 41

	.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 _Z37__device_stub__inicializar_histogramaPjm
	.addrsig_sym _Z34__device_stub__calcular_histogramaPjS_mm
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z22inicializar_histogramaPjm
	.addrsig_sym _Z19calcular_histogramaPjS_mm
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z22inicializar_histogramaPjm ; -- Begin function _Z22inicializar_histogramaPjm
	.globl	_Z22inicializar_histogramaPjm
	.p2align	8
	.type	_Z22inicializar_histogramaPjm,@function
_Z22inicializar_histogramaPjm:          ; @_Z22inicializar_histogramaPjm
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mov_b32_e32 v2, 0
	v_cmp_gt_u64_e32 vcc_lo, s[2:3], v[1:2]
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v2, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22inicializar_histogramaPjm
		.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 3
		.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	_Z22inicializar_histogramaPjm, .Lfunc_end0-_Z22inicializar_histogramaPjm
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 104
; NumSgprs: 18
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 3
; 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	_Z19calcular_histogramaPjS_mm ; -- Begin function _Z19calcular_histogramaPjS_mm
	.globl	_Z19calcular_histogramaPjS_mm
	.p2align	8
	.type	_Z19calcular_histogramaPjS_mm,@function
_Z19calcular_histogramaPjS_mm:          ; @_Z19calcular_histogramaPjS_mm
; %bb.0:
	s_clause 0x1
	s_load_b32 s8, s[0:1], 0x2c
	s_load_b256 s[0:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s8, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s8, v[0:1]
	v_mov_b32_e32 v2, 0
	v_cmp_gt_u64_e32 vcc_lo, s[4:5], v[1:2]
	s_and_saveexec_b32 s4, vcc_lo
	s_cbranch_execz .LBB1_2
; %bb.1:
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_sub_u32 s0, 0, s6
	s_subb_u32 s1, 0, s7
	global_load_b32 v4, v[0:1], off
	v_cvt_f32_u32_e32 v0, s6
	v_cvt_f32_u32_e32 v1, s7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmamk_f32 v0, v1, 0x4f800000, v0
	v_rcp_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x5f7ffffc, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v1, 0x2f800000, v0
	v_trunc_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmamk_f32 v0, v1, 0xcf800000, v0
	v_cvt_u32_f32_e32 v1, v1
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v2, s0, v1
	v_mul_hi_u32 v3, s0, v0
	v_mul_lo_u32 v5, s1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, v3, v2
	v_mul_lo_u32 v3, s0, v0
	v_add_nc_u32_e32 v2, v2, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v5, v0, v3
	v_mul_lo_u32 v6, v0, v2
	v_mul_hi_u32 v7, v0, v2
	v_mul_hi_u32 v8, v1, v3
	v_mul_lo_u32 v3, v1, v3
	v_mul_hi_u32 v9, v1, v2
	v_mul_lo_u32 v2, v1, v2
	v_add_co_u32 v5, vcc_lo, v5, v6
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, v5, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, v6, v8, vcc_lo
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v3, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, v0, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v2, s0, v0
	v_mul_lo_u32 v5, s1, v0
	v_mul_lo_u32 v3, s0, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, v2, v3
	v_mul_lo_u32 v3, s0, v0
	v_add_nc_u32_e32 v2, v2, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v5, v0, v3
	v_mul_lo_u32 v6, v0, v2
	v_mul_hi_u32 v7, v0, v2
	v_mul_hi_u32 v8, v1, v3
	v_mul_lo_u32 v3, v1, v3
	v_mul_hi_u32 v9, v1, v2
	v_mul_lo_u32 v2, v1, v2
	v_add_co_u32 v5, vcc_lo, v5, v6
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, v5, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, v6, v8, vcc_lo
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v3, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v5, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v0, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, v1, v3, vcc_lo
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mad_u64_u32 v[0:1], null, v4, v3, 0
	v_mul_hi_u32 v2, v4, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, v2, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v1, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[0:1], null, s6, v5, 0
	v_mad_u64_u32 v[2:3], null, s7, v5, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_co_u32 v0, vcc_lo, v4, v0
	v_sub_nc_u32_e32 v1, 0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_subrev_co_ci_u32_e64 v1, s0, s7, v1, vcc_lo
	v_sub_co_ci_u32_e32 v2, vcc_lo, 0, v2, vcc_lo
	v_sub_co_u32 v3, vcc_lo, v0, s6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_subrev_co_ci_u32_e64 v4, s0, 0, v1, vcc_lo
	v_cmp_le_u32_e64 s0, s6, v0
	v_subrev_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s7, v2
	v_cndmask_b32_e64 v5, 0, -1, s0
	v_cmp_le_u32_e64 s0, s6, v3
	v_cndmask_b32_e64 v8, 0, -1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, s7, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v6, 0, -1, s0
	v_cmp_le_u32_e64 s0, s7, v4
	v_cndmask_b32_e64 v7, 0, -1, s0
	v_cmp_eq_u32_e64 s0, s7, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v6, v7, v6, vcc_lo
	v_sub_co_u32 v7, vcc_lo, v3, s6
	v_subrev_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, 0, v6
	v_cndmask_b32_e64 v5, v8, v5, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v1, v4, v1, vcc_lo
	v_cndmask_b32_e32 v3, v3, v7, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, 0, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_cndmask_b32 v1, v2, v1 :: v_dual_cndmask_b32 v0, v0, v3
	v_mov_b32_e32 v2, 1
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_atomic_add_u32 v[0:1], v2, off
.LBB1_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19calcular_histogramaPjS_mm
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 10
		.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	_Z19calcular_histogramaPjS_mm, .Lfunc_end1-_Z19calcular_histogramaPjS_mm
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 816
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           8
        .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:           _Z22inicializar_histogramaPjm
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z22inicializar_histogramaPjm.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           8
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19calcular_histogramaPjS_mm
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19calcular_histogramaPjS_mm.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
