Skip to content

contract: an XPU limits backend (gate 5, the .ze_info reader, planted controls) - #2155

Merged
ashhart merged 3 commits into
ashhart:mainfrom
tolewis:xpu-contract-limits
Nov 6, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
tolewis:xpu-contract-limits

Conversation

@tolewis

@tolewis tolewis commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

What this changes

XPU kernels can now register with the kernel contract, and gate 5 (launch limits) checks them with no GPU. This PR adds an XPU launch record, a BMG-G31 (Arc Pro B70) device row, a reader for the .ze_info section of an ocloc zebin, gate 5 with planted controls, and xpu-kernel-contract-limits. The Level Zero runner with gates 1 to 4 is the second PR.

  • Issue: Refs XPU backend in core/contract: kernel gates and launch limits for Intel GPUs #2080 (PR 1 of the two agreed there).
  • Stacked on: main (9d6f1d78).
  • atc overlap --json: not run, because the CLI needs gh auth that I do not use here. By hand: 40 open pull requests change docs/kernel-contract.md, zig/src/core/contract.zig or zig/build/xpu.zig. I ran git merge-tree of each one against main and against this head. This head adds no conflicting file to any of them. Every conflict it has is one that the pull request already has with main. This head merges into current main cleanly.

As you asked on #2080, the audit checks each record's GRF mode against the zebin. ocloc writes grf_count for every kernel: 128 by default, and 256 with -cl-intel-256-GRF-per-thread. xpu_limits.grfBuilt fails a record whose mode is not that value, and also a kernel that has no grf_count. A record cannot claim 128 for an image built at 256.

File Lines Job
zig/src/core/contract/xpu_limits.zig 174 the BMG-G31 row, the launch and usage records, fits, stale, grfBuilt, xpu
zig/src/core/contract/xpu_records.zig 146 six Qwen3.8-27B glue registrations and six planted gate-5 controls
zig/src/core/contract/zebin.zig 70 the .ze_info section of a zebin ELF, and a fixture builder for the tests
zig/src/core/contract/zeinfo.zig 143 each kernel's work-group, SLM, sub-group, GRF, spill and private bytes from that section
zig/tests/xpu/contract_limits.zig 106 the records table and the limits DIR audit
zig/tests/xpu/contract_main.zig 30 tf-xpu-kernel-contract [limits DIR]
zig/build/xpu_contract.zig 44 tf-xpu-kernel-contract, xpu-kernel-contract-objects, xpu-kernel-contract-limits
zig/kernels/xpu/contract_controls.cl 24 the 160 KiB SLM, 1024-at-256-GRF, wide-group and sub-group 32 controls
zig/kernels/xpu/contract_controls_sg8.cl 5 the sub-group 8 control, which ocloc refuses for bmg
zig/src/core/contract.zig +11 exports and the host tests of the four modules
zig/build/xpu.zig +3 calls the contract steps behind -Dxpu-contract
docs/kernel-contract.md +15 the XPU record, the GRF check, the no-GPU audit and the registration step

The build wiring is in zig/build/xpu.zig, not build.zig. Zig 0.17 refuses a second b.option with the same name, and xpu.zig already declares ocloc and xpu-device.

The device row follows the card's own read: work-group 1024, work-item sizes 1024/1024/1024, SLM 131072 bytes a work-group, sub-groups 16 and 32, 8 EUs a Xe-core, 8 threads an EU. The limit of 512 work-items at 256 GRF comes from the compile (eu_thread_count: 4 at 256 GRF, 8 at 128) and from Intel's oneAPI GPU optimization guide, "Small Register Mode vs. Large Register Mode".

Checks on this head

  • Head commit: 3cbd915d
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 425 and 425, the same lines; 0 new findings.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-kernel-contract: 189 passed, 0 failed, 0 skipped.
    • zig build test: 6964 tests, 6904 passed, 1 failed, 59 skipped. The failure is the listener test that binds the IPv6 loopback, which this machine does not have. It also fails on main on the same machine.
    • zig fmt --check zig/: clean.
  • CI: not yet run on this head.
  • Not run, and why: gates 1 to 4 and a run on the card itself, because they are the Level Zero runner of PR 2.

Receipt

  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: 3cbd915d on main 9d6f1d78, Linux, Zig 0.17.0, ocloc 26.35.39758.10. ocloc runs on an Intel Arc Pro B70 host, as a CPU compile only. No checkpoint is needed.
  • Paths and platforms the change reaches, which I ran and which I could not: the contract only. No inference path changes, so no model ran. One host has ocloc and the other has Zig, so I compiled the zebins with the build step's own commands and ran tf-xpu-kernel-contract limits DIR on the Zig host.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a. No kernel, weight or inference path changes.
  • Decode speed before and after, from tools/bench_openai.py: n/a, for the same reason.
  • Prompt speed before and after: n/a, for the same reason.
  • Licence of any new weights or drafter, or "n/a": n/a.

The zebins, from the repository root of this head:

ocloc compile -q -file zig/kernels/xpu/qwen27/glue.cl -device bmg \
  -options "-cl-std=CL3.0 -cl-intel-256-GRF-per-thread -I zig/kernels/xpu/qwen27" \
  -output_no_suffix -output glue -out_dir <dir>/bmg
ocloc compile -q -file zig/kernels/xpu/contract_controls.cl -device bmg \
  -options "-cl-std=CL3.0 -cl-intel-256-GRF-per-thread" \
  -output_no_suffix -output contract_controls -out_dir <dir>/bmg
