Repository navigation
[HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages - #7432
Conversation
…ages
On gfx1250 the custom all-reduce had a flat one-shot LL kernel up to 4 MiB,
which sends (n - 1) x the message per rank (x2 for LL lines), and above that a
one-shot pull (ar_gfx1250_naive_unroll4) that is 4-8x slower than RCCL at TP8.
Add ar_2s_ll_gfx1250, a reduce-scatter + all-gather over the same LL lines,
scratch, banks and per-block epochs as ar_ll_gfx1250, so no buffer is added.
Each rank sends 2 (n - 1) / n x the message (x2 for LL lines), for one more
fabric round trip. It takes inputs from 1 MiB up to world_size x 2 MiB (one
bank of the LL scratch) at 4+ ranks and reads them in place (no copy-in). The
existing knobs keep their meaning: AITER_CUSTOM_AR_MAX_SIZE caps it and
AITER_CUSTOM_AR_DISABLE_LL turns it off with the one-shot LL.
Also launch both LL kernels with 512-thread blocks once 256-thread blocks
would put more than one block on a CU (the CU count is read at run time): at
TP8 the one-shot at 0.57 MB drops from 20.0 to 18.0 us, level with RCCL.
MI455X, TP8 across two trays over UALink, bf16, CUDA graph, us per call:
size RCCL* before after
0.57 MB 17.2 20.0 18.0 one-shot, 512-thread blocks
1.15 MB 29.7 28.8 23.3 two-shot
2.29 MB 39.2 47.9 25.6
3.67 MB 40.7 74.0 26.3
4.59 MB 42.2 157.8 34.5
8.39 MB 44.3 270.9 40.6
* RCCL 2.30.7 with RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and
RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728
Tests: test_custom_allreduce.py gains a gfx1250 LL two-shot mixed-size
regression. It runs two-shot and one-shot sizes back to back and negates the
inputs every other round, so a stale line cannot pass. The --regression suite
passes at TP4 with --transport symm and auto. At TP8 across two trays, 200
calls per size, each with a fresh random input, match an fp32 all-reduce to
bf16 rounding.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
The new fast path changes rank accumulation order, breaking tested BF16 numerical behavior, while regression tests leave stale-buffer reuse and TP6 two-shot coverage gaps.
3 open issues
What changed in this PR
This PR adds a gfx1250 two-shot custom all-reduce path to reduce communication traffic for larger messages, while reusing the existing LL scratch buffers and epoch tracking.
Changes:
- Adds reduce-scatter plus all-gather routing for eligible messages from 1 MiB through ranks × 2 MiB at four or more ranks.
- Skips input staging for the new path and selects LL block sizes using the GPU’s compute-unit count.
- Adds mixed-size regression coverage with alternating input signs.
| File | Description |
|---|---|
op_tests/multigpu_tests/test_custom_allreduce.py |
Adds mixed one-shot/two-shot regression cases and alternating inputs. |
csrc/kernels/custom_all_reduce_gfx1250.cu |
Skips staging copies for both LL all-reduce paths. |
csrc/include/custom_all_reduce_gfx1250.cuh |
Implements the two-shot kernel, dispatch conditions, and adaptive block sizing. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The two-shot kernel’s changed accumulation order breaks the established BF16 numerical reference, while regression gaps can hide stale payloads and skip two-shot execution entirely at TP6.
3 open issues
Review effort: Balanced
TennyWang1223
left a comment
There was a problem hiding this comment.
Review summary — #7432 gfx1250 LL two-shot all-reduce
The 1–8 MiB gains are compelling, but two things need to change before merge.
1. Rank-order summation is broken (blocking)
ar_2s_ll_gfx1250 (custom_all_reduce_gfx1250.cuh:449-476) adds the chunk owner's value first, then ranks rank-1, rank-2, .... Since #6954, every other custom-AR path sums ranks in a fixed 0..n-1 order. #6954 removed exactly this owner-first pattern.
- The result bits now depend on which rank owns an element (its row offset). They also change when a message crosses 1 MiB and switches between one-shot and two-shot, so results are no longer batch-invariant.
- At TP4,
test_custom_allreduce_rank_order.pynow sends[97,7168]bf16/fp16 and[512,7168]bf16 through this kernel. Its partials summed in this order give different bits (e.g. bf16 −0.02795 vs −0.02808 expected). - The new regression test uses integer-valued inputs, so the fp32 sums are exact and the test cannot catch this.
Fix: poll into w[s] indexed by sender rank (unrolled s = 0..n-1, skipping s == rank, so indexing stays compile-time). Accumulate in rank order with the local value at position rank. Then run test_custom_allreduce_rank_order.py on gfx1250 TP4.
2. Keep the two-shot independent of the LL scratch
The two-shot currently reuses the one-shot LL's state:
- the peer scratch and banks (
d_ll_peers_,flag & 1) - the epoch array (
d_ll_block_flags_) - its size cap (
ws × 2 MiB), which is derived fromkLLPackCapacity
This couples the two kernels. Any later change to the LL scratch layout or capacity would silently change the two-shot's correctness and routing. Interleaving safety also has to be reasoned about across both kernels.
Please:
- Give the two-shot its own scratch region in the meta buffer, with its own offset/size constants counted in
meta_size(), and its own epoch array. - Size that region from the two-shot's own cap, not from
kLLPackCapacity. - Leave
ar_ll_gfx1250,kLLScratchCapBytes/kLLPackCapacityand the LL scratch layout unchanged.
3. Take the upper cap from measurements
Your TP8 data shows RCCL ahead above ~8 MiB (14.68 MB: 59.1 µs vs 51–54 µs). use_2s_ll still accepts up to 16 MiB, and AITER_CUSTOM_AR_MAX_SIZE defaults to 64 MiB, so default configs take the slower path. Set the cap per TP in code from the measured crossover. That cap also sets the size of the new scratch region.
ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…50 LL two-shot
The two-shot reused the one-shot LL's state. It carved each LL bank into
chunk-sized reduce-scatter and all-gather regions, shared the LL per-block
epochs, and derived its size cap (world_size x 2 MiB) from kLLPackCapacity.
A change to the LL scratch layout or capacity would therefore have changed
the two-shot's correctness and routing without notice.
- Own scratch: after the fused AR + RMSNorm shard in the meta buffer
(ar2sScratchOffset). It is counted in meta_size(), so every transport
zero-initializes it with the rest. It has two banks, each with a
reduce-scatter and an all-gather region of ar2sMaxBytes / 8 lines. That is
8 x ar2sMaxBytes a rank: 64 MiB at TP4 and TP8, nothing at TP2 or TP6.
- Own peer table and per-block epochs (d_2s_peers_, d_2s_block_flags_),
built at construction like the LL tables, so nothing is allocated inside a
graph capture.
- A per-world-size cap from measurements (ar2sMaxBytes), which also sizes the
scratch:
- TP8, two MI455X trays: 8 MiB. The two-shot is ahead of RCCL at 8.39 MB
(40.6 vs 44.3 us) and behind at 14.68 MB (59.1 vs 51.0 us).
- TP4: 8 MiB, as before. RCCL within a tray is not measured yet.
- TP6: off, as it is not measured.
- ar_ll_gfx1250, ag_ll_gfx1250, kLLScratchCapBytes, kLLPackCapacity and the
LL scratch layout are unchanged. Built for gfx1250, the one-shot and
all-gather LL kernels keep identical resource usage.
With AITER_CUSTOM_AR_MAX_SIZE unset (64 MiB), an all-reduce of 8-16 MiB at
TP8 now takes the one-shot pull (ar_gfx1250_naive_unroll4), as on main,
rather than the two-shot. Sending it to RCCL by default needs a per-TP
gfx1250 AR cutoff in _resolve_custom_sizes, which is left for the review.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nk reuse Rounds of the mixed-size regression alternated x and -x. A kernel reuses the same scratch bank every second call of that kernel. For a kernel called once a round (here the one-shot LL), the bank's previous contents therefore carried the sign now expected, and accepting a stale line would still have passed the exact comparison. Rounds now cycle through x, -x and 2x, which is exact both in fp32 and on bf16 integers. The previous use of any bank, one or two rounds back, never carries the expected bits. The test now runs only at TP4 and TP8, where the two-shot runs (ar2sMaxBytes); at TP6 it only ever exercised the one-shot and the pull. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, @TennyWang1223 . All three points are addressed. The commits sit on top of a merge of main, which brings in #7433:
1. Rank-order summation (267f69c)
2. Own scratch and epochs (930c527)
3. Cap (930c527)
One caveat on "default configs take the slower path". With Sending these messages to RCCL by default needs the gfx1250 AR cutoff in Copilot's test comments (5c522b3)
|
Validation on MI455X (gfx1250), head 5c522b3Setup
Checklist
TP4, µs
Notes
|
|
Suggestion:
|
|
Thanks @lihaoyang-amd , this split is better than moving the cutoff in
|
|
Hi @TennyWang1223 @haoyangli0109 @zufayu |
There was a problem hiding this comment.
LGTM,
But we still need tenny's approval.
cc @TennyWang1223
…nders and pollers in separate waves Decode-size all-reduces at TP8 were slow in both LL kernels: - each 16-byte line carried 8 bytes and two flags, so a rank moved 2 x its payload on the wire; - a poll was issued after the same wave's remote stores, and on gfx1250 a load after a remote store waits for that store (about a fabric round trip) while a peer's line lands in about half of one; - the one-shot polled the peers one after another and re-read the peer table (scalar loads) between its stores. Both kernels now send 12-byte lines with one flag (a line is a single 16-byte store and load, so one flag guards it), read the peer bases once before any store, and poll every peer in one batch. The one-shot runs W senders and W pollers a block; the two-shot three wave groups (send the reduce-scatter; poll, reduce and send the all-gather; poll the all-gather). Both still sum in rank order in fp32 and round once, so results are bit-identical to before. The two-shot's per-source slots start on 4 KiB boundaries (a misaligned slot cost ~3 us a call). Blocks: the smallest W with one block a CU. The two-shot takes over from 768 KiB at TP8 (ar2sMinBytes; 1 MiB elsewhere). MI455X TP8 across two trays, bf16, 50 all-reduces in one CUDA graph, us an all-reduce (slowest rank), before -> after: [40, 3584] 0.29 MB 15.8 -> 11.4, [40, 7168] 0.57 MB 19.1 -> 13.4, [80, 7168] 1.15 MB 23.8 -> 18.1, [115, 3584] 0.82 MB 22.0 -> 16.9, [115, 7168] 1.65 MB 26.0 -> 18.1, [320, 7168] 4.59 MB 34.9 -> 26.5. Checked bit for bit against an fp32 rank-order sum at 28 shapes, with 600 mixed calls interleaving the all-gather, and over CUDA-graph replays. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TennyWang1223
left a comment
There was a problem hiding this comment.
Review summary — #7432 (head 6b28946)
Verdict: Request changes. Up to 5c522b3 the PR was close to mergeable. The blockers come from the last commit 6b28946 and from one promised change that was never pushed.
Previous review points
| # | Point | Status |
|---|---|---|
| 1 | Sum ranks in order 0..n−1 | ✅ Fixed in 267f69c |
| 2 | Two-shot gets its own scratch and epochs; LL left unchanged | 930c527, then 6b28946 rewrote ar_ll_gfx1250 |
| 3 | Per-TP cap taken from measurements |
Must fix
1. 6b28946 rewrites the one-shot LL kernel, with no PR comment and no posted validation
ar_ll_gfx1250is the path every gfx1250 decode all-reduce of 1 MiB or less takes, at every TP. Point 2 asked to leave it unchanged, and your 11-05 reply said it was.- It was pushed after the only approval, so that approval covers
5c522b3, not head. - The new U=2/4 sender paths (one-shot messages above ~1.5 MiB, e.g. TP2) are outside the
--regressionruns you reported. - Action: split the one-shot rewrite into its own PR, or post TP2/4/8 correctness and timing for
6b28946. Either way, update the PR description: it still describes the first revision.
2. The one-shot is no longer safe when out aliases inp
- Sender and poller now run in different waves. A poller writes
out[3i+q]as soon as the peers' lines arrive, without waiting for this rank's sender to loadin[3i+q]. - If
out == inp, this rank can publish the already-reduced value, and every peer gets a wrong sum with no error. - Base was alias-safe because each thread published before it reduced. The all-gather has
ll_ag_reads_in_place;all_reduce()has no such check. - Action: in
all_reduce(), reject anoutthat overlapsinpon the LL paths, or restore alias safety in the kernel.
3. One flag per 16-byte line requires 16-byte remote atomicity
- Base lines were
[d0, f0, d1, f1]and both flags were checked, which needs only 8-byte atomicity. Both LL all-reduce kernels now carry[d0, d1, d2, flag]and check word 3 only. - If a remote
global_store_b128over UALink can be split, a poller can read a new flag with stale data. - Action: cite the gfx1250 / UALink spec that guarantees 16-byte single-copy atomicity for system-scope b128 stores and loads to a peer. Otherwise keep a flag per 8 bytes.
4. The default cutoff promised on 11-05 is missing
- The diff has no Python change, no binding returning
max(kLLArMaxBytes, ar2sMaxBytes(ws)), and no cutoff test. - With
AITER_CUSTOM_AR_MAX_SIZEunset, TP4 4–8 MiB takes the two-shot, which you measured slower than RCCL. 8–16 MiB at TP4/TP8 still takes the pull: 133–402 µs vs 41–54 µs for RCCL. - Action: add the cutoff in this PR, or state on the PR that it moves to a linked follow-up.
… one-shot safe in place Review of 6b28946 (#7432): - Lines carry 8 bytes again, [d0, flag, d1, flag], and a reader takes a line only once both flags carry the epoch, so a line has to land atomically per 8 bytes only. The 12-byte lines with one flag relied on a remote b128 store landing atomically as a whole, which no gfx1250 or UALink document guarantees. - The one-shot is safe with recvbuff == sendbuff again. Its sender also writes the line to its own scratch, first, and the poller takes the local value from that line. So no output is written before its input packet has been loaded and sent. - The two-shot runs send, reduce and gather in three wave groups while one block of 3 x 128 threads a CU covers a chunk, else in two, with gather in the send group, so a block covers more packets a CU. It takes over from the one-shot at 512 KiB at TP8 (1 MiB at TP4, as before). - Kept from 6b28946: sender and poller waves, batched polls, peer bases read once into registers. MI455X, bf16, CUDA graph, us an all-reduce (slowest rank), 5c522b3 -> this: TP8, two trays: 0.29 MB 14.6 -> 12.0, 0.57 MB 17.6 -> 13.5, 1.15 MB 22.6 -> 15.3, 1.65 MB 24.3 -> 15.6, 4.59 MB 34.2 -> 28.4, 8.39 MB 41.5 -> 39.2 TP4: 1.15 MB 14.6 -> 10.4, 2.29 MB 17.1 -> 14.2, 4.59 MB 27.5 -> 22.2 TP2: 1.65 MB 11.7 -> 9.5, 2.29 MB 13.8 -> 11.9 The regression test gets an in-place case (output aliasing the input) that covers the one-shot with 1, 2 and 4 packets a sender, and the two-shot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the measured crossover As agreed on #7432 (11-05). On gfx1250, with AITER_CUSTOM_AR_MAX_SIZE unset, plain all-reduce (CudaCommunicator.all_reduce) runs the custom kernels only up to about where RCCL becomes faster: 4 MiB at TP2 and TP4, 8 MiB at TP8. Larger inputs went to the two-shot (TP4, 4-8 MiB) or to the one-shot pull, which takes 405 us at 14.68 MB at TP8 against 55 us for RCCL. - New binding ll_ar_max_bytes(world_size): the largest input the LL kernels take, max(kLLArMaxBytes, ar2sMaxBytes). The default never exceeds it, so Python does not copy the C++ caps. - An explicit AITER_CUSTOM_AR_MAX_SIZE keeps its meaning. TP6 and gfx9 keep the AR cutoff. - should_custom_ar and the fused AR + RMSNorm paths are unchanged; their fallback to all_reduce picks up the default. - Tests: the default applies only with the env unset (test_custom_allreduce_size_env.py), and every rank resolves the same cutoff and takes the same path (test_custom_allreduce.py --regression). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks @TennyWang1223. All four points are addressed in two commits on top of 6b28946:
I kept the one-shot rewrite in this PR, with the validation below. The PR description is rewritten for the current head. Its Evidence section has the full TP2, TP4 and TP8 tables. 1. The one-shot rewrite and its validationYou're right. On 11-05 I said Validation of head 04c61b7. MI455X, image
2. In placeRight. With the poller in its own wave, an output could land before its input was sent. No caller passes
3. 16-byte atomicityI couldn't find a gfx1250 or UALink document that guarantees a remote b128 store lands atomically as a whole. The closest are in LLVM's AMDGPUUsage:
6b28946 passed every check we ran, but passing tests doesn't establish the guarantee. So both kernels are back to The LL all-gather merged in #7555 uses the same 12-byte lines with one flag, so it relies on the same assumption. I suggest a follow-up that moves it back to a flag per 8 bytes, unless we get that guarantee for peer memory. 4. Default cutoff (04c61b7)As agreed with @haoyangli0109 on 11-05:
TP2 is new compared with the 11-05 plan. It is measured now, and above 4 MiB it took the pull, which is slower than RCCL.
|
Conflicts with #7499 (gfx1250 Lamport AR + RMSNorm), both additive: the plain all-reduce cutoff table and the Lamport size table in custom_all_reduce.py, and the two-shot tables and the Lamport inbox member in CustomAllreduce. Both kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ages (#7432) * [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages On gfx1250 the custom all-reduce had a flat one-shot LL kernel up to 4 MiB, which sends (n - 1) x the message per rank (x2 for LL lines), and above that a one-shot pull (ar_gfx1250_naive_unroll4) that is 4-8x slower than RCCL at TP8. Add ar_2s_ll_gfx1250, a reduce-scatter + all-gather over the same LL lines, scratch, banks and per-block epochs as ar_ll_gfx1250, so no buffer is added. Each rank sends 2 (n - 1) / n x the message (x2 for LL lines), for one more fabric round trip. It takes inputs from 1 MiB up to world_size x 2 MiB (one bank of the LL scratch) at 4+ ranks and reads them in place (no copy-in). The existing knobs keep their meaning: AITER_CUSTOM_AR_MAX_SIZE caps it and AITER_CUSTOM_AR_DISABLE_LL turns it off with the one-shot LL. Also launch both LL kernels with 512-thread blocks once 256-thread blocks would put more than one block on a CU (the CU count is read at run time): at TP8 the one-shot at 0.57 MB drops from 20.0 to 18.0 us, level with RCCL. MI455X, TP8 across two trays over UALink, bf16, CUDA graph, us per call: size RCCL* before after 0.57 MB 17.2 20.0 18.0 one-shot, 512-thread blocks 1.15 MB 29.7 28.8 23.3 two-shot 2.29 MB 39.2 47.9 25.6 3.67 MB 40.7 74.0 26.3 4.59 MB 42.2 157.8 34.5 8.39 MB 44.3 270.9 40.6 * RCCL 2.30.7 with RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728 Tests: test_custom_allreduce.py gains a gfx1250 LL two-shot mixed-size regression. It runs two-shot and one-shot sizes back to back and negates the inputs every other round, so a stale line cannot pass. The --regression suite passes at TP4 with --transport symm and auto. At TP8 across two trays, 200 calls per size, each with a fresh random input, match an fp32 all-reduce to bf16 rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): sum the gfx1250 LL two-shot in rank order ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] refactor(custom_ar): own scratch and a per-TP cap for the gfx1250 LL two-shot The two-shot reused the one-shot LL's state. It carved each LL bank into chunk-sized reduce-scatter and all-gather regions, shared the LL per-block epochs, and derived its size cap (world_size x 2 MiB) from kLLPackCapacity. A change to the LL scratch layout or capacity would therefore have changed the two-shot's correctness and routing without notice. - Own scratch: after the fused AR + RMSNorm shard in the meta buffer (ar2sScratchOffset). It is counted in meta_size(), so every transport zero-initializes it with the rest. It has two banks, each with a reduce-scatter and an all-gather region of ar2sMaxBytes / 8 lines. That is 8 x ar2sMaxBytes a rank: 64 MiB at TP4 and TP8, nothing at TP2 or TP6. - Own peer table and per-block epochs (d_2s_peers_, d_2s_block_flags_), built at construction like the LL tables, so nothing is allocated inside a graph capture. - A per-world-size cap from measurements (ar2sMaxBytes), which also sizes the scratch: - TP8, two MI455X trays: 8 MiB. The two-shot is ahead of RCCL at 8.39 MB (40.6 vs 44.3 us) and behind at 14.68 MB (59.1 vs 51.0 us). - TP4: 8 MiB, as before. RCCL within a tray is not measured yet. - TP6: off, as it is not measured. - ar_ll_gfx1250, ag_ll_gfx1250, kLLScratchCapBytes, kLLPackCapacity and the LL scratch layout are unchanged. Built for gfx1250, the one-shot and all-gather LL kernels keep identical resource usage. With AITER_CUSTOM_AR_MAX_SIZE unset (64 MiB), an all-reduce of 8-16 MiB at TP8 now takes the one-shot pull (ar_gfx1250_naive_unroll4), as on main, rather than the two-shot. Sending it to RCCL by default needs a per-TP gfx1250 AR cutoff in _resolve_custom_sizes, which is left for the review. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] test(custom_ar): vary the LL two-shot regression's inputs on bank reuse Rounds of the mixed-size regression alternated x and -x. A kernel reuses the same scratch bank every second call of that kernel. For a kernel called once a round (here the one-shot LL), the bank's previous contents therefore carried the sign now expected, and accepting a stale line would still have passed the exact comparison. Rounds now cycle through x, -x and 2x, which is exact both in fp32 and on bf16 integers. The previous use of any bank, one or two rounds back, never carries the expected bits. The test now runs only at TP4 and TP8, where the two-shot runs (ar2sMaxBytes); at TP6 it only ever exercised the one-shot and the pull. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 LL all-reduce lines carry 12 bytes; senders and pollers in separate waves Decode-size all-reduces at TP8 were slow in both LL kernels: - each 16-byte line carried 8 bytes and two flags, so a rank moved 2 x its payload on the wire; - a poll was issued after the same wave's remote stores, and on gfx1250 a load after a remote store waits for that store (about a fabric round trip) while a peer's line lands in about half of one; - the one-shot polled the peers one after another and re-read the peer table (scalar loads) between its stores. Both kernels now send 12-byte lines with one flag (a line is a single 16-byte store and load, so one flag guards it), read the peer bases once before any store, and poll every peer in one batch. The one-shot runs W senders and W pollers a block; the two-shot three wave groups (send the reduce-scatter; poll, reduce and send the all-gather; poll the all-gather). Both still sum in rank order in fp32 and round once, so results are bit-identical to before. The two-shot's per-source slots start on 4 KiB boundaries (a misaligned slot cost ~3 us a call). Blocks: the smallest W with one block a CU. The two-shot takes over from 768 KiB at TP8 (ar2sMinBytes; 1 MiB elsewhere). MI455X TP8 across two trays, bf16, 50 all-reduces in one CUDA graph, us an all-reduce (slowest rank), before -> after: [40, 3584] 0.29 MB 15.8 -> 11.4, [40, 7168] 0.57 MB 19.1 -> 13.4, [80, 7168] 1.15 MB 23.8 -> 18.1, [115, 3584] 0.82 MB 22.0 -> 16.9, [115, 7168] 1.65 MB 26.0 -> 18.1, [320, 7168] 4.59 MB 34.9 -> 26.5. Checked bit for bit against an fp32 rank-order sum at 28 shapes, with 600 mixed calls interleaving the all-gather, and over CUDA-graph replays. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): gfx1250 LL all-reduce keeps a flag per 8 bytes; one-shot safe in place Review of 6b28946 (#7432): - Lines carry 8 bytes again, [d0, flag, d1, flag], and a reader takes a line only once both flags carry the epoch, so a line has to land atomically per 8 bytes only. The 12-byte lines with one flag relied on a remote b128 store landing atomically as a whole, which no gfx1250 or UALink document guarantees. - The one-shot is safe with recvbuff == sendbuff again. Its sender also writes the line to its own scratch, first, and the poller takes the local value from that line. So no output is written before its input packet has been loaded and sent. - The two-shot runs send, reduce and gather in three wave groups while one block of 3 x 128 threads a CU covers a chunk, else in two, with gather in the send group, so a block covers more packets a CU. It takes over from the one-shot at 512 KiB at TP8 (1 MiB at TP4, as before). - Kept from 6b28946: sender and poller waves, batched polls, peer bases read once into registers. MI455X, bf16, CUDA graph, us an all-reduce (slowest rank), 5c522b3 -> this: TP8, two trays: 0.29 MB 14.6 -> 12.0, 0.57 MB 17.6 -> 13.5, 1.15 MB 22.6 -> 15.3, 1.65 MB 24.3 -> 15.6, 4.59 MB 34.2 -> 28.4, 8.39 MB 41.5 -> 39.2 TP4: 1.15 MB 14.6 -> 10.4, 2.29 MB 17.1 -> 14.2, 4.59 MB 27.5 -> 22.2 TP2: 1.65 MB 11.7 -> 9.5, 2.29 MB 13.8 -> 11.9 The regression test gets an in-place case (output aliasing the input) that covers the one-shot with 1, 2 and 4 packets a sender, and the two-shot. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 plain all-reduce defaults to RCCL past the measured crossover As agreed on #7432 (11-05). On gfx1250, with AITER_CUSTOM_AR_MAX_SIZE unset, plain all-reduce (CudaCommunicator.all_reduce) runs the custom kernels only up to about where RCCL becomes faster: 4 MiB at TP2 and TP4, 8 MiB at TP8. Larger inputs went to the two-shot (TP4, 4-8 MiB) or to the one-shot pull, which takes 405 us at 14.68 MB at TP8 against 55 us for RCCL. - New binding ll_ar_max_bytes(world_size): the largest input the LL kernels take, max(kLLArMaxBytes, ar2sMaxBytes). The default never exceeds it, so Python does not copy the C++ caps. - An explicit AITER_CUSTOM_AR_MAX_SIZE keeps its meaning. TP6 and gfx9 keep the AR cutoff. - should_custom_ar and the fused AR + RMSNorm paths are unchanged; their fallback to all_reduce picks up the default. - Tests: the default applies only with the env unset (test_custom_allreduce_size_env.py), and every rank resolves the same cutoff and takes the same path (test_custom_allreduce.py --regression). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…ages (#7432) * [HIP] perf(custom_ar): gfx1250 LL two-shot all-reduce for 1 MiB+ messages On gfx1250 the custom all-reduce had a flat one-shot LL kernel up to 4 MiB, which sends (n - 1) x the message per rank (x2 for LL lines), and above that a one-shot pull (ar_gfx1250_naive_unroll4) that is 4-8x slower than RCCL at TP8. Add ar_2s_ll_gfx1250, a reduce-scatter + all-gather over the same LL lines, scratch, banks and per-block epochs as ar_ll_gfx1250, so no buffer is added. Each rank sends 2 (n - 1) / n x the message (x2 for LL lines), for one more fabric round trip. It takes inputs from 1 MiB up to world_size x 2 MiB (one bank of the LL scratch) at 4+ ranks and reads them in place (no copy-in). The existing knobs keep their meaning: AITER_CUSTOM_AR_MAX_SIZE caps it and AITER_CUSTOM_AR_DISABLE_LL turns it off with the one-shot LL. Also launch both LL kernels with 512-thread blocks once 256-thread blocks would put more than one block on a CU (the CU count is read at run time): at TP8 the one-shot at 0.57 MB drops from 20.0 to 18.0 us, level with RCCL. MI455X, TP8 across two trays over UALink, bf16, CUDA graph, us per call: size RCCL* before after 0.57 MB 17.2 20.0 18.0 one-shot, 512-thread blocks 1.15 MB 29.7 28.8 23.3 two-shot 2.29 MB 39.2 47.9 25.6 3.67 MB 40.7 74.0 26.3 4.59 MB 42.2 157.8 34.5 8.39 MB 44.3 270.9 40.6 * RCCL 2.30.7 with RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152 and RCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728 Tests: test_custom_allreduce.py gains a gfx1250 LL two-shot mixed-size regression. It runs two-shot and one-shot sizes back to back and negates the inputs every other round, so a stale line cannot pass. The --regression suite passes at TP4 with --transport symm and auto. At TP8 across two trays, 200 calls per size, each with a fresh random input, match an fp32 all-reduce to bf16 rounding. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): sum the gfx1250 LL two-shot in rank order ar_2s_ll_gfx1250 reduced the owner's value first, then the other ranks in descending ring order. Since #6954 every other custom all-reduce sums ranks 0..n-1, with the local value at its own rank. Under the owner-first order an element's bits depended on which rank owns its chunk, that is, on its offset in the message. They also changed when a message crossed 1 MiB, between the one-shot and the two-shot. At TP4, test_custom_allreduce_rank_order.py sends [97, 7168] bf16/fp16 and [512, 7168] bf16 through this kernel. The reduce now polls slots s = 0..ngpus-1, where slot s holds rank s's packet, and sums them in that order with the local value at position rank. The own slot is loaded too, which keeps the loads free of branches; its contents go unused. All indices stay compile-time. Built for gfx1250, the TP8 bf16 kernel takes 56 VGPRs instead of 50, at the same occupancy (16 waves/SIMD) and with no spills. The two-shot's mixed-size regression used integer inputs, whose fp32 sums are exact in any order. It now sums random fp32 partials and checks every round, bit for bit, against their sum in rank order 0..n-1, at any TP. The message sizes in bytes are unchanged, and so are the kernels and launch shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] refactor(custom_ar): own scratch and a per-TP cap for the gfx1250 LL two-shot The two-shot reused the one-shot LL's state. It carved each LL bank into chunk-sized reduce-scatter and all-gather regions, shared the LL per-block epochs, and derived its size cap (world_size x 2 MiB) from kLLPackCapacity. A change to the LL scratch layout or capacity would therefore have changed the two-shot's correctness and routing without notice. - Own scratch: after the fused AR + RMSNorm shard in the meta buffer (ar2sScratchOffset). It is counted in meta_size(), so every transport zero-initializes it with the rest. It has two banks, each with a reduce-scatter and an all-gather region of ar2sMaxBytes / 8 lines. That is 8 x ar2sMaxBytes a rank: 64 MiB at TP4 and TP8, nothing at TP2 or TP6. - Own peer table and per-block epochs (d_2s_peers_, d_2s_block_flags_), built at construction like the LL tables, so nothing is allocated inside a graph capture. - A per-world-size cap from measurements (ar2sMaxBytes), which also sizes the scratch: - TP8, two MI455X trays: 8 MiB. The two-shot is ahead of RCCL at 8.39 MB (40.6 vs 44.3 us) and behind at 14.68 MB (59.1 vs 51.0 us). - TP4: 8 MiB, as before. RCCL within a tray is not measured yet. - TP6: off, as it is not measured. - ar_ll_gfx1250, ag_ll_gfx1250, kLLScratchCapBytes, kLLPackCapacity and the LL scratch layout are unchanged. Built for gfx1250, the one-shot and all-gather LL kernels keep identical resource usage. With AITER_CUSTOM_AR_MAX_SIZE unset (64 MiB), an all-reduce of 8-16 MiB at TP8 now takes the one-shot pull (ar_gfx1250_naive_unroll4), as on main, rather than the two-shot. Sending it to RCCL by default needs a per-TP gfx1250 AR cutoff in _resolve_custom_sizes, which is left for the review. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] test(custom_ar): vary the LL two-shot regression's inputs on bank reuse Rounds of the mixed-size regression alternated x and -x. A kernel reuses the same scratch bank every second call of that kernel. For a kernel called once a round (here the one-shot LL), the bank's previous contents therefore carried the sign now expected, and accepting a stale line would still have passed the exact comparison. Rounds now cycle through x, -x and 2x, which is exact both in fp32 and on bf16 integers. The previous use of any bank, one or two rounds back, never carries the expected bits. The test now runs only at TP4 and TP8, where the two-shot runs (ar2sMaxBytes); at TP6 it only ever exercised the one-shot and the pull. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 LL all-reduce lines carry 12 bytes; senders and pollers in separate waves Decode-size all-reduces at TP8 were slow in both LL kernels: - each 16-byte line carried 8 bytes and two flags, so a rank moved 2 x its payload on the wire; - a poll was issued after the same wave's remote stores, and on gfx1250 a load after a remote store waits for that store (about a fabric round trip) while a peer's line lands in about half of one; - the one-shot polled the peers one after another and re-read the peer table (scalar loads) between its stores. Both kernels now send 12-byte lines with one flag (a line is a single 16-byte store and load, so one flag guards it), read the peer bases once before any store, and poll every peer in one batch. The one-shot runs W senders and W pollers a block; the two-shot three wave groups (send the reduce-scatter; poll, reduce and send the all-gather; poll the all-gather). Both still sum in rank order in fp32 and round once, so results are bit-identical to before. The two-shot's per-source slots start on 4 KiB boundaries (a misaligned slot cost ~3 us a call). Blocks: the smallest W with one block a CU. The two-shot takes over from 768 KiB at TP8 (ar2sMinBytes; 1 MiB elsewhere). MI455X TP8 across two trays, bf16, 50 all-reduces in one CUDA graph, us an all-reduce (slowest rank), before -> after: [40, 3584] 0.29 MB 15.8 -> 11.4, [40, 7168] 0.57 MB 19.1 -> 13.4, [80, 7168] 1.15 MB 23.8 -> 18.1, [115, 3584] 0.82 MB 22.0 -> 16.9, [115, 7168] 1.65 MB 26.0 -> 18.1, [320, 7168] 4.59 MB 34.9 -> 26.5. Checked bit for bit against an fp32 rank-order sum at 28 shapes, with 600 mixed calls interleaving the all-gather, and over CUDA-graph replays. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] fix(custom_ar): gfx1250 LL all-reduce keeps a flag per 8 bytes; one-shot safe in place Review of 6b28946 (#7432): - Lines carry 8 bytes again, [d0, flag, d1, flag], and a reader takes a line only once both flags carry the epoch, so a line has to land atomically per 8 bytes only. The 12-byte lines with one flag relied on a remote b128 store landing atomically as a whole, which no gfx1250 or UALink document guarantees. - The one-shot is safe with recvbuff == sendbuff again. Its sender also writes the line to its own scratch, first, and the poller takes the local value from that line. So no output is written before its input packet has been loaded and sent. - The two-shot runs send, reduce and gather in three wave groups while one block of 3 x 128 threads a CU covers a chunk, else in two, with gather in the send group, so a block covers more packets a CU. It takes over from the one-shot at 512 KiB at TP8 (1 MiB at TP4, as before). - Kept from 6b28946: sender and poller waves, batched polls, peer bases read once into registers. MI455X, bf16, CUDA graph, us an all-reduce (slowest rank), 5c522b3 -> this: TP8, two trays: 0.29 MB 14.6 -> 12.0, 0.57 MB 17.6 -> 13.5, 1.15 MB 22.6 -> 15.3, 1.65 MB 24.3 -> 15.6, 4.59 MB 34.2 -> 28.4, 8.39 MB 41.5 -> 39.2 TP4: 1.15 MB 14.6 -> 10.4, 2.29 MB 17.1 -> 14.2, 4.59 MB 27.5 -> 22.2 TP2: 1.65 MB 11.7 -> 9.5, 2.29 MB 13.8 -> 11.9 The regression test gets an in-place case (output aliasing the input) that covers the one-shot with 1, 2 and 4 packets a sender, and the two-shot. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] perf(custom_ar): gfx1250 plain all-reduce defaults to RCCL past the measured crossover As agreed on #7432 (11-05). On gfx1250, with AITER_CUSTOM_AR_MAX_SIZE unset, plain all-reduce (CudaCommunicator.all_reduce) runs the custom kernels only up to about where RCCL becomes faster: 4 MiB at TP2 and TP4, 8 MiB at TP8. Larger inputs went to the two-shot (TP4, 4-8 MiB) or to the one-shot pull, which takes 405 us at 14.68 MB at TP8 against 55 us for RCCL. - New binding ll_ar_max_bytes(world_size): the largest input the LL kernels take, max(kLLArMaxBytes, ar2sMaxBytes). The default never exceeds it, so Python does not copy the C++ caps. - An explicit AITER_CUSTOM_AR_MAX_SIZE keeps its meaning. TP6 and gfx9 keep the AR cutoff. - should_custom_ar and the fused AR + RMSNorm paths are unchanged; their fallback to all_reduce picks up the default. - Tests: the default applies only with the env unset (test_custom_allreduce_size_env.py), and every rank resolves the same cutoff and takes the same path (test_custom_allreduce.py --regression). Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 484095e)
Route the gfx1250 plain all-reduce through Lamport kernels on the shared Lamport inbox: a one-shot up to 1.25 MiB at TP4 and 9 MiB at TP2, and a new two-shot (pushed reduce-scatter + all-gather) above it, up to world_size x the Lamport cap (32 MiB at TP2/TP4). fp16/bf16 only; same bits as the custom all-reduce (rank-order fp32 sum). The plain all-reduce cutoff of CudaCommunicator.all_reduce (#7432, 4 MiB at TP2/TP4, RCCL above) no longer applies to the inputs the Lamport kernels take: they stay ahead of RCCL up to world_size x the cap. Other inputs keep the cutoff. The two-shot's all-gather gets a private inbox of world_size x cap after the escape inbox (per-rank Lamport buffer 120 -> 152 MiB at TP2/TP4); the shared inbox, the cap and the other Lamport ops are unchanged. Signed-off-by: TennyWang1223 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Route the gfx1250 plain all-reduce through Lamport kernels on the shared Lamport inbox: a one-shot up to 1.25 MiB at TP4 and 9 MiB at TP2, and a new two-shot (pushed reduce-scatter + all-gather) above it, up to world_size x the Lamport cap (32 MiB at TP2/TP4). fp16/bf16 only; same bits as the custom all-reduce (rank-order fp32 sum). The plain all-reduce cutoff of CudaCommunicator.all_reduce (#7432, 4 MiB at TP2/TP4, RCCL above) no longer applies to the inputs the Lamport kernels take: they stay ahead of RCCL up to world_size x the cap. Other inputs keep the cutoff. The two-shot's all-gather gets a private inbox of world_size x cap after the escape inbox (per-rank Lamport buffer 120 -> 152 MiB at TP2/TP4); the shared inbox, the cap and the other Lamport ops are unchanged. Signed-off-by: TennyWang1223 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…ort lines ar_2s_ll_gfx1250 sent LL lines, 8 bytes of payload and two epoch flags in 16 bytes, so a TP8 two-shot put 3.5 x the message on the fabric. Its replacement, ar_2s_lamport_gfx1250, sends the payload alone. The receiver's inbox holds a sentinel (all bits set) in every 32-bit word where nothing is pending. A payload word equal to it is sent as 0x7fffffff (a NaN in fp32 and NaNs in fp16 / bf16, as the sentinel is), and the reducing rank writes its own chunk with the same bits. Inbox rounds work as in the other Lamport kernels: three buffers, a rank-local round counter a wave of packs, the previous round's buffer re-armed, so CUDA graphs replay as is. It reuses their constants, line helpers and inbox arming. The reduce-scatter + all-gather, the in-place read and the rank-order fp32 sum rounded once (bit-identical on every rank) are unchanged. Routing: the size range is the same (ar2sMinBytes to ar2sMaxBytes), but use_2s now needs whole 16-byte packs a chunk, bytes % (16 x world_size) (8 before). So a TP8 bf16 all-reduce above 4 MiB whose numel is 32 mod 64 takes the pull kernel instead; no shipped TP8 shape is one. At TP4, fp16 / bf16 on the IPC transport go to the Lamport kernels on the AR + RMSNorm pool first (select_lamport_ar), as on main. Launch: at most one block a CU, since a CU running two finishes last (TP8, 7.81 MB: 273 blocks of 2 x 224 threads 45.5 us, 239 of 2 x 256 26.2 us). W threads a role, the smallest of 64, 128, 256 and 512 that covers a chunk in cu_count blocks; three wave groups (send, reduce, gather) up to W = 128, two above. The pollers first sleep through the time before anything can land. The inbox (48 MiB a rank at TP4 and TP8) starts on a 2 MiB boundary of the meta buffer. Started where the shard ends, 258 KiB past one, the TP8 call took 6.7 us longer at 7.81 MB. The meta buffer still shrinks by 15 MB a rank (TP8 218.4 -> 203.4 MB, TP4 151.3 -> 136.3 MB). CustomAllreduce barriers after init_custom_ar so that every rank's sentinel fill lands before any push. MI455X, TP8 across two trays (symm_mem), bf16 in a CUDA graph, us an all-reduce, #7432's two-shot -> this one (RCCL): 0.92 MB 13.9 -> 12.6 (20.3), 2.75 MB 20.7 -> 15.5 (40.1), 3.91 MB 25.2 -> 17.9 (39.4), 5.50 MB 29.6 -> 23.5 (39.5), 7.81 MB 38.3 -> 25.4 (42.5), 8.26 MB 39.0 -> 25.9 (42.8). Kimi-K3's c128 decode all-reduces are [545, 3584] (3.91 MB) and [545, 7168] (7.81 MB). Tests: - test_custom_allreduce.py: the two-shot mixed-size and in-place lists add sizes whose chunks end in a partial wave of packs. Their regressions cycle four exact input variants, so a stale line in any of the three buffers is caught. test_allreduce_2s_gfx1250_sentinel_payload feeds a payload word with the sentinel's bits. - gfx1250_poc/test_gfx1250_lamport_allreduce.py names the renamed kernel and its 16 x tp divisor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ort lines ar_2s_ll_gfx1250 sent LL lines, 8 bytes of payload and two epoch flags in 16 bytes, so a TP8 two-shot put 3.5 x the message on the fabric. Its replacement, ar_2s_lamport_gfx1250, sends the payload alone. The receiver's inbox holds a sentinel (all bits set) in every 32-bit word where nothing is pending. A payload word equal to it is sent as 0x7fffffff (a NaN in fp32 and NaNs in fp16 / bf16, as the sentinel is), and the reducing rank writes its own chunk with the same bits. Inbox rounds work as in the other Lamport kernels: three buffers, a rank-local round counter a wave of packs, the previous round's buffer re-armed, so CUDA graphs replay as is. It reuses their constants, line helpers and inbox arming. The reduce-scatter + all-gather, the in-place read and the rank-order fp32 sum rounded once (bit-identical on every rank) are unchanged. Routing: the size range is the same (ar2sMinBytes to ar2sMaxBytes), but use_2s now needs whole 16-byte packs a chunk, bytes % (16 x world_size) (8 before). So a TP8 bf16 all-reduce above 4 MiB whose numel is 32 mod 64 takes the pull kernel instead; no shipped TP8 shape is one. At TP4, fp16 / bf16 on the IPC transport go to the Lamport kernels on the AR + RMSNorm pool first (select_lamport_ar), as on main. Launch: at most one block a CU, since a CU running two finishes last (TP8, 7.81 MB: 273 blocks of 2 x 224 threads 45.5 us, 239 of 2 x 256 26.2 us). W threads a role, the smallest of 64, 128, 256 and 512 that covers a chunk in cu_count blocks; three wave groups (send, reduce, gather) up to W = 128, two above. The pollers first sleep through the time before anything can land. The inbox (48 MiB a rank at TP4 and TP8) starts on a 2 MiB boundary of the meta buffer. Started where the shard ends, 258 KiB past one, the TP8 call took 6.7 us longer at 7.81 MB. The meta buffer still shrinks by 15 MB a rank (TP8 218.4 -> 203.4 MB, TP4 151.3 -> 136.3 MB). CustomAllreduce barriers after init_custom_ar so that every rank's sentinel fill lands before any push. MI455X, TP8 across two trays (symm_mem), bf16 in a CUDA graph, us an all-reduce, #7432's two-shot -> this one (RCCL): 0.92 MB 13.9 -> 12.6 (20.3), 2.75 MB 20.7 -> 15.5 (40.1), 3.91 MB 25.2 -> 17.9 (39.4), 5.50 MB 29.6 -> 23.5 (39.5), 7.81 MB 38.3 -> 25.4 (42.5), 8.26 MB 39.0 -> 25.9 (42.8). Kimi-K3's c128 decode all-reduces are [545, 3584] (3.91 MB) and [545, 7168] (7.81 MB). Tests: - test_custom_allreduce.py: the two-shot mixed-size and in-place lists add sizes whose chunks end in a partial wave of packs. Their regressions cycle four exact input variants, so a stale line in any of the three buffers is caught. test_allreduce_2s_gfx1250_sentinel_payload feeds a payload word with the sentinel's bits. - gfx1250_poc/test_gfx1250_lamport_allreduce.py names the renamed kernel and its 16 x tp divisor. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ansport
Review 5992632906, items 1-6: one Lamport two-shot, main's
lamport_ar_2shot_gfx1250, with the fp32 codec and the split layout of the
kernels it replaces.
- lamport_ar_2shot_gfx1250<T, ngpus, BLOCK, ROLES>:
- LamportArCodec<T>: 2-byte dtypes keep the 16-bit sentinel; fp32 gets a
32-bit one.
- ROLES 1 is fused (main's); 2-3 is split: send, reduce and gather wave
groups, with the pre-poll sleep.
- Chunks of ceil(packs / ngpus) packs with p < packs guards, so any input
of whole 16-byte packs runs.
- run_2shot launch:
- split: W = min(512, roundup32(ceil(part / CUs))), three roles while
W <= 320, at most one block a CU;
- fused: add_threads(part).
- Removed ar_2s_lamport_gfx1250 and its 48 MiB inbox, and #7432's
ar_2s_ll_gfx1250 with its tables and dispatch. The meta buffer a rank goes
from 144.3 to 80.3 MiB at TP4 and from 208.3 to 144.3 MiB at TP8.
- The Lamport inbox is built on every transport (IPC, symm_mem, VMM). Plain
all-reduce gets its own cap, _LAMPORT_AR_MAX_BYTES:
- {2: 16, 4: 8, 8: 1} MiB a sender, so the two-shot takes up to 32 MiB at
TP2 and TP4 and 8 MiB at TP8;
- the TP8 inbox is 38 MiB a rank.
- select_lamport_ar returns (two_shot, split):
- fp16/bf16: the one-shot up to _LAMPORT_AR_1SHOT_MAX_BYTES (TP8 1 MiB
added);
- fp32: the LL one-shot up to _LAMPORT_AR_FP32_LL_MAX_BYTES (TP2 1 MiB, else
none);
- split in _LAMPORT_AR_SPLIT_BYTES (TP2 (2, 4], TP4 (4, 8], TP8
(0.25, 4] MiB), fused elsewhere.
- The TP8 plain cutoff drops from 8 to 4 MiB: past 4 MiB the meta-buffer
path is the pull.
- Dropped the post-init barrier that only the meta-buffer two-shot needed.
- Tests:
- two ragged fp32 sizes in _AR2S_GFX1250_MIXED_SIZES;
- the sentinel test at TP2 too;
- test_gfx1250_lamport_ar_route in size_env;
- the PoC's split and fp32 candidates and routes.
- The "LL kernels" text and the two-bank comment are fixed.
MI455X, production route against main, CUDA graph, slowest rank:
- TP4 over symm_mem, bf16: 1.37-2.06x from 256 KiB to 16 MiB.
- TP4 over IPC: bf16 1.35-1.51x at 5-8 MiB (split); fp32 1.18-2.0x from
512 KiB to 4 MiB and 1.46-2.87x above, where main took RCCL.
- TP2: fp32 1.16-1.52x from 1.5 to 8 MiB; bf16 unchanged (the one-shot).
- TP8 (two trays, symm_mem): the routes come from timing the two kernels
merged here.
--regression passes at TP2 (IPC) and TP4 (IPC, symm_mem, VMM). At TP8
(symm_mem, two trays) it passed on these kernels, before the TP8 tables
above changed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wo-shot, on every transport (#7937) * [HIP] perf(custom_ar): gfx1250 two-shot all-reduce moves 16-byte Lamport lines ar_2s_ll_gfx1250 sent LL lines, 8 bytes of payload and two epoch flags in 16 bytes, so a TP8 two-shot put 3.5 x the message on the fabric. Its replacement, ar_2s_lamport_gfx1250, sends the payload alone. The receiver's inbox holds a sentinel (all bits set) in every 32-bit word where nothing is pending. A payload word equal to it is sent as 0x7fffffff (a NaN in fp32 and NaNs in fp16 / bf16, as the sentinel is), and the reducing rank writes its own chunk with the same bits. Inbox rounds work as in the other Lamport kernels: three buffers, a rank-local round counter a wave of packs, the previous round's buffer re-armed, so CUDA graphs replay as is. It reuses their constants, line helpers and inbox arming. The reduce-scatter + all-gather, the in-place read and the rank-order fp32 sum rounded once (bit-identical on every rank) are unchanged. Routing: the size range is the same (ar2sMinBytes to ar2sMaxBytes), but use_2s now needs whole 16-byte packs a chunk, bytes % (16 x world_size) (8 before). So a TP8 bf16 all-reduce above 4 MiB whose numel is 32 mod 64 takes the pull kernel instead; no shipped TP8 shape is one. At TP4, fp16 / bf16 on the IPC transport go to the Lamport kernels on the AR + RMSNorm pool first (select_lamport_ar), as on main. Launch: at most one block a CU, since a CU running two finishes last (TP8, 7.81 MB: 273 blocks of 2 x 224 threads 45.5 us, 239 of 2 x 256 26.2 us). W threads a role, the smallest of 64, 128, 256 and 512 that covers a chunk in cu_count blocks; three wave groups (send, reduce, gather) up to W = 128, two above. The pollers first sleep through the time before anything can land. The inbox (48 MiB a rank at TP4 and TP8) starts on a 2 MiB boundary of the meta buffer. Started where the shard ends, 258 KiB past one, the TP8 call took 6.7 us longer at 7.81 MB. The meta buffer still shrinks by 15 MB a rank (TP8 218.4 -> 203.4 MB, TP4 151.3 -> 136.3 MB). CustomAllreduce barriers after init_custom_ar so that every rank's sentinel fill lands before any push. MI455X, TP8 across two trays (symm_mem), bf16 in a CUDA graph, us an all-reduce, #7432's two-shot -> this one (RCCL): 0.92 MB 13.9 -> 12.6 (20.3), 2.75 MB 20.7 -> 15.5 (40.1), 3.91 MB 25.2 -> 17.9 (39.4), 5.50 MB 29.6 -> 23.5 (39.5), 7.81 MB 38.3 -> 25.4 (42.5), 8.26 MB 39.0 -> 25.9 (42.8). Kimi-K3's c128 decode all-reduces are [545, 3584] (3.91 MB) and [545, 7168] (7.81 MB). Tests: - test_custom_allreduce.py: the two-shot mixed-size and in-place lists add sizes whose chunks end in a partial wave of packs. Their regressions cycle four exact input variants, so a stale line in any of the three buffers is caught. test_allreduce_2s_gfx1250_sentinel_payload feeds a payload word with the sentinel's bits. - gfx1250_poc/test_gfx1250_lamport_allreduce.py names the renamed kernel and its 16 x tp divisor. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] custom_ar: gfx1250 two-shot comments and test text follow main valarLip's review 5988279188 of e2127e7, items 5 and 6: - The two-shot's comments point to lamport_ar_1shot_gfx1250 (there is no lamport_ar_add_gfx1250 on main). The line helpers serve every Lamport kernel. - The allreduce() comment covers the two-shot as well as the LL one-shot. - ll_ar_max_bytes and the plain cutoff no longer count the two-shot among "the LL kernels". - The meta size is 48 to 194 MiB. - The inbox offset cost 7.1 us (33.2 vs 26.1 us, the prototype that changed only the offset). - Tests: - the vary_inputs comment says what a pack that three sizes reach reads; - the --regression help lists the two-shot mixed sizes and the sentinel payload; - ll2s / LL2S names become 2s / AR2S. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] custom_ar: gfx1250 TP8 plain all-reduce stays off the Lamport kernels At TP8 plain all-reduce never takes the Lamport all-reduce (lamport_ar_1shot/2shot_gfx1250), even when AITER_CUSTOM_AR_LAMPORT_RMS_MAX_SIZE sets a Lamport cap there. It keeps the meta-buffer kernels, ar_2s_lamport_gfx1250 in its range, which is measured across two trays; the Lamport all-reduce is measured at TP2 and TP4 only. select_lamport_ar returns None at the world sizes in _LAMPORT_AR_SKIP_WORLD_SIZES. TP2 and TP4 route as before. test_custom_allreduce_size_env.py checks the TP8 gate (it fails without it); the gfx1250 PoC test restates it in expect_route. Signed-off-by: TennyWang1223 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * Revert "[HIP] custom_ar: gfx1250 TP8 plain all-reduce stays off the Lamport kernels" This reverts commit 741e9530404c5ac58d02a1ae4a4b0e66d1e3ca72. valarLip's review 5992632906, item 3. The gate decides nothing by default: TP8 has no Lamport cap, and only the IPC transport builds the Lamport pool. With a cap set, it changes only single-node TP8 over IPC, while the evidence it cites was measured across two trays on symm_mem, where it is a no-op. On those trays the Lamport one-shot and two-shot are the fastest TP8 paths at 8-512 KiB and 5-8 MiB, and the AR + add, AR + RMSNorm and all-gather Lamport ops were never gated. It also adds a check to every plain all-reduce. TP8 plain all-reduce is routed by size in the next commit instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] custom_ar: gfx1250 all-reduce on one Lamport two-shot, every transport Review 5992632906, items 1-6: one Lamport two-shot, main's lamport_ar_2shot_gfx1250, with the fp32 codec and the split layout of the kernels it replaces. - lamport_ar_2shot_gfx1250<T, ngpus, BLOCK, ROLES>: - LamportArCodec<T>: 2-byte dtypes keep the 16-bit sentinel; fp32 gets a 32-bit one. - ROLES 1 is fused (main's); 2-3 is split: send, reduce and gather wave groups, with the pre-poll sleep. - Chunks of ceil(packs / ngpus) packs with p < packs guards, so any input of whole 16-byte packs runs. - run_2shot launch: - split: W = min(512, roundup32(ceil(part / CUs))), three roles while W <= 320, at most one block a CU; - fused: add_threads(part). - Removed ar_2s_lamport_gfx1250 and its 48 MiB inbox, and #7432's ar_2s_ll_gfx1250 with its tables and dispatch. The meta buffer a rank goes from 144.3 to 80.3 MiB at TP4 and from 208.3 to 144.3 MiB at TP8. - The Lamport inbox is built on every transport (IPC, symm_mem, VMM). Plain all-reduce gets its own cap, _LAMPORT_AR_MAX_BYTES: - {2: 16, 4: 8, 8: 1} MiB a sender, so the two-shot takes up to 32 MiB at TP2 and TP4 and 8 MiB at TP8; - the TP8 inbox is 38 MiB a rank. - select_lamport_ar returns (two_shot, split): - fp16/bf16: the one-shot up to _LAMPORT_AR_1SHOT_MAX_BYTES (TP8 1 MiB added); - fp32: the LL one-shot up to _LAMPORT_AR_FP32_LL_MAX_BYTES (TP2 1 MiB, else none); - split in _LAMPORT_AR_SPLIT_BYTES (TP2 (2, 4], TP4 (4, 8], TP8 (0.25, 4] MiB), fused elsewhere. - The TP8 plain cutoff drops from 8 to 4 MiB: past 4 MiB the meta-buffer path is the pull. - Dropped the post-init barrier that only the meta-buffer two-shot needed. - Tests: - two ragged fp32 sizes in _AR2S_GFX1250_MIXED_SIZES; - the sentinel test at TP2 too; - test_gfx1250_lamport_ar_route in size_env; - the PoC's split and fp32 candidates and routes. - The "LL kernels" text and the two-bank comment are fixed. MI455X, production route against main, CUDA graph, slowest rank: - TP4 over symm_mem, bf16: 1.37-2.06x from 256 KiB to 16 MiB. - TP4 over IPC: bf16 1.35-1.51x at 5-8 MiB (split); fp32 1.18-2.0x from 512 KiB to 4 MiB and 1.46-2.87x above, where main took RCCL. - TP2: fp32 1.16-1.52x from 1.5 to 8 MiB; bf16 unchanged (the one-shot). - TP8 (two trays, symm_mem): the routes come from timing the two kernels merged here. --regression passes at TP2 (IPC) and TP4 (IPC, symm_mem, VMM). At TP8 (symm_mem, two trays) it passed on these kernels, before the TP8 tables above changed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * [HIP] custom_ar: gfx1250 TP8 routes from this head's own timings TP8 across two MI455X trays over symm_mem, this head's kernels, CUDA graph, bf16 unless noted: - The one-shot stops at 768 KiB. The split two-shot overtakes it past there: 9.9 vs 10.3 us at 768 KiB, 11.1 vs 10.5 at 1 MiB. - fp32 takes the split from the smallest size up to 4 MiB. Against the fused layout: 9.0 vs 9.6 us at 16 KiB, 10.1 vs 10.7 at 256 KiB, 10.8 vs 15.5 at 1 MiB. - The cap goes back to 4 MiB a sender, so the two-shot runs to 32 MiB. Past 8 MiB the fused layout stays ahead of RCCL: 33.5 vs 43.2 us at 10 MiB, 66.0 vs 96.6 at 32 MiB. Its send loop issues every load before its first remote store; main's two-shot, which set the 8 MiB cap, did not. - The code comments quote these numbers in place of the ones taken on the kernels before the merge. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Signed-off-by: TennyWang1223 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: TennyWang1223 <[email protected]>


End-to-end result below. No blocking issues known.
On gfx1250, a custom all-reduce of 1–16 MiB takes either the one-shot LL kernel or, above 4 MiB, a one-shot pull. The one-shot LL sends 14× the message per rank at TP8. The pull reads every peer's full input over the fabric.
At TP8 across two MI455X trays this hits Kimi-K3 TP8 decode directly. A c32 step all-reduces [160, 7168] bf16 (2.29 MB) in 47.9 µs, against 39.2 µs on tuned RCCL. A c64 step all-reduces [320, 7168] (4.59 MB) in 157.8 µs, against 42.2 µs.
This PR adds an LL two-shot all-reduce (reduce-scatter + all-gather) for 1 MiB up to ranks × 2 MiB at 4+ ranks. The same message now takes 25.6 µs and 34.5 µs.
Dev record
ar_2s_ll_gfx1250usesar_ll_gfx1250's LL lines, scratch banks and per-block epochs (d_ll_block_flags_). The two kernels interleave safely and no buffer is added: the reduce-scatter and all-gather slots fit one bank, which caps the two-shot at ranks × 2 MiB.all_reduceskips the staging copy for it as for the one-shot.allreduce()only: no Python change and no new environment variable.AITER_CUSTOM_AR_MAX_SIZEandAITER_CUSTOM_AR_DISABLE_LLkeep their meaning.use_2s_ll,allreduce_2s_llandll_threads_for.s_wait_xcnt) before it overwrites the data VGPRs of a store in flight.(rank + k) % ngpus, so register arrays are indexed at compile time.asm volatile("" ::: "memory")barrier thatll_load_b128carries is deleted by the compiler, and a test with a fixed input still passes. The new regression test negates its inputs every other round.Named result
Kimi-K3 TP8+DCP8, MLPerf Endpoints agentic, concurrency 16, two MI455X trays: decode TPOT −4.5%, tok/s/user +4.8%, tok/s/GPU +3.2%. Accuracy is unchanged.
How it was measured:
rocm/fw-bringup:gfx1250-atom-k3-20261103,/opt/k3/k3-mlperf-repro): agentx, MoE TP8, DSpark 4 drafts, max-num-seqs 32, FP8 KV with block 128, HERD.AITER_CUSTOM_AR_MAX_SIZE=8388608, default RCCL. It is a separate baseline run of the same kit on another MI455X tray pair.AITER_CUSTOM_AR_MAX_SIZE=8388608,RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152andRCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728. The two RCCL settings only change RCCL's > 8 MiB (prefill) all-reduces; every decode all-reduce here is ≤ 8 MiB and takes this PR's kernels.The TPOT drop (−0.6 ms) matches what the per-op numbers below predict for a full c16 decode step, which is 80 tokens: −0.7 ms. That step does one [80, 7168] and one [80, 3584] all-reduce in each of 92 layers.
K3 decode all-reduces per step (attention output [T, 7168] + MoE latent [T, 3584], 92 layers, T = 5 × concurrency, TP8 per-op times below):
Gates
op_tests/multigpu_tests/test_custom_allreduce.py --regression -t 4passes with--transport symmand--transport auto. It covers the tail shapes, LL128, the gfx1250 LL mixed sizes, and the new gfx1250 LL two-shot mixed sizes: 200 rounds of 1.15 / 0.36 / 4.59 MB, with the inputs negated every other round.Evidence
TP8, two MI455X trays (4 + 4 GPUs) over UALink, bf16, 50 all-reduces captured in one CUDA graph. µs an op, median of 5 replays, slowest rank. RCCL 2.30.7 with
RCCL_DDA_LL_ONESHOT_THRESHOLD=2097152andRCCL_DDA_LL_TWOSHOT_THRESHOLD=134217728; its default settings are slower or equal.¹ This size was timed on a second tray pair, which is faster than the first: two-shot 59.1 µs vs RCCL 51.0 there, and 20.2 / 32.5 µs at 2.29 / 4.59 MB.
TP4 and TP2, one MI455X tray, same method, custom path only (main → this PR, µs):
At TP2 the two-shot is not used: ≤ 4 MiB stays on the one-shot (512-thread blocks above 512 KiB), and above 4 MiB stays on the pull, as on main.
Fabric, MI455X (one thread bouncing a flag; puts of 16 MB per peer):