Repository navigation
Vulkan base: runtime and the Q4 projection registered in the kernel contract (opt-in) - #1526
Merged
Merged
Conversation
5 tasks
joshuaswarren
force-pushed
the
vulkan-base-pr
branch
2 times, most recently
from
October 28, 2026 16:18
518acc2 to
420127b
Compare
joshuaswarren
marked this pull request as ready for review
October 28, 2026 19:41
Contributor
Author
|
This is the smallest first PR, as you asked, now ready for review at head 17fa2cd. Every kernel in it is registered in your contract, and the contract runner passes gates 1 to 4 on M1, M1 Max and M2 Max with all 8 planted controls caught. The SUMMARY lines and the stderr sha256 of each run are in the description. PR-B (#1544) builds on this one and stays a draft until you are happy with this one. [Joshua agent] |
The Vulkan backend comes in on the same terms as HIP: every kernel registers with the kernel contract. This registers the one kernel the base PR holds, the affine Q4 group-64 projection (qmm_bf16: bf16 in and out, fp32 sums). contract_qmm.zig fills the shared contract.spec for it and gives the shared gates a Vulkan fixture (real dispatch through the runtime, staged upload and readback, poisoned guard words). Served shapes are the ones the Qwen3.5-2B engine calls it at: K 2048 and 6144, N from 16 up to the 248320-row head, one row for decode and 32 for a prefill chunk, plus small fixture shapes. Gate 4 keeps the harness default (fp16 and bf16 sums must miss by 100x). contract_controls.comp holds the planted controls, one per gate, each a kernel built to break its gate: a projection that drops NaN, an order-dependent atomic sum, a sum that writes into its input, a projection that loses its K tail, and one that sums in fp16. A run where a control passes is a failed run. Gate 5 needs per-chip limits: vulkan_records.zig declares each launch's workgroup size and shared bytes, limits.zig adds the Vulkan launch and limit types, and a host test refuses any chip whose limits are not measured, so no value is assumed. The runner prints every limit it reads from the live device (LIMITS lines) and checks the declared launches against them. tf-vulkan-kernel-contract builds the runner and the controls without running them; vulkan-kernel-contract runs them on the device. Both exist only with -Dvulkan=true. Checked: the host tests and the aarch64 build of the runner pass. Not yet run: the runner on a device (gates 1 to 4 and the live limits check), so no SUMMARY line exists yet, and the per-chip limit table is still unmeasured.
…wo input-write controls Review found gate 2 (repeat, aliasing, guards) vacuous for qmm_bf16: Fixture.run read back only the output buffer and the rig's inputs stayed the host snapshot taken before upload, so 'inputs untouched' could not fail for the real kernel. (The scribble control was caught only because Control.run downloads its x buffer.) Fixture.run now downloads all four input buffers (x, w, scales, biases) into the snapshot after each run, so the before/after comparison sees what the device holds. Two planted controls prove it: the same fixture with a write to its weights and to its biases (the last input, so a readback that stops one short misses it) after the dispatch must fail gate 2 and are counted as controls (8 controls now). The records comment no longer cites runner stderr hashes (they were from older runs, and a file cannot carry the hash of a run of itself); the description carries the hashes of the runs on this head. Proved by: vulkan-host-test 26 of 26 (18, 6 and 2 in three binaries) and the aarch64 ReleaseSafe runner build; not device-run yet.
Each multi-line or over-120-column comment in vulkan_records.zig, contract_main.zig and contract_qmm.zig becomes one line saying the same thing; no code changes.
ashhart
force-pushed
the
vulkan-base-pr
branch
from
October 29, 2026 23:44
17fa2cd to
771140e
Compare
Owner
|
Thank you @joshuaswarren. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0 It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog. |
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.
What this changes
First of the stacked Vulkan PRs for #1420, smallest first as the maintainers asked: an opt-in Vulkan compute runtime, and one kernel, the affine Q4 group-64 projection, registered in the kernel contract. Nothing else of the Vulkan backend is in this PR; the 2B engine, submit batching and penalties follow as separate PRs.
zig/src/vulkan/): loads the Vulkan loader at run time, picks a device, owns buffers, a command buffer, a fence and the staged upload and readback paths, and dispatches compute pipelines over checked SPIR-V, bindings and limits. Every submit has a finite fence wait; a timeout or an in-flight failure ends the process before anything is freed. Bindings are checked against the device's storage-buffer range and offset alignment.zig/kernels/vulkan/qmm.comp, compiled asqmm_bf16): the Q4 affine projection, bf16 in and out, fp32 sums.zig/tests/vulkan/probe.zig,affine_fixture.zig,zig/src/vulkan/gpu_tests.zig): the first device checks (a real device, staged buffer round trips and the projection against its float64 bound); host-checkable parts run invulkan-host-test, the device parts only through explicitvulkan-gpu-testandvulkan-probesteps.zig/tests/vulkan/contract_*.zig,zig/kernels/vulkan/contract_controls.comp,zig/src/core/contract/vulkan_records.zig): the Vulkan counterpart of HIP's. The kernel fills the sharedcontract.spec; the shared gates run its float64 reference. Five planted controls, one per gate, each built to break its gate, plus two that write to the weights and to the biases after the dispatch and must fail gate 2. Gate 5 per-chip limits are measured, not assumed.-Dvulkan=true(default off). With it,zig build tf-vulkan-kernel-contractbuilds the runner andzig build vulkan-kernel-contractruns it;vulkan-host-testjoinstest. Without the option no Vulkan step exists and no other backend's code changes. Outside the new files the diff touchesbuild.zig(the option and call),THIRD_PARTY_NOTICES.mdandLICENSES/mlx-omarchy-MIT.txt(the MIT notice for shader code adapted from mlx-omarchy), andzig/src/core/contract.zigpluszig/src/core/contract/limits.zig(additive Vulkan launch and limit types).Part of #1420; the stacking order is this PR, then the 2B engine, then submit batching, then penalties.
Receipt (kernel contract)
Gate 5 limits, measured on the devices (Mesa 26.3.0-devel Honeykrisp, Vulkan, all three chips reported the same values): maxComputeWorkGroupInvocations 1024, maxComputeWorkGroupSize 1024,1024,64, maxComputeSharedMemorySize 32768, maxStorageBufferRange 2147483647, minStorageBufferOffsetAlignment 16, subgroup size 32. The kernel and every control launch at 256x1x1 with no shared memory; the over-limit control declares 2048x1x1 and is rejected.
Served shapes: the ones the Qwen3.5-2B engine calls the projection at (K 2048 and 6144, N from 16 to the 248320-row head, one row for decode, 32 for a prefill chunk) plus small fixture shapes.
SUMMARY lines from the runner built at this PR's head 17fa2cd (
tf-vulkan-kernel-contract, ReleaseSafe aarch64, 4573232 bytes, sha256 0cfd4fe10761973a3ea08453a5a7e46d640f84c1885b17a4544b57b7e99fa4ea; zig 0.17.0,-Dvulkan=true -Dtarget=aarch64-linux-gnu -Doptimize=ReleaseSafe):SHA-256 of the full stderr of each run: M1 Max
ee54483cab907f645800bb64056f05df0527efd3821b8581c86976dc8e42fb41, M2 Maxae9ee961dc894bf8f80fd9e8156e6af4d9f8051ca4e67866ea9f604ab280a04b, M1f9ee23180d8968b04d5f7dc5fd42e03f8a808570095a42e782feb8003e1031ff.What this does not claim
zig build vulkan-host-test -Dvulkan=true(26 of 26 host tests pass on head 17fa2cd, in three test binaries of 18, 6 and 2, run fresh), and the runner and the probe cross-build for aarch64-linux-gnu with ReleaseSafe. Not run: CUDA, HIP, XPU and Metal (their code is unchanged).