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 Grids, make them mutable objects #1487

Merged
merged 71 commits into from
Nov 16, 2023
Merged

Add Grids, make them mutable objects #1487

merged 71 commits into from
Nov 16, 2023

Conversation

simonbyrne
Copy link
Member

Fixes #1120 and #1467.

I've gone with option 2 in #1120 (comment).

In the following benchmark:

using ClimaComms

import ClimaCore:
    ClimaCore,
    slab,
    Spaces,
    Domains,
    Meshes,
    Geometry,
    Topologies,
    Spaces,
    Fields,
    Operators


FT = Float64
vertdomain = Domains.IntervalDomain(
    Geometry.ZPoint{FT}(0.0),
    Geometry.ZPoint{FT}(1.0);
    boundary_tags = (:bottom, :top),
)
vertmesh = Meshes.IntervalMesh(vertdomain, nelems = 10)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)

horzdomain = Domains.SphereDomain(30.0)
horzmesh = Meshes.EquiangularCubedSphere(horzdomain, 4)
horztopology = Topologies.Topology2D(
    ClimaComms.SingletonCommsContext(ClimaComms.CPUSingleThreaded()),
    horzmesh,
)
quad = Spaces.Quadratures.GLL{3 + 1}()
horzspace = Spaces.SpectralElementSpace2D(horztopology, quad)

hv_center_space =
    Spaces.ExtrudedFiniteDifferenceSpace(horzspace, vert_center_space)

coords = Fields.coordinate_field(hv_center_space)
x = Geometry.UVWVector.(cosd.(coords.lat), 0.0, 0.0)


t = ntuple(i -> x, 80);
f(t) = t
@time f(t);

On main:

julia> @time f(t);
  1.455831 seconds (343 allocations: 24.953 KiB, 100.00% compilation time)

on this branch

julia> @time f(t);
  0.002401 seconds (343 allocations: 24.953 KiB, 99.12% compilation time)
  • Code follows the style guidelines OR N/A.
  • Unit tests are included OR N/A.
  • Code is exercised in an integration test OR N/A.
  • Documentation has been added/updated OR N/A.

@Sbozzolo
Copy link
Member

Sbozzolo commented Oct 4, 2023

With regards to integration in ClimaAtmos, I had this in mind: CliMA/ClimaAtmos.jl#2147

I also defined some Grid objects that are directly relevant to the most common applications in ClimaAtmos

@Sbozzolo Sbozzolo mentioned this pull request Oct 4, 2023
@simonbyrne
Copy link
Member Author

@Sbozzolo for ClimaAtmos, could we just use the ClimaCore grid objects directly?

@Sbozzolo
Copy link
Member

Sbozzolo commented Oct 4, 2023

@Sbozzolo for ClimaAtmos, could we just use the ClimaCore grid objects directly?

I think we should have simple and physically-relevant objects in ClimaAtmos. The computational grid is one of the main players in a simulation, and I think that the ClimaCore grids are still too low level. I think that it should be easy to know if I am simulating a sphere or a plane and get the relevant properties (How many points do I have? What is the physical extent? What is the radius of the sphere?)

In ClimaAtmos, we care about 4 configurations (x2 depending if your vertical resolution is constant or not):

  • sphere
  • box
  • plane
  • column

For 2 of these 4, we want to support topography and optionally enable the bubble correction. These are clearly distinct
cases that have implications for the rest of ClimaAtmos. For example, there are flags that are automatically turned on/off for some cases, and now we are relying on manually checking parsed_args. In addition to this, building the various cases requires specialized code that is purview of ClimaAtmos, so I think that there are good reasons to add another level of abstraction in ClimaAtmos.

@simonbyrne
Copy link
Member Author

We could probably define type aliases that would allow you to do dispatch, e.g.

const ExtrudedCubedSphereGrid = ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid2D{<:Topology2D{<:ClimaComms.AbstractCommsContext, <:AbstractCubedSphereMesh}}}

@simonbyrne
Copy link
Member Author

If it would help, we could make this simpler by making the lower level objects (domain, mesh) fields of the grid as well?

@simonbyrne
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Oct 20, 2023
@bors
Copy link
Contributor

bors bot commented Oct 20, 2023

try

Build failed:

bors bot added a commit that referenced this pull request Oct 27, 2023
@bors
Copy link
Contributor

bors bot commented Oct 27, 2023

try

Build failed:

@simonbyrne
Copy link
Member Author

bors try

bors bot added a commit that referenced this pull request Oct 28, 2023
@bors
Copy link
Contributor

bors bot commented Oct 28, 2023

try

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@simonbyrne simonbyrne marked this pull request as ready for review October 28, 2023 20:58
@simonbyrne
Copy link
Member Author

face_local_geometry::LG
end

@memoize WeakValueDict function ExtrudedFiniteDifferenceGrid(
Copy link
Member

Choose a reason for hiding this comment

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

Can we document (or provide a link to docs to show) what @memoise WeakValueDict is doing here? or somewhere?

@@ -50,7 +50,7 @@ single_field_solve!(::ClimaComms.AbstractCPUDevice, cache, x, A, b) =
_single_field_solve!(cache, x, A, b)
function single_field_solve!(::ClimaComms.CUDADevice, cache, x, A, b)
Ni, Nj, _, _, Nh = size(Fields.field_values(A))
nthreads, nblocks = Spaces._configure_threadblock(Ni * Nj * Nh)
nthreads, nblocks = Topologies._configure_threadblock(Ni * Nj * Nh)
Copy link
Member

@charleskawczynski charleskawczynski Nov 1, 2023

Choose a reason for hiding this comment

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

Can/should we instead move _configure_threadblock to _configure_threadblock a separate file or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Member

Choose a reason for hiding this comment

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

_configure_threadblock doesn't really have anything to do with Topologies

Co-authored-by: Charles Kawczynski <[email protected]>
Copy link
Member

@charleskawczynski charleskawczynski left a comment

Choose a reason for hiding this comment

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

Overall, the changes look good, and I want to slow this down given the quality of life improvement it brings!

@charleskawczynski
Copy link
Member

And thanks for testing in CliMA Atmos!

@simonbyrne simonbyrne merged commit c6b3ee3 into main Nov 16, 2023
14 checks passed
@simonbyrne simonbyrne deleted the sb/mutable-grid branch November 16, 2023 20:55
@Sbozzolo Sbozzolo mentioned this pull request Dec 22, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants