-
Notifications
You must be signed in to change notification settings - Fork 221
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
Implement convert
between Array and CuArray like unsafe_wrap
#2434
Comments
On second thought, I assume Julia's array constructors are typically assumed to make a copy of the incoming data. But probably In the same way, |
I would agree that EDIT: Thinking about this some more, I'm not entirely convinced if |
CuArray{T,N,CUDA.HostMemory}(A::Array{T,N})
equal unsafe_wrap(CuArray, A)
?convert
between Array and CuArray like unsafe_wrap
Alia occurs only when the original type and the converted type are the same - see https://github.com/JuliaLang/julia/blob/8f5b7ca12ad48c6d740e058312fc8cf2bbe67848/base/essentials.jl#L439-L461 Making |
The docstring is much more general:
So using |
I am not sure if this qualifies as a bug or a feature request, but I was wondering whether the constructor
CuArray{T,N,CUDA.HostMemory}(A::Array{T,N})
shouldunsafe_wrap(CuArray, A)
?The current general implementation at https://github.com/JuliaGPU/CUDA.jl/blob/master/src/array.jl#L404 will allocate new host memory and then copy the contents of
A
into this. Because of this, alsoconvert(CuArray{T,N,CUDA.HostMemory}, A::Array{T,N})
(over at GPUArrays.jl) and ultimatelyadapt(CuArray{T,N,CUDA.HostMemory}, A::Array{T,N})
will result in new host memory being allocated. Hence, the only way to actually reuseA
is viaunsafe_wrap(CuArray, A)
, but that does only work forA::Array
and not for any of the wrapper types that one could feed intoadapt
.The text was updated successfully, but these errors were encountered: