Defer BroadcastStyle construction to back-ends. #506
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To fix JuliaGPU/CUDA.jl#2191, where broadcasting a CuArray backed by unified memory results in a CuArray in device memory (i.e. the buffer type is lost), I want to make the
CuArrayStyle
broadcast style include the buffer type so that we can preserve it. That's currently impossible, as the style is constructed by GPUArrays, by doing the very cursedAdapt.parent(W){Adapt.eltype(W), Adapt.ndims(W)}
constructor call (Adapt.parent
currently returns an unordained typename), which both does not know about the additional buffer typevar, and calls a specific constructor without setting the buffer typevar.Instead, in JuliaGPU/Adapt.jl#75 I make it so that
Adapt.parent
(renamed toAdapt.parent_type
to avoid confusion withBase.parent
, which doesn't work on types) returns the full type, including the buffer typevar. Then, in this PR, I make it so that the back-end is not responsible for providing theBroadcastStyle
methods, so that additional information can be put in there.Changes to back-ends should be minimal, see the JLArrays diff in here, or JuliaGPU/CUDA.jl#2203. It is however a breaking change.
cc @vchuravy @jpsamaroo @pxl-th