Skip to content
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

Adding copyto for non-contiguous matrices and vectors #1778

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

evelyne-ringoot
Copy link
Contributor

No description provided.

@evelyne-ringoot evelyne-ringoot changed the title Adding copyto for non-contigous matrices and vectors Adding copyto for non-contiguous matrices and vectors Feb 22, 2023
@evelyne-ringoot evelyne-ringoot marked this pull request as draft March 1, 2023 06:05
@evelyne-ringoot evelyne-ringoot marked this pull request as ready for review March 1, 2023 21:25
@jpsamaroo jpsamaroo requested a review from maleadt March 3, 2023 14:26
@maleadt
Copy link
Member

maleadt commented Mar 15, 2023

@maleadt maleadt added the cuda array Stuff about CuArray. label Mar 15, 2023
@evelyne-ringoot
Copy link
Contributor Author

evelyne-ringoot commented Sep 5, 2023

Linking #1829 which is one of the use cases

I get the following scalar indexing error:

julia> a= CUDA.randn(10,10)
10×10 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}:

julia> aview=view(a,2:2:6,3:2:7)
3×3 view(::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, 2:2:6, 3:2:7) with eltype Float32:

julia> b= ones(Float32,8,8)
8×8 Matrix{Float32}:

julia> bview=view(b,2:2:6,3:2:7)
3×3 view(::Matrix{Float32}, 2:2:6, 3:2:7) with eltype Float32:

julia> copyto!(aview,bview)
┌ Warning: Performing scalar indexing on task Task (runnable) @0x000001dfa8d20010.
│ Invocation of setindex! resulted in scalar indexing of a GPU array.
│ This is typically caused by calling an iterating implementation of a method.
│ Such implementations *do not* execute on the GPU, but very slowly on the CPU,
│ and therefore are only permitted from the REPL for prototyping purposes.
│ If you did intend to index this array, annotate the caller with @allowscalar.
└ @ GPUArraysCore C:\Users\evely\.julia\packages\GPUArraysCore\HaQcr\src\GPUArraysCore.jl:106
3×3 view(::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, 2:2:6, 3:2:7) with eltype Float32:
 1.0  1.0  1.0
 1.0  1.0  1.0
 1.0  1.0  1.0

julia> @which copyto!(aview,bview)
copyto!(dest::AbstractArray, src::AbstractArray)
     @ Base abstractarray.jl:1066

julia> typeof(aview)
SubArray{Float32, 2, CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, Tuple{StepRange{Int64, Int64}, StepRange{Int64, Int64}}, false}

julia> typeof(bview)
SubArray{Float32, 2, Matrix{Float32}, Tuple{StepRange{Int64, Int64}, StepRange{Int64, Int64}}, false}

julia> 

Possibly https://github.com/JuliaGPU/GPUArrays.jl/blob/4bb112c55c581e51e21d07a7df2dc2df7a8ca20e/src/host/abstractarray.jl#L51-L81 cannot handle non-contiguous memory and https://github.com/JuliaGPU/GPUArrays.jl/blob/4bb112c55c581e51e21d07a7df2dc2df7a8ca20e/src/host/abstractarray.jl#L151-L214 does not handle a mix of Subarrays on GPU and CPU? Perhaps this could also be resolved by changing line 179 in the latter from 'AbstractGPUArray' to 'Union{SubArray{<:Any, <:Any, <:AbstractGPUArray}, AbstractGPUArray}', but this might increase compilation time? Might also need to include Adjoints and Transponse in the union, to be determined.

@evelyne-ringoot
Copy link
Contributor Author

evelyne-ringoot commented Sep 11, 2023

@maleadt Is this one ready? Also linking #1830 which is a more light-weight attempt to do the same, but does not cover all possible types of views I believe

@maleadt maleadt force-pushed the master branch 15 times, most recently from 5d585c4 to c850163 Compare December 20, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants