Skip to content

[HIP] perf: gfx1250 LL all-gather lines carry 12 bytes and one flag - #7555

Merged
zejunchen-zejun merged 2 commits into
mainfrom
zejun/gfx1250-ag-ll12
Nov 11, 2026
Merged

zejunchen-zejun merged 2 commits into
mainfrom
zejun/gfx1250-ag-ll12

Conversation

@zejunchen-zejun

@zejunchen-zejun zejunchen-zejun commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

On gfx1250, an all-gather of up to 4 MiB a rank runs ag_ll_gfx1250. That kernel sends the all-reduce's LL lines: each 16-byte line carries 8 bytes of payload and two 4-byte flags. So a rank puts twice its input on the wire for every peer.

This hits Kimi-K3 TP8 + DCP8 prefill directly. Every MLA layer all-gathers the cached prefix's FP8 KV in chunks; a 16,384-token chunk is 2048 rows of 576 bytes a rank (1.18 MB). Across two MI455X trays that all-gather takes 31.9 µs.

This PR changes the kernel's lines to 12 bytes of payload and one flag, and each thread now moves one 12-byte unit. The same all-gather now takes 20.2 µs (1.58×). From 0.07 to 4.19 MB a rank the kernel is 1.21–1.72× faster at TP8 across two trays, and 1.09–1.62× at TP4 in one tray.

