Skip to content

Commit 69a3969

Browse files
authored
Merge pull request #739 from CliMA/js/gpu_tests
tests on GPU - parent usage
2 parents 897515e + 5d7975a commit 69a3969

10 files changed

+69
-61
lines changed

.buildkite/pipeline.yml

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ steps:
133133
agents:
134134
slurm_mem: 16GB
135135

136+
- group: "GPU: unit tests and global bucket"
137+
steps:
138+
- label: "GPU runtests"
139+
command: "julia --color=yes --project=test/ test/runtests.jl"
140+
agents:
141+
slurm_ntasks: 1
142+
slurm_gres: "gpu:1"
143+
136144
- group: "Integration Tests"
137145
steps:
138146

test/checkpointer_tests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Checkpointer.get_model_prog_state(sim::DummySimulation) = sim.state
2020
end
2121

2222
@testset "checkpoint_model_state, restart_model_state!" begin
23-
boundary_space = TestHelper.create_space(FT)
24-
t = 1
2523
comms_ctx = ClimaComms.context(ClimaComms.CPUSingleThreaded())
24+
boundary_space = TestHelper.create_space(FT; comms_ctx = comms_ctx)
25+
t = 1
2626
# old sim run
2727
sim = DummySimulation(CC.Fields.FieldVector(T = ones(boundary_space)))
2828
Checkpointer.checkpoint_model_state(sim, comms_ctx, t, output_dir = "test_checkpoint")

test/component_model_tests/bucket_tests.jl

+6-7
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ for FT in (Float32, Float64)
2828
),
2929
t = FT(0),
3030
)
31-
integrator_copy = deepcopy(integrator)
3231
sim = BucketSimulation(nothing, nothing, nothing, integrator, nothing)
3332

3433
# make fields non-constant to check the impact of the dss step
35-
for i in eachindex(parent(sim.integrator.u.state_field_2d))
36-
parent(sim.integrator.u.state_field_2d)[i] = sin(i)
37-
end
38-
for i in eachindex(parent(sim.integrator.u.state_field_3d))
39-
parent(sim.integrator.u.state_field_3d)[i] = sin(i)
40-
end
34+
coords_lat = CC.Fields.coordinate_field(sim.integrator.u.state_field_2d).lat
35+
@. sim.integrator.u.state_field_2d = sin(coords_lat)
36+
37+
coords_lat = CC.Fields.coordinate_field(sim.integrator.u.state_field_3d).lat
38+
@. sim.integrator.u.state_field_3d = sin(coords_lat)
4139

4240
# apply DSS
41+
integrator_copy = deepcopy(integrator)
4342
dss_state!(sim)
4443

4544
# test that uniform field and cache are unchanged, non-constant is changed

test/component_model_tests/climaatmos_tests.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ for FT in (Float32, Float64)
1818
),
1919
p = (; cache_field = FT.(CC.Fields.zeros(boundary_space))),
2020
)
21-
integrator_copy = deepcopy(integrator)
2221
sim = ClimaAtmosSimulation(nothing, nothing, nothing, integrator)
2322

2423
# make field non-constant to check the impact of the dss step
25-
for i in eachindex(parent(sim.integrator.u.state_field2))
26-
parent(sim.integrator.u.state_field2)[i] = FT(sin(i))
27-
end
24+
coords_lat = CC.Fields.coordinate_field(sim.integrator.u.state_field2).lat
25+
@. sim.integrator.u.state_field2 = sin(coords_lat)
2826

27+
integrator_copy = deepcopy(integrator)
2928
# apply DSS
3029
dss_state!(sim)
3130

test/component_model_tests/prescr_seaice_tests.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,14 @@ for FT in (Float32, Float64)
7575
),
7676
p = (; cache_field = FT.(CC.Fields.zeros(boundary_space)), dss_buffer = dss_buffer),
7777
)
78-
integrator_copy = deepcopy(integrator)
7978
sim = PrescribedIceSimulation(nothing, nothing, nothing, integrator)
8079

8180
# make field non-constant to check the impact of the dss step
82-
for i in eachindex(parent(sim.integrator.u.state_field2))
83-
parent(sim.integrator.u.state_field2)[i] = FT(sin(i))
84-
end
81+
coords_lat = CC.Fields.coordinate_field(sim.integrator.u.state_field2).lat
82+
@. sim.integrator.u.state_field2 = sin(coords_lat)
8583

8684
# apply DSS
85+
integrator_copy = deepcopy(integrator)
8786
dss_state!(sim)
8887

8988
# test that uniform field and cache are unchanged, non-constant is changed

test/component_model_tests/slab_ocean_tests.jl

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ for FT in (Float32, Float64)
2121
),
2222
p = (; cache_field = FT.(CC.Fields.zeros(boundary_space)), dss_buffer = dss_buffer),
2323
)
24-
integrator_copy = deepcopy(integrator)
2524
sim = SlabOceanSimulation(nothing, nothing, nothing, integrator)
2625

2726
# make field non-constant to check the impact of the dss step
28-
for i in eachindex(parent(sim.integrator.u.state_field2))
29-
parent(sim.integrator.u.state_field2)[i] = FT(sin(i))
30-
end
27+
coords_lat = CC.Fields.coordinate_field(sim.integrator.u.state_field2).lat
28+
@. sim.integrator.u.state_field2 = sin(coords_lat)
3129

3230
# apply DSS
31+
integrator_copy = deepcopy(integrator)
3332
dss_state!(sim)
3433

3534
# test that uniform field and cache are unchanged, non-constant is changed

test/field_exchanger_tests.jl

+25-25
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ for FT in (Float32, Float64)
105105
coupler_fields =
106106
NamedTuple{coupler_names}(ntuple(i -> CC.Fields.zeros(boundary_space), length(coupler_names)))
107107
FieldExchanger.import_atmos_fields!(coupler_fields, model_sims, boundary_space, t)
108-
@test parent(coupler_fields.F_turb_energy)[1] == results[i]
109-
@test parent(coupler_fields.F_turb_moisture)[1] == results[i]
110-
@test parent(coupler_fields.F_radiative)[1] == results[1]
111-
@test parent(coupler_fields.P_liq)[1] == results[1]
112-
@test parent(coupler_fields.P_snow)[1] == results[1]
108+
@test Array(parent(coupler_fields.F_turb_energy))[1] == results[i]
109+
@test Array(parent(coupler_fields.F_turb_moisture))[1] == results[i]
110+
@test Array(parent(coupler_fields.F_radiative))[1] == results[1]
111+
@test Array(parent(coupler_fields.P_liq))[1] == results[1]
112+
@test Array(parent(coupler_fields.P_snow))[1] == results[1]
113113
end
114114
end
115115

@@ -138,12 +138,12 @@ for FT in (Float32, Float64)
138138
coupler_fields =
139139
NamedTuple{coupler_names}(ntuple(i -> CC.Fields.zeros(boundary_space), length(coupler_names)))
140140
FieldExchanger.import_combined_surface_fields!(coupler_fields, sims, boundary_space, t)
141-
@test parent(coupler_fields.T_S)[1] == results[1]
142-
@test parent(coupler_fields.surface_direct_albedo)[1] == results[1]
143-
@test parent(coupler_fields.surface_diffuse_albedo)[1] == results[1]
144-
@test parent(coupler_fields.z0m_S)[1] == results[i]
145-
@test parent(coupler_fields.z0b_S)[1] == results[i]
146-
@test parent(coupler_fields.beta)[1] == results[i]
141+
@test Array(parent(coupler_fields.T_S))[1] == results[1]
142+
@test Array(parent(coupler_fields.surface_direct_albedo))[1] == results[1]
143+
@test Array(parent(coupler_fields.surface_diffuse_albedo))[1] == results[1]
144+
@test Array(parent(coupler_fields.z0m_S))[1] == results[i]
145+
@test Array(parent(coupler_fields.z0b_S))[1] == results[i]
146+
@test Array(parent(coupler_fields.beta))[1] == results[i]
147147
end
148148
end
149149

@@ -203,31 +203,31 @@ for FT in (Float32, Float64)
203203
FieldExchanger.update_model_sims!(model_sims, coupler_fields, t)
204204

205205
# test atmos
206-
@test parent(model_sims.atmos_sim.cache.albedo_direct)[1] == results[2]
207-
@test parent(model_sims.atmos_sim.cache.albedo_diffuse)[1] == results[3]
206+
@test Array(parent(model_sims.atmos_sim.cache.albedo_direct))[1] == results[2]
207+
@test Array(parent(model_sims.atmos_sim.cache.albedo_diffuse))[1] == results[3]
208208
if t isa FluxCalculator.CombinedStateFluxes
209-
@test parent(model_sims.atmos_sim.cache.roughness_momentum)[1] == results[2]
209+
@test Array(parent(model_sims.atmos_sim.cache.roughness_momentum))[1] == results[2]
210210
else
211-
@test parent(model_sims.atmos_sim.cache.roughness_momentum)[1] == results[1]
211+
@test Array(parent(model_sims.atmos_sim.cache.roughness_momentum))[1] == results[1]
212212
end
213213

