You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using copyto! wtih a destination on the device and a view of an array on the host causing scalar indexing.
To reproduce
The Minimal Working Example (MWE) for this bug:
using CUDA
full_cpu_arr =collect(1:128)
partial_cpu_arr =view(full_cpu_arr, 1:16)
# Preallocate the
a_gpu = CUDA.zeros(Int, length(partial_cpu_arr))
# The following causing scalar indexing?copyto!(a_gpu, partial_cpu_arr)
Manifest.toml
CUDA v4.0.1
Expected behavior
For a view with a contiguous range (i.e. a UnitRange), this should behave exactly like copying a normal dense array, but with an offset pointer and copying fewer elements.
I was able to do some type piracy to fix the problem, as the SubArray type (i.e. what comes out of view implements pointer function). The type definitions could probably be made broader as this only allows ints to be copied:
Base.copyto!(dest::CuArray{T}, src::SubArray{T, 1, Vector{T}}) where {T<:Int} =copyto!(dest, 1, src, 1, length(src))
function Base.copyto!(dest::CuArray{T}, doffs::Integer, src::SubArray{T, 1, Vector{T}}, soffs::Integer,
n::Integer) where {T<:Int}
n==0&&return dest
@boundscheckcheckbounds(dest, doffs)
@boundscheckcheckbounds(dest, doffs+n-1)
@boundscheckcheckbounds(src, soffs)
@boundscheckcheckbounds(src, soffs+n-1)
unsafe_copyto!(dest, doffs, src, soffs, n)
return dest
endfunction Base.unsafe_copyto!(dest::CuArray{T}, doffs,
src::SubArray{T, 1, Vector{T}}, soffs, n) where {T<:Int}
CUDA.context!(CUDA.context(dest)) do# operations on unpinned memory cannot be executed asynchronously, and synchronize# without yielding back to the Julia scheduler. prevent that by eagerly synchronizing.
s = CUDA.stream()
CUDA.is_pinned(pointer(src)) || CUDA.nonblocking_synchronize(s)
GC.@preserve src dest begin
CUDA.unsafe_copyto!(pointer(dest, doffs), pointer(src, soffs), n; async=true)
endendreturn dest
end
The text was updated successfully, but these errors were encountered:
Describe the bug
Using
copyto!
wtih a destination on the device and a view of an array on the host causing scalar indexing.To reproduce
The Minimal Working Example (MWE) for this bug:
Manifest.toml
Expected behavior
For a view with a contiguous range (i.e. a UnitRange), this should behave exactly like copying a normal dense array, but with an offset pointer and copying fewer elements.
Version info
Details on Julia: 1.8.5
Details on CUDA:
Additional context
I was able to do some type piracy to fix the problem, as the
SubArray
type (i.e. what comes out ofview
implementspointer
function). The type definitions could probably be made broader as this only allows ints to be copied:The text was updated successfully, but these errors were encountered: