Skip to content

(Direct) Constructors for sparse CSC, CSR and BSR arrays #677

@nHackel

Description

@nHackel

Hello, I think it would be very helpful to add constructors to the generic GPU sparse arrays interface for building sparse matrices directly from index/value GPU vectors, bypassing the COO path used by sparse. This would enable packages to precompute the structure and values and construct sparse matrices efficiently across backends.

I was imaging something like:

# in GPUArrays.jl
export GPUSparseMatrixCSC, ...
function GPUSparseMatrixCSC end
# same for other formats

# in JLArrays.jl
GPUSparseMatrix{Tv, Ti}(rowPtr::JLArray, colVal::JLArray, nzVal::JLArray, dims) = JLSparseMatrixCSC{Tv, Ti}(rowPtr, colVal, nzVal, dims)

# in CUDA.jl
GPUSparseMatrix{Tv, Ti}(rowPtr::CuArray, colVal::CuArray, nzVal::CuArray, dims) = CuSparseMatrixCSC{Tv, Ti}(rowPtr, colVal, nzVal, dims)

# and so on in the other backends

One issue is that the arguments might differ between backends or have different requirements on their values(see #648). I think in this case, the formats are so specific though, that the implementations will likely just differ in the types of their vectors.

An example use case can be seen here, where in initial tests the overhead of the COO format negates performance gains over the CPU implementation.

I'm not sure if I fully understand the relationship between AbstractGPUSparseMatrices and GPUSparseDeviceVector yet and if it would make sense to provide a default implementation for the constructor which defaults to reference to the corresponding default vector.

If this or another version of such a constructor seems sensible, I'd be happy to make PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions