Skip to content

Add an EnzymeCore extension for KernelAbstractions' Enzyme support - #771

Draft
vchuravy wants to merge 1 commit into
mainfrom
vc/enzyme
Draft

vchuravy wants to merge 1 commit into
mainfrom
vc/enzyme

Conversation

@vchuravy

@vchuravy vchuravy commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

KernelAbstractions has its Enzyme extension back (JuliaGPU/KernelAbstractions.jl#826). That extension calls EnzymeCore.compiler_job_from_backend to compile the derivatives of kernels and their tapes. This PR adds an EnzymeCoreExt that:

  • implements it for oneAPIBackend, compiling like KI.kernel_function does: with the back end's always_inline and the sub-group size;
  • marks oneL0.synchronize inactive, as CUDA.jl does.

Reverse mode also needs SPIRVIntrinsics 1.6.2 (JuliaGPU/OpenCL.jl#642), hence the compat bump. oneAPI computes KernelInterface indices in 32 bits, so the result of a work-item built-in such as __spirv_BuiltInWorkgroupId reaches integer code only through a truncation. Enzyme's type analysis can't infer the type from that, so it couldn't rule out a pointer and failed to differentiate the call. SPIRVIntrinsics 1.6.2 declares the built-ins' results as integers.

Testing, on an Arc A770 with SPIRVIntrinsics 1.6.2 from that PR:

  • KernelAbstractions' Enzyme test suite (test/extensions/enzyme.jl, in Float32) passes, forward and reverse. With SPIRVIntrinsics 1.6.1, forward mode passes and reverse mode fails to compile.
  • The new extensions/enzyme test, which checks the compiler job's configuration, passes, as do kernelabstractions and kernelinterface.

JuliaGPU/KernelAbstractions.jl#986 adds a Buildkite job that runs KA's Enzyme tests against oneAPI.jl main.

Draft until SPIRVIntrinsics 1.6.2 is registered: CI can't resolve the environment before then.

@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.81%. Comparing base (ebbaa28) to head (7e3247e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #771      +/-   ##
==========================================
- Coverage   86.94%   86.81%   -0.14%     
==========================================
  Files          55       55              
  Lines        5195     5135      -60     
==========================================
- Hits         4517     4458      -59     
+ Misses        678      677       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

KernelAbstractions' Enzyme extension calls
`EnzymeCore.compiler_job_from_backend` to compile the derivatives of
kernels and their tapes. Implement it for `oneAPIBackend`, compiling like
`KI.kernel_function` does (with the back end's `always_inline` and the
sub-group size), and mark `synchronize` inactive.

Reverse mode needs SPIRVIntrinsics 1.6.2, whose work-item built-ins tell
Enzyme that they return integers: oneAPI computes KernelInterface indices
in 32 bits, and Enzyme can't infer the type of a built-in's result from
its truncation.
@maleadt
maleadt marked this pull request as draft December 2, 2026 19:11
@maleadt

maleadt commented Dec 2, 2026

Copy link
Copy Markdown
Member

I've reworked this onto current main. KA's Enzyme suite now passes on an Arc A770, forward and reverse. Reverse mode failed because oneAPI computes KernelInterface indices in 32 bits: Enzyme couldn't infer the type of a work-item built-in's result from its truncation, so it tried to differentiate the call. JuliaGPU/OpenCL.jl#642 declares the built-ins' results as integers (SPIRVIntrinsics 1.6.2), and this PR now requires that version. It also adds a small test of the compiler job's configuration.

Your guess on JuliaGPU/OpenCL.jl#621, that the exception reporting's stores of the work-item IDs were to blame, turned out not to be it: removing oneAPI's equivalent stores made no difference.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants