-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e30fd8
commit 60d9d37
Showing
8 changed files
with
248 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
import ClimaCore: | ||
ClimaCore, | ||
DataLayouts, | ||
Geometry, | ||
Topologies, | ||
Quadratures, | ||
Grids, | ||
Spaces, | ||
Fields, | ||
Operators, | ||
Hypsography, | ||
slab | ||
import ClimaComms | ||
import CUDA | ||
import StaticArrays: SMatrix | ||
|
||
ClimaCoreCUDAExt = Base.get_extension(ClimaCore, :ClimaCoreCUDAExt) | ||
|
||
# TODO: Move this to ClimaCore.jl/ext/ClimaCoreCUDAExt/data_layouts.jl | ||
function Base.copyto!( | ||
dest::DataLayouts.IFH{S, Ni}, | ||
bc::Union{ | ||
DataLayouts.IFH{S, Ni, A}, | ||
Base.Broadcast.Broadcasted{DataLayouts.IFHStyle{Ni, A}}, | ||
}, | ||
) where {S, Ni, A <: ClimaCoreCUDAExt.CuArrayBackedTypes} | ||
_, _, _, _, Nh = size(bc) | ||
if Nh > 0 | ||
ClimaCoreCUDAExt.auto_launch!( | ||
ClimaCoreCUDAExt.knl_copyto!, | ||
(dest, bc), | ||
dest; | ||
threads_s = (Ni, 1), | ||
blocks_s = (Nh, 1), | ||
) | ||
end | ||
return dest | ||
end | ||
function Base.copyto!( | ||
dest::DataLayouts.VIFH{S, Nv, Ni}, | ||
bc::Union{ | ||
DataLayouts.VIFH{S, Nv, Ni, A}, | ||
Base.Broadcast.Broadcasted{DataLayouts.VIFHStyle{Nv, Ni, A}}, | ||
}, | ||
) where {S, Nv, Ni, A <: ClimaCoreCUDAExt.CuArrayBackedTypes} | ||
_, _, _, _, Nh = size(bc) | ||
if Nv > 0 && Nh > 0 | ||
Nv_per_block = min(Nv, fld(256, Ni)) | ||
Nv_blocks = cld(Nv, Nv_per_block) | ||
ClimaCoreCUDAExt.auto_launch!( | ||
ClimaCoreCUDAExt.knl_copyto!, | ||
(dest, bc), | ||
dest; | ||
threads_s = (Ni, Nv_per_block), | ||
blocks_s = (Nh, Nv_blocks), | ||
) | ||
end | ||
return dest | ||
end | ||
|
||
# TODO: Move this to ClimaCore.jl/ext/ClimaCoreCUDAExt/operators_sem_shmem.jl.jl | ||
Base.@propagate_inbounds function ClimaCoreCUDAExt.operator_shmem( | ||
space, | ||
::Val{Nvt}, | ||
op::Operators.Gradient{(1,)}, | ||
arg, | ||
) where {Nvt} | ||
FT = Spaces.undertype(space) | ||
QS = Spaces.quadrature_style(space) | ||
Nq = Quadratures.degrees_of_freedom(QS) | ||
# allocate temp output | ||
IT = eltype(arg) | ||
input = CUDA.CuStaticSharedArray(IT, (Nq, Nvt)) | ||
return (input,) | ||
end | ||
Base.@propagate_inbounds function ClimaCoreCUDAExt.operator_fill_shmem!( | ||
op::Operators.Gradient{(1,)}, | ||
(input,), | ||
space, | ||
ij, | ||
slabidx, | ||
arg, | ||
) | ||
vt = threadIdx().z | ||
i, _ = ij.I | ||
input[i, vt] = arg | ||
end | ||
|
||
# TODO: Move this to ClimaCore.jl/src/Grids/spectralelement.jl | ||
function Grids._SpectralElementGrid1D( | ||
topology::Topologies.IntervalTopology, | ||
quadrature_style::Quadratures.QuadratureStyle, | ||
) | ||
DA = ClimaComms.array_type(topology) | ||
global_geometry = Geometry.CartesianGlobalGeometry() | ||
CoordType = Topologies.coordinate_type(topology) | ||
AIdx = Geometry.coordinate_axis(CoordType) | ||
FT = eltype(CoordType) | ||
nelements = Topologies.nlocalelems(topology) | ||
Nq = Quadratures.degrees_of_freedom(quadrature_style) | ||
LG = Geometry.LocalGeometry{AIdx, CoordType, FT, SMatrix{1, 1, FT, 1}} | ||
quad_points, quad_weights = | ||
Quadratures.quadrature_points(FT, quadrature_style) | ||
|
||
# Initialize the local_geometry with Array{FT} as the backing array type. | ||
local_geometry = DataLayouts.IFH{LG, Nq}(Array{FT}, nelements) | ||
|
||
for elem in 1:nelements | ||
local_geometry_slab = slab(local_geometry, elem) | ||
for i in 1:Nq | ||
ξ = quad_points[i] | ||
vcoords = Topologies.vertex_coordinates(topology, elem) | ||
x = Geometry.linear_interpolate(vcoords, ξ) | ||
∂x∂ξ = | ||
( | ||
Geometry.component(vcoords[2], 1) - | ||
Geometry.component(vcoords[1], 1) | ||
) / 2 | ||
J = abs(∂x∂ξ) | ||
WJ = J * quad_weights[i] | ||
local_geometry_slab[i] = Geometry.LocalGeometry( | ||
x, | ||
J, | ||
WJ, | ||
Geometry.AxisTensor( | ||
( | ||
Geometry.LocalAxis{AIdx}(), | ||
Geometry.CovariantAxis{AIdx}(), | ||
), | ||
∂x∂ξ, | ||
), | ||
) | ||
end | ||
end | ||
|
||
# TODO: Why was this code setting dss_weights = 1 / DSS(1)? That's just 1?? | ||
# dss_weights = copy(local_geometry.J) | ||
# dss_weights .= one(FT) | ||
# Topologies.dss_1d!(topology, dss_weights) | ||
# dss_weights = one(FT) ./ dss_weights | ||
|
||
dss_weights = copy(local_geometry.J) | ||
Topologies.dss_1d!(topology, dss_weights) | ||
dss_weights .= local_geometry.J ./ dss_weights | ||
|
||
# If needed, move the local_geometry and dss_weights onto the GPU. | ||
return Grids.SpectralElementGrid1D( | ||
topology, | ||
quadrature_style, | ||
global_geometry, | ||
DataLayouts.rebuild(local_geometry, DA), | ||
DataLayouts.rebuild(dss_weights, DA), | ||
) | ||
end | ||
|
||
# TODO: Move this to ClimaCore.jl/src/Hypsography/Hypsography.jl | ||
function Grids._ExtrudedFiniteDifferenceGrid( | ||
horizontal_grid::Grids.AbstractGrid, | ||
vertical_grid::Grids.FiniteDifferenceGrid, | ||
adaption::Grids.HypsographyAdaption, | ||
global_geometry::Geometry.AbstractGlobalGeometry, | ||
) | ||
@assert Spaces.grid(axes(adaption.surface)) == horizontal_grid | ||
z_surface = Fields.field_values(adaption.surface) | ||
|
||
face_z_ref = | ||
Grids.local_geometry_data(vertical_grid, Grids.CellFace()).coordinates | ||
vertical_domain = Topologies.domain(vertical_grid) | ||
z_top = vertical_domain.coord_max | ||
|
||
face_z = | ||
modified_ref_z_to_physical_z.( | ||
Ref(typeof(adaption)), | ||
face_z_ref, | ||
z_surface, | ||
Ref(z_top), | ||
Ref(adaption_parameters(adaption)), | ||
) | ||
|
||
return Grids._ExtrudedFiniteDifferenceGrid( | ||
horizontal_grid, | ||
vertical_grid, | ||
adaption, | ||
global_geometry, | ||
face_z, | ||
) | ||
end | ||
|
||
adaption_parameters(::Grids.Flat) = (;) | ||
adaption_parameters(::Hypsography.LinearAdaption) = (;) | ||
adaption_parameters((; ηₕ, s)::Hypsography.SLEVEAdaption) = (; ηₕ, s) | ||
|
||
function modified_ref_z_to_physical_z( | ||
::Type{<:Grids.Flat}, | ||
z_ref::Geometry.ZPoint, | ||
z_surface::Geometry.ZPoint, | ||
z_top::Geometry.ZPoint, | ||
_, | ||
) | ||
return z_ref | ||
end | ||
function modified_ref_z_to_physical_z( | ||
::Type{<:Hypsography.LinearAdaption}, | ||
z_ref::Geometry.ZPoint, | ||
z_surface::Geometry.ZPoint, | ||
z_top::Geometry.ZPoint, | ||
_, | ||
) | ||
Geometry.ZPoint(z_ref.z + (1 - z_ref.z / z_top.z) * z_surface.z) | ||
end | ||
function modified_ref_z_to_physical_z( | ||
::Type{<:Hypsography.SLEVEAdaption}, | ||
z_ref::Geometry.ZPoint, | ||
z_surface::Geometry.ZPoint, | ||
z_top::Geometry.ZPoint, | ||
(; ηₕ, s), | ||
) | ||
if s * z_top.z <= z_surface.z | ||
error("Decay scale (s*z_top) must be higher than max surface elevation") | ||
end | ||
|
||
η = z_ref.z / z_top.z | ||
if η <= ηₕ | ||
return Geometry.ZPoint( | ||
η * z_top.z + | ||
z_surface.z * (sinh((ηₕ - η) / s / ηₕ)) / (sinh(1 / s)), | ||
) | ||
else | ||
return Geometry.ZPoint(η * z_top.z) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
module ClimaAtmos | ||
|
||
# include("disable_topography_dss.jl") | ||
|
||
using NVTX, Colors | ||
import Thermodynamics as TD | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters