Skip to content

Handle constructors, the unsafe boundary, the load/store verbs and the root re-exports each pick two conventions #129

Open

Description

@feitreim

Found by the 2026-07-29 library audit (GAPS.md §7). Pure surface consistency —
no behaviour is wrong, but a new user meets all of this in the first ten minutes.

1. Two names for one operation

Every handle in the crate is "a raw base plus a compile-time shape, whose
validity the caller promises". Half of them spell that from_raw and half spell
it attach, and the split is not by kind:

from_raw attach
SharedTile, SharedVec, GlobalRows, TmemTile SharedTileRing, StoreRing, Semaphore, PhasedSemaphore, SemaphoreRing, ClcQueue

"Rings use attach" is the obvious rule and it is false — Semaphore and
PhasedSemaphore are not rings. The real split is by module (shared/global/
tmem against sync/epilogue/pipeline), except that SharedTileRing lives
in shared.rs and uses attach.

2. The unsafe boundary disagrees between the two tile types

SharedTile::from_raw is unsafe. TmemTile::from_raw is safe, and so are
TmemTile::at, columns_right and split_columns — which can name a segment
past the end of an allocation, a case split_columns' own doc says has "no
diagnostic: the two MMAs simply write each other's accumulator."

Neither function dereferences anything, so "unsafe iff it dereferences" is not
the rule. Nor is "unsafe iff a wrong argument is UB", because
StoreRing::buffer is safe and hands out a tile the TMA engine may still be
reading (documented: "writing through this handle is writing to whatever the
engine may still be reading"
). There may be a good rule here — plausibly a
pointer's provenance is a safety obligation and a TMEM address is a device
resource with no Rust aliasing story
— but it is not written down anywhere, and
without it the two tile types read as an oversight.

3. Load and store are named asymmetrically, in both directions

read write
ldst (shared ↔ register) load_fragment, load_tile, load_vec store_fragment, store_tile, store_vec
tmem (TMEM ↔ register) fragment, fragment_tile, tile store_fragment, store_fragment_tile, store_tile

The TMEM read direction has no verb, so TmemTile::tile and ldst::load_tile
are the same operation at two sources under two names — and TmemTile::store_tile
and ldst::store_tile are the same name at two sources, which is the pairing
that reads correctly.

The instruction-width suffixes then mean two different things:

  • ldst::store_fragment_x4 — one fragment, through one stmatrix.x4.
  • TmemTile::fragments_x8 — four fragments, through one tcgen05.ld.x8.

Both suffixes name the instruction, correctly, and a reader who learns one will
guess the other's arity wrong.

4. The root re-export set does not let you write a program

src/lib.rs re-exports ReduceOp but not Add, Max, Mul or Min — the
only four types that implement it — so tile.row_reduce::<Add>() needs
kittens::reg::Add while ReduceOp is at the root. Likewise:

  • ldst::load_tile takes a SwizzledChunks, which is not re-exported.
  • No free function is re-exported at all: ldst::*, mma::*, tmem::alloc_*,
    global::store_rows, reg::quad_reduce, pipeline::{Job, run, grouped}.
  • SharedTileRing is at the root; StoreRing's peer ClcQueue is not.

The result is that use kittens::* gives you types you cannot operate on. Either
a deliberate prelude or a stated rule ("types at the root, verbs in their
modules") would fix it; today it is neither.

Scope

Pick one convention for each of the four and sweep. Suggested, but the point is
that a choice is made and written in lib.rs:

  1. attach everywhere (it reads better for "lay a type over memory the kernel
    owns") or from_raw everywhere.
  2. Write the unsafe rule down in lib.rs and make TmemTile obey it.
  3. Add the verb to the TMEM read direction (load_tile, load_fragment), keep
    the width suffixes, and say in each doc how many fragments the instruction
    covers.
  4. A kittens::prelude with the op structs and the movers in it.

Estimate

~100 lines of renames plus call-site sweeps in examples/ and device-tests/.
Cheap, mechanical, and it is the kind of change that gets more expensive with
every kernel written against the current spelling — which is the same argument
§1.1 made for doing scope early, and lost.

Related: #124 (the other half of "what does the surface say about itself"), #127
(the root surface does not include the thread identities either).

Activity

  1. added
    area:types
    on Jul 29, 2026
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