CliMA / CliMA/ClimaCore.jl

Allocations incurred from `copyto!` with `FastBroadcast`

Open
#1,356 0 comments 0 reactions 0 assignees View on GitHub
Allocations bug
Dominant language
Julia
Stars
117
Forks
19
Avg merge
3d 4h
Merged PRs (30d)
41

Description

MWE:

```julia
using FastBroadcast
using Test
import ClimaCore
include(
joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"),
)
import .TestUtilities as TU

function fast_broadcast_single_field!(Y1, dt, Y2)
x = Y1.x
@.. x += 2.0
nothing
end
# Removing dt from argument fixes allocations
function fast_broadcast_copyto!(Y1, dt, Y2)
@.. Y1 = Y2
nothing
end
@testset "Allocations in @.. broadcasting" begin
FT = Float32
for space in TU.all_spaces(FT)
Y1 = fill((; x = FT(2.0), y = FT(2.0), z = FT(2.0)), space)
Y2 = fill((; x = FT(2.0), y = FT(2.0), z = FT(2.0)), space)
Y3 = fill((; x = FT(2.0), y = FT(2.0), z = FT(2.0)), space)
dt = FT(2.0)
fast_broadcast_single_field!(Y1, dt, Y2)
p = @allocated fast_broadcast_single_field!(Y1, dt, Y2)
@test p == 0
fast_broadcast_copyto!(Y1, dt, Y2)
p = @allocated fast_broadcast_copyto!(Y1, dt, Y2)
@test_broken p == 0
end
end
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Julia MWE and confirm the allocation difference between the two @.. functions. Inspect the FastBroadcast copyto! path and compare it with the single-field broadcast case. Done means the copyto! case no longer allocates and the broken allocation assertion can pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.