zig build -Dxpu-contract=true tf-xpu-kernel-contract
./zig-out/bin/tf-xpu-kernel-contract limits <dir>

On an Intel GPU host with both tools, zig build -Dxpu-contract=true xpu-kernel-contract-limits -Docloc=... -Dxpu-device=bmg does the same in one step.

tf-xpu-kernel-contract limits <dir>, exit 0 (the RECORD lines are left out):

PASS limits bmg-g31 add_rmsnorm: 128 work-items, 10272 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record current)
PASS limits bmg-g31 add_rmsnorm_dec: 512 work-items, 10368 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record current)
PASS limits bmg-g31 gated_norm: 256 work-items, 12288 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record current)
PASS limits bmg-g31 swiglu: 256 work-items, 2048 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record current)
PASS limits bmg-g31 argmax: 256 work-items, 2048 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record current)
PASS limits bmg-g31 embed: 256 work-items, 0 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record current)
RED  limits bmg-g31 control: 2048 work-items a work-group: ... 2048 work-items a work-group, the most is 1024
RED  limits bmg-g31 control: 200 work-items, not a multiple of sub-group 16: ... 200 work-items are not a multiple of sub-group 16
RED  limits bmg-g31 control: 160 KiB of SLM: ... 163840 SLM bytes a work-group, the most is 131072
RED  limits bmg-g31 control: 1024 work-items at 256 GRF: ... 1024 work-items at 256 GRF and sub-group 16, a Xe-core holds 512
RED  limits bmg-g31 control: sub-group 32 at 256 GRF: ... sub-group 32 at 256 GRF (the most is 16)
RED  limits bmg-g31 control: sub-group 8: declared only, ocloc does not build it for this device: ... sub-group 8, the device runs { 16, 32 }
PASS xpu-kernel-contract-limits: every registered launch fits bmg-g31, every record current, every control red

The GRF check, planted: I set the add_rmsnorm_dec record to 128 GRF, rebuilt, and ran the audit on the same zebins. Exit 1:

FAIL limits bmg-g31 add_rmsnorm_dec: 512 work-items, 10368 SLM bytes, sub-group 16, 256 GRF, 0 spill bytes, 0 private bytes (record stale): add_rmsnorm_dec on bmg-g31: the record says 128 GRF, the zebin was built at 256
FAIL xpu-kernel-contract-limits: 2 problems

The two problems are the GRF mode and the stored usage, which no longer matches the image. The host test a record cannot claim 128 GRF for a zebin built at 256 in zeinfo.zig does the same on fixture bytes, with no ocloc.

ocloc refuses to build the sub-group 8 control for bmg, so that record has compiled = false and the audit checks its declaration only:

[bmg] error: in kernel 'tf_ctl_subgroup8': Kernel compiled with required subgroup size 8, which is unsupported on this platform
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: add_rmsnorm, add_rmsnorm_dec, gated_norm, swiglu, argmax and embed from the Qwen3.8-27B glue image, for gate 5. None replaces a kernel. These kernels do not change.
  • A planted control for each new kernel, and each one fails as planted: one for each gate-5 rule: 2048 work-items a work-group, 200 work-items not a multiple of sub-group 16, 160 KiB of SLM, 1024 work-items at 256 GRF, sub-group 32 at 256 GRF, and sub-group 8. All six are red, above. A record with the wrong GRF mode fails, above.
  • Each backend's SUMMARY line and exit status: the runner and its SUMMARY line are PR 2. The limits audit ends PASS xpu-kernel-contract-limits: every registered launch fits bmg-g31, every record current, every control red, exit 0. The records-only run ends PASS xpu-kernel-contract: every registered XPU launch fits bmg-g31, every control red, exit 0.
  • Chips I could not run: any XPU chip other than BMG-G31. Gen12LP and Arc A-series need their own device rows.

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. (The host tests need no ocloc and no GPU.)
  • 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 4, 2026

Copy link
Copy Markdown
Owner

Thanks @tolewis. This is PR 1 as agreed on #2080, and the GRF check is exactly what we asked for: a record can't claim 128 GRF for a zebin built at 256, pinned by a host test and by your planted run. Keeping the steps behind -Dxpu-contract means no default build needs ocloc. Ready to land. PR 2, the Level Zero runner with gates 1 to 4, is next, and your B70 SUMMARY line will be its evidence.

@ashhart
ashhart force-pushed the xpu-contract-limits branch from 3cbd915 to 8ef0f6f Compare November 6, 2026 03:37
ashhart added a commit to tolewis/TensorFold that referenced this pull request Nov 6, 2026
tolewis and others added 3 commits November 6, 2026 04:16
An XPU launch record holds the symbol, image, work-group size, static SLM bytes,
sub-group size and GRF mode, with what ocloc made of it for the BMG-G31 card.
Gate 5 checks each launch against the card row, which follows the device's own
clinfo read, and refuses a stale record, from the zebin's .ze_info, so it runs
with no GPU. The six Qwen3.8-27B glue kernels register first, and six planted
controls must stay red, including sub-group 32 at 256 GRF and the sub-group 8
the device does not run. The device runner, gates 1 to 4, comes in a second
pull request.
@ashhart
ashhart force-pushed the xpu-contract-limits branch from 8ef0f6f to b5898b7 Compare November 6, 2026 04:16
@ashhart
ashhart merged commit 05e1cb3 into ashhart:main Nov 6, 2026
1 of 7 checks passed
@ashhart

ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

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

@tolewis
tolewis deleted the xpu-contract-limits branch November 6, 2026 18:15
@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

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.

2 participants