Skip to content

Implement convert between Array and CuArray like unsafe_wrap #2434

@Jutho

Description

@Jutho

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}) should unsafe_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, also convert(CuArray{T,N,CUDA.HostMemory}, A::Array{T,N}) (over at GPUArrays.jl) and ultimately adapt(CuArray{T,N,CUDA.HostMemory}, A::Array{T,N}) will result in new host memory being allocated. Hence, the only way to actually reuse A is via unsafe_wrap(CuArray, A), but that does only work for A::Array and not for any of the wrapper types that one could feed into adapt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cuda arrayStuff about CuArray.hardThis is difficult.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions