Conversation
maleadt
added this pull request to stack #29
September 25, 2026 13:30
maleadt
force-pushed
the
tb/scopes
branch
2 times, most recently
from
September 25, 2026 14:41
9d072c1 to
4cb0821
Compare
maleadt
marked this pull request as ready for review
September 25, 2026 15:11
Back-ends need the workgroup, device, ... scopes, and use the internal LLVMSyncScope type to get them. Provide `subgroup`, `workgroup`, `device` and `system` (the existing `none`) as constants, and `SyncScope(name)` for target-specific scopes such as `:agent`.
The IR for Ptr atomics that can't use the intrinsics was built for each scope singleton when defining the methods. Build it in @generated helpers that take the scope as a type parameter instead, so that other scopes can be supported without enumerating them. No functional change.
Atomics on Ptr only accepted the `none` and `singlethread` scopes, while LLVMPtr accepts any. Define the llvmcall-based methods for every LLVMSyncScope, so that the canonical scopes and target-specific ones like `SyncScope(:agent)` work on Ptr too. The system scope keeps using the intrinsics where possible.
Fences only accepted the `none` and `singlethread` scopes, so back-ends had to add methods for others (AMDGPU does). Emit them for any LLVMSyncScope. This also fixes `fence(monotonic, singlethread)` and `fence(unordered, singlethread)`, which emitted IR that failed to parse: like for the system scope, the former is now a no-op and the latter throws a ConcurrencyViolationError.
Nothing is exported, so mark the functions, orderings and scopes as `public` on Julia 1.11 and later, to distinguish them from the internals that back-ends currently reach into.
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.
Stack: #28 → #25 → this PR → #30.
GPU back-ends need scopes such as
workgroupanddevice, but UnsafeAtomics only exposednoneandsinglethread. As a result, Metal.jl, SPIRVIntrinsics and AMDGPU.jl construct the internalUnsafeAtomics.Internal.LLVMSyncScope{name}()type, and AMDGPU.jl piratesUnsafeAtomics.fencebecause fences only accepted those two scopes. OnlyLLVMPtrhonored other scopes at all.This PR adds a public set of scopes:
singlethread,subgroup,workgroup,deviceandsystem(an alias ofnone), plusSyncScope(:name)for target-specific scopes such as:agent. All operations on both pointer types, includingfence, accept any of them. The change is purely additive.Once released, back-ends can stop using the internal type, and AMDGPU.jl can remove its
fencemethods.