Repository navigation
Name the lane, the warp and the proxy fence (#127) - #135
Merged
Merged
Conversation
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.
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.
Closes #127 (
GAPS.md§7.2). Three names, +186 net lines, most of them doc.kittens::lane()src/lib.rscuda_device::warp::lane_id()kittens::warp_id()src/lib.rscuda_device::warp::warp_id()kittens::shared::publish_to_async_proxy()tma_store_commitfence_proxy_async_shared_cta()The three decisions the issue asked for
1. Wrappers, not
pub use— andwarp_id(), not thewarp()the issueproposed. 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 saysit is the
laneargument the whole register surface takes and cites thehoisting convention
device-tests'lane probepriced;warp_id()'s says32 * warp_id()is aBaseLdtmband origin and that it isthreadIdx.x / 32and so 1-D-block-only.
I did not take the spelling.
warp()is legal besidecuda_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.rsalreadydoes
use kittens::epilogue::{StoreRing, Warp}and callswarp::sync_mask, sowarp()would put three unrelatedwarps in one file's imports. For it:symmetry with
lane().warp_idis what the crate already calls this value —tmem.rs'stile::<32, N>(32 * warp_id, 0), both GEMMs'warp_id: u32field,device-tests'dump_band(tile, warp_id, lane, out)— andlaneis what everysignature 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(), insharedbecause that is where
tma_storeand the two store waits live and where threekernels already import from.
StoreRing::publishnow calls it, so there is onebody. 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, andblock_reduce's scratch — both quoted fromcontracts 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_syncpair: no, and here is the argument. Itstays two lines, documented on
tmem::dealloc_cluster(the issue's statedalternative) with the two-line snippet, a pointer to
pipeline::runas theplace that already performs it, and
dealloc_blockpointing at the sameparagraph for the block-scope form.
crate. The rendezvous is a scope choice —
pipeline::boundaryalreadybranches
cluster_sync/sync_threadsonJ::RANKS. Exporting them weldedfixes 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.
examples/src/gemm.rs:679,experiments/src/gemm.rs:2849,experiments/src/gemm_ws.rs:1156) sit infiles that import
cuda_device::clusterforblock_rank()/cluster_idx()anyway — I grepped all three. It would remove one
useline(
tcgen05_fence_before_thread_sync) and no dependency.Callers
softmax,layernormandflash_forwardlosecuda_device::warpandcuda_device::barrier::fence_proxy_async_shared_ctaentirely — 7 fence sites,which is the issue's count, and 8 identity ones. The three GEMMs lose the
identity calls and keep
cuda_device::warpforwarp::sync_mask, which the issue itself names as#126's. After this,
warp::lane_id()andwarp::warp_id()appear nowhere insrc/,examples/orexperiments/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:90andsrc/shared.rs:868and nothing else.The library now uses its own three:
epilogue::Warp::issuing,sync::block_reduce,tmem's fivewarp_id() == 0guards, andpipeline::run's two fences.flash_forward.rs's header claim — "Nothing in this file reaches past thelibrary 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_probeatdevice-tests/src/main.rs:3547and:3620measureswarp::lane_id()'slowering — 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
scripts/fmt --check(four manifests)cargo clippy --all-targets -- -D warningscargo testRUSTDOCFLAGS=-D warnings cargo doc --no-depsscripts/modal-run buildmissing_safety_doc,manual_is_multiple_ofinexperiments/)scripts/modal-run regcountmain— see belowscripts/modal-run examplesgemm/softmax/layernormpass inexamples/,gemm/gemm_wspass inexperiments/, both check sizes, all traversal widthsThe regcount diff, and how it was taken. Two runs of
scripts/modal-run regcountfrom this same worktree: one with the branch applied, one aftergit stashput the tree back atf5e9735. Both outputs were sliced from thefirst
kernel regs spill st …header to EOF (386 lines each) anddiffed;after dropping the Modal app URL and one interleaved
Stopping appline, thediff 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_registersnever had to be consulted.That is the result I expected and the reason to expect it is in the lowering:
lane_idis#[inline(never)]upstream and is the codegen backend's loweringtarget,
warp_idis#[inline(always)]overthreadIdx_x() / 32, andfence_proxy_async_shared_ctais#[inline(never)]. Every wrapper here is#[inline(always)]around one call to one of those, so there is nothing for aregister 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
stmatrixneedsa
fence.proxy.async.shared::ctabeforeldmatrixreads it. Both of thoseare 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 theordering 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.
grep -c cuda_device examples/src/softmax.rsis 4 before and 4 after: thefence shared its
useline withBarrier, which belongs to A kernel's shared plan is entirely open-coded, in bytes, twice per kernel #125's sharedplan. What went down is the symbol count, 8 → 6 in
softmax, 9 → 7 inlayernormandflash_forward. Inflash_forward.rsthe line count goes4 → 5 because the corrected header paragraph says the words
cuda_device.The second criterion — no kernel importing
cuda_device::warponly to feed akittenscall — is met.regcountsays no instruction moved andexamplessays every kernel still computes; neither is a throughputmeasurement, and I did not run
bench.cuda-bindingswantscuda.hand this machine has no toolkit.scripts/modal-run buildis theonly compile evidence for
examples/andexperiments/in this PR.Ownership
Touches no
SHARED_BYTES,shared_plan, pointer walk,DynamicSharedArraycall,
*mut Barriercast orClcQueuealignment block — #125's ground. Theonly lines changed inside
attachare the two identity bindings and the twostruct fields that take them.