Skip to content

inkling2 metal dspark: match maxThreads guard to kappa (64) and attention (768) - #5041

Merged
ashhart merged 2 commits into
ashhart:mainfrom
gilby:fix-dspark-threads-guard
Nov 25, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
gilby:fix-dspark-threads-guard

Conversation

@gilby

@gilby gilby commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

What this changes

Before: after #4981's load-time maxThreads() guard merged alongside #4699's DSpark overhaul, zig/src/families/inkling2/metal/dspark_kernels.zig still checked .attention => 128 and else => 256, while zig/kernels/metal/inkling2/dspark.metal declares [[max_total_threads_per_threadgroup(64)]] on tf_ink2_dspark_kappa (dispatched at 64) and [[max_total_threads_per_threadgroup(768)]] on tf_ink2_dspark_attention (dispatched at 768). Every Pipelines.load / Pipelines.loadSource call failed immediately with error: DsparkThreads on kappa and under-checked attention.

After: Kind.requiredThreads() returns .kappa => 64, .block_qkv, .context_kv => 128, .attention => 768, and else => 256, matching dspark.metal, inkling2_dspark_metal_records.zig, and the host dispatches. dspark_kernels_test.zig checks Kind.requiredThreads() against the contract records and adds a Pipelines.load(device) GPU test (skipping cleanly when no Metal device is present).

Checks on this head

  • Head commit: 2d7ce3cbb59f3b3e888c8d9d8a749023c596b773
  • Lean checker, python3 tools/pr_check.py --base origin/main: merge base 9961ca4920848b84a98ec8eea978437662fd0300; 2 changed files; lean 164 vs 164, 0 new; 0 error(s), 1 warning(s) (advisory --pr Unreleased bullet notice; CHANGELOG.md intentionally left untouched). Touched .zig files: dspark_kernels.zig (282 lines), dspark_kernels_test.zig (185 lines), both <= 600.
  • Formatting & diff cleanliness:
    • zig fmt --check build.zig zig — exit 0.
    • git diff --check origin/main..HEAD — exit 0.
  • Tests & builds run (Zig 0.17.0, macOS 27.0.1):
    • zig build compile-inkling2-native-host — exit 0.
    • zig build compile-inkling2-native-host -Dtarget=x86_64-windows — exit 0.
    • zig build test-inkling2-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all: 45 pass, 4 skip (49 total) — exit 0.
    • zig build test-inkling2-metal-host -Dcpu=apple_m1 -Doptimize=ReleaseFast + binary --seed=0xcc8ea13f on Apple M5 Max (applegpu_g17, tensor units true): 110 passed; 6 skipped; 0 failed — exit 0 (before fix: new test failed 109 pass, 6 skip, 1 fail with error.DsparkThreads; tf-kernel-contract --only "metal inkling2 dspark" also failed with error: DsparkThreads).
    • ./zig-out/bin/tf-kernel-contract --only "metal inkling2" on Apple M5 Max (applegpu_g17, tensor units true): SUMMARY 61 kernels: 61 pass gates 1-4, 0 fail, 0 known findings; 67 controls: 67 red as planted, 0 missed; 0 limit problems; gates 10951 ms, limits 155 ms — exit 0.
  • CI: Pending GitHub Actions on 2d7ce3cbb59.
  • Not run, and why: Full-checkpoint server inference benchmarks (n/a — load-time maxThreads() guard alignment only; zero kernel shader or dispatch-grid changes) and non-Apple GPU backends (Metal-only files).

Receipt

  • Main against branch: Clears error: DsparkThreads on origin/main (9961ca4920) caused by the inkling2 metal: match kernel threadgroup reservations and enforce load guards #4981 TG guard + inkling2: rebase DSpark overhaul onto #4465 #4699 DSpark overhaul merge interaction without changing any shader code, dispatch width, or arithmetic.
  • Boxes it reaches: zig/src/families/inkling2/metal/dspark_kernels.zig (Kind.requiredThreads, Pipelines.loadSource) and zig/src/families/inkling2/metal/dspark_kernels_test.zig.
  • New switch? No.
  • Environment: Commit 2d7ce3cbb59f3b3e888c8d9d8a749023c596b773 on origin/main 9961ca4920848b84a98ec8eea978437662fd0300, Zig 0.17.0 (-Dcpu=apple_m1 -Doptimize=ReleaseFast), Apple M5 Max (applegpu_g17, macOS 27.0.1, Metal 4 tensor units true).
  • Paths and platforms the change reaches: DSpark Metal pipeline initialization on Apple Silicon GPUs (Pipelines.load / Pipelines.loadSource), plus host tests and Windows/native host compilation checks.
  • Exactness: n/a for server inference; all 61 metal inkling2 contract kernels (including all 11 DSpark kernels) pass gates 1-4 and limit checks with 0 failures.
  • Decode speed before and after: n/a — load-time maxThreads() guard only.
  • Prompt speed before and after: n/a — load-time maxThreads() guard only.
  • 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.
  • 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.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled.

@AIFlowML

Copy link
Copy Markdown
Contributor

This fixes the M5 Max failure I reproduced on main after #4699. On a clean trial merge of 2d7ce3cbb5 into 9961ca492, the new Pipelines.load regression ran on Metal and passed. The two targets passed 112 tests with six skipped.

zig build test-inkling2-metal-host test-inkling2-launch-map-host -Dfixed-cpu -j2 --summary all

Landing this first gives #5020 688c39cc53 two conflicts in the DSpark loader and its tests. I tried the rebase locally. Keeping Kind.requiredThreads() and the live pipeline test from this PR, plus #5020’s full shader-declaration check and Q4 test, passed the same two targets with 118 passes and six skips.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The required widths now match all eleven shader reservations and the existing dispatches, including kappa at 64 and attention at 768. The shader and arithmetic are unchanged, and the existing load-failure cleanup still covers the pipeline that fails its guard. This looks safe to land through the normal checks.

  • Synthena

@ashhart
ashhart force-pushed the fix-dspark-threads-guard branch from 2d7ce3c to 2ded151 Compare November 25, 2026 14:50
@ashhart
ashhart merged commit a992d0d into ashhart:main Nov 25, 2026
1 check passed
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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