Skip to content

Indexing (Cartesian or Linear) isn't defined for sparse device arrays #694

Open

Description

@alonsoC1s

Indexing a CUDA.CUSPARSE with brackets inside a CUDA.jl kernel triggers a error_if_canonical_getindex Error. The following reproduces the bug:

using CUDA, SparseArrays

src_mwe = cu(ones(Float32, 2, 5))
dst_mwe = cu([1, 2, 3, 4, 5])

function mwe_kernel!(dst, src)
    index = threadIdx().x + (blockIdx().x - 1) * blockDim().x
    dst[index] = src[1, index]
    return nothing
end

kernel = @cuda launch=false mwe_kernel!(dst_mwe, sparse(src_mwe, fmt=:csc))
kernel(dst_mwe, sparse(src_mwe, fmt=:csc); threads=length(dst_mwe), blocks=1)

julia> ERROR: a exception was thrown during kernel execution on thread (1, 1, 1) in block (1, 1, 1).
Stacktrace:
 [1] error_if_canonical_getindex at ./abstractarray.jl:1357
 [2] getindex at ./abstractarray.jl:1341
 [3] _getindex at ./abstractarray.jl:1383
 [4] getindex at ./abstractarray.jl:1342
 [5] mwe_kernel! at ./REPL[11]:3

The fix is to implement indexing functionality for the given array types in src/device/sparse.jl

Activity

  1. added theissue type on Oct 19, 2026
  2. added
    arraysThe array abstraction: broadcasting, mapreduce, indexing, views, generic linear algebra.
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraysThe array abstraction: broadcasting, mapreduce, indexing, views, generic linear algebra.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions