Skip to content

[HIP] [fix] MLA reduce: LDS race between rows in kn_mla_reduce_v1's massive path - #7912

Merged
kaiyang-1 merged 1 commit into
mainfrom
gyu/mla-reduce-v1-lds-race
Nov 18, 2026
Merged

kaiyang-1 merged 1 commit into
mainfrom
gyu/mla-reduce-v1-lds-race

Conversation

@gbyu-amd

@gbyu-amd gbyu-amd commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes an LDS race in kn_mla_reduce_v1 / kn_mla_reduce_v1_ps. When a workgroup reduces several query rows of a tile on the massive path (>= kMassiveThreshold splits), warp 0 can overwrite row r's split scales with row r + kNumThreadGroupPerBh's while another warp is still reading them, and some output elements then mix the scales of two rows. On MI455X (gfx1250) op_tests/test_mla_reduce.py fails on main in 5 of 5 runs, and 27 of 60 multi-row decode-shaped reduces give wrong output. With the fix, all pass, at the same speed.

Motivation

mla_reduce_v1_impl_massive walks its rows in a loop. Per row:

  1. warp 0 (reduce_lse_massive) computes the row's split weights and writes them to p_lds_lse_scale;
  2. __syncthreads();
  3. every warp (reduce_output_massive) reads p_lds_lse_scale while accumulating its slice of the output.

Nothing separates step 3 of one row from step 1 of the next, so warp 0 can rewrite p_lds_lse_scale before the other warp has read it. The final LSE is computed in warp 0's registers and stays correct; only the output is affected, a small fraction of elements per tile, varying from run to run.

It needs more than one row per workgroup and a massive-path tile. That covers:

  • the 12-head, DV-128 multi-row cases of test_mla_reduce.py (64x[4] with 64 rows per tile, 512x[4] with 2);
  • the DV-512 layout cases "8 rows, max_seqlen_q 1/4", when they reach kn_mla_reduce_v1 (they do on gfx1250, where kn_mla_reduce_v1_wide is not selected until [HIP] [gfx1250] MLA reduce: run kn_mla_reduce_v1_wide on wave32 GPUs #7914);
  • decode with a multi-token query below 128 / heads rows per tile, e.g. 64 heads x 2-row tiles or 16/32 heads x 4-row tiles with 4+ splits.

Single-row tiles (most decode) and the simple path (2–3 splits, no LDS in the row loop) are not affected. The race does not depend on the target; it shows readily on gfx1250's wave32 workgroups. It may stay hidden elsewhere through timing; gfx9 was not run.

Changes

csrc/include/mla_reduce_kernels.cuh, reduce_lse_massive / mla_reduce_v1_impl_massive:

  • Warp 0 still computes a row's LSE and weights in registers first.
  • From the second row of the workgroup on, a __syncthreads() follows before it stores the final LSE and writes p_lds_lse_scale.
  • The weight computation (global loads, wave reductions) overlaps with the other warps finishing the previous row, so the barrier costs nothing measurable.
  • The condition is uniform across the workgroup, and the first row has no extra barrier. LDS size and layout are unchanged.

Performance (if applicable)

Op-test times, MI455X (gfx1250), main vs fix:

Hardware Workload/configuration Before After Change
MI455X 12 heads x DV 128, 64 tiles x 4 splits, 64 rows per tile (bf16 / fp16 out) 43.7 / 41.9 us (wrong) 43.8 / 41.7 us 0%
MI455X 12 heads x DV 128, 512 tiles x 4 splits, 2 rows per tile (bf16 / fp16 out) 14.3 / 14.3 us (intermittently wrong) 13.6 / 13.7 us within noise
MI455X 64 heads x DV 512, 2 rows per tile, 16–256 tiles x 4–32 splits (20 shapes) 7.7–226.6 us 7.8–227.8 us within run-to-run noise
MI455X 16 / 32 heads x DV 512, 4 rows per tile, same grid (40 shapes) 5.9–224.5 us 5.8–224.2 us within run-to-run noise

Two runs of main itself differ by up to 11% on the smallest of these shapes (64 heads, 16 tiles x 4 splits: 7.9 and 8.7 us), and by 1–3% from 64 tiles up.

An earlier version put the barrier at the end of each row instead, before warp 0 starts the next row's loads. It cost 13% on the 64-row tiles (43.7 → 49.4 us), so it was dropped.

Testing

  • Unit tests added or updated
  • Performance benchmarks run (above)
  • Tested on MI250X
  • Tested on MI300X

On MI455X (gfx1250), aiter main at 111fbd8, module_mla_reduce built for gfx950 + gfx1250:

  • python3 op_tests/test_mla_reduce.py (all default dtypes, head dims and cases), 5 runs each. main: SOME FAILED in 5 of 5 (64x[4] h=12 dv=128 every run, 512x[4] in 2 of 5). Fix: ALL PASSED in 5 of 5.
  • The 60 multi-row decode shapes of the table, each checked against the torch reference. main: 27 wrong. Fix: 0 wrong.
  • Not run: gfx9 (compiles; same code path).

The existing cases cover it; no test is added. They fail intermittently rather than every run, so a new case would not make the race deterministic either.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Bug fix with no interface change.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 7912 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions github-actions Bot added the HIP label Nov 16, 2026
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 8e39d40f0985 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

zufayu pushed a commit that referenced this pull request Nov 17, 2026
…n row's stage-2 k-tile to K (#7963)

kimik3tp8_tuned_grouped_fmoe.csv runs the token=16384 row's stage 2
(K = inter_dim = 384 per TP8 expert slice) with tile_k2 = 512, larger
than K. The gfx1250 TDM grouped GEMM then reads past the expert slice and
the GPU faults in mxfp4_tdm_fp4_t128x128x512_..._K384_e896 ("Page not
present"). ATOM's warmup prefills 2 x 8192 tokens, so Kimi-K3 TP8 hits
this row at every server start.

Use tile_k2 = 128, which every other row of the table uses and which
divides 384. The row came from #7296; the other 14 rows are unchanged.

Verified on two MI455X nodes (Kimi-K3 TP8 + DCP8 with DSpark, ATOM main
9fec99786 + ROCm/ATOM#2647 + #2760, aiter main b6f1ff6 + #7912 + #7913
+ this change). The server starts where it faulted in warmup before.
GSM8K 5-shot is 0.9606 flexible / 0.9613 strict, and the MLPerf Endpoints
agentic bench completes 293/293 samples at c4 and 1703/1703 at c64.
@zufayu

zufayu commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Review ownership / next action:

  • Primary review: @minmengdie for the MLA/HIP path.
  • Please first validate the barrier placement / LDS race fix and the gfx1250 reproduction evidence.
  • Once the primary review is clear, I can follow with an integration co-review.

I will wait for the MLA primary review rather than approve ahead of it.

@zufayu
zufayu requested a review from kaiyang-1 November 17, 2026 13:30
@kaiyang-1
kaiyang-1 merged commit 90da535 into main Nov 18, 2026
@kaiyang-1
kaiyang-1 deleted the gyu/mla-reduce-v1-lds-race branch November 18, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants