Repository navigation
[GDN] Add gdn_chunk_prepare: fused intra-chunk GDN prefill prep kernel (opus, arch-specialized) - #4016
Closed
jayzlee147 wants to merge 3 commits into
Closed
[GDN] Add gdn_chunk_prepare: fused intra-chunk GDN prefill prep kernel (opus, arch-specialized)#4016jayzlee147 wants to merge 3 commits into
jayzlee147 wants to merge 3 commits into
Conversation
…rch-specialized) Unified single-template K1 op built on opus.hpp, branched fresh from main. Fuses the four FLA prefill kernels that run before the h-recurrence: chunk_local_cumsum + chunk_scaled_dot_kkt_fwd + solve_tril + recompute_w_u_fwd into one token-parallel HIP kernel (BT=64, K=V=128). Numerics = the proven neumann path (Neumann-squaring triangular inverse: 6 MFMAs; Schur-complement merge; single-warp __shfl_up cumsum). Arch偏特化, best-only: gfx950 (MI350): OCC=2, C^-1 staged in LDS bf16 gfx942 (MI300): OCC=3, C^-1 register-cached (smaller LDS -> OCC 2->3) Underperforming variants (bt16/bt32/bt128/basic) dropped. opus.hpp: all global<->LDS traffic via make_gmem/make_smem/make_layout (vectorized b128 dispatch); MFMA via opus::mfma; LDS tile access via opus::make_smem. Validated on gfx950 vs fp32 ground truth (7 shapes incl. non-BT-multiple): g_cumsum exact (~1e-7); w_bar/u_bar rel-L2 ~3-5e-3 (bf16-level, on par with Triton). Perf: 98.8us @ B1T8192H32, VGPR=32, LDS=25.3KB — matches the neumann baseline. gfx942 path is arch-gated (compiles here; needs MI300 to runtime-validate). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Fused 1-kernel gdn_chunk_prepare vs Triton 4-kernel k14 (cumsum + kkt + solve_tril + recompute_w_u) under CUDA graph capture/replay. gfx950 measured: 1.86-2.32x end-to-end speedup; precision aligned vs Triton (w/u rel-L2 ~3-4e-3, bf16-level). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…model configs) Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
|
Nice fusion work. One suggestion: add varlen and GQA support, otherwise gdn_chunk_prepare can't be used on packed/GQA prefill paths.
|
1 task
Contributor
|
No activity for 15 days, so this is now labelled |
Contributor
|
Closing due to inactivity: no pushes, reviews, or comments for 100 days. This is housekeeping, not a judgement on the change — if you want to continue this work, comment here and we'll reopen, or open a fresh PR rebased on the latest main. |
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.
Motivation
The Gated-DeltaNet (GDN) chunkwise prefill runs four separate FLA kernels before
the h-state recurrence:
chunk_local_cumsum → chunk_scaled_dot_kkt_fwd → solve_tril → recompute_w_u_fwd
This costs 4 kernel launches, an
A_raw[B,T,H,64]HBM round-trip, and repeatedreloads of g/beta/k. This PR fuses all four into a single token-parallel HIP
kernel,
gdn_chunk_prepare, built on theopus.hpptemplate library, withper-arch specialization that ships only the best-performing path for each target.
Technical Details
gdn_chunk_prepare(module_gdn_chunk_prepare): one HIP kernel thatfuses cumsum + gated KKT Gram + triangular inverse + WY-factor recompute.
Inputs
k,v(bf16),g,beta(fp32); outputsg_cumsum(fp32),w_bar,u_bar(bf16).BT=64, K=V=128.
make_gmem/make_smem/make_layout(vectorized b128 dispatch); MFMA via
opus::mfma<bf16,bf16,fp32,16,16,16>;LDS MFMA-tile access via
opus::make_smem.(I+B)(I+B²)(I+B⁴)(I+B⁸)(6 MFMAs vs 15 Horner), 3-level warp-parallel Schur-complement merge, and a
single-warp
__shfl_upcumsum (drops ~6 block barriers).#if defined(__gfx950__):csrc/include/opus_gdn/gdn_chunk_prepare_*),TU + host launcher (
csrc/py_itfs_cu/opus_gdn_chunk_prepare*.cu), pybind/header,Python op (
aiter/ops/gdn_chunk_prepare.py), JIT config entry, and tests.Test Plan
op_tests/triton_tests/test_gdn_chunk_prepare.py): compares thefused output against an fp32 ground-truth reference and the Triton non-fused
k14 across multiple shapes (incl. a non-BT-multiple T).
op_tests/triton_tests/bench_gdn_chunk_prepare.py): CUDA-graphcapture/replay, fused 1-kernel vs Triton 4-kernel k14, median µs, across the
35B/FULL model configs (K=V=128).
Test Result
Precision (vs fp32 ground truth and Triton non-fused, both arches):
g_cumsumexact (~1e-7);
w_barrel-L2 ~3e-3,u_barrel-L2 ~4.3e-3 — bf16-level, alignedwith Triton.
Performance — fused
gdn_chunk_prepare(1 kernel) vs Triton non-fused k14(4 kernels), under CUDA graph (launch overhead removed). A structural win from
single-kernel fusion + LDS staging (no
A_rawHBM round-trip): MI300X is flat at~2.4–2.5×; MI350 is ~1.9–2.3× (gfx950's 32×32×16 MFMA makes Triton's k14
GEMMs relatively faster, narrowing the margin slightly). Both arch-specialized
paths are runtime-validated.
MI300X (gfx942)
Anchor (35B-tp1 T=8192): Opus K1 470 µs vs Triton k14 1124 µs (2.39×).
MI350 (gfx950)
Anchor (35B-tp1 T=8192): Opus K1 106.1 µs vs Triton k14 209.2 µs (1.97×).
Single-kernel profile (gfx950, B1T8192H32): 98.8 µs, VGPR=32, LDS=25.3 KB.
Submission Checklist