Repository navigation
Fit the reductions' partial results in local memory for large element types - #204
Merged
Merged
Conversation
maleadt
force-pushed
the
tb/reduce-localmem
branch
from
November 5, 2026 11:19
6f8a708 to
007a1ab
Compare
maleadt
force-pushed
the
tb/reduce-localmem
branch
from
November 5, 2026 12:04
007a1ab to
f40b208
Compare
… types Every reduction kernel keeps a partial result per thread in local memory, in blocks of 256 threads by default, so elements of more than 128 bytes exceeded the 32 KiB budget that the sorts and scans keep to, and those of more than 192 bytes failed to compile on CUDA devices before Blackwell (48 KiB of static shared memory). ForwardDiff duals with 16 partials, or nested ones, are that large. As CUB's `MemBoundScaling`, lower an unset block size to the largest power of two whose partial results fit the tuning's new `local_mem_bytes`, sized by the partial-result type (an `Optional` for operators without a neutral element), and keep the second pass of split reductions within the first pass's block size. An explicit `block_size` is kept. x-ref JuliaGPU/CUDA.jl#3516
maleadt
force-pushed
the
tb/reduce-localmem
branch
from
November 6, 2026 09:59
f40b208 to
7eb9b2b
Compare
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.
Every reduction kernel keeps a partial result per thread in local memory, in blocks of 256 threads by default, without checking the element size. Elements larger than 128 bytes exceed the 32 KiB budget that the sorts and scans keep to, and those larger than 192 bytes fail to compile on CUDA devices before Blackwell (48 KiB of static shared memory; about 396 bytes on Blackwell). ForwardDiff duals with 16 partials, or nested ones, are that large: JuliaGPU/CUDA.jl#3516.
As CUB's
MemBoundScaling, an unset block size is now lowered to the largest power of two whose partial results fit the tuning's newlocal_mem_bytes. The size is that of the partial-result type, anOptionalfor operators without a neutral element, whichresolve_reducetakes as an optional argument likeresolve_scan. The second pass of split reductions stays within the first pass's block size. An explicitblock_sizeis kept as given.Tests: resolution of the block size for elements of 4 bytes to 64 KiB, and reductions of 648- and 2080-byte elements (blocks of 32 and 8) along every launch shape, which fail to compile without this change. On AMDGPU, ordered reductions of the larger size need
AMDGPU_LLVM_Backend_jll23.1.3+1 (JuliaPackaging/Yggdrasil#15464, backporting llvm/llvm-project#239163): LLVM's AMDGPU back-end crashed on the kernel's divergentendpgmonce it outgrew the branch range.Sub-group reductions, which shrink the kernels' local memory further, follow in a stacked PR. Ordered reductions of elements of more than 32 words also need JuliaGPU/KernelAbstractions.jl#947, so this should be merged after KernelInterface 0.4.5 is registered.