JuliaGPU / JuliaGPU/CUDA.jl

Higher-level API for unsafe_copy3d!

Open
#83 0 comments 0 reactions 0 assignees View on GitHub
cuda array enhancement
Dominant language
Julia
Stars
1.4k
Forks
281
Avg merge
1d 7h
Merged PRs (30d)
30

Description

It would be nice to have higher level API to perform 3-D memcopy (relying on `Mem.unsafe_copy3d!` from `CUDAdrv`). Here is a collection of the discussions on done in the PR [Wrap 3d memcpy JuliaGPU/CUDAnative.jl#238 in CUDAdrv](https://github.com/JuliaGPU/CUDAdrv.jl/pull/238):

> Thoughts on a more high-level API are welcome too.

What do you think about a CUDAnative function with a signature approximately like the following?
```
copy3d!(
src::AbstractArray{},
srcranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}},
dst::AbstractArray{},
dstranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}};
async::Bool=false,
stream::Union{Nothing,CuStream}=nothing
)
```
Moreover, CuArrays could then maybe invoke this function automatically for 3-D copies in vectorized notation (e.g. A[:, :] = B[:, 2, :]) that match the requirements.

>> What do you think about a CUDAnative function with a signature approximately like the following?

> The problem is that we can't know from an array if it's host|device, or unified memory.

I see. Maybe something along the following lines? That is, the idea would be to use multiple dispatch with specialization for CuArray arguments. For CuArrays one could determine if it is a host/device/unifiedmem array; for the AbstractArrays one would assume always that it is a host array.
```
copy3d!(
src::CuArray{},
srcranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}},
dst::CuArray{},
dstranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}};
async::Bool=false,
stream::Union{Nothing,CuStream}=nothing
)

copy3d!(
src::CuArray{},
srcranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}},
dst::AbstractArray{},
dstranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}};
async::Bool=false,
stream::Union{Nothing,CuStream}=nothing
)

copy3d!(
src::AbstractArray{},
srcranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}},
dst::CuArray{},
dstranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}};
async::Bool=false,
stream::Union{Nothing,CuStream}=nothing
)

copy3d!(
src::AbstractArray{},
srcranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}},
dst::AbstractArray{},
dstranges::Tuple{Union{UnitRange{},Integer},Union{UnitRange{},Integer},Union{UnitRange{},Integer}};
async::Bool=false,
stream::Union{Nothing,CuStream}=nothing
)
```

>> For CuArrays one could determine if it is a host/device/unifiedmem array; for the AbstractArrays one would assume always that it is a host array

> No, that's not true, because of unsafe_wrap!.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.