Repository navigation
feat(te): support per-request RDMA NIC hints - #4248
Conversation
staryxchen
left a comment
There was a problem hiding this comment.
This PR looks good to me overall. I left a few comments below — please take a look.
| // 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 = {}; |
There was a problem hiding this comment.
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.
| // 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)) { |
There was a problem hiding this comment.
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_hintis 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 != 0clears the hint). Once a slice is queued on anRdmaContext, ordinary remote redispatch stays on that local NIC; only local handoff moves it, and it cannot seenic_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; |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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 > 0dropping the hint inRdmaTransport- 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.
|
Addressed in ab605a2:
|
staryxchen
left a comment
There was a problem hiding this comment.
LGTM. Please address the conflict.
ab605a2 to
22edc45
Compare
|
Rebased |
22edc45 to
724fde0
Compare
Description
Add an advisory per-request local RNIC hint to the classic RDMA transport.
Mooncake already had
Topology::selectDevice(location, hint, retry_count), butclassic RDMA requests could not pass a non-empty hint to it. This change wires a
new
TransferRequest::nic_hintthrough the request-level and per-slice fallbackselection paths.
The hint is intentionally advisory:
The Python transfer APIs expose the same option as a trailing
nic_hint=""keyword argument, without changing existing positional calls. The
transfer_engine_benchexample exposes--nic_hintfor 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
mooncake-transfer-engine)mooncake-store)mooncake-conductor)mooncake-reshard)mooncake-ep)mooncake-pg)mooncake-integration)mooncake-p2p-store)mooncake-wheel)mooncake-common)Type of Change
How Has This Been Tested?
Test commands:
Current results:
topology_testpasses on both nodesnic_hintmainTested branch:
feature/rdma-nic-hintat1bcf2429(the final amend after thehardware 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-sidedRDMA 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.
nic_hint=mlx5_3Anic_hint=mlx5_5Anic_hint=mlx5_5Bnic_hint=mlx5_3BBoth 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
./scripts/code_format.shmainAI Assistance Disclosure
AI assistance was used to inspect the existing selection path, port the earlier
prototype onto the latest
main, update bindings/documentation, and preparetests. The submitter reviewed the design and is responsible for the change.