Repository navigation
[Triton/Gluon] Conflict-free bf16 KV-tile stores in gfx950 sparse_mla rope-free walk - #6276
Conversation
… rope-free walk The row gather gives each lane 16 elements, which is one 16 B load for 1-byte fp8 rows. On the bf16 STAGED_K32 walk (rope-free bf16 cache) the same count puts lanes 32 B apart, so every 128-bit store into the KV tile is a two-way LDS bank conflict. Gather 8 bf16 elements per lane on that walk; every other format and walk keeps its layout. bench_sparse_mla.py gains --qk_rope_head_dim so the rope-free geometry can be benchmarked (default 64 keeps the existing behavior). Signed-off-by: Raiden-Makoto <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Behind SGLANG_OPT_GLM53_AITER_SPARSE_MLA (off by default; needs AITER with ROCm/aiter#6276): AITER sparse_mla_fwd serves decode batches >= 16 and prefill batches <= 256 tokens inside the validated GLM-5.3 Triton geometry. All other batches stay on the Triton kernels.
vgokhale
left a comment
There was a problem hiding this comment.
Review: PR #6276 — Conflict-free bf16 KV-tile stores in gfx950 sparse_mla rope-free walk
The fix is correct. The comment in the diff explains the problem clearly, and the change follows from the arithmetic.
What the bug is
The kernel gathers 512-byte KV rows into LDS and stores them as 128-bit KV tiles. The per-lane element stride GSPT was 16 for all formats.
For fp8 (1 byte per element), 16 elements = 16 bytes per lane. Consecutive lanes are 16 bytes apart. The 128-bit stores hit distinct LDS banks. No conflict.
For bf16 (2 bytes per element), 16 elements = 32 bytes per lane. Consecutive lanes are 32 bytes apart. LDS has 32 banks of 4 bytes each, so two consecutive lanes land in the same bank. Every 128-bit KV-tile store has a two-way bank conflict, which serializes it.
What the fix does
GSPT = (8 if BF16_GATHER else 16) * (32 // GATHER_TW1)For bf16, GSPT becomes 8 elements = 16 bytes per lane. Consecutive lanes are now 16 bytes apart and hit distinct banks. The stores are conflict-free. fp8 keeps GSPT = 16 and is not changed.
BF16_GATHER is a derived constexpr: STAGED_K32 and MAIN_FMT == "bf16". So this only changes the bf16 staged-K32 path. fp8 and other formats are untouched.
The change is consistent
GSPT is defined once and used everywhere: size_per_thread=[1, GSPT], [1, GSPT//2], [1,1,GSPT], and cfg.GSPT.value in the gather loop. The other 16s in the file are unrelated constants (MFMA columns, ROPE_VEC, AVEC, LDS_PAD). The 16 → 8 remapping is consistent throughout.
A useful secondary effect: the intended design is one 128-bit load per lane. Old bf16 with GSPT=16 (32 bytes per lane) did two 128-bit loads per lane. The new GSPT=8 (16 bytes per lane) restores the one-load design, so this also fixes a load issue, not just the store conflict.
Rule 1 (repr) is fine
The repr key already includes MAIN_FMT. BF16_GATHER is fully derived from MAIN_FMT and arch. The bf16 variant is already distinguishable. No new repr entry is needed.
Two requests before merge
1. Post the measured speedup on the rope-free bf16 path. The PR adds --qk_rope_head_dim 0 to the benchmark specifically to exercise this path. Please run it before and after this change and post the numbers. Halving GSPT removes the store conflict but also changes how many elements each lane processes per iteration. The net impact is a measurement question, not something you can read off the diff.
Ideally also post a profiler bank-conflict count (before and after) to back the "conflict-free" claim. rocprof or omnitrace can give per-kernel LDS bank conflict counts.
2. Confirm the existing bf16 numerics tests still pass. The change affects the span and iteration layout, not the arithmetic. But please confirm sparse_mla bf16 correctness tests pass on gfx950 so we know the surrounding loop logic adapts correctly to the smaller GSPT.
Summary
The fix is correct and the scope is tight. Post the benchmark numbers for the rope-free bf16 path and confirm the numerics tests pass, then this is good to merge.
Replace SGLANG_OPT_GLM53_AITER_SPARSE_MLA with an aiter_sparse_mla DSA backend value. It keeps the measured split: AITER Gluon sparse_mla_fwd for decode batches >= 16 and prefill batches <= 256 tokens, Triton otherwise. Selecting it outside the validated GLM-5.3 geometry raises at startup. Requires AITER with ROCm/aiter#6276.
|
Thanks for the review. Both requests are covered: 1. Benchmark (rope-free BF16 path). Ran 2. BF16 correctness on gfx950. Ran |
There was a problem hiding this comment.
🔵 Needs a closer look
The hardware-specific GPU layout change requires final human confirmation despite the reported correctness and performance validation.
0 open findings
What changed in this PR
Optimizes gfx950 rope-free bf16 sparse MLA by using conflict-free KV-tile gathers and extends benchmarking to cover rope-free geometry.
Changes:
- Uses 8-element bf16 lane gathers for the
STAGED_K32path. - Adds configurable rope dimensions to the sparse MLA benchmark.
| File | Description |
|---|---|
aiter/ops/triton/_gluon_kernels/gfx950/attention/sparse_mla.py |
Selects the narrower bf16 gather layout. |
op_tests/op_benchmarks/triton/bench_sparse_mla.py |
Adds rope-free benchmark configuration and metric accounting. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
What
The gfx950
sparse_mla_fwdrow gather assigns each lane 16 cache elements. For 1-byte fp8 rows that is one 16 B load per lane, and consecutive lanes write consecutive 16 B chunks into the KV tile.The bf16
STAGED_K32walk (a bf16 cache withqk_rope_head_dim=0, the rope-free GLM-5.3-Flash geometry) uses the same element count. Each lane then holds 32 B, so lanes are 32 B apart and every 128-bit store into the KV tile is a two-way LDS bank conflict.This change gathers 8 bf16 elements (16 B) per lane on that walk only.
Cfgtakes a newBF16_GATHERflag, set by_sparse_mlawhenSTAGED_K32is on and the main format isbf16;GSPTis 8 instead of 16 in that case. fp8 formats, the DSv4 walk, and bf16 with an appended rope keep their existing layout and compile to identical instructions.bench_sparse_mla.pygains--qk_rope_head_dim(default 64, the existing behavior) so the rope-free geometry can be benchmarked.Performance
Measured at submitted head
8f53e55a462fcc5062cab44530da926a996d75ff(base31aef274b128203c330750e7bb70b116cd6f44ea) on AMD Instinct MI355X (gfx950, 256 CUs) with Docker imagerocm/sgl-dev:v0.5.21-rocm724-mi35x-20261001(sha256:fe1425e21a184cbf330bb2f525d93fa65f7ea282abe43d3c8dfccfd361cd3cd4), Triton 3.7.0.python op_tests/op_benchmarks/triton/bench_sparse_mla.py --qk_rope_head_dim 0with--context 8192for decode and--context 16384for prefill,topk=2048, the default L2 flush between iterations, and bf16 dots. Values are medians of 12 runs: three on each of four GPUs, alternating which arm runs first. The baseline ismainat the base commit. Both arms use the image's AITER build with thesparse_mlaTriton/Gluon modules taken from the respective commit.Prefill is faster in every run. Decode is unchanged within run-to-run noise: with the cache flushed, the decode loop is bound by the HBM gather rather than LDS. The fp8-dot series in the same runs, whose kernels are unchanged, moved between -1.5% and +0.9%.
rocprofv3counters on the bf16 rope-free kernel, averaged over all dispatches of the same benchmark:Register use is unchanged: 204–224 VGPRs, no spills, no scratch, and the same LDS allocation and occupancy as
main.Correctness
Result:
72 passed, 2 skippedon bothmainand this PR. This includestest_sparse_mla_rope_freefor bf16 at 8 and 16 heads (top-k 2048, ragged top-k 500, and the 2048-row prefill case).Compiled-code comparison over every
sparse_mlavariant the test suite builds: the 4 bf16 rope-free variants change, and the other 17 (fp8 per-tensor, fp8 DSv3.2, and bf16 with an appended rope; 8 and 16 heads; split-K on and off) have identical instruction streams.Black and Ruff (
0.16.0) pass on the changed files.#6199 also appends a
Cfgargument afterSTAGED_K32; whichever lands second needs a one-line rebase.