Skip to content

[3/3] [Store] Avoid staging for remote GPU reads - #3431

Merged
ykwd merged 1 commit into
kvcache-ai:mainfrom
neverhook:codex/store-direct-gpu-read
Oct 16, 2026
Merged

ykwd merged 1 commit into
kvcache-ai:mainfrom
neverhook:codex/store-direct-gpu-read

Conversation

@neverhook

@neverhook neverhook commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Avoid mandatory CPU staging when the selected remote memory replica can be
read directly into a GPU destination through Transfer Engine.

Stack

This is [3/3] of the RFC implementation stack:

  1. [1/3] [TransferEngine] Add HOST_NUMA Fabric allocation core #2966 — HOST_NUMA/Fabric Transfer Engine prerequisite (merged).
  2. [2/3] [Store] Add EGM-backed Store pool over NVLink #3335 — Provider-owned EGM Store pool (merged).
  3. [3/3] [Store] Avoid staging for remote GPU reads #3431 — direct remote-memory reads into GPU destinations (this PR).

#3335 has merged, and this PR has been rebased onto main by replaying the
direct-read patch. GitHub now shows only this PR's single-commit, four-file
direct-read change against main.

Problem

Remote memory reads into GPU buffers fall back to CPU staging even when
Transfer Engine can write directly to the destination. Direct-read eligibility
must follow the selected replica's transport, which can differ from the
protocol requested at client setup.

The staging path adds a CPU allocation and host-to-device copy, which can
become the throughput bottleneck for cross-node paths such as EGM to HBM.

Fix

The private direct-read predicate now receives the selected
Replica::Descriptor and uses the memory replica's actual
buffer_descriptor.protocol_:

Selected replica Destination behavior
nvlink Ordinary CUDA destination is passed directly to Transfer Engine
rdma Direct only when the full destination range is Store-registered
Other protocols Existing CPU staging fallback

The affected full, ranged, and batched GPU-read paths pass the selected replica.
The newer snapshot APIs retain their existing registration and lease contracts.
There is no new Transfer Engine introspection API, public C++/Python API, wire
schema, or configuration change.

Relationship to existing work

Review size

  • 1 logical commit.
  • 4 changed files.
  • +98/-6 lines relative to main.

Validation

The direct-read logic and tests are unchanged. This update replays the patch
onto main after #3335 merged; the direct-read increment retains the same
patch-id.

Current-head CI (db195f7f7cad61a0a3c3141b8ecf6ca399a54fca):

The Sphinx documentation job was skipped by path filtering in this run; it
was not rerun on this head.

Earlier validation, retained as history rather than new results for this replay:

  • clang-format 20 check on PR-changed C/C++ lines.
  • git diff --check and all applicable PR-scoped hooks, including CMake formatting.
  • CUDA-on and CUDA-off direct-read regression tests (3 entries each).
  • CUDA-on VMM regression tests (2 entries).
  • CUDA-on/off EGM configuration/capacity and backend-selection regressions.
  • CUDA-off Transfer Engine, Store, Master and Python binding build.
  • CPU/TCP tensor snapshot: 3/3 with no skips; probe exports and close/fresh-setup smoke.
  • Strict Sphinx documentation build on the previous revision.

The earlier upstream CMake formatting issue is fixed in the new base; no hook
exception is needed. Repository-wide pre-commit run --all-files is not a merge gate.

The regression matrix intentionally crosses requested and selected protocols:

  • requested nvlink + selected RDMA replica: staging until the full
    destination range is registered;
  • requested rdma + selected NVLink replica: direct GPU destination;
  • TCP/other replica: staging fallback;
  • registered-range boundaries are covered.

The existing two-node GB200 result is historical supporting evidence, not
validation of this head. No GB200 run is included in this update. The simplified EGM lifecycle in
#3335 still needs fresh hardware evidence; its previous results are not reused.

Module

  • Mooncake Store (mooncake-store)

Type of Change

  • Bug fix
  • Performance improvement

Checklist

  • I have performed a self-review of my own code
  • I have formatted changed C++ code using clang-format 20.1.8
  • I have added tests to prove the changes are effective

Repository-wide pre-commit is intentionally not used as a merge gate for this
focused change.

AI Assistance Disclosure

  • AI tools were used

AI assistance was used to inspect the Store/Transfer Engine path, implement the
focused fix, add regression coverage, run validation, and update this PR. The
human submitter remains responsible for reviewing and defending the change.

@neverhook

Copy link
Copy Markdown
Contributor Author

Core change: remote memory reads no longer equate !CanUseLocalMemcpy() with mandatory CPU staging. NVLink reads can target ordinary CUDA allocations directly; RDMA/GDR reads are direct only for Store-registered destination ranges. TCP, file-backed, hot-cache, and unregistered RDMA paths retain the existing fallback. This is split from #3335 so the cross-node Transfer Engine behavior can be reviewed independently.

@yokinoshitayoki

Copy link
Copy Markdown
Collaborator

@neverhook I think this direction looks good to me, recently merged PR #3159 avoids staging for same-node tensor writes, while #3197 covers same-node reads. This PR further avoids staging for remote node reads. But could we test it on real NVLink devices to validate both correctness and performance?

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from 78b70a7 to 77b965e Compare August 18, 2026 04:39
@github-actions github-actions Bot added documentation Improvements or additions to documentation Transfer Engine CI/Build Integration labels Aug 18, 2026
@neverhook neverhook changed the title [Store] Avoid staging for remote GPU reads [3/3] [Store] Avoid staging for remote GPU reads Aug 18, 2026
@neverhook

Copy link
Copy Markdown
Contributor Author

@yokinoshitayoki The real NVLink validation is now complete on two GB200 nodes in the same NVL72 NVLink domain.

For the direct remote-memory read covered by this PR, Consumer local_buffer_size=0 successfully read Provider EGM directly into local HBM. Correctness passed for single-GPU and four-GPU runs. After excluding first-use lazy initialization, EGM-to-HBM sustained p50 was 211.77–211.90 GB/s per GPU and 390.62 GB/s for the four-GPU aggregate. Store Get aggregate p50 reached 175.92 GiB/s. Fabric health remained good, no new C2C errors were observed, and Provider metadata/EGM resources were fully cleaned up.

The complete acceptance context is in the Store PR validation report and the RFC update.

@neverhook

Copy link
Copy Markdown
Contributor Author

Stack maintenance update:

  • Rebased the complete [1/3] -> [2/3] -> [3/3] stack onto current main; this layer remains patch-equivalent by range-diff.
  • The composed head passed diff/format/pre-commit checks, CUDA-on focused tests (nvlink_vmm_unit 2/2, egm_store_pool_unit 1/1, direct-read 3/3), and CUDA-off Store/Transfer Engine/Master/Python validation.
  • Fresh exact-head GitHub Actions have been triggered and are currently queued.

GB200 was not rerun because this was a patch-equivalent baseline rebase with no functional-path change.

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from e8caa64 to 1743f7e Compare September 1, 2026 03:55
@neverhook

Copy link
Copy Markdown
Contributor Author

Stack update:

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from 1743f7e to 5d17c90 Compare September 5, 2026 10:17
@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased onto #3335 with the direct-read patch unchanged. All three regression tests pass with and without CUDA. Full CI is running again.

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from 5d17c90 to 7957c54 Compare September 7, 2026 08:15
@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased onto #3335 with the direct-read patch unchanged. The stack now includes #3870, and fresh CI has been triggered.

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from 7957c54 to 26c6c6c Compare September 10, 2026 10:42
@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased on the updated Store layer. No changes to the direct-read logic; the new CI run will check the combined stack.

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch 3 times, most recently from c316f1d to 882a0d0 Compare September 23, 2026 07:00
@neverhook

Copy link
Copy Markdown
Contributor Author

Rebased onto the updated Store layer after #2966 merged. The direct-read patch is unchanged, and its CUDA-on/off regressions still pass. Fresh CI will check the combined stack.

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from 882a0d0 to d0acafe Compare September 23, 2026 12:20
@neverhook

Copy link
Copy Markdown
Contributor Author

Replayed this on the simplified EGM Store layer in #3335. The direct-read logic
and tests are unchanged. Local CUDA-on/off regressions and the CPU/TCP snapshot
tests pass; the new CI runs are underway. No new GB200 result is claimed.

@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from d0acafe to 16b212e Compare September 24, 2026 12:03
@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch 2 times, most recently from aa23e02 to 577f772 Compare October 4, 2026 09:10
Signed-off-by: wugou.cyf <wugou.cyf@antfin.com>
@neverhook
neverhook force-pushed the codex/store-direct-gpu-read branch from 577f772 to db195f7 Compare October 15, 2026 06:44

Copy link
Copy Markdown
Contributor Author

@yokinoshitayoki #3335 has merged, and this PR is now rebased onto main. CI is green on the current head, including 249/249 CTest tests. Could you take another look and approve if it's ready?

@Aionw Aionw 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

@ykwd
ykwd merged commit 9c0528d into kvcache-ai:main Oct 16, 2026
30 checks passed
LujhCoconut added a commit to LujhCoconut/Mooncake that referenced this pull request Oct 18, 2026
The PR changed registered_buffer_sizes_ from unordered_map<void*,
size_t> to unordered_map<void*, BufferRegistrationRecord>; the test
merged from main (kvcache-ai#3431) still assigned a bare size_t. Use aggregate
initialization.
xiaguan added a commit to xiaguan/Mooncake that referenced this pull request Oct 26, 2026
…nted with

A memory replica's descriptor reported `protocol_ == "tcp"` for every
segment except CXL: `AllocatedBuffer::protocol` defaulted to "tcp" and only
`change_to_cxl` / `copyTransferProtocolFrom` ever changed it, so the
protocol a client mounted its segment with (rdma, nvlink, ...) never reached
readers. `RealClient::can_use_direct_memory_read` (kvcache-ai#3431) decides from that
field, so a GPU-destination read always fell back to staging through the
local buffer, even from an nvlink/EGM segment.

The protocol is now a property of the allocator, like the transport
endpoint: every allocator creation site passes the mounted segment's
protocol (SegmentManager and SegmentPool mounts, snapshot restore, the CXL
global allocator as "cxl", NoF segments as "nvmeof"), and a buffer carved
from an allocator carries that protocol in its descriptor.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
xiaguan added a commit to xiaguan/Mooncake that referenced this pull request Nov 3, 2026
…nted with

A memory replica's descriptor reported `protocol_ == "tcp"` for every
segment except CXL: `AllocatedBuffer::protocol` defaulted to "tcp" and only
`change_to_cxl` / `copyTransferProtocolFrom` ever changed it, so the
protocol a client mounted its segment with (rdma, nvlink, ...) never reached
readers. `RealClient::can_use_direct_memory_read` (kvcache-ai#3431) decides from that
field, so a GPU-destination read always fell back to staging through the
local buffer, even from an nvlink/EGM segment.

The protocol is now a property of the allocator, like the transport
endpoint: every allocator creation site passes the mounted segment's
protocol (SegmentManager and SegmentPool mounts, snapshot restore, the CXL
global allocator as "cxl", NoF segments as "nvmeof"), and a buffer carved
from an allocator carries that protocol in its descriptor.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: JinYan Su <751080330@qq.com>
Aionw pushed a commit that referenced this pull request Nov 10, 2026
…ts keep a GPU context on their own socket (#4951)

* [Bugfix][Store] Replicas advertise the protocol their segment was mounted with

A memory replica's descriptor reported `protocol_ == "tcp"` for every
segment except CXL: `AllocatedBuffer::protocol` defaulted to "tcp" and only
`change_to_cxl` / `copyTransferProtocolFrom` ever changed it, so the
protocol a client mounted its segment with (rdma, nvlink, ...) never reached
readers. `RealClient::can_use_direct_memory_read` (#3431) decides from that
field, so a GPU-destination read always fell back to staging through the
local buffer, even from an nvlink/EGM segment.

The protocol is now a property of the allocator, like the transport
endpoint: every allocator creation site passes the mounted segment's
protocol (SegmentManager and SegmentPool mounts, snapshot restore, the CXL
global allocator as "cxl", NoF segments as "nvmeof"), and a buffer carved
from an allocator carries that protocol in its descriptor.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: JinYan Su <751080330@qq.com>

* [Bugfix][TE] An EGM segment keeps a GPU context on its own socket

NvlinkHostNumaAllocation::Create allocates one HOST_NUMA segment per NUMA
node, but the provider process only ever holds a context on device 0.
When a peer imports the fabric handle, the driver routes the mapping
through a GPU of the exporting process that sits on the memory's socket
if the process has a context on one, and otherwise through whatever GPU
it has; for the far socket's segment every access then also crosses the
host's CPU-to-CPU link. On a GB300 tray that is 87 GiB/s instead of the
197 GiB/s C2C rate, and the route is fixed when the handle is imported.

Create now retains the primary context of the first visible GPU whose
HOST_NUMA_ID is the segment's node, for as long as the allocation lives.
A node with no GPU attached keeps the old behaviour.

Measured with the store's nvlink consumer reading a 1 GiB object from a
64 GiB EGM pool on another tray: get_into GPU 86 -> 182-184 GiB/s, get_into
host 87 -> 171 GiB/s.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: JinYan Su <751080330@qq.com>

* [Bugfix][Store] A remounted replica advertises its segment's current protocol

ReMountSegment imports each segment's allocator with the protocol the
segment is mounted with, so the rebuilt buffers carry it, but
Replica::replace_memory_buffer then copied the protocol of the buffer
being replaced onto the new one. Before the previous commit that copy
was a no-op, every buffer said "tcp"; after it, the copy put the
snapshot's stale protocol back, so replicas restored from a pre-upgrade
snapshot kept advertising "tcp" until the object was rewritten, and a
segment remounted under another protocol kept advertising the old one.

The imported buffer keeps its segment's protocol; copyTransferProtocolFrom
goes with its only caller. The new test restores a standby snapshot whose
descriptor says "tcp", remounts the segment with protocol "nvlink" and
reads "nvlink" back; without the fix it reads "tcp".

Reported by Aionw in the review of #4951.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: JinYan Su <751080330@qq.com>

* [Bugfix][Store] The cachelib remount test mounts its segment with the protocol it expects

RemountRestoresCachelibMemoryReplica wrote "rdma" into the snapshot
descriptor and expected it back after remount, but remounted a segment
with no protocol. Since the previous commit a remounted replica takes its
segment's current protocol, so it read back "". The segment now mounts
with "rdma", which is what the assertion means.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: JinYan Su <751080330@qq.com>

---------

Signed-off-by: JinYan Su <751080330@qq.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
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.

4 participants