Skip to content

[TENT] Add asynchronous MLU host-device copies - #4720

Merged
staryxchen merged 12 commits into
kvcache-ai:mainfrom
lhzds:codex/tent-mlu-async
Oct 23, 2026
Merged

staryxchen merged 12 commits into
kvcache-ai:mainfrom
lhzds:codex/tent-mlu-async

Conversation

@lhzds

@lhzds lhzds commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Synchronous MLU staging copies block the submitting thread until each copy finishes. This PR uses CNDRV queues and per-copy notifiers for pinned D2H copies and pinned H2D copies above 64 KiB, allowing submission to return while the copy is in flight.

Small H2D copies run synchronously when their direction queue is absent or idle; otherwise, pinned copies join the queue. Pageable copies wait for earlier work in their direction to drain before copying synchronously. Copies preserve submission order within each transport, device context, and direction. Dependencies across directions or contexts require caller synchronization.

MLU staging uses cnrtHostMalloc, with a fallback to the normal NUMA allocator when the requested cpu:N placement cannot be satisfied. Ordinary internal CPU allocations retain the engine’s existing allocator selection.

The change also handles the completion and memory lifetimes required by asynchronous copies:

  • Queue failures: Keep in-flight copies pending until nonblocking driver queries confirm that the queue has drained. Reject new submissions to an errored queue until it is idle, then use a fresh queue.
  • Progress and notifications: Deliver completion notifications with the runtime queue enabled or disabled, including when TCP work is appended to a pending MLU batch. Synchronize task publication and notification-hook installation so polling cannot observe incomplete requests or consume a completion wake too early.
  • Registration rollback: Roll back staging registration before freeing memory. If rollback fails, retain the allocation and report the error so registered memory remains valid.

Suggested Merge Priority

  • P2 — Normal: Asynchronous MLU staging copies.

Module

  • Transfer Engine (mooncake-transfer-engine)

Type of Change

  • New feature

How Has This Been Tested?

Correctness validation — 342b4a01

Validated on two MLU580-X6 hosts, each with one visible 48 GiB device and driver 6.5.42. This validation was performed on 342b4a01, before the subsequent rebase.

  • All 296 cases passed per host, with no failures or skips, covering MLU transport, platform, engine, process, memory lifecycle, background progress, runtime queue dispatch, and local notifications.
  • The 15 progress, task-publication and initialization tests passed 20 repetitions per host. They cover nonblocking notifier-error handling, mixed MLU/TCP batches, and notifications with the runtime queue on or off.
  • The initialization probe reproduced a permanent logical failure on all five runs against the previous revision despite correct DMA payloads. The unpublished-task and notification-hook tests also failed on all five runs against the previous implementation. The fixed probe checks both task status and payload integrity.
Validation details

The 296 cases comprise 65 MLU transport, 6 platform, 153 engine, 9 process, 10 memory lifecycle, 28 progress worker, 17 runtime queue dispatch, and 8 local notification cases.

Both hosts used identical test binaries and libraries built from the tested source. Scoped formatting and pre-commit checks, and git diff --check, passed.

Historical performance measurements

Measurements on earlier revisions showed much shorter submission blocking and about 3% lower full-batch completion time for large local copies. The two-host HP TCP comparison showed lower throughput and higher tail latency.

Performance measurements on earlier revisions

The measurements below were collected on earlier revisions. Each comparison identifies its tested version and baseline.

Environment: two MLU580-X6 hosts, each with one visible 48 GiB device and driver 6.5.42.

Local copies

Versions: synchronous baseline c3aea655 versus local revisions based on 10f1a673. The revised source was unpushed at measurement time; the original record does not identify a unique commit for that source snapshot.

Both builds used identical pinned buffers and fixed NUMA placement, with five alternating A/B pairs, 10 warmups, and 100 samples per point. The table reports per-host medians for 4 × 64 MiB copies, or 256 MiB per batch.

Direction Submission: baseline → revised Full completion: baseline → revised
D2H 4.88 ms → 26–29 μs 4.88 ms → 4.75 ms
H2D 5.42–5.43 ms → 32–35 μs 5.42–5.43 ms → 5.28 ms

The main improvement is reduced submission-thread blocking, allowing overlap with other work. Full batch completion time decreases by about 3%.

For 4–64 KiB copies, single-copy D2H completion increases by 2.7–2.9 μs (35–45%), while batch-4 completion improves by 10–15%. Small H2D stays within 2%. The local-copy validation completed 52,800 full-payload checks.

Two-host HP TCP

Versions: the same c3aea655 baseline and local revisions based on 10f1a673, both with the same #4703 benchmark overlay. Both builds predate #4797; these measurements use merge_requests=false to avoid the existing duplicate staging submission.

The workload is READ, 4 × 64 MiB per batch, one worker, 512 MiB device buffers, and 4 MiB staging chunks, with a 1-second warmup and 60 seconds per run. Each host initiates separately. Device memory was explicitly selected and checked at both endpoints; payload checks were outside the performance loop.

Each initiator ran two baseline/revised pairs. The table includes all eight runs, using medians across runs for throughput and medians of per-run latency percentiles. GB/s counts logical payload; latency covers batch submission through completion.

Initiator GB/s: baseline → revised P99 ms: baseline → revised P99.9 ms: baseline → revised
Host A 9.437 → 8.711 33.156 → 34.928 36.673 → 39.589
Host B 9.517 → 8.954 31.707 → 34.257 36.102 → 37.367

These runs do not establish an end-to-end performance improvement. The all-run medians show lower throughput and higher tail latency in the revised build.

Per-pair measurements and receive-CPU observations

Receive-CPU distribution was inspected after measurement. Each run had four HP TCP data connections. In pair 1 on each host, both builds had connections on four distinct receive CPUs. In the slower revised run of pair 2, two connections shared a receive CPU. This association does not establish the cause of the slowdown.

All arrows show baseline → revised.

Initiator Pair Distinct receive CPUs GB/s P99 ms P99.9 ms
Host A 1 4 → 4 9.321 → 10.068 34.153 → 29.883 36.753 → 37.379
Host A 2 4 → 3 9.553 → 7.354 32.159 → 39.973 36.593 → 41.798
Host B 1 4 → 4 9.427 → 10.105 32.140 → 29.475 36.814 → 34.656
Host B 2 4 → 3 9.607 → 7.802 31.273 → 39.039 35.391 → 40.079

The broader two-host validation included 16 × 120-second runs with merging enabled and these 8 × 60-second controls with merging disabled. All 24 separate 256 MiB WRITE/readback checks passed.

Small H2D copies after the ordering fix

Versions: 1b37418f versus the previous PR head, 10f1a673.

Measurements used SDK-pinned buffers, fixed NUMA placement, and six interleaved runs per build and host. Sizes were 4/16/64 KiB, with batch sizes 1/4; full-payload checks ran outside timing.

Queue state Change in median completion latency versus 10f1a673
No queue, small copies only +0.1% to +0.9%
Existing idle H2D queue, batch 1 +0.73–0.79 μs
Existing idle H2D queue, batch 4 +2.42–2.55 μs

The idle-queue path remained faster than submitting every small copy asynchronously. With a busy H2D queue, small copies wait for earlier work to finish, preserving submission order.

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation
  • I have added tests to prove my changes are effective

AI Assistance Disclosure

  • AI tools were used

OpenAI Codex assisted with implementation, regression tests, hardware validation, and this description.

@staryxchen staryxchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please do a rebase.

lhzds added 12 commits October 22, 2026 15:05
Signed-off-by: lepam <69680504+lhzds@users.noreply.github.com>
Restore location-only Pin requests and select the MLU allocator on the
node owning the staging pool. Remove allocator hints and capability
metadata while retaining asynchronous copies and NUMA fallback.

Cover local and remote pool reuse, allocator selection, and legacy Pin payloads.
Signed-off-by: lepam <69680504+lhzds@users.noreply.github.com>
Signed-off-by: lepam <69680504+lhzds@users.noreply.github.com>
@lhzds
lhzds force-pushed the codex/tent-mlu-async branch from 342b4a0 to f9a0385 Compare October 22, 2026 07:22
@lhzds

lhzds commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

LGTM. Please do a rebase.

Done, rebased onto the latest main and pushed. Thanks for the review!

@lhzds

lhzds commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@staryxchen Could you please help rerun the failed CI jobs? The EFA build failed during dependency installation because the Microsoft package repository returned HTTP 403 Forbidden, before compilation started.

@staryxchen
staryxchen merged commit a749680 into kvcache-ai:main Oct 23, 2026
56 of 60 checks passed
@lhzds lhzds mentioned this pull request Oct 23, 2026
11 tasks done
Connor-Matthew added a commit to LinQuickDev/Mooncake that referenced this pull request Oct 26, 2026
A staged owner holds the receiver credit for all of its chunks, and the
chunks themselves are credit-exempt. If one chunk fails while a sibling's
cross stage is still writing into the receiver, returning the credit at
that point would let the receiver grant the same capacity to another
sender while the old write is still landing.

Upstream kvcache-ai#4720 made ProxyManager keep the parent PENDING until in-flight
siblings drain. Add an end-to-end regression through the runtime queue
and receiver-credit gate: the staged owner stays PENDING and a second
credit-gated write never reaches the transport until the held cross-stage
write drains; only then does the owner fail, return the credit, and let
the second write complete. Reverting the upstream drain makes the test
fail on all three checks.

CI hosts have no device memory, so add a test-only
setStagingPolicyForTest hook that forces host staging for selected
requests.
wzy-782 added a commit to wzy-782/Mooncake that referenced this pull request Oct 29, 2026
Conflicts with upstream main, resolved:
- transfer_engine_impl.cpp, planTransport (getTransportType before
  kvcache-ai#4378): upstream added the XPU dma-buf RDMA (kvcache-ai#4378) and same-host XPU
  IPC (kvcache-ai#4379) routes. A request with a TPU side always stages and never
  takes either route; XPU and MLU requests behave as upstream.
- transfer_engine_impl.cpp, findStagingPolicy: #2's combined TPU/XPU/MLU
  staging block replaces the old TPU case, with upstream's note on the
  XPU dma-buf bypass. XPU memory is no longer called never
  NIC-addressable.
- transfer_engine_impl.cpp, submitTransfer: upstream's progress lock
  (kvcache-ai#4720) around #2's prepareSubmit call with the staged route.
- tent/tests/CMakeLists.txt: #1's TPU adapter tests, then #2's engine,
  staged-route and host-initiator tests.

Known failure: EngineFailoverE2E.MergedStagingRequestsShareOneSubmission
(kvcache-ai#4797). The test marks the peer buffer as MLU only in the test thread's
segment cache, which is thread-local. #2 re-plans a staged request's hop
on the ProxyManager thread, whose cache shows host memory, so the hop
gets no route.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants