Add atomic memory orderings for Metal#79
Open
VEZY wants to merge 1 commit into
Open
Conversation
This was referenced Jul 1, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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