Reuse Base.ReshapeArray/ReinterpretArray #322
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.
Currently,
reshape
andreinterpret
are expected to yield the original array type, complicating that type's definition (it should somehow refcount the underlying buffer, or otherwise support mutating the object). Furthermore, withview
we sometimes (in the non-contiguous case) need to return aSubArray
anyhow. So let's just get rid of that behavior, re-useBase.ReshapedArray
andReinterpretArray
.As a result, downstream packages (i.e. CUDA.jl, AMDGPU.jl, oneAPI.jl) will need to make sure operations that previously only needed to accept a
::GPUArray
now also accept aReinterpretArray{<:CuArray}
, and the same forReshapeArray
. The reference implementation here does so using aDenseJLArray
type, for methods that work with (a pointer to) contiguous memory. Next to that, this PR also addsStridedJLArray
for supporting methods that accept a pointer and a stride (not used here, but interesting for working with CUBLAS in JuliaGPU/CUDA.jl#435), and we already hadWrappedJLArray
for types that we can convert to something GPU-compatible (i.e. for kernels).TL;DR: remove
GPUArrays.unsafe_reinterpret
, don't implementBase._reshape
, add aDenseGPUArray
definition and use that with methods that previously accepted::GPUArray
and converted it to a pointer. For bonus points: do the same forview
and always have it return aSubArray
, introduce aStridedGPUArray
type and use it for methods that can work with a pointer+stride, and together with thereshape
/reinterpret
changes this should allow removing all buffer refcounting from your GPU array type.cc @jpsamaroo