Description
Describe the bug
The OpenCL 3.0 SPIR-V Environment specifies under 2.9. Built-in Variables
that all builtin variables have to be in the Input Storage Class:
"An OpVariable in a SPIR-V module with the BuiltIn decoration represents a built-in variable. All built-in variables must be in the Input storage class."
But the generated sycl SPIR-V puts them into the Cross Workgroup Storage class.
This is a new requirement introduced by OpenCL 3.0, though earlier versions did not specify details of BuiltIn variables, using Cross Workgroup doesn't make any sense from a technical perspective either way.
To Reproduce
This can be seen with any SyCL program using builtins.
- fetch the sycl sample app from https://intel.github.io/llvm-docs/GetStartedGuide.html#run-simple-dpc-application
- clang++ -fsycl -fsycl-device-only -fno-sycl-use-bitcode -fsycl-targets=spir64-unknown-unknown test.cpp -o - | spirv-dis
relevant bits of the SPIR-V:
OpDecorate %__spirv_BuiltInGlobalInvocationId LinkageAttributes "__spirv_BuiltInGlobalInvocationId" Import
OpDecorate %__spirv_BuiltInGlobalInvocationId BuiltIn GlobalInvocationId
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
%__spirv_BuiltInGlobalInvocationId = OpVariable %_ptr_CrossWorkgroup_v3ulong CrossWorkgroup
Environment:
- OS: Linux
- DPC++ version:
clang version 16.0.0 (https://github.com/intel/llvm 22e3fc56c8c2bef6d92a19819b7bea106a7992d1)
Additional context
SyCL binaries shouldn't rely on spec violations to be accepted by OpenCL runtimes even though if requirements were introduced later on.
Also, this doesn't happen if upstream clang is used to compile normal OpenCL C applications using get_global_id
to SPIR-V through https://github.com/KhronosGroup/SPIRV-LLVM-Translator