 //---------------------------------------------------------------
 // Trabalho PrÃ¡ctico NÂº4 - CUDA I - CHAD
 // Óscar Ferraz
 // 2018/2019
 // --------------------------------------------------------------
 
 
// nvcc -o vecAdd vecAdd.cu -I /usr/local/cuda-9.1/samples/common/inc


#include <stdio.h>
#include <time.h>
#include <cuda_runtime.h>
//#include <helper_cuda.h>



/**
 * CUDA Kernel Device code
 *
 * Computes the vector addition of A and B into C. The 3 vectors have the same
 * number of elements numElements.
 * 
 */
 
 __global__ void histo(unsigned int * hist, unsigned char * Image,int width1, int height1){
	
	__shared__ unsigned int histo_s[256];
	if (threadIdx.x < 256)
		histo_s[threadIdx.x]=0;
	__syncthreads();
	
	int i=threadIdx.x +blockIdx.x * blockDim.x;
	int stride = blockDim.x * gridDim.x;
	while (i < width1*height1){
		atomicAdd( &(histo_s[Image[i]]), 1);
		i += stride;
	}
	__syncthreads();
	if (threadIdx.x < 256)
		atomicAdd( &(hist[threadIdx.x]),histo_s[threadIdx.x]);
}
/**
 * Host main routine
 */
int
main(void)
{
	int width=813; 
	int height=707;
	int numElements=width*height;
	printf("[Vector addition of %d elements]\n", numElements);
	
	// Error code to check return values for CUDA calls
    cudaError_t err = cudaSuccess;
    
    size_t size=width*height*sizeof(unsigned char);
    size_t size_hist=256*sizeof(unsigned int);
    
    // Allocate the host input vector image
    unsigned char *h_image=(unsigned char *)malloc(size);
    // Allocate the host input vector igrey
    unsigned int *h_hist=(unsigned int *)malloc(size_hist);
    
    // Verify that allocations succeeded
    if (h_image==NULL||h_hist==NULL)
    {
        fprintf(stderr, "Failed to allocate horgbImagest vectors!\n");
        exit(EXIT_FAILURE);
    }
    
	// reading file
	FILE *fp;
    unsigned char ch;
    fp = fopen("model_result.ppm", "r");

    if(fp == NULL)
    {
        printf("Error in opening the image\n");
        fclose(fp);
        return(0);
    }

    printf("Successfully opened the image file\n");
	int k=0;
	int i=0;
    while((ch = fgetc(fp)) != EOF)
    {
		
		if(k>=3){
			h_image[i]=ch;
			i++;
		}
		if(ch == '\n')
			k++;
			
        if(i>=813*707)
			break;
    }
    
    printf("reading completed\n");
    fclose(fp);
    
    
    // Allocate the device input vector image
    unsigned char *d_image=NULL;
    err=cudaMalloc((void **)&d_image, size);
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to allocate device vector image (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
        // Allocate the device input vector grey
    unsigned int *d_hist=NULL;
    err=cudaMalloc((void **)&d_hist, size_hist);
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to allocate device vector grey (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    // Copy the host input vectors A and B in host memory to the device input vectors in device memory
    printf("Copy input image from the host memory to the CUDA device\n");
    err=cudaMemcpy(d_image, h_image, size, cudaMemcpyHostToDevice);
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to copy vector image from host to device (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
	
	// [!!] Define the number of threads per block and blocks per grid
    int threadsPerBlock =1024;
    int blocksPerGrid = 1;
    printf("CUDA kernel launch with %d blocks of %d threads\n", blocksPerGrid, threadsPerBlock);
    
    struct timespec start, end;
	clock_gettime(CLOCK_MONOTONIC, &start);
     // [!!] Launch the Vector Add CUDA Kernel with the respective input parameters
    histo<<<blocksPerGrid, threadsPerBlock>>>(d_hist, d_image, width, height);
     clock_gettime(CLOCK_MONOTONIC, &end);
    err=cudaGetLastError();
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to launch colorToGreyScaleConvertion kernel (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    // Copy the device result vector in device memory to the host result vector in host memory
    printf("Copy output data from the CUDA device to the host memory\n");
    err=cudaMemcpy((unsigned int *)h_hist, (unsigned int *)d_hist, size_hist, cudaMemcpyDeviceToHost);
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to copy vector grey from device to host (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    

//=====================================================
// write result
//=====================================================
    /*fp = fopen("result_cuda.ppm", "w");
    fprintf(fp, "P6\n813 707\n255\n");
    for(i=0;i<813*707;i++){
		fputc(h_grey[i], fp);
		fputc(h_grey[i], fp);
		fputc(h_grey[i], fp);
	}
    fclose(fp);*/
	
	double initialTime=(start.tv_sec*1e3)+(start.tv_nsec*1e-6);
	double finalTime=(end.tv_sec*1e3)+(end.tv_nsec*1e-6);
	printf("TIme:\t%f ms\n", (finalTime - initialTime));
	
	 // Free device global memory
    err=cudaFree(d_image);
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to free device vector image(error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    err=cudaFree(d_hist);
    if(err!=cudaSuccess)
    {
        fprintf(stderr, "Failed to free device vector grey (error code %s)!\n", cudaGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    // Free host memory
    free(h_image);
    free(h_hist);
	printf("Done\n");
    return 0;
}

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

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z28__device_stub__Z5histoPjPhiiPjPhii
	.type	_Z28__device_stub__Z5histoPjPhiiPjPhii, @function
_Z28__device_stub__Z5histoPjPhiiPjPhii:
.LFB2052:
	.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	.L2
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z5histoPjPhii(%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
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z28__device_stub__Z5histoPjPhiiPjPhii, .-_Z28__device_stub__Z5histoPjPhiiPjPhii
	.globl	_Z5histoPjPhii
	.type	_Z5histoPjPhii, @function
_Z5histoPjPhii:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z28__device_stub__Z5histoPjPhiiPjPhii
	.cfi_endproc
.LFE2053:
	.size	_Z5histoPjPhii, .-_Z5histoPjPhii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"[Vector addition of %d elements]\n"
.LC1:
	.string	"Failed to allocate horgbImagest vectors!\n"
.LC2:
	.string	"r"
.LC3:
	.string	"model_result.ppm"
.LC4:
	.string	"Error in opening the image\n"
.LC5:
	.string	"Successfully opened the image file\n"
.LC6:
	.string	"reading completed\n"
.LC7:
	.string	"Failed to allocate device vector image (error code %s)!\n"
.LC8:
	.string	"Failed to allocate device vector grey (error code %s)!\n"
.LC9:
	.string	"Copy input image from the host memory to the CUDA device\n"
.LC10:
	.string	"Failed to copy vector image from host to device (error code %s)!\n"
.LC11:
	.string	"CUDA kernel launch with %d blocks of %d threads\n"
.LC12:
	.string	"Failed to launch colorToGreyScaleConvertion kernel (error code %s)!\n"
.LC13:
	.string	"Copy output data from the CUDA device to the host memory\n"
.LC14:
	.string	"Failed to copy vector grey from device to host (error code %s)!\n"
.LC17:
	.string	"TIme:\t%f ms\n"
.LC18:
	.string	"Failed to free device vector image(error code %s)!\n"
.LC19:
	.string	"Failed to free device vector grey (error code %s)!\n"
.LC20:
	.string	"Done\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	$574791, %edx
	movl	$2, %edi
	leaq	.LC0(%rip), %rsi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$574791, %edi
	call	malloc@PLT
	movl	$1024, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	testq	%rbx, %rbx
	je	.L29
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L9
.L29:
	movq	stderr(%rip), %rdi
	leaq	.LC1(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L33
.L9:
	leaq	.LC2(%rip), %rsi
	leaq	.LC3(%rip), %rdi
	call	fopen@PLT
	movq	%rax, %r12
	testq	%rax, %rax
	jne	.L11
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	fclose@PLT
	jmp	.L12
.L11:
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	xorl	%r13d, %r13d
	xorl	%r14d, %r14d
	movl	$2, %edi
	call	__printf_chk@PLT
.L13:
	movq	%r12, %rdi
	call	fgetc@PLT
	cmpl	$2, %r14d
	jle	.L35
	movslq	%r13d, %rdx
	incl	%r13d
	movb	%al, (%rbx,%rdx)
	cmpb	$10, %al
	jne	.L14
.L26:
	incl	%r14d
.L14:
	cmpl	$574791, %r13d
	jne	.L13
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	xorl	%edx, %edx
	leaq	8(%rsp), %rdi
	movl	$574791, %esi
	movq	%rdx, 8(%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L18
	call	cudaGetErrorString@PLT
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rcx
.L34:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L33:
	movl	$1, %edi
	call	exit@PLT
.L18:
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	movl	$1024, %esi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L19
	call	cudaGetErrorString@PLT
	leaq	.LC8(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L34
.L19:
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$574791, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L20
	call	cudaGetErrorString@PLT
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L34
.L20:
	movl	$1024, %ecx
	movl	$1, %edx
	leaq	.LC11(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	40(%rsp), %rsi
	movl	$1, %edi
	call	clock_gettime@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$10, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdx, 56(%rsp)
	movl	$1, 64(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L21
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdi
	movl	$707, %ecx
	movl	$813, %edx
	call	_Z28__device_stub__Z5histoPjPhiiPjPhii
.L21:
	movl	$1, %edi
	leaq	56(%rsp), %rsi
	call	clock_gettime@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L22
	call	cudaGetErrorString@PLT
	leaq	.LC12(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L34
.L22:
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	16(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	movl	$1024, %edx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L23
	call	cudaGetErrorString@PLT
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L34
.L23:
	cvtsi2sdq	56(%rsp), %xmm0
	movl	$2, %edi
	movb	$1, %al
	movsd	.LC15(%rip), %xmm2
	cvtsi2sdq	64(%rsp), %xmm1
	movsd	.LC16(%rip), %xmm3
	leaq	.LC17(%rip), %rsi
	mulsd	%xmm2, %xmm0
	mulsd	%xmm3, %xmm1
	addsd	%xmm1, %xmm0
	cvtsi2sdq	40(%rsp), %xmm1
	mulsd	%xmm2, %xmm1
	cvtsi2sdq	48(%rsp), %xmm2
	mulsd	%xmm3, %xmm2
	addsd	%xmm2, %xmm1
	subsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L24
	call	cudaGetErrorString@PLT
	leaq	.LC18(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L34
.L24:
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L25
	call	cudaGetErrorString@PLT
	leaq	.LC19(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L34
.L25:
	movq	%rbx, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	leaq	.LC20(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L12:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L28
	call	__stack_chk_fail@PLT
.L35:
	cmpb	$10, %al
	jne	.L13
	jmp	.L26
.L28:
	addq	$80, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC21:
	.string	"_Z5histoPjPhii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC21(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z5histoPjPhii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2055:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC15:
	.long	0
	.long	1083129856
	.align 8
.LC16:
	.long	-1598689907
	.long	1051772663
	.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:

 //---------------------------------------------------------------
 // Trabalho PrÃ¡ctico NÂº4 - CUDA I - CHAD
 // Óscar Ferraz
 // 2018/2019
 // --------------------------------------------------------------
 
 
// nvcc -o vecAdd vecAdd.cu -I /usr/local/cuda-9.1/samples/common/inc


#include <stdio.h>
#include <time.h>
#include <hip/hip_runtime.h>
//#include <helper_cuda.h>



/**
 * CUDA Kernel Device code
 *
 * Computes the vector addition of A and B into C. The 3 vectors have the same
 * number of elements numElements.
 * 
 */
 
 __global__ void histo(unsigned int * hist, unsigned char * Image,int width1, int height1){
	
	__shared__ unsigned int histo_s[256];
	if (threadIdx.x < 256)
		histo_s[threadIdx.x]=0;
	__syncthreads();
	
	int i=threadIdx.x +blockIdx.x * blockDim.x;
	int stride = blockDim.x * gridDim.x;
	while (i < width1*height1){
		atomicAdd( &(histo_s[Image[i]]), 1);
		i += stride;
	}
	__syncthreads();
	if (threadIdx.x < 256)
		atomicAdd( &(hist[threadIdx.x]),histo_s[threadIdx.x]);
}
/**
 * Host main routine
 */
int
main(void)
{
	int width=813; 
	int height=707;
	int numElements=width*height;
	printf("[Vector addition of %d elements]\n", numElements);
	
	// Error code to check return values for CUDA calls
    hipError_t err = hipSuccess;
    
    size_t size=width*height*sizeof(unsigned char);
    size_t size_hist=256*sizeof(unsigned int);
    
    // Allocate the host input vector image
    unsigned char *h_image=(unsigned char *)malloc(size);
    // Allocate the host input vector igrey
    unsigned int *h_hist=(unsigned int *)malloc(size_hist);
    
    // Verify that allocations succeeded
    if (h_image==NULL||h_hist==NULL)
    {
        fprintf(stderr, "Failed to allocate horgbImagest vectors!\n");
        exit(EXIT_FAILURE);
    }
    
	// reading file
	FILE *fp;
    unsigned char ch;
    fp = fopen("model_result.ppm", "r");

    if(fp == NULL)
    {
        printf("Error in opening the image\n");
        fclose(fp);
        return(0);
    }

    printf("Successfully opened the image file\n");
	int k=0;
	int i=0;
    while((ch = fgetc(fp)) != EOF)
    {
		
		if(k>=3){
			h_image[i]=ch;
			i++;
		}
		if(ch == '\n')
			k++;
			
        if(i>=813*707)
			break;
    }
    
    printf("reading completed\n");
    fclose(fp);
    
    
    // Allocate the device input vector image
    unsigned char *d_image=NULL;
    err=hipMalloc((void **)&d_image, size);
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to allocate device vector image (error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
        // Allocate the device input vector grey
    unsigned int *d_hist=NULL;
    err=hipMalloc((void **)&d_hist, size_hist);
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to allocate device vector grey (error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    // Copy the host input vectors A and B in host memory to the device input vectors in device memory
    printf("Copy input image from the host memory to the CUDA device\n");
    err=hipMemcpy(d_image, h_image, size, hipMemcpyHostToDevice);
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to copy vector image from host to device (error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
	
	// [!!] Define the number of threads per block and blocks per grid
    int threadsPerBlock =1024;
    int blocksPerGrid = 1;
    printf("CUDA kernel launch with %d blocks of %d threads\n", blocksPerGrid, threadsPerBlock);
    
    struct timespec start, end;
	clock_gettime(CLOCK_MONOTONIC, &start);
     // [!!] Launch the Vector Add CUDA Kernel with the respective input parameters
    histo<<<blocksPerGrid, threadsPerBlock>>>(d_hist, d_image, width, height);
     clock_gettime(CLOCK_MONOTONIC, &end);
    err=hipGetLastError();
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to launch colorToGreyScaleConvertion kernel (error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    // Copy the device result vector in device memory to the host result vector in host memory
    printf("Copy output data from the CUDA device to the host memory\n");
    err=hipMemcpy((unsigned int *)h_hist, (unsigned int *)d_hist, size_hist, hipMemcpyDeviceToHost);
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to copy vector grey from device to host (error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    

//=====================================================
// write result
//=====================================================
    /*fp = fopen("result_cuda.ppm", "w");
    fprintf(fp, "P6\n813 707\n255\n");
    for(i=0;i<813*707;i++){
		fputc(h_grey[i], fp);
		fputc(h_grey[i], fp);
		fputc(h_grey[i], fp);
	}
    fclose(fp);*/
	
	double initialTime=(start.tv_sec*1e3)+(start.tv_nsec*1e-6);
	double finalTime=(end.tv_sec*1e3)+(end.tv_nsec*1e-6);
	printf("TIme:\t%f ms\n", (finalTime - initialTime));
	
	 // Free device global memory
    err=hipFree(d_image);
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to free device vector image(error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    err=hipFree(d_hist);
    if(err!=hipSuccess)
    {
        fprintf(stderr, "Failed to free device vector grey (error code %s)!\n", hipGetErrorString(err));
        exit(EXIT_FAILURE);
    }
    
    // Free host memory
    free(h_image);
    free(h_hist);
	printf("Done\n");
    return 0;
}

	.text
	.file	"histogram.hip"
	.globl	_Z20__device_stub__histoPjPhii  # -- Begin function _Z20__device_stub__histoPjPhii
	.type	_Z20__device_stub__histoPjPhii,@function
_Z20__device_stub__histoPjPhii:         # @_Z20__device_stub__histoPjPhii
	.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	$_Z5histoPjPhii, %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	_Z20__device_stub__histoPjPhii, .Lfunc_end0-_Z20__device_stub__histoPjPhii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI1_0:
	.quad	0x408f400000000000              # double 1000
.LCPI1_1:
	.quad	0x3eb0c6f7a0b5ed8d              # double 9.9999999999999995E-7
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.L.str, %edi
	movl	$574791, %esi                   # imm = 0x8C547
	xorl	%eax, %eax
	callq	printf
	movl	$574791, %edi                   # imm = 0x8C547
	callq	malloc
	movq	%rax, %rbx
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	testq	%rbx, %rbx
	je	.LBB1_19
# %bb.1:
	movq	%rax, %r14
	testq	%rax, %rax
	je	.LBB1_19
# %bb.2:
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_17
# %bb.3:
	movq	%rax, %r15
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	fgetc
	cmpl	$3, %ebp
	jb	.LBB1_6
# %bb.5:                                #   in Loop: Header=BB1_4 Depth=1
	movslq	%r12d, %r12
	movb	%al, (%rbx,%r12)
	incl	%r12d
.LBB1_6:                                #   in Loop: Header=BB1_4 Depth=1
	movzbl	%al, %eax
	xorl	%ecx, %ecx
	cmpl	$10, %eax
	sete	%cl
	addl	%ecx, %ebp
	cmpl	$574791, %r12d                  # imm = 0x8C547
	jl	.LBB1_4
# %bb.7:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	%r15, %rdi
	callq	fclose
	leaq	8(%rsp), %rdi
	movq	$0, (%rdi)
	movl	$574791, %esi                   # imm = 0x8C547
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_20
# %bb.8:
	movq	%rsp, %rdi
	movq	$0, (%rdi)
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_21
# %bb.9:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	8(%rsp), %rdi
	movl	$574791, %edx                   # imm = 0x8C547
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_22
# %bb.10:
	movl	$.L.str.11, %edi
	movl	$1, %esi
	movl	$1024, %edx                     # imm = 0x400
	xorl	%eax, %eax
	callq	printf
	leaq	32(%rsp), %rsi
	movl	$1, %edi
	callq	clock_gettime
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	leaq	1023(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_12
# %bb.11:
	movq	(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	$813, %edx                      # imm = 0x32D
	movl	$707, %ecx                      # imm = 0x2C3
	callq	_Z20__device_stub__histoPjPhii
.LBB1_12:
	leaq	16(%rsp), %rsi
	movl	$1, %edi
	callq	clock_gettime
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_23
# %bb.13:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movq	(%rsp), %rsi
	movl	$1024, %edx                     # imm = 0x400
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_24
# %bb.14:
	cvtsi2sdq	32(%rsp), %xmm0
	movsd	.LCPI1_0(%rip), %xmm1           # xmm1 = mem[0],zero
	cvtsi2sdq	40(%rsp), %xmm2
	mulsd	%xmm1, %xmm0
	movsd	.LCPI1_1(%rip), %xmm3           # xmm3 = mem[0],zero
	mulsd	%xmm3, %xmm2
	addsd	%xmm0, %xmm2
	cvtsi2sdq	16(%rsp), %xmm4
	xorps	%xmm0, %xmm0
	cvtsi2sdq	24(%rsp), %xmm0
	mulsd	%xmm1, %xmm4
	mulsd	%xmm3, %xmm0
	addsd	%xmm4, %xmm0
	subsd	%xmm2, %xmm0
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_25
# %bb.15:
	movq	(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_26
# %bb.16:
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	jmp	.LBB1_18
.LBB1_17:
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	xorl	%edi, %edi
	callq	fclose
.LBB1_18:
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_19:
	.cfi_def_cfa_offset 96
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$41, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	jmp	.LBB1_28
.LBB1_20:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.7, %esi
	jmp	.LBB1_27
.LBB1_21:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.8, %esi
	jmp	.LBB1_27
.LBB1_22:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.10, %esi
	jmp	.LBB1_27
.LBB1_23:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	jmp	.LBB1_27
.LBB1_24:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.14, %esi
	jmp	.LBB1_27
.LBB1_25:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.16, %esi
	jmp	.LBB1_27
.LBB1_26:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.17, %esi
.LBB1_27:
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
.LBB1_28:
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z5histoPjPhii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB3_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z5histoPjPhii,@object          # @_Z5histoPjPhii
	.section	.rodata,"a",@progbits
	.globl	_Z5histoPjPhii
	.p2align	3, 0x0
_Z5histoPjPhii:
	.quad	_Z20__device_stub__histoPjPhii
	.size	_Z5histoPjPhii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"[Vector addition of %d elements]\n"
	.size	.L.str, 34

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Failed to allocate horgbImagest vectors!\n"
	.size	.L.str.1, 42

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"model_result.ppm"
	.size	.L.str.2, 17

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Failed to allocate device vector image (error code %s)!\n"
	.size	.L.str.7, 57

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Failed to allocate device vector grey (error code %s)!\n"
	.size	.L.str.8, 56

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Failed to copy vector image from host to device (error code %s)!\n"
	.size	.L.str.10, 66

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"CUDA kernel launch with %d blocks of %d threads\n"
	.size	.L.str.11, 49

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Failed to launch colorToGreyScaleConvertion kernel (error code %s)!\n"
	.size	.L.str.12, 69

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Failed to copy vector grey from device to host (error code %s)!\n"
	.size	.L.str.14, 65

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"TIme:\t%f ms\n"
	.size	.L.str.15, 13

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Failed to free device vector image(error code %s)!\n"
	.size	.L.str.16, 52

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Failed to free device vector grey (error code %s)!\n"
	.size	.L.str.17, 52

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z5histoPjPhii"
	.size	.L__unnamed_1, 15

	.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	"Successfully opened the image file"
	.size	.Lstr, 35

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"reading completed"
	.size	.Lstr.1, 18

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Copy input image from the host memory to the CUDA device"
	.size	.Lstr.2, 57

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Copy output data from the CUDA device to the host memory"
	.size	.Lstr.3, 57

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Done"
	.size	.Lstr.4, 5

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"Error in opening the image"
	.size	.Lstr.5, 27

	.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 _Z20__device_stub__histoPjPhii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z5histoPjPhii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z5histoPjPhii          ; -- Begin function _Z5histoPjPhii
	.globl	_Z5histoPjPhii
	.p2align	8
	.type	_Z5histoPjPhii,@function
_Z5histoPjPhii:                         ; @_Z5histoPjPhii
; %bb.0:
	v_cmp_gt_u32_e32 vcc_lo, 0x100, v0
	v_lshlrev_b32_e32 v4, 2, v0
	s_and_saveexec_b32 s2, 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, s2
	s_clause 0x2
	s_load_b32 s10, s[0:1], 0x24
	s_load_b64 s[8:9], s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	s_add_u32 s2, s0, 24
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s1, s10, 0xffff
	s_mul_i32 s8, s9, s8
	v_mad_u64_u32 v[1:2], null, s15, s1, v[0:1]
	s_mov_b32 s9, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB0_5
; %bb.3:                                ; %.lr.ph.preheader
	s_load_b32 s2, s[2:3], 0x0
	v_ashrrev_i32_e32 v3, 31, v1
	v_add_co_u32 v2, s0, s6, v1
	v_mov_b32_e32 v0, 1
	s_mov_b32 s6, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_add_co_ci_u32_e64 v3, s0, s7, v3, s0
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s2, s2, s1
	s_ashr_i32 s3, s2, 31
.LBB0_4:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_u8 v5, v[2:3], off
	v_add_nc_u32_e32 v1, s2, v1
	v_add_co_u32 v2, s1, v2, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v3, s1, s3, v3, s1
	v_cmp_le_i32_e64 s0, s8, v1
	s_delay_alu instid0(VALU_DEP_1)
	s_or_b32 s6, s0, s6
	s_waitcnt vmcnt(0)
	v_lshlrev_b32_e32 v5, 2, v5
	ds_add_u32 v5, v0
	s_and_not1_b32 exec_lo, exec_lo, s6
	s_cbranch_execnz .LBB0_4
.LBB0_5:                                ; %Flow22
	s_or_b32 exec_lo, exec_lo, s9
	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[4:5]
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z5histoPjPhii
		.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	_Z5histoPjPhii, .Lfunc_end0-_Z5histoPjPhii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 312
; 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
	.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:           _Z5histoPjPhii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z5histoPjPhii.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
