Skip to content

ggml-rpc: keep several RDMA sends in flight - #34

Merged
lukekim merged 4 commits into
spiceai-b11999from
lukim/rdma-send-ring
Nov 9, 2026
Merged

lukekim merged 4 commits into
spiceai-b11999from
lukim/rdma-send-ring

Conversation

@lukekim

@lukekim lukekim commented Nov 9, 2026 •

Copy link
Copy Markdown

What

Over RDMA, a message longer than one 256 KiB chunk went out one chunk at a time. Each chunk was copied into the connection's single send buffer and waited for before the next one was copied. A deferred send longer than one chunk fell back to that blocking send. So the mesh all-reduce's 1 MiB pieces (rpc_comm_mesh_exchange, chunked) went to one peer, then the other, with the link idle while each chunk was copied. The chunked exchange is meant to send each piece to every peer at once.

How it showed: a cold read of a 3754-token prompt across three ranks, profiled with Nsight Systems on each rank's ggml-rpc-server. Each rank's GPU spent 1.9–2.0 s of the 5.4–5.5 s read waiting on all-reduces: 882 of them, 2.5–2.6 ms each (P50) for a 512-token partial of 5 MiB. The kernels took 2.3–2.5 s.

The change (ggml/src/ggml-rpc/transport.cpp, the Linux RDMA transport):

  • Send buffers: a connection keeps four 256 KiB send buffers instead of one, registered as one region. Four hold a whole 1 MiB mesh piece. A connection now registers 28 chunks (7 MiB) instead of 25.
  • Posting: a chunk is copied into the next free buffer and posted. A send waits only when the send queue (now 8 entries, from 4) or every buffer is in use. Buffers are taken in posting order and freed in completion order, so the oldest buffer in use is always the one the oldest pending copied send reads.
  • Deferred sends: a deferred send of any length is posted chunk by chunk, and its completions are taken when the queue or the buffers are needed again, or by wait_sends. So a rank posts a piece to every peer before either peer acknowledges it.
  • Blocking sends: a blocking send posts the same way, then waits for every pending send on the connection, so the call still reports a failure.

Also (tests/test-rpc-comm-mesh.cpp): the test's two-rank runs now drop the GGML_RPC_COMM_HOSTS entries for ranks 2 and up. They read each entry as rpc_comm_mesh_hosts does, and keep any entry that doesn't parse, so the comm still reports it. A lab whose ranks share one link per pair needs a three-rank map, and the two-rank mesh refused that map's rank-2 entries, so those checks never ran there.

Tests

test-rpc-comm-mesh checks that every rank ends with the same bits, the F32 sum of the partials in rank order, for 1, 7168, 300007 and 4000037 floats. It runs over the three-rank mesh, a two-rank mesh, and the pairwise comm. Here it ran on three DGX Spark (GB10) nodes, every link RDMA, with the servers and the client each on the build named:

servers and client three-rank mesh two-rank mesh pairwise exit
b20c7a2 4/4 ok 4/4 ok 4/4 ok 0
this PR 4/4 ok 4/4 ok 4/4 ok 0
this PR with the mutation below, two runs 3/4, 3/4 3/4, 3/4 3/4, 3/4 1, 1

The test is this PR's. Against b20c7a2 it ran with b20c7a2's servers and libraries. Before this PR's test change, the two-rank mesh rows did not run on this lab: GGML_RPC_COMM_HOSTS entry '2:0=…' is not i:j=host with j < i < 2, then world 2: the comm did not initialize.

Mutation: the mutation lets a chunk take the next send buffer without waiting for the send still reading it. The test fails on it at 4000037 floats, in every comm and on every rank:

world 3, 4000037 floats, rank 0: 3656053 floats differ from the rank-order sum, first at 77620 (-174.474365, want -382.56897)
world 3, 4000037 floats, rank 1: 3656053 floats differ from the rank-order sum, first at 77620 (-174.474365, want -382.56897)
world 3, 4000037 floats, rank 2: 3656053 floats differ from the rank-order sum, first at 77620 (-174.474365, want -382.56897)

At that size the test uploads each partial as one message of 62 chunks. Up to 300007 floats, a message is at most five chunks, and those checks pass.

Build: CUDA build on GB10, as in the lab rows below. The macOS CPU build compiles ggml-rpc and test-rpc-comm-mesh. It doesn't compile this RDMA transport, which is Linux only.

Lab A/B: llama-server, b20c7a2 against this PR

Setup:

  • Rig: three DGX Spark (GB10) nodes over RDMA RPC, -sm tensor, the mesh comm (GGML_RPC_COMM_MESH=1).
  • Model: Qwen3.8-Flash-Next UD-Q3_K_XL with its Q8_0 MTP head (--spec-type draft-mtp --spec-draft-n-max 3), -fa on -c 8192 -b 512 -ub 512 -np 1.
  • Builds: both CUDA builds from the same source, b20c7a2 with and without this PR's transport change.
  • Order: the arms were interleaved b20c7a2, PR, PR, b20c7a2, each a fresh session. Date 2026-11-08 and 09.

Prompt read, one-token requests after an unrelated flush, median of 3 per length:

arm cold 59 / 966 / 3754 tokens, ms per prompt token, 966→3754, ms warm 3754, ms
b20c7a2 (1) 293 / 1673 / 5514 1.378 127
PR (1) 291 / 1496 / 4903 1.222 122
PR (2) 287 / 1528 / 4973 1.235 120
b20c7a2 (2) 289 / 1653 / 5432 1.355 126

Decode, 8 prompts × 200 tokens, temperature 0, two counted runs per session:

arm pooled tok/s time to 200 tokens, max of 8, s texts equal to the first b20c7a2 run
b20c7a2 (1) 59.94, 60.45 3.87, 3.73 8/8, 8/8
PR (1) 59.86, 60.24 3.91, 3.81 8/8, 8/8
PR (2) 60.40, 60.44 3.84, 3.83 8/8, 8/8
b20c7a2 (2) 60.18, 60.71 3.82, 3.79 8/8, 8/8

Multi-turn, 4 conversations × 5 turns × 200 tokens, the whole history re-sent each turn (n=20 turns):

arm concurrency output tok/s first token P50 / P99, ms turn P99, s
b20c7a2 (1) 1 52.60 721 / 952 4.37
PR (1) 1 53.85 689 / 896 4.14
PR (2) 1 54.15 682 / 882 4.15
b20c7a2 (2) 1 53.49 731 / 937 4.21
b20c7a2 (1) 2 56.97 4001 / 4198 7.37
PR (1) 2 56.85 3953 / 4200 7.43
PR (2) 2 57.19 3968 / 4285 7.57
b20c7a2 (2) 2 57.21 3945 / 4212 7.41

All-reduce cost, from test-rpc-comm-mesh's bench mode (TEST_RPC_COMM_MESH_BENCH, three ranks). It reports a mean per all-reduce over the count, so it measures the transport alone and the tables above carry the tails. Arms interleaved b20c7a2, PR, PR, b20c7a2:

floats b20c7a2, µs PR, µs
1310720 (a 512-token partial, 5 MiB), ×300 2737.7, 2761.7 1717.1, 1720.7
2560 (one decode token), ×2000 16.4, 16.4 16.0, 16.1
10240 (four decode tokens), ×2000 26.4, 26.4 26.3, 26.4

The profile again, cold 3754-token read, Nsight Systems on two of the three ranks, three windows each:

b20c7a2 PR
window per rank, ms 5439–5482 4769–4934
waiting on all-reduces, ms 1927–2023 1310–1460
5 MiB all-reduce wait, P50 / P99, µs 2524–2648 / 3978–4209 1628–1801 / 3188–3435
GPU kernels, ms 2250–2514 2281–2499

What the numbers say:

  • Prompt reads: 10% faster from 966 tokens up (1.22–1.24 against 1.36–1.38 ms per prompt token), with the kernels unchanged.
  • Decode: inside the noise, with every text identical, as expected: a decode partial fits one chunk and never waited on a buffer.
  • Multi-turn at concurrency 1: first-token P99 882–896 against 937–952 ms. At concurrency 2 the turns wait on each other's decode, and the arms are within the noise.
  • What's left: each 512-token all-reduce still costs about 1.7 ms. A follow-up reduces large partials by a reduce-scatter and an all-gather.

A message longer than one 256 KiB chunk was sent chunk by chunk, each chunk copied into the connection's one send
buffer and waited for before the next, and a deferred send longer than one chunk fell back to that blocking send. So a
mesh all-reduce's 1 MiB pieces went to one peer, then the next, with the link idle while each chunk was copied.

A connection now keeps four send buffers. A chunk is copied into the next free one and posted without waiting, and a
send waits only when the send queue or every buffer is taken; a blocking send then waits for all of its chunks. A
deferred send of any length is posted chunk by chunk, so a rank posts a piece to every peer before either acknowledges it.
…TS's entries for rank 1

With a map of where each of three ranks reaches the others, as a lab whose ranks share a link per pair needs, the
two-rank mesh refused the map's rank-2 entries and its checks did not run.
Copilot AI balanced review requested due to automatic review settings November 9, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The test’s literal prefix check drops valid rank-1 entries accepted by the production parser, causing the two-rank mesh to lose its link override and fall back to an unreachable endpoint host.

1 open issue
What changed in this PR

This PR pipelines Linux RDMA sends in the RPC transport to reduce serialization during mesh all-reduces.

Changes:

  • Adds four send buffers and increases the send queue capacity to keep multiple chunks in flight.
  • Uses shared chunk-posting logic for deferred and blocking sends, with blocking sends draining pending completions.
  • Filters GGML_RPC_COMM_HOSTS for the mesh test's two-rank runs.
File Description
tests/​test-rpc-comm-mesh.cpp Filters host-map entries before running two-rank checks.
ggml/​src/​ggml-rpc/​transport.cpp Adds buffered RDMA send pipelining and completion-based buffer reuse.

Review effort: Balanced

Comment thread tests/test-rpc-comm-mesh.cpp Resolved
…comm_mesh_hosts does

The two-rank runs kept an entry only when it began with "1:", so one the comm accepts for rank 1, such as "01:0=host",
was dropped and the two-rank mesh fell back to rank 0's serving host. They now drop only the entries that parse as rank
2 or up, and keep any other, so an entry that does not parse is reported by the comm as before.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Two new comments in ggml/src/ggml-rpc/transport.cpp use a multiplication sign instead of ASCII x, contrary to the source convention documented in AGENTS.md.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Replace multiplication signs in comments with ASCII x

ggml/​src/​ggml-rpc/​transport.cpp:72

Use ASCII x instead of the multiplication sign in this new comment to follow the documented source convention in AGENTS.md. Apply the same replacement to the buffer-size comment at ggml/src/ggml-rpc/transport.cpp:88.

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 9, 2026 02:15
@lukekim

lukekim commented Nov 9, 2026

Copy link
Copy Markdown
Author

Re: Copilot's review 5820902474, the previously missed issue: fixed in 7216f35. transport.cpp:72 and :88, the two comments this PR added, now use ASCII x. The same character at :70 and :91 predates this PR, so it stays as it is.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approved

No active review issues are recorded for the RDMA send-pipelining and test host-filtering changes.

No open issues 🎉

Review effort: Balanced

@lukekim
lukekim merged commit 6fbeb5e into spiceai-b11999 Nov 9, 2026
21 of 28 checks passed
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