Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Dec 23, 2024
1 parent 92f3b2b commit 9c6d01c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/DataLayouts/DataLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export slab,
VIHF,
DataF

# Internal types for managing CPU/GPU dispatching
# Internal types for managing CPU/GPU dispatching / conversions
abstract type AbstractDispatchToDevice end
struct ToCPU <: AbstractDispatchToDevice end
struct ToCUDA <: AbstractDispatchToDevice end
Expand Down
39 changes: 39 additions & 0 deletions test/Spaces/unit_spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,45 @@ end
end
end

using ClimaCore.CommonSpaces
using ClimaCore.Grids
using ClimaCore.DataLayouts: ToCPU, ToCUDA
using Adapt
@testset "Adapt between CPU<->CPU" begin
cpu_space_in = ExtrudedCubedSphereSpace(;
device = ClimaComms.CPUSingleThreaded(),
z_elem = 10,
z_min = 0,
z_max = 1,
radius = 10,
h_elem = 10,
n_quad_points = 4,
staggering = Grids.CellCenter()
)
cpu_space_out = Adapt.adapt(ToCPU(), cpu_space_in)
@test cpu_space_in === cpu_space_out
end

if ClimaComms.device() isa ClimaComms.CUDADevice
@testset "Adapt between CPU->GPU->CPU" begin
cpu_space_in = ExtrudedCubedSphereSpace(;
device = ClimaComms.CPUSingleThreaded(),
z_elem = 10,
z_min = 0,
z_max = 1,
radius = 10,
h_elem = 10,
n_quad_points = 4,
staggering = Grids.CellCenter()
)
cpu_space_out = Adapt.adapt(ToCPU(), cpu_space_in)
@test cpu_space_in === cpu_space_out
gpu_space_out = Adapt.adapt(ToCUDA(), cpu_space_in)
gpu_array_type = ClimaComms.array_type(ClimaComms.CUDADevice())
@test parent(Spaces.coordinates_data(space)) isa gpu_array_type

end
end

#=
@testset "dss on 2×2 rectangular mesh (unstructured)" begin
Expand Down

0 comments on commit 9c6d01c

Please sign in to comment.