Build a histogram on the GPU. You are given an integer array input of length n whose values lie in [0, num_bins), and you must fill hist of length num_bins with the counts
Many threads may increment the same bin at the same time. A plain hist[b] += 1 races and drops updates. Your kernel must accumulate with atomicAdd so every increment is counted exactly once.
Complete:
__global__ kernel that updates the device histogram with atomics.void solve(const int* input, int* hist, int n, int num_bins) where both pointers are host pointers. Zero the histogram (do not assume hist is pre-zeroed), copy input to the device, launch, copy hist back, and free. n may be 0.Constraints: 0 <= n <= 4096, 1 <= num_bins <= 128. Do not write a main() in your solution.