Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LevelPlaceholderSpace #1987

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ ClimaCore.jl Release Notes
main
-------

v0.14.15
-------

- Added support for mixing extruded and horizontal spaces in GPU kernels. PR [#1987](https://github.com/CliMA/ClimaCore.jl/pull/1987).

v0.14.14
-------

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 <clima-software@caltech.edu>"]
version = "0.14.14"
version = "0.14.15"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
19 changes: 14 additions & 5 deletions src/Operators/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ end

# Functions for CUDASpectralStyle
struct PlaceholderSpace <: Spaces.AbstractSpace end
struct LevelPlaceholderSpace <: Spaces.AbstractSpace end
struct CenterPlaceholderSpace <: Spaces.AbstractSpace end
struct FacePlaceholderSpace <: Spaces.AbstractSpace end


placeholder_space(current_space, parent_space) = current_space
placeholder_space(current_space::T, parent_space::T) where {T} =
PlaceholderSpace()
placeholder_space(current_space, parent_space) = current_space
placeholder_space(
current_space::Spaces.AbstractPointSpace,
parent_space::Spaces.AbstractFiniteDifferenceSpace,
) = LevelPlaceholderSpace()
placeholder_space(
current_space::Spaces.AbstractSpectralElementSpace,
parent_space::Spaces.ExtrudedFiniteDifferenceSpace,
) = LevelPlaceholderSpace()
Comment on lines +79 to +86
Copy link
Member

Choose a reason for hiding this comment

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

Why should these return level spaces?

Copy link
Member Author

Choose a reason for hiding this comment

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

Suppose that, as in the case of the nonorographic gravity wave parametrization, we have a broadcast over extruded/vertical fields and horizontal/point fields that needs to be evaluated on the GPU. The parent_space in this case is the space of the extruded/vertical output field, and the current_space is either the same as the parent_space or just one level of the parent_space. In the first case we get a PlaceholderSpace, and in the second case we get a LevelPlaceholderSpace.

Copy link
Member

Choose a reason for hiding this comment

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

That may makes sense for the second method, but the first method looks to me like it should return the parent space.

Copy link
Member

Choose a reason for hiding this comment

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

That’s after all how we support point-sphere broadcasting.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the first method returned parent_space instead of LevelPlaceholderSpace, there would be multiple non-placeholder spaces passed to the GPU. My impression is that we want only one non-placeholder space (the output of the broadcast) passed to the GPU, and all other spaces can be reconstructed from that non-placeholder space when they are needed.

With the current design, if a PointField is used in a broadcast expression with a FiniteDifferenceField as the output, a LevelPlaceholderSpace will be returned by placeholder_space and a PointSpace will be returned by reconstruct_placeholder_space. If the first method returned parent_space instead of LevelPlaceholderSpace, reconstruct_placeholder_space would return a FiniteDifferenceSpace for a PointField, which makes no sense to me.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, sorry, I meant ..., but the first method looks to me like it should a type similar to the parent space..

if a PointField is used in a broadcast expression with a FiniteDifferenceField as the output

Given this condition, I agree with you, but this condition is not enforced in placeholder_space, which is why this change looks a bit odd to me.

placeholder_space(
current_space::Spaces.CenterFiniteDifferenceSpace,
parent_space::Spaces.FaceFiniteDifferenceSpace,
Expand All @@ -93,8 +101,12 @@ placeholder_space(
parent_space::Spaces.CenterExtrudedFiniteDifferenceSpace,
) = FacePlaceholderSpace()

@inline reconstruct_placeholder_space(current_space, parent_space) =
current_space
@inline reconstruct_placeholder_space(::PlaceholderSpace, parent_space) =
parent_space
@inline reconstruct_placeholder_space(::LevelPlaceholderSpace, parent_space) =
Spaces.level(parent_space, left_idx(parent_space)) # extract arbitrary level
@inline reconstruct_placeholder_space(
::CenterPlaceholderSpace,
parent_space::Spaces.FaceFiniteDifferenceSpace,
Expand All @@ -111,9 +123,6 @@ placeholder_space(
::FacePlaceholderSpace,
parent_space::Spaces.CenterExtrudedFiniteDifferenceSpace,
) = Spaces.FaceExtrudedFiniteDifferenceSpace(parent_space)
@inline reconstruct_placeholder_space(current_space, parent_space) =
current_space


strip_space(obj, parent_space) = obj

Expand Down
Loading