Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
1a05c0b
start it
simone-silvestri Aug 8, 2025
780060b
change
simone-silvestri Aug 8, 2025
e8125e1
add this
simone-silvestri Aug 8, 2025
952bee4
also this goes away
simone-silvestri Aug 8, 2025
6e3618c
all away
simone-silvestri Aug 8, 2025
21fd637
let's go
simone-silvestri Aug 8, 2025
44655da
go with it
simone-silvestri Aug 8, 2025
a061b7f
go for it
simone-silvestri Aug 8, 2025
f8c9dec
Update hydrostatic_free_surface_tendency_kernel_functions.jl
simone-silvestri Aug 8, 2025
3f82063
remove number of lines
simone-silvestri Aug 8, 2025
2d5cf2a
Merge branch 'ss/catke-for-rk3' of github.com:CliMA/Oceananigans.jl i…
simone-silvestri Aug 8, 2025
c711b81
bugfix
simone-silvestri Aug 8, 2025
09850d0
make it work
simone-silvestri Aug 8, 2025
f1cfb4d
go like this
simone-silvestri Aug 8, 2025
617c429
vestigial stuff
simone-silvestri Aug 8, 2025
1a7d6b1
fix
simone-silvestri Aug 8, 2025
7611c14
go ahead
simone-silvestri Aug 8, 2025
2ff463c
let;s go
simone-silvestri Aug 8, 2025
0ad96c0
fix a bit
simone-silvestri Aug 8, 2025
51ea3d7
go ahead
simone-silvestri Aug 8, 2025
9fa3da7
this should all work
simone-silvestri Aug 8, 2025
347abf3
add a tuple
simone-silvestri Aug 8, 2025
393d590
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Aug 9, 2025
51322fd
test hypothesis
simone-silvestri Aug 9, 2025
4b19e27
Merge branch 'ss/fix-bc-slowdown' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Aug 9, 2025
6738f32
fix
simone-silvestri Aug 9, 2025
16b40b3
just remove this tupled fill halo regions
simone-silvestri Aug 11, 2025
644b757
remove signed
simone-silvestri Aug 11, 2025
3016b13
just remove tupled fill_halo_regions
simone-silvestri Aug 12, 2025
8927c62
startg simplifying
simone-silvestri Aug 12, 2025
b238ab3
start precomputing kernels
simone-silvestri Aug 12, 2025
16bd2cd
start with the simple ones
simone-silvestri Aug 12, 2025
df8369e
this works for one field
simone-silvestri Aug 12, 2025
5627e1d
some refactoring
simone-silvestri Aug 12, 2025
bc910d0
more refactorinf
simone-silvestri Aug 12, 2025
8b7ab6d
remove multi region for the moment
simone-silvestri Aug 12, 2025
02a882b
ok, this starts to shape up
simone-silvestri Aug 12, 2025
571c6b3
remove this for now
simone-silvestri Aug 12, 2025
29458c8
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Aug 12, 2025
70b49a5
go ahead
simone-silvestri Aug 13, 2025
71bff55
Merge branch 'ss/fix-bc-slowdown' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Aug 13, 2025
9672b3c
simplify
simone-silvestri Aug 13, 2025
33fbf2e
more changes
simone-silvestri Aug 13, 2025
baeef6f
more changes
simone-silvestri Aug 13, 2025
c127bae
more fixing
simone-silvestri Aug 13, 2025
d5b4d79
at the top level
simone-silvestri Aug 13, 2025
2e93da2
remove unuset code
simone-silvestri Aug 13, 2025
2868cd6
go ahead
simone-silvestri Aug 13, 2025
47e1ea6
more chnages
simone-silvestri Aug 13, 2025
10a709b
think about this later on
simone-silvestri Aug 13, 2025
38a06c9
think about this later on
simone-silvestri Aug 13, 2025
aae4a30
more chnages
simone-silvestri Aug 13, 2025
db6031f
refactor
simone-silvestri Aug 13, 2025
f491030
remove the val
simone-silvestri Aug 13, 2025
06c275b
tuple not a vector
simone-silvestri Aug 13, 2025
41d0366
fix some typos
simone-silvestri Aug 13, 2025
048d4b8
add also the polar BC
simone-silvestri Aug 13, 2025
0655910
more fixing
simone-silvestri Aug 13, 2025
52ec822
deal with open BC
simone-silvestri Aug 13, 2025
d0aaa89
change stuff
simone-silvestri Aug 13, 2025
e950713
add a reduced dimension
simone-silvestri Aug 13, 2025
fc75a05
all but multiregion tests should pass?
simone-silvestri Aug 13, 2025
5246cdb
still multi-region to fix
simone-silvestri Aug 13, 2025
722c768
dealt with open BCS
simone-silvestri Aug 13, 2025
5a50c28
BCS integration works
simone-silvestri Aug 13, 2025
09b72c0
had to change a bit the atol
simone-silvestri Aug 13, 2025
cd133fb
reset the bcs test
simone-silvestri Aug 13, 2025
6ca2299
no need for reduced_dimensions no more
simone-silvestri Aug 13, 2025
47fb6b0
distributed works, let's go!
simone-silvestri Aug 13, 2025
1867523
distributed works
simone-silvestri Aug 13, 2025
ec18906
include multiregion
simone-silvestri Aug 13, 2025
2fea58d
also multiregion works! Let's go!
simone-silvestri Aug 13, 2025
4eaa117
fix also the tripolar grid
simone-silvestri Aug 13, 2025
bfdecd3
make sure we can fill ALL boundary conditions
simone-silvestri Aug 13, 2025
9081415
typo
simone-silvestri Aug 13, 2025
6f28c13
more fixes
simone-silvestri Aug 13, 2025
8448f73
fix tripolar tests
simone-silvestri Aug 13, 2025
d418d52
remove vestigial comments
simone-silvestri Aug 13, 2025
f0a80ad
Update boundary_condition_ordering.jl
simone-silvestri Aug 13, 2025
d4aded5
Update fill_halo_kernels.jl
simone-silvestri Aug 13, 2025
47aa233
Update fill_halo_regions_open.jl
simone-silvestri Aug 13, 2025
10a62af
Update field.jl
simone-silvestri Aug 13, 2025
921d8a7
Update cubed_sphere_boundary_conditions.jl
simone-silvestri Aug 13, 2025
c1908b7
recv_and_fill_ -> recv_
simone-silvestri Aug 13, 2025
8f672c5
Merge branch 'ss/fix-bc-slowdown' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Aug 13, 2025
8bb38f3
correct typo
simone-silvestri Aug 13, 2025
06c8e6c
fix distributed tripolar tests
simone-silvestri Aug 13, 2025
df82140
hmmm, this works but not optimal
simone-silvestri Aug 13, 2025
7132449
remove commented code
simone-silvestri Aug 13, 2025
2870569
compact
simone-silvestri Aug 13, 2025
c0a2965
use same syntax
simone-silvestri Aug 13, 2025
e1e6c01
some cleanup
simone-silvestri Aug 13, 2025
8c19e6d
this should make also the output writers work
simone-silvestri Aug 13, 2025
a02c7d5
split the two
simone-silvestri Aug 13, 2025
801b494
fix kwcall issue
simone-silvestri Aug 14, 2025
93918ba
add an inbounds
simone-silvestri Aug 14, 2025
5fccb80
fix doctests
simone-silvestri Aug 14, 2025
798d680
add this
simone-silvestri Aug 14, 2025
e182090
add double tests
simone-silvestri Aug 14, 2025
437160f
scrape
simone-silvestri Aug 14, 2025
5abe060
Update catke_vertical_diffusivity.jl
simone-silvestri Aug 14, 2025
1ccc0ae
Update distributed_zipper.jl
simone-silvestri Aug 14, 2025
f54c010
Update halo_communication.jl
simone-silvestri Aug 14, 2025
3a4c018
bugfix
simone-silvestri Aug 18, 2025
0301b59
Merge branch 'ss/fix-bc-slowdown' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Aug 18, 2025
cb3f60e
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Aug 18, 2025
4cd231c
fix tests
simone-silvestri Aug 18, 2025
fb45f35
Merge branch 'ss/fix-bc-slowdown' of github.com:CliMA/Oceananigans.jl…
simone-silvestri Aug 18, 2025
d4b71aa
update
simone-silvestri Aug 18, 2025
8516087
import method
simone-silvestri Aug 18, 2025
5e42431
launch!
simone-silvestri Aug 18, 2025
6f0586e
adding the CuDeviceArray
simone-silvestri Aug 18, 2025
4fe373a
Update field_boundary_conditions.jl
simone-silvestri Aug 26, 2025
236289e
Apply suggestion from @navidcy
simone-silvestri Aug 26, 2025
4bf3d21
Apply suggestion from @navidcy
simone-silvestri Aug 26, 2025
41e0b2d
Apply suggestion from @navidcy
simone-silvestri Aug 26, 2025
be0b738
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Aug 26, 2025
1184dc5
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Aug 27, 2025
d0359b6
give a name to the namedtuple
simone-silvestri Aug 28, 2025
d178c24
Implement adapt_structure for boundary conditions
simone-silvestri Aug 28, 2025
da61000
Fix adapt_structure to include ordered_bcs
simone-silvestri Aug 28, 2025
7436103
test again
simone-silvestri Aug 29, 2025
915d6e6
Update fill_halo_kernels.jl
simone-silvestri Aug 29, 2025
4d39d90
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Aug 29, 2025
89f8974
Merge branch 'main' into ss/fix-bc-slowdown
simone-silvestri Sep 1, 2025
a305538
Merge remote-tracking branch 'origin/main' into ss/fix-bc-slowdown
simone-silvestri Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/OceananigansCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Base.summary(::CUDAGPU) = "CUDAGPU"

AC.architecture(::CuArray) = CUDAGPU()
AC.architecture(::Type{CuArray}) = CUDAGPU()
AC.architecture(::CuDeviceArray) = CUDAGPU()
AC.architecture(::Type{CuDeviceArray}) = CUDAGPU()
AC.architecture(::CuSparseMatrixCSC) = CUDAGPU()
AC.array_type(::AC.GPU{CUDABackend}) = CuArray

Expand Down
2 changes: 1 addition & 1 deletion ext/OceananigansEnzymeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EnzymeCore.EnzymeRules.inactive_noinl(::typeof(Oceananigans.AbstractOperations.m
EnzymeCore.EnzymeRules.inactive_noinl(::typeof(Oceananigans.Utils.flatten_reduced_dimensions), x...) = nothing
EnzymeCore.EnzymeRules.inactive_noinl(::typeof(Oceananigans.Utils.prettytime), x...) = nothing
EnzymeCore.EnzymeRules.inactive(::typeof(Oceananigans.Grids.total_size), x...) = nothing
EnzymeCore.EnzymeRules.inactive(::typeof(Oceananigans.BoundaryConditions.parent_size_and_offset), x...) = nothing
EnzymeCore.EnzymeRules.inactive(::typeof(Oceananigans.BoundaryConditions.periodic_size_and_offset), x...) = nothing
@inline EnzymeCore.EnzymeRules.inactive_type(v::Type{Oceananigans.Utils.KernelParameters}) = true

@inline batch(::Val{1}, ::Type{T}) where T = T
Expand Down
19 changes: 17 additions & 2 deletions src/BoundaryConditions/BoundaryConditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export
validate_boundary_condition_topology, validate_boundary_condition_architecture,
FieldBoundaryConditions,
compute_x_bcs!, compute_y_bcs!, compute_z_bcs!,
fill_halo_regions!
fill_halo_regions!,
WestAndEast, SouthAndNorth, BottomAndTop,
West, East, South, North, Bottom, Top,
DistributedFillHalo

using Adapt
using KernelAbstractions: @index, @kernel
Expand All @@ -21,10 +24,22 @@ using Oceananigans.Grids

import Adapt: adapt_structure

# All possible fill_halo! kernels
struct WestAndEast end
struct SouthAndNorth end
struct BottomAndTop end
struct West end
struct East end
struct South end
struct North end
struct Bottom end
struct Top end

include("boundary_condition_classifications.jl")
include("boundary_condition.jl")
include("discrete_boundary_function.jl")
include("continuous_boundary_function.jl")
include("boundary_condition_ordering.jl")
include("field_boundary_conditions.jl")
include("show_boundary_conditions.jl")

Expand All @@ -33,8 +48,8 @@ include("fill_halo_regions_value_gradient.jl")
include("fill_halo_regions_open.jl")
include("fill_halo_regions_periodic.jl")
include("fill_halo_regions_flux.jl")
include("fill_halo_regions_nothing.jl")
include("fill_halo_regions_zipper.jl")
include("fill_halo_kernels.jl")

include("compute_flux_bcs.jl")

Expand Down
128 changes: 128 additions & 0 deletions src/BoundaryConditions/boundary_condition_ordering.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
extract_bc(bcs, ::West) = tuple(bcs.west)
extract_bc(bcs, ::East) = tuple(bcs.east)
extract_bc(bcs, ::South) = tuple(bcs.south)
extract_bc(bcs, ::North) = tuple(bcs.north)
extract_bc(bcs, ::Bottom) = tuple(bcs.bottom)
extract_bc(bcs, ::Top) = tuple(bcs.top)

extract_bc(bcs, ::BottomAndTop) = (bcs.bottom, bcs.top)
extract_bc(bcs, ::WestAndEast) = (bcs.west, bcs.east)
extract_bc(bcs, ::SouthAndNorth) = (bcs.south, bcs.north)

# In case of a DistributedCommunication paired with a
# Flux, Value or Gradient boundary condition, we split the direction in two single-sided
# fill_halo! events (see issue #3342)
# `permute_boundary_conditions` returns a 2-tuple containing the ordered operations to execute in
# position [1] and the associated boundary conditions in position [2]
function permute_boundary_conditions(bcs)

split_x_halo_filling = split_halo_filling(bcs.west, bcs.east)
split_y_halo_filling = split_halo_filling(bcs.south, bcs.north)

if split_x_halo_filling
if split_y_halo_filling
sides = [West(), East(), South(), North(), BottomAndTop()]
bcs_array = [bcs.west, bcs.east, bcs.south, bcs.north, bcs.bottom]
else
sides = [West(), East(), SouthAndNorth(), BottomAndTop()]
bcs_array = [bcs.west, bcs.east, bcs.south, bcs.bottom]
end
else
if split_y_halo_filling
sides = [WestAndEast(), South(), North(), BottomAndTop()]
bcs_array = [bcs.west, bcs.south, bcs.north, bcs.bottom]
else
sides = [WestAndEast(), SouthAndNorth(), BottomAndTop()]
bcs_array = [bcs.west, bcs.south, bcs.bottom]
end
end

perm = sortperm(bcs_array, lt=fill_first)
sides = tuple(sides[perm]...)

boundary_conditions = Tuple(extract_bc(bcs, side) for side in sides)

return sides, boundary_conditions
end

side_name(::West) = :west
side_name(::East) = :east
side_name(::South) = :south
side_name(::North) = :north
side_name(::Bottom) = :bottom
side_name(::Top) = :top
side_name(::WestAndEast) = :west_and_east
side_name(::SouthAndNorth) = :south_and_north
side_name(::BottomAndTop) = :bottom_and_top

# Split direction in two distinct fill_halo! events in case of a communication boundary condition
# (distributed DCBC), paired with a Flux, Value or Gradient boundary condition
split_halo_filling(bcs1, bcs2) = false
split_halo_filling(::DCBC, ::DCBC) = false
split_halo_filling(bcs1, ::DCBC) = true
split_halo_filling(::DCBC, bcs2) = true

# Same thing for MultiRegion boundary conditions
split_halo_filling(::MCBC, ::MCBC) = false
split_halo_filling(bcs1, ::MCBC) = true
split_halo_filling(::MCBC, bcs2) = true

# heterogenous distribute-shared communication is not supported
# TODO: support heterogeneous distributed-shared communication
split_halo_filling(::MCBC, ::DCBC) = throw("Cannot split MultiRegion and Distributed boundary conditions.")
split_halo_filling(::DCBC, ::MCBC) = throw("Cannot split MultiRegion and Distributed boundary conditions.")

#####
##### Halo filling order
#####

const PBCT = Union{PBC, Tuple{Vararg{PBC}}}
const MCBCT = Union{MCBC, Tuple{Vararg{MCBC}}}
const DCBCT = Union{DCBC, Tuple{Vararg{DCBC}}}
const OBCTC = Union{OBC, Tuple{Vararg{OBC}}}

# Distributed halos have to be filled last to allow the
# possibility of asynchronous communication:
# If other halos are filled after we initiate the distributed communication,
# (but before communication is completed) the halos will be overwritten.
# For this reason we always want to perform local halo filling first and then
# initiate communication

# Periodic is handled after Flux, Value, Gradient because
# Periodic fills also corners while Flux, Value, Gradient do not
# TODO: remove this ordering requirement (see issue https://github.com/CliMA/Oceananigans.jl/issues/3342)

# Order of halo filling
# 1) Flux, Value, Gradient (TODO: remove these BC and apply them as fluxes)
# 2) Periodic (PBCT)
# 3) Shared Communication (MCBCT)
# 4) Distributed Communication (DCBCT)

# We define "greater than" `>` and "lower than", for boundary conditions
# following the rules outlined in `fill_first`
# i.e. if `bc1 > bc2` then `bc2` precedes `bc1` in filling order
@inline Base.isless(bc1::BoundaryCondition, bc2::BoundaryCondition) = fill_first(bc1, bc2)

# fallback for `Nothing` BC.
@inline Base.isless(::Nothing, ::Nothing) = true
@inline Base.isless(::BoundaryCondition, ::Nothing) = false
@inline Base.isless(::Nothing, ::BoundaryCondition) = true
@inline Base.isless(::BoundaryCondition, ::Missing) = false
@inline Base.isless(::Missing, ::BoundaryCondition) = true

fill_first(bc1::DCBCT, bc2) = false
fill_first(bc1::PBCT, bc2::DCBCT) = true
fill_first(bc1::DCBCT, bc2::PBCT) = false
fill_first(bc1::MCBCT, bc2::DCBCT) = true
fill_first(bc1::DCBCT, bc2::MCBCT) = false
fill_first(bc1, bc2::DCBCT) = true
fill_first(bc1::DCBCT, bc2::DCBCT) = true
fill_first(bc1::PBCT, bc2) = false
fill_first(bc1::MCBCT, bc2) = false
fill_first(bc1::PBCT, bc2::MCBCT) = true
fill_first(bc1::MCBCT, bc2::PBCT) = false
fill_first(bc1, bc2::PBCT) = true
fill_first(bc1, bc2::MCBCT) = true
fill_first(bc1::PBCT, bc2::PBCT) = true
fill_first(bc1::MCBCT, bc2::MCBCT) = true
fill_first(bc1, bc2) = true
22 changes: 19 additions & 3 deletions src/BoundaryConditions/field_boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,25 @@ default_auxiliary_bc(grid, ::Val{:top}, loc) = _default_auxiliary_bc(topology
##### Field boundary conditions
#####

mutable struct FieldBoundaryConditions{W, E, S, N, B, T, I}
mutable struct FieldBoundaryConditions{W, E, S, N, B, T, I, K, O}
west :: W
east :: E
south :: S
north :: N
bottom :: B
top :: T
immersed :: I
kernels :: K # kernels used to fill halo regions
ordered_bcs :: O
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what does "ordered bcs" mean here? Shouldn't we store the ordering (eg something like a tuple that reads (:west, :east, :top, :bottom, :south, :north)? If we store the kernels, can't the ordering be embedded in that object?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we can give it another name? Basically, ordered_bcs holds the boundary conditions in the correct order to be used by the kernels. In practice, the redundant fields here are the west, east, south, north, etc... the "meat" is in ordered_bcs.

end

const boundarynames = (:west, :east, :south, :north, :bottom, :top, :immersed)

const NoKernelFBC = FieldBoundaryConditions{W, E, S, N, B, T, I, Nothing, Nothing} where {W, E, S, N, B, T, I}

# Internal constructor that fills up computational details in the "auxiliaries" spot.
function FieldBoundaryConditions(west, east, south, north, bottom, top, immersed)
return FieldBoundaryConditions(west, east, south, north, bottom, top, immersed, nothing, nothing)
end

function FieldBoundaryConditions(indices::Tuple, west, east, south, north, bottom, top, immersed)
Expand All @@ -66,7 +77,7 @@ function FieldBoundaryConditions(indices::Tuple, west, east, south, north, botto
end

FieldBoundaryConditions(indices::Tuple, bcs::FieldBoundaryConditions) =
FieldBoundaryConditions(indices, (getproperty(bcs, side) for side in propertynames(bcs))...)
FieldBoundaryConditions(indices, (getproperty(bcs, side) for side in boundarynames)...)

FieldBoundaryConditions(indices::Tuple, ::Nothing) = nothing
FieldBoundaryConditions(indices::Tuple, ::Missing) = nothing
Expand All @@ -76,14 +87,19 @@ window_boundary_conditions(::UnitRange, left, right) = nothing, nothing
window_boundary_conditions(::Base.OneTo, left, right) = nothing, nothing
window_boundary_conditions(::Colon, left, right) = left, right

# The only thing we need
Adapt.adapt_structure(to, fbcs::FieldBoundaryConditions) = (kernels = fbcs.kernels, ordered_bcs = Adapt.adapt(to, fbcs.ordered_bcs))

on_architecture(arch, fbcs::FieldBoundaryConditions) =
FieldBoundaryConditions(on_architecture(arch, fbcs.west),
on_architecture(arch, fbcs.east),
on_architecture(arch, fbcs.south),
on_architecture(arch, fbcs.north),
on_architecture(arch, fbcs.bottom),
on_architecture(arch, fbcs.top),
on_architecture(arch, fbcs.immersed))
on_architecture(arch, fbcs.immersed),
fbcs.kernels,
on_architecture(arch, fbcs.ordered_bcs))

"""
FieldBoundaryConditions(; kwargs...)
Expand Down
Loading
Loading