214214
# unspecified variables
215-
@test parent(model_sims.atmos_sim.cache.surface_temperature)[1] == results[1]
216-
@test parent(model_sims.atmos_sim.cache.beta)[1] == results[1]
217-
@test parent(model_sims.atmos_sim.cache.roughness_buoyancy)[1] == results[1]
215+
@test Array(parent(model_sims.atmos_sim.cache.surface_temperature))[1] == results[1]
216+
@test Array(parent(model_sims.atmos_sim.cache.beta))[1] == results[1]
217+
@test Array(parent(model_sims.atmos_sim.cache.roughness_buoyancy))[1] == results[1]
218218

219219
# test surface
220-
@test parent(model_sims.land_sim.cache.turbulent_energy_flux)[1] == results[2] # assuming units / m2
221-
@test parent(model_sims.land_sim.cache.turbulent_moisture_flux)[1] == results[2]
220+
@test Array(parent(model_sims.land_sim.cache.turbulent_energy_flux))[1] == results[2] # assuming units / m2
221+
@test Array(parent(model_sims.land_sim.cache.turbulent_moisture_flux))[1] == results[2]
222222

223223
# unspecified variables
224-
@test parent(model_sims.land_sim.cache.radiative_energy_flux_sfc)[1] == results[1]
225-
@test parent(model_sims.land_sim.cache.liquid_precipitation)[1] == results[1]
226-
@test parent(model_sims.land_sim.cache.snow_precipitation)[1] == results[1]
224+
@test Array(parent(model_sims.land_sim.cache.radiative_energy_flux_sfc))[1] == results[1]
225+
@test Array(parent(model_sims.land_sim.cache.liquid_precipitation))[1] == results[1]
226+
@test Array(parent(model_sims.land_sim.cache.snow_precipitation))[1] == results[1]
227227

228228
# test stub - albedo should be updated by update_sim!
229-
@test parent(model_sims.stub_sim.cache.albedo_direct)[1] == results[2]
230-
@test parent(model_sims.stub_sim.cache.albedo_diffuse)[1] == results[2]
229+
@test Array(parent(model_sims.stub_sim.cache.albedo_direct))[1] == results[2]
230+
@test Array(parent(model_sims.stub_sim.cache.albedo_diffuse))[1] == results[2]
231231

232232
end
233233
end

test/flux_calculator_tests.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Test: @test, @testset, @test_throws
22
import StaticArrays
33
import ClimaCore as CC
4+
import ClimaParams
45
import Thermodynamics as TD
56
import Thermodynamics.Parameters.ThermodynamicsParameters
67
import SurfaceFluxes.Parameters.SurfaceFluxesParameters
@@ -149,7 +150,7 @@ for FT in (Float32, Float64)
149150
for (i, t) in enumerate(flux_types)
150151
sim.cache.flux .= FT(0)
151152
FluxCalculator.combined_turbulent_fluxes!(model_sims, coupler_fields, t)
152-
@test parent(sim.cache.flux)[1] results[i]
153+
@test Array(parent(sim.cache.flux))[1] results[i]
153154
end
154155
sim2 = DummySimulation2((; cache = (; flux = zeros(boundary_space))))
155156
model_sims = (; atmos_sim = sim2)
@@ -270,7 +271,7 @@ for FT in (Float32, Float64)
270271
@test parent(fields.F_turb_energy[colidx]) == -parent(atmos_sim.integrator.p.energy_bc[colidx])
271272

272273
end
273-
@test parent(fields.F_turb_moisture)[1] FT(0)
274+
@test Array(parent(fields.F_turb_moisture))[1] FT(0)
274275
end
275276
end
276277

test/interfacer_tests.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ for FT in (Float32, Float64)
5757
for sim in (DummySimulation(space), DummySimulation2(space), DummySimulation3(space))
5858
# field
5959
colidx = CC.Fields.ColumnIndex{2}((1, 1), 73)
60-
@test parent(Interfacer.get_field(sim, Val(:var), colidx))[1] == FT(1)
60+
@test Array(parent(Interfacer.get_field(sim, Val(:var), colidx)))[1] == FT(1)
6161
# float
6262
@test Interfacer.get_field(sim, Val(:var_float), colidx) == FT(2)
6363
end
@@ -108,10 +108,10 @@ for FT in (Float32, Float64)
108108
Interfacer.update_field!(stub, Val(:surface_direct_albedo), ones(boundary_space) .* 3)
109109
Interfacer.update_field!(stub, Val(:surface_diffuse_albedo), ones(boundary_space) .* 4)
110110

111-
@test parent(Interfacer.get_field(stub, Val(:area_fraction)))[1] == FT(1)
112-
@test parent(Interfacer.get_field(stub, Val(:surface_temperature)))[1] == FT(2)
113-
@test parent(Interfacer.get_field(stub, Val(:surface_direct_albedo)))[1] == FT(3)
114-
@test parent(Interfacer.get_field(stub, Val(:surface_diffuse_albedo)))[1] == FT(4)
111+
@test Array(parent(Interfacer.get_field(stub, Val(:area_fraction))))[1] == FT(1)
112+
@test Array(parent(Interfacer.get_field(stub, Val(:surface_temperature))))[1] == FT(2)
113+
@test Array(parent(Interfacer.get_field(stub, Val(:surface_direct_albedo))))[1] == FT(3)
114+
@test Array(parent(Interfacer.get_field(stub, Val(:surface_diffuse_albedo))))[1] == FT(4)
115115
end
116116
end
117117

test/runtests.jl

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import SafeTestsets: @safetestset
2+
import ClimaComms
3+
4+
gpu_broken = ClimaComms.device() isa ClimaComms.CUDADevice
25

36
@safetestset "Aqua tests" begin
47
include("aqua.jl")
58
end
69
@safetestset "Interfacer tests" begin
710
include("interfacer_tests.jl")
811
end
9-
@safetestset "Regridder tests" begin
12+
gpu_broken || @safetestset "Regridder tests" begin
1013
include("regridder_tests.jl")
1114
end
1215
@safetestset "ConservationChecker tests" begin
1316
include("conservation_checker_tests.jl")
1417
end
15-
@safetestset "BCReader tests" begin
18+
gpu_broken || @safetestset "BCReader tests" begin
1619
include("bcreader_tests.jl")
1720
end
1821
@safetestset "Utilities tests" begin
@@ -24,19 +27,19 @@ end
2427
@safetestset "FieldExchanger tests" begin
2528
include("field_exchanger_tests.jl")
2629
end
27-
@safetestset "FluxCalculator tests" begin
30+
gpu_broken || @safetestset "FluxCalculator tests" begin
2831
include("flux_calculator_tests.jl")
2932
end
30-
@safetestset "Diagnostics tests" begin
33+
gpu_broken || @safetestset "Diagnostics tests" begin
3134
include("diagnostics_tests.jl")
3235
end
33-
@safetestset "PostProcessor tests" begin
36+
gpu_broken || @safetestset "PostProcessor tests" begin
3437
include("postprocessor_tests.jl")
3538
end
3639
@safetestset "Checkpointer tests" begin
3740
include("checkpointer_tests.jl")
3841
end
39-
@safetestset "experiment test: CoupledSims tests" begin
42+
gpu_broken || @safetestset "experiment test: CoupledSims tests" begin
4043
include("experiment_tests/coupled_sims.jl")
4144
end
4245
@safetestset "experiment test: Leaderboard" begin
@@ -51,12 +54,12 @@ end
5154
@safetestset "component model test: prescr. sea ice" begin
5255
include("component_model_tests/prescr_seaice_tests.jl")
5356
end
54-
@safetestset "component model test: eisenman sea ice" begin
57+
gpu_broken || @safetestset "component model test: eisenman sea ice" begin
5558
include("component_model_tests/eisenman_seaice_tests.jl")
5659
end
5760
@safetestset "component model test: slab ocean" begin
5861
include("component_model_tests/slab_ocean_tests.jl")
5962
end
60-
@safetestset "debug diagnostics: amip plots" begin
63+
gpu_broken || @safetestset "debug diagnostics: amip plots" begin
6164
include("debug/debug_amip_plots.jl")
6265
end

0 commit comments

Comments
 (0)