-
Notifications
You must be signed in to change notification settings - Fork 80
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
Use style dispatch in broadcast(!) #393
Conversation
@@ -47,7 +47,15 @@ end | |||
copyto!(similar(bc, ElType), bc) | |||
end | |||
|
|||
@inline function Base.copyto!(dest::BroadcastGPUArray, bc::Broadcasted{Nothing}) | |||
@inline function Base.materialize!(::Style, dest, bc::Broadcasted) where {Style<:AbstractGPUArrayStyle} | |||
return _copyto!(dest, instantiate(Broadcasted{Style}(bc.f, bc.args, axes(dest)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this, and the original Base implementation at https://github.com/JuliaLang/julia/blob/17775537232de5b12a38b257e402756b6df55386/base/broadcast.jl#L871, creates a Broadcasted{<:AbstractGPUArrayStyle}
, why doesn't the copyto!(::AbstractArray, Broadcasted{<:AbstractGPUArrayStyle})
implementation below suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base
won't create a Broadcasted{<:AbstractGPUArrayStyle}
, bc
's stype is kept there.
So we need to create Broadcasted{<:AbstractGPUArrayStyle}
ourself.
The error should be unrelated? |
Style-based dispatch would be easier to extend by external array wrapper package. (Reusing more code)
JuliaArrays/StructArrays.jl#215
OffsetArrays
should be simiar, but IIRC@cartesianidx(dest, i)
doesn't support 1d offset axes.This PR also wants to move
backend
toAdapt.jl
JuliaGPU/Adapt.jl#50 to keep dependence lightweight.