Skip to content

Metal: lower bare LLVM fences to air.atomic.fence - #932

Merged
maleadt merged 3 commits into
mainfrom
tb/fences
Sep 16, 2026
Merged

maleadt merged 3 commits into
mainfrom
tb/fences

Conversation

@maleadt

@maleadt maleadt commented Sep 15, 2026

Copy link
Copy Markdown
Member

The macOS 27 AGX compiler aborts on bare LLVM fences emitted by Julia's atomic_fence intrinsic (JuliaGPU/Metal.jl#968). Lower them during AIR code generation to the intrinsic used by MSL's atomic_thread_fence.

Cover device and threadgroup memory, using thread scope for singlethread and device scope otherwise. Preserve orderings on Metal 4.1 and strengthen them to seq_cst on Metal 3.2-4.0. Older targets retain bare fences because the intrinsic is unavailable, and still require a back-end that accepts them.

Test all fence orderings with system, singlethread and custom scopes, both version boundaries, existing declarations, and Julia-to-AIR lowering.

The macOS 27 AGX compiler aborts on bare LLVM fences emitted by Julia's
atomic_fence intrinsic (JuliaGPU/Metal.jl#968). Lower them during AIR
code generation to the intrinsic used by MSL's atomic_thread_fence.

Cover device and threadgroup memory, using thread scope for singlethread
and device scope otherwise. Preserve orderings on Metal 4.1 and strengthen
them to seq_cst on Metal 3.2-4.0. Older targets retain bare fences because
the intrinsic is unavailable, and still require a back-end that accepts
them.

Read the fence ordering from the instruction's textual form: before
LLVM 18, LLVMGetOrdering casts a fence to an RMW instruction and returns
garbage, which lowered every ordering as seq_cst on Julia 1.10 and 1.11.
Use the textual path on all versions so newer CI also tests the workaround.

Test all fence orderings with system, singlethread and custom scopes,
including escaped scope names and trailing debug/annotation metadata,
both version boundaries, existing declarations, and Julia-to-AIR lowering.
Under coverage, current Julia nightlies keep an inlined-at debug comment
naming `GPUCompiler.alloca`, which the bare `@check_not "alloca"` matched.
Check for the instruction instead.
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.85%. Comparing base (cf51f4f) to head (c55354b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #932      +/-   ##
==========================================
+ Coverage   85.78%   85.85%   +0.06%     
==========================================
  Files          29       29              
  Lines        5613     5654      +41     
==========================================
+ Hits         4815     4854      +39     
- Misses        798      800       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit cae55dd into main Sep 16, 2026
33 checks passed
@maleadt
maleadt deleted the tb/fences branch September 16, 2026 05:07
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