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

Broadcasting or-or incurs allocations #1355

Closed
charleskawczynski opened this issue Jun 30, 2023 · 4 comments
Closed

Broadcasting or-or incurs allocations #1355

charleskawczynski opened this issue Jun 30, 2023 · 4 comments
Labels
Allocations bug Something isn't working performance

Comments

@charleskawczynski
Copy link
Member

charleskawczynski commented Jun 30, 2023

MWE:

using Revise, Test
import ClimaCore
if !(@isdefined TU)
    include(joinpath(pkgdir(ClimaCore), "test", "TestUtilities", "TestUtilities.jl"))
    import .TestUtilities as TU
end
foo(a, c) = a;
FT_broadcast_allocating!(a) = FT_broadcast_allocating!(a, eltype(a));
function FT_broadcast_allocating!(a, ::Type{FT}) where FT
    @. a = foo(a, false || a < FT(1))
    # @. a = foo(a, a < FT(1)) # unexpected pass
    return nothing
end;
space = TU.CenterExtrudedFiniteDifferenceSpace(Float32);
a = ClimaCore.Fields.level(fill(Float32(0), space), 1);

FT_broadcast_allocating!(a) # compile first

p_allocated = @allocated FT_broadcast_allocating!(a)
@test_broken p_allocated == 0
@simonbyrne
Copy link
Member

Does broadcasting over || actually work?

@charleskawczynski
Copy link
Member Author

Does broadcasting over || actually work?

It at least doesn't break

@charleskawczynski charleskawczynski changed the title Broadcasting ifelse sometimes incurs allocations Broadcasting or-or incurs allocations Jul 14, 2023
@charleskawczynski
Copy link
Member Author

This is an upstream issue: JuliaLang/julia#50554

@charleskawczynski
Copy link
Member Author

This is now fixed in Julia 1.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Allocations bug Something isn't working performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants