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

Scalar indexing with CuArray * ReshapedArray{SubArray{CuArray}}} #2009

Closed
vpuri3 opened this issue Jul 26, 2023 · 1 comment
Closed

Scalar indexing with CuArray * ReshapedArray{SubArray{CuArray}}} #2009

vpuri3 opened this issue Jul 26, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@vpuri3
Copy link
Contributor

vpuri3 commented Jul 26, 2023

MWE:

julia> CUDA.allowscalar(false)                                                                                                                                                                          [0/1467]
                                                                                                                                                                                                                
julia> CUDA.ones(5, 4) * reshape(view(CUDA.ones(10, 10, 10), 1:4, :, :), 4, 100)                                                                                                                                
ERROR: Scalar indexing is disallowed.                                                                                                                                                                           
Invocation of getindex 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.                                                                                                                                   
Stacktrace:                                                                                                                                                                                                     
  [1] error(s::String)                                                                                                                                                                                          
    @ Base ./error.jl:35                                                                                                                                                                                        
  [2] assertscalar(op::String)                                                                                                                                                                                  
    @ GPUArraysCore ~/.julia/packages/GPUArraysCore/uOYfN/src/GPUArraysCore.jl:103                                                                                                                              
  [3] getindex(::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, ::Int64, ::Int64)                                                                                                                                  
    @ GPUArrays ~/.julia/packages/GPUArrays/5XhED/src/host/indexing.jl:9     
  [4] _generic_matmatmul!(C::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, tA::Char, tB::Char, A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, B::Base.ReshapedArray{Float32, 2, SubArray{Float32, 3, CuArray{Float
32, 3, CUDA.Mem.DeviceBuffer}, Tuple{UnitRange{Int64}, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, false}, Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}, Base.Multipl
icativeInverses.SignedMultiplicativeInverse{Int64}}}, _add::LinearAlgebra.MulAddMul{true, true, Bool, Bool})                                                                                                    
    @ LinearAlgebra ~/.julia/juliaup/julia-1.9.2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:876
  [5] generic_matmatmul!(C::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, tA::Char, tB::Char, A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, B::Base.ReshapedArray{Float32, 2, SubArray{Float32, 3, CuArray{Float3
2, 3, CUDA.Mem.DeviceBuffer}, Tuple{UnitRange{Int64}, Base.Slice{Base.OneTo{Int64}}, Base.Slice{Base.OneTo{Int64}}}, false}, Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}, Base.Multipli
cativeInverses.SignedMultiplicativeInverse{Int64}}}, _add::LinearAlgebra.MulAddMul{true, true, Bool, Bool})
    @ LinearAlgebra ~/.julia/juliaup/julia-1.9.2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:844
  [6] mul!                                                                                              
    @ ~/.julia/juliaup/julia-1.9.2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:303 [inlined]                                                                                            
  [7] mul!                                                                                                                                                                                                      
    @ ~/.julia/juliaup/julia-1.9.2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:276 [inlined]
  [8] *(A::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, B::Base.ReshapedArray{Float32, 2, SubArray{Float32, 3, CuArray{Float32, 3, CUDA.Mem.DeviceBuffer}, Tuple{UnitRange{Int64}, Base.Slice{Base.OneTo{Int64}},
 Base.Slice{Base.OneTo{Int64}}}, false}, Tuple{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}, Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64}}})
    @ LinearAlgebra ~/.julia/juliaup/julia-1.9.2+0.x64.linux.gnu/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:141
  [9] top-level scope
    @ REPL[8]:1
 [10] top-level scope
    @ ~/.julia/packages/CUDA/tVtYo/src/initialization.jl:185
@vpuri3 vpuri3 added the bug Something isn't working label Jul 26, 2023
@vpuri3 vpuri3 changed the title Scalar indexing with CuArray * ReshapedArray(SubArray) Scalar indexing with CuArray * ReshapedArray{SubArray{CuArray}}} Jul 26, 2023
@maleadt
Copy link
Member

maleadt commented Aug 15, 2023

That's "expected"; multiple layers of array wrappers are not supported, as it would require an exponential amount of method definitions. See JuliaGPU/Adapt.jl#21. Would require support in Base to fix this using traits, e.g., JuliaLang/julia#31563.

@maleadt maleadt closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants