Repository navigation
Conversation
…ion accumulators In FlushSumShared, cg::labeled_partition(cg::coalesced_threads(), unique) followed by cg::reduce inside the divergent (idx.argsort != 0xffff) branch produces incorrect warp reductions when compiled with Clang CUDA, where floating-point coalesced_group reductions fall back to inclusive_scan_non_contiguous with per-group variable shuffle loop trip counts. Under Clang, replace it with an explicit uniform warp-shuffle reduction over __activemask() (LabeledWarpSum). nvcc keeps the cg::labeled_partition + cg::reduce path, since the explicit reduction regresses performance there. Zero-initialize tot in FlushSumShared, FlushSumBlock, and FlushSumBlockAdd unconditionally (following up on a768308): it was uninitialized across __syncthreads() in inactive lanes. Also add a test case in caspar_solver_cuda_test covering shared nodes and partial blocks. Signed-off-by: Paul-Edouard Sarlin <15985472+sarlinpe@users.noreply.github.com>
This was referenced Dec 4, 2026
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.
Mirrors symforce-org#472, rebased onto upstream
mainatacdedd0b.Changes relative to the upstream PR: its three commits are squashed into one. The explicit warp-shuffle reduction (
LabeledWarpSum) is only used under Clang CUDA; nvcc keeps thecg::labeled_partition+cg::reducepath, as requested in the upstream review. The zero-initialization is unconditional.Summary
Follows up on symforce-org#469 (
a768308e) with two related fixes insymforce/caspar/source/runtime/memops.cuhwhen compiling Caspar kernels with Clang CUDA:StorageT tot = 0;inFlushSumShared,FlushSumBlock, andFlushSumBlockAdd:When a thread is inactive (
idx.argsort == 0xffffor!valid),totwas previously uninitialized across__syncthreads()barriers, triggering-Wsometimes-uninitializedunder Clang and creating anundef/poisonphi node in LLVM IR.cg::labeled_partition+cg::reduceinFlushSumSharedwith an explicit warp-shuffle reduction:cg::labeled_partition(cg::coalesced_threads(), unique)was called outside theif (idx.argsort != 0xffff)guard whilecg::reduce(group, ...)was called inside it. Forfloatanddouble,cg::reduceover acoalesced_groupfalls back tocg::details::inclusive_scan_non_contiguous, which runs a warp-shuffle loop (__shfl_sync(mask, ...)) whose trip count (groupSize) varies per partition within the same warp. Under Clang CUDA, this divergent shuffle loop produces corrupted reductions when multiple factors in a warp share a target node. Replacing it with a uniform warp-shuffle reduction over__activemask()ensures all active threads execute__shfl_syncin lockstep.caspar_solver_cuda_test.cc:Existing solver tests used
kNumNodes = 4096(an exact multiple of the 1024-thread block size, leaving no inactive lanes) with a 1-to-1 factor-to-node mapping (indices[i] = i, so all partitions inFlushSumSharedhad size 1). Added a test case with shared nodes (kNumSharedNodes = 64) and a partial block (kNumFactors = 1500).