Repository navigation
FA4 phase 2: warp-specialized pipelined tcgen05 forward (#35) - #37
Merged
Merged
Conversation
- flash_forward_pipelined: 192 threads — TMA load warp with a PIPELINE_STAGES-deep K/V mbarrier ring, MMA-issue warp staggered so S-MMA(i+1) overlaps softmax(i) via a double-buffered S TMEM, and the 128-thread softmax warpgroup keeping correction+epilogue (register O accumulator + TMEM lane ownership pin them there) - per-tile softmax/drain/epilogue extracted into helpers shared with the phase-1 sync kernel, which stays as the in-artifact oracle - PIPELINE_STAGES is the SWEEP knob; the host allocates a 4-stage SMEM ceiling so stage sweeps are a one-const edit (free at 1 CTA/SM, which the 512-column TMEM alloc already forces) - launch_bounds(192, 1); bin gates + bench and harness oracle parity now cover both forwards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of #35: the warp-specialized pipelined forward — K/V TMA rings, S TMEM double-buffering, and mbarrier-only role handoffs, landed behind the same gates as phase 1. The phase-1 synchronous kernel stays in the artifact as an oracle and hang-debugging fallback; the model still runs the fp32 tiled kernels (integration is phase 3).
What's here
flash_forward_pipelined— 192 threads in three roles, connected purely by mbarrier phase-parity spins (no named barriers in cuda-oxide v0.2.1; FA4 does the same):PIPELINE_STAGES-deep ring (kv_full[stage]expect_tx, recycling onkv_free[stage]).S-MMA(i)into the double-buffered S TMEM (columns 0/128, guarded bys_free) beforeO-MMA(i-1)(guarded byp_full) — so while the softmax warpgroup works tile i, the tensor core is already producingS(i+1). This is the checklist's softmax(i) ∥ MMA(i+1) overlap, and it is also whyPIPELINE_STAGES >= 2is aconstassert: with one stage thekv_fullwait forS-MMA(i)would precede theO-MMA(i-1)whose completion recycles the stage.s_full, runs the register softmax, releasess_free/p_full, waitso_full, merges the O segment. Correction and epilogue stay fused here rather than in FA4's separate warpgroups: the output accumulator lives in these registers and TMEM lane ownership pins every drain to warps 0–3 — a standalone correction warpgroup only becomes possible withtcgen05.st(Bump cuda-oxide pin from v0.2.1 to current upstream main #34).Two safety-driven choices worth reviewing:
o_full(i)wait (needed anyway before draining O) provesO-MMA(i)finished reading P before pass 2 of tile i+1 overwrites it.kv_freeis released by the warpgroup after that same wait, not by a secondtcgen05.commitfrom the MMA warp — the PTX "commits all prior operations" wording is ambiguous about already-committed MMAs, and a commit that arrived immediately would let TMA overwrite a V tile mid-read.The kernel doc comment records the phase-parity soundness argument (every barrier's completions lead their waiter by at most one phase) since that invariant is what a future reordering could silently break.
Shared per-tile math —
softmax_tile/merge_output_tile/store_outputsare extracted#[inline(always)]helpers used by both kernels, so the sync kernel gates also gate the shared code, and phase 3's conditional-rescale work edits one place.SWEEP + launch bounds —
PIPELINE_STAGESis the tuning const (pub const ... usizeper SPEC §10). The host side allocates a fixed SMEM ceiling sized for 4 stages (176 KiB), so sweeping stages is a one-const edit that can never desync host from device; the flash bin asserts the ceiling. Over-allocating is free here: the 512-column TMEM alloc against a 512-column SM budget already pins occupancy to one CTA/SM. The kernel carries#[launch_bounds(192, 1)](the issue's__launch_bounds_configitem — the macro lowers to exactly that intrinsic). BK and the role ratios from the issue's sweep list are structurally pinned (TMA box + MMA shapes; TMEM lane ownership) and recorded as such rather than swept.run_sweepin modal_app.py learned to rebuildflash.ptxper config and use the flash bin as gate+bench for this crate.Gates (B200, same container)
run_sanitizer's build path lacked the--arch sm_100apin (fixed here); rerun once the image's CUDA toolkit supports sm_100 sanitizingPIPELINE_STAGESsweep (one container, parity green in every config): 2 → 1.383 ms, 3 → 1.385 ms, 4 → 1.386 ms — flat within noise, confirming TMA is fully hidden at every depth and the warpgroup is the critical path. Default stays 3 (headroom for phase 3's second workstream)The modest headline delta is the expected shape of phase 2: the softmax warpgroup is the critical path, and this phase only strips TMA waits,
S-MMA, and part ofO-MMAout of it while building the substrate phase 3 needs — two-Q-tile ping-pong (fills the tensor-core idle window during softmax) and conditional rescaling (removes most per-tile O drains from the warpgroup).Phase-2 checklist from #35
__launch_bounds_configregister budgeting; SWEEP stages (BK × role ratios structurally pinned, recorded)Next per the issue: phase 3 (conditional rescaling segments, full-tile/diagonal loop split, two-Q-tile ping-pong, persistent scheduler, model integration).