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

Fix type-casting allocations in broadcasting #1365

Closed
wants to merge 1 commit into from

Conversation

charleskawczynski
Copy link
Member

@charleskawczynski charleskawczynski commented Jul 11, 2023

Closes #1355 and #1097.

I'm not thrilled that this is basically type piracy, but it does fix the allocations. It's actually a bit surprising to me that a simple definition doesn't exist in Base.

This should fix the GPU moisture issue in ClimaAtmos (among other isbits errors and allocations).

@@ -301,6 +301,8 @@ Base.Broadcast.broadcasted(
::Val{n},
) where {n} = Base.Broadcast.broadcasted(x -> Base.literal_pow(^, x, Val(n)), f)

Base.Broadcast.broadcasted(::Type{T}, x::Number) where {T <: Number} = x
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Base.Broadcast.broadcasted(::Type{T}, x::Number) where {T <: Number} = x
Base.Broadcast.broadcasted(::Type{T}, x::Number) where {T <: Number} = T(x)

I guess we should actually do this instead

@charleskawczynski
Copy link
Member Author

We can work around this on the implementation side, without type piracy. Maybe that's a better solution for now, until JuliaLang/julia#50554 is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broadcasting or-or incurs allocations
1 participant