JuliaGPU / JuliaGPU/GPUArrays.jl

`copyto!` of triangular of adjoint fails

Open
#354 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
450
Forks
104
Avg merge
1d 4h
Merged PRs (30d)
10

Description

```julia
julia> using CUDA, LinearAlgebra

julia> CUDA.allowscalar(false)

julia> U = cu(UpperTriangular(
[1.0 0.0;
0.0 1.0]
))
2×2 UpperTriangular{Float32, CuArray{Float32, 2}}:
1.0 0.0
⋅ 1.0

julia> copyto!(Σ, U')
ERROR: scalar getindex is disallowed
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] assertscalar(op::String)
@ GPUArrays ~/.julia/packages/GPUArrays/4n0iS/src/host/indexing.jl:62
[3] getindex(::CuArray{Float32, 2}, ::Int64, ::Int64)
@ GPUArrays ~/.julia/packages/GPUArrays/4n0iS/src/host/indexing.jl:104
[4] getindex
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:203 [inlined]
[5] getindex
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/triangular.jl:222 [inlined]
[6] _getindex
@ ./abstractarray.jl:1214 [inlined]
[7] getindex
@ ./abstractarray.jl:1170 [inlined]
[8] iterate
@ ./abstractarray.jl:1096 [inlined]
[9] iterate
@ ./abstractarray.jl:1094 [inlined]
[10] copyto_unaliased!(deststyle::IndexLinear, dest::CuArray{Float32, 2}, srcstyle::IndexCartesian, src::LowerTriangular{Float32, Adjoint{Float32, CuArray{Float32, 2}}})
@ Base ./abstractarray.jl:975
[11] copyto!(dest::CuArray{Float32, 2}, src::LowerTriangular{Float32, Adjoint{Float32, CuArray{Float32, 2}}})
@ Base ./abstractarray.jl:950
[12] top-level scope
@ REPL[11]:1
[13] top-level scope
@ ~/.julia/packages/CUDA/LTbUr/src/initialization.jl:81

julia> @which copyto!(Σ, U')
copyto!(dest::AbstractArray, src::AbstractArray) in Base at abstractarray.jl:947
```
Type is
```julia
julia> typeof(U')
LowerTriangular{Float32, Adjoint{Float32, CuArray{Float32, 2}}}
```
which means that it won't hit https://github.com/JuliaGPU/GPUArrays.jl/blob/8e1bde0ee96b3da889ba99af4caddbecedcfd0cc/src/host/linalg.jl#L70 because `Adjoint` is not a subtype of `AbstractGPUArray`, nor will it hit https://github.com/JuliaGPU/GPUArrays.jl/blob/8e1bde0ee96b3da889ba99af4caddbecedcfd0cc/src/host/linalg.jl#L70 since this is a `LowerTriangular`.

Similar issue of course also exists for `UpperTriangular`.

Hotfix would be to just add additional impl for `UpperTriangular{T, <:Adjoint{T, <:AbstractGPUArray{T,N}}}`, etc. but unclear to me if this is the best approach, e.g. maybe there's a more "generic" solution to these wrappers of wrappers arrays?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with the Julia example and inspect the copyto! dispatches in src/host/linalg.jl, especially the implementation around the referenced line. Compare the LowerTriangular and Adjoint wrapper types involved in the Base copyto! path. Done means copying the adjoint triangular GPU array without scalar getindex errors, with equivalent behavior for the related triangular case.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.