Skip to content

kittens follow-ups: phase-5 leftovers (fused gpu/ops, tcgen05.st correction warpgroup) and post-phase-5 measurements #63

Open

Description

@feitreim

Summary

Phase 5 of #61 shipped its two halves — the remaining flash kernels ported onto gpu/kittens, and the first kernels written kittens-first (flash_backward_q_pipelined / flash_backward_kv_pipelined, attention backward 5.541 → 4.799 ms, outputs bit-identical). This issue tracks what phase 5 listed but did not reach, plus the follow-ups that work generated.

Branch: feat/issue-61-kittens-phase1 (pushed). Full record in SPEC 7e17.

Not reached from phase 5's list

  • Fused gpu/ops kernels. The one phase-5 target genuinely untouched. gpu/ops/src/lib.rs is ~2.7k lines of one-op-per-kernel elementwise/norm/softmax work; the fusion candidates want picking by profile, not by taste (decision 17). Note the current profile says no single non-GEMM kernel exceeds ~2.1% of step, so this is a many-small-wins area rather than one big one — worth a profile pass first to decide whether it is above the line at all.
  • FA4 conditional rescaling in TMEM as a dedicated correction warpgroup (unblocked by tcgen05.st, Bump cuda-oxide pin to upstream main @ b099f64 (tcgen05.st landed) #56). Re-scope before starting: the phase-5 gate reports corrections firing 0 of 92160 eligible tile visits (0.00%) at the bench shape, so this is not a speed play. The actual prize is register pressure — the drain/rescale/restart machinery lives in the softmax warpgroup's registers, and the persistent forward is the most register-tight kernel in the repo. Frame it as "does moving correction to its own warpgroup buy back registers in flash_forward_persistent," and kill it if the answer is no.
  • Router/scatter kittens-style (Router phase 2: weight-reuse pass for backward input/weight #54/scatter_dy phase 2: vectorized row copy + fold zero_dy_bins #55). Both landed pre-kittens and are no longer bottlenecks (router backward 14.64 → 3.19 ms, scatter 7.49 → 3.31 ms). Porting them is consistency work with no expected win — do it only if someone is already in that code.

Follow-ups the phase-5 work generated

  • BASELINE_REF A/B for the pipelined backwards. The kernel-level delta is measured in-container (−13.4%); the step-level number is not. The candidate-side profile puts backward.attention.flash_q + flash_kv at 71.03 ms = 12.51% of a 567.59 ms step (B=12 T=2048), implying ≈−11 ms, but that is inference, not measurement. Now that the branch is pushed, BASELINE_REF=<pre-pipeline commit> ./run.sh model profile can settle it. T=2048 gives more key tiles per CTA than the bench's T=1024, so the pipelined form should do better at model shape than at bench shape.
  • Sweep BACKWARD_STAGES. SWEEP="BACKWARD_STAGES=2,BACKWARD_STAGES=3,BACKWARD_STAGES=4" ./run.sh flash-attn is a one-const sweep the harness already supports (it is the only pub const usize of that name). Blocked on one thing: the ptxas budget pins reject any config that allocates differently, so the sweep run needs them loosened. Depth 3 was chosen by shared-memory arithmetic, never measured against 2 or 4.
  • A persistent backward. The forward's ladder was sync → pipelined → persistent, and the backward has only climbed the first two rungs. kittens::pipeline::run already exists (phase 4), so the scaffold is there; the open question is whether two backward workstreams can ping-pong given the backward's TMEM footprint — kernel B already uses all 512 columns, so it would need a different S/dP buffering scheme.
  • Reclaim the unified P-store's 1.3%, if ever worth it. softmax_tile's pass-2 store now goes through store_fragment_bf16, which costs persistent forward 234.7 → 231.8 TFLOP/s. The instruction stream is strictly smaller (13–28 fewer per kernel, frame and local traffic identical to the byte); the cost is entirely ptxas re-rolling its schedule (sync 40→32, pipelined 180→216, persistent 240→236). So the lever is schedule-level — a SASS A/B (nvdisasm in-container) or a toolkit bump — not source. Accepted deliberately; see SPEC 7e17.

Two things worth not re-learning

Recorded here because both cost real measurement time and neither is visible in the Rust:

  1. Register tiles must be built as literals, not filled through indexed loops. Fragment::zero() then t.0[slot][value] = ... inside a while loop does not scalarize — it put 64 B of frame and 76 st.local into the softmax inner loop. The same values as a literal (RegTile([[a,b,c,d],[e,f,g,h]]) over an #[inline(always)] helper) evaporate into registers. This is risk 1 from kittens: ThunderKittens-style tile library for cuda-oxide (tcgen05-only) #61 landing in practice, and the only readout is the .local .align depot line in the emitted PTX.
  2. A SemaphoreRing's parity is a visit count, not a tile index. Any pipelined kernel whose loop starts at a runtime value (kernel B streams query tiles key_a..T/64) must drive every ring index and parity off the step, keeping the absolute tile only for addressing. Getting it wrong hangs exactly the CTAs with key_a > 0.

Acceptance

Nothing here is a blocker for #61's acceptance criteria, which phase 5 met (all phases merged with gates green, register counts held, kernel crates reduced to kernel-specific logic, one new kernel shipped kittens-first). This issue is the backlog that phase 5 scoped out or generated, and each item should be re-justified against a current profile before it is picked up.

Activity

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