From f0cd59abe601b6bcd00027b98c33b5146499f2f3 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 28 Oct 2025 17:25:09 +0100 Subject: [PATCH 1/3] add KernelAbstractions integration test --- .github/workflows/Integration.yml | 1 + .../KernelAbstractions/Project.toml | 11 ++++ .../KernelAbstractions/runtests.jl | 55 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 test/integration/KernelAbstractions/Project.toml create mode 100644 test/integration/KernelAbstractions/runtests.jl diff --git a/.github/workflows/Integration.yml b/.github/workflows/Integration.yml index 71a1a308dc..54eea4c241 100644 --- a/.github/workflows/Integration.yml +++ b/.github/workflows/Integration.yml @@ -51,6 +51,7 @@ jobs: - DynamicExpressions - Lux - SciML + - KernelAbstractions steps: - uses: actions/checkout@v5 - uses: julia-actions/setup-julia@v2 diff --git a/test/integration/KernelAbstractions/Project.toml b/test/integration/KernelAbstractions/Project.toml new file mode 100644 index 0000000000..ea0916d2a8 --- /dev/null +++ b/test/integration/KernelAbstractions/Project.toml @@ -0,0 +1,11 @@ +[deps] +Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" +EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869" +KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c" + +[sources] +Enzyme = {path = "../../.."} +EnzymeCore = {path = "../../../lib/EnzymeCore"} + +[compat] +KernelAbstractions = "0.9" \ No newline at end of file diff --git a/test/integration/KernelAbstractions/runtests.jl b/test/integration/KernelAbstractions/runtests.jl new file mode 100644 index 0000000000..18f93241ca --- /dev/null +++ b/test/integration/KernelAbstractions/runtests.jl @@ -0,0 +1,55 @@ +using Test +using Enzyme +using KernelAbstractions + +@kernel function square!(A) + I = @index(Global, Linear) + @inbounds A[I] *= A[I] +end + +function square_caller(A) + backend = get_backend(A) + kernel = square!(backend) + kernel(A, ndrange = size(A)) + KernelAbstractions.synchronize(backend) + return +end + + +@kernel function mul!(A, B) + I = @index(Global, Linear) + @inbounds A[I] *= B +end + +function mul_caller(A, B) + backend = get_backend(A) + kernel = mul!(backend) + kernel(A, B, ndrange = size(A)) + KernelAbstractions.synchronize(backend) + return +end + +@testset "kernels" begin + A = Array{Float64}(undef, 64) + dA = Array{Float64}(undef, 64) + + A .= (1:1:64) + dA .= 1 + + Enzyme.autodiff(Reverse, square_caller, Duplicated(A, dA)) + @test all(dA .≈ (2:2:128)) + + A .= (1:1:64) + dA .= 1 + + _, dB, _ = Enzyme.autodiff(Reverse, mul_caller, Duplicated(A, dA), Active(1.2))[1] + + @test all(dA .≈ 1.2) + @test dB ≈ sum(1:1:64) + + A .= (1:1:64) + dA .= 1 + + Enzyme.autodiff(Forward, square_caller, Duplicated(A, dA)) + @test all(dA .≈ 2:2:128) +end From 8934eacdea9e8bba99fcda61c5dad778f18a3164 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 28 Oct 2025 17:40:04 +0100 Subject: [PATCH 2/3] Update test/integration/KernelAbstractions/Project.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com> --- test/integration/KernelAbstractions/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/KernelAbstractions/Project.toml b/test/integration/KernelAbstractions/Project.toml index ea0916d2a8..ae658be845 100644 --- a/test/integration/KernelAbstractions/Project.toml +++ b/test/integration/KernelAbstractions/Project.toml @@ -8,4 +8,4 @@ Enzyme = {path = "../../.."} EnzymeCore = {path = "../../../lib/EnzymeCore"} [compat] -KernelAbstractions = "0.9" \ No newline at end of file +KernelAbstractions = "0.9" From 31200fe7b45deff30d227e69347e3449479c51fd Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 28 Oct 2025 17:40:35 +0100 Subject: [PATCH 3/3] Update test/integration/KernelAbstractions/runtests.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com> --- test/integration/KernelAbstractions/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/KernelAbstractions/runtests.jl b/test/integration/KernelAbstractions/runtests.jl index 18f93241ca..f66bf87ae2 100644 --- a/test/integration/KernelAbstractions/runtests.jl +++ b/test/integration/KernelAbstractions/runtests.jl @@ -42,7 +42,7 @@ end A .= (1:1:64) dA .= 1 - _, dB, _ = Enzyme.autodiff(Reverse, mul_caller, Duplicated(A, dA), Active(1.2))[1] + _, dB = Enzyme.autodiff(Reverse, mul_caller, Duplicated(A, dA), Active(1.2))[1] @test all(dA .≈ 1.2) @test dB ≈ sum(1:1:64)