Skip to content

[Triton/Gluon] Conflict-free bf16 KV-tile stores in gfx950 sparse_mla rope-free walk - #6276

Merged
vgokhale merged 1 commit into
ROCm:mainfrom
Raiden-Makoto:RM/glm53-bf16-gather-lds
Oct 12, 2026
Merged

vgokhale merged 1 commit into
ROCm:mainfrom
Raiden-Makoto:RM/glm53-bf16-gather-lds

Conversation

@Raiden-Makoto

@Raiden-Makoto Raiden-Makoto commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What

The gfx950 sparse_mla_fwd row 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_K32 walk (a bf16 cache with qk_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. Cfg takes a new BF16_GATHER flag, set by _sparse_mla when STAGED_K32 is on and the main format is bf16; GSPT is 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.py gains --qk_rope_head_dim (default 64, the existing behavior) so the rope-free geometry can be benchmarked.

Performance

Measured at submitted head 8f53e55a462fcc5062cab44530da926a996d75ff (base 31aef274b128203c330750e7bb70b116cd6f44ea) on AMD Instinct MI355X (gfx950, 256 CUs) with Docker image rocm/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 0 with --context 8192 for decode and --context 16384 for 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 is main at the base commit. Both arms use the image's AITER build with the sparse_mla Triton/Gluon modules taken from the respective commit.

phase heads seqs × tokens main (us) this PR (us) change per-run range
prefill 16 1 × 8192 1392.33 1322.95 -5.0% -8.1% .. -3.7%
prefill 16 1 × 16384 3048.50 2933.82 -3.8% -4.5% .. -2.5%
prefill 8 1 × 8192 1390.49 1322.03 -4.9% -6.8% .. -3.4%
prefill 8 1 × 16384 3042.42 2925.58 -3.8% -4.0% .. -3.6%
decode 16 1 21.85 21.57 -1.3% -3.8% .. +0.6%
decode 16 16 28.05 28.17 +0.4% -1.7% .. +1.6%
decode 16 32 37.27 37.18 -0.2% -2.8% .. +1.0%
decode 16 64 63.37 63.17 -0.3% -1.0% .. +0.1%
decode 8 1 21.53 20.79 -3.4% -5.6% .. +32.5%
decode 8 16 27.46 27.48 +0.1% -2.8% .. +0.9%
decode 8 64 60.40 60.24 -0.3% -0.8% .. +0.3%
decode 8 128 109.67 109.33 -0.3% -0.7% .. +6.3%
decode 8 256 166.06 166.24 +0.1% -0.3% .. +0.4%
decode 8 512 252.11 251.85 -0.1% -0.3% .. +0.2%

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%.

rocprofv3 counters on the bf16 rope-free kernel, averaged over all dispatches of the same benchmark:

case LDS bank-conflict cycles, main → PR LDS active cycles, main → PR LDS instructions
prefill, 16 heads, 1 × 8192 178.00M → 60.03M (-66.3%) 442.97M → 325.01M (-26.6%) unchanged
decode, 16 heads, 64 seqs 1.64M → 0.59M (-64.0%) 4.16M → 3.11M (-25.2%) unchanged
decode, 8 heads, 512 seqs 12.75M → 4.36M (-65.8%) 31.52M → 23.13M (-26.6%) unchanged

Register use is unchanged: 204–224 VGPRs, no spills, no scratch, and the same LDS allocation and occupancy as main.

Correctness

python -m pytest op_tests/triton_tests/attention/test_sparse_mla.py -q

Result: 72 passed, 2 skipped on both main and this PR. This includes test_sparse_mla_rope_free for 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_mla variant 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 Cfg argument after STAGED_K32; whichever lands second needs a one-line rebase.

… 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]>
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6276 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@Raiden-Makoto
Raiden-Makoto marked this pull request as ready for review October 8, 2026 18:04
@Raiden-Makoto
Raiden-Makoto requested a review from a team October 8, 2026 18:04
Raiden-Makoto added a commit to Raiden-Makoto/squidward that referenced this pull request Oct 8, 2026
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 vgokhale left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Raiden-Makoto added a commit to Raiden-Makoto/squidward that referenced this pull request Oct 8, 2026
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.
@Raiden-Makoto

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Both requests are covered:

1. Benchmark (rope-free BF16 path). Ran op_tests/op_benchmarks/triton/bench_sparse_mla.py --qk_rope_head_dim 0, main vs this PR, 12 runs per shape across 4 GPUs with alternating order. Prefill is 3.7–5.0% faster in every run (16 heads × 8192 tokens: 1392.33 → 1322.95 µs). Decode is unchanged within noise. rocprofv3 LDS bank-conflict cycles drop 64–66% (16 heads × 8192 prefill: 178.00M → 60.03M), with the same LDS instruction count, registers, and occupancy. Full tables are in the description.

2. BF16 correctness on gfx950. Ran op_tests/triton_tests/attention/test_sparse_mla.py: 72 passed, 2 skipped, the same as main. All 6 BF16 rope-free cases passed: test_sparse_mla_rope_free[...-bf16] for 8 and 16 heads, each at top-k 2048, ragged top-k 500, and the 2048-row prefill case. These are the cases that exercise the loop with the smaller GSPT. The 2 skips are test_native_fp8_cache_rejected, which skips on gfx950 by design. Only the 4 BF16 rope-free kernel variants compile differently; the other 17 have identical instruction streams.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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_K32 path.
  • 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.

@zufayu
zufayu requested review from a team and azaidy October 9, 2026 01:55
@azaidy azaidy assigned vgokhale and unassigned azaidy Oct 9, 2026
@vgokhale
vgokhale merged commit 9fd025e into ROCm:main Oct 12, 2026
Raiden-Makoto added a commit to Raiden-Makoto/aiter that referenced this pull request Oct 14, 2026
The 8f53e55 sparse_mla wrapper loads configs/<arch>/gluon/attention/
sparse_mla/DEFAULT.json, which the image's AITER does not ship.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants