Skip to content

Name the lane, the warp and the proxy fence (#127) - #135

Merged
feitreim merged 1 commit into
mainfrom
issue-127-identities-and-proxy-fence
Jul 29, 2026
Merged

feitreim merged 1 commit into
mainfrom
issue-127-identities-and-proxy-fence

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Closes #127 (GAPS.md §7.2). Three names, +186 net lines, most of them doc.

new where what it wraps
kittens::lane() src/lib.rs cuda_device::warp::lane_id()
kittens::warp_id() src/lib.rs cuda_device::warp::warp_id()
kittens::shared::publish_to_async_proxy() beside tma_store_commit fence_proxy_async_shared_cta()

The three decisions the issue asked for

1. Wrappers, not pub use — and warp_id(), not the warp() the issue
proposed.
The issue's argument for wrapping is that the wrapper is the one
place a doc can say what the value is for, and I took it: lane()'s doc says
it is the lane argument the whole register surface takes and cites the
hoisting convention device-tests' lane probe priced; warp_id()'s says
32 * warp_id() is a BaseLdtm band origin and that it is threadIdx.x / 32
and so 1-D-block-only.

I did not take the spelling. warp() is legal beside cuda_device::warp —
modules live in the type namespace and functions in the value namespace, and I
compiled a four-line probe to confirm it rather than assume — so this is a
readability call and nothing else. Against it: experiments/src/gemm.rs already
does use kittens::epilogue::{StoreRing, Warp} and calls warp::sync_mask, so
warp() would put three unrelated warps in one file's imports. For it:
symmetry with lane(). warp_id is what the crate already calls this value —
tmem.rs's tile::<32, N>(32 * warp_id, 0), both GEMMs' warp_id: u32 field,
device-tests' dump_band(tile, warp_id, lane, out) — and lane is what every
signature already calls the other, so each name matches the identifier at its
use site. The asymmetry is deliberate.

2. The fence is exported as shared::publish_to_async_proxy(), in shared
because that is where tma_store and the two store waits live and where three
kernels already import from. StoreRing::publish now calls it, so there is one
body. Its doc states the two-proxy rule, that it orders the executing thread's
writes and is not a barrier, and the two cases where it is not owed —
tma_load → tma_store, and block_reduce's scratch — both quoted from
contracts already in the tree rather than newly reasoned.

Eight safety contracts state the obligation and all eight now name the function
(ldst: store_fragment, store_fragment_x4, store_tile, store_tile_x4,
store_vec; shared: SharedTile::tma_store, SharedVec::set,
SharedVec::tma_store). block_reduce's, which states the fence is not owed,
names it too, so both sides of the question use one vocabulary.

3. The tcgen05 fence + cluster_sync pair: no, and here is the argument. It
stays two lines, documented on tmem::dealloc_cluster (the issue's stated
alternative) with the two-line snippet, a pointer to pipeline::run as the
place that already performs it, and dealloc_block pointing at the same
paragraph for the block-scope form.

  • It is not one thing. The fence retires tcgen05 work and belongs to this
    crate. The rendezvous is a scope choice — pipeline::boundary already
    branches cluster_sync/sync_threads on J::RANKS. Exporting them welded
    fixes the scope, and that is a fifth spelling of scope beside the four §7.1
    counts, added at the moment Scope is named in the type in exactly one place, and spelled three other ways #124 is about to unify them.
  • It closes no leak. All three call sites (examples/src/gemm.rs:679,
    experiments/src/gemm.rs:2849, experiments/src/gemm_ws.rs:1156) sit in
    files that import cuda_device::cluster for block_rank()/cluster_idx()
    anyway — I grepped all three. It would remove one use line
    (tcgen05_fence_before_thread_sync) and no dependency.

Callers

softmax, layernorm and flash_forward lose cuda_device::warp and
cuda_device::barrier::fence_proxy_async_shared_cta entirely — 7 fence sites,
which is the issue's count, and 8 identity ones. The three GEMMs lose the
identity calls and keep
cuda_device::warp for warp::sync_mask, which the issue itself names as
#126's. After this, warp::lane_id() and warp::warp_id() appear nowhere in
src/, examples/ or experiments/ except in the two wrapper bodies —
established by grep -rn "warp::lane_id\|warp::warp_id\|fence_proxy_async_shared_cta"
over all four trees, which returns src/lib.rs:73, src/lib.rs:90 and
src/shared.rs:868 and nothing else.

The library now uses its own three: epilogue::Warp::issuing, sync::block_reduce,
tmem's five warp_id() == 0 guards, and pipeline::run's two fences.

flash_forward.rs's header claim — "Nothing in this file reaches past the
library any more"
, which #127 filed as false — is corrected rather than
deleted: it now names what was false, what fixed it, and what still reaches past
(the shared plan, #125/#85; thread, #124; the kernel ABI).

device-tests/ is deliberately untouched. It is not one of the five kernels
§7.2 is about, it reaches past the library on purpose, and lane_probe at
device-tests/src/main.rs:3547 and :3620 measures warp::lane_id()'s
lowering — routing it through a wrapper would change the subject of a probe
whose whole point is the intrinsic. Several dozen mechanical sites; a follow-up
if wanted.

Verification — what I ran, and what it showed

gate result
scripts/fmt --check (four manifests) clean
cargo clippy --all-targets -- -D warnings clean
cargo test 94 + 1 pass
RUSTDOCFLAGS=-D warnings cargo doc --no-deps clean
scripts/modal-run build passes; only pre-existing warnings (missing_safety_doc, manual_is_multiple_of in experiments/)
scripts/modal-run regcount identical to main — see below
scripts/modal-run examples gemm/softmax/layernorm pass in examples/, gemm/gemm_ws pass in experiments/, both check sizes, all traversal widths

The regcount diff, and how it was taken. Two runs of scripts/modal-run regcount from this same worktree: one with the branch applied, one after
git stash put the tree back at f5e9735. Both outputs were sliced from the
first kernel regs spill st … header to EOF (386 lines each) and diffed;
after dropping the Modal app URL and one interleaved Stopping app line, the
diff is empty.
That covers all three crates' ptxas tables, the register
ladder, the per-spelling cliff table, #63's timed twins and #95's occupancy-step
gate. No count moved, so _ctas_by_registers never had to be consulted.

That is the result I expected and the reason to expect it is in the lowering:
lane_id is #[inline(never)] upstream and is the codegen backend's lowering
target, warp_id is #[inline(always)] over threadIdx_x() / 32, and
fence_proxy_async_shared_cta is #[inline(never)]. Every wrapper here is
#[inline(always)] around one call to one of those, so there is nothing for a
register allocator to see. The empty diff is the evidence; this paragraph is
only why it is not a surprise.

What I could not establish

  • ldst::load_fragment's safety contract (src/ldst.rs:212) may be wrong,
    and I left it alone.
    It says a tile whose bytes arrived by stmatrix needs
    a fence.proxy.async.shared::cta before ldmatrix reads it. Both of those
    are generic-proxy accesses, so by the rule the rest of the crate states — and
    that publish_to_async_proxy's new doc states — that fence is not the
    ordering for that pair. I did not touch the line, did not point it at the new
    name, and cannot test it here; it wants its own issue and a B200.
  • The issue's first acceptance criterion is not literally met.
    grep -c cuda_device examples/src/softmax.rs is 4 before and 4 after: the
    fence shared its use line with Barrier, which belongs to A kernel's shared plan is entirely open-coded, in bytes, twice per kernel #125's shared
    plan. What went down is the symbol count, 8 → 6 in softmax, 9 → 7 in
    layernorm and flash_forward. In flash_forward.rs the line count goes
    4 → 5 because the corrected header paragraph says the words cuda_device.
    The second criterion — no kernel importing cuda_device::warp only to feed a
    kittens call — is met.
  • Nothing here was timed. regcount says no instruction moved and
    examples says every kernel still computes; neither is a throughput
    measurement, and I did not run bench.
  • I did not verify the kernel crates compile locally — cuda-bindings wants
    cuda.h and this machine has no toolkit. scripts/modal-run build is the
    only compile evidence for examples/ and experiments/ in this PR.

Ownership

Touches no SHARED_BYTES, shared_plan, pointer walk, DynamicSharedArray
call, *mut Barrier cast or ClcQueue alignment block — #125's ground. The
only lines changed inside attach are the two identity bindings and the two
struct fields that take them.

The library took a `lane: u32` at every warp-scope entry point and exposed no
way to obtain one, and eight safety contracts stated a
`fence.proxy.async.shared::cta` obligation while the only thing that issued
that fence was the private `StoreRing::publish`. So all five kernels opened
with `use cuda_device::warp`, and three imported `cuda_device::barrier` for one
instruction.

`kittens::lane()`, `kittens::warp_id()` and `shared::publish_to_async_proxy()`
are those three. Wrappers rather than re-exports: the wrapper is the one place
a doc can say that `lane` is the argument the whole register surface takes,
that `32 * warp_id()` is a `BaseLdtm` band origin, and that a barrier after
the fence is what carries one thread's ordering to the thread that issues the
store. The contracts that create the obligation now name the function that
discharges it, and the library uses its own three internally: `epilogue`,
`sync`, `tmem` and `pipeline` no longer reach for `cuda_device::warp` or the
raw fence.

`warp::lane_id()` and `warp::warp_id()` are called nowhere in the repo outside
`device-tests` but in the bodies of the two wrappers. `softmax`, `layernorm`
and `flash_forward` drop `cuda_device::warp` and the raw fence import
outright; the three GEMMs keep `cuda_device::warp` for `warp::sync_mask` and
nothing else, which is #126's.

The tcgen05 fence + `cluster_sync` pair stays two lines, documented on
`tmem::dealloc_cluster` rather than exported. The fence is tcgen05's and the
rendezvous is a scope choice; welding one scope in would add a fifth spelling
of scope beside the four GAPS.md 7.1 counts, and it would close no leak, since
a kernel calling `cluster_sync` there already imports `cuda_device::cluster`
for `block_rank`.

`regcount` is identical to a run on f5e9735 — all 386 table lines — and
`examples` passes on a B200.
@feitreim
feitreim merged commit 3236455 into main Jul 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Every register-side entry point takes a lane the library gives no way to obtain

1 participant