The histogram of an image conveys important information related to the contrast of an image, and it can also be used as an image feature for computer vision tasks. A histogram indicates the frequency of the occurrence of a particular pixel value. While calculating the histogram of an 8-bit image that is 256 x 256 in size, the 65,535-pixel values will work on arrays of intensity values from 0-255. If one thread is launched per pixel, then 65,535 threads will work on 256 memory locations of intensity values.
Consider a situation in which a large number of threads try to modify a small portion of memory. While calculating the histogram of an image, read-modify-write operations have to be performed for all memory locations. This operation is d_out[i] ++, where first d_out[i] is read from memory, then incremented, and then written back to the memory...