Skip to content

Commit

Permalink
Add FastBroadcast alloc test
Browse files Browse the repository at this point in the history
Add broken test
  • Loading branch information
charleskawczynski committed Jul 5, 2023
1 parent b11470c commit 7ed2246
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

0 comments on commit 7ed2246

Please sign in to comment.