Skip to content

feat(te): support per-request RDMA NIC hints - #4248

Merged
alogfans merged 2 commits into
kvcache-ai:mainfrom
linhu-nv:feature/rdma-nic-hint
Oct 8, 2026
Merged

alogfans merged 2 commits into
kvcache-ai:mainfrom
linhu-nv:feature/rdma-nic-hint

Conversation

@linhu-nv

Copy link
Copy Markdown
Contributor

Description

Add an advisory per-request local RNIC hint to the classic RDMA transport.

Mooncake already had Topology::selectDevice(location, hint, retry_count), but
classic RDMA requests could not pass a non-empty hint to it. This change wires a
new TransferRequest::nic_hint through the request-level and per-slice fallback
selection paths.

The hint is intentionally advisory:

  • empty hint preserves the existing topology-based selection behavior;
  • unknown or disabled devices fall back to normal selection;
  • only the initial attempt is pinned, so retries can fail over to another RNIC.

The Python transfer APIs expose the same option as a trailing nic_hint=""
keyword argument, without changing existing positional calls. The
transfer_engine_bench example exposes --nic_hint for hardware validation.

This enables callers that know more than the transport about workload placement
to isolate KV traffic from NCCL/EP traffic or enforce a known GPU–NIC affinity.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test commands:

# CUDA-enabled compile of the affected core, example, test, and Python binding
cmake -S . -B build -G Ninja \
  -DWITH_STORE=OFF -DWITH_STORE_RUST=OFF -DWITH_TE=ON \
  -DBUILD_UNIT_TESTS=ON -DBUILD_EXAMPLES=ON \
  -DUSE_CUDA=ON -DUSE_TENT=OFF -DUSE_REDIS=OFF -DUSE_HTTP=OFF
cmake --build build --target topology_test transfer_engine_bench engine -j8
ctest --test-dir build -R '^topology_test$' --output-on-failure

# Repository checks
pre-commit run --files <changed files>

Current results:

  • CUDA-enabled affected targets compile
  • CPU-only builds pass on both RDMA test nodes
  • topology_test passes on both nodes
  • Python binding signatures expose nic_hint
  • Pre-commit hooks pass
  • Two-node classic RDMA validation on current main

Tested branch: feature/rdma-nic-hint at 1bcf2429 (the final amend after the
hardware run only completed the C++ API documentation snippet).

Hardware environment: two H20 nodes, six active ConnectX-7 400G NDR RNICs per
node (mlx5_0..5), RoCEv2/GID index 3. The test used host DRAM only, one-sided
RDMA READ, 8 submit threads, batch size 64, and 1 MiB requests. Initiator RX was
measured from the RNIC hardware counters over a five-second steady-state window.

case bench GB/s hardware RX GB/s top RX RNIC top share
baseline A 90.123 92.325 mlx5_1 16.82%
nic_hint=mlx5_3 A 46.049 47.439 mlx5_3 100.00%
nic_hint=mlx5_5 A 48.408 49.252 mlx5_5 100.00%
invalid hint 90.624 92.882 mlx5_1 16.71%
nic_hint=mlx5_5 B 48.338 49.027 mlx5_5 100.00%
nic_hint=mlx5_3 B 47.189 47.977 mlx5_3 100.00%
baseline B 90.525 92.610 mlx5_2 16.70%

Both run orders reproduced the result. Valid hints put all measured payload
bytes on the requested RNIC at its expected 400G effective line rate. The
unknown hint completed successfully and reproduced the baseline's even six-RNIC
distribution. The lower aggregate throughput in a valid-hint cell is expected:
the test validates pinning semantics, not whether constraining traffic to one
rail improves throughput.

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 a topology-level fallback test
  • Hardware integration test completed on the latest main
  • Changes are under 500 LOC

AI Assistance Disclosure

  • AI tools were used

AI assistance was used to inspect the existing selection path, port the earlier
prototype onto the latest main, update bindings/documentation, and prepare
tests. The submitter reviewed the design and is responsible for the change.

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

This PR looks good to me overall. I left a few comments below — please take a look.

Comment on lines +78 to +81
// Optional local RNIC preference for the classic RDMA transport, e.g.
// "mlx5_3". The hint is advisory: an unknown or unavailable device
// falls back to normal topology-based selection.
std::string nic_hint = {};

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.

This is the default-path concern.

TransferRequest is currently 64B and trivially copyable. Adding std::string makes it 96B and gives every request a ctor/dtor/copy, including callers that never set a hint (Store slice submit, Python {entry}, vector<TransferRequest>). Empty SSO is not a heap alloc, but it is still not free, and it is on the common path.

priority already leaves 4 bytes of padding. int nic_hint = -1 would keep the struct 64B. The Python / --nic_hint APIs can keep taking "mlx5_3" and intern at the boundary. If the C++ request must carry a name, std::string_view (valid until submitTransfer returns) or a small char nic_hint[16] is better than std::string.

Comment on lines +911 to +921
// Select once per request so all of its slices normally use the same
// local RNIC. A caller-provided hint takes precedence when it names an
// eligible device; Topology falls back to its normal policy when the
// hint is empty, unknown, or no longer available.
auto request_buffer_id = -1, request_device_id = -1;
const std::string_view request_hint =
request.advise_retry_cnt == 0 ? std::string_view(request.nic_hint)
: std::string_view{};
if (selectDevice(local_segment_desc.get(), (uint64_t)request.source,
request.length, request_buffer_id, request_device_id,
0, last_local_buffer_id)) {
request.length, request_hint, request_buffer_id,
request_device_id, 0, last_local_buffer_id)) {

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.

Empty-hint selection here is fine: pickTopologyDevice already branches on hint.empty() and calls the original selectDevice(location, retry_count) overload, so we do not add a getHcaIndex lookup or change random/round-robin.

Two things worth making explicit:

  • The hint is only looked up in the buffer location's preferred/avail maps. A miss falls back immediately (>= 0), so the wildcard+hint branch never runs. If a GPU buffer's topology does not list the hinted RNIC, nic_hint is silently ignored. That is easy to miss because the hardware test used host DRAM. Please document it, or try wildcard before falling back.
  • “Retries are not pinned” is submit-level (advise_retry_cnt != 0 clears the hint). Once a slice is queued on an RdmaContext, ordinary remote redispatch stays on that local NIC; only local handoff moves it, and it cannot see nic_hint. That is reasonable for an advisory hint — just do not document it as a hard pin.

}

for (int retry = 0; retry < max_retry; ++retry) {
for (auto& entry : entries) entry.advise_retry_cnt = retry;

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.

This is needed so a later Python retry does not keep pinning to nic_hint (RdmaTransport only applies the hint when advise_retry_cnt == 0).

It also changes the empty-hint batchTransferSync failure path: retries used to keep advise_retry_cnt = 0 (random among preferred), and now they use Topology::selectDevice's sequential failover, matching transferSync. First attempt is unchanged. Please mention this in the PR description, or drop the hint with nic_hint.clear() without bumping advise_retry_cnt.

The same loop in batchTransferAsync is a no-op: submit failure returns 0 immediately and does not continue the retry loop.

Comment on lines 105 to 135
TEST(ToplogyTest, TestSelectDeviceHonorsHintAndFallsBack) {
mooncake::Topology topology;
std::string json_str = "{\"cpu:0\" : [[\"mlx5_0\"],[\"mlx5_1\"]]}";
topology.clear();
ASSERT_EQ(topology.parse(json_str), 0);

const auto &hca_list = topology.getHcaList();
auto index_of = [&hca_list](const std::string &name) {
auto it = std::find(hca_list.begin(), hca_list.end(), name);
return it == hca_list.end()
? -1
: static_cast<int>(std::distance(hca_list.begin(), it));
};
const int preferred = index_of("mlx5_0");
const int fallback = index_of("mlx5_1");
ASSERT_GE(preferred, 0);
ASSERT_GE(fallback, 0);

// An explicit hint may select either topology tier.
EXPECT_EQ(topology.selectDevice("cpu:0", "mlx5_0"), preferred);
EXPECT_EQ(topology.selectDevice("cpu:0", "mlx5_1"), fallback);

// An unknown or disabled hint remains advisory and falls back to the
// normal preferred-device policy rather than failing the transfer.
EXPECT_EQ(topology.selectDevice("cpu:0", "does_not_exist"), preferred);
ASSERT_EQ(topology.disableDevice("mlx5_1"), 0);
EXPECT_EQ(topology.selectDevice("cpu:0", "mlx5_1"), preferred);
}

TEST(ToplogyTest, TestSelectDeviceAny) {
mooncake::Topology topology;

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.

This is useful, but it tests the existing Topology::selectDevice(location, hint) overload, which was already on main. It does not cover the new TransferRequest::nic_hint wiring.

Could you add coverage for:

  • empty hint vs no hint selecting the same way
  • advise_retry_cnt > 0 dropping the hint in RdmaTransport
  • hint present in the global HCA list but not in this buffer location (today this falls back to that location's preferred and never tries wildcard)

rdma_transport_submit_task_test looks like a better home for the submit-path cases.

@linhu-nv

Copy link
Copy Markdown
Contributor Author

Addressed in ab605a2:

  • replaced std::string nic_hint with an integer HCA index, keeping TransferRequest 64 bytes and trivially copyable;
  • resolve Python/benchmark NIC names at the API boundary;
  • added exact location-then-wildcard lookup before normal fallback;
  • restored the historical empty-hint batch retry behavior and removed the async no-op;
  • added submit-path tests for layout, empty hint, retry behavior, and wildcard selection. @staryxchen

@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 address the conflict.

@linhu-nv
linhu-nv force-pushed the feature/rdma-nic-hint branch from ab605a2 to 22edc45 Compare September 23, 2026 07:03
@linhu-nv

Copy link
Copy Markdown
Contributor Author

Rebased

@linhu-nv
linhu-nv force-pushed the feature/rdma-nic-hint branch from 22edc45 to 724fde0 Compare October 8, 2026 05:29
@alogfans
alogfans merged commit bb0d749 into kvcache-ai:main Oct 8, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Integration run-ci Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants