Repository navigation
Description
Found by the 2026-07-29 library audit (GAPS.md §7). The smallest finding in
the audit and probably the cheapest fix in the repo.
A kernel cannot call one register-side function without importing cuda_device
Every warp-scope entry point in kittens takes the lane as a parameter —
ldst::load_tile(chunks, row, column, lane), ldst::store_tile(.., lane, tile),
ldst::load_vec(vec, lane), global::store_rows(.., lane, tile),
RegTile::mask(lane, ..), RegVec::row(lane, slot) — and the library exposes
no way to obtain one. It uses cuda_device::warp::lane_id() internally in
sync.rs:550 and epilogue.rs:182, and re-exports neither it nor warp_id().
So all five kernels open with the same import and the same three lines:
lane_id() |
warp_id() |
|
|---|---|---|
gemm.rs |
2716 | 2715 |
gemm_ws.rs |
1129 | 1128 |
softmax.rs |
280 | 279 |
layernorm.rs |
219, 334 | 220, 335 |
flash_forward.rs |
252 | 251 |
This makes flash_forward.rs:133's claim — "Nothing in this file reaches past
the library any more" — false in the first three lines of its kernel body.
(That file is examples/ and not fixable here; noted so the correction is not
lost.)
The library creates a fence obligation and does not export the fence
ldst::store_fragment's safety contract says the caller "owes a
fence.proxy.async.shared::cta before any MMA or TMA reads the tile", and
SharedTile::tma_store's says the same. The only thing in the crate that issues
that fence is StoreRing::publish, which is private. So the obligation is
created by a kittens function and discharged by a cuda_device one, at seven
sites across the three small kernels, each with an identical explanatory comment
(softmax.rs:349-350, layernorm.rs:297-299 and 369-371).
And one protocol pair that is performed internally and not exported
tcgen05_fence_before_thread_sync() immediately followed by
cluster::cluster_sync() appears at gemm.rs:2133, gemm.rs:2847 and
gemm_ws.rs:1154. pipeline::run performs exactly this pair
(src/pipeline.rs:339 + boundary), and tmem::alloc_cluster performs the
sync_threads + cluster_sync half (src/tmem.rs:186-187). A kernel that
rendezvouses outside run — which both GEMMs do, before dealloc_cluster —
has to know the pairing and spell it.
Scope
Three small things, none of which changes a signature:
- Re-export or wrap the thread identities.
kittens::lane()and
kittens::warp()(or apub use cuda_device::warp::{lane_id, warp_id}).
Wrapping is slightly better than re-exporting: it is the one place a doc can
say thatlaneis the argument the whole register surface takes and that
warp_id() * 32is aBaseLdtmband origin (see The epilogue that ships is open-coded in both GEMMs; epilogue.rs holds the route that lost #126, where that32is
also open-coded everywhere). - Export the proxy fence as something named for what it is for —
shared::publish_to_async_proxy()or similar — so the contract and its
discharge are in the same vocabulary.StoreRing::publishalready has the
body and the argument for the ordering; it isunsafe fn publish(self)at
src/epilogue.rs:398. - Export the tcgen05-before-rendezvous pair, or say in
tmem's docs that a
caller rendezvousing outsidepipeline::runowes it.
Acceptance
grep -c cuda_device examples/src/softmax.rs goes down rather than a kernel
being rewritten around it, and no kernel imports cuda_device::warp only to
feed a kittens call. tests/gaps.rs names whatever the identities become.
Related: #124 (scope — issuing()/converge() are the collective form of the
same question), #126 (the epilogue loop, whose warp::sync_mask is a fourth
instance of this).
Activity
Name the lane, the warp and the proxy fence (#127) (#135)
The drains dispatch on the ladder's byte count again, and the jump ta…