Skip to content

feat(mma_frag): predicate accumulator registers against a logical extent - #511

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
honeyspoon:up/mma-fragment-predication
Jul 28, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
honeyspoon:up/mma-fragment-predication

Conversation

@honeyspoon

Copy link
Copy Markdown
Contributor

Follows #474, which derived the layout.

A tile shape rarely divides the problem, and the accumulator makes the mismatch awkward. Each lane's four values are scattered across the tile, so clipping is not a contiguous prefix — two lanes disagree about the same register index:

M = 9 against the 16-row tile
lane  0  group 0  ->  mask 0b1111     all four registers inside
lane  4  group 1  ->  mask 0b0011     rows 9+ are padding
lane 31  group 7  ->  mask 0b0011

j 0 and 1 land on row group and are always inside; j 2 and 3 land on row group + 8 and are inside only for group 0. So lanes 0..3 keep four registers and every other lane keeps two: 4*4 + 28*2 = 72 = 9 * 8. The whole logical tile, nothing more.

API

A 4-bit mask per lane, not a per-store bounds check — a kernel tests one mask, and the warp stays convergent because every lane evaluates the same shape. acc_mask_is_uniform reports all-in or all-out, which is what decides whether an epilogue can take one unpredicated path.

Masking cannot introduce a race

It removes registers from a bijection, so surviving stores stay pairwise disjoint. Asserted rather than argued: the test claims each element and fails on a double claim.

Hardware validation

Real mma.sync on sm_86 with the destination prefilled with a sentinel — that is what distinguishes "computed the right values" from "suppressed the wrong stores":

valid rows written: 72 (expect 72)
wrong values      : 0
padding clobbered : 0

Tests

Every extent from 0x0 to 16x8 swept, asserting the valid count equals rows * cols — a wrong predicate surfaces as a wrong total rather than as missing output. Column clipping covered separately, because it behaves differently: columns come from tig, so a narrow extent removes whole lanes rather than registers.

12 tests, clippy --all-targets clean.

Follows NVIDIA#474, which derived the layout. A tile shape rarely divides the
problem, and the accumulator makes the mismatch awkward: each lane's four
values are scattered across the tile, so clipping is not a contiguous prefix.
Two lanes disagree about the same register index.

At M = 9 against the 16-row tile, j 0 and 1 land on row `group` and are always
inside; j 2 and 3 land on row `group + 8` and are inside only for group 0. So
lanes 0..3 keep four registers and every other lane keeps two, which is
4*4 + 28*2 = 72 = 9 * 8 - the whole logical tile and nothing more.

The predicate is per register, so it is returned as a 4-bit mask: a kernel
tests one mask instead of recomputing bounds per store, and the warp stays
convergent because every lane evaluates the same shape.
`acc_mask_is_uniform` reports whether a lane is all-in or all-out, which is
what decides whether an epilogue can take one unpredicated path.

Masking cannot introduce a race: it removes registers from a bijection, so the
surviving stores stay pairwise disjoint. Asserted rather than argued, by
claiming each element and failing on a double claim.

Verified against hardware with the destination prefilled with a sentinel, which
is what distinguishes 'computed the right values' from 'suppressed the wrong
stores':

    valid rows written: 72 (expect 72)
    wrong values      : 0
    padding clobbered : 0

Tests sweep every extent from 0x0 to 16x8 and assert the valid count equals
rows * cols, so a wrong predicate surfaces as a wrong total rather than as
missing output. Column clipping is covered separately because it behaves
differently: columns come from `tig`, so a narrow extent removes whole lanes
rather than registers.

Signed-off-by: abder <[email protected]>
…he rebase

The predication commit was written against a pre-NVIDIA#474 version of the
module docs and its context hunks reverted two maintainer passages:
the paragraph stating the accumulator mapping also applies to the
bf16/tf32/s8 `m16n8` shapes, and the `crate::disjoint::DisjointSlice`
cross-reference. The replacement text also linked
`crate::thread::DisjointBlock` and `crate::thread::DisjointTiling`,
which do not exist, breaking rustdoc under -D warnings. Restore the
current main text; the additive predication section and its tests are
untouched.
…otes

Predication does not by itself keep a warp convergent: the mask is
computed from straight-line expressions, but its value differs across
lanes, so stores guarded on mask bits can still diverge exactly as any
bounds check would. Say what the mask actually buys - fewer tests per
store and a uniform fast path when `acc_mask_is_uniform` holds for
every lane - instead of overclaiming convergence.
@nihalpasham nihalpasham added enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) labels Jul 28, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks,

landed with two maintainer doc commits on top: r

  • restored the feat(cuda-device): derive the m16n8k16 accumulator fragment layout #474 module-doc passages that this branch's context hunks reverted (the replacement linked nonexistent DisjointBlock/DisjointTiling types and broke rustdoc -D warnings), and
  • corrected the 'warp stays convergent' claim - masks differ across lanes, so guarded stores can still diverge; the mask buys fewer tests and a uniform fast path.

The six new predication tests, clippy, and rustdoc -D warnings are all clean. Closes no open issue.

Merging

@nihalpasham
nihalpasham merged commit 13fab63 into NVIDIA:main Jul 28, 2026
33 checks passed
@honeyspoon
honeyspoon deleted the up/mma-fragment-predication branch July 28, 2026 14:02
honeyspoon pushed a commit to honeyspoon/cuda-oxide that referenced this pull request Jul 29, 2026
…t promise

Exploratory work on gap #31 (89 graph FFI entry points, none wrapped). Graph
replay is the largest measured win in the harness — a fixed ~1 µs per launch,
0.170/0.179/0.178 ms across FP16/INT8/W8A16 — and it is currently driven by raw
FFI with `assert_eq!` on every status.

Wraps the minimum useful slice: `begin_capture` -> `StreamCapture` guard ->
`CapturedGraph` -> `GraphExec::launch`, all RAII, all returning `DriverError`.

Two obligations the types now discharge:

* Capture must be terminated even on the error path. The driver documents that an
  invalidated capture leaves the stream unusable until `cuStreamEndCapture` runs,
  and that a capturing blocking stream also makes the legacy null stream
  unusable. The existing raw-FFI code panics via `assert_eq!` between begin and
  end, which skips termination. `StreamCapture` terminates in `Drop`, so
  unwinding cannot poison the stream. Two hardware tests cover it: the stream is
  idle and usable after an abandoned capture, and can be recaptured.
* Concurrent replay of one exec is not permitted, so `launch` takes `&mut self`.

And one it cannot, now measured rather than assumed. A `GraphExec` outliving a
buffer captured into it is undiagnosed and silently plausible:

    launch = Ok(())  sync = Ok(())  read = Ok(())
    dst    = [7, 8, 9, 10]   (captured source was [7, 8, 9, 10])

The replay read freed device memory that still held the old bytes, so it "worked".
No error at launch, synchronize, or read-back. Stream-ordered deallocation
returning pages to a pool makes that the likely presentation, not a rare one, and
it is the worst failure mode available: correct in testing, corrupt later. Because
of that, `instantiate` being `unsafe` is probably the honest default; the module
names the hole and the three ways to close it instead of choosing one.

Findings worth keeping regardless of what happens to this code:

* The doc's "89 FFI entry points" reproduces exactly as `grep -c "pub fn cuGraph"`.
  About 10 of those are `cuGraphics*` GL interop and some are `_v2` aliases, so
  unique true graph-API names are 83. There is no bindgen allowlist, so all of
  them really are reachable.
* This crate resolves module-level intra-doc links against the *crate root*,
  because every module carries both a `///` on its `pub mod` line and `//!` docs
  in the file. `[CudaEvent]` works only because `event::CudaEvent` is re-exported.
  A new module whose types are not re-exported gets broken links that
  `rustdoc -D warnings` rejects — the same class of failure as upstream NVIDIA#511.
  Fixed by following the convention and re-exporting.

Gates on nightly-2026-04-03: fmt, clippy --all-targets -D warnings, rustdoc
-D warnings, doctests clean. `graph_capture` is 4 passed / 1 ignored (the ignored
one is the deliberate use-after-free probe). `cargo test -p cuda-core` has one
failure, `device_copy_derive_compile_pass`, which reproduces identically on an
untouched `main`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants