Skip to content

ggml-rpc: carry a connection to this host over the NIC's loopback when no port has its address - #18

Merged
lukekim merged 3 commits into
spiceai-b11803from
lukim/b11803-rdma-self
Oct 30, 2026
Merged

lukekim merged 3 commits into
spiceai-b11803from
lukim/b11803-rdma-self

Conversation

@lukekim

@lukekim lukekim commented Oct 29, 2026 •

Copy link
Copy Markdown

What this changes

The RDMA transport picks the port whose GID is the TCP connection's local address. A client that reaches a server on its own host at an address no port carries (a /32 on the loopback interface, 127.0.0.1) therefore stayed on TCP over the loopback interface. When a connection's two ends are this host (the peer's address is the socket's own) and no port has that address, both ends now take the IPv4 RoCE v2 GID of the first active port (of GGML_RDMA_DEV, when set), and the NIC loops the connection back. Both ends run the same choice on the same device list, so they pick the same port (by device name and GID index). Each end of any connection to this host also chooses its port from its own GGML_RDMA_DEV and GGML_RDMA_GID, so such a connection takes RDMA only when both ends chose the same GID, which both see; otherwise both stay on TCP. On such a connection an end advertises RDMA only over a RoCE v2 GID, since the two ends compare GID bytes alone and a RoCE v1 entry has the same bytes as the v2 one. A peer from a build without this change cannot take part in that agreement, because the exchanged capabilities carry no version: a connection to this host needs both ends from this build, or the same GGML_RDMA_DEV and GGML_RDMA_GID on both.

Nothing else changes: a connection whose address a port has uses that port as before, and a connection between two hosts is untouched. GGML_RDMA_GID (an explicit GID index) and GGML_RPC_NO_RDMA keep their meaning. A peer without this change advertises no RDMA for such a connection, so the two negotiate TCP as before.

Why

A tensor split over RPC (#8) drives every rank's GPU as a device, the head's own included, through an RPC server on the head. Spice serves that GPU at the head's own address from its nodes list, so that no GPU server listens on an interface the list does not name. When that address is not on the RDMA NIC (in this lab, a /32 on lo that routes to every node), the head drove its own GPU over TCP. Naming the head's ConnectX address instead decoded GLM-5.3 6.6% faster (symmetric) in an earlier A/B. With this change the head takes the NIC's loopback whatever address it serves at, so nothing has to be configured for it.

Testing

How it was measured

Three DGX Spark (GB10) nodes, each pair cabled over 200 GbE ConnectX-7 (RoCE v2), serving GLM-5.3 (Q2_K_XL) split three ways (-sm tensor, the full-mesh all-reduce from #8). The head's own GPU is served at an address on the loopback interface, which no port carries. Each bench is 8 prompts, so no P99 is stated.

Transport, llama.cpp's own tools (base 3fcbdd2 vs this branch, each with a local test-only hook that lets test-backend-ops reach an RPC server):

  • The RPC servers' logs: on the base, no connection from the head to its own GPU negotiates RDMA. With this change, the head's 14 such connections are "looped back by the NIC". On the other two nodes, whose connections all come from other hosts, none is.
  • test-backend-ops -b RPC0 -o MUL_MAT through a CUDA RPC server at the loopback address: on both builds, the same 185 cases, all OK, with identical per-case results. Both runs then stop at the same next case, in an abort inside the CUDA backend (mmvq.cu:1460, the default of mul_mat_vec_q's type switch). That case is TQ2_0: in test-backend-ops' type list it follows Q6_K, the last type that passed. Neither upstream nor this fork's CUDA backend has a TQ2_0 kernel. The case ran because the RPC device reports every op as supported (ggml_backend_rpc_device_supports_op, upstream's TODO to ask the server). So the abort is the same on both builds and independent of this change.
  • llama-server decode (no draft model), interleaved sessions:
arm head GPU served at mean (range), tok/s
base loopback address 34.14 (34.12–34.16)
this change loopback address 34.67 (34.52–34.82)
base ConnectX address 34.71 (34.54–34.88)

Replies were identical in all six sessions (8/8 each).

The Spice runtime's llama.cpp engine, the target. spiced was built against the merged levers (a337bb5 + the commits of #14, #15 and #16), with and without this commit cherry-picked, and the opt-in decode levers on.

run arm build head GPU served at symmetric mean (range), tok/s standard mean (range), tok/s
1 L base loopback address 45.42 (44.55–46.21) 43.53 (43.44–43.63)
1 R this change loopback address 48.08 (47.21–49.21) 46.18 (45.95–46.42)
1 N base ConnectX address 50.04 (49.06–51.04) 48.18 (48.12–48.24)
2 R this change loopback address 49.82 (49.09–50.70) 47.85 (47.85–47.86)
2 N this change ConnectX address 49.11 (47.08–50.83) 47.31 (46.33–48.10)
  • Run 1 (sessions L R N N R L): this change gains 5.9% symmetric and 6.1% standard over the base at the loopback address.
  • Run 2 (one binary, sessions R N N R R N): R measures the same as N, so the loopback address now costs nothing. Run 1's R-below-N gap did not reproduce in run 2 with one binary; drift of that size between runs was seen elsewhere on this lab.
  • Replies: in every session of both runs, identical to the run's first N session (8/8).
  • No connection opens while requests are served: the head logged 69 RDMA probes when the model was ready and the same 69 at the end of its benches. So the extra device scan this change adds for a connection to the same host is paid at load only.

Ends that choose different ports (c72ae2d), CPU ggml-rpc-server at the loopback address, with test-backend-ops -b RPC0 -o ADD against it (167 cases):

build unpinned server pinned to rocep1s0f1, client unpinned both pinned to rocep1s0f1
base 3fcbdd2 TCP, 167/167 TCP, 167/167 TCP, 167/167
16789f2 looped back on rocep1s0f0, 167/167 RDMA on two different ports, 167/167 looped back on rocep1s0f1, 167/167
c72ae2d looped back on rocep1s0f0, 167/167 both log the mismatch and stay on TCP, 167/167 looped back on rocep1s0f1, 167/167

On this lab the two ports loop back through one NIC, so the mismatched case passed even on 16789f2; ports that cannot reach each other were not available to test.

RoCE v1 and v2 (84f12a9), same setup; rocep1s0f0's GID 2 is RoCE v1 and GID 3 RoCE v2, with the same bytes:

build unpinned server pinned to GID 2 (v1), client unpinned server pinned to GID 3 (v2), client unpinned
c72ae2d loopback RDMA, 167/167 v1 server with v2 client, 167/167 (this NIC carried it) RDMA, 167/167
84f12a9 loopback RDMA, 167/167 server advertises nothing, both on TCP, 167/167 RDMA, 167/167
  • Not run: a host with no active RoCE port (the probe finds no GID and the connection stays on TCP, as before; from reading only), IPv6 loopback, Apple RDMA (GGML_RPC_RDMA_APPLE, untouched by this change).

…n no port has its address

The RDMA probe finds the port whose GID is the TCP connection's local address, so a client
that reaches a server on its own host at an address no port carries (a /32 on the loopback
interface, 127.0.0.1) stays on TCP over the loopback interface. When the connection's two
ends are this host and no port has its address, both ends now take the IPv4 RoCE v2 GID of
the first active port (of GGML_RDMA_DEV, when set), and the NIC loops the connection back.
GGML_RDMA_GID and GGML_RPC_NO_RDMA keep their meaning.
Copilot AI balanced review requested due to automatic review settings October 29, 2026 08:17
@github-actions github-actions Bot added the ggml label Oct 29, 2026

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

Loopback RDMA selection can choose an inactive or RoCE v1 port or incompatible NICs across peers, breaking localhost connections.

2 open issues
What changed in this PR

This PR enables same-host RPC connections to use NIC RDMA loopback when their TCP address is not assigned to an RDMA port, reducing transport overhead for the head node's own GPU.

Changes:

  • Detects connections whose local and peer addresses match.
  • Adds fallback selection of an active port's IPv4 RoCE v2 GID when no port carries the TCP address.
  • Logs when the NIC loopback fallback is selected.
File Description
ggml/​src/​ggml-rpc/​transport.cpp Adds same-host detection, loopback GID selection, and diagnostic logging to the non-Apple RDMA transport.

Review effort: Balanced

Comment thread ggml/src/ggml-rpc/transport.cpp Resolved
Comment thread ggml/src/ggml-rpc/transport.cpp Resolved
…th this host only on one GID

The loopback fallback handed the probe only GID bytes, so a device scanned earlier with the
same GID on a down or RoCE v1 port could carry the connection; it now names the device and
the GID's index it chose. Each end of a connection to this host also chooses its port from
its own GGML_RDMA_DEV and GGML_RDMA_GID, and two ports need not reach each other, so such a
connection now takes RDMA only when both ends chose the same GID, which both see the same
way, and otherwise stays on TCP at both ends.
Copilot AI balanced review requested due to automatic review settings October 29, 2026 10:01
@lukekim

lukekim commented Oct 29, 2026

Copy link
Copy Markdown
Author

Round on c72ae2d, answering Copilot review #18 (review):

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

Transport negotiation can leave peers using different transports or incompatible RoCE modes, causing subsequent RPCs to stall or fail.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread ggml/src/ggml-rpc/transport.cpp Resolved
Comment thread ggml/src/ggml-rpc/transport.cpp Resolved
The two ends of a connection to this host compare only the GID bytes they advertised, and a
RoCE v1 entry has the same bytes as the v2 one, so one end pinned to the v1 index
(GGML_RDMA_GID) and one choosing v2 passed the comparison with incompatible modes. On such a
connection an end whose GID is not RoCE v2 now advertises nothing, and both stay on TCP.
Copilot AI balanced review requested due to automatic review settings October 29, 2026 14:41
@lukekim

lukekim commented Oct 29, 2026

Copy link
Copy Markdown
Author

Round on 84f12a9, answering Copilot review #18 (review):

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

Maintainer confirmation is needed that the unversioned same-host GID exchange’s requirement for matching endpoint builds or RDMA settings is acceptable for supported deployments.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@lukekim lukekim self-assigned this Oct 29, 2026
@lukekim
lukekim merged commit 4312ca5 into spiceai-b11803 Oct 30, 2026
20 of 27 checks passed
lukekim added a commit that referenced this pull request Nov 3, 2026
* ggml-rpc: carry a connection to this host over the NIC's loopback when no port has its address (#18)

* ggml-rpc: carry a connection to this host over the NIC's loopback when no port has its address

The RDMA probe finds the port whose GID is the TCP connection's local address, so a client
that reaches a server on its own host at an address no port carries (a /32 on the loopback
interface, 127.0.0.1) stays on TCP over the loopback interface. When the connection's two
ends are this host and no port has its address, both ends now take the IPv4 RoCE v2 GID of
the first active port (of GGML_RDMA_DEV, when set), and the NIC loops the connection back.
GGML_RDMA_GID and GGML_RPC_NO_RDMA keep their meaning.

* ggml-rpc: take the loopback port by name and index, and share RDMA with this host only on one GID

The loopback fallback handed the probe only GID bytes, so a device scanned earlier with the
same GID on a down or RoCE v1 port could carry the connection; it now names the device and
the GID's index it chose. Each end of a connection to this host also chooses its port from
its own GGML_RDMA_DEV and GGML_RDMA_GID, and two ports need not reach each other, so such a
connection now takes RDMA only when both ends chose the same GID, which both see the same
way, and otherwise stays on TCP at both ends.

* ggml-rpc: advertise RDMA on a connection to this host only over RoCE v2

The two ends of a connection to this host compare only the GID bytes they advertised, and a
RoCE v1 entry has the same bytes as the v2 one, so one end pinned to the v1 index
(GGML_RDMA_GID) and one choosing v2 passed the comparison with incompatible modes. On such a
connection an end whose GID is not RoCE v2 now advertises nothing, and both stay on TCP.

* Turn the tensor-split levers on by default: graph slots, one input wait per split, stream-queued all-reduce, deferred sends (#19)

* llama, ggml-backend: two graph slots and one input wait per split by default for a tensor split

LLAMA_GRAPH_SLOTS and GGML_SCHED_SYNC_INPUTS_ONCE were off unless set. Unset, a tensor split
(LLAMA_SPLIT_MODE_TENSOR) now gets the second graph slot, and a split on the meta backend
waits for its backend once before copying its inputs; any other model keeps one slot and a
wait per input, and a value in the environment still decides either way. On a GLM-5.3 split
across three nodes over RPC, each was worth 3-5% of decode with the other levers on.

* ggml-rpc: queue a tensor split's all-reduce on a stream and defer its sends by default

GGML_RPC_COMM_ASYNC and GGML_RPC_COMM_SEND_DEFER were off unless set; they are now on unless
set to 0. Only a tensor split's all-reduce reaches either. On a GLM-5.3 split across three
nodes over RPC, with the other levers on, the stream-queued all-reduce was worth 1.4-2.6% of
decode and the deferred sends 0.9-1.7%, with replies unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants