Skip to content

Commit 9066a73

Browse files
Refactor cubed sphere dss test
1 parent 1add428 commit 9066a73

File tree

4 files changed

+108
-117
lines changed

4 files changed

+108
-117
lines changed

.buildkite/pipeline.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,21 @@ steps:
278278
key: unit_ddss1
279279
command:
280280
- "julia --project=.buildkite -e 'using CUDA; CUDA.versioninfo()'"
281-
- "julia --color=yes --check-bounds=yes --project=.buildkite test/Spaces/ddss1.jl CUDA"
281+
- "julia --color=yes --check-bounds=yes --project=.buildkite test/Spaces/ddss1.jl"
282282
env:
283283
CLIMACOMMS_DEVICE: "CUDA"
284284
agents:
285285
slurm_gpus: 1
286286

287+
- label: "Unit: ddss1 cs"
288+
key: unit_cuda_ddss1_cs
289+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/Spaces/ddss1_cs.jl"
290+
287291
- label: "Unit: ddss1 cs"
288292
key: unit_ddss1_cs
289293
command:
290294
- "julia --project=.buildkite -e 'using CUDA; CUDA.versioninfo()'"
291-
- "julia --color=yes --check-bounds=yes --project=.buildkite test/Spaces/ddss1_cs.jl CUDA"
295+
- "julia --color=yes --check-bounds=yes --project=.buildkite test/Spaces/ddss1_cs.jl"
292296
env:
293297
CLIMACOMMS_DEVICE: "CUDA"
294298
agents:

test/Spaces/ddss1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#=
2-
julia --project=test
2+
julia --project
33
using Revise; include(joinpath("test", "Spaces", "ddss1.jl"))
44
=#
55
using Logging

test/Spaces/ddss1_cs.jl

Lines changed: 100 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#=
2+
julia --project
3+
using Revise; include(joinpath("test", "Spaces", "ddss1_cs.jl"))
4+
=#
15
using Test
26
using ClimaComms
37
ClimaComms.@import_required_backends
@@ -13,29 +17,68 @@ import ClimaCore:
1317
Topologies,
1418
DataLayouts
1519

16-
@testset "DSS on Equiangular Cubed Sphere mesh (ne = 3, serial run)" begin
17-
device = ClimaComms.device() #ClimaComms.CUDADevice()
18-
context = ClimaComms.SingletonCommsContext(device)
19-
context_cpu =
20-
ClimaComms.SingletonCommsContext(ClimaComms.CPUSingleThreaded())
21-
22-
println("running test on $device device")
23-
24-
domain = Domains.SphereDomain(300.0)
20+
function get_space_cs(::Type{FT}; context, R = 300.0) where {FT}
21+
domain = Domains.SphereDomain{FT}(300.0)
2522
mesh = Meshes.EquiangularCubedSphere(domain, 3)
2623
topology = Topologies.Topology2D(context, mesh)
27-
topology_cpu = Topologies.Topology2D(context_cpu, mesh)
2824
quad = Quadratures.GLL{4}()
2925
space = Spaces.SpectralElementSpace2D(topology, quad)
30-
space_cpu = Spaces.SpectralElementSpace2D(topology_cpu, quad)
26+
return space
27+
end
3128

32-
x = ones(space)
33-
x_cpu = ones(space_cpu)
29+
function get_space_and_buffers(::Type{FT}; context) where {FT}
30+
init_state_covariant12(local_geometry, p) =
31+
Geometry.Covariant12Vector(1.0, -1.0)
32+
init_state_covariant123(local_geometry, p) =
33+
Geometry.Covariant123Vector(1.0, -1.0, 1.0)
34+
35+
R = FT(6.371229e6)
36+
npoly = 2
37+
z_max = FT(30e3)
38+
z_elem = 3
39+
h_elem = 2
40+
device = ClimaComms.device(context)
41+
@info "running dss-Covariant123Vector test on $(device)" h_elem z_elem npoly R z_max FT
42+
# horizontal space
43+
domain = Domains.SphereDomain{FT}(R)
44+
horizontal_mesh = Meshes.EquiangularCubedSphere(domain, h_elem)
45+
horizontal_topology = Topologies.Topology2D(
46+
context,
47+
horizontal_mesh,
48+
Topologies.spacefillingcurve(horizontal_mesh),
49+
)
50+
quad = Quadratures.GLL{npoly + 1}()
51+
h_space = Spaces.SpectralElementSpace2D(horizontal_topology, quad)
52+
# vertical space
53+
z_domain = Domains.IntervalDomain(
54+
Geometry.ZPoint{FT}(zero(z_max)),
55+
Geometry.ZPoint{FT}(z_max);
56+
boundary_names = (:bottom, :top),
57+
)
58+
z_mesh = Meshes.IntervalMesh(z_domain, nelems = z_elem)
59+
z_topology = Topologies.IntervalTopology(context, z_mesh)
60+
z_center_space = Spaces.CenterFiniteDifferenceSpace(z_topology)
61+
space = Spaces.ExtrudedFiniteDifferenceSpace(h_space, z_center_space)
62+
args = (Fields.local_geometry_field(space), Ref(nothing))
63+
y12 = init_state_covariant12.(args...)
64+
y123 = init_state_covariant123.(args...)
65+
dss_buffer12 = Spaces.create_dss_buffer(y12)
66+
dss_buffer123 = Spaces.create_dss_buffer(y123)
67+
return (; space, y12, y123, dss_buffer12, dss_buffer123)
68+
end
3469

70+
@testset "DSS on Equiangular Cubed Sphere mesh (ne = 3, serial run)" begin
71+
FT = Float64
72+
device = ClimaComms.device()
73+
context = ClimaComms.SingletonCommsContext(device)
74+
println("running test on $device device")
75+
space = get_space_cs(FT; context)
76+
space_cpu = get_space_cs(FT; context)
77+
x = ones(space)
3578
Spaces.weighted_dss!(x)
36-
Spaces.weighted_dss!(x_cpu)
3779

38-
@test parent(x_cpu) Array(parent(x))
80+
@test Array(parent(x)) ones(size(parent(x))) # TODO: improve the quality of this test
81+
3982
wrong_field = map(Fields.coordinate_field(space)) do cf
4083
(; a = Float64(0))
4184
end
@@ -60,113 +103,57 @@ end
60103

61104
@testset "DSS of Covariant12Vector & Covariant123Vector on extruded Cubed Sphere mesh (ne = 3, serial run)" begin
62105
FT = Float64
63-
context = ClimaComms.SingletonCommsContext(ClimaComms.CUDADevice())
64-
context_cpu =
65-
ClimaComms.SingletonCommsContext(ClimaComms.CPUSingleThreaded()) # CPU context for comparison
66-
R = FT(6.371229e6)
67-
68-
npoly = 4
69-
z_max = FT(30e3)
70-
z_elem = 10
71-
h_elem = 4
72-
println(
73-
"running dss-Covariant123Vector test on $(context.device); h_elem = $h_elem; z_elem = $z_elem; npoly = $npoly; R = $R; z_max = $z_max; FT = $FT",
74-
)
75-
# horizontal space
76-
domain = Domains.SphereDomain(R)
77-
horizontal_mesh = Meshes.EquiangularCubedSphere(domain, h_elem)
78-
horizontal_topology = Topologies.Topology2D(
79-
context,
80-
horizontal_mesh,
81-
Topologies.spacefillingcurve(horizontal_mesh),
82-
)
83-
horizontal_topology_cpu = Topologies.Topology2D(
84-
context_cpu,
85-
horizontal_mesh,
86-
Topologies.spacefillingcurve(horizontal_mesh),
87-
)
88-
quad = Quadratures.GLL{npoly + 1}()
89-
h_space = Spaces.SpectralElementSpace2D(horizontal_topology, quad)
90-
h_space_cpu = Spaces.SpectralElementSpace2D(horizontal_topology_cpu, quad)
91-
92-
# vertical space
93-
z_domain = Domains.IntervalDomain(
94-
Geometry.ZPoint(zero(z_max)),
95-
Geometry.ZPoint(z_max);
96-
boundary_names = (:bottom, :top),
97-
)
98-
z_mesh = Meshes.IntervalMesh(z_domain, nelems = z_elem)
99-
z_topology = Topologies.IntervalTopology(context, z_mesh)
100-
z_topology_cpu = Topologies.IntervalTopology(context_cpu, z_mesh)
101-
102-
z_center_space = Spaces.CenterFiniteDifferenceSpace(z_topology)
103-
z_center_space_cpu = Spaces.CenterFiniteDifferenceSpace(z_topology_cpu)
104-
105-
hv_center_space =
106-
Spaces.ExtrudedFiniteDifferenceSpace(h_space, z_center_space)
107-
108-
hv_center_space_cpu =
109-
Spaces.ExtrudedFiniteDifferenceSpace(h_space_cpu, z_center_space_cpu)
106+
device = ClimaComms.device()
107+
nt = get_space_and_buffers(FT; context = ClimaComms.context(device))
110108

111109
# test DSS for a Covariant12Vector
112-
init_state_covariant12(local_geometry, p) =
113-
Geometry.Covariant12Vector(1.0, -1.0)
114-
115-
y12 =
116-
init_state_covariant12.(
117-
Fields.local_geometry_field(hv_center_space),
118-
Ref(nothing),
119-
)
120-
y12_cpu =
121-
init_state_covariant12.(
122-
Fields.local_geometry_field(hv_center_space_cpu),
123-
Ref(nothing),
124-
)
125-
126-
dss_buffer12 = Spaces.create_dss_buffer(y12)
127-
dss_buffer12_cpu = Spaces.create_dss_buffer(y12_cpu)
128110
# ensure physical velocity is continous across SE boundary for initial state
129-
Spaces.weighted_dss!(y12 => dss_buffer12)
130-
Spaces.weighted_dss!(y12_cpu => dss_buffer12_cpu)
111+
Spaces.weighted_dss!(nt.y12 => nt.dss_buffer12)
112+
init = copy(nt.y12)
113+
Spaces.weighted_dss!(nt.y12, nt.dss_buffer12)
114+
@test init nt.y12
115+
# ensure physical velocity is continous across SE boundary for initial state
116+
Spaces.weighted_dss!(nt.y123, nt.dss_buffer123)
117+
init = copy(nt.y123)
118+
Spaces.weighted_dss!(nt.y123, nt.dss_buffer123)
119+
@test init nt.y123
120+
end
131121

132-
yinit12 = copy(y12)
133-
yinit12_cpu = copy(y12_cpu)
122+
# TODO: remove once the quality of the above test is improved
123+
(ClimaComms.device() isa ClimaComms.CUDADevice) &&
124+
@testset "GPU-vs-CPU test: DSS of Covariant12Vector & Covariant123Vector on extruded Cubed Sphere mesh (ne = 3, serial run)" begin
125+
FT = Float64
126+
cpu_device = ClimaComms.CPUSingleThreaded()
127+
gpu_device = ClimaComms.CUDADevice()
128+
gpu =
129+
get_space_and_buffers(FT; context = ClimaComms.context(gpu_device))
130+
cpu =
131+
get_space_and_buffers(FT; context = ClimaComms.context(cpu_device))
134132

135-
Spaces.weighted_dss!(y12, dss_buffer12)
136-
Spaces.weighted_dss!(y12_cpu, dss_buffer12_cpu)
137-
@test yinit12 y12
138-
@test yinit12_cpu y12_cpu
139-
@test parent(y12_cpu) Array(parent(y12))
133+
# test DSS for a Covariant12Vector
134+
# ensure physical velocity is continous across SE boundary for initial state
135+
Spaces.weighted_dss!(cpu.y12 => cpu.dss_buffer12)
136+
Spaces.weighted_dss!(gpu.y12 => gpu.dss_buffer12)
140137

141-
# test DSS for a Covariant123Vector
142-
init_state_covariant123(local_geometry, p) =
143-
Geometry.Covariant123Vector(1.0, -1.0, 1.0)
138+
inity12 = (; cpu = copy(cpu.y12), gpu = copy(gpu.y12))
144139

145-
y123 =
146-
init_state_covariant123.(
147-
Fields.local_geometry_field(hv_center_space),
148-
Ref(nothing),
149-
)
150-
y123_cpu =
151-
init_state_covariant123.(
152-
Fields.local_geometry_field(hv_center_space_cpu),
153-
Ref(nothing),
154-
)
140+
Spaces.weighted_dss!(cpu.y12, cpu.dss_buffer12)
141+
Spaces.weighted_dss!(gpu.y12, gpu.dss_buffer12)
155142

156-
dss_buffer123 = Spaces.create_dss_buffer(y123)
157-
dss_buffer123_cpu = Spaces.create_dss_buffer(y123_cpu)
143+
@test inity12.cpu cpu.y12
144+
@test inity12.gpu gpu.y12
145+
@test parent(cpu.y12) Array(parent(gpu.y12))
158146

159-
# ensure physical velocity is continous across SE boundary for initial state
160-
Spaces.weighted_dss!(y123, dss_buffer123)
161-
Spaces.weighted_dss!(y123_cpu, dss_buffer123_cpu)
147+
# ensure physical velocity is continous across SE boundary for initial state
148+
Spaces.weighted_dss!(cpu.y123, cpu.dss_buffer123)
149+
Spaces.weighted_dss!(gpu.y123, gpu.dss_buffer123)
162150

163-
yinit123 = copy(y123)
164-
yinit123_cpu = copy(y123_cpu)
151+
inity123 = (; cpu = copy(cpu.y123), gpu = copy(gpu.y123))
165152

166-
Spaces.weighted_dss!(y123, dss_buffer123)
167-
Spaces.weighted_dss!(y123_cpu, dss_buffer123_cpu)
153+
Spaces.weighted_dss!(cpu.y123, cpu.dss_buffer123)
154+
Spaces.weighted_dss!(gpu.y123, gpu.dss_buffer123)
168155

169-
@test yinit123 y123
170-
@test yinit123_cpu y123_cpu
171-
@test parent(y123_cpu) Array(parent(y123))
172-
end
156+
@test inity123.cpu cpu.y123
157+
@test inity123.gpu gpu.y123
158+
@test parent(cpu.y123) Array(parent(gpu.y123))
159+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ UnitTest("Cubedsphere surface topology" ,"Topologies/cubedsphere_sfc.
3333
UnitTest("Quadratures" ,"Quadratures/Quadratures.jl"),
3434
UnitTest("Spaces" ,"Spaces/unit_spaces.jl"),
3535
UnitTest("Spaces - serial CPU DSS" ,"Spaces/ddss1.jl"),
36+
UnitTest("Spaces - DSS cubed sphere" ,"Spaces/ddss1_cs.jl"),
3637
UnitTest("Sphere spaces" ,"Spaces/sphere.jl"),
3738
# UnitTest("Terrain warp" ,"Spaces/terrain_warp.jl"), # appears to hang on GHA
3839
UnitTest("Fields" ,"Fields/unit_field.jl"), # has benchmarks
@@ -107,7 +108,6 @@ UnitTest("Aqua" ,"aqua.jl"),
107108
UnitTest("Deprecations" ,"deprecations.jl"),
108109
UnitTest("GPU - cuda" ,"gpu/cuda.jl";meta=:gpu_only),
109110
UnitTest("GPU - data" ,"DataLayouts/cuda.jl";meta=:gpu_only),
110-
UnitTest("Spaces - serial CUDA DSS on CubedSphere" ,"Spaces/ddss1_cs.jl";meta=:gpu_only),
111111
UnitTest("Operators - spectral element CUDA" ,"Operators/spectralelement/rectilinear_cuda.jl";meta=:gpu_only),
112112
UnitTest("Operators - finite difference CUDA" ,"Operators/hybrid/unit_cuda.jl";meta=:gpu_only),
113113
UnitTest("Operators - extruded sphere space ops" ,"Operators/hybrid/extruded_sphere_cuda.jl";meta=:gpu_only),

0 commit comments

Comments
 (0)