intel / intel/llvm

Handling of Builtin Variables violates OpenCL 3.0 SPIR-V Environment Specification.

Open
#6,703 9 comments 0 reactions 1 assignee Claimed by @MrSidims View on GitHub
bug confirmed SPIR-V
Dominant language
LLVM
Stars
1.5k
Forks
854
Avg merge
3d 17h
Merged PRs (30d)
137

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.

1. fetch the sycl sample app from https://intel.github.io/llvm-docs/GetStartedGuide.html#run-simple-dpc-application
1. 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:
```spv
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.