Skip to content

metal: guard Inkling 2 and LFM2 generated libraries against repeated threadgroup-size attributes - #5405

Merged
ashhart merged 3 commits into
mainfrom
lead/metal-threadgroup-guards
Nov 27, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/metal-threadgroup-guards

Conversation

@ashhart

@ashhart ashhart commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Metal compilers on current macOS refuse a kernel declaration that repeats [[max_total_threads_per_threadgroup(N)]] and reject the whole library at load. M5 did first; since macOS 27.0 the M3 Ultra compiler does too. #5303 fixed the Inkling 2 convolution kernels that had the duplicate, and #5376 fixes the Flash Next, Nemotron and Qwen4 source rewriters. This adds the guard that keeps it fixed.

  • Every Inkling 2 source builder (runtime, sample, glue and the model's aliases) checks its complete assembled text: each kernel carries at most one threadgroup-size attribute, and two different values are refused at build time.
  • LFM2's masked prompt builder sliced at [[kernel]] and prepended a 128-thread reservation, so a reservation already after the marker would have become a duplicate and a conflicting one before it would have been kept silently. It now keeps one, the value the kernel had, and refuses a conflict.

Every library main emits today is byte-identical: a test reconstructs 20 library and alias hashes and lengths independently. A host test replaying the pre-#5303 Inkling 2 source fails before this change (four doubled headers) and passes after. Both landing orders with #5376 were checked.

Collapse equal duplicate threadgroup attributes without changing kernel bodies, and reject conflicting bounds at build time. Route every Inkling source export through the shared check and validate the retained LFM2 prompt header before adding its reservation. Add focused source checks independent of the Apple SDK.
@ashhart
ashhart force-pushed the lead/metal-threadgroup-guards branch from 5c21db5 to a4eae69 Compare November 27, 2026 19:03
@ashhart
ashhart merged commit c464c91 into main Nov 27, 2026
2 of 12 checks passed
@ashhart
ashhart deleted the lead/metal-threadgroup-guards branch November 27, 2026 19:04
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.

1 participant