Skip to content

Commit 039a65b

Browse files
Merge pull request #2112 from CliMA/ck/adapt_limiter_fixes
Fix adapt for new limiters, test on gpu
2 parents 6040306 + dd739e5 commit 039a65b

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

.buildkite/pipeline.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,21 +1454,32 @@ steps:
14541454
- "julia --color=yes --project=.buildkite examples/column/fct_advection.jl"
14551455
artifact_paths:
14561456
- "examples/column/output/fct_advection/*"
1457-
1457+
14581458
- label: ":computer: Column TVD Slope-limited Advection Eq"
14591459
key: "cpu_tvd_column_advect"
14601460
command:
14611461
- "julia --color=yes --project=.buildkite examples/column/tvd_advection.jl"
14621462
artifact_paths:
14631463
- "examples/column/output/tvd_advection/*"
1464-
1464+
14651465
- label: ":computer: Column Lin vanLeer Limiter Advection Eq"
14661466
key: "cpu_lvl_column_advect"
14671467
command:
14681468
- "julia --color=yes --project=.buildkite examples/column/vanleer_advection.jl"
14691469
artifact_paths:
14701470
- "examples/column/output/vanleer_advection/*"
14711471

1472+
- label: ":computer: Column Lin vanLeer Limiter Advection Eq cuda"
1473+
key: "gpu_lvl_column_advect"
1474+
command:
1475+
- "julia --color=yes --project=.buildkite examples/column/vanleer_advection.jl"
1476+
artifact_paths:
1477+
- "examples/column/output/vanleer_advection/*"
1478+
env:
1479+
CLIMACOMMS_DEVICE: "CUDA"
1480+
agents:
1481+
slurm_gpus: 1
1482+
14721483
- label: ":computer: Column BB FCT Advection Eq"
14731484
key: "cpu_bb_fct_column_advect"
14741485
command:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClimaCore"
22
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
33
authors = ["CliMA Contributors <clima-software@caltech.edu>"]
4-
version = "0.14.21"
4+
version = "0.14.23"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

examples/column/vanleer_advection.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#=
2+
julia --project=.buildkite
3+
ENV["CLIMACOMMS_DEVICE"] = "CUDA"
4+
using Revise; include("examples/column/vanleer_advection.jl")
5+
=#
16
using Test
27
using LinearAlgebra
38
import ClimaComms
@@ -51,13 +56,13 @@ end
5156

5257
# Define a pulse wave or square wave
5358

54-
FT = Float64
55-
t₀ = FT(0.0)
56-
t₁ = FT(6)
57-
z₀ = FT(0.0)
58-
zₕ = FT(2π)
59-
z₁ = FT(1.0)
60-
speed = FT(-1.0)
59+
const FT = Float64
60+
const t₀ = FT(0.0)
61+
const t₁ = FT(6)
62+
const z₀ = FT(0.0)
63+
const zₕ = FT(2π)
64+
const z₁ = FT(1.0)
65+
const speed = FT(-1.0)
6166
pulse(z, t, z₀, zₕ, z₁) = abs(z - speed * t) zₕ ? z₁ : z₀
6267

6368
n = 2 .^ 8
@@ -135,6 +140,14 @@ for (i, stretch_fn) in enumerate(stretch_fns)
135140
err = norm(q_final .- q_analytic)
136141
rel_mass_err = norm((sum(q_final) - sum(q_init)) / sum(q_init))
137142

143+
@test err 0.25
144+
@test rel_mass_err 10eps()
145+
146+
device = ClimaComms.device(q_init)
147+
if device isa ClimaComms.CUDADevice
148+
continue
149+
end
150+
138151
if j == 1
139152
fig = Plots.plot(q_analytic; label = "Exact", color = :red)
140153
end
@@ -162,7 +175,5 @@ for (i, stretch_fn) in enumerate(stretch_fns)
162175
),
163176
)
164177
end
165-
@test err 0.25
166-
@test rel_mass_err 10eps()
167178
end
168179
end

src/Operators/finitedifference.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,19 +3061,24 @@ function Adapt.adapt_structure(to, bc::AbstractBoundaryCondition)
30613061
end
30623062

30633063
# Extend `adapt_structure` for all operator types with boundary conditions.
3064-
function Adapt.adapt_structure(to, op::FiniteDifferenceOperator)
3065-
if hasfield(typeof(op), :bcs)
3066-
bcs_adapted = NamedTuple{keys(op.bcs)}(
3067-
UnrolledFunctions.unrolled_map(
3068-
bc -> Adapt.adapt_structure(to, bc),
3069-
values(op.bcs),
3070-
),
3071-
)
3072-
return unionall_type(typeof(op))(bcs_adapted)
3073-
else
3074-
return op
3075-
end
3076-
end
3064+
Adapt.adapt_structure(to, op::FiniteDifferenceOperator) =
3065+
hasfield(typeof(op), :bcs) ? adapt_fd_operator(to, op, op.bcs) : op
3066+
3067+
@inline adapt_fd_operator(to, op::LinVanLeerC2F, bcs) =
3068+
LinVanLeerC2F(adapt_bcs(to, bcs), Adapt.adapt_structure(to, op.constraint))
3069+
3070+
@inline adapt_fd_operator(to, op::TVDLimitedFluxC2F, bcs) =
3071+
TVDLimitedFluxC2F(adapt_bcs(to, bcs), Adapt.adapt_structure(to, op.method))
3072+
3073+
@inline adapt_fd_operator(to, op, bcs) =
3074+
unionall_type(typeof(op))(adapt_bcs(to, bcs))
3075+
3076+
@inline adapt_bcs(to, bcs) = NamedTuple{keys(bcs)}(
3077+
UnrolledFunctions.unrolled_map(
3078+
bc -> Adapt.adapt_structure(to, bc),
3079+
values(bcs),
3080+
),
3081+
)
30773082

30783083
"""
30793084
D = DivergenceC2F(;boundaryname=boundarycondition...)

0 commit comments

Comments
 (0)