Skip to content

xpu: add Level Zero multi-GPU P2P AllReduce collectives and tf-xpu-tp-bench - #3585

Merged
ashhart merged 3 commits into
ashhart:mainfrom
supernovae:xpu-tp-collectives
Nov 19, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
supernovae:xpu-tp-collectives

Conversation

@supernovae

@supernovae supernovae commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Before: zig/src/xpu/ze.zig opened a single Level Zero device per context with no cross-GPU peer residency or collective primitives. After: ze.zig opens TP={1, 2, 4} peer devices in one shared Level Zero context (openPeers, closePeers, makeResident, sharedEvents), and tp.zig + tp.cl provide deterministic rank-ordered FP32 P2P AllReduce (1-shot direct P2P <= 512 KiB and 2-shot P2P ReduceScatter + DMA AllGather > 512 KiB) with tf-xpu-tp-bench.

Checks on this head

  • Head commit: 2dcfc70802464f746342cbe2bc8bdc603e23dbf1
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 on base (6bc82ac) — inherited, 221 on head (2dcfc70), 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig: passes
    • git diff --check: passes
    • python3 tools/pr_check.py --base origin/main: 0 errors
    • zig build xpu-tp-bench -Doptimize=ReleaseFast -Dngen-include=<ngen> + ./zig-out/bin/tf-xpu-tp-bench: passes bit-exact rank-ordered FP32 check on 2× and 4× Arc Pro B70 (0 diff on 1-shot 32 KiB and 2-shot 40 MiB paths)
    • zig build -Dxpu-contract=true xpu-kernel-contract-limits xpu-contract-run: 9/9 pass gates 1–4, 0 fail, 5/5 controls red, 0 limit problems
    • umask 0022 && zig build -Dfixed-cpu test --test-timeout 20m: 696/696 steps succeeded (0 failed)
    • zig build -Dfixed-cpu test-kernel-contract test-golden test-gradient-serving test-qwen-serving-host test-server-security test-pull-security fuzz-cortheon: 62/62 steps succeeded; 317/317 tests passed
  • CI: pending on this push.
  • Not run, and why: Metal (M1–M5), CUDA (sm_*), HIP (gfx*), and Windows GPU checks (Linux 4× Intel Arc Pro B70 host only).

Receipt

  • Main against branch: n/a for model inference on this slice alone (ze.zig single-device open is unchanged; openPeers and TpComm are only called by tf-xpu-tp-bench in slice 1 and wired into qwen27 / flashnext in slices 2 and 3). Microbenchmark receipt on 4× Intel Arc Pro B70 (0xe223, PCIe Gen5 P2P):
    • TP=2: 3.81 µs/op (1-row 20 KiB FP32), 9.22 µs/op (16-row 320 KiB FP32), 34.89 GB/s (4,096-row 40 MiB FP32); bit-exact (0 diff) vs rank-ordered FP32 host reference.
    • TP=4: 8.50 µs/op (1-row 20 KiB FP32, 1.09 ms per 128-op token), 23.07 µs/op (16-row 320 KiB FP32), 26.89 GB/s busbw (17.92 GB/s algbw, 40 MiB FP32); bit-exact (0 diff) vs rank-ordered FP32 host reference.
  • Boxes it reaches: tf-xpu-tp-bench only in slice 1 (zig/src/xpu/ze.zig, zig/src/xpu/tp.zig, zig/kernels/xpu/tp.cl).
  • New switch? Default, accepted values, profile row: none in slice 1.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: base 6bc82acac41737e7159f2b597b562d12bf437291, head 2dcfc70802464f746342cbe2bc8bdc603e23dbf1, Zig 0.17.0, ocloc 26.27.039122 (-device bmg), Linux 7.3.0-10-generic x86_64, AMD EPYC Turin (DDR5 RAM), 4× Intel Arc Pro B70 (0xe223, 32 GB GDDR6 each, 230 W). Checkpoint: n/a in slice 1.
  • Paths and platforms the change reaches, which I ran and which I could not: ran Linux x86_64 host suite and Intel Xe2 (bmg-g31, 0xe223) 1/2/4-GPU Level Zero tests; could not run macOS Metal, CUDA, ROCm HIP, or Windows GPU.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: tf-xpu-tp-bench verifies bit-for-bit equality (0 ULP difference) against strict rank-ordered (0 -> 1 -> ... -> tp-1) FP32 host reduction (#pragma OPENCL FP_CONTRACT OFF); end-to-end served --alone --serial receipts are in slices 2 and 3.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): posted in slice 2 (Qwen3.8-27B TP=1 matches main token-for-token at 34.1 vs 34.1 tok/s plain decode and 2,051 vs 2,044 tok/s prefill).
  • Decode speed before and after, from tools/bench_openai.py: n/a in slice 1 (see slices 2 and 3).
  • Prompt speed before and after: n/a in slice 1 (see slices 2 and 3).
  • Licence of any new weights or drafter, or "n/a": n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: New collective image zig/kernels/xpu/tp.cl (tp2_allreduce_f16, tp4_allreduce_f16, tp2_rs_f16, tp4_rs_f16, tp2_allreduce_bf16, tp4_allreduce_bf16, tp2_allreduce_f32, tp4_allreduce_f32, tp4_rs_f32; replaces none; WG=256, subgroup=16, 0 SLM, 0 spills). Note: zig/src/core/contract/xpu_records.zig currently covers single-device glue kernels only; multi-device P2P collectives require openPeers across >= 2 GPUs and are verified in tf-xpu-tp-bench (agreed XPU contract scope requested in XPU (Arc Pro B70): Level Zero P2P tensor parallelism (TP=2, 4) for Qwen3.8-27B and Qwen3.8 Flash Next (qwen4_exp) #3583).
  • A planted control for each new kernel, and each one fails as planted: Existing XPU contract controls (5/5 gates 1–4 controls + 6/6 limit controls) run and fail red as planted; tf-xpu-tp-bench checks bit-exact FP32 rank-order sums across all elements.
  • Each backend's SUMMARY line and exit status:
    • xpu-contract-run (exit 0): SUMMARY bmg-g31 0xe223 9 kernels: 9 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 5558 ms, limits 1 ms
  • Chips I could not run: Apple M1–M5, NVIDIA sm_80/86/89/120/121, AMD gfx1030/1100/1151/1201.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @supernovae. The shared Level Zero peer context and the rank-ordered FP32 reductions with contraction off look right, and 0 ULP across 2 and 4 B70s is the evidence we asked for.

On your question: yes, please register the tp.cl collectives in xpu_records.zig with the kernel contract's gates and planted controls, as #3583 asked. The changelog line and the small zig/build/xpu.zig offset are ours.

  • Synthena

@munikor

munikor commented Nov 17, 2026

Copy link
Copy Markdown

Thanks for this stack — the shared-context design and the 0-ULP receipts look great. I tried to run TP=2 on a 2×B70 box and hit a hard topology wall that I think affects most consumer dual-card rigs, so I wanted to raise it before testing further.

Setup: ASUS ProArt Z890-Creator WiFi (Arrow Lake-S, LGA1851), 2× Arc Pro B70 (0xE223), both cards in the two CPU-attached x16 slots (BIOS x8/x8 bifurcation on the CPU slot), Ubuntu 26.04.1, kernel 7.0.0-43, staged compute-runtime 26.40 + IGC 2.42.6 + L0 loader 1.21.9.

Topology (lspci -t): the CPU presents the two x8 segments as two sibling root ports, not one bridge with two children:

00:06.0-[02-05]--+-01.0-[04]----00.0   ← B70 #1 (04:00.0)
                 \-02.0-[05]----00.0
00:06.3-[06-09]--+-01.0-[08]----00.0   ← B70 #2 (08:00.0)
                 \-02.0-[09]----00.0

Result: zeDeviceCanAccessPeer returns can=0 in both directions, so ze.Gpu.openPeers refuses with ZeFailed before any allocation. dmesg carries the exact reason:

xe 0000:04:00.0: cannot be used for peer-to-peer DMA as the client and provider
(0000:08:00.0) do not share an upstream bridge or whitelisted host bridge

Both cards work individually (26.40 driver exposes both; XMX bench hits full rate on each), so this is purely the cross-root-port P2P policy in xe on consumer silicon — I understand the same wall is what oneCCL's CCL_TOPO_P2P_ACCESS=0 host-staged fallback path exists for in the vLLM/oneCCL stack, which does run TP=2 on this exact box.

Question: would you consider a fallback in tp.zig/openPeers when zeDeviceCanAccessPeer returns 0 — host-staged collectives (rank writes to a host-pinned buffer, peers copy from it, or a shared-context host allocation both ranks touch), selected at open time so the P2P path stays the default when it's available? The rank-ordered determinism you built should survive it since the reduction order is host-side, and it would make TP={2,4} usable on the (large) population of consumer dual-B70 boxes that can't pass the peer check. Happy to test any branch on this box — it's otherwise idle and reproducible (tf-xpu-tp-bench currently prints skipped TP=2: ZeFailed here).

@supernovae

Copy link
Copy Markdown
Contributor Author

@ashhart Registered all 9 tp.cl collectives (tp2_allreduce_f16, tp4_allreduce_f16, tp2_rs_f16, tp4_rs_f16, tp2_allreduce_bf16, tp4_allreduce_bf16, tp2_allreduce_f32, tp4_allreduce_f32, tp4_rs_f32) in zig/src/core/contract/xpu_records.zig, zig/build/xpu_contract.zig, and zig/tests/xpu/contract_tp.zig (contract_rig.zig / contract_live.zig / contract_run.zig).

Verification on amended commit a56fcb114:

  • zig build -Dxpu-contract=true xpu-kernel-contract-limits xpu-contract-run -Docloc=ocloc -Dxpu-device=bmg:
    SUMMARY bmg-g31 0xe223 18 kernels: 18 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 5086 ms, limits 0 ms
    
  • zig build test-kernel-contract: 244/244 tests passed (34/34 steps).
  • python3 tools/pr_check.py --base origin/main --pr 3585: 0 error(s), lean 221 vs 221, 0 new.

@munikor Thanks for testing and sharing that clean lspci -t / dmesg topology isolation! We're keeping #3585 scoped to P2P collectives and contract registration as reviewed, and will track a host-staged collective fallback (gated on zeDeviceCanAccessPeer == 0 while keeping rank-ordered FP32 reductions) as a clean follow-up PR so consumer cross-root-port dual/quad-B70 rigs work out of the box.

@supernovae
supernovae force-pushed the xpu-tp-collectives branch 2 times, most recently from a56fcb1 to aff61d1 Compare November 18, 2026 02:05
@supernovae
supernovae marked this pull request as ready for review November 18, 2026 02:06
@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thank you @supernovae. All nine tp.cl collectives are registered with launch records and planted controls, and your bmg-g31 summary shows every kernel passing gates 1-4 with every control red as planted. The contract suite and pr_check are green.

We agree with keeping this PR scoped to P2P collectives. The host-staged fallback for consumer cross-root-port boxes belongs in a separate change.

This is ready to land.

  • Synthena

@ashhart
ashhart merged commit 3e3344c into ashhart:main Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @supernovae. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to AIflow-Labs/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit that referenced this pull request Nov 19, 2026
ashhart added a commit to ultradaoto/TensorFold that referenced this pull request Nov 19, 2026
ashhart added a commit that referenced this pull request Nov 19, 2026
@supernovae
supernovae deleted the xpu-tp-collectives branch November 22, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants