Skip to content

fix(metal): build with Xcode 27 / Metal 4.1 (explicit thread on member functions) - #16

Open
solderzzc wants to merge 1 commit into
mainfrom
fix/metal-4.1-thread-addrspace
Open

solderzzc wants to merge 1 commit into
mainfrom
fix/metal-4.1-thread-addrspace

Conversation

@solderzzc

@solderzzc solderzzc commented Sep 23, 2026

Copy link
Copy Markdown
Member

Problem

Xcode 27 ships Metal 4.1 (metalfe-32023.921). In Metal 4.1, this inside a member function no longer defaults to the thread address space; it now defaults to __metal_generic. As a result, a member function that returns thread T& to one of its members fails to compile:

steel/gemm/mma.h:245: error: reference to type 'thread vec' could not bind to an lvalue of type 'vec'

17 of the 40 kernels fail. That includes every quantized matmul kernel (quantized, quantized_nax, fp_quantized*) and all steel GEMM and attention kernels. ./build.sh in SwiftLM stops at mlx-metallib, so nothing can be built with Xcode 27. Found while setting up an M6 Mac mini on macOS 27.0.

Fix

  • Backport ml-explore/mlx#3963 (ef5fc0fab2), the upstream fix for this exact issue, into the vendored mlx 0.30.6. Some of its hunks don't apply because upstream has since rewritten that code (sort.h LessThan, the NAXFrag-based nax.h, the Conv3D loaders). Those hunks aren't needed here.
  • Apply the same rule to the older NAXSubTile/NAXTile structs in steel/gemm/nax.h and steel/attn/nax.h: add an explicit thread qualifier to each member function signature (32 per file). #3963 doesn't cover these because upstream replaced them.
  • Regenerate mlx-generated/. Both the JIT .cpp sources and the metal/ header copies are regenerated from the patched kernels. I ran the generator twice, on unpatched and on patched sources, and applied only the difference between the two runs. The existing hand edits in mlx-generated/ (the compiled_preamble bool fix, conv.cpp, and the hand-written steel_conv_3d.cpp stub) are left as they were.

On older toolchains this changes nothing, because thread was already the implicit default for this.

Verification

  • With Metal 32023.921 (Xcode 27A266a), all 39 kernels in the metallib build list compile. steel_conv_3d still fails on its own, but it isn't in the build list and it failed before this change too.
  • SwiftLM ./build.sh completes: a 128 MB mlx.metallib, and the Swift 6.4 build succeeds.
  • Inference smoke test on M6 with mlx-community/Qwen3.8-27B-4bit (it runs the quantized, GEMM, attention and NAX kernels). Results: correct answers on a short factual question and on arithmetic, and a planted code word retrieved correctly from a 7.9K-token prompt; decode 9.0 tok/s; no Metal errors.
  • Build check on Xcode 26

🤖 Generated with Claude Code

…ber functions)

Metal 4.1 (Xcode 27, metalfe-32023) makes the implicit address space of
`this` in member functions `__metal_generic` instead of `thread`. Returning
`thread T&` to a member then no longer compiles, which broke 17 of 40
kernels, including every quantized matmul (quantized, quantized_nax,
fp_quantized*) and all steel GEMM/attention kernels.

- Backport ml-explore/mlx#3963 (ef5fc0fab2) to the vendored mlx 0.30.6.
  Hunks for code that has since diverged upstream (sort.h LessThan, the
  newer NAXFrag-based nax.h, the Conv3D loaders) do not apply and are
  not needed here.
- Apply the same rule to the older NAXSubTile/NAXTile structs in
  steel/gemm/nax.h and steel/attn/nax.h (32 signatures each), which
  #3963 does not cover because upstream rewrote them.
- Regenerate mlx-generated/ (JIT sources and metal/ headers) from the
  patched kernels. Only the patched-vs-unpatched delta is applied, so
  existing hand edits in mlx-generated/ are kept.

All 39 kernels in the metallib build list compile with Metal 32023.921.
The change is a no-op on older toolchains (the qualifier was already
the implicit default there).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@solderzzc
solderzzc marked this pull request as ready for review September 24, 2026 03:22
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