Repository navigation
[FlyDSL] [Kernel] Add a DCP mailbox query gather and LSE combine - #6972
Conversation
94f6f30 to
9a12bfc
Compare
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
8bbad54 to
c072a78
Compare
c072a78 to
b6d1656
Compare
b6d1656 to
424fff7
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
424fff7 to
79527a2
Compare
79527a2 to
0d02e61
Compare
0d02e61 to
cdbfc6e
Compare
fixed, split-phase gather now advances the epoch only after phase 2. Epochs wrap at 2^30, and missing-rank checks use modular arithmetic. After one debug poll expires, later tokens skip their waits. Default tests cover tokens 8 and 99. Manual JIT keys are removed, and all tests pass with FlyDSL 0.5.0. Device checks, shared tile selection, and exact vLLM baseline details are also added. |
|
@xiaohuguo2023 @coderfeli Round 5 (head What remains is coderfeli's open change request, i.e. the rules in
Could you two agree whether these land in this PR or a follow-up? Then the CHANGES_REQUESTED can be resolved. |
508802c to
b63594d
Compare
@yitingw1 Thanks for the Round 5 validation. I agree that @coderfeli 's requested changes should land in this PR.
On 8 × MI355X with FlyDSL 0.5.0, the default token cases 8 and 99 pass. TOKENS=240 also passes. |
|
@xiaohuguo2023 Thanks. The pushed head
Could you push them? One more thing from the rebase: main moved |
The gather replaces the DCP query all-gather, including the fp8 quant of ql_nope and q_pe. The combine replaces the LSE all-to-all reduce. Both kernels use one tagged peer buffer and one CTA per token and local head. Signed-off-by: Xiaohu Guo <[email protected]>
The combine ran a fixed 128 threads per CTA and asserted dim == 256, so it rejected the 512-dim MLA latent and every other head size. A CTA still owns one (token, local head); it now runs dim / 4 threads, each owning four values, so one build covers dim 64, 128, 512, 576 and any multiple of 4 with 4 * ranks <= dim <= 4096 (thread r pushes the LSE to rank r). The test covers dims 64, 128, 512 and 576 with base-e and base-2 LSE, with and without seq_lens masking, and checks return_lse=False against the returned output. The gather case now uses an explicit dim. The benchmark loops over dims and aligns the ranks before each timed graph replay. Without the barrier every workspace after the first measured rank skew, since each rank polls its peers. MI355X, 8 ranks, 16 tokens, 12 heads per rank, CUDA graph: combine dim 128 10.3 us combine dim 512 19.2 us combine dim 576 19.9 us gather dim 512 14.4 us Signed-off-by: Xiaohu Guo <[email protected]>
Move the tagged peer mailbox into communication_ops_utils and use its existing agent-scope atomic helper. Consolidate the small DCP build and device helpers in common.py, and remove the copied monokernel execution, tracing, rank, and diagnostic code. The 8-rank correctness test passed twice on MI355X. Same-node two-run benchmark averages stayed within noise: combine dim 128 10.18 to 10.61 us, dim 512 19.72 to 19.81 us, dim 576 20.88 to 20.89 us, and gather dim 512 15.23 to 15.46 us. Signed-off-by: Xiaohu Guo <[email protected]>
Signed-off-by: Xiaohu Guo <[email protected]>
Signed-off-by: Xiaohu Guo <[email protected]>
Signed-off-by: Xiaohu Guo <[email protected]>
A debug workspace (debug=True) adds one untagged epoch slot per source rank after both parities. CTA 0 pushes the launch epoch to every peer, and every poll is bounded at 10 s. On timeout it records which source ranks are behind, and the host raises. A normal build compiles the epoch push and the bounded poll out completely. Workspace close now unmaps the peers and runs a group barrier before it frees the local buffer. A buffer freed while a peer still mapped it made the next allocation fail hipIpcGetMemHandle. Document the 8-byte tagged-pair alignment that makes the hand-off fence-free. The test runs the dim 128 combine in a debug build. The benchmark adds the FP8 quantize + gather path and reports the spread of two graph replays. MI355X, 8 ranks, 16 tokens, 12 heads, same node as the control: combine dim 128 10.57 us (control 10.57) combine dim 512 19.89 us (control 19.98) combine dim 576 20.71 us (control 20.70) gather dim 512 14.72 us (control 14.77) Signed-off-by: Xiaohu Guo <[email protected]>
Process multiple tokens per CTA at larger DCP batches to reduce epoch-counter contention. Keep one token per CTA for small batches and select 2, 4, or 8-token tiles as parallelism increases. At 240 tokens on 8x MI355X, dim-512 combine improves from 216.43 to 135.06 us and quant-gather improves from 80.04 to 69.63 us. The 240-token correctness test passes, while 16-token timings remain within 2%. Signed-off-by: Xiaohu Guo <[email protected]>
Publish epoch plus one so zero always means that a rank never entered the launch. Set an unconditional timeout bit with atomic OR so every bounded timeout raises, including an empty missing-rank mask. Reject debug graph capture explicitly, document the identical-call-sequence contract, validate the BF16 gather limit, and add an optional per-row empty mask to the LSE combine. The 8-rank test covers epoch-zero missing peers, an empty timeout mask, debug graph rejection, the BF16 gather boundary, and per-row masking. Signed-off-by: Xiaohu Guo <[email protected]>
Add independent vLLM A2A, BF16 all-gather, and FP8 quantize-plus-gather arms to the mailbox benchmark. Run mailbox and vLLM arms in separate processes so graph-captured collectives do not share protocol state. Report the median and full range of ten aligned graph replays. Accept a token-count list so the published 8-token and 16-token rows are directly reproducible. Signed-off-by: Xiaohu Guo <[email protected]>
Keep split-phase gather on one epoch and wrap the int32 epoch at 2^30. After one debug poll expires, its CTA sets a timeout flag. Later tokens in the tile skip their own waits. Share and document token-tile selection. Validate mask and gather devices. Identify the exact vLLM baseline revision in the benchmark. The 8-rank test runs token counts 8 and 99 by default. It covers two split-phase rounds and six calls across the epoch modulus. Signed-off-by: Xiaohu Guo <[email protected]>
Keep split-phase gather on one epoch and wrap the int32 epoch at 2^30. Later tokens skip their waits after one debug poll expires. Remove manual JIT keys for FlyDSL 0.5.0. Share token-tile selection and validate mask and gather devices. The 8-rank test covers token counts 8 and 99, two split-phase rounds, and six calls across both epoch boundaries. Signed-off-by: Xiaohu Guo <[email protected]>
Place device bodies under kernels/dcp_mailbox and keep launch wrappers in dcp_mailbox. Replace new buffer_ops calls with typed buffer tensor copies and document raw API boundaries. Import UncachedIpcHeap from the canonical ipc_heap module. Signed-off-by: Xiaohu Guo <[email protected]>
b63594d to
f602738
Compare
@yitingw1 sorry, done! |
* [FlyDSL] Add the DCP mailbox query gather and LSE combine. The gather replaces the DCP query all-gather, including the fp8 quant of ql_nope and q_pe. The combine replaces the LSE all-to-all reduce. Both kernels use one tagged peer buffer and one CTA per token and local head. Signed-off-by: Xiaohu Guo <[email protected]> * [FlyDSL] Support any head dim in the DCP mailbox LSE combine The combine ran a fixed 128 threads per CTA and asserted dim == 256, so it rejected the 512-dim MLA latent and every other head size. A CTA still owns one (token, local head); it now runs dim / 4 threads, each owning four values, so one build covers dim 64, 128, 512, 576 and any multiple of 4 with 4 * ranks <= dim <= 4096 (thread r pushes the LSE to rank r). The test covers dims 64, 128, 512 and 576 with base-e and base-2 LSE, with and without seq_lens masking, and checks return_lse=False against the returned output. The gather case now uses an explicit dim. The benchmark loops over dims and aligns the ranks before each timed graph replay. Without the barrier every workspace after the first measured rank skew, since each rank polls its peers. MI355X, 8 ranks, 16 tokens, 12 heads per rank, CUDA graph: combine dim 128 10.3 us combine dim 512 19.2 us combine dim 576 19.9 us gather dim 512 14.4 us Signed-off-by: Xiaohu Guo <[email protected]> * [FlyDSL] Reuse shared communication helpers for DCP mailbox Move the tagged peer mailbox into communication_ops_utils and use its existing agent-scope atomic helper. Consolidate the small DCP build and device helpers in common.py, and remove the copied monokernel execution, tracing, rank, and diagnostic code. The 8-rank correctness test passed twice on MI355X. Same-node two-run benchmark averages stayed within noise: combine dim 128 10.18 to 10.61 us, dim 512 19.72 to 19.81 us, dim 576 20.88 to 20.89 us, and gather dim 512 15.23 to 15.46 us. Signed-off-by: Xiaohu Guo <[email protected]> * [FlyDSL] Fix DCP mailbox review findings Signed-off-by: Xiaohu Guo <[email protected]> * [FlyDSL] Reuse shared helpers in DCP mailbox Signed-off-by: Xiaohu Guo <[email protected]> * [FlyDSL] Correct DCP mailbox license provenance Signed-off-by: Xiaohu Guo <[email protected]> * [FlyDSL] Add DCP mailbox debug diagnostics and the FP8 benchmark arm A debug workspace (debug=True) adds one untagged epoch slot per source rank after both parities. CTA 0 pushes the launch epoch to every peer, and every poll is bounded at 10 s. On timeout it records which source ranks are behind, and the host raises. A normal build compiles the epoch push and the bounded poll out completely. Workspace close now unmaps the peers and runs a group barrier before it frees the local buffer. A buffer freed while a peer still mapped it made the next allocation fail hipIpcGetMemHandle. Document the 8-byte tagged-pair alignment that makes the hand-off fence-free. The test runs the dim 128 combine in a debug build. The benchmark adds the FP8 quantize + gather path and reports the spread of two graph replays. MI355X, 8 ranks, 16 tokens, 12 heads, same node as the control: combine dim 128 10.57 us (control 10.57) combine dim 512 19.89 us (control 19.98) combine dim 576 20.71 us (control 20.70) gather dim 512 14.72 us (control 14.77) Signed-off-by: Xiaohu Guo <[email protected]> * [Perf][FlyDSL] Tile DCP mailbox tokens across CTAs Process multiple tokens per CTA at larger DCP batches to reduce epoch-counter contention. Keep one token per CTA for small batches and select 2, 4, or 8-token tiles as parallelism increases. At 240 tokens on 8x MI355X, dim-512 combine improves from 216.43 to 135.06 us and quant-gather improves from 80.04 to 69.63 us. The 240-token correctness test passes, while 16-token timings remain within 2%. Signed-off-by: Xiaohu Guo <[email protected]> * [Bugfix][FlyDSL] Make DCP mailbox diagnostics fail closed Publish epoch plus one so zero always means that a rank never entered the launch. Set an unconditional timeout bit with atomic OR so every bounded timeout raises, including an empty missing-rank mask. Reject debug graph capture explicitly, document the identical-call-sequence contract, validate the BF16 gather limit, and add an optional per-row empty mask to the LSE combine. The 8-rank test covers epoch-zero missing peers, an empty timeout mask, debug graph rejection, the BF16 gather boundary, and per-row masking. Signed-off-by: Xiaohu Guo <[email protected]> * [Bench][FlyDSL] Add reproducible DCP collective baselines Add independent vLLM A2A, BF16 all-gather, and FP8 quantize-plus-gather arms to the mailbox benchmark. Run mailbox and vLLM arms in separate processes so graph-captured collectives do not share protocol state. Report the median and full range of ten aligned graph replays. Accept a token-count list so the published 8-token and 16-token rows are directly reproducible. Signed-off-by: Xiaohu Guo <[email protected]> * [Bugfix][FlyDSL] Preserve DCP mailbox phase and epoch state Keep split-phase gather on one epoch and wrap the int32 epoch at 2^30. After one debug poll expires, its CTA sets a timeout flag. Later tokens in the tile skip their own waits. Share and document token-tile selection. Validate mask and gather devices. Identify the exact vLLM baseline revision in the benchmark. The 8-rank test runs token counts 8 and 99 by default. It covers two split-phase rounds and six calls across the epoch modulus. Signed-off-by: Xiaohu Guo <[email protected]> * [Bugfix][FlyDSL] Fix DCP mailbox phase and epoch boundaries Keep split-phase gather on one epoch and wrap the int32 epoch at 2^30. Later tokens skip their waits after one debug poll expires. Remove manual JIT keys for FlyDSL 0.5.0. Share token-tile selection and validate mask and gather devices. The 8-rank test covers token counts 8 and 99, two split-phase rounds, and six calls across both epoch boundaries. Signed-off-by: Xiaohu Guo <[email protected]> * [Refactor][FlyDSL] Move DCP mailbox kernels Place device bodies under kernels/dcp_mailbox and keep launch wrappers in dcp_mailbox. Replace new buffer_ops calls with typed buffer tensor copies and document raw API boundaries. Import UncachedIpcHeap from the canonical ipc_heap module. Signed-off-by: Xiaohu Guo <[email protected]> --------- Signed-off-by: Xiaohu Guo <[email protected]>
Summary
Add two model-agnostic FlyDSL kernels for decode-context-parallel (DCP) attention.
dcp_query_gatheranddcp_quant_query_gatherreplace the DCP query all-gather, including the fp8 quant ofql_nopeandq_pe.dcp_lse_combinereplaces the log-sum-exp (LSE) all-to-all reduce. Each kernel uses one tagged peer buffer. Larger batches process several tokens per CTA to reduce epoch-counter contention.Motivation
A DCP rank must gather the query from its peers and combine partial attention outputs with their LSE values. NCCL all-gather and all-to-all do that as several launches and do not keep a tagged peer mailbox. These kernels do both steps in one launch per operator. The API takes ranks, heads, and head dim from the caller, so any model can use it.
Changes
aiter/ops/flydsl/dcp_mailbox/and exportdcp_lse_combine,dcp_query_gather,dcp_quant_query_gather,CombineWorkspace, andGatherWorkspacefromaiter.ops.flydsl.dim / 4threads. Each thread owns four values.dimis a multiple of 4, and4 * ranks <= dim <= 4096. Threadrpushes the LSE to rankr. One build covers head dims 64, 128, 512, and 576.float8_e4m3fn) quant gather.2^30, and tiled debug timeouts skip later polls after the first timeout.aiter/ops/flydsl/kernels/dcp_mailbox/. Public wrappers, compile caches, workspaces, and peer allocation stay underaiter/ops/flydsl/dcp_mailbox/.fx.copy, not the legacybuffer_opsmodule. Retained raw timer, sleep, and wave-broadcast operations have comments that name the missing stable API and ISA behavior.dcp_lse_combineaccepts optional contiguous int32row_counts[tokens]; rows with zero locally owned keys contribute-infLSE.Performance
MI355X, 8 DCP ranks, 12 local heads per rank, CUDA Graph replay. Results are medians of ten aligned replays. Lower is better.
The combine shape is BF16 with head dim 512. The quantized gather reads BF16
ql_nopedim 512 plusq_pedim 64 and produces FP8 dim 576.The existing DCP baseline uses separate query quantization and all-gather operations. Its output reduction uses
_dcp_a2a_pack_send,all_to_all_single, and_dcp_a2a_unpack_combine. The mailbox implementation fuses each sequence into one kernel. Each value is the median of ten aligned CUDA Graph replays; the benchmark prints the full[min, max]range.The optional
VLLM_BASELINE=1arm requires vLLM commita2bcb5657a881a002e79d0adab3c6b5e39436121, tested with imagevllm/vllm-openai-rocm:nightly-rocm100-a2bcb5657a881a002e79d0adab3c6b5e39436121.High-concurrency mailbox scaling
At 240 tokens, one-token CTAs contend on the per-workspace epoch counter. Token tiling reduces the CTA count while keeping one launch. Same-node CUDA Graph timings on n244:
Tile 4 is fastest at 128 tokens. Tile 8 is fastest at 240 tokens. Tile 16 loses occupancy. At 16 tokens, all operators keep one token per CTA and remain within 2% of the previous revision.
The vLLM C48 integration uses
max_tokens=480and shares one workspace per geometry across all MLA layers. At DCP8 with 12 local heads, the dim-512 combine peer allocation is about 181 MiB/GPU. The fp8 dim-576 gather peer allocation is about 101 MiB/GPU, and its persistent gathered-query output is about 34 MiB/GPU. The measured KV-capacity delta is-1.07%.Kimi-K3 MI355X AgentX C48 e2e evaluation
Measured in vLLM using a local integration branch. The PR does not change AITER call sites, so the integration is not part of this PR. Same-node A/B on MI355X n244 with image
a2bcb565, TP8/DCP8, DSpark K4 (AL 3.36), SimpleCPU offload, and a 3,600-second replay. Both arms used the same frozen image; the control disabled mailbox dispatch.Intvty@P90 = 1000 / full_response_inter_token_latency.p90_ms.Throughput/GPU uses total input-plus-output token throughput divided by TP8.
Dashboard comparison
The live dashboard has no matching B300 vLLM C48 result. The e2e primary-metric gains are positive but remain inside the run-to-run noise floor; the kernel-level gains above are the performance claim.
Testing
op_tests/multigpu_tests/test_dcp_mailbox.pyop_tests/op_benchmarks/flydsl/bench_dcp_mailbox.py0.5.0, as pinned by current AITER main.WORLD=8 python3 op_tests/multigpu_tests/test_dcp_mailbox.pyprintedDCP_MAILBOX OKfor default token counts 8 and 99.TOKENS=240 WORLD=8 python3 op_tests/multigpu_tests/test_dcp_mailbox.pyprintedDCP_MAILBOX OK.TOKENS=8,16 WORLD=8 python3 op_tests/op_benchmarks/flydsl/bench_dcp_mailbox.py.VLLM_BASELINE=1 TOKENS=8,16 WORLD=8 python3 op_tests/op_benchmarks/flydsl/bench_dcp_mailbox.py.TOKENS={128,240}with tile overrides 1/2/4/8/16.The combine test loops dims 64, 128, 512, and 576, base-e and base-2 LSE, with request and per-row masking, and checks
return_lse=Falseagainst the returned output. It also checks epoch-zero missing peers, timeout with a zero rank mask, one timeout flag per tile, explicit debug graph rejection, BF16 dim-576 rejection, split-phase gather, six calls across the2^30epoch modulus, and workspace teardown. Token count 99 covers a partial tile tail. The gather test uses dim 512. The quant-gather test uses nope 512 and pe 64.Kernel checklist
aiter_dcp_lse_combine_t{tokens}_n{ranks}_h{heads}_d{dim}_m{max_tokens}_s{seqs}_e{base_e}_l{ret_lse}_g{debug}_r{row_mask}_bt{token_tile}. Gather:aiter_dcp_qgather_t{tokens}_n{ranks}_h{heads}_w{words}_p{pad_heads}_m{max_tokens}_q{nope}_f{fold}x{qlen}_s{phase}_g{debug}_bt{token_tile}.op_tests/multigpu_tests/test_dcp_mailbox.py.op_tests/op_benchmarks/flydsl/bench_dcp_mailbox.py.aiter/ops/flydsl/kernels/dcp_mailbox/. Wrappers, compile caches, workspaces, and peer allocation live underaiter/ops/flydsl/dcp_mailbox/.tensor_shimbuffer tensors andfx.copy. Raws_sleep,s_memrealtime, andreadfirstlaneremain only where FlyDSL has no stable typed API.Reviewed revision
f602738
Behavior and intent
This revision moves both launchable kernel bodies and shared device helpers under
aiter/ops/flydsl/kernels/dcp_mailbox/. It replaces new legacybuffer_opsuse with FlyDSL buffer tensors andfx.copy. Raw sleep, timer, and wave-broadcast operations remain only where FlyDSL has no stable typed API, with a short comment at each boundary. The wrapper ABI, kernel names, split phases, graph behavior, epoch wrap, token tiling, and public APIs are unchanged.Validation and unverified scope
For this revision, Black 26.3.0, CI-pinned Ruff 0.16.0,
python3 -m py_compile,git diff --check, and IDE lints pass. On 8x MI355X n180 with FlyDSL 0.5.0, the default 8- and 99-token cases andTOKENS=240printedDCP_MAILBOX OK. This includes split-phase gather, epoch wrap, debug timeout, partial-tile, and CUDA Graph coverage.The reverse-order C48 operator replicate stayed within the measured ranges. Baseline to refactor: combine dim 128
18.95 -> 18.68 us(-1.4%), dim 51243.75 -> 42.77 us(-2.2%), dim 57645.94 -> 46.38 us(+1.0%), BF16 gather33.97 -> 33.35 us(-1.8%), and FP8 quant-gather22.02 -> 22.07 us(+0.2%). MI250X and MI300X remain unverified.PR-specific question
Before this PR, the new mailbox behavior was unavailable: the test could not import or call
dcp_lse_combine,dcp_query_gather, ordcp_quant_query_gather. The test validates the multi-rank tagged-mailbox protocol, numerical LSE combination, FP8 query gather, request and per-row masking, multiple LSE bases, supported head dimensions, timeout diagnostics, graph-debug rejection, and workspace teardown. Existing canonical tests cover other communication paths and do not cover these operators or their mailbox protocol.Changed op tests
op_tests/multigpu_tests/test_dcp_mailbox.py: Before this PR, the test could not import or call the new mailbox operators. It covers combine, BF16 gather, and FP8 quantized gather across 8 ranks; dimensions 64/128/512/576; both LSE bases; request and per-row masking; epoch-zero and empty-mask timeouts; one timeout wait per tile; debug graph rejection; BF16 dim-576 rejection; split-phase gather; epoch wrap; workspace teardown; and a partial tile tail. It is not redundant because no existing canonical test covers these tagged-mailbox operators.op_tests/op_benchmarks/flydsl/bench_dcp_mailbox.py: Before this PR, the mailbox workspaces and operators were unavailable. It measures mailbox and independent vLLM A2A, all-gather, and quantize-plus-gather arms at configurable token counts. It reports median[min, max]from ten aligned graph replays. It is not redundant with the correctness test because it measures synchronized operator latency rather than numerics.