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

Defer BroadcastStyle construction to back-ends. #506

Merged
merged 4 commits into from
Dec 19, 2023

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Dec 13, 2023

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 cursed Adapt.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 to Adapt.parent_type to avoid confusion with Base.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 the BroadcastStyle 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

@maleadt maleadt force-pushed the tb/defer_broadcaststyle branch 3 times, most recently from 9ec1077 to f20efe2 Compare December 18, 2023 16:02
@maleadt maleadt marked this pull request as ready for review December 18, 2023 16:09
@maleadt maleadt force-pushed the tb/defer_broadcaststyle branch 14 times, most recently from 852447f to abdac33 Compare December 18, 2023 20:28
@maleadt maleadt merged commit b2c6998 into master Dec 19, 2023
13 of 14 checks passed
@maleadt maleadt deleted the tb/defer_broadcaststyle branch December 19, 2023 09:38
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.

Broadcast does not preserve buffer type
1 participant