Skip to content

Examples crate: kernels written against the API we want - #20

Merged
feitreim merged 4 commits into
mainfrom
issue-18-examples
Jul 27, 2026
Merged

feitreim merged 4 commits into
mainfrom
issue-18-examples

Conversation

@feitreim

Copy link
Copy Markdown
Owner

Four kernels, each with a header stating compiles or aspirational, and
examples/README.md collecting the API surface all four demand that does not
exist yet.

Its own workspace like device-tests, so cargo at the root never sees it.
Each aspirational kernel sits behind its own feature and is off by default, so
everything in the default build genuinely compiles and a reader can tell the two
apart without running anything. Turning a feature on prints that kernel's gap
list as compiler errors, at the call sites that want it.

Kernel Status Blocked on
gemm compiles — (three gaps worked around in-file, all fenced and marked)
flash_forward aspirational #5, #6, #7, #11 + 3 unfiled
softmax aspirational #5, #6, #9 + 2 unfiled
layernorm aspirational #3, #5, #6, #9, #13 + 3 unfiled

Verification

modal run modal_app.py::build passes: cargo check --features host --all-targets, the host tests, cargo oxide build device-tests --arch sm_100a,
and a new cargo oxide build kittens-examples --arch sm_100a. gemm really
builds
— that last step is the only thing that catches post-monomorphization
const { assert!(..) } failures. It has not been run: this issue needs no
GPU, so treat it as a statement about expressiveness, not a numerical result.
The 2-CTA operand split is the first thing to check on hardware.

cargo fmt --check and cargo clippy clean. Confirmed that every error the
aspirational kernels produce is an unresolved import, a missing method, or an
unsatisfied FragmentLayout bound — nothing in those files fails for any reason
other than the API not existing.

The part worth reading

Nine things the kernels needed that no open issue covers, in
examples/README.md. The top four:

  1. There is no shared → register path at all. ldst is store-only. Any
    kernel whose input is not an MMA operand — every normalization, activation,
    elementwise epilogue — cannot start. Softmax is four lines of algorithm and
    is blocked before the first one.
  2. The movers are per-[16,16]-block. fragment_tile and store_fragment
    force every kernel to rewrite the same block-composition loop. reg.rs's own
    test states that composition as an invariant, and then no function implements
    it.
  3. SwizzledChunks cannot span stacked subtiles, so only 64-wide bf16 tiles
    have a register → shared path at all.
  4. The RegTile shape set is closed by a macro inside src/reg.rs; flash
    cannot name its [32, 64] score band out of tree.

Plus: no cluster-scope TMEM allocation, no cluster-scope semaphore arrival,
pipeline::run cannot schedule a cluster (its work items are blockIdx.x
strided, so a pair gets different items), and multicast has no geometry to live
in — under a 2-CTA UMMA both operands are already split, so
tma_load_2d_multicast_cg2 has nothing to broadcast.

Two corrections to filed issues: #7's make_causal needs a coordinate origin it
is not filed with (make_causal_at(lane, query_base, key_base, fill)), and #8
is why this crate ships no host launcher — encode_bf16_panels builds 3-D panel
maps and both the GEMM's 2-D operands and layernorm's parameter vectors want
another shape.

And a negative result worth as much: #12 (MMA coverage) was not demanded by
any of the four.
mma_abt, mma_ab and mma_walk_cg2 covered every multiply
in the layouts they wanted. The MMA layer is the finished part of this library.

Note on the root manifest

autoexamples = false is required: examples/ is one of cargo's own target
directory names and exclude does not stop target auto-discovery, so without it
examples/src/main.rs gets compiled as an example target of the library,
against the library's dependencies. (Caught the hard way.) The package is named
kittens-examples because cargo forbids examples as a binary target name.

Closes #18

feitreim added 4 commits July 27, 2026 16:55
Its own workspace, like device-tests, so cargo at the root never sees it and
an aspirational kernel cannot break the library's build. Aspirational kernels
sit behind per-kernel features and are off by default, so anything in the
default build genuinely compiles and the two kinds are distinguishable without
running anything.

gemm is the first thing to exercise the cta_group::2 path: a CTA pair shares
one M256_N128 UMMA, K is software-pipelined over a SharedTileRing pair with
SemaphoreRing owning the parity arithmetic, and `free` is released by the MMA's
own commit rather than by a thread. It builds under `cargo oxide build
kittens-examples --arch sm_100a`; it has not been run.

Three things it had to reach past the library for, each fenced and marked in
the file: cluster-scope TMEM allocation (alloc_block is cta_group::1),
cluster-scope semaphore arrival (Semaphore is CTA-scoped, so the peer's TMA
cannot complete on the leader's barrier), and a global store from registers
(#11). None has an open issue.

The root manifest needs `autoexamples = false`: `examples/` is one of cargo's
own target directory names and `exclude` does not stop target auto-discovery,
so without it `examples/src/main.rs` is compiled as an example target of the
library, against the library's dependencies.
Only the kernels marked *compiles* are in the default feature set, so a real
`cargo oxide build --arch sm_100a` of this crate is what keeps that claim
honest -- a post-monomorphization `const { assert!(..) }` in a tile shape is
invisible to `cargo check`.
Each names the API it wants at the call site that wants it, with the issue
numbers it is blocked on in its header. Verified that every resulting compiler
error is an unresolved import, a missing method, or an unsatisfied
FragmentLayout bound -- nothing in these files fails for any reason other than
the API not existing.

What they turned up beyond the filed backlog: there is no shared -> register
path at all, so softmax cannot get past its first line; the movers are
per-[16, 16]-block, so every kernel rewrites the same composition loop;
SwizzledChunks refuses tiles wider than one swizzle atom, so a [128, 128] tile
has no register -> shared path; and the RegTile shape set is closed by a macro
inside src/reg.rs, so flash cannot name its [32, 64] score band out of tree.

#7's make_causal also needs a coordinate origin it is not filed with: a flash
kernel masks a band whose diagonal sits at query_base - key_base.
Grouped and mapped to issues, with the nine things no open issue covers called
out separately -- that last set is the part of the backlog derived from trying
to write a kernel rather than from reading ThunderKittens' feature list.

Two negative results worth as much as the gaps: #12 (MMA coverage) was not
demanded by any of the four, and multicast has no geometry to live in -- under
a 2-CTA UMMA both operands are already split across the pair, so
tma_load_2d_multicast_cg2 has nothing to broadcast and the GEMM cannot use it.
@feitreim
feitreim merged commit b9c26c3 into main Jul 27, 2026
@feitreim
feitreim deleted the issue-18-examples branch July 27, 2026 21:19
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.

Examples crate: kernels written against the API we want, compiling or not

1 participant