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 FastBroadcast alloc test #966

Merged
merged 1 commit into from
Jul 6, 2023
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
28 changes: 28 additions & 0 deletions test/Fields/field_opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ClimaCore.DataLayouts: IJFH
import ClimaCore:
Fields, slab, Domains, Topologies, Meshes, Operators, Spaces, Geometry

using FastBroadcast
using LinearAlgebra: norm
using Statistics: mean
using ForwardDiff
Expand Down Expand Up @@ -71,6 +72,33 @@ end
end
end

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
# https://github.com/CliMA/ClimaCore.jl/issues/1356
@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

# https://github.com/CliMA/ClimaCore.jl/issues/963
sc(::Type{FT}) where {FT} =
Operators.StencilCoefs{-1, 1}((zero(FT), one(FT), zero(FT)))
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
CubedSphere = "7445602f-e544-4518-8976-18f8e8ae6cdb"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GFlops = "2ea8233c-34d4-5acc-88b4-02f326385bcc"
GaussQuadrature = "d54b0c1a-921d-58e0-8e36-89d8069c0969"
Expand Down
Loading