Skip to content

Replace gpu/kittens with ferro-kittens; bump cuda-oxide to 20a5616 - #71

Merged
feitreim merged 2 commits into
mainfrom
feat/issue-66-ferro-kittens
Aug 3, 2026
Merged

feitreim merged 2 commits into
mainfrom
feat/issue-66-ferro-kittens

Conversation

@feitreim

@feitreim feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Closes #66.

gpu/kittens is deleted; gemm, flash-attn and model now take
kittens = { package = "ferro-kittens", git = ..., rev = "caa6075" }, and
cuda-oxide moves b099f64 → 20a5616 in the seven remaining gpu/*
manifests, all lockfiles, modal_app.py:CUDA_OXIDE_REF, and the three SPEC.md
citations (repointed for the live pin, dated for the two historical claims).
The features = ["host"] split is preserved — flash-attn and model enable
it, gemm does not, and gemm still builds without it.

ferro-kittens' [lib] name is still kittens, so no use path changed.
This is the drift-only port the issue asked for: no SharedPlan, no
StoreRing, no kittens::lane(), no mm_*.

Drift fixes, each break → its fix

Anticipated in #66

Break Fix
ldst::store_fragment_bf16 gone ldst::store_fragment — element-generic, E inferred from the SwizzledChunks<Bf16> the tile hands out. 5 call sites.
Semaphore::multicast_alias() removed (ferro#50) tma_sem.at_rank(0), giving a ClusterSemaphore both ranks aim their halves at. Rank 0 alone charges, now charge.across_ranks(2) instead of the hand-written (128*64*2)*4. gemm/src/optimized.rs:60.
pipeline::Job reshaped (ferro#51) No source change needed. RANKS defaults to 1 and init/inval/work are unchanged, so PersistentForward still conforms. run now deals items by %clusterid and takes the boundary at RANKS scope; the persistent forward is not #[cluster_launch], so its cluster is one CTA and both degenerate to the blockIdx.x/sync_threads loop it already had. Documented at the kernel.

Not anticipated — the bulk of the diff

Break Fix
Every tma_load* returns #[must_use] TransactionBytes; expect_tx takes only that, not u32 The hand-written byte counts are gone. Each stage sums the charges the loads handed back and pays that: let charge = k.tma_load(..) + v.tma_load(..); full.expect_tx(charge);. Conditional stages accumulate into a mut charge and pay once, replacing the two-branch if i == 0 { expect_tx(A) } else { expect_tx(B) }. 17 sites. I re-derived every one against the old constant — all agree (Panel 16384 B, PairedPanel box-of-TILE 16384 B, KStage/MnStage 16384 B, cluster stage 65536 B).
tma_load_at gained an uninferrable const BOX_ROWS tma_load_at::<TILE> at 12 sites. This one has a hole — BOX_ROWS scales the returned charge and nothing ties it to the tensor map — so I filed feitreim/ferro-kittens#168 rather than working around it silently.
tma_load_2d_multicast_cg2 takes ClusterSemaphore, not Semaphore Falls out of the at_rank fix above.
RegVec<N> → RegVec<M, L: RowLayout<M>>, RegTile<SLOTS, VALUES> → RegTile<M, N, L> The parameters are logical extents against a layout now, not per-thread counts. Under BaseLdtm, SLOTS = M/8 and VALUES = N/4, so RegVec<4> → RegVec<32, BaseLdtm> and RegTile<4, 32> → RegTile<32, 128, BaseLdtm> — same storage, same registers. .0[slot][value] still indexes, and Fragment keeps its spelling.
reg::value_column(v) removed BaseLdtm::column(lane, v), which is lane_column + value_column(v) in one call; the separate lane_column locals go with it. 4 sites.
RegVec::add_assign removed bin_map_assign::<Add>.
mma_ab/mma_abt/mma_walk_cg2 take MmaShape, not a packed u32 descriptor, and gained a leading E: MmaElement Element, accumulator type and both transpose flags are the operands' and the entry point's own now (mma_abt ⇒ no transpose, mma_ab ⇒ transpose_b, mma_walk_cg2 ⇒ from OperandWalk::transposed) — which is exactly what the 15 Tcgen05InstructionDescriptor::builder() chains were saying by hand, including optimized.rs's transpose_a/b(transposed) (its walks already carry that). All 15 collapse to one shape: MMA_SHAPE = M128_N64 in flash-attn, M128_N128/M256_N256 literals in gemm. Four MMA helpers lose a parameter that had become a constant. mma_walk_cg2::<4> → mma_walk_cg2::<Bf16, 4>.

Net: −2684/+340 lines, and −92 lines in tcgen05.rs alone from the descriptor
builders going away.

Verified locally (macOS, no CUDA toolkit)

cargo check on the GPU crates is impossible on this host and was before this
PR too: all three consumers depend on cuda-host/cuda-core, which pull
cuda-bindings, whose build script wants cuda.h. So:

  • ✅ ferro-kittens itself builds clean at 20a5616 as a dependency, both
    default and via the consumers' resolution.
  • ✅ Every kittens call site type-checks and codegens. I built a scratch
    crate depending only on cuda-device + ferro-kittens and pulled in
    gemm/src/lib.rs (+ its include!d optimized.rs) and
    flash-attn/src/tcgen05.rs by #[path], with #[cuda_module]/#[kernel]
    stripped (those expand to host launchers needing cuda-core) and gemm's
    host module stubbed to its five consts. That is every line the migration
    touched. cargo build — not just check — so post-monomorphization
    const asserts fire
    : I confirmed the harness catches them by breaking one
    on purpose (tma_load_at::<512> ⇒ "a box taller than the tile cannot land
    in it"
    ), then restored it. Clean at HEAD, no warnings beyond the ones the
    attribute stripping itself creates.
  • ✅ cargo fmt --check clean in gpu/gemm and gpu/flash-attn.
  • ✅ cargo test --workspace — 51 CPU tests pass.
  • ❌ Not attempted: Modal / cargo oxide build --arch sm_100a. No B200 run
    was made, so nothing here is validated as PTX or numerically.

Needs the B200 tier

  • cargo oxide build --arch sm_100a for all four kernel crates, then the
    device tests and numeric gates for gemm, flash-attn and model.
  • Register-count re-baselining is expected, not a regression. ferro-kittens
    made this identical cuda-oxide bump in The pin moves to 20a5616, and two doc claims did not survive the audit ferro-kittens#152 with zero
    non-comment Rust changes and still moved 46 of 272 register counts. Any gate
    in bench_util::enforce_kernel_budgets that pins a count should be
    re-baselined against a fresh run rather than read as a regression — and note
    that this PR is not a pure toolchain bump on top of that: the epilogue and
    softmax paths changed shape (RegTile layout parameter, MmaShape), so
    liveness at those call sites is worth a look if a count moves a lot.
  • The at_rank(0) cluster charge in gemm/src/optimized.rs is the one change
    with a runtime failure mode that no host check can reach (an over-charge
    hangs, an under-charge races). Its arithmetic matches the old constant
    exactly, but synccheck on the pair-UMMA GEMM would be the cheap confirmation.

Filed upstream

…nt surface

`gpu/kittens` was frozen at the 2026-07-26 extraction while ferro-kittens took
~167 PRs on top of the same snapshot. Replace it with a pinned git dependency
(`caa6075`) and bump cuda-oxide b099f64 -> 20a5616 in all seven remaining
`gpu/*` manifests, their lockfiles, `modal_app.py`, and the SPEC citations —
the pins have to match, since kittens takes cuda_device/cuda_core types in its
signatures.

ferro-kittens' `[lib] name` is still `kittens`, so no import path moves. What
moved is the surface:

- `ldst::store_fragment_bf16` -> element-generic `store_fragment`.
- `Semaphore::multicast_alias` -> `Semaphore::at_rank(0)`, returning a
  `ClusterSemaphore` that may be arrived at but not waited on. Only rank 0
  charges, now via `TransactionBytes::across_ranks`.
- Every TMA load hands back a `#[must_use]` `TransactionBytes` and
  `expect_tx` takes only that, so the byte counts the kernels wrote by hand
  are gone: the charge is summed from the loads that earned it. Partial-height
  loads need `tma_load_at::<TILE>` (feitreim/ferro-kittens#168).
- `RegVec<N>`/`RegTile<S, V>` count logical rows and columns against a layout
  now, not per-thread slots: `RegVec<32, BaseLdtm>`, `RegTile<32, 128,
  BaseLdtm>`. `value_column(v)` folds into `BaseLdtm::column(lane, v)` and
  `add_assign` into `bin_map_assign::<Add>`.
- `mma_*` derive element, accumulator and both transpose flags from the
  operands and the entry point, so all fifteen instruction-descriptor builders
  collapse to one shape — `MMA_SHAPE` in flash-attn, a literal in gemm — and
  the four MMA helpers lose a parameter that had become a constant.
- `pipeline::Job` gained a defaulted `RANKS` and `run` deals items by
  `%clusterid`; at this kernel's one-CTA cluster both degenerate to the loop
  already written.

Refs #66.
@feitreim

feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

B200 validation of this branch via modal_app.py::main (image rebuilt at cuda-oxide 20a5616):

  • vecadd: ✓ correct — canary for the new codegen backend rev.
  • gemm: ✓ fp32 + tcgen05 bf16 store/accumulate parity. ptxas: both optimized kernels 48 regs, 0 spill, maxntid 1024. This exercises the pair-UMMA path, so the at_rank(0) + across_ranks(2) cluster charge and the walk-derived transpose bits are numerically confirmed — the two changes host checks couldn't reach.
  • flash-attn: ✓ forward parity (sync/pipelined/persistent, y and lse vs both oracles, max abs err ≤ 2.3e-3) and backward parity at [1,128,2,128], [2,256,3,128], [1,1024,4,128] (dq/dk/dv ≤ 5.4e-3).

Runs: ap-owYWr892pYYBZqaCahe1hQ, ap-YrcTroJBwmzbkqCVIyG25f, ap-5pAv26D3Lo17moalcNyxsw. Review of the diff itself is on the issue thread's side: charge sums reproduce the old byte constants, RegVec/RegTile re-parameterizations preserve per-thread storage, no hand-counted expect_tx remains outside transpose_probe.rs (which bypasses kittens by design).

Not drift from the kittens swap — `gpu/model/src/bin/sample.rs` is byte
identical to main here and has not compiled since 0ec4ad6 (2026-07-23), which
added the `L` layer count and split `GpuDenseWorkspace` into
`GpuMoeWorkspace`. Nothing builds this binary: `modal_app.py` runs `train` and
`profile`, and no host without a CUDA toolkit can `cargo check` it, so the
arity rotted in silence for three days before ferro-kittens existed.

`checkpoint::load` takes thirteen const generics and was given twelve;
`GpuDenseWorkspace` takes eight and was given eleven, and is not what
`GpuDense::forward` accepts anyway. Follow train.rs: `GpuMoeWorkspace` with
`L`, and the canonical 12-block MoE configuration both other bins run — the
old 1_536-wide/64-head numbers would have failed the checkpoint header check
at runtime even once the types lined up.

Refs #66.
@feitreim

feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

Pushed a466aa1 — fixes gpu/model/src/bin/sample.rs, which a downstream agent found not compiling on this branch.

It is not drift from this PR. Worth stating plainly, because the B200 validation above stands and I don't want this read as a hole in it:

  • sample.rs on this branch is byte-identical to origin/main (git diff origin/main -- gpu/model/src/bin/sample.rs was empty before this commit). The kittens sweep didn't miss it; there was nothing kittens-shaped in it to miss. grep -rn "Reg[VT]\|kittens::" gpu/model/src returns nothing.
  • It has been broken since 0ec4ad6 (2026-07-23), "multi-block MoE model — L-deep GpuBlock stack", which added the L const generic and split GpuDenseWorkspace into GpuMoeWorkspace. That is three days before ferro-kittens' first commit and well before this branch existed.
  • It survived because nothing builds it: modal_app.py builds train and profile, and no host without a CUDA toolkit can cargo check the model crate at all (cuda-host → cuda-bindings → cuda.h).

The two arity errors and the fix

expected supplied
checkpoint::load 13 const generics (…, C, L) 12 — no L
GpuDenseWorkspace 8 (N, NP, T, VOCAB, VP, D, H, FF) 11 — still carrying E, K, C

The third error is the knock-on: GpuDense::forward takes &mut GpuMoeWorkspace<N, NP, T, VOCAB, VP, D, H, FF, E, K, C, L>, so the workspace was the wrong type, not just the wrong arity. Fixed by following train.rs exactly — GpuMoeWorkspace with L, and load given its L.

I also aligned the config block to the canonical 12-block MoE that train.rs and profile.rs both run (D=3_072, HD=128, FF=4_096, C=6_144, L=12, B=12, T=2_048). The old 1_536-wide / 64-head / C=8_192 numbers are the pre-MoE shape; leaving them would have compiled and then failed checkpoint::load's header check at runtime against any checkpoint train.rs writes, which is the only kind this binary samples.

Verification

cargo check still can't reach the bins on this host, so I wrote a source-level const-generic arity checker instead — the bug class is decidable without a toolchain. It reads every generic item defined in a crate's own sources, then compares against every turbofish naming it in that crate's src/bin, honouring defaults (GpuMoeWorkspace's L = 1):

$ python3 arity.py .          # on main's sample.rs
gpu/model/src/bin/sample.rs:86: load takes 13 generic arguments, 12 supplied
gpu/model/src/bin/sample.rs:96: GpuDenseWorkspace takes 8 generic arguments, 11 supplied
arity check: FAIL

$ python3 arity.py .          # after a466aa1
arity check: clean

Clean across all of gemm, flash-attn and model's bins, so sample.rs was the only instance of this class. The kittens drift harness still builds the branch clean too (gemm/src/lib.rs + optimized.rs + flash-attn/src/tcgen05.rs, codegen included).

The checker lives in my scratchpad, not in this diff — the repo has no CI and no scripts/, so a committed script wouldn't actually prevent recurrence without somewhere to run it. Say the word and I'll land it wherever you want it hooked up; otherwise the diff here stays surgical, one file, +12/−11.

Still unverified by me: sample.rs compiling for real, and running. It needs the CUDA toolchain, and it is the one binary no Modal path builds — if it's worth keeping working, it's worth adding to modal_app.py's build set.

@feitreim

feitreim commented Aug 3, 2026

Copy link
Copy Markdown
Owner Author

Follow-up verification of a466aa1: ran modal_app.py::dump_ptx --kernel model on the branch, which cargo oxide builds every model bin at sm_100a. sample compiled — rustc's per-target summary (model (bin "sample") generated 91 warnings) only prints on successful compilation, and the log contains no errors. (The Modal client dropped mid-PTX-dump after the build, so no PTX text was retained — irrelevant to the fix.) With that, the last unverified binary in this PR is confirmed building. Worth considering separately: adding model to the Modal build set so this bin can't rot invisibly again — it was broken on main since 2026-07-23 for exactly that reason.

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.

Replace gpu/kittens with ferro-kittens; bump cuda-oxide to 20a5616

1 participant