Repository navigation
fix(cuda-device): handle partial warps in block collectives - #1311
Merged
nihalpasham merged 2 commits intoSep 23, 2026
Merged
Conversation
YunusMutlu
marked this pull request as draft
September 20, 2026 17:42
YunusMutlu
force-pushed
the
fix/block-collectives-partial-warp
branch
from
September 20, 2026 17:50
712fdeb to
c8fd64d
Compare
YunusMutlu
marked this pull request as ready for review
September 20, 2026 17:51
YunusMutlu
force-pushed
the
fix/block-collectives-partial-warp
branch
from
September 20, 2026 18:20
c8fd64d to
fb158b1
Compare
Signed-off-by: Yunus Mutlu <[email protected]>
Signed-off-by: nihalp <[email protected]>
nihalpasham
force-pushed
the
fix/block-collectives-partial-warp
branch
from
September 23, 2026 06:14
fb158b1 to
cba1382
Compare
nihalpasham
approved these changes
Sep 23, 2026
nihalpasham
left a comment
Collaborator
There was a problem hiding this comment.
I kept the partial-warp algorithm and added the scratch ownership follow-up:
- Raw element accesses avoid overlapping mutable borrows of the shared allocation.
- Both block collective APIs now require
unsafe, with allocation, participation, and reuse requirements documented; all callers are updated. - The regressions cover 77 launch shapes, including 3D blocks, two CTAs, maximum capacity, and scratch reuse. Undersized scratch traps.
The GPU cases, memcheck, racecheck, and synccheck pass on RTX 5090. Local device checks pass; all seven hosted workflows pass on this exact head.
This closes #1310 and changes the call sites to require unsafe.
pifu-zh
added a commit
to pifu-zh/cuda-oxide
that referenced
this pull request
Oct 6, 2026
…4 restored) Rebase onto upstream ec4aa47 (74 commits) changed the exported .ll shapes; four adaptations, each semantics-preserving: - Step 4: tid.y/tid.z -> llvm.amdgcn.workitem.id.y/z (upstream NVIDIA#1311 computes in-block rank via 3-D coords; on 1-D launches both sides return 0). Declares added to the mapped-strip list. - Step 10: accept dynamic membermask ((1<<live)-1 from the partial-warp collectives) and clamp=0 for .up (PTX clamp is the min-source-lane bound for .up; ds_bpermute's data movement is mask-independent and the convergent marker carries the all-lanes-execute requirement). - Step 12d: parse asm operands with top-level comma splitting - NVIDIA#1327 packed-as3 emits constant-expression pointers (ptr addrspacecast (ptr addrspace(3) @sym to ptr)) that the old [^,)] captures could not span. - Step 12e: panic trap is now inline PTX asm "trap;" (NVIDIA#1309) which the AMDGPU backend rejects; map to llvm.trap() (lowers to s_trap). Batch tool: select artifacts by exact name - the old "*.opt.ll" glob also matched the integrated pipeline's leftover *.amdgcn.preopt.opt.ll (sorted first), so the Python dimension double-rewrote the wrong file; the recorded 9/17 was measurement poisoning as much as shape drift. Verified: batch 14/14 llc-pass; tests/test_gfx1030.py 14 passed.
pifu-zh
added a commit
to pifu-zh/cuda-oxide
that referenced
this pull request
Oct 6, 2026
…tions Mirror of the Python-pipeline adaptation (35bed77) on the integrated path, for the two shapes the Rust prep pass also meets: - Step 10 envelope: dynamic membermask accepted (upstream NVIDIA#1311 partial-warp collectives emit (1<<live)-1 as SSA; ds_bpermute's data movement is mask-independent, convergent survives), and .up clamp=0 accepted (PTX clamp bounds the lowest source lane for .up; the other modes keep width-1=31). Literal non-(-1) masks still fall through for llc to reject explicitly. - Step 12e: panic trap is inline PTX asm post-NVIDIA#1309 and the AMDGPU backend rejects the mnemonic; map the exact shape to llvm.trap() (s_trap on gfx1030). 12d's store/load operand parsing already handled NVIDIA#1327 constant- expression pointers via split_top_level_commas (no change needed). Verified: dynamic-mask up@0 + trap-asm unit tests; lib 1252 green.
pifu-zh
added a commit
to pifu-zh/cuda-oxide
that referenced
this pull request
Oct 6, 2026
… launches) Upstream NVIDIA#1311's examples launch multi-dimensional blocks (warp_reduce runs 77 shapes including (3,5,3)/(8,3,2)/(7,3,3)/(8,8,8) and expands the in-block rank from the 3-D coordinates). Folding ntid.{y,z} to constant 1 - the Phase-1 1-D-launch decision - is a wrong-semantics bug there: block_scan_partial_warp_distinct died with an HSA hardware exception on the GPU. - prep pass (amdgcn.rs) + Python rewriter: ntid.{y,z} -> kernarg identity-ors like ntid.x; nctaid.{y,z} keep the 1-D-grid folding. - signatures: every amdgpu_kernel unconditionally gains (i32 %ntid_x, %ntid_y, %ntid_z). The launchers always push blockDim.0/.1/.2 on the gfx path, so a reference-only rule would misalign the whole kernarg tail for subset readers (e.g. .y without .x); two dead i32 kernargs are the price of a deterministic ABI. Non-kernel defines keep the conditional rule (alwaysinline leftovers). - host: the three macro templates (async builder, generated async launchers, generated sync launchers) push all three dims behind the same amdgcn_ntid_append_active() gate. - fixture hosts in tests/test_gfx1030.py updated to the 9- and 5-slot kparams. Verified on gfx1030 GPU: warp_reduce e2e (all warp tests + 77 launch shapes incl. every 3-D one), barrier e2e (3 kernels incl. noComplete split), redux_sum e2e (warp sums = 496). Python batch 14/14; codegen lib 1262 green; test_gfx1030.py 14 passed (incl. the two GPU e2e fixtures).
pifu-zh
added a commit
to pifu-zh/cuda-oxide
that referenced
this pull request
Oct 24, 2026
… launches) Upstream NVIDIA#1311's examples launch multi-dimensional blocks (warp_reduce runs 77 shapes including (3,5,3)/(8,3,2)/(7,3,3)/(8,8,8) and expands the in-block rank from the 3-D coordinates). Folding ntid.{y,z} to constant 1 - the Phase-1 1-D-launch decision - is a wrong-semantics bug there: block_scan_partial_warp_distinct died with an HSA hardware exception on the GPU. - prep pass (amdgcn.rs) + Python rewriter: ntid.{y,z} -> kernarg identity-ors like ntid.x; nctaid.{y,z} keep the 1-D-grid folding. - signatures: every amdgpu_kernel unconditionally gains (i32 %ntid_x, %ntid_y, %ntid_z). The launchers always push blockDim.0/.1/.2 on the gfx path, so a reference-only rule would misalign the whole kernarg tail for subset readers (e.g. .y without .x); two dead i32 kernargs are the price of a deterministic ABI. Non-kernel defines keep the conditional rule (alwaysinline leftovers). - host: the three macro templates (async builder, generated async launchers, generated sync launchers) push all three dims behind the same amdgcn_ntid_append_active() gate. - fixture hosts in tests/test_gfx1030.py updated to the 9- and 5-slot kparams. Verified on gfx1030 GPU: warp_reduce e2e (all warp tests + 77 launch shapes incl. every 3-D one), barrier e2e (3 kernels incl. noComplete split), redux_sum e2e (warp sums = 496). Python batch 14/14; codegen lib 1262 green; test_gfx1030.py 14 passed (incl. the two GPU e2e fixtures).
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.
What this fixes
Block reductions and scans now handle a partial final warp without reading nonexistent lanes or unused scratch slots.
What we fixed
ceil(block_threads / 32) <= NUM_WARPSbefore scratch access. Extra capacity is allowed.block_reduceandblock_scanunsafe and updated all repository callers. An arbitrary raw pointer cannot prove that shared scratch is valid or exclusively assigned to the collective.Call contract
Every thread in the block must call with the same live shared allocation and reach every collective/barrier. Other operations must not access that scratch while the collective runs. Place a block barrier before reusing it.
Verification
Checked at
cba13824against main66ff93c1:Closes #1310. The unsafe call requirement is a source compatibility change.