Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ oneAPI_Level_Zero_Headers_jll = "f4bc562b-d309-54f8-9efb-476e56f0410d"
oneAPI_Level_Zero_Loader_jll = "13eca655-d68d-5b81-8367-6d99d727ab01"
oneAPI_Support_jll = "b049733a-a71d-5ed3-8eba-7d323ac00b36"

[weakdeps]
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"

[extensions]
EnzymeCoreExt = "EnzymeCore"

[compat]
AbstractFFTs = "1.5.0"
Adapt = "4"
CEnum = "0.5, 1"
Crayons = "4"
EnzymeCore = "0.8"
GPUArrays = "12.1"
GPUCompiler = "2.24"
GPUToolbox = "3.7"
Expand All @@ -52,7 +59,7 @@ PTI_jll = "1.2"
PrecompileTools = "1"
PrettyTables = "3"
Preferences = "1"
SPIRVIntrinsics = "1.6"
SPIRVIntrinsics = "1.6.2"
SPIRV_LLVM_Backend_jll = "23"
SPIRV_LLVM_Translator_jll = "23"
SPIRV_Tools_jll = "2025.4.0"
Expand Down
27 changes: 27 additions & 0 deletions ext/EnzymeCoreExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# compatibility with EnzymeCore
module EnzymeCoreExt

using oneAPI
import oneAPI: GPUCompiler, oneAPIBackend, oneL0
import KernelInterface as KI

import EnzymeCore
using EnzymeCore.EnzymeRules

# the compiler job that kernels for `backend` are compiled with (see `KI.kernel_function`),
# for Enzyme to compile the derivatives of kernels (e.g. by KernelAbstractions' Enzyme
# extension) and their tapes
function EnzymeCore.compiler_job_from_backend(
backend::oneAPIBackend, @nospecialize(F::Type), @nospecialize(TT::Type)
)
mi = GPUCompiler.methodinstance(F, TT)
sub_group_size = KI.sub_group_size(backend)
config = oneAPI.compiler_config(oneAPI.device(); backend.always_inline,
sub_group_size = sub_group_size > 0 ? sub_group_size : nothing)
return GPUCompiler.CompilerJob(mi, config)
end

# waiting for the GPU has no derivative
EnzymeRules.inactive(::typeof(oneL0.synchronize), args...; kwargs...) = nothing

end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
BFloat16s = "ab4f0b2a-ad5b-11e8-123f-65d77653426b"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
GPUToolbox = "096a3bc2-3ced-46d0-87f4-dd12716f4bfc"
Expand Down
15 changes: 15 additions & 0 deletions test/extensions/enzyme.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import EnzymeCore
import KernelInterface as KI
using oneAPI: GPUCompiler

@testset "compiler_job_from_backend" begin
# compiled like `KI.kernel_function` compiles kernels for the back end
for always_inline in (false, true)
backend = oneAPIBackend(; always_inline)
job = EnzymeCore.compiler_job_from_backend(backend, typeof(identity), Tuple{Float32})
@test job isa GPUCompiler.CompilerJob
@test job.config.always_inline == always_inline
sub_group_size = KI.sub_group_size(backend)
@test job.config.params.sub_group_size == (sub_group_size > 0 ? sub_group_size : nothing)
end
end
Loading