You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: I used Codex with GPT-5.5 High to implement this feature (both on Metal.jl and here). The original issue for context is linked to building a TLAS on GPU with RayCore.jl (JuliaGeometry/Raycore.jl#19). The PR on Metal is here: JuliaGPU/Metal.jl#870. Please wait for this PR to be merged before merging this one.
Summary
This updates AtomixMetalExt so atomic operations on Metal arrays preserve the memory ordering requested through Atomix/UnsafeAtomics.
The extension previously dispatched to Metal atomic operations without forwarding the requested ordering. That makes relaxed counter-style atomics work, but it prevents acquire/release synchronization patterns from being represented correctly on Metal.
Changes:
Map Atomix/UnsafeAtomics orderings to Metal memory orders:
unordered / monotonic -> relaxed
acquire -> acquire
release -> release
acq_rel / acquire_release -> acq_rel
seq_cst / sequentially_consistent -> seq_cst
Pass the mapped ordering through modify!.
Pass success and failure orderings through replace!.
Implement Metal-backed get and set! using ordered Metal load/store operations.
Preserve relaxed Metal atomics for unordered/monotonic requests.
Add Metal extension tests covering get/set and ordering propagation.
Why
Atomix exposes memory ordering as part of its atomic API, and downstream GPU code relies on those orderings for synchronization-sensitive algorithms. In particular, algorithms that publish ordinary device-memory writes through an atomic operation need acquire/release or stronger semantics to make the writes visible to another workitem. This was my case when building a TLAS on GPU for performing all hits computations with a ray tracing algorithm (using RayCore).
Forwarding the requested ordering to Metal fixes those synchronization cases while keeping unordered/monotonic atomics mapped to relaxed Metal operations for fast counters and reductions.
Downstream RayCore.jl TLAS/BLAS Metal repro passed with Atomix orderings wired through to Metal.
ArchimedLight (my package) derived static TLAS comparison passed: CPU-built/adapted and direct Metal-built TLAS match for nodes, instances, all BLAS buffers, descriptors, and root AABB.
❌ Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.35%. Comparing base (e60c518) to head (7605e9b). ⚠️ Report is 22 commits behind head on main.
I'm going to close this in favour of a more general fix: With JuliaGPU/Metal.jl#977, Metal.jl emits plain LLVM atomics that GPUCompiler lowers to AIR, so orderings are honoured on every supported macOS version, with fences before Metal 4.1. Atomix's generic UnsafeAtomics path then works on Metal as-is, so I'll remove AtomixMetalExt instead of forwarding orderings through it. Your publish pattern should just work once that's released.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: I used Codex with GPT-5.5 High to implement this feature (both on Metal.jl and here). The original issue for context is linked to building a TLAS on GPU with RayCore.jl (JuliaGeometry/Raycore.jl#19). The PR on Metal is here: JuliaGPU/Metal.jl#870. Please wait for this PR to be merged before merging this one.
Summary
This updates
AtomixMetalExtso atomic operations on Metal arrays preserve the memory ordering requested through Atomix/UnsafeAtomics.The extension previously dispatched to Metal atomic operations without forwarding the requested ordering. That makes relaxed counter-style atomics work, but it prevents acquire/release synchronization patterns from being represented correctly on Metal.
Changes:
unordered/monotonic-> relaxedacquire-> acquirerelease-> releaseacq_rel/acquire_release-> acq_relseq_cst/sequentially_consistent-> seq_cstmodify!.replace!.getandset!using ordered Metal load/store operations.Why
Atomix exposes memory ordering as part of its atomic API, and downstream GPU code relies on those orderings for synchronization-sensitive algorithms. In particular, algorithms that publish ordinary device-memory writes through an atomic operation need acquire/release or stronger semantics to make the writes visible to another workitem. This was my case when building a TLAS on GPU for performing all hits computations with a ray tracing algorithm (using RayCore).
Forwarding the requested ordering to Metal fixes those synchronization cases while keeping unordered/monotonic atomics mapped to relaxed Metal operations for fast counters and reductions.
Validation