Repository navigation
[ROCm][Performance] Coalesce contiguous SimpleCPUOffload DMA copies - #56110
Open
Fangzhou-Ai wants to merge 4 commits into
Open
Fangzhou-Ai wants to merge 4 commits into
Fangzhou-Ai wants to merge 4 commits into
Conversation
Merge adjacent block mappings when both source and destination advance together, reducing batch descriptors without changing copied bytes or stream ordering. Cover mappings, heterogeneous region sizes and chunking. Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: fai <fangzhouai@gmail.com>
Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: fai <fangzhouai@gmail.com>
4 tasks done
Fangzhou-Ai
marked this pull request as ready for review
September 10, 2026 00:49
Collaborator
Author
|
Hi @ivanium , please take a look at this PR and let's discuss how to effectively accelerate the ROCm MM3 cache offloading cc @ChuanLi1101 |
Preserve coalescing when source and destination block IDs descend together, as produced by lazy offload eviction order. Split direction changes and guard uint64 boundaries. Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: fai <fangzhouai@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
SimpleCPUOffload submits one DMA descriptor per block per KV region even when consecutive mappings cover one contiguous span. A MiniMax-M3 TP4 rank with 118 KV regions and 256 blocks therefore submits 30,208 descriptors for about 0.99 GB of payload.
On ROCm, coalesce a run when source and destination block IDs both advance by one or both decrease by one. Split at gaps, repeated IDs, mismatched directions, and direction changes; normalize descending runs to their lower source and destination endpoints. Each merged range covers exactly the requested adjacent blocks. Payload bytes, destination mappings, region boundaries, streams, attributes, and the existing descriptor cap remain unchanged. CUDA retains its existing per-block descriptors.
Descending support matters for lazy offload: eviction order commonly produces paired descending physical block IDs, which the ascending-only implementation could not merge.
For every KV region, the merged run lengths partition the original block list, so
sum(run_length * bytes_per_block) == block_count * bytes_per_block. A gap or turn starts a new run; the implementation never spans the gap. The byte-array tests also verify untouched destination sentinels. Coalescing therefore removes descriptors and does not add payload traffic.Duplicate searches repeated on 2026-09-10 for SimpleCPUOffload coalescing, descending KV DMA, and
hipMemcpyBatchAsyncreturned only this PR for this change. Related PRs operate at different layers: #54483 batches NIXL staging groups, #55841 changes block allocation preference, #53860 fixes memcpy attribute indices, #47324 fixes cross-stream synchronization, and #56170 changes a MiniMax-M3 scalar upload.OpenAI Codex assisted with implementation, tests, benchmarking, analysis, and drafting. The submitting human will review every changed line and the validation evidence before merge.
Test Plan
Reproducers, individual samples, byte checks, model outputs, and the sanitized C32 diagnostic are in the benchmark evidence.
Test Result
Copy microbenchmarks
One MI355X, ROCm 7.2.3 / HIP 7.2.53211, 118 regions, 256 blocks, 32 KiB per block per region, and 989,855,744 bytes per direction. Completion includes descriptor construction, submission, and stream synchronization; allocation, initialization, warmup, and validation are excluded.
The ascending rows compare the pre-PR helper with the intermediate ascending-only implementation. The descending rows compare that intermediate implementation with the current helper at commit
ca560745bb/ file SHA2566c66dc25775e76aaa60a21e02151547c56a2a7380adcb6ebad41517cece6767e.Bounded MiniMax-M3 C32 diagnostic
A separate TP4, 32-request natural-eviction diagnostic exercised the lazy descending restore path. Before and after transferred the same 16,128 blocks and 62,360,911,872 H2D bytes. Descending coalescing reduced submitted descriptors from 1,903,104 to 75,992, HIP calls from 252 to 32, and aggregate worker host-submission time from 23.367 s to 0.416 s. The restore phase fell from 8.141 s to 2.696 s and mean TTFT from 3.855 s to 0.853 s, with identical 516,096/521,128 CPU-cache recovery and zero preemptions. The fixed lazy restore duration was within 0.5% of eager (2.696 versus 2.684 s).
This was a bounded diagnostic run separately before and after on a broader experimental stack containing early-load/order changes. It is not a full InferenceX replay or model-quality evaluation; its answer-correctness diagnostic was false and was not used as an acceptance gate. The matched payload, restore counters, timing gates, and copy instrumentation passed.