Skip to content

Commit fed789e

Browse files
Setup GPU testing infrastructure
Noted in #759 (comment), GPU is completely untested in ForwardDiff.jl, so this sets up the buildkite pipeline. I setup the backend and all, and just took a few tests from #760 to seed it. The point of this isn't really to be a comprehensive set of GPU tests but rather to update this repo to have the standard tools the other repos have so GPU doesn't regress again/more.
1 parent 1082aa3 commit fed789e

File tree

5 files changed

+126
-47
lines changed

5 files changed

+126
-47
lines changed

.buildkite/pipeline.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
steps:
2+
- label: "CUDA"
3+
plugins:
4+
- JuliaCI/julia#v1:
5+
version: "1"
6+
- JuliaCI/julia-test#v1:
7+
coverage: false # 1000x slowdown
8+
agents:
9+
queue: "juliagpu"
10+
cuda: "*"
11+
env:
12+
GROUP: 'CUDA'
13+
JULIA_PKG_SERVER: "" # it often struggles with our large artifacts
14+
# SECRET_CODECOV_TOKEN: "..."
15+
timeout_in_minutes: 180
16+
# Don't run Buildkite if the commit message includes the text [skip tests]
17+
if: build.message !~ /\[skip tests\]/

test/gpu/GPUGradientTest.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using ForwardDiff, CUDA, Test
2+
3+
fn(x) = sum(x .^ 2 ./ 2)
4+
5+
x = [1.0, 2.0, 3.0]
6+
x_jl = CuArray(x)
7+
8+
grad = ForwardDiff.gradient(fn, x)
9+
grad_jl = ForwardDiff.gradient(fn, x_jl)
10+
11+
@test grad_jl isa CuArray
12+
@test Array(grad_jl) grad
13+
14+
cfg = ForwardDiff.GradientConfig(
15+
fn, x_jl, ForwardDiff.Chunk{2}(), ForwardDiff.Tag(fn, eltype(x))
16+
)
17+
grad_jl = ForwardDiff.gradient(fn, x_jl, cfg)
18+
19+
@test grad_jl isa CuArray
20+
@test Array(grad_jl) grad

test/gpu/GPUJacobianTest.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using ForwardDiff, CUDA, Test
2+
3+
f(x) = x .^ 2 ./ 2
4+
5+
x = [1.0, 2.0, 3.0]
6+
x_jl = CuArray(x)
7+
8+
jac = ForwardDiff.jacobian(f, x)
9+
jac_jl = ForwardDiff.jacobian(f, x_jl)
10+
11+
@test jac_jl isa CuArray
12+
@test Array(jac_jl) jac

test/gpu/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3+
4+
[compat]
5+
CUDA = "5"

test/runtests.jl

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,80 @@
11
using ForwardDiff, Test, Random
2+
using Pkg
3+
4+
const GROUP = get(ENV, "GROUP", "All")
5+
6+
function activate_gpu_env()
7+
Pkg.activate("gpu")
8+
Pkg.develop(PackageSpec(path = dirname(@__DIR__)))
9+
Pkg.instantiate()
10+
end
211

312
SEED = trunc(Int, time())
413
println("##### Random.seed!($SEED), on VERSION == $VERSION")
514
Random.seed!(SEED)
615

7-
@testset "ForwardDiff.jl" begin
8-
t0 = time()
9-
@testset "Partials" begin
10-
println("##### Testing Partials...")
11-
t = @elapsed include("PartialsTest.jl")
12-
println("##### done (took $t seconds).")
13-
end
14-
@testset "Dual" begin
15-
println("##### Testing Dual...")
16-
t = @elapsed include("DualTest.jl")
17-
println("##### done (took $t seconds).")
18-
end
19-
@testset "Derivatives" begin
20-
println("##### Testing derivative functionality...")
21-
t = @elapsed include("DerivativeTest.jl")
22-
println("##### done (took $t seconds).")
23-
end
24-
@testset "Gradients" begin
25-
println("##### Testing gradient functionality...")
26-
t = @elapsed include("GradientTest.jl")
27-
println("##### done (took $t seconds).")
16+
if GROUP == "All" || GROUP == "Core"
17+
@testset "ForwardDiff.jl" begin
18+
t0 = time()
19+
@testset "Partials" begin
20+
println("##### Testing Partials...")
21+
t = @elapsed include("PartialsTest.jl")
22+
println("##### done (took $t seconds).")
23+
end
24+
@testset "Dual" begin
25+
println("##### Testing Dual...")
26+
t = @elapsed include("DualTest.jl")
27+
println("##### done (took $t seconds).")
28+
end
29+
@testset "Derivatives" begin
30+
println("##### Testing derivative functionality...")
31+
t = @elapsed include("DerivativeTest.jl")
32+
println("##### done (took $t seconds).")
33+
end
34+
@testset "Gradients" begin
35+
println("##### Testing gradient functionality...")
36+
t = @elapsed include("GradientTest.jl")
37+
println("##### done (took $t seconds).")
38+
end
39+
@testset "Jacobians" begin
40+
println("##### Testing jacobian functionality...")
41+
t = @elapsed include("JacobianTest.jl")
42+
println("##### done (took $t seconds).")
43+
end
44+
@testset "Hessians" begin
45+
println("##### Testing hessian functionality...")
46+
t = @elapsed include("HessianTest.jl")
47+
println("##### done (took $t seconds).")
48+
end
49+
@testset "Perturbation Confusion" begin
50+
println("##### Testing perturbation confusion functionality...")
51+
t = @elapsed include("ConfusionTest.jl")
52+
println("##### done (took $t seconds).")
53+
end
54+
@testset "Miscellaneous" begin
55+
println("##### Testing miscellaneous functionality...")
56+
t = @elapsed include("MiscTest.jl")
57+
println("##### done (took $t seconds).")
58+
end
59+
@testset "Allocations" begin
60+
println("##### Testing allocations...")
61+
t = @elapsed include("AllocationsTest.jl")
62+
println("##### done (took $t seconds).")
63+
end
64+
println("##### Running all ForwardDiff tests took $(time() - t0) seconds.")
2865
end
29-
@testset "Jacobians" begin
30-
println("##### Testing jacobian functionality...")
31-
t = @elapsed include("JacobianTest.jl")
32-
println("##### done (took $t seconds).")
66+
elseif GROUP == "CUDA"
67+
@testset "ForwardDiff.jl CUDA" begin
68+
activate_gpu_env()
69+
@testset "CUDA Gradients" begin
70+
println("##### Testing CUDA gradients...")
71+
t = @elapsed include("CUDAGradientTest.jl")
72+
println("##### done (took $t seconds).")
73+
end
74+
@testset "CUDA Jacobians" begin
75+
println("##### Testing CUDA Jacobians...")
76+
t = @elapsed include("CUDAJacobianTest.jl")
77+
println("##### done (took $t seconds).")
78+
end
3379
end
34-
@testset "Hessians" begin
35-
println("##### Testing hessian functionality...")
36-
t = @elapsed include("HessianTest.jl")
37-
println("##### done (took $t seconds).")
38-
end
39-
@testset "Perturbation Confusion" begin
40-
println("##### Testing perturbation confusion functionality...")
41-
t = @elapsed include("ConfusionTest.jl")
42-
println("##### done (took $t seconds).")
43-
end
44-
@testset "Miscellaneous" begin
45-
println("##### Testing miscellaneous functionality...")
46-
t = @elapsed include("MiscTest.jl")
47-
println("##### done (took $t seconds).")
48-
end
49-
@testset "Allocations" begin
50-
println("##### Testing allocations...")
51-
t = @elapsed include("AllocationsTest.jl")
52-
println("##### done (took $t seconds).")
53-
end
54-
println("##### Running all ForwardDiff tests took $(time() - t0) seconds.")
55-
end
80+
end

0 commit comments

Comments
 (0)