Repository navigation
ggml-cuda : P2P direct-write path for the internal AllReduce - #516
Open
danielhanchen wants to merge 3 commits into
Open
danielhanchen wants to merge 3 commits into
danielhanchen wants to merge 3 commits into
Conversation
On two GPUs with peer access, the chunked AllReduce kernel writes its data and arrival token straight into the peer's device memory instead of staging through pinned host memory, and the large-tensor path copies peer to peer. The path is used only after an integrity probe (production kernel on known values plus a peer copy each way, every element checked). In the default auto mode it is also kept only when a decode-sized AllReduce is measurably faster than host staging. GGML_CUDA_AR_P2P=0 disables it, =1 uses it whenever the probe passes. Builds with GGML_CUDA_NO_PEER_COPY and HIP keep host staging. The wire type follows the same GGML_CUDA_AR_BF16_THRESHOLD default as host staging.
danielhanchen
marked this pull request as ready for review
December 6, 2026 09:04
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Dec 6, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The unslothai/llama.cpp prebuilt is an aged upstream
b####tag plus the pins listed inscripts/unsloth/pr-set.json, merged in order. This pin is one commit on top of upstream b12966 (9a811bab3c4) and needs no other pin. Once upstream has an equivalent change, the pin is dropped.The problem
With
-sm tensoron two NVIDIA GPUs, the prebuilt (built without NCCL) runs the internal AllReduce inallreduce.cu. It always stages through pinned host memory: each GPU writes its contribution to host memory, the peer reads it back, and both spin on arrival tokens in host memory. On a pair with a direct peer link this crosses the link twice per element and polls host memory.The fix
allreduce.cu: a P2P variant of the chunked AllReduce kernel writes the data and the arrival token straight into the peer's device memory and spins on a local flag; the large-tensor path copies peer to peer with onecudaMemcpyPeerAsynceach way.GGML_CUDA_AR_P2P=0disables the path,=1uses it whenever the probe passes.GGML_CUDA_AR_BF16_THRESHOLDdefault as host staging, so default output is unchanged.GGML_CUDA_DEVICESvirtual ids. Two virtual devices on one physical GPU keep host staging.GGML_CUDA_NO_PEER_COPYbuilds keep host staging. The chosen transport is logged once at init (AllReduce transport: ...).Evidence
-sm tensor -fa on,GGML_CUDA_ALLREDUCE=internal, greedy 128 tokens, each arm twice: auto vsGGML_CUDA_AR_P2P=1vs=0b9ec376840ca, Qwen3-0.6B Q4_K_M814061ab2564, Llama-3.2-1B F16faf5d87eb24e. Engagement (-lv 4): auto logsAllReduce transport: P2P direct write (probe passed (4 kernel rounds + 32 MiB peer copy each way), 32 KiB AllReduce 11.7 us P2P vs 18.5 us host-staged), wire BF16 for F32;=1logs P2P forced;=0logs host-staged. The=0arm runs the unchanged host-staged code, so it stands in for the base herellama_pinset.py sim, private copy, b13023, 12-06): master pr-set + open candidates #485-#503 (without #495) + #505 + #508-#513 + #516 at their current heads, 74 pins (this pin at750e4cddcbb; the current headb8b7cd99110merges clean on that tree too)merge_checksclean;pin_contract: all pins intact once #491 is listed at its current heade6e34ffd3c2(the copy listed it at131d93897cd, whose comment-trimmed line arrives through #505 / #512, a listing artifact). CUDAmmvq.cu/mmvf.cu/mmid-gemm.cu/fusion.cucompile on the merged tree (sm_75 + sm_100a)nvidia-smi topo -p2p rOK both ways), b13023 + master pr-set (A) vs A + this pin (B), plusGGML_CUDA_AR_P2P=1(B1) and=0(B0);GGML_CUDA_ALLREDUCE=internal -sm tensor -ngl 999 -fa on; greedy 128 tokens-sm tensoron any arm; with-sm layerit is identical and the path is not reached. B logsAllReduce transport: P2P direct write (probe passed ..., 32 KiB AllReduce ~14-15 us P2P vs 22-24 us host-staged)nvidia-smi topo -p2p rOK both ways), static build of750e4cddcbb(A) vs A + the physical-id fixc29cfdfe6(B, code-identical tob8b7cd99110); Qwen3-0.6B Q4_K_M,GGML_CUDA_ALLREDUCE=internal -sm tensor -ngl 999 -fa on -lv 4, greedy 96 tokens3050476a9976in all 10 cells.CUDA0,CUDA1auto /=1/=0: same transport on A and B (auto: P2P, 18.6 / 17.5 us P2P vs 23.8 / 22.6 us host-staged).GGML_CUDA_DEVICES=3,CUDA1,CUDA2(physical 1, 0),=1: A logshost-staged (cudaDeviceCanAccessPeer(1 -> 2) = 0)(virtual id passed as physical), B logsP2P direct write (probe passed ...).CUDA0,CUDA2(both physical 0),=1: Ahost-staged (cudaDeviceCanAccessPeer(0 -> 2) = 0), Bhost-staged (devices 0 and 2 share physical GPU 0)-sm tensor, median of 3 rotated roundsNot proven