Skip to content

Commit

Permalink
Merge pull request #2112 from CliMA/ck/adapt_limiter_fixes
Browse files Browse the repository at this point in the history
Fix adapt for new limiters, test on gpu
  • Loading branch information
charleskawczynski authored Dec 23, 2024
2 parents 6040306 + dd739e5 commit 039a65b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 25 deletions.
15 changes: 13 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1454,21 +1454,32 @@ steps:
- "julia --color=yes --project=.buildkite examples/column/fct_advection.jl"
artifact_paths:
- "examples/column/output/fct_advection/*"

- label: ":computer: Column TVD Slope-limited Advection Eq"
key: "cpu_tvd_column_advect"
command:
- "julia --color=yes --project=.buildkite examples/column/tvd_advection.jl"
artifact_paths:
- "examples/column/output/tvd_advection/*"

- label: ":computer: Column Lin vanLeer Limiter Advection Eq"
key: "cpu_lvl_column_advect"
command:
- "julia --color=yes --project=.buildkite examples/column/vanleer_advection.jl"
artifact_paths:
- "examples/column/output/vanleer_advection/*"

- label: ":computer: Column Lin vanLeer Limiter Advection Eq cuda"
key: "gpu_lvl_column_advect"
command:
- "julia --color=yes --project=.buildkite examples/column/vanleer_advection.jl"
artifact_paths:
- "examples/column/output/vanleer_advection/*"
env:
CLIMACOMMS_DEVICE: "CUDA"
agents:
slurm_gpus: 1

- label: ":computer: Column BB FCT Advection Eq"
key: "cpu_bb_fct_column_advect"
command:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaCore"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
authors = ["CliMA Contributors <[email protected]>"]
version = "0.14.21"
version = "0.14.23"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
29 changes: 20 additions & 9 deletions examples/column/vanleer_advection.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#=
julia --project=.buildkite
ENV["CLIMACOMMS_DEVICE"] = "CUDA"
using Revise; include("examples/column/vanleer_advection.jl")
=#
using Test
using LinearAlgebra
import ClimaComms
Expand Down Expand Up @@ -51,13 +56,13 @@ end

# Define a pulse wave or square wave

FT = Float64
t₀ = FT(0.0)
t₁ = FT(6)
z₀ = FT(0.0)
zₕ = FT(2π)
z₁ = FT(1.0)
speed = FT(-1.0)
const FT = Float64
const t₀ = FT(0.0)
const t₁ = FT(6)
const z₀ = FT(0.0)
const zₕ = FT(2π)
const z₁ = FT(1.0)
const speed = FT(-1.0)
pulse(z, t, z₀, zₕ, z₁) = abs(z - speed * t) zₕ ? z₁ : z₀

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

@test err 0.25
@test rel_mass_err 10eps()

device = ClimaComms.device(q_init)
if device isa ClimaComms.CUDADevice
continue
end

if j == 1
fig = Plots.plot(q_analytic; label = "Exact", color = :red)
end
Expand Down Expand Up @@ -162,7 +175,5 @@ for (i, stretch_fn) in enumerate(stretch_fns)
),
)
end
@test err 0.25
@test rel_mass_err 10eps()
end
end
31 changes: 18 additions & 13 deletions src/Operators/finitedifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3061,19 +3061,24 @@ function Adapt.adapt_structure(to, bc::AbstractBoundaryCondition)
end

# Extend `adapt_structure` for all operator types with boundary conditions.
function Adapt.adapt_structure(to, op::FiniteDifferenceOperator)
if hasfield(typeof(op), :bcs)
bcs_adapted = NamedTuple{keys(op.bcs)}(
UnrolledFunctions.unrolled_map(
bc -> Adapt.adapt_structure(to, bc),
values(op.bcs),
),
)
return unionall_type(typeof(op))(bcs_adapted)
else
return op
end
end
Adapt.adapt_structure(to, op::FiniteDifferenceOperator) =
hasfield(typeof(op), :bcs) ? adapt_fd_operator(to, op, op.bcs) : op

@inline adapt_fd_operator(to, op::LinVanLeerC2F, bcs) =
LinVanLeerC2F(adapt_bcs(to, bcs), Adapt.adapt_structure(to, op.constraint))

@inline adapt_fd_operator(to, op::TVDLimitedFluxC2F, bcs) =
TVDLimitedFluxC2F(adapt_bcs(to, bcs), Adapt.adapt_structure(to, op.method))

@inline adapt_fd_operator(to, op, bcs) =
unionall_type(typeof(op))(adapt_bcs(to, bcs))

@inline adapt_bcs(to, bcs) = NamedTuple{keys(bcs)}(
UnrolledFunctions.unrolled_map(
bc -> Adapt.adapt_structure(to, bc),
values(bcs),
),
)

"""
D = DivergenceC2F(;boundaryname=boundarycondition...)
Expand Down

2 comments on commit 039a65b

@charleskawczynski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/121909

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.23 -m "<description of version>" 039a65b306869d840b49fa113f0f4b680666a347
git push origin v0.14.23

Also, note the warning: Version 0.14.23 skips over 0.14.22
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.