Skip to content

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

Closed

Description

@feitreim

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:

  1. Re-export or wrap the thread identities. kittens::lane() and
    kittens::warp() (or a pub use cuda_device::warp::{lane_id, warp_id}).
    Wrapping is slightly better than re-exporting: it is the one place a doc can
    say that lane is the argument the whole register surface takes and that
    warp_id() * 32 is a BaseLdtm band origin (see The epilogue that ships is open-coded in both GEMMs; epilogue.rs holds the route that lost #126, where that 32 is
    also open-coded everywhere).
  2. 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::publish already has the
    body and the argument for the ordering; it is unsafe fn publish(self) at
    src/epilogue.rs:398.
  3. Export the tcgen05-before-rendezvous pair, or say in tmem's docs that a
    caller rendezvousing outside pipeline::run owes 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:types

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions