Skip to content

Evaluate/port gpu/ops and gpu/tensor-gpu kernels onto ferro-kittens tiles — measure first #70

Open

Description

@feitreim

Blocked on #66. Evaluate and, where the measurement says yes, rewrite the gpu/ops and gpu/tensor-gpu kernels on ferro-kittens tiles. Unlike gemm/flash-attn these crates don't currently depend on kittens at all, so this is adoption, not migration — and the standing rule applies: port where tiles win on the clock, not for uniformity. Measure first.

Inventory, grouped by likely outcome

Ferro-kittens has a direct reference — port these first:

  • rms_norm_forward / _fast / backward family → ferro's examples/src/layernorm.rs (SharedVec-staged γ/β via ldst::load_vec, block_reduce for the row statistic, TMA store).
  • softmax_forward, cross_entropy_loss, softmax_cross_entropy_backward, fused_classifier_* → ferro's examples/src/softmax.rs (row_max/row_sum, online_rescale, Exp2*). Note ferro Flash HD=128 follow-ups: persistent stream-B regression + M64 operand-K mispairing (M128 waste) #47's finding for this family: softmax is shared-memory-capped, so register streaming that helps elsewhere cost 2.6× there — which resource is binding decides the shape.

Plausible but unproven — measure a tile version against the current one before committing:

  • swiglu_forward/_bf16/backward, rope_forward/rope_backward — bandwidth-bound elementwise; a tile pass buys vectorized 16-byte access (store_shared_rows-style) but the current flat kernels may already be at bandwidth. If the probe says no win, close that half with the numbers attached.

Probably not tile-shaped — justify inclusion, don't assume it:

  • embedding_forward/backward, moe_gather_*, router_backward_weight, split_group* — gather/scatter with no dense tile structure.
  • All of tensor-gpu (adamw, muon_apply_bf16, ema_momentum, conversions, fills) — optimizer-state streaming; bandwidth-bound by construction.
  • attention_probabilities / attention_output / attention_backward_* — the non-flash attention path; gpu/model/src/lib.rs no longer references it. Confirm it's dead and consider deleting instead of porting.

Process

  • One PR per family above, branch off main, never touch main.
  • Every port PR carries a B200 before/after via modal_app.py; a family where tiles lose gets its result recorded here and stays flat.
  • Any library gap the ports surface (e.g. shared-tile/shared-vector map+reduce instantiations — GAPS §3.1/§3.2, the tile half filed nowhere; fp32 TensorMapElement for descriptors over f32 buffers — GAPS §1.5) gets an issue on feitreim/ferro-kittens, linked from the PR. The rms_norm and classifier ports are exactly the consumers those gaps have been waiting for.
  • A Modal check red in ~15s is the spend limit, not the code.

Activity

  1. feitreim commented on Aug 3, 2026

    @feitreim
    OwnerAuthor

    Measured on a B200, at gpu/model/src/bin/train.rs's shapes (N = 24576, D = 3072, FF = 4096, VOCAB = 50257, VP = 50432), three warmups and twenty timed iterations per row, shipped and tile kernel in the same container on the same clocks. Every number below is effective bytes per second over compulsory traffic — the reads and writes the kernel is obliged to move, no reuse assumed — because every family here is bandwidth-shaped and FLOP/s says nothing about any of them.

    The tiering in this issue is backwards. Both port-first families lose; the measure-first one wins. #73 ports SwiGLU. The rest of this comment is the record for the ones that stay flat.

    The exploration is on feat/issue-70-tile-probes — every kernel below, its correctness gate against the shipped one, and the bench rows, so these are reproducible and not just reported.


    1. RMSNorm — tiles lose, stays flat

    rms_norm_forward_fast reaches 4167 GB/s and rms_norm_backward_x_fast 5634 GB/s. The best tile shape found reaches 0.83x and 0.91x of those. Fifteen shapes, sweeping rows per warp, columns per chunk, and warps per block:

    rows/warp chunk warps forward backward_x
    32 16 4 0.737x 0.689x
    32 32 4 0.832x 0.780x
    32 32 8 0.837x 0.800x
    32 48 4 0.636x 0.454x
    32 64 4 0.165x 0.108x
    16 16 2 0.821x 0.488x
    16 32 1 0.823x 0.905x
    16 32 4 0.803x 0.899x
    16 64 4 0.280x 0.187x
    16 192 4 0.116x 0.070x

    Why. The row statistic is genuinely cheaper on tiles — RegTile::row_sum is two shuffles against a 256-thread shared-memory tree and eight barriers — and it does not matter, because the reduction was never what these kernels were waiting on. What decides them is memory-level parallelism, and the shipped block-per-row kernel has 24576 CTAs of 256 threads = 6.3M threads where a warp-per-band kernel has 24576. A tile lane holds a chunk's worth of loads in flight; 128x fewer lanes cannot make that up, and the chunk width is the only knob that would — which runs into the second finding.

    The cliff past 32 columns is a .local depot, not registers. The natural suspect was the parameter vector: reading a [dim] weight through a stride-zero load_rows costs SLOTS * VALUES registers to hold VALUES distinct numbers. That is real, and I filed and fixed it (ferro-kittens#172 / #173, global::load_cols, the global twin of ldst::load_vec). It moved chunk 64 from 0.151x to 0.165x and no further. So what collapses there is something else, upstream of ptxas — the same shape ferro-kittens' regcount local-memory census (#167 there) was built to see. Worth its own issue there; it is not what decides this family either way.

    RMSNorm's own headroom is real and is not a tile question. Forward is at 4167 GB/s where backward, on the same card and the same buffers, reaches 5634. Backward does 24 elements per thread against forward's 12, so what forward is short of is work per thread, not bandwidth — a two-rows-per-block variant of the existing kernel is the shape that would collect it.

    2. Softmax / cross-entropy / fused classifier — tiles lose, stays flat

    fused_classifier_forward_bf16 at 24576 x 50432 reaches 1676 GB/s. The tile version — one warp per 16 rows, row_max/row_sum instead of the two shared arrays and the branchy eight-round merge, running (max, sum_exp) carried across chunks in registers so it is still one pass — reaches 720 GB/s, 0.430x.

    Same mechanism as RMSNorm and worse: 24576 CTAs become 192. ferro-kittens#47's finding is the same result reached from the other side — softmax's binding resource is not the one register streaming buys.

    Forward only, deliberately: both directions share one reduction and one row walk, and the backward only adds a write-back pass no tile shape changes. A forward at 0.43x settles the family.

    3. SwiGLU — tiles win, ported in #73

    kernel shipped tile
    swiglu_forward 2447 GB/s 2900 GB/s 1.185x
    swiglu_backward_gate 3026 GB/s 3487 GB/s 1.152x
    swiglu_backward_up 2444 GB/s 2931 GB/s 1.199x
    swiglu_forward_bf16 3516 GB/s 2454 GB/s 0.696x

    This issue's guess about SwiGLU was that "the current flat kernels may already be at bandwidth". They are not: 2447 GB/s where the RMSNorm backward reaches 5634 on the same card. The flat kernel gives one output element to one thread — one 4-byte load from each input, one 4-byte store — and what a tile buys is the access width and the loads in flight, which is the entire difference. No reduction is involved anywhere in this family.

    The bf16 arm losing is the same fact read backwards, and it is the useful half of the result: that kernel already stores a packed pair per thread, so it already had the access width, and at 3516 GB/s a tile has nothing left to sell it. Not ported.

    Peak shape is 16 rows per warp and 32 columns per chunk. 64 columns falls to 0.39x — the same .local cliff as §1, at the same width, on a kernel with no parameter vector in it at all, which is what identifies it as the codegen and not the operand.

    4. RoPE — not a memory kernel, no tile version written

    rope_forward at 24576 x 3072: 924 GB/s, against SwiGLU's 2447 on comparable traffic and the same card. It computes a powf, a sin and a cos per element. It is transcendental-bound, not bandwidth-bound, and a tile pass moves the same bytes with the same arithmetic still in it — the probe this issue asked for is answered by the ratio without writing one.

    The win here is a precomputed [T, HD/2] cos/sin table, which is T * HD / 2 * 4 = 512 KB at the training shape and read from L2 — orthogonal to tiles and worth its own issue if anyone wants it.

    5. attention_probabilities / attention_output / attention_backward_* — not dead, do not delete

    This issue's premise is half right: gpu/model no longer references any of the five. It stopped at 0b79bdf (2026-07-17), which deleted the naive_attention_probabilities: Option<...> oracle plumbing and made flash_attention_forward_into/_backward_into unconditional. But gpu/flash-attn is a live consumer — it #[path]-includes ../../ops/src/lib.rs as mod naive (gpu/flash-attn/src/main.rs:19-20) and diffs the tcgen05 flash output against all five:

    kernel consumers outside ops' own gate
    attention_probabilities gpu/flash-attn/src/main.rs:127, 276, 449; src/bin/bench.rs:58
    attention_output gpu/flash-attn/src/main.rs:137, 459; src/bin/bench.rs:68
    attention_backward_q gpu/flash-attn/src/main.rs:289, 469; src/bin/bench.rs:111
    attention_backward_k gpu/flash-attn/src/main.rs:302, 482; src/bin/bench.rs:124
    attention_backward_v gpu/flash-attn/src/main.rs:314, 494; src/bin/bench.rs:136

    Deleting them removes flash-attn's correctness gate and its bench baseline, which is exactly the role SPEC.md:353-356 assigns them ("the naive kernels are never deleted — they are the spec the fused ones are tested against"). They are oracle-only and never in the training loop; that is the intended state, not rot.

    One real cost, and it is not runtime: gpu/model textually includes all of gpu/ops/src/lib.rs, so those five compile into the training binary's device image and are paid for in PTX size and ptxas time by a binary that cannot launch them. If that is worth fixing, the fix is a #[cfg] on the oracle set, not a deletion.

    Library gaps filed

    • A per-column operand in global memory has no way into registers: load_cols, the global twin of ldst::load_vec ferro-kittens#172 — a per-column operand in global memory had no way into registers; ldst::load_vec reads a ColVec out of a SharedVec and global::load_rows reads a RegTile out of global memory, and there was no third call. Fixed in A per-column operand in global memory reaches registers without a tile's worth of them (#172) ferro-kittens#173 (global::load_cols), device case global column map, 43/43 on a B200. Honest caveat carried on that PR: the RMSNorm port that motivated it did not ship, so it lands with a device case and no kernel consumer.
    • The two gaps this issue predicted — shared-tile/shared-vector map+reduce instantiations (GAPS §3.1/§3.2) and an fp32 TensorMapElement (§1.5) — were not needed, and the reason is worth recording. Neither port went through shared memory or a TMA descriptor at all. global::load_rows/store_rows are generic over Element, so an fp32 register tile reaches global memory directly, with no descriptor to encode and no shared tile to stage; the fp32 TensorMapElement only binds if you want the engine, and at these shapes there is nothing to prefetch into. The tile path being 16-bit-only (ldst's Element<Unpacked = [f32; 2]> bound on the ldmatrix/stmatrix paths) never came up for the same reason.
  2. added a commit that references this issue on Aug 3, 2026
  3. feitreim commented on Aug 4, 2026

    @feitreim
    OwnerAuthor

    Re-measured both families that this issue left flat, against the c648c67 pin (#76) that carries ferro-kittens#180's mover unroll. One of the three kernels turns over; #78 ports it.

    Same conditions as the comment above — B200, bin/train.rs shapes, three warmups and twenty timed iterations, shipped and tile in one container on one set of clocks.

    kernel #70 now
    rms_norm_forward 0.837x 0.2174 → 0.1749 ms, 4167 → 5179 GB/s 1.243x
    rms_norm_backward_x 0.905x 0.2680 → 0.2716 ms, 5635 → 5560 GB/s 0.997x
    fused_classifier_forward_bf16 0.430x 1.4796 → 3.3491 ms, 1675 → 740 GB/s 0.442x

    §1, RMSNorm — the forward ports, the backward does not

    This issue's cliff was right about where it was and right that it was not registers. It was the depot, and it moved rather than vanished:

    rows/warp chunk forward backward_x #70's forward
    16 48 1.061x 0.865x —
    16 64 1.246x 0.988x 0.280x
    16 96 0.387x 0.249x —
    16 192 0.345x 0.217x 0.116x
    32 64 1.026x 0.818x 0.165x

    64 columns went from 0.165x to 1.026x at 32 rows and to 1.246x at 16. The new edge is at 96, and it is a different failure: both tile kernels now come out of ptxas with no .local declaration at all at 64, so what breaks at 96 is a [16, 96] fp32 band that no longer fits the register file — ferro-kittens#181's category, not #180's.

    This issue's diagnosis of why was correct and is why the forward wins. The reduction was never what these kernels were waiting on; what the tile buys is loads in flight, and at 64 columns per lane against the block-per-row kernel's 12 elements per thread it buys enough of them to beat the 64x cut in thread count that this issue counted (6.3M → 98k). And this issue named the target itself: "forward is at 4167 GB/s where backward, on the same card and the same buffers, reaches 5634 ... what forward is short of is work per thread, not bandwidth". That is exactly the gap the tile collects — 5179 GB/s — and it is why 16 rows beats 32, which spends the same register budget on rows instead of columns and reaches only 1.026x.

    It is also why the backward cannot follow. It was already at the roof the forward just reached; 0.985–0.997x across four shapes is the same rate from the same side. The two-rows-per-block variant of the existing forward that this issue proposed would have been chasing the same 5600 GB/s ceiling — the tile got there first, so that follow-up is now closed rather than open.

    §2, classifier — still not close, and the frame is not the reason

    0.442x at 64 classes per chunk, 0.224x at 128, 0.206x at 256, 0.367x at 32 rows per warp. No shape helps.

    It is the one kernel here that still carries a frame, and the frame is real: 400 bytes, from RegTile::mask behind the single right_fill on the vocabulary's ragged last chunk. mask walks slots by a runtime index, so set under a data-dependent condition keeps the slot array addressable and LLVM homes the whole 32-register tile — once per vocabulary chunk, all 786 of them, not just the masked one. ferro-kittens#180 did not reach it; src/reg.rs has no __unroll_config anywhere.

    Deleting that one call removes the depot entirely and moves the kernel to 0.563x. So the frame is 27% of its runtime and it is still not what decides the family — this issue's count is: 24576 CTAs become 384, and no tile shape reaches that.

    Filed as feitreim/ferro-kittens#184 with the PTX. The patch is two lines and I did not push it: it drops examples/flash_forward's frame 1824 → 1568 bytes and takes it from 165 to 255 registers, which is #181's band-that-does-not-fit surfacing honestly rather than a win, and no kernel here gets faster from it.

    What is left of this issue

    §3 SwiGLU shipped in #73, §1's forward ships in #78. Still open and unchanged by any of this: §1's backward and §2 stay flat with the numbers above, §4 RoPE's precomputed cos/sin table, and §5's #[cfg] on the five oracle kernels that compile into the training binary without being launchable from it.

  4. added a commit that references this issue on Aug 4, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions