Skip to content

xpu: shared TP events use device scope, as their comment says - #3980

Merged
ashhart merged 3 commits into
ashhart:mainfrom
SergiioB:xpu-shared-events-device-scope
Nov 20, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
SergiioB:xpu-shared-events-device-scope

Conversation

@SergiioB

@SergiioB SergiioB commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Gpu.sharedEvents (zig/src/xpu/ze.zig:365-366, from #3585) creates the cross-card TP events with
.signal = 1, .wait = 1, and its comment calls that DEVICE. In Level Zero 1 is ZE_EVENT_SCOPE_FLAG_SUBDEVICE;
DEVICE is 2. The header gives SUBDEVICE cache flushes "sufficient for local sub-device access" and DEVICE
"sufficient for global device access and peer device access". Every rank waits on events the other ranks signal
(tp.zig:130 signals, tp.zig:147 waits on all ranks), so 2 is the scope the comment describes. This sets
.signal = 2, .wait = 2 and corrects the comment: 2 lines. No output was ever seen wrong; this is about what the
scope promises, not a failure we reproduced.

Checks on this head

  • Head commit: 94b7fe63a (the change is e56669f14; 94b7fe63a adds the CHANGELOG bullet)
  • Lean checker, python3 tools/zig/lean_check.py (this head's checker on both trees, then tools/zig/lean_new.py):
    189 on 6e7f3083b, 189 on 369c64469, 0 new (inherited), run before the last rebase. On this head,
    python3 tools/pr_check.py --base 905ce9b11 --pr 3980: lean 189 vs 189, 0 new, 0 errors, 0 warnings.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build xpu-tp-bench then ./zig-out/bin/tf-xpu-tp-bench (no arguments; the binary runs TP=2 then TP=4),
      from main 517a44563 and from this change as 1614c927a, 3 runs each in the order main, change, change, main,
      main, change: 6 passed, 0 failed, 6 skipped (skipped TP=4: NoDevice), 0 mismatches. The bit-exactness check
      covers 1-shot 32 KB and 2-shot 10 MB against the rank-ordered FP32 reference.
    • git diff --check 905ce9b11..HEAD passes on this head; zig fmt --check build.zig zig passed on 369c64469,
      which has the same ze.zig.
  • CI: not run yet (fork branch only).
  • Not run, and why: TP 4 (two cards here; the bench prints skipped TP=4: NoDevice); the served engine, because on
    main only tf-xpu-tp-bench reaches TpComm (xpu(qwen27): serve Qwen3.8-27B across TP={1, 2, 4} with DFlash2 #3586 and xpu(flashnext): serve Qwen3.8 Flash Next (qwen4_exp) at TP={1, 2, 4} with host-RAM PLE and MTP #3587 add the serving callers); no bench run on
    this head, whose two changed lines differ from 1614c927a only in the comment's wording.

Receipt

  • Main against branch: tf-xpu-tp-bench, two Intel Arc Pro B70 (BMG-G31, 32 GB), PCIe 4.0 x8 each from a Ryzen 7
    5700X3D on an X570 board, both capped at 230 W / 2,800 MHz, card temperatures 47-63 °C at the start of each run,
    compute-runtime 26.05.37020.3, Zig 0.17.0, ocloc 26.05.1. Best of each run, µs per all-reduce:
Op (bytes) main 517a44563, 3 runs this change 1614c927a, 3 runs
decode 1 row (10 KB) 8.09, 7.89, 7.86 8.09, 7.76, 8.39
verify 8 rows (80 KB) 12.30, 12.30, 12.28 12.31, 12.32, 12.29
tree 16 rows (160 KB) 20.08, 20.13, 20.05 20.05, 20.08, 20.08
prefill 512 rows (5.0 MB) 520.58, 520.29, 520.09 519.47, 520.94, 520.59
prefill 1024 rows (10 MB) 1028.86, 1028.33, 1028.16 1026.55, 1028.79, 1028.55
prefill 4096 rows (40 MB) 4120.59, 4118.95, 4118.08 4113.51, 4122.57, 4121.00

The two columns overlap at every size. A standalone Level Zero chain (each rank's kernel waits on the other
rank's event and then reads the peer's buffer; 25 timed repeats after one discarded, 0 errors) shows no consistent
scope cost at the medians. In the replay cells, scope 1 and scope 4 (HOST) differ by at most 0.02 µs per step at
10,240, 40,960 and 163,840 bytes (6.71/6.71, 9.68/9.70, 21.53/21.53 µs). The immediate cells agree within
0.04 µs at 40,960 and 163,840 bytes (11.11/11.09, 22.67/22.63); one 10,240-byte immediate cell reads 11.43 vs
13.06 µs at the medians, with minima of 11.18 vs 11.11 µs. We did not time ZE_EVENT_SCOPE_FLAG_DEVICE on its
own in that chain, and we have not run the engine with the scope changed; the table above times the change in
the collective only.

  • Boxes it reaches: XPU tensor parallelism only (TpComm.init → sharedEvents, tp.zig:69). TP=1 returns before
    the call (tp.zig:39), so one-card runs never create these events. The host never synchronizes them: it
    host-synchronizes the lists and then resets them (tp.zig:101), so HOST scope is not required.
  • New switch? No.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: base
    905ce9b11 (receipt on 517a44563), head 94b7fe63a (receipt on 1614c927a), Zig 0.17.0, compute-runtime
    26.05.37020.3, IGC 2.28.4, Level Zero loader 1.28.2, ocloc 26.05.1, Ubuntu 26.04 (kernel 7.0.0-28),
    Ryzen 7 5700X3D (X570 board), 60 GiB RAM, 2× Intel Arc Pro B70 (BMG-G31, 32 GB, PCIe 4.0 x8), both capped at
    230 W / 2,800 MHz. Checkpoint: n/a (the bench loads no model). One local build change on both sides, not in this
    pull request: -cl-intel-128-GRF-per-thread dropped from the Gemma 4 prompt-rows kernel options in
    zig/build/xpu.zig, which our ocloc 26.05.1 rejects.
  • Paths and platforms: sharedEvents, called once by TpComm.init. Ran: TP 2 on two B70. Not run: TP 4, other Intel
    GPUs.
  • Exactness: the bench's bit-exactness check, 6 of 6 passed, 0 mismatches. No served tokens on main to compare.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines: the table
    above; no run on your machines is requested.
  • Decode speed before and after: the table (collective level); engine decode not reachable on main.
  • Prompt speed before and after: n/a, same reason.
  • Licence of any new weights or drafter: n/a.

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. No new test: the
    constant is not observable in output, and tf-xpu-tp-bench's bit-exactness check passes on both sides.
  • 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.

How to revert: revert the merge (or the squashed commit); the code change is git revert e56669f14.

SergiioB added a commit to SergiioB/TensorFold that referenced this pull request Nov 19, 2026
@SergiioB
SergiioB force-pushed the xpu-shared-events-device-scope branch from 644da4d to 94b7fe6 Compare November 19, 2026 14:42
SergiioB added a commit to SergiioB/TensorFold that referenced this pull request Nov 19, 2026
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @SergiioB. The two lines read right: scope 2 is what the Level Zero header promises for peer-device access, and that is what the cross-rank waits need; the comment now matches the code, and your bench and collective runs cover it.

One thing is open: we have not seen the checks on this head yet. Please let them run and post the result. The only file that needs a touch at merge time is the changelog hunk, the usual Unreleased rebase.

We were unable to run any XPU cell on our side, so your posted runs stand as the device evidence.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged 94b7fe63 into 767d3d75. The only conflict was CHANGELOG.md. On M5 Max with Zig 0.17.0, this passed 23 host tests and the Linux compile target:

zig build test-flashnext-xpu-host test-draft-xpu-host test-xpu-refusal-host \
  compile-xpu-qwen27-tail-linux -Dcpu=apple_m1 -j5 --summary all

I also ran zig test zig/src/xpu/ze.zig -lc with a scratch recording fixture in the same module. It calls the real Gpu.sharedEvents and observes a pool for two devices and three descriptors, each with signal and wait equal to 1 << 1. Both tests passed. That is the device scope value in the Level Zero header. This checks the descriptors at the API boundary. The peer-card behavior is covered by the existing device receipt.

Igor Lessio - AIFLOW LABS

SergiioB and others added 3 commits November 20, 2026 20:48
sharedEvents created its events with signal = wait = 1, which is
ZE_EVENT_SCOPE_FLAG_SUBDEVICE, while the comment says DEVICE. Every rank
waits on events another card signals, and only DEVICE scope (2) promises
cache flushes "sufficient for global device access and peer device access".
@ashhart
ashhart force-pushed the xpu-shared-events-device-scope branch from 94b7fe6 to 4ff2363 Compare November 20, 2026 20:48
@ashhart
ashhart merged commit 14ba57c into ashhart:main Nov 20, 2026
3 of 11 checks passed
ashhart pushed a commit that referenced this pull request Nov 20, 2026
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @SergiioB. 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.

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