Skip to content

Allocation-free copy#613

Merged
tapios merged 2 commits into
mainfrom
ts/flux-getter-nocopy
Jul 14, 2026
Merged

Allocation-free copy#613
tapios merged 2 commits into
mainfrom
ts/flux-getter-nocopy

Conversation

@tapios

@tapios tapios commented Jul 14, 2026

Copy link
Copy Markdown
Member

Purpose

Documents copy-free flux getter, to make CPU branch allocation free

To-do

Content


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

tapios and others added 2 commits July 13, 2026 22:59
The output flux getters (`net_flux`, `lw_flux_up`, `sw_flux_dn`, ...) return
single-level views of plain `(nlev, ncol)` presentation buffers, so a host wraps
them with ClimaCore's `array2field` copy-free and in the correct memory order.

A consumer that `copy(getter(solver))`s before wrapping materializes a full
`(nlev, ncol)` field per getter per call; a diagnostics pass reading many fluxes
every step turns that into large per-step allocations (observed as ~17 MB/step
in a ClimaAtmos aquaplanet flame test, from ~12 such copies). RRTMGP itself is
unchanged and its solve stays allocation-free; this documents the getter
contract and adds a regression test so the copy-free guarantee can't silently
regress.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tapios
tapios requested a review from szy21 July 14, 2026 14:44
Comment thread test/standalone.jl
full = @allocated copy(g) # copy materializes a full field
read = @allocated (dst .= g) # reading needs no such copy
@test full >= length(g) * sizeof(eltype(g))
@test read < full ÷ 4

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.

wow I didn't know this symbol ÷ exists

@tapios
tapios merged commit a625448 into main Jul 14, 2026
16 of 20 checks passed
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.

2 participants