/* Histogram generation on the GPU. 
 * Host-side code.
	
 * Author: Naga Kandasamy
 * Date modified: May 17, 2020
*/

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#include <math.h>
#include <float.h>

#define THREAD_BLOCK_SIZE 256 
#define NUM_BLOCKS 40 
#define HISTOGRAM_SIZE 256 /* Histogram has 256 bins */

#include "histogram_kernel.cu"

void run_test(int);
void compute_on_device(int *, int *, int, int);
void check_for_error(const char *);
extern "C" void compute_gold(int *, int *, int, int);
void check_histogram(int *, int, int);
void print_histogram(int *, int , int);

int main(int argc, char **argv) 
{
	if (argc < 2) {
		printf("Usage: %s num-elements\n", argv[0]);
		exit(EXIT_SUCCESS);	
	}

	int num_elements = atoi(argv[1]);
	run_test(num_elements);
	
    exit(EXIT_SUCCESS);
}

void run_test(int num_elements) 
{
	float diff;
	int i; 

    /* Allocate and initialize space to store histograms generated by the CPU and the GPU */
	int *histogram_on_cpu = (int *)malloc(sizeof(int) * HISTOGRAM_SIZE); 
    memset(histogram_on_cpu, 0, sizeof(int) * HISTOGRAM_SIZE);    
    
    int *histogram_on_gpu = (int *)malloc(sizeof(int) * HISTOGRAM_SIZE); 
    memset(histogram_on_gpu, 0, sizeof(int) * HISTOGRAM_SIZE);    

	/* Generate input data to be integer values between 0 and (HISTOGRAM_SIZE - 1) */
    printf("\nGenerating input data\n");
	int size = sizeof(int) * num_elements;
	int *input_data = (int *)malloc (size);
    for(i = 0; i < num_elements; i++)
        input_data[i] = floorf((HISTOGRAM_SIZE - 1) * (rand()/(float)RAND_MAX));

	printf("\nGenerating histrgram on CPU\n");
    struct timeval start, stop;	
	gettimeofday(&start, NULL);

	compute_gold(input_data, histogram_on_cpu, num_elements, HISTOGRAM_SIZE);

    gettimeofday(&stop, NULL);
	printf("Eexcution time = %f\n",stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000);

	check_histogram(histogram_on_cpu, num_elements, HISTOGRAM_SIZE);
    
    printf("\nGenerating histrgram on device\n");
	compute_on_device(input_data, histogram_on_gpu, num_elements, HISTOGRAM_SIZE);
	check_histogram(histogram_on_gpu, num_elements, HISTOGRAM_SIZE);

	/* Compute the differences between the CPU and GPU results. */
	diff = 0.0;
    for(i = 0; i < HISTOGRAM_SIZE; i++)
		diff += abs(histogram_on_cpu[i] - histogram_on_gpu[i]);

	printf("Difference between CPU and device results = %f\n", diff);
   
	/* cleanup memory. */
	free((void *)input_data);
	free((void *)histogram_on_cpu);
	free((void *)histogram_on_gpu);

	exit(EXIT_SUCCESS);
}

void compute_on_device(int *input_data, int *histogram, int num_elements, int histogram_size)
{
    int *input_data_on_device = NULL;
	int *histogram_on_device = NULL;

	/* Allocate space on GPU for input data */
	cudaMalloc((void**)&input_data_on_device, num_elements * sizeof(int));
	cudaMemcpy(input_data_on_device, input_data, num_elements * sizeof(int), cudaMemcpyHostToDevice);

	/* Allocate space on GPU for histogram and initialize contents to zero */
	cudaMalloc((void**)&histogram_on_device, histogram_size * sizeof(int));
	cudaMemset(histogram_on_device, 0, histogram_size * sizeof(int));

 	/* Set up the execution grid on GPU */
	dim3 thread_block(THREAD_BLOCK_SIZE, 1, 1);
	dim3 grid(NUM_BLOCKS,1);
	
    struct timeval start, stop;	
	gettimeofday(&start, NULL);
    
    printf("Using global memory to generate histrogram\n");    
	histogram_kernel_slow<<<grid, thread_block>>>(input_data_on_device, histogram_on_device, num_elements, histogram_size); 
    cudaDeviceSynchronize();
    gettimeofday(&stop, NULL);
	printf("Execution time = %f \n",stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000);
	check_for_error("KERNEL FAILURE");

	printf("Using shared memory to generate histogram\n");
    gettimeofday(&start, NULL);
    cudaMemset(histogram_on_device, 0, histogram_size * sizeof(int)); /* Reset histogram */
    histogram_kernel_fast<<<grid, thread_block>>>(input_data_on_device, histogram_on_device, num_elements, histogram_size); 
	cudaDeviceSynchronize();
    gettimeofday(&stop, NULL);
	printf("Eexecution time = %f\n",stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000);
	check_for_error("KERNEL FAILURE");

	/* Copy result back from GPU */ 
	cudaMemcpy(histogram, histogram_on_device, histogram_size * sizeof(int), cudaMemcpyDeviceToHost);
	print_histogram(histogram, histogram_size, num_elements);
	/* Free memory */
	cudaFree(input_data_on_device);
	cudaFree(histogram_on_device);
}

/* Check correctness of result: sum of histogram bins must equal number of input elements */
void check_histogram(int *histogram, int num_elements, int histogram_size)
{
	int sum = 0;
    int i;
	for (i = 0; i < histogram_size; i++)
		sum += histogram[i];

	printf("Number of histogram entries = %d. \n", sum);
	if (sum == num_elements)
		printf("Histogram generated successfully. \n");
	else
		printf("Error generating histogram. \n");
	
    printf("\n");
}


/* Check for errors during kernel execution */
void check_for_error(const char *msg)
{
	cudaError_t err = cudaGetLastError();
	if (cudaSuccess != err) {
		printf("CUDA ERROR: %s (%s)\n", msg, cudaGetErrorString(err));
		exit(EXIT_FAILURE);
	}
} 

	.file	"tmpxft_0032168d_00000000-6_histogram.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Number of histogram entries = %d. \n"
.LC1:
	.string	"Histogram generated successfully. \n"
.LC2:
	.string	"Error generating histogram. \n"
.LC3:
	.string	"\n"
	.text
	.globl	_Z15check_histogramPiii
	.type	_Z15check_histogramPiii, @function
_Z15check_histogramPiii:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %ebp
	xorl	%eax, %eax
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 32
.L3:
	cmpl	%eax, %edx
	jle	.L10
	addl	(%rdi,%rax,4), %ebx
	incq	%rax
	jmp	.L3
.L10:
	leaq	.LC0(%rip), %rsi
	movl	%ebx, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rsi
	cmpl	%ebp, %ebx
	je	.L8
	leaq	.LC2(%rip), %rsi
