[CUB] Add runtime-sized shared-memory histogram privatization - #10553
Closed
robobryce wants to merge 1 commit into
Closed
[CUB] Add runtime-sized shared-memory histogram privatization#10553robobryce wants to merge 1 commit into
robobryce wants to merge 1 commit into
Conversation
Contributor
Author
|
Superseded by the same focused change under the corrected branch namespace: #10556. |
Author
|
Replacement draft under the corrected branch namespace: #10556 (). |
Author
|
Corrected branch name: pr/histocache/smem-privatized. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CUB currently keeps at most 256 privatized histogram bins per channel in shared memory. Larger histograms use per-block global-memory privatization, even when the complete histogram would fit comfortably in the device's runtime-sized shared-memory budget.
The raw experiments in #10547 explored several ways to extend this range, including multiple compile-time bin tiers, global staging slabs, cooperative combine kernels, and hybrid paths. This PR extracts the smallest useful design from that work: one runtime-sized shared-memory kernel with a direct per-block merge into the output.
This PR is independent of the benchmark/testing PR #10548 and is based directly on
main.What changed
Runtime-sized privatized storage
AgentHistogramcan now receive its privatized counter storage from anextern __shared__allocation. The existing accumulation, zeroing, and output-store code continues to access the histogram through the same per-channel indexing interface.The normal static-storage constructor is unchanged. The dynamic-storage constructor always selects the shared-memory path and initializes channel pointers into the contiguous runtime allocation.
One dynamic shared-memory kernel
The new sweep kernel keeps only the small agent metadata and block-load scratch storage in static shared memory. Histogram counters are allocated dynamically at launch according to the actual number of bins and
sizeof(CounterT).After processing its tiles, each block merges its private histogram directly into the output using the existing
StoreOutputpath. There is no global staging slab, follow-on combine kernel, cooperative launch, or cache algorithm in this PR.Conservative dispatch
The new path is initially limited to single-channel, host-initialized, non-byte EVEN and RANGE histograms. The existing 256-bin static path remains unchanged. Histograms use the dynamic path only when:
The capacity check is byte-based, so a 64-bit counter supports half as many bins as a 32-bit counter. Larger or otherwise unsupported cases retain the existing global-memory privatized fallback.
The occupancy query receives the dynamic allocation size, and the temporary-storage calculation does not allocate an unused per-block global histogram slab for dynamic-shared-memory cells.
Deliberately excluded
This PR does not include:
Those concerns can be measured and reviewed independently after this basic shared-memory extension is accepted.
Tests
The histogram test adds single-channel EVEN and RANGE cases above the static 256-bin boundary. It covers:
Formatting and source checks pass:
The focused test target builds successfully with CUDA 13.3.33 for SM90:
Runtime execution is blocked by the current machine's driver/toolkit combination. All three histogram launch modes, including unchanged tests, fail before assertions with:
Runtime validation therefore still needs a compatible CUDA driver for the CUDA 13.3.33-generated PTX.
Relationship to the research snapshot
This is a clean reimplementation of the final simplified shared-memory idea from #10547, rather than a chronological cherry-pick of the research commits. The earlier staging, cooperative, and fixed-tier implementations were intentionally discarded.