Skip to content

Conversation

@juliasloan25
Copy link
Member

@juliasloan25 juliasloan25 commented Dec 5, 2025

Purpose

Before we were calling the allocating get_field method. Now we remap and store the surface field in a temp coupler field, so we don't allocate. To me it's also more readable now which is nice.

Content

  • remove allocations in combine_surfaces by remapping the surface field of each simulation onto a temp coupler field
  • update tests
  • check buildkite results as compared to main
  • check buildkite performance as compared to main

  • I have read and checked the items on the review checklist.

@juliasloan25 juliasloan25 requested a review from ph-kev December 5, 2025 01:48
@juliasloan25
Copy link
Member Author

This change actually slightly worsens performance. I think it's because of runtime dispatch on the field_name Val, so I'm restructuring this function a bit

@juliasloan25
Copy link
Member Author

juliasloan25 commented Dec 5, 2025

Ok, with the current state of this PR it does speed up simulations. For example comparing this build to main we see the following SYPD changes:

  • GPU slabplanet albedo from function: 2.174 SYPD --> 3.017 SYPD
  • GPU AMIP diag. EDMF + bucket: 0.15 SYPD --> 0.274 SYPD
  • GPU CMIP with prescribed sea ice: 4.426 SYPD --> 5.511 SYPD

However runs with integrated land has the opposite trend:

  • AMIP integrated land non-spun up IC test: 0.204 SYPD --> 0.12 SYPD
  • AMIP ED only + integrated land: 0.415 SYPD --> 0.321 SYPD
  • AMIP diag EDMF + integrated land: 0.149 SYPD --> 0.121 SYPD

@juliasloan25
Copy link
Member Author

juliasloan25 commented Dec 5, 2025

physical results
unchanged: slabplanet with albedo from function, CMIP with prescribed sea ice
changed (only MO length, precipitation): ED only + bucket, diag EDMF + bucket, AMIP ED only + integrated land

@juliasloan25
Copy link
Member Author

juliasloan25 commented Dec 5, 2025

I did some investigating into why this PR slightly slows down the benchmark, and it comes down to the following. When we swap the roles of remap and remap! in #1594 this should be fixed and then we can apply this PR and should see speedup.

  • get_field! allocates more than get_field
julia> @allocated Interfacer.get_field!(csf.scalar_temp1, sim, Val(:area_fraction))
160

julia> @allocated Interfacer.get_field(sim, Val(:area_fraction), boundary_space)
32

this is because:

  • remap! allocates more than remap
julia> @allocated Interfacer.remap!(field2, field1)
128

julia> @allocated Interfacer.remap(field1, boundary_space)
32
  • using zero(field) in broadcasted ifelse allocates (we do this in many places and need to remove them all)
julia> @allocated combined_field .+=
                       area_fraction .*
                       ifelse.(area_fraction .≈ 0, zero(combined_field), surface_field)
6544

julia> @allocated combined_field .+=
                       area_fraction .*
                       ifelse.(area_fraction .≈ 0, zero(eltype(combined_field)), surface_field)
272

julia> @allocated combined_field .+=
                       area_fraction .*
                       ifelse.(area_fraction .≈ 0, 0, surface_field)
272 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants