Skip to content

Commit 53b2461

Browse files
vchuravygiordano
andauthored
add KernelAbstractions integration test (#2709)
* add KernelAbstractions integration test * Update test/integration/KernelAbstractions/Project.toml Co-authored-by: Mosè Giordano <[email protected]> * Update test/integration/KernelAbstractions/runtests.jl Co-authored-by: Mosè Giordano <[email protected]> --------- Co-authored-by: Mosè Giordano <[email protected]>
1 parent 057744f commit 53b2461

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.github/workflows/Integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
- DynamicExpressions
5252
- Lux
5353
- SciML
54+
- KernelAbstractions
5455
steps:
5556
- uses: actions/checkout@v5
5657
- uses: julia-actions/setup-julia@v2
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[deps]
2+
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
3+
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
4+
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
5+
6+
[sources]
7+
Enzyme = {path = "../../.."}
8+
EnzymeCore = {path = "../../../lib/EnzymeCore"}
9+
10+
[compat]
11+
KernelAbstractions = "0.9"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Test
2+
using Enzyme
3+
using KernelAbstractions
4+
5+
@kernel function square!(A)
6+
I = @index(Global, Linear)
7+
@inbounds A[I] *= A[I]
8+
end
9+
10+
function square_caller(A)
11+
backend = get_backend(A)
12+
kernel = square!(backend)
13+
kernel(A, ndrange = size(A))
14+
KernelAbstractions.synchronize(backend)
15+
return
16+
end
17+
18+
19+
@kernel function mul!(A, B)
20+
I = @index(Global, Linear)
21+
@inbounds A[I] *= B
22+
end
23+
24+
function mul_caller(A, B)
25+
backend = get_backend(A)
26+
kernel = mul!(backend)
27+
kernel(A, B, ndrange = size(A))
28+
KernelAbstractions.synchronize(backend)
29+
return
30+
end
31+
32+
@testset "kernels" begin
33+
A = Array{Float64}(undef, 64)
34+
dA = Array{Float64}(undef, 64)
35+
36+
A .= (1:1:64)
37+
dA .= 1
38+
39+
Enzyme.autodiff(Reverse, square_caller, Duplicated(A, dA))
40+
@test all(dA .≈ (2:2:128))
41+
42+
A .= (1:1:64)
43+
dA .= 1
44+
45+
_, dB = Enzyme.autodiff(Reverse, mul_caller, Duplicated(A, dA), Active(1.2))[1]
46+
47+
@test all(dA .≈ 1.2)
48+
@test dB sum(1:1:64)
49+
50+
A .= (1:1:64)
51+
dA .= 1
52+
53+
Enzyme.autodiff(Forward, square_caller, Duplicated(A, dA))
54+
@test all(dA .≈ 2:2:128)
55+
end

0 commit comments

Comments
 (0)