Skip to content

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

@alonsoC1s

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions