Skip to content

Default algs for CUSPARSE failing #827

@hexaeder

Description

@hexaeder

Currently, the default algorithm choice is not really able to handle sparse cuda matrices. In short:

  • CuSparseMatrixCSC -> defaults always to GenericLU which is not GPU compatible (scalar indexing)
  • CuSparseMatrixCSR
    • CUDSS not available -> defaults to Krylov which not GPU compatibe (scalar indexing). It gives a warning however
    • CUDSS available + asym matrix -> works
    • CUDSS available + symmetric matrix -> Cholesky which is not GPU compatible (scalar indexing)

I am not sure what the right thing here is. Maybe just give a clearer error message? Or maybe convert to dense?

Code to play around with:

using LinearSolve
using SparseArrays
using CUDA
using CUDSS

b = Float64[1, 2, 3, 4]
b_gpu = adapt(CuArray, b)

A = Float64[1 1 0 0
            0 1 1 0
            0 0 3 1
            0 0 0 4]
A_sym = Float64[1 1 0 0
                1 0 0 2
                0 0 3 0
                0 2 0 0]

# asymetric matrix on GPU (dense)
A_gpu = adapt(CuArray, A)
prob_gpu = LinearProblem(A_gpu, b_gpu)
solve(prob_gpu) # works

# asymetric sparse matrix
A_gpu_sparse1 = CUDA.CUSPARSE.CuSparseMatrixCSR(sparse(A))
prob_gpu_sparse1 = LinearProblem(A_gpu_sparse1, b_gpu)
solve(prob_gpu_sparse1) # works

A_gpu_sparse2 = CUDA.CUSPARSE.CuSparseMatrixCSC(sparse(A))
prob_gpu_sparse2 = LinearProblem(A_gpu_sparse2, b_gpu)
solve(prob_gpu_sparse2) # fails because of generic LU


# symmetric matrix on GPU (dense)
A_gpu_sym = adapt(CuArray, A_sym)
prob_gpu_sym = LinearProblem(A_gpu_sym, b_gpu)
solve(prob_gpu_sym) # works

# symetric sparse on GPU
A_gpu_sym_sparse1 = CUDA.CUSPARSE.CuSparseMatrixCSR(sparse(A_sym))
prob_gpu_sym_sparse1 = LinearProblem(A_gpu_sym_sparse1, b_gpu)
solve(prob_gpu_sym_sparse1) # errors in colesky

A_gpu_sym_sparse2 = CUDA.CUSPARSE.CuSparseMatrixCSC(sparse(A_sym))
prob_gpu_sym_sparse2 = LinearProblem(A_gpu_sym_sparse2, b_gpu)
solve(prob_gpu_sym_sparse2) # errors in generic LU

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions