In this article
Zero is a legitimate histogram category, not an absent observation; carry a validity mask into counting rather than inferring validity from the loaded value.
Distinguish memory access from counting
The Triton load API lets a masked-out lane return a supplied fallback without reading the corresponding address. That protects memory access. It does not automatically remove the fallback value from subsequent computations. A histogram makes this distinction particularly visible because a fallback can look exactly like a valid category and contribute a real count unless the aggregation receives its own validity information.
Read the categorical counting contract
The histogram API uses unit-width bins starting at zero and exposes a mask that excludes selected inputs. The language source forwards that mask to the histogram operation. Keep memory validity and observation validity associated through the kernel. A protected load followed by an unmasked histogram is a different computation from counting only the original valid observations.
Preserve genuine zero labels
Suppose a partially filled tile loads invalid lanes with zero. Counting all loaded lanes inflates the zero bin. Filtering every zero afterward is also wrong when the source data contains legitimate zero-valued labels. The needed distinction is provenance: which positions came from real input, not which numeric value they happen to contain. Carry the position-derived validity mask instead of reconstructing it from the category values after loading.
Test the conservation property
Build a small categorical fixture containing valid zero labels and a final partial tile. Compare the complete histogram with a straightforward reference and check that total counts equal the number of included observations. This detects padding bias even when the nonzero bins look correct. If the application also excludes categories outside its supported domain, define that filtering policy explicitly rather than relying on undocumented behavior for invalid bin indices or treating every loaded integer as a supported label.
Evaluate local and merged counts
Record bin configuration, inclusion policy, load fallback, per-tile validity, and how local histograms are combined. Guides to tensor axes and GPU acceptance evidence support the audit. Check both partial-tile counts and the final aggregate before benchmarking. A histogram kernel is correct when it counts the intended observations exactly, because safe memory reads and numerically plausible bins do not by themselves establish that padding stopped being data.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.