.L8:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 24
	leaq	.LC3(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z15check_histogramPiii, .-_Z15check_histogramPiii
	.section	.rodata.str1.1
.LC4:
	.string	"CUDA ERROR: %s (%s)\n"
	.text
	.globl	_Z15check_for_errorPKc
	.type	_Z15check_for_errorPKc, @function
_Z15check_for_errorPKc:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L11
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	movq	%rbx, %rdx
	leaq	.LC4(%rip), %rsi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L11:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z15check_for_errorPKc, .-_Z15check_for_errorPKc
	.globl	_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii
	.type	_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii, @function
_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii:
.LFB2056:
	.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
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%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	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%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	_Z21histogram_kernel_fastPiS_ii(%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
.LFE2056:
	.size	_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii, .-_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii
	.globl	_Z21histogram_kernel_fastPiS_ii
	.type	_Z21histogram_kernel_fastPiS_ii, @function
_Z21histogram_kernel_fastPiS_ii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii
	.cfi_endproc
.LFE2057:
	.size	_Z21histogram_kernel_fastPiS_ii, .-_Z21histogram_kernel_fastPiS_ii
	.globl	_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii
	.type	_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii, @function
_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii:
.LFB2058:
	.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
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%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	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%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	.L19
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z21histogram_kernel_slowPiS_ii(%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
.L19:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii, .-_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii
	.globl	_Z21histogram_kernel_slowPiS_ii
	.type	_Z21histogram_kernel_slowPiS_ii, @function
_Z21histogram_kernel_slowPiS_ii:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii
	.cfi_endproc
.LFE2059:
	.size	_Z21histogram_kernel_slowPiS_ii, .-_Z21histogram_kernel_slowPiS_ii
	.section	.rodata.str1.1
.LC5:
	.string	"Using global memory to generate histrogram\n"
.LC7:
	.string	"Execution time = %f \n"
.LC8:
	.string	"KERNEL FAILURE"
.LC9:
	.string	"Using shared memory to generate histogram\n"
.LC10:
	.string	"Eexecution time = %f\n"
	.text
	.globl	_Z17compute_on_devicePiS_ii
	.type	_Z17compute_on_devicePiS_ii, @function
_Z17compute_on_devicePiS_ii:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r13, %rbp
	salq	$2, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r13, %rsi
	movl	%ecx, %ebx
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	xorl	%eax, %eax
	leaq	56(%rsp), %r15
	movq	%rax, 16(%rsp)
	movq	%rax, 24(%rsp)
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movslq	%ebx, %rax
	leaq	24(%rsp), %rdi
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdx
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	$16777217, %eax
	xorl	%esi, %esi
	movq	%r15, %rdi
	salq	$8, %rax
	movl	$1, 40(%rsp)
	movq	%rax, 32(%rsp)
	subq	$216, %rax
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	gettimeofday@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	40(%rsp), %ecx
	movl	52(%rsp), %esi
	xorl	%r9d, %r9d
	movq	32(%rsp), %rdx
	movq	44(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebx, %ecx
	movl	%ebp, %edx
	call	_Z45__device_stub__Z21histogram_kernel_slowPiS_iiPiS_ii
.L25:
	leaq	72(%rsp), %r14
	leaq	.LC8(%rip), %r13
	call	cudaDeviceSynchronize@PLT
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	gettimeofday@PLT
	movq	80(%rsp), %rax
	subq	64(%rsp), %rax
	leaq	.LC7(%rip), %rsi
	cvtsi2ssq	%rax, %xmm0
	movq	72(%rsp), %rax
	subq	56(%rsp), %rax
	divss	.LC6(%rip), %xmm0
	cvtsi2ssq	%rax, %xmm1
	movl	$2, %edi
	movb	$1, %al
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	_Z15check_for_errorPKc
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%esi, %esi
	movq	%r15, %rdi
	call	gettimeofday@PLT
	movq	8(%rsp), %rdx
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	40(%rsp), %ecx
	movl	52(%rsp), %esi
	xorl	%r9d, %r9d
	movq	32(%rsp), %rdx
	movq	44(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	%ebx, %ecx
	movl	%ebp, %edx
	call	_Z45__device_stub__Z21histogram_kernel_fastPiS_iiPiS_ii
.L26:
	call	cudaDeviceSynchronize@PLT
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	gettimeofday@PLT
	movq	80(%rsp), %rax
	subq	64(%rsp), %rax
	leaq	.LC10(%rip), %rsi
	cvtsi2ssq	%rax, %xmm0
	movq	72(%rsp), %rax
	subq	56(%rsp), %rax
	divss	.LC6(%rip), %xmm0
	cvtsi2ssq	%rax, %xmm1
	movl	$2, %edi
	movb	$1, %al
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	_Z15check_for_errorPKc
	movq	8(%rsp), %rdx
	movq	24(%rsp), %rsi
	movq	%r12, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	%ebp, %edx
	movl	%ebx, %esi
	movq	%r12, %rdi
	call	_Z15print_histogramPiii@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$104, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z17compute_on_devicePiS_ii, .-_Z17compute_on_devicePiS_ii
	.section	.rodata.str1.1
.LC12:
	.string	"\nGenerating input data\n"
.LC15:
	.string	"\nGenerating histrgram on CPU\n"
.LC16:
	.string	"Eexcution time = %f\n"
.LC17:
	.string	"\nGenerating histrgram on device\n"
.LC18:
	.string	"Difference between CPU and device results = %f\n"
	.text
	.globl	_Z8run_testi
	.type	_Z8run_testi, @function
_Z8run_testi:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edi, %r12d
	movl	$1024, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$256, %ecx
	movq	%rax, %rdi
	movq	%rax, %rbp
	movl	%r13d, %eax
	rep stosl
	movl	$1024, %edi
	call	malloc@PLT
	movl	$256, %ecx
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	movq	%rax, %rbx
	movl	%r13d, %eax
	rep stosl
	movl	$2, %edi
	call	__printf_chk@PLT
	leal	0(,%r12,4), %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movq	%rax, %r13
.L30:
	cmpl	%r14d, %r12d
	jle	.L36
	call	rand@PLT
	cvtsi2ssl	%eax, %xmm0
	mulss	.LC13(%rip), %xmm0
	mulss	.LC14(%rip), %xmm0
	call	floorf@PLT
	cvttss2sil	%xmm0, %eax
	movl	%eax, 0(%r13,%r14,4)
	incq	%r14
	jmp	.L30
.L36:
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movl	$256, %ecx
	movl	%r12d, %edx
	movq	%rbp, %rsi
	movq	%r13, %rdi
	call	compute_gold@PLT
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	call	gettimeofday@PLT
	movq	32(%rsp), %rax
	subq	16(%rsp), %rax
	leaq	.LC16(%rip), %rsi
	cvtsi2ssq	%rax, %xmm0
	movq	24(%rsp), %rax
	subq	8(%rsp), %rax
	divss	.LC6(%rip), %xmm0
	cvtsi2ssq	%rax, %xmm1
	movl	$2, %edi
	movb	$1, %al
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	%r12d, %esi
	movq	%rbp, %rdi
	movl	$256, %edx
	call	_Z15check_histogramPiii
	leaq	.LC17(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$256, %ecx
	movl	%r12d, %edx
	movq	%rbx, %rsi
	movq	%r13, %rdi
	call	_Z17compute_on_devicePiS_ii
	movl	$256, %edx
	movl	%r12d, %esi
	movq	%rbx, %rdi
	call	_Z15check_histogramPiii
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L32:
	movl	0(%rbp,%rax), %edx
	subl	(%rbx,%rax), %edx
	movl	%edx, %ecx
	negl	%ecx
	cmovns	%ecx, %edx
	addq	$4, %rax
	cvtsi2ssl	%edx, %xmm1
	addss	%xmm1, %xmm0
	cmpq	$1024, %rax
	jne	.L32
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z8run_testi, .-_Z8run_testi
	.section	.rodata.str1.1
.LC19:
	.string	"Usage: %s num-elements\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	decl	%edi
	pushq	%rax
	.cfi_def_cfa_offset 16
	jg	.L38
	movq	(%rsi), %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC19(%rip), %rsi
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
.L38:
	movq	8(%rsi), %rdi
	call	atoi@PLT
	movl	%eax, %edi
	call	_Z8run_testi
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC20:
	.string	"_Z21histogram_kernel_slowPiS_ii"
.LC21:
	.string	"_Z21histogram_kernel_fastPiS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2061:
	.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	.LC20(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z21histogram_kernel_slowPiS_ii(%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	.LC21(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z21histogram_kernel_fastPiS_ii(%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
.LFE2061:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC6:
	.long	1232348160
	.align 4
.LC13:
	.long	805306368
	.align 4
.LC14:
	.long	1132396544
	.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:

/* Histogram generation on the GPU. 
 * Host-side code.
	
 * Author: Naga Kandasamy
 * Date modified: May 17, 2020
*/


#include <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#include <math.h>
#include <float.h>

#define THREAD_BLOCK_SIZE 256 
#define NUM_BLOCKS 40 
#define HISTOGRAM_SIZE 256 /* Histogram has 256 bins */

#include "histogram_kernel.cu"

void run_test(int);
void compute_on_device(int *, int *, int, int);
void check_for_error(const char *);
extern "C" void compute_gold(int *, int *, int, int);
void check_histogram(int *, int, int);
void print_histogram(int *, int , int);

int main(int argc, char **argv) 
{
	if (argc < 2) {
		printf("Usage: %s num-elements\n", argv[0]);
		exit(EXIT_SUCCESS);	
	}

	int num_elements = atoi(argv[1]);
	run_test(num_elements);
	
    exit(EXIT_SUCCESS);
}

void run_test(int num_elements) 
{
	float diff;
	int i; 

    /* Allocate and initialize space to store histograms generated by the CPU and the GPU */
	int *histogram_on_cpu = (int *)malloc(sizeof(int) * HISTOGRAM_SIZE); 
    memset(histogram_on_cpu, 0, sizeof(int) * HISTOGRAM_SIZE);    
    
    int *histogram_on_gpu = (int *)malloc(sizeof(int) * HISTOGRAM_SIZE); 
    memset(histogram_on_gpu, 0, sizeof(int) * HISTOGRAM_SIZE);    

	/* Generate input data to be integer values between 0 and (HISTOGRAM_SIZE - 1) */
    printf("\nGenerating input data\n");
	int size = sizeof(int) * num_elements;
	int *input_data = (int *)malloc (size);
    for(i = 0; i < num_elements; i++)
        input_data[i] = floorf((HISTOGRAM_SIZE - 1) * (rand()/(float)RAND_MAX));

	printf("\nGenerating histrgram on CPU\n");
    struct timeval start, stop;	
	gettimeofday(&start, NULL);

	compute_gold(input_data, histogram_on_cpu, num_elements, HISTOGRAM_SIZE);

    gettimeofday(&stop, NULL);
	printf("Eexcution time = %f\n",stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000);

	check_histogram(histogram_on_cpu, num_elements, HISTOGRAM_SIZE);
    
    printf("\nGenerating histrgram on device\n");
	compute_on_device(input_data, histogram_on_gpu, num_elements, HISTOGRAM_SIZE);
	check_histogram(histogram_on_gpu, num_elements, HISTOGRAM_SIZE);

	/* Compute the differences between the CPU and GPU results. */
	diff = 0.0;
    for(i = 0; i < HISTOGRAM_SIZE; i++)
		diff += abs(histogram_on_cpu[i] - histogram_on_gpu[i]);

	printf("Difference between CPU and device results = %f\n", diff);
   
	/* cleanup memory. */
	free((void *)input_data);
	free((void *)histogram_on_cpu);
	free((void *)histogram_on_gpu);

	exit(EXIT_SUCCESS);
}

void compute_on_device(int *input_data, int *histogram, int num_elements, int histogram_size)
{
    int *input_data_on_device = NULL;
	int *histogram_on_device = NULL;

	/* Allocate space on GPU for input data */
	hipMalloc((void**)&input_data_on_device, num_elements * sizeof(int));
	hipMemcpy(input_data_on_device, input_data, num_elements * sizeof(int), hipMemcpyHostToDevice);

	/* Allocate space on GPU for histogram and initialize contents to zero */
	hipMalloc((void**)&histogram_on_device, histogram_size * sizeof(int));
	hipMemset(histogram_on_device, 0, histogram_size * sizeof(int));

 	/* Set up the execution grid on GPU */
	dim3 thread_block(THREAD_BLOCK_SIZE, 1, 1);
	dim3 grid(NUM_BLOCKS,1);
	
    struct timeval start, stop;	
	gettimeofday(&start, NULL);
    
    printf("Using global memory to generate histrogram\n");    
	histogram_kernel_slow<<<grid, thread_block>>>(input_data_on_device, histogram_on_device, num_elements, histogram_size); 
    hipDeviceSynchronize();
    gettimeofday(&stop, NULL);
	printf("Execution time = %f \n",stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000);
	check_for_error("KERNEL FAILURE");

	printf("Using shared memory to generate histogram\n");
    gettimeofday(&start, NULL);
    hipMemset(histogram_on_device, 0, histogram_size * sizeof(int)); /* Reset histogram */
    histogram_kernel_fast<<<grid, thread_block>>>(input_data_on_device, histogram_on_device, num_elements, histogram_size); 
	hipDeviceSynchronize();
    gettimeofday(&stop, NULL);
	printf("Eexecution time = %f\n",stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000);
	check_for_error("KERNEL FAILURE");

	/* Copy result back from GPU */ 
	hipMemcpy(histogram, histogram_on_device, histogram_size * sizeof(int), hipMemcpyDeviceToHost);
	print_histogram(histogram, histogram_size, num_elements);
	/* Free memory */
	hipFree(input_data_on_device);
	hipFree(histogram_on_device);
}

/* Check correctness of result: sum of histogram bins must equal number of input elements */
void check_histogram(int *histogram, int num_elements, int histogram_size)
{
	int sum = 0;
    int i;
	for (i = 0; i < histogram_size; i++)
		sum += histogram[i];

	printf("Number of histogram entries = %d. \n", sum);
	if (sum == num_elements)
		printf("Histogram generated successfully. \n");
	else
		printf("Error generating histogram. \n");
	
    printf("\n");
}


/* Check for errors during kernel execution */
void check_for_error(const char *msg)
{
	hipError_t err = hipGetLastError();
	if (hipSuccess != err) {
		printf("CUDA ERROR: %s (%s)\n", msg, hipGetErrorString(err));
		exit(EXIT_FAILURE);
	}
} 

	.text
	.file	"histogram.hip"
	.globl	_Z36__device_stub__histogram_kernel_fastPiS_ii # -- Begin function _Z36__device_stub__histogram_kernel_fastPiS_ii
	.type	_Z36__device_stub__histogram_kernel_fastPiS_ii,@function
_Z36__device_stub__histogram_kernel_fastPiS_ii: # @_Z36__device_stub__histogram_kernel_fastPiS_ii
	.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	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%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	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	$_Z21histogram_kernel_fastPiS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z36__device_stub__histogram_kernel_fastPiS_ii, .Lfunc_end0-_Z36__device_stub__histogram_kernel_fastPiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z36__device_stub__histogram_kernel_slowPiS_ii # -- Begin function _Z36__device_stub__histogram_kernel_slowPiS_ii
	.type	_Z36__device_stub__histogram_kernel_slowPiS_ii,@function
_Z36__device_stub__histogram_kernel_slowPiS_ii: # @_Z36__device_stub__histogram_kernel_slowPiS_ii
	.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	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%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	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	$_Z21histogram_kernel_slowPiS_ii, %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	_Z36__device_stub__histogram_kernel_slowPiS_ii, .Lfunc_end1-_Z36__device_stub__histogram_kernel_slowPiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	cmpl	$1, %edi
	jg	.LBB2_2
# %bb.1:
	movq	(%rsi), %rsi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%edi, %edi
	callq	exit
.LBB2_2:
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %edi
	callq	_Z8run_testi
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z8run_testi
.LCPI3_0:
	.long	0x30000000                      # float 4.65661287E-10
.LCPI3_1:
	.long	0x437f0000                      # float 255
.LCPI3_2:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z8run_testi
	.type	_Z8run_testi,@function
_Z8run_testi:                           # @_Z8run_testi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edi, %r12d
	movl	$1, %edi
	movl	$1024, %esi                     # imm = 0x400
	callq	calloc@PLT
	movq	%rax, %rbx
	movl	$1, %edi
	movl	$1024, %esi                     # imm = 0x400
	callq	calloc@PLT
	movq	%rax, %r14
	movl	$.Lstr, %edi
	callq	puts@PLT
	leal	(,%r12,4), %eax
	movslq	%eax, %rdi
	callq	malloc
	movq	%rax, %r15
	testl	%r12d, %r12d
	jle	.LBB3_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%r12d, %r13d
	xorl	%ebp, %ebp
.LBB3_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	mulss	.LCPI3_0(%rip), %xmm0
	mulss	.LCPI3_1(%rip), %xmm0
	callq	floorf@PLT
	cvttss2si	%xmm0, %eax
	movl	%eax, (%r15,%rbp,4)
	incq	%rbp
	cmpq	%rbp, %r13
	jne	.LBB3_2
.LBB3_3:                                # %._crit_edge
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	xorl	%r13d, %r13d
	leaq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	%r15, %rdi
	movq	%rbx, %rsi
	movl	%r12d, %edx
	movl	$256, %ecx                      # imm = 0x100
	callq	compute_gold
	leaq	24(%rsp), %rbp
	movq	%rbp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbp), %rax
	leaq	8(%rsp), %rcx
	subq	(%rcx), %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	movq	8(%rbp), %rax
	subq	8(%rcx), %rax
	cvtsi2ss	%rax, %xmm1
	divss	.LCPI3_2(%rip), %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.3, %edi
	movb	$1, %al
	callq	printf
	movq	%rbx, %rdi
	movl	%r12d, %esi
	movl	$256, %edx                      # imm = 0x100
	callq	_Z15check_histogramPiii
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	%r15, %rdi
	movq	%r14, %rsi
	movl	%r12d, %edx
	movl	$256, %ecx                      # imm = 0x100
	callq	_Z17compute_on_devicePiS_ii
	movq	%r14, %rdi
	movl	%r12d, %esi
	movl	$256, %edx                      # imm = 0x100
	callq	_Z15check_histogramPiii
	xorps	%xmm0, %xmm0
.LBB3_4:                                # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r13,4), %eax
	subl	(%r14,%r13,4), %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovsl	%eax, %ecx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ecx, %xmm1
	addss	%xmm1, %xmm0
	incq	%r13
	cmpq	$256, %r13                      # imm = 0x100
	jne	.LBB3_4
# %bb.5:
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.5, %edi
	movb	$1, %al
	callq	printf
	movq	%r15, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%edi, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z8run_testi, .Lfunc_end3-_Z8run_testi
	.cfi_endproc
                                        # -- End function
	.globl	_Z15check_histogramPiii         # -- Begin function _Z15check_histogramPiii
	.type	_Z15check_histogramPiii,@function
_Z15check_histogramPiii:                # @_Z15check_histogramPiii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movl	%esi, %ebx
	testl	%edx, %edx
	jle	.LBB4_1
# %bb.2:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorl	%ecx, %ecx
	xorl	%ebp, %ebp
.LBB4_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addl	(%rdi,%rcx,4), %ebp
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB4_3
	jmp	.LBB4_4
.LBB4_1:
	xorl	%ebp, %ebp
.LBB4_4:                                # %._crit_edge
	movl	$.L.str.11, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	cmpl	%ebx, %ebp
	movl	$.Lstr.4, %eax
	movl	$.Lstr.3, %edi
	cmoveq	%rax, %rdi
	callq	puts@PLT
	movl	$10, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end4:
	.size	_Z15check_histogramPiii, .Lfunc_end4-_Z15check_histogramPiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z17compute_on_devicePiS_ii
.LCPI5_0:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z17compute_on_devicePiS_ii
	.type	_Z17compute_on_devicePiS_ii,@function
_Z17compute_on_devicePiS_ii:            # @_Z17compute_on_devicePiS_ii
	.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	%ecx, %ebp
	movl	%edx, %ebx
	movq	%rsi, 16(%rsp)                  # 8-byte Spill
	movq	%rdi, %r15
	xorl	%eax, %eax
	leaq	8(%rsp), %r12
	movq	%rax, (%r12)
	movq	%rsp, %r13
	movq	%rax, (%r13)
	movslq	%edx, %r14
	shlq	$2, %r14
	movq	%r12, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	%ebp, %r15
	shlq	$2, %r15
	movq	%r13, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	movq	(%r13), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	hipMemset
	leaq	24(%rsp), %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movabsq	$4294967336, %rdi               # imm = 0x100000028
	leaq	216(%rdi), %r13
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_2
# %bb.1:
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	%ebx, %edx
	movl	%ebp, %ecx
	callq	_Z36__device_stub__histogram_kernel_slowPiS_ii
.LBB5_2:
	callq	hipDeviceSynchronize
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r14), %rax
	leaq	24(%rsp), %r12
	subq	(%r12), %rax
	cvtsi2ss	%rax, %xmm0
	movq	8(%r14), %rax
	subq	8(%r12), %rax
	cvtsi2ss	%rax, %xmm1
	divss	.LCPI5_0(%rip), %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.8, %edi
	callq	_Z15check_for_errorPKc
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	hipMemset
	movabsq	$4294967336, %rdi               # imm = 0x100000028
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_4
# %bb.3:
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	movl	%ebx, %edx
	movl	%ebp, %ecx
	callq	_Z36__device_stub__histogram_kernel_fastPiS_ii
.LBB5_4:
	callq	hipDeviceSynchronize
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%r14), %rax
	subq	24(%rsp), %rax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rax, %xmm0
	movq	8(%r14), %rax
	subq	32(%rsp), %rax
	xorps	%xmm1, %xmm1
	cvtsi2ss	%rax, %xmm1
	divss	.LCPI5_0(%rip), %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.8, %edi
	callq	_Z15check_for_errorPKc
	movq	(%rsp), %rsi
	movq	16(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r14, %rdi
	movl	%ebp, %esi
	movl	%ebx, %edx
	callq	_Z15print_histogramPiii
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	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_end5:
	.size	_Z17compute_on_devicePiS_ii, .Lfunc_end5-_Z17compute_on_devicePiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z15check_for_errorPKc          # -- Begin function _Z15check_for_errorPKc
	.type	_Z15check_for_errorPKc,@function
_Z15check_for_errorPKc:                 # @_Z15check_for_errorPKc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB6_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB6_2:
	.cfi_def_cfa_offset 16
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.15, %edi
	movq	%rbx, %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	_Z15check_for_errorPKc, .Lfunc_end6-_Z15check_for_errorPKc
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21histogram_kernel_fastPiS_ii, %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	$_Z21histogram_kernel_slowPiS_ii, %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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z21histogram_kernel_fastPiS_ii,@object # @_Z21histogram_kernel_fastPiS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z21histogram_kernel_fastPiS_ii
	.p2align	3, 0x0
_Z21histogram_kernel_fastPiS_ii:
	.quad	_Z36__device_stub__histogram_kernel_fastPiS_ii
	.size	_Z21histogram_kernel_fastPiS_ii, 8

	.type	_Z21histogram_kernel_slowPiS_ii,@object # @_Z21histogram_kernel_slowPiS_ii
	.globl	_Z21histogram_kernel_slowPiS_ii
	.p2align	3, 0x0
_Z21histogram_kernel_slowPiS_ii:
	.quad	_Z36__device_stub__histogram_kernel_slowPiS_ii
	.size	_Z21histogram_kernel_slowPiS_ii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: %s num-elements\n"
	.size	.L.str, 24

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Eexcution time = %f\n"
	.size	.L.str.3, 21

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Difference between CPU and device results = %f\n"
	.size	.L.str.5, 48

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Execution time = %f \n"
	.size	.L.str.7, 22

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"KERNEL FAILURE"
	.size	.L.str.8, 15

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Eexecution time = %f\n"
	.size	.L.str.10, 22

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Number of histogram entries = %d. \n"
	.size	.L.str.11, 36

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"CUDA ERROR: %s (%s)\n"
	.size	.L.str.15, 21

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21histogram_kernel_fastPiS_ii"
	.size	.L__unnamed_1, 32

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z21histogram_kernel_slowPiS_ii"
	.size	.L__unnamed_2, 32

	.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	"\nGenerating input data"
	.size	.Lstr, 23

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\nGenerating histrgram on CPU"
	.size	.Lstr.1, 29

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"\nGenerating histrgram on device"
	.size	.Lstr.2, 32

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Error generating histogram. "
	.size	.Lstr.3, 29

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Histogram generated successfully. "
	.size	.Lstr.4, 35

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"Using global memory to generate histrogram"
	.size	.Lstr.5, 43

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"Using shared memory to generate histogram"
	.size	.Lstr.6, 42

	.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 _Z36__device_stub__histogram_kernel_fastPiS_ii
	.addrsig_sym _Z36__device_stub__histogram_kernel_slowPiS_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z21histogram_kernel_fastPiS_ii
	.addrsig_sym _Z21histogram_kernel_slowPiS_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21histogram_kernel_fastPiS_ii ; -- Begin function _Z21histogram_kernel_fastPiS_ii
	.globl	_Z21histogram_kernel_fastPiS_ii
	.p2align	8
	.type	_Z21histogram_kernel_fastPiS_ii,@function
_Z21histogram_kernel_fastPiS_ii:        ; @_Z21histogram_kernel_fastPiS_ii
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x10
	v_lshlrev_b32_e32 v4, 2, v0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_u32_e32 vcc_lo, s3, v0
	s_and_saveexec_b32 s3, vcc_lo
	s_cbranch_execz .LBB0_2
; %bb.1:
	v_mov_b32_e32 v1, 0
	ds_store_b32 v4, v1
.LBB0_2:
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	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_addc_u32 s9, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s1, s3, 0xffff
	s_mov_b32 s3, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s1, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s2, v1
	s_cbranch_execz .LBB0_5
; %bb.3:                                ; %.lr.ph.preheader
	s_load_b32 s0, s[8:9], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	v_mov_b32_e32 v0, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s8, s0, s1
	v_add_co_u32 v2, s0, s4, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_add_co_ci_u32_e64 v3, s0, s5, v3, s0
	s_ashr_i32 s9, s8, 31
	s_lshl_b64 s[4:5], s[8:9], 2
	s_mov_b32 s9, 0
.LBB0_4:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v5, v[2:3], off
	v_add_nc_u32_e32 v1, s8, v1
	v_add_co_u32 v2, s1, v2, s4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v3, s1, s5, v3, s1
	v_cmp_le_i32_e64 s0, s2, v1
	s_delay_alu instid0(VALU_DEP_1)
	s_or_b32 s9, s0, s9
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v5, 2, v5
	ds_add_u32 v5, v0
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_4
.LBB0_5:                                ; %Flow23
	s_or_b32 exec_lo, exec_lo, s3
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB0_7
; %bb.6:
	ds_load_b32 v0, v4
	s_waitcnt lgkmcnt(0)
	global_atomic_add_u32 v4, v0, s[6:7]
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21histogram_kernel_fastPiS_ii
		.amdhsa_group_segment_fixed_size 1024
		.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_end0:
	.size	_Z21histogram_kernel_fastPiS_ii, .Lfunc_end0-_Z21histogram_kernel_fastPiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 328
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 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
	.protected	_Z21histogram_kernel_slowPiS_ii ; -- Begin function _Z21histogram_kernel_slowPiS_ii
	.globl	_Z21histogram_kernel_slowPiS_ii
	.p2align	8
	.type	_Z21histogram_kernel_slowPiS_ii,@function
_Z21histogram_kernel_slowPiS_ii:        ; @_Z21histogram_kernel_slowPiS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b32 s8, s[0:1], 0x10
	s_add_u32 s2, s0, 24
	s_addc_u32 s3, s1, 0
	s_mov_b32 s5, exec_lo
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s5, s[2:3], 0x0
	s_load_b128 s[0:3], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	v_mov_b32_e32 v0, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s4, s5, s4
	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
	s_ashr_i32 s5, s4, 31
	s_mov_b32 s1, 0
	s_lshl_b64 s[6:7], s[4:5], 2
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b32 v4, v[2:3], off
	v_add_nc_u32_e32 v1, s4, v1
	v_add_co_u32 v2, s0, v2, s6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s0, s7, v3, s0
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, s2, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v5, vcc_lo
	v_cmp_le_i32_e32 vcc_lo, s8, v1
	global_atomic_add_u32 v[4:5], v0, off
	s_or_b32 s1, vcc_lo, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB1_2
.LBB1_3:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21histogram_kernel_slowPiS_ii
		.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	_Z21histogram_kernel_slowPiS_ii, .Lfunc_end1-_Z21histogram_kernel_slowPiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 244
; 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 : 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .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
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21histogram_kernel_fastPiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z21histogram_kernel_fastPiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .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:           4
        .value_kind:     by_value
      - .offset:         20
        .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
    .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:           _Z21histogram_kernel_slowPiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z21histogram_kernel_slowPiS_ii.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