Approach

  • Line format. Words 0–2 of a 16-byte line carry 12 bytes of payload and word 3 the epoch flag. The wire carries 1.33 × the payload instead of 2 ×.
    • One flag is enough because a line is written with a single 16-byte system-scope store (ll_store_b128) and read with a single 16-byte load (ll_load_b128). The existing LL kernels rely on the same single-transaction property.
    • The last unit of a message may carry 4 or 8 bytes.
  • Shared LL state. The kernel uses the existing LL scratch, banks, slot stride and per-block epoch (d_ll_block_flags_). It therefore interleaves with ar_ll_gfx1250: a line written by another LL kernel carries an older epoch in word 3, so it is never mistaken for a fresh one.
  • Launch. Each thread takes one 12-byte unit:
    • 256-thread blocks while kMaxBlocks of them cover the message, then 512-thread blocks, then two units a thread above kMaxBlocks × 512 units (3 MiB).
    • Before, 256-thread blocks under the 512-block cap left some threads a second round from 1 MiB a rank. That round waits one fabric round trip, because on gfx1250 a load issued after a remote store waits for that store.
    • A thread issues all its loads before its remote stores, and polls all its lines in one batch.
  • Unchanged.
    • The routing: use_ll_ag (up to kLLArMaxBytes) decides by shape alone, so every rank takes the same protocol.
    • The in-place read of the input (ll_ag_reads_in_place), the scratch size and the Python side.
  • Alignment. A misaligned input or output moves byte by byte. That is a rank-local choice: the lines on the wire are the same.
  • Name. The kernel keeps its name, so use_ll_ag and its callers are untouched and this PR does not overlap [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages #7432 textually. Its template parameters change from <T, ngpus, ALIGNED> to <ngpus, U, ALIGNED>, so a trace still tells the two versions apart.

Op-level speedup

MI455X, rows of 288 two-byte elements (the K3 DCP prefix-KV rows). Device µs per call of 50 back-to-back calls on the slowest rank, median of 7 rounds (TP8) or 5 rounds (TP4). The rounds interleave the old and the new kernel in one process. Every call's output is bit-exact on every rank.

TP8 across two trays (4 + 4 GPUs, UALink):

per rank rows before after speedup time
0.074 MB 128 10.7 8.8 1.21× −18%
0.295 MB 512 13.7 11.2 1.22× −18%
0.516 MB 896 15.3 12.1 1.27× −21%
0.590 MB 1024 17.8 12.4 1.43× −30%
1.106 MB 1920 29.0 18.1 1.61× −38%
1.180 MB 2048 31.9 20.2 1.58× −37%
1.769 MB 3072 37.7 27.0 1.40× −28%
2.359 MB 4096 49.4 28.8 1.72× −42%
3.539 MB 6144 71.9 51.1 1.41× −29%
4.193 MB 7280 78.4 54.1 1.45× −31%

Bold rows are the K3 DCP prefill chunks of 7168, 15360 and 16384 tokens.

TP4 in one tray:

per rank rows before after speedup time
0.074 MB 128 8.0 7.3 1.09× −8%
0.295 MB 512 9.0 7.9 1.14× −12%
0.516 MB 896 10.0 8.6 1.17× −14%
1.106 MB 1920 16.3 10.6 1.53× −35%
1.180 MB 2048 16.6 11.4 1.45× −31%
2.359 MB 4096 25.8 15.9 1.62× −38%
4.193 MB 7280 36.6 24.0 1.52× −34%

Dev record

  • Found:
    • At TP8 across two trays, ncclAllGather (RCCL 2.30.7, MNNVL) takes 34.2 / 56.0 / 104.5 µs at 0.52 / 1.18 / 4.19 MB a rank. That is 1.3–2.2 × the old LL kernel's time and 1.9–2.9 × the new kernel's.
    • The copy-in + pull path overtook the old LL kernel at about 3.5 MB a rank (71.8 vs 71.9 µs; 54.3 vs 78.4 µs at 4.19 MB), so the 4 MiB LL cap was too high for it. The new kernel stays ahead of copy-in + pull up to the cap (54.1 vs 54.3 µs at 4.19 MB), so the cap stays.
  • Decided:
    • One flag a 16-byte line rather than an LL128-style protocol. A wider protocol would rely on the order in which several stores land in a peer's memory, which the fabric does not promise.
    • A push protocol was tried and dropped: plain stores, then per-block flags once the stores complete. It loses to LL below 4 MiB because it adds a round trip for store completion plus a flag. On gfx1250 a system-scope release is a global_wb of the L2 per wave, and an acquire load a global_inv per poll.
    • Check ag_ll_gfx1250 and allgather_ll.
  • Surprised:
    • Across trays the same kernel's time drifts up to 1.5× between runs minutes apart, so every comparison above interleaves the variants in one process.
    • custom_all_gather costs about 13 µs of host time a call, more than the kernel itself below 0.5 MB a rank. The device times above are measured with the GPU held behind a spin while the host queues the calls.
  • Left undone:
    • The all-reduce LL kernels (ar_ll_gfx1250) still send 8-byte lines.
    • The dim-0 copy-in + pull path still takes naive_unroll4 when numel is a multiple of 1024 packs. At TP8 that kernel is latency-bound: 65–72 µs from 0.3 to 3.5 MB a rank, against 22–35 µs for naive_vec. It runs only above 4 MiB or with LL off.

Named result

Kimi-K3 TP8 + DCP8 across two MI455X trays: the prefill prefix-KV all-gather of a 16,384-token chunk (2048 rows of 576 bytes a rank) drops from 31.9 to 20.2 µs a call (−37%). Each prefill MLA layer runs two or three of these (2048 / 2048 / 896 rows in a c32 MLPerf Endpoints agentic trace).

Gates

  • op_tests/multigpu_tests/test_allgather.py at TP4: all 40 cases err 0.
    • The cases include odd ranks' input one element into its storage (rank_offset, the byte-wise build), last-dim rows of 8 bytes ((12, 4), a unit spanning rows) and the new K3 DCP shapes (2048, 288) and (896, 288).
  • op_tests/multigpu_tests/test_custom_allreduce.py at TP4 passes, including the gfx1250 LL mixed-size regression, where LL all-reduces share the scratch and epochs.
  • Stress at TP8 across two trays: 0 mismatching words.
    • It ran 3000 back-to-back calls for each of 6 sizes (4.6 KB to 4.19 MB a rank), on this kernel at 256- and 512-thread blocks. Every call changes the input and compares every rank's whole output on the GPU.
  • The 1105 Kimi-K3 image builds the module from this branch's sources.
Evidence: how the numbers were taken
  • Setup: two MI455X trays in one UALink vpod; image rocm/fw-bringup:gfx1250-atom-k3-20261105; AITER_CUSTOM_AR_USE_SYMM_MEM=1 (the symm_mem / mori transport the K3 server uses across trays).
  • Calls: CustomAllreduce.custom_all_gather(x, 0) as CudaCommunicator.all_gather calls it, with x an fp16 tensor of [rows, 288].
  • Timing: 5 warm-up calls; a GPU spin of 20 ms while the host queues 3 alignment calls and 50 timed calls; events around the 50. The reported number is the slowest rank's time per call.
  • Rounds: the old kernel was built back in behind an evaluation-only switch, read on every call, so that each round runs both kernels.
  • Exactness: each variant's output is compared bit for bit with every rank's input, regenerated from its seed.

@github-actions

github-actions Bot commented Nov 6, 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:windows Windows JIT op smoke test on the gfx1201 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 7555 --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.

… one flag

ag_ll_gfx1250 sent the all-reduce's LL lines, 8 bytes of payload and two
flags in 16 bytes, so a rank pushed 2 x (ngpus - 1) x its input. A line is
one 16-byte store and one 16-byte load, so a single flag in word 3 guards
it, and words 0-2 now carry 12 bytes: 1.33 x on the wire. The kernel keeps
its name, the LL epoch, banks and slot stride, the routing (use_ll_ag) and
the in-place read. Each thread takes one 12-byte unit and loads before its
remote stores: 256-thread blocks while kMaxBlocks of them cover the message,
then 512-thread blocks, then two units a thread. Before, the 512-block cap
left threads a second round, one fabric round trip, from 1 MiB a rank.

MI455X, rows of 288 two-byte elements (the Kimi-K3 DCP prefill prefix-KV
gather), device time of back-to-back calls, rounds interleaved with the old
kernel:
TP8 across two trays: 0.52 MB a rank 15.3 -> 12.1 us, 1.18 MB 31.9 -> 20.2 us,
2.36 MB 49.4 -> 28.8 us, 4.19 MB 78.4 -> 54.1 us.
TP4 in one tray: 0.52 MB 10.0 -> 8.6 us, 1.18 MB 16.6 -> 11.4 us,
4.19 MB 36.6 -> 24.0 us.

test_allgather.py adds the K3 DCP shapes (2048, 288) and (896, 288).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@zejunchen-zejun zejunchen-zejun changed the title Zejun/gfx1250 ag ll12 [HIP] perf: gfx1250 LL all-gather lines carry 12 bytes and one flag Nov 6, 2026
@zejunchen-zejun
zejunchen-zejun marked this pull request as ready for review November 9, 2026 03:04
@zejunchen-zejun
zejunchen-zejun requested review from a team and a balanced review from Copilot November 9, 2026 03:04

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 9, 2026
@aiter-bot

aiter-bot commented Nov 9, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision c0fae66c9875 · 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
  • FAIL — changed op test not explained in Changed op tests: op_tests/multigpu_tests/test_allgather.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

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

@TennyWang1223 TennyWang1223 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.

LGTM

Copilot AI balanced review requested due to automatic review settings November 10, 2026 08:19

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.

@zejunchen-zejun
zejunchen-zejun merged commit 882bd62 into main Nov 11, 2026
@zejunchen-zejun
zejunchen-zejun deleted the zejun/gfx1250-ag-ll12 branch November 11, 2026 01:42
lirui927 pushed a commit that referenced this pull request Nov 16, 2026
… one flag (#7555)

ag_ll_gfx1250 sent the all-reduce's LL lines, 8 bytes of payload and two
flags in 16 bytes, so a rank pushed 2 x (ngpus - 1) x its input. A line is
one 16-byte store and one 16-byte load, so a single flag in word 3 guards
it, and words 0-2 now carry 12 bytes: 1.33 x on the wire. The kernel keeps
its name, the LL epoch, banks and slot stride, the routing (use_ll_ag) and
the in-place read. Each thread takes one 12-byte unit and loads before its
remote stores: 256-thread blocks while kMaxBlocks of them cover the message,
then 512-thread blocks, then two units a thread. Before, the 512-block cap
left threads a second round, one fabric round trip, from 1 MiB a rank.

MI455X, rows of 288 two-byte elements (the Kimi-K3 DCP prefill prefix-KV
gather), device time of back-to-back calls, rounds interleaved with the old
kernel:
TP8 across two trays: 0.52 MB a rank 15.3 -> 12.1 us, 1.18 MB 31.9 -> 20.2 us,
2.36 MB 49.4 -> 28.8 us, 4.19 MB 78.4 -> 54.1 us.
TP4 in one tray: 0.52 MB 10.0 -> 8.6 us, 1.18 MB 16.6 -> 11.4 us,
4.19 MB 36.6 -> 24.0 us.

test_allgather.py adds the K3 DCP shapes (2048, 288) and (896, 288).

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: TennyWang1223 <[email protected]>
(cherry picked from commit 882bd62)
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.

4 participants