Skip to content

[Metal] demote unordered atomic loads and stores - #904

Open
simeonschaub wants to merge 1 commit into
JuliaGPU:mainfrom
simeonschaub:sds/metal_unordered_atomics
Open

[Metal] demote unordered atomic loads and stores#904
simeonschaub wants to merge 1 commit into
JuliaGPU:mainfrom
simeonschaub:sds/metal_unordered_atomics

Conversation

@simeonschaub

@simeonschaub simeonschaub commented Aug 21, 2026

Copy link
Copy Markdown
Member

The AGX back-end crashes on these with XPC_ERROR_CONNECTION_INTERRUPTED, because AIR has no LLVM-level atomic load/store instructions.

The compilesig_invokes=false change in #899 only surfaced this issue, since Bool(::Real) throws an InexactError(:Bool, Bool, x) through its vararg @nospecialize constructor, which previously was a dead dynamic call that lower_throw! just deleted. It's now a real noinline call whose body allocates the Tuple{DataType,Int64} with an unordered pointer store, breaking MtlArray{Bool}(undef, 2) .= 1 on 1.12+.

Since there is no GC on GPUs, this should be legal, but please correct me otherwise

@christiangnrd Can you confirm whether this fixes the Metal issues?

@christiangnrd

Copy link
Copy Markdown
Member

This seems to have fixed things locally

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.25%. Comparing base (805b0c1) to head (e364a82).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #904      +/-   ##
==========================================
+ Coverage   84.00%   84.25%   +0.25%     
==========================================
  Files          28       28              
  Lines        5382     5393      +11     
==========================================
+ Hits         4521     4544      +23     
+ Misses        861      849      -12     

☔ 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 self-assigned this Aug 22, 2026
Julia marks heap-reference accesses unordered so raced pointer reads cannot
invent values. With compilesig_invokes=false, Bool(::Real) now compiles its
noinline InexactError constructor, whose argument tuple contains such a store
on Julia 1.12+.

AIR rejects LLVM atomic load/store instructions. GPUCompiler has no device GC,
and Metal atomics already use air.atomic.* intrinsics, so demote unordered
accesses after optimization while preserving stronger orderings.
@maleadt
maleadt force-pushed the sds/metal_unordered_atomics branch from e096836 to e364a82 Compare August 22, 2026 06:16
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