liveBook · Manning

Histogram

As explained in Grokking GPU Programming

A histogram is a collection of counts recording how many values fall into each category or bin.

A histogram counts how many input values fall into each category, or bin. For [2, 0, 1, 2, 2], the counts are [1, 1, 3]. section 8.5

Figure 8.2 The histogram pattern on a CPU. A single thread T0 reads each element of the data array (length n) one at a time and writes to the corresponding bin in the 256-element hist array. With only one writer, there are no conflicts.

A single CPU thread reads each value and increments its matching bin. With only one writer, updates cannot conflict. section 8.5

Parallel counting adds a coordination problem:

  • Multiple threads may update the same bin. Use atomicAdd to protect updates, or let each block build a shared-memory histogram and merge the results. section 8.11
  • Counts that vary between runs can signal a race; unusually large or carried-over totals can mean the histogram was not zeroed before launch. section 8.11

How Grokking GPU Programming covers it

How deep it goes
Defines bin counts with a small array example, then outlines CPU counting, parallel conflicts, and remedies.
Examples
Uses [2, 0, 1, 2, 2] producing [1, 1, 3], plus grayscale intensities mapped to 256 bins.
What it assumes
Assumes C for-loop and function familiarity; treats pointer comfort as helpful and explains needed CUDA pointer tricks as they arise.
What you can do after
Build a sequential histogram or reason about parallelizing it with atomicAdd or block-local shared histograms.
How it connects
Connects histograms to parallel programming, atomic updates, and shared-memory privatization.

Also explained in

Compare how 13 books explain histogram →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.