CuSparseMatrixCSC constructor

Hello,

I am trying to use the CuSparseMatrixCSC constructor as defined here, but it throws an error. I’m wondering what’s gone wrong.

julia> using CUDA

julia> I = CuArray([1,1]);

julia> J = CuArray([1,2]);

julia> V = CuArray([0.2, 0.3]);

julia> CUSPARSE.CuSparseMatrixCSC(I, J, V, (3,3))
3×3 CUDA.CUSPARSE.CuSparseMatrixCSC{Float64} with 2 stored entries:Error showing value of type CUDA.CUSPARSE.CuSparseMatrixCSC{Float64}:
ERROR: ArgumentError: 2 == length(colptr) < 4

This only works for sparse from SparseArrays:

julia> using SparseArrays

julia> sparse(Array(I), Array(J), Array(V), 3, 3)
3×3 SparseMatrixCSC{Float64,Int64} with 2 stored entries:
  [1, 1]  =  0.2
  [1, 2]  =  0.3

You need to convert your coordinate lists (I and J) to CSC format (colPtr and rowVal).

julia> colPtr = CuArray([1, 2, 3, 3]);

julia> rowVal = CuArray([1, 1]);

julia> CUSPARSE.CuSparseMatrixCSC(colPtr, rowVal, V, (3,3))
3×3 CuSparseMatrixCSC{Float64} with 2 stored entries:
  [1, 1]  =  0.2
  [1, 2]  =  0.3
2 Likes

Thank you for your help, this is great!