-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing dimidx checks when translating get_global_offset #2638
Comments
I think this depends on how much the OpenCL C spec defines those builtins. There is the Which means, that those builtins aren't defined as not even the core SPIR-V spec defines them. So I think technically using all of those builtins is strictly speaking undefined behavior to begin with and I was already wondering if something should be done about that. |
On the other hand, out of bound accesses are also not defined, so maybe that's a good reason on why to fix it in the translator. |
I agree. The SPIRVWriter, particularly the
I agree, it is essential to maintain OpenCL C functionality within SPIRV. The OpenCL SPIR-V Environment Specification should clearly state that components (for instance, in the case of |
I've actually worked on this; I'll try get a PR out later today. |
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638
To be fixed by #3023 |
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes #2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup#2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes #2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes #2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes #2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes #2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes #2638 .
The behaviour for out-of-range dimension arguments to work-item functions is well defined in OpenCL C. For example, `get_global_size` must return 1 if its argument is larger than `get_work_dim() - 1`. Ensure the generated `extractelement` index never exceeds the vector size and return the correct out-of-range value (which is either 0 or 1 depending on the builtin). Fixes KhronosGroup/SPIRV-LLVM-Translator#2638 . Original commit: KhronosGroup/SPIRV-LLVM-Translator@07a3da9fe789224
For the following kernel, the
dimidx
value passed toget_global_offset
will be out-of-range for at least some calls regardless of the value ofj
:The OpenCL C spec has defined out-of-range behavior for
get_global_offset
though, so this program is correct:However, when I generate SPIR-V using Clang and the SPIR-V LLVM Translator there are no range checks:
I think there needs to be some sort of
dimidx
check when translatingget_global_offset
, to have the proper out-of-range behavior. These will be removed in most common cases, such as when thedimidx
is an integer literal, but they will probably need to be preserved when the index is unknown like it is in the example above.Since the OpenCL SPIR-V Environment spec requires the GlobalOffset BuiltIn to have three components we probably can use that to simplify the range checks vs. querying the work dimension?
As an aside, we should also clarify in the OpenCL SPIR-V Environment spec what happens to the upper components of the GlobalOffset BuiltIn (and other vector built-ins) when the ND-range dimension is smaller than three.
The text was updated successfully, but these errors were encountered: