[llvm] [SPIR-V] Align memory scopes with SPIR-V specification and LLVM expectations and change default mem scope value (PR #108528)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 12:01:00 PDT 2024
================
@@ -847,25 +852,18 @@ bool SPIRVInstructionSelector::selectBitcast(Register ResVReg,
static SPIRV::Scope::Scope getScope(SyncScope::ID Ord,
const SyncScopeIDs &SSIDs) {
- if (Ord == SyncScope::SingleThread || Ord == SSIDs.Work_ItemSSID)
+ if (Ord == SyncScope::SingleThread)
return SPIRV::Scope::Invocation;
- else if (Ord == SyncScope::System || Ord == SSIDs.DeviceSSID)
- return SPIRV::Scope::Device;
- else if (Ord == SSIDs.WorkGroupSSID)
- return SPIRV::Scope::Workgroup;
- else if (Ord == SSIDs.AllSVMDevicesSSID)
- return SPIRV::Scope::CrossDevice;
- else if (Ord == SSIDs.SubGroupSSID)
+ if (Ord == SSIDs.SubGroupSSID)
return SPIRV::Scope::Subgroup;
- else
- // OpenCL approach is: "The functions that do not have memory_scope argument
- // have the same semantics as the corresponding functions with the
- // memory_scope argument set to memory_scope_device." See ref.: //
- // https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#atomic-functions
- // In our case if the scope is unknown, assuming that SPIR-V code is to be
- // consumed in an OpenCL environment, we use the same approach and set the
- // scope to memory_scope_device.
+ if (Ord == SSIDs.WorkGroupSSID)
+ return SPIRV::Scope::Workgroup;
+ if (Ord == SSIDs.DeviceSSID)
return SPIRV::Scope::Device;
+ if (Ord == SyncScope::System)
+ return SPIRV::Scope::CrossDevice;
+ // Use the most conservative/safe choice as the default.
+ return SPIRV::Scope::CrossDevice;
----------------
arsenm wrote:
I'd expect this to also be caught by an explicit Ord == SyncScope::System above where the other generic ID is handled
https://github.com/llvm/llvm-project/pull/108528
More information about the llvm-commits
mailing list