SciML / SciML/ComponentArrays.jl

ComponentArray with scalars on GPU

Open
#160 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
375
Forks
42
Avg merge
7h 25m
Merged PRs (30d)
17

Description

julia> using ComponentArrays, Lux                                                               
                                                
julia> c = ComponentArray(a=ones(2,3), b=0.0) |> gpu                                    
ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tuple{Axis{(a = ViewAxis(1:
6, ShapedAxis((2, 3), NamedTuple())), b = 7)}}}(a = Float32[1.0 1.0 1.0; 1.0 1.0 1.0], b = Error
 showing value of type ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tupl
e{Axis{(a = ViewAxis(1:6, ShapedAxis((2, 3), NamedTuple())), b = 7)}}}:                         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/ZBmfM/src/GPUArraysCore.jl:87
  [3] getindex                                                                                  
    @ ~/.julia/packages/GPUArrays/Hyss4/src/host/indexing.jl:9 [inlined]    
  [4] macro expansion                                                                           
    @ ~/.julia/packages/ComponentArrays/Eoni9/src/array_interface.jl:0 [inlined]
  [5] _getindex(index_fun::typeof(getindex), x::ComponentVector{Float32, CuArray{Float32, 1, CUD
A.Mem.DeviceBuffer}, Tuple{Axis{(a = ViewAxis(1:6, ShapedAxis((2, 3), NamedTuple())), b = 7)}}}, idx::Val{:b})                                  
julia> c.a
2×3 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}:
 1.0  1.0  1.0
 1.0  1.0  1.0

julia> c.b
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/ZBmfM/src/GPUArraysCore.jl:87
 [3] getindex
   @ ~/.julia/packages/GPUArrays/Hyss4/src/host/indexing.jl:9 [inlined]
 [4] maybeview
   @ ./views.jl:147 [inlined]
 [5] macro expansion
   @ ~/.julia/packages/ComponentArrays/Eoni9/src/array_interface.jl:0 [inlined]
 [6] _getindex(index_fun::typeof(Base.maybeview), x::ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tuple{Axis{(a = ViewAxis(1:6, ShapedAxis((2, 3), NamedTuple())), b = 7)}}}, idx::Val{:b})
   @ ComponentArrays ~/.julia/packages/ComponentArrays/Eoni9/src/array_interface.jl:121
 [7] getproperty(x::ComponentVector{Float32, CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}, Tuple{Axis{(a = ViewAxis(1:6, ShapedAxis((2, 3), NamedTuple())), b = 7)}}}, s::Symbol)
   @ ComponentArrays ~/.julia/packages/ComponentArrays/Eoni9/src/namedtuple_interface.jl:14
 [8] top-level scope
   @ REPL[17]:1
 [9] top-level scope
   @ ~/.julia/packages/CUDA/DfvRa/src/initialization.jl:52

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Julia reproducer with ComponentArrays, Lux, and gpu, then inspect ComponentArrays' array_interface.jl and namedtuple_interface.jl at the stack-trace locations. The issue is resolved when accessing the scalar component b on the GPU-backed ComponentArray works without triggering GPU scalar-indexing errors, while c.a continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.