Repository navigation
SPIRVIntrinsics: tell Enzyme that the built-in vector variables are integers - #642
Merged
Merged
Conversation
…ntegers Reverse-mode Enzyme failed to compile KernelAbstractions kernels on oneAPI.jl: it found no derivative for the call of `_Z26__spirv_BuiltInWorkgroupIdi`, and compiled an `EnzymeNoDerivativeError` into the kernel. oneAPI.jl computes KernelInterface indices in 32 bits, so the built-in's 64-bit result only reaches integer code through a `trunc`, through which Enzyme's type analysis doesn't infer the source type. Not knowing that the result isn't a pointer, Enzyme then needs a derivative of the call. KA's POCL back end uses 64-bit indices, which is why it passed. Enzyme knows that the NVVM and AMDGPU work-item intrinsics return integers. Give the SPIR-V declarations the same knowledge with an `enzyme_type` return attribute, which the SPIR-V back-end and translator drop.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #642 +/- ##
==========================================
- Coverage 90.32% 90.14% -0.18%
==========================================
Files 18 18
Lines 1684 1684
==========================================
- Hits 1521 1518 -3
- Misses 163 166 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Reverse-mode Enzyme fails to compile KernelAbstractions kernels on oneAPI.jl (JuliaGPU/oneAPI.jl#771). It finds no derivative for the call of
_Z26__spirv_BuiltInWorkgroupIdi, and compiles anEnzymeNoDerivativeErrorinto the kernel.The cause is Enzyme's type analysis. oneAPI.jl computes KernelInterface indices in 32 bits, so the built-in's 64-bit result only reaches integer code through a
trunc, and Enzyme doesn't infer the type of a value from its truncation. Unable to rule out a pointer, Enzyme treats the call as one it has to differentiate. KA's POCL back end uses 64-bit indices, where the result feeds integer arithmetic directly, which is why the same tests pass there.Enzyme knows that the NVVM and AMDGPU work-item intrinsics return integers. This gives the SPIR-V built-in declarations an
enzyme_typereturn attribute that says the same. The SPIR-V back-end and the Khronos translator ignore it. The existing test of the declarations' attributes now also checks for it, and fails without the change.Testing:
intrinsicspasses on PoCL (SPIR-V and OpenCL C), the Intel Arc A770 and NVIDIA;intrinsicsandexecutionalso pass with the Khronos translator on PoCL and the Arc.SimpleGVNpass (dataOperandHasImpliedAttr: "Data operand index out of bounds"). That is a separate Enzyme bug, left for Add an EnzymeCore extension for KernelAbstractions' Enzyme support #621.Includes the bump to SPIRVIntrinsics 1.6.2.