Skip to content

gpu, gpu-gates: the link's all-gather of f32 row spans among N ranks, and link_probe --gather - #501

Merged
juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-link-gather
Oct 19, 2026
Merged

juliankang4 merged 2 commits into
midagedev:mainfrom
juliankang4:dgx-spark-link-gather

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

TP=2를 위해 두 개의 노드가 층마다 계산 결과를 서로 주고받는 통신(all-gather)을 기존 RDMA 링크 위에 더하는 작업입니다.

What and why

Part of #494, the "The exchange of partial rows between the two nodes over the existing link" item.

Under TP=2, each GLM-5.3-Flash layer ends its attention and its feed-forward block with a partial row on each node, and both nodes need the same sum before the next layer starts. This PR adds that exchange to the existing link as an all-gather among N ranks. Each rank's card writes its part into its own page, the link's ends carry the part to every other rank's page, and each card waits for the other parts and adds all of them in rank order. Every rank adds the same values in the same order, so every rank holds the same bits. Nothing in the engine opens a gather yet; the TP=2 placement and decode are later items of #458.

What the PR adds:

  • bloomery_gpu::host::Gathers (crates/gpu/src/host/link/gather.rs) lays out the gather slots alike on every rank's page. A slot holds two span sets, each with one part per rank, and one counter per set and rank. The link's tail follows, with a block of lines for every pair of ranks. Each pair of ranks is one link of the existing RdmaEnd and pump, and a part crosses it the way a tier's done does.
  • Gathers::post and Gathers::wait return a gather's stream memory operations. A post is a system-scope barrier and one more generation on the rank's own counter. A wait is, on each other rank's counter, a wait for at least one and the take back of one. A captured CUDA graph therefore waits on one fixed target on every replay. Gathers::enqueue_sum adds the parts in rank order through the existing ElemKernels::enqueue_add. Its windows over the page come from WindowMut::from_raw (crates/gpu/src/tensor.rs), a non-owning window over caller-owned memory that releases its context handle when it drops, as Window's drop already does.
  • Two sets per slot let a fast rank start the next gather while a late rank is still adding the current one. Between two uses of one set the ranks run another gather, so stream order alone keeps every part until each rank has added it. With one set, the fast rank overwrites a part the late rank has not added yet, and the late-reader test below catches that.
  • The code takes any number of ranks from two up. No array size, span count or sum order assumes two, and every test runs at 2, 3 and 4 ranks.
  • link_probe --gather ROWS runs the gather on N nodes. Each node holds an end to every other node, and the stage passes the peers' endpoints between them. One replay is a captured chain of a token's 91 gathers: two a layer for 45 layers, each ROWS rows of 4096 f32, then the output head's gather of two words a row. Each node counts the stale words in the parts it waited for, checks its last replay's sums against the host's rank-order sum, and prints the gather latency lambda_g, per gather and summed over a chain, as a link_gather record that link_probe --records-schema lists. lambda_g runs from a stamp after the rank's part is written to a stamp once its wait has released, one kernel launch included. The stage fails on a stale word, a sum the host disagrees with, or a digest of the sums (Fnv1a64 over the per-value digests) that differs between nodes. The round-trip and --size runs keep their star layout, and setup refuses --gather together with --size.

Existing paths: a page with no gather slot has the layout link_tail gives on main, and no tier page, crossing or message changes. In link/pump.rs only the test module and its Mem test page become visible to the gather's tests, link.rs gains only the gather module and its re-export, and tensor.rs gains only WindowMut::from_raw and its test.

Release notes: Under the hood: the link carries an all-gather of f32 row spans among N ranks that a captured CUDA graph waits on, and link_probe --gather runs a token's 91 gathers across N nodes.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. The gather reuses the link's RdmaEnd, pump and link_tail, the graph's op_wait_geq, op_add and op_barrier_sys, and ElemKernels::enqueue_add for the sum. It adds no kernel to bloomery-gpu; the only new kernels are link_probe's own test kernels.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone.
  • No silent failure. Gathers::new refuses fewer than two ranks, a rank past them, an empty slot and a slot or rank count whose page passes usize by name, checking every product before it can wrap, and Gathers::enqueue_sum refuses more rows than the slot holds, a short output or an output over the page's parts, counters or tail by name.
  • Comments state what is true now.
  • No relaxed gate. tools/unsafe-ratchet.txt moves the gpu and gpu-gates counts up for the new blocks only, each count with its PIN(2026-10-19): line, and every new unsafe block has its SAFETY line.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": in link_probe, both modes now open their ends through one open_ends (crates/gpu-gates/src/bin/link_probe.rs:592), share one Node for the stall report, the bounded wait and the release on failure (crates/gpu-gates/src/bin/link_probe.rs:719), and enqueue through one bounded replays loop (crates/gpu-gates/src/bin/link_probe.rs:1320). The digest reuses Fnv1a64, the line goes through record.rs, and the gather's loopback tests reuse pump's Mem test page.

What I ran

Head 960eb44c6059aec7c250497bdf31b6c7e6443881, base b36f8e916360005ce070b35e6e2308fef83fc18d. The RTX 5090 machine (NVIDIA GeForce RTX 5090, 595.99.02, 12.0) ran the gather, link and window tests at a6de7dcb; the head adds the output overlap check and makes the window test's stream through capsync::fresh_stream, and a DGX Spark ran the changed tests at it. The DGX Spark runs (NVIDIA GB10, 595.84, 12.1) were made at earlier commits named in each line: since then the gather's wire layout, posts and waits are unchanged, and the head adds the overflow checks, the window release, the shared submission loop and the record. The link_probe digests quoted below come from those commits, before the digest moved to Fnv1a64, so this head prints other digest values for the same sums.

The reference for every sum is the host's rank-order sum of the same parts, compared bit for bit:

Check Reference Result
Loopback, host cards, 2, 3 and 4 ranks, 400 gathers each host rank-order sum test host::link::gather::tests::every_rank_adds_every_part_in_rank_order ... ok
Card test on a GB10 (at 46cee04f), 2, 3 and 4 ranks, a captured chain of four gathers replayed 200 times host rank-order sum test host::link::gather::tests::hw_held_every_rank_adds_the_parts_in_rank_order_on_the_card ... ok
link_probe --gather 4, two ranks on one DGX Spark, 200 replays (at 88c48909) host sum, and each rank's digest against the other's rank 0 and rank 1 both stale_words=0 host_wrong=0 digest=0xcbfe869afdd52ac0
link_probe --gather 1, two DGX Spark nodes on a direct 200 Gb/s link, 10,000 replays (at 88c48909) host sum, and each rank's digest against the other's rank 0 and rank 1 both stale_words=0 host_wrong=0 digest=0x0ffeadeb885668c8
link_probe --gather 4, two DGX Spark nodes on a direct 200 Gb/s link, 10,000 replays (at 88c48909) host sum, and each rank's digest against the other's rank 0 and rank 1 both stale_words=0 host_wrong=0 digest=0xf7ba6934cf33e11e
link_probe --gather 512, two DGX Spark nodes on a direct 200 Gb/s link, 10,000 replays (at 88c48909) host sum, and each rank's digest against the other's rank 0 and rank 1 both stale_words=0 host_wrong=0 digest=0x9b447b0f6b87afc6

Difference from the reference: in every link_probe run above, every rank has 0 stale words and 0 host disagreements, and the ranks' digests are equal.

  • On the RTX 5090 machine at the head, RUST_TEST_THREADS=1 bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- --include-ignored host::link:: ran the gather and link tests, the card test among them: test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 278 filtered out. test tensor::tests::hw_a_raw_window_releases_its_context_handle ... ok, and the link_probe build after them ended rc tests=0 probe=0.
  • On a DGX Spark (NVIDIA GB10), bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- --include-ignored --test-threads 1 hw_held_every_rank_adds_the_parts hw_a_raw_window_releases every_rank_lays_out at the head's tree: test result: ok. 3 passed; 0 failed. Output overlap, with the test's assertion and enqueue_sum unchanged: 2 ranks: a sum into a part is refused, then test result: FAILED. 1 passed; 1 failed.
  • Page overflow, with Gathers::new's products unchecked as before the fix (at 46e30f60, whose constructor is the head's): pages past usize taken, (bytes, ranks): [(0, 9223372036854775808), (0, 4294967297), (64, 9223372036854775808), (64, 4294967297)], then test result: FAILED. 0 passed; 1 failed. With the checks, the layout test passes in the 18 above.
  • Window release, with the test's window made by window as before the fix: assertion left == right failed: the window's context handle released with left: 4 and right: 3. With WindowMut::from_raw the test passes, as above.
  • Late-reader test with Gathers::SETS set to 1 (pub const SETS: usize = 1;), on an RTX 5090 machine at 3c7051dd: 2 ranks, the last one late: wrong values per rank [Ok(0), Ok(4536)], then test result: FAILED. 0 passed; 1 failed. With the PR's two sets, test host::link::gather::tests::a_late_rank_adds_the_parts_of_its_own_gather ... ok.
  • On a DGX Spark with BLOOMERY_ARCH=sm_121 (at 46cee04f), RUST_TEST_THREADS=1 bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- --include-ignored link::gather ran the four gather tests (both loopback tests, the page layout test and the card test): test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 290 filtered out. The layout test also checks that a page with no slot is link_tail(bytes, 0). The link_probe build for sm_121 after it ended rc gather=0 probe=0.
  • link_probe at 88c48909, both ranks as two processes on one DGX Spark over one RDMA port (commands below). The --size 4096 --iters 2000 --warmup 100 run printed PASS: link_probe stale lines after the counter 0, and the --gather 4 --iters 200 --warmup 10 run printed PASS: link_probe gather stale words and host disagreements 0, digests equal on every node true, with rc0=0 rc1=0 for each. The two ranks shared one card, so this run's times are not quoted.
  • On two DGX Spark nodes on a direct 200 Gb/s link, at 88c48909, link_probe --gather ROWS --iters 10000 --warmup 100 at 1, 4 and 512 rows. Rank 0 printed PASS: link_probe gather stale words and host disagreements 0, digests equal on every node true after each run, and both ranks ended rc=0. Each node's line carries its stale words, its host check, its digest and lambda_g at p50 and p99:
    • 1 row: link gather rank=0 nodes=2 rows=1 gathers=91 iters=10000 lambda_us_p50=16.45 lambda_us_p90=18.11 lambda_us_p99=28.51 lambda_us_max=269.79 chain_us_p50=1489.57 chain_us_p90=1501.47 chain_us_p99=1548.29 stale_words=0 host_wrong=0 digest=0x0ffeadeb885668c8 and link gather rank=1 nodes=2 rows=1 gathers=91 iters=10000 lambda_us_p50=16.58 lambda_us_p90=18.21 lambda_us_p99=28.61 lambda_us_max=265.50 chain_us_p50=1498.37 chain_us_p90=1510.43 chain_us_p99=1555.90 stale_words=0 host_wrong=0 digest=0x0ffeadeb885668c8
    • 4 rows: link gather rank=0 nodes=2 rows=4 gathers=91 iters=10000 lambda_us_p50=17.54 lambda_us_p90=17.86 lambda_us_p99=28.22 lambda_us_max=275.42 chain_us_p50=1562.30 chain_us_p90=1606.66 chain_us_p99=1720.67 stale_words=0 host_wrong=0 digest=0xf7ba6934cf33e11e and link gather rank=1 nodes=2 rows=4 gathers=91 iters=10000 lambda_us_p50=17.79 lambda_us_p90=17.98 lambda_us_p99=28.35 lambda_us_max=273.82 chain_us_p50=1576.99 chain_us_p90=1621.86 chain_us_p99=1737.25 stale_words=0 host_wrong=0 digest=0xf7ba6934cf33e11e
    • 512 rows: link gather rank=0 nodes=2 rows=512 gathers=91 iters=10000 lambda_us_p50=643.62 lambda_us_p90=644.83 lambda_us_p99=651.07 lambda_us_max=1151.68 chain_us_p50=57764.29 chain_us_p90=57827.90 chain_us_p99=58770.43 stale_words=0 host_wrong=0 digest=0x9b447b0f6b87afc6 and link gather rank=1 nodes=2 rows=512 gathers=91 iters=10000 lambda_us_p50=657.28 lambda_us_p90=669.06 lambda_us_p99=680.67 lambda_us_max=1123.65 chain_us_p50=59446.53 chain_us_p90=59537.86 chain_us_p99=60391.14 stale_words=0 host_wrong=0 digest=0x9b447b0f6b87afc6
    • At 1 row, rank 0's lambda_g is 16.45 µs at p50 and 28.51 µs at p99. At 512 rows it is 643.62 µs at p50 and 651.07 µs at p99.
  • On the same two nodes, link_probe --size 4096 --iters 2000 --warmup 100 printed PASS: link_probe stale lines after the counter 0, with a one way p50 of 6.78 µs (one_way_us_p50=6.78). The nodes ran no other job during these runs. The times come from the probe itself, with no separate timing run.
  • I did not run the two node GLM path (gate_glm5next_nodes) for this PR. The PR does not change that path's code: the diff touches only link_probe.rs, record.rs, gather.rs, link.rs, host/mod.rs, tensor.rs, the test module's visibility in pump.rs, tools/spawn-allow.txt and tools/unsafe-ratchet.txt, and leaves gate_glm5next_nodes.rs, tier_server.rs and rdma.rs as they are on main.
  • just contrib-check --tier t0 on this head, on a Linux x86_64 machine: DONE tier=t0 total=94 red=0.

The one-machine link_probe run, on a DGX Spark with an RDMA port rocep1s0f0 and GID index 3:

cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gpu --release --bin link_probe
target/release/link_probe --nodes 2 --rank 0 --dev rocep1s0f0 --gid 3 --listen 127.0.0.1:47312 --gather 4 --iters 200 --warmup 10 &
sleep 2
target/release/link_probe --nodes 2 --rank 1 --dev rocep1s0f0 --gid 3 --stage 127.0.0.1:47312 --gather 4 --iters 200 --warmup 10

On two nodes, rank 1 takes --stage <rank 0's address>:<port> and rank 0 takes --listen on that address, each with its own --dev.

What I ran into

None of this blocks the PR. Nothing outside the change came up in these runs.

Hardware (if the change is for a machine)

The change is for two or more DGX Sparks joined by their direct link. The GB10 runs were on a DGX Spark in the CUDA 13.3.1 container with BLOOMERY_ARCH=sm_121. The late-reader and card tests also ran on an RTX 5090 machine.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 19, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: MUST_FIX: the new test bypasses capture synchronization, and a permitted output alias corrupts the gather sum.

Must fix

1. Create the test's first stream through capsync

crates/gpu/src/tensor.rs:842 The normal gate-gpu-lib pass (justfile:1756) runs this test alongside graph-capture tests, including graph.rs:1481. Between fresh_context returning and new_stream, another thread can start a capture. The first stream then runs an unguarded context-wide synchronize and invalidates that capture, as documented in capsync.rs:124–130. capsync::fresh_stream holds the exclusive lock across both operations.
This is a one-call fix before the hardware gate gains an intermittent failure. Replace the two initialization lines with:

let (ctx, stream) = crate::capsync::fresh_stream(0).expect("CUDA device 0 with a stream");

2. Reject output windows that overlap gather storage

crates/gpu/src/host/link/gather.rs:337 The safety contract at lines 303–306 requires a live mapped page but permits y to overlap its parts. With three ranks, one value per part [1, 4, 8], and all accesses ordered on the same stream, a WindowMut::from_raw output over part 2 satisfies the contracts. The first add overwrites 8 with 5; the next add reads that overwritten part and returns 10 instead of 13.
Reject overlap in this owner to prevent silent wrong sums. After let n = rows * s.shape.width;, insert:

let out = y.cu_deviceptr();
let out_end = out + (n * 4) as u64;
let first = dev + self.slots[0].parts as u64;
let end = dev + self.page_bytes() as u64;
if out < end && first < out_end {
    return Err(GpuError::shape(
        "Gathers::enqueue_sum",
        "output overlaps gather parts, counters or link tail",
    ));
}

This preserves output in the page's reserved prefix. Extend the existing device test to assert that an output window over a part is refused.

Checked

Duplicates: diagnostics report 0 dryer pairs in gpu; gpu-gates was excluded.
Complexity: diagnostics report gather_run new at 47 and opts rising 31→35.
Silent failure: enqueue_sum rejects empty/excess rows and short outputs, but accepts the overlapping output above.
Tests: the device sum test uses separate output buffers and misses overlap. The window test asserts context-handle release; its stream creation bypasses capture synchronization.
Gates: unsafe ratchet increases have dated PIN reasons. The PR body reports FAIL-first results for layout overflow, one-set reuse and window release.
Escape catalog: no shell-script changes match C1–C4.

Notes

CUDA tests were not rerun. The reported hardware runs use one test thread, which excludes finding 1's interleaving.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/link_probe.rs, crates/gpu-gates/src/record.rs, crates/gpu/src/host/link.rs … and carries a gate run on the author's card, which counts as verified.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Comment thread crates/gpu/src/tensor.rs Outdated
Comment on lines +842 to +843
let ctx = crate::capsync::fresh_context(0).expect("CUDA device 0");
let stream = ctx.new_stream().expect("a stream");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Create the fresh handle and its first stream under capsync's exclusive lock so this test cannot invalidate another thread's capture.

Suggested change
let ctx = crate::capsync::fresh_context(0).expect("CUDA device 0");
let stream = ctx.new_stream().expect("a stream");
let (ctx, stream) = crate::capsync::fresh_stream(0).expect("CUDA device 0 with a stream");

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 19, 2026
…pages

Gathers lays out every rank's page alike: past the page's own bytes, each gather slot holds two span sets of one
part per rank and one counter per set and rank, then the link's tail with a block of lines for every pair of ranks.
A part crosses each pair's link as a done of the tier protocol does, through the existing ends and pump: the writer
posts its part with one more generation, the reader's end adds one to the part's counter on its page, and the
card's captured wait takes it back. post and wait give the stream memory operations of a gather and enqueue_sum adds
every rank's part in rank order, so every rank holds the same bits. Its windows over the page come from
WindowMut::from_raw, which drops their context handle with them. Between two uses of one set the ranks run
another gather, so stream order alone keeps a part until every rank has added it. No slot leaves the page and the
tier link as they were; nothing else opens a gather yet.

Tests at 2, 3 and 4 ranks: host cards over the loopback add the host's rank-order sum, a late rank still adds its
own gather's parts while the next gather lands, every rank lays out the same page, and on a card captured chains of
four gathers replayed 200 times sum bit-equal to the host.
… nodes

Each node holds an end to every other node; the stage passes the peers' endpoints between them, and the ready
barrier now waits for every peer before any starts. One replay is a captured chain of 45 layers' two gathers of
ROWS rows of 4096 f32 and the head's gather of two words a row. Each node counts stale words in the parts it
waited for, checks its last replay's sums against the host's rank-order sum and prints lambda_g per gather and
summed over a chain as a link_gather record; the stage fails on a stale word, a host disagreement or a digest of
the sums that differs between nodes. The stall report, the bounded wait and the release on failure move to one Node
both modes use, and both modes enqueue at most AHEAD steps ahead of the host through one replays loop.
@juliankang4
juliankang4 force-pushed the dgx-spark-link-gather branch from a6de7dc to 6476ccd Compare October 19, 2026 17:04

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the last review:

  • Fixed 1: tensor.rs:842 creates the context and first stream under the capture lock.
  • Fixed 2: gather.rs:334 rejects output overlapping any slot, counter or tail before launching.

Verdict: CLEAN: Both previous must-fix items are fixed, and the interdiff adds no blocking defect.

Checked

Duplicates: 0 new definitions in the interdiff; dryer reports 0 candidate pairs in gpu.
Complexity: crapper flags new orchestration gather_run at 47 and option branches in opts at 31→35; both are unchanged in this interdiff.
Silent failure: 1 added rejection followed; overlapping output returns a named shape error before any launch.
Tests: removing the guard at gather.rs:334 makes the assertion at gather.rs:625 fail. Replacing the raw window with the old constructor fails the context-count assertion at tensor.rs:850. The PR supplies FAIL-first output for both.
Gates: the unsafe ratchet increase covers two added test blocks with a dated PIN and reason; no tolerance changed.
Bounds: output ending at the first part stays allowed; partial overlap, later slots and the tail are rejected. Constructor checks bound the byte products.
Escape catalog: no changes match C1–C4.

Notes

CUDA tests were not rerun during this review. Dryer excluded gpu-gates; that crate is unchanged in the interdiff.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/link_probe.rs, crates/gpu-gates/src/record.rs, crates/gpu/src/host/link.rs … and carries a gate run on the author's card, which counts as verified.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app gpu-evidence Verified on the author's card: the pull request carries the gate run and its output

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant