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

Use style dispatch in broadcast(!) #393

Merged
merged 3 commits into from
Mar 15, 2022
Merged

Use style dispatch in broadcast(!) #393

merged 3 commits into from
Mar 15, 2022

Conversation

N5N3
Copy link
Contributor

@N5N3 N5N3 commented Feb 20, 2022

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 to Adapt.jl JuliaGPU/Adapt.jl#50 to keep dependence lightweight.

src/device/indexing.jl Outdated Show resolved Hide resolved
src/host/broadcast.jl Outdated Show resolved Hide resolved
@maleadt
Copy link
Member

maleadt commented Feb 21, 2022

So this is a rebase of #295? cc @vchuravy

@@ -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))))
Copy link
Member

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?

Copy link
Contributor Author

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.

test/testsuite/broadcasting.jl Show resolved Hide resolved
@N5N3
Copy link
Contributor Author

N5N3 commented Feb 25, 2022

The error should be unrelated?

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

Successfully merging this pull request may close these issues.

2 participants