Skip to content

Commit cbd9f55

Browse files
committed
update tests for GPU
1 parent 873d81a commit cbd9f55

File tree

4 files changed

+74
-72
lines changed

4 files changed

+74
-72
lines changed

.buildkite/JuliaProject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[extras]
2+
HDF5_jll = "0234f1f7-429e-5d53-9886-15a909be8d59"
3+
MPIPreferences = "3da0fdf6-3ccc-4f1b-acd9-58baa6c99267"
4+
5+
[preferences.HDF5_jll]
6+
libhdf5_path = "libhdf5"
7+
libhdf5_hl_path = "libhdf5_hl"
8+
9+
[preferences.MPIPreferences]
10+
_format = "1.0"
11+
abi = "OpenMPI"
12+
binary = "system"
13+
libmpi = "libmpi"
14+
mpiexec = "mpiexec"

.buildkite/pipeline.yml

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1+
2+
agents:
3+
queue: central
4+
slurm_mem: 8G
5+
modules: julia/1.8.5 openmpi/4.1.1 cuda/11.3 hdf5/1.12.1-ompi411
6+
17
env:
2-
JULIA_VERSION: "1.8.3"
3-
CUDA_VERSION: "11.2"
4-
OPENMPI_VERSION: "4.1.1"
8+
JULIA_LOAD_PATH: "${JULIA_LOAD_PATH}:${BUILDKITE_BUILD_CHECKOUT_PATH}/.buildkite"
9+
JULIA_CUDA_USE_BINARYBUILDER: false
510
OPENBLAS_NUM_THREADS: 1
6-
CLIMATEMACHINE_SETTINGS_FIX_RNG_SEED: "true"
711

812
steps:
913
- label: "init cpu env"
1014
key: "init_cpu_env"
1115
command:
12-
- echo "--- Configure MPI"
13-
- julia -e 'using Pkg; Pkg.add("MPIPreferences"); using MPIPreferences; use_system_binary()'
14-
1516
- echo "--- Instantiate project"
1617
- "julia --project -e 'using Pkg; Pkg.instantiate(;verbose=true); Pkg.precompile(;strict=true)'"
18+
- "julia --project -e 'using CUDA; CUDA.precompile_runtime()'"
1719

1820
- echo "--- Instantiate test"
1921
- "julia --project=test -e 'using Pkg; Pkg.develop(path=\".\"); Pkg.instantiate(;verbose=true); Pkg.precompile(;strict=true)'"
@@ -23,85 +25,38 @@ steps:
2325

2426
- echo "--- Package status"
2527
- "julia --project -e 'using Pkg; Pkg.status()'"
26-
2728
agents:
28-
config: cpu
29-
queue: central
30-
slurm_ntasks: 1
31-
32-
# - label: "init gpu env"
33-
# key: "init_gpu_env"
34-
# command:
35-
# - echo "--- Configure MPI"
36-
# - julia -e 'using Pkg; Pkg.add("MPIPreferences"); using MPIPreferences; use_system_binary()'
37-
38-
# - echo "--- Instantiate project"
39-
# - "julia --project -e 'using Pkg; Pkg.instantiate(;verbose=true); Pkg.precompile(;strict=true)'"
40-
41-
# - echo "--- Instantiate test"
42-
# - "julia --project=test -e 'using Pkg; Pkg.develop(path=\".\"); Pkg.instantiate(;verbose=true); Pkg.precompile()'"
43-
44-
# - echo "--- Initialize CUDA runtime"
45-
# - "julia --project -e 'using CUDA; CUDA.precompile_runtime(); CUDA.versioninfo()'"
46-
47-
# - echo "--- Package status"
48-
# - "julia --project -e 'using Pkg; Pkg.status()'"
49-
# agents:
50-
# config: gpu
51-
# queue: central
52-
# slurm_ntasks: 1
53-
# slurm_gres: "gpu:1"
29+
slurm_cpus_per_task: 8
30+
env:
31+
JULIA_NUM_PRECOMPILE_TASKS: 8
5432

5533
- wait
5634

5735
- label: "CPU tests"
5836
command:
5937
- "julia --project=test --check-bounds=yes test/runtests.jl"
6038
artifact_paths: "output/*"
61-
agents:
62-
config: cpu
63-
queue: central
64-
slurm_ntasks: 1
65-
66-
# - label: "GPU tests"
67-
# command:
68-
# - "julia --project=test --check-bounds=yes test/runtests.jl CuArray"
69-
# artifact_paths: "output/*"
70-
# agents:
71-
# config: gpu
72-
# queue: central
73-
# slurm_ntasks: 1
74-
# slurm_gres: "gpu:1"
7539

7640
- label: "Flame graph (1D diffusion)"
7741
command:
7842
- "julia --project=perf perf/flame.jl --job_id diffusion_1D"
7943
artifact_paths: "diffusion_1D/*"
80-
agents:
81-
config: cpu
82-
queue: central
83-
slurm_ntasks: 1
8444

8545
- label: "Jet graph (ode fun)"
8646
command:
8747
- "julia --project=perf perf/jet.jl --problem ode_fun"
88-
agents:
89-
config: cpu
90-
queue: central
91-
slurm_ntasks: 1
9248

9349
- label: "Jet (forward euler)"
9450
command:
9551
- "julia --project=perf perf/jet.jl --problem fe"
96-
agents:
97-
config: cpu
98-
queue: central
99-
slurm_ntasks: 1
10052

10153
- label: "Benchmark"
10254
command:
10355
- "julia --project=perf perf/benchmark.jl"
56+
57+
- label: "GPU tests"
58+
command:
59+
- julia --project=test --check-bounds=yes test/simple_gpu.jl
60+
artifact_paths: "output/*"
10461
agents:
105-
config: cpu
106-
queue: central
107-
slurm_ntasks: 1
62+
slurm_gpus: 1

test/problems.jl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ u(t) = u_0 e^{αt}
2121
2222
This is an in-place variant of the one from DiffEqProblemLibrary.jl.
2323
"""
24-
function linear_prob()
24+
function linear_prob(::Type{ArrayType} = Array) where {ArrayType}
2525
ODEProblem(
2626
IncrementingODEFunction{true}((du, u, p, t, α = true, β = false) -> (du .= α .* p .* u .+ β .* du)),
27-
[1 / 2],
27+
ArrayType([1 / 2]),
2828
(0.0, 1.0),
2929
1.01,
3030
)
3131
end
32-
function linear_prob_fe()
33-
ODEProblem(ForwardEulerODEFunction((un, u, p, t, dt) -> (un .= u .+ dt .* p .* u)), [1.0], (0.0, 1.0), -0.2)
32+
function linear_prob_fe(::Type{ArrayType} = Array) where {ArrayType}
33+
ODEProblem(
34+
ForwardEulerODEFunction((un, u, p, t, dt) -> (un .= u .+ dt .* p .* u)),
35+
ArrayType([1.0]),
36+
(0.0, 1.0),
37+
-0.2,
38+
)
3439
end
3540

3641
function linear_prob_wfactt()
@@ -96,27 +101,29 @@ with initial condition ``u_0=[0,1]``, parameter ``α=2``, and solution
96101
u(t) = [cos(αt) sin(αt); -sin(αt) cos(αt) ] u_0
97102
```
98103
"""
99-
function sincos_prob()
104+
function sincos_prob(::Type{ArrayType} = Array) where {ArrayType}
100105
ODEProblem(
101106
IncrementingODEFunction{true}((du, u, p, t, α = true, β = false) -> (du[1] = α * p * u[2] + β * du[1];
102107
du[2] = -α * p * u[1] + β * du[2])),
103-
[0.0, 1.0],
108+
ArrayType([0.0, 1.0]),
104109
(0.0, 1.0),
105110
2.0,
106111
)
107112
end
108-
function sincos_prob_fe()
113+
function sincos_prob_fe(::Type{ArrayType} = Array) where {ArrayType}
109114
ODEProblem(
110115
ForwardEulerODEFunction((un, u, p, t, dt) -> (un[1] = u[1] + dt * p * u[2]; un[2] = u[2] - dt * p * u[1])),
111-
[0.0, 1.0],
116+
ArrayType([0.0, 1.0]),
112117
(0.0, 1.0),
113118
2.0,
114119
)
115120
end
116121

117122
function sincos_sol(u0, p, t)
118123
s, c = sincos(p * t)
119-
[c s; -s c] * u0
124+
SC = similar(u0, (2, 2))
125+
copyto!(SC, [c s; -s c])
126+
return SC * u0
120127
end
121128

122129
"""

test/simple_gpu.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using ClimaTimeSteppers, LinearAlgebra, Test, CUDA
2+
3+
include(joinpath(@__DIR__, "convergence_orders.jl"))
4+
include(joinpath(@__DIR__, "convergence_utils.jl"))
5+
include(joinpath(@__DIR__, "utils.jl"))
6+
include(joinpath(@__DIR__, "problems.jl"))
7+
8+
9+
@testset "LSRK and SSP convergence" begin
10+
dts = 0.5 .^ (4:7)
11+
12+
for (prob, sol, tscale) in [
13+
(linear_prob(CuArray), linear_sol, 1)
14+
(sincos_prob(CuArray), sincos_sol, 1)
15+
]
16+
17+
@test convergence_order(prob, sol, LSRKEulerMethod(), dts .* tscale) 1 atol = 0.1
18+
@test convergence_order(prob, sol, LSRK54CarpenterKennedy(), dts .* tscale) 4 atol = 0.05
19+
@test convergence_order(prob, sol, LSRK144NiegemannDiehlBusch(), dts .* tscale) 4 atol = 0.05
20+
21+
@test convergence_order(prob, sol, SSPRK22Heuns(), dts .* tscale) 2 atol = 0.05
22+
@test convergence_order(prob, sol, SSPRK22Ralstons(), dts .* tscale) 2 atol = 0.05
23+
@test convergence_order(prob, sol, SSPRK33ShuOsher(), dts .* tscale) 3 atol = 0.05
24+
@test convergence_order(prob, sol, SSPRK34SpiteriRuuth(), dts .* tscale) 3 atol = 0.05
25+
end
26+
end

0 commit comments

Comments
 (0)