Skip to content

Commit aaec9ef

Browse files
committed
update tests for GPU
2 parents ca67975 + 15990ea commit aaec9ef

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

.buildkite/pipeline.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ steps:
3737
- "julia --project=test --check-bounds=yes test/runtests.jl"
3838
artifact_paths: "output/*"
3939

40-
- label: "GPU tests"
41-
command:
42-
- "julia --project=test --check-bounds=yes test/runtests.jl CuArray"
43-
artifact_paths: "output/*"
44-
agents:
45-
slurm_gpus: 1
46-
4740
- label: "Flame graph (1D diffusion)"
4841
command:
4942
- "julia --project=perf perf/flame.jl --job_id diffusion_1D"
@@ -60,3 +53,10 @@ steps:
6053
- label: "Benchmark"
6154
command:
6255
- "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/*"
61+
agents:
62+
slurm_gpus: 1

test/problems.jl

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DiffEqBase, ClimaTimeSteppers, LinearAlgebra, StaticArrays
22
using ClimaCore
3+
import ClimaCore.Device as Device
34
import ClimaCore.Domains as Domains
45
import ClimaCore.Geometry as Geometry
56
import ClimaCore.Meshes as Meshes
@@ -21,16 +22,21 @@ u(t) = u_0 e^{αt}
2122
2223
This is an in-place variant of the one from DiffEqProblemLibrary.jl.
2324
"""
24-
function linear_prob()
25+
function linear_prob(::Type{ArrayType} = Array) where {ArrayType}
2526
ODEProblem(
2627
IncrementingODEFunction{true}((du, u, p, t, α = true, β = false) -> (du .= α .* p .* u .+ β .* du)),
27-
[1 / 2],
28+
ArrayType([1 / 2]),
2829
(0.0, 1.0),
2930
1.01,
3031
)
3132
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)
33+
function linear_prob_fe(::Type{ArrayType} = Array) where {ArrayType}
34+
ODEProblem(
35+
ForwardEulerODEFunction((un, u, p, t, dt) -> (un .= u .+ dt .* p .* u)),
36+
ArrayType([1.0]),
37+
(0.0, 1.0),
38+
-0.2,
39+
)
3440
end
3541

3642
function linear_prob_wfactt()
@@ -96,27 +102,29 @@ with initial condition ``u_0=[0,1]``, parameter ``α=2``, and solution
96102
u(t) = [cos(αt) sin(αt); -sin(αt) cos(αt) ] u_0
97103
```
98104
"""
99-
function sincos_prob()
105+
function sincos_prob(::Type{ArrayType} = Array) where {ArrayType}
100106
ODEProblem(
101107
IncrementingODEFunction{true}((du, u, p, t, α = true, β = false) -> (du[1] = α * p * u[2] + β * du[1];
102108
du[2] = -α * p * u[1] + β * du[2])),
103-
[0.0, 1.0],
109+
ArrayType([0.0, 1.0]),
104110
(0.0, 1.0),
105111
2.0,
106112
)
107113
end
108-
function sincos_prob_fe()
114+
function sincos_prob_fe(::Type{ArrayType} = Array) where {ArrayType}
109115
ODEProblem(
110116
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],
117+
ArrayType([0.0, 1.0]),
112118
(0.0, 1.0),
113119
2.0,
114120
)
115121
end
116122

117123
function sincos_sol(u0, p, t)
118124
s, c = sincos(p * t)
119-
[c s; -s c] * u0
125+
SC = similar(u0, (2, 2))
126+
copyto!(SC, [c s; -s c])
127+
return SC * u0
120128
end
121129

122130
"""
@@ -428,9 +436,16 @@ end
428436
429437
2D diffusion test problem. See [`2D diffusion problem`](@ref) for more details.
430438
"""
431-
function climacore_2Dheat_test_cts(::Type{FT}) where {FT}
439+
function climacore_2Dheat_test_cts(::Type{FT}; print_arr_type = false) where {FT}
432440
dss_tendency = true
433441

442+
device = Device.device()
443+
context = ClimaComms.SingletonCommsContext(device)
444+
445+
if print_arr_type
446+
@info "Array type: $(Device.device_array_type(device))"
447+
end
448+
434449
n_elem_x = 2
435450
n_elem_y = 2
436451
n_poly = 2
@@ -445,13 +460,17 @@ function climacore_2Dheat_test_cts(::Type{FT}) where {FT}
445460
Domains.IntervalDomain(Geometry.YPoint(FT(0)), Geometry.YPoint(FT(1)), periodic = true),
446461
)
447462
mesh = Meshes.RectilinearMesh(domain, n_elem_x, n_elem_y)
448-
topology = Topologies.Topology2D(mesh)
463+
topology = Topologies.Topology2D(context, mesh)
449464
quadrature = Spaces.Quadratures.GLL{n_poly + 1}()
450465
space = Spaces.SpectralElementSpace2D(topology, quadrature)
451466
(; x, y) = Fields.coordinate_field(space)
452467

453468
λ = (2 * FT(π))^2 * (n_x^2 + n_y^2)
454-
φ_sin_sin = @. sin(2 * FT(π) * n_x * x) * sin(2 * FT(π) * n_y * y)
469+
470+
# Revert once https://github.com/CliMA/ClimaCore.jl/issues/1097
471+
# is fixed
472+
# φ_sin_sin = @. sin(2 * FT(π) * n_x * x) * sin(2 * FT(π) * n_y * y)
473+
φ_sin_sin = @. sin(2 * π * n_x * x) * sin(2 * π * n_y * y)
455474

456475
init_state = Fields.FieldVector(; u = φ_sin_sin)
457476

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)