//#include "cuda_runtime.h"
//#include "device_launch_parameters.h"
//#include <cuda.h>
//#include <stdio.h>
//#include <iostream>
//#include <time.h>
//#include "common.h"
////#include "cuda_common.cuh"
//
//#define HISTOGRAM_BUCKET_SIZE 10
//
////---------------------------------------------------KERNELS AND CPU IMPLEMENTATIONS-----------------------------//
//
////in this kernel we expect grid with only single block
//__global__ void histogram_gpu_v01(int* input, int*output, int input_size)
//{
//	atomicAdd(&(output[input[threadIdx.x]]),1);
//}
//
//// in this kernel we expect 1D grid with multiple 1D blocks 
//// reduce the global memory writes by introducing shared memory intermideate store
//__global__ void histogram_gpu_v02(int* input, int*output, int input_size)
//{
//	__shared__  int block_output[HISTOGRAM_BUCKET_SIZE];
//	
//	int gid = blockIdx.x*blockDim.x + threadIdx.x;
//
//	atomicAdd(&(block_output[input[gid]]), 1);
//	__syncthreads();
//
//	if (threadIdx.x < HISTOGRAM_BUCKET_SIZE)
//	{
//		atomicAdd(&(output[threadIdx.x]), block_output[threadIdx.x]);
//	}
//}
//
////crating thread for to represent each element in the array may be inefficient
////so change the kernel so that single threads handles multiple elements 
//__global__ void histogram_gpu_v03(int* input, int*output, int input_size)
//{
//	//to be implements
//}
//
//void histogram_cpu(int * input, int* output, int input_size)
//{
//	for (int i = 0; i < input_size; i++)
//	{
//		output[input[i]]++;
//	}
//}
//
//
////---------------------------------------------------RUNING FUNCTIONS--------------------------------------------//
//
//void run_histogram_cpu(int input_size, int histogram_buckets)
//{
//	int * input, *output;
//	int input_byte_size = sizeof(int)*input_size;
//	int histogram_bucket_byte_size = sizeof(int)*histogram_buckets;
//
//	input = (int*)malloc(input_byte_size);
//	output = (int*)malloc(histogram_bucket_byte_size);
//	memset(output, 0, histogram_bucket_byte_size);
//
//	initialize(input, input_size);
//	printf("Printing input array \n");
//	print_array(input,input_size);
//
//	histogram_cpu(input,output,input_size);
//	printf("Printing histogram array \n");
//	print_array(output, histogram_buckets);
//	
//	free(output);
//	free(input);
//}
//
//void run_histogram_gpu(int input_size, int histogram_buckets)
//{
//	int * h_input, *h_ref;
//	int input_byte_size = sizeof(int)*input_size;
//	int histogram_bucket_byte_size = sizeof(int)*histogram_buckets;
//
//	h_input = (int*)malloc(input_byte_size);
//	h_ref = (int*)malloc(histogram_bucket_byte_size);;
//	
//	initialize(h_input, input_size);
//
//	int * d_input, *d_output;
//	cudaMalloc((int**)&d_input, input_byte_size);
//	cudaMalloc((int**)&d_output,histogram_bucket_byte_size);
//
//	dim3 grid(4);
//	dim3 block(input_size/grid.x);
//
//	cudaMemset(d_output, 0, histogram_bucket_byte_size);
//	cudaMemcpy(d_input, h_input, input_byte_size, cudaMemcpyHostToDevice);
//
//	histogram_gpu_v02 << <grid,block >> > (d_input, d_output, input_size);
//	cudaDeviceSynchronize();
//
//	cudaMemcpy(h_ref, d_output, histogram_bucket_byte_size, cudaMemcpyDeviceToHost);
//
//	print_array(h_ref,histogram_buckets);
//
//	cudaFree(d_output);
//	cudaFree(d_input);
//
//	free(h_ref);
//	free(h_input);
//}
//
////int main()
////{
////	printf("--------------------RUNNING HISTOGRAM EXAMPLE------------------------- \n");
////	int input_size = 1024; 
////	int histogram_buckets = 10;
////	run_histogram_gpu(input_size,histogram_buckets);
////
////	system("pause");
////	return 0;
////}
	.file	"tmpxft_002486db_00000000-6_histogram_v01.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2010:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2010:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2033:
	.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
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
//#include "cuda_runtime.h"
//#include "device_launch_parameters.h"
//#include <cuda.h>
//#include <stdio.h>
//#include <iostream>
//#include <time.h>
//#include "common.h"
////#include "cuda_common.cuh"
//
//#define HISTOGRAM_BUCKET_SIZE 10
//
////---------------------------------------------------KERNELS AND CPU IMPLEMENTATIONS-----------------------------//
//
////in this kernel we expect grid with only single block
//__global__ void histogram_gpu_v01(int* input, int*output, int input_size)
//{
//	atomicAdd(&(output[input[threadIdx.x]]),1);
//}
//
//// in this kernel we expect 1D grid with multiple 1D blocks 
//// reduce the global memory writes by introducing shared memory intermideate store
//__global__ void histogram_gpu_v02(int* input, int*output, int input_size)
//{
//	__shared__  int block_output[HISTOGRAM_BUCKET_SIZE];
//	
//	int gid = blockIdx.x*blockDim.x + threadIdx.x;
//
//	atomicAdd(&(block_output[input[gid]]), 1);
//	__syncthreads();
//
//	if (threadIdx.x < HISTOGRAM_BUCKET_SIZE)
//	{
//		atomicAdd(&(output[threadIdx.x]), block_output[threadIdx.x]);
//	}
//}
//
////crating thread for to represent each element in the array may be inefficient
////so change the kernel so that single threads handles multiple elements 
//__global__ void histogram_gpu_v03(int* input, int*output, int input_size)
//{
//	//to be implements
//}
//
//void histogram_cpu(int * input, int* output, int input_size)
//{
//	for (int i = 0; i < input_size; i++)
//	{
//		output[input[i]]++;
//	}
//}
//
//
////---------------------------------------------------RUNING FUNCTIONS--------------------------------------------//
//
//void run_histogram_cpu(int input_size, int histogram_buckets)
//{
//	int * input, *output;
//	int input_byte_size = sizeof(int)*input_size;
//	int histogram_bucket_byte_size = sizeof(int)*histogram_buckets;
//
//	input = (int*)malloc(input_byte_size);
//	output = (int*)malloc(histogram_bucket_byte_size);
//	memset(output, 0, histogram_bucket_byte_size);
//
//	initialize(input, input_size);
//	printf("Printing input array \n");
//	print_array(input,input_size);
//
//	histogram_cpu(input,output,input_size);
//	printf("Printing histogram array \n");
//	print_array(output, histogram_buckets);
//	
//	free(output);
//	free(input);
//}
//
//void run_histogram_gpu(int input_size, int histogram_buckets)
//{
//	int * h_input, *h_ref;
//	int input_byte_size = sizeof(int)*input_size;
//	int histogram_bucket_byte_size = sizeof(int)*histogram_buckets;
//
//	h_input = (int*)malloc(input_byte_size);
//	h_ref = (int*)malloc(histogram_bucket_byte_size);;
//	
//	initialize(h_input, input_size);
//
//	int * d_input, *d_output;
//	cudaMalloc((int**)&d_input, input_byte_size);
//	cudaMalloc((int**)&d_output,histogram_bucket_byte_size);
//
//	dim3 grid(4);
//	dim3 block(input_size/grid.x);
//
//	cudaMemset(d_output, 0, histogram_bucket_byte_size);
//	cudaMemcpy(d_input, h_input, input_byte_size, cudaMemcpyHostToDevice);
//
//	histogram_gpu_v02 << <grid,block >> > (d_input, d_output, input_size);
//	cudaDeviceSynchronize();
//
//	cudaMemcpy(h_ref, d_output, histogram_bucket_byte_size, cudaMemcpyDeviceToHost);
//
//	print_array(h_ref,histogram_buckets);
//
//	cudaFree(d_output);
//	cudaFree(d_input);
//
//	free(h_ref);
//	free(h_input);
//}
//
////int main()
////{
////	printf("--------------------RUNNING HISTOGRAM EXAMPLE------------------------- \n");
////	int input_size = 1024; 
////	int histogram_buckets = 10;
////	run_histogram_gpu(input_size,histogram_buckets);
////
////	system("pause");
////	return 0;
////}
	.text
	.file	"histogram_v01.hip"
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
