Table of Contents

Class SparseLinearAlgebra

Namespace
NVMathNet.Sparse
Assembly
NVMath.Net.dll

Static helpers for sparse linear algebra operations using cuSPARSE.

public static class SparseLinearAlgebra

Inheritance

Inherited Members

Methods

SddmmAsync<T>(DeviceBuffer<T>, DeviceBuffer<T>, CsrMatrix<T>, long, T?, T?, CudaStream?, CancellationToken)

Sampled dense-dense matrix product: C = alpha · (A · B) ∘ spy(C) + beta · C, where only the entries in the sparsity pattern of C are computed and C's values are updated in place.

public static Task SddmmAsync<T>(DeviceBuffer<T> a, DeviceBuffer<T> b, CsrMatrix<T> c, long k, T? alpha = null, T? beta = null, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

a DeviceBuffer<T>

Dense A (m × k), column-major on device.

b DeviceBuffer<T>

Dense B (k × n), column-major on device.

c CsrMatrix<T>

Sparse CSR matrix C (m × n); its values are updated in place.

k long

Inner dimension.

alpha T?

Scale for the product. Default: 1.

beta T?

Scale for the existing values of C. Default: 0.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpGemmAsync<T>(CsrMatrix<T>, CsrMatrix<T>, T?, CudaStream?, CancellationToken)

Sparse-sparse matrix product: returns a new CSR matrix C = alpha · A · B.

public static Task<CsrMatrix<T>> SpGemmAsync<T>(CsrMatrix<T> a, CsrMatrix<T> b, T? alpha = null, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

a CsrMatrix<T>

Sparse CSR matrix A (m × k).

b CsrMatrix<T>

Sparse CSR matrix B (k × n).

alpha T?

Scale for the product. Default: 1.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task<CsrMatrix<T>>

The product C; the caller owns and must dispose it.

Type Parameters

T

SpMMAsync<T>(CsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, float, float, bool, CudaStream?, CancellationToken)

Sparse matrix-dense matrix product: C = alpha * op(A) * B + beta * C.

public static Task SpMMAsync<T>(CsrMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CsrMatrix<T>

Sparse CSR matrix A (m × k).

b DeviceBuffer<T>

Dense matrix B (k × n), column-major on device.

c DeviceBuffer<T>

Dense output matrix C (m × n), column-major on device; updated in place.

n long

Number of columns in B and C.

alpha float

Scalar multiplier for the sparse-dense product. Default: 1.

beta float

Scalar multiplier for the existing values in C. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMMAsync<T>(CooMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, float, float, bool, CudaStream?, CancellationToken)

Sparse-dense matrix product C = alpha · op(A) · B + beta · C for a COO matrix.

public static Task SpMMAsync<T>(CooMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CooMatrix<T>

Sparse CSR matrix A (m × k).

b DeviceBuffer<T>

Dense matrix B (k × n), column-major on device.

c DeviceBuffer<T>

Dense output matrix C (m × n), column-major on device; updated in place.

n long

Number of columns in B and C.

alpha float

Scalar multiplier for the sparse-dense product. Default: 1.

beta float

Scalar multiplier for the existing values in C. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMMAsync<T>(BsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, float, float, bool, CudaStream?, CancellationToken)

Sparse-dense matrix product C = alpha · op(A) · B + beta · C for a BSR matrix.

public static Task SpMMAsync<T>(BsrMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix BsrMatrix<T>

Sparse CSR matrix A (m × k).

b DeviceBuffer<T>

Dense matrix B (k × n), column-major on device.

c DeviceBuffer<T>

Dense output matrix C (m × n), column-major on device; updated in place.

n long

Number of columns in B and C.

alpha float

Scalar multiplier for the sparse-dense product. Default: 1.

beta float

Scalar multiplier for the existing values in C. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMMAsync<T>(CscMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, float, float, bool, CudaStream?, CancellationToken)

Sparse-dense matrix product C = alpha · op(A) · B + beta · C for a CSC matrix.

public static Task SpMMAsync<T>(CscMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CscMatrix<T>

Sparse CSR matrix A (m × k).

b DeviceBuffer<T>

Dense matrix B (k × n), column-major on device.

c DeviceBuffer<T>

Dense output matrix C (m × n), column-major on device; updated in place.

n long

Number of columns in B and C.

alpha float

Scalar multiplier for the sparse-dense product. Default: 1.

beta float

Scalar multiplier for the existing values in C. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMMAsync<T>(CsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, T, T, bool, CudaStream?, CancellationToken)

C = alpha · op(A) · B + beta · C for a CSR matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMMAsync<T>(CsrMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CsrMatrix<T>
b DeviceBuffer<T>
c DeviceBuffer<T>
n long
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMMAsync<T>(CooMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, T, T, bool, CudaStream?, CancellationToken)

C = alpha · op(A) · B + beta · C for a COO matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMMAsync<T>(CooMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CooMatrix<T>
b DeviceBuffer<T>
c DeviceBuffer<T>
n long
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMMAsync<T>(BsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, T, T, bool, CudaStream?, CancellationToken)

C = alpha · op(A) · B + beta · C for a BSR matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMMAsync<T>(BsrMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix BsrMatrix<T>
b DeviceBuffer<T>
c DeviceBuffer<T>
n long
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMMAsync<T>(CscMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, T, T, bool, CudaStream?, CancellationToken)

C = alpha · op(A) · B + beta · C for a CSC matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMMAsync<T>(CscMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CscMatrix<T>
b DeviceBuffer<T>
c DeviceBuffer<T>
n long
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMVAsync<T>(CsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, float, float, bool, CudaStream?, CancellationToken)

Sparse matrix-vector product: y = alpha * op(A) * x + beta * y.

public static Task SpMVAsync<T>(CsrMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CsrMatrix<T>

Sparse CSR matrix A.

x DeviceBuffer<T>

Dense vector x on device.

y DeviceBuffer<T>

Dense vector y on device; updated in place.

alpha float

Scalar multiplier for the product. Default: 1.

beta float

Scalar multiplier for existing y. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMVAsync<T>(CooMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, float, float, bool, CudaStream?, CancellationToken)

Sparse matrix-vector product y = alpha · op(A) · x + beta · y for a COO matrix.

public static Task SpMVAsync<T>(CooMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CooMatrix<T>

Sparse CSR matrix A.

x DeviceBuffer<T>

Dense vector x on device.

y DeviceBuffer<T>

Dense vector y on device; updated in place.

alpha float

Scalar multiplier for the product. Default: 1.

beta float

Scalar multiplier for existing y. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMVAsync<T>(BsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, float, float, bool, CudaStream?, CancellationToken)

Sparse matrix-vector product y = alpha · op(A) · x + beta · y for a BSR matrix.

public static Task SpMVAsync<T>(BsrMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix BsrMatrix<T>

Sparse CSR matrix A.

x DeviceBuffer<T>

Dense vector x on device.

y DeviceBuffer<T>

Dense vector y on device; updated in place.

alpha float

Scalar multiplier for the product. Default: 1.

beta float

Scalar multiplier for existing y. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMVAsync<T>(CscMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, float, float, bool, CudaStream?, CancellationToken)

Sparse matrix-vector product y = alpha · op(A) · x + beta · y for a CSC matrix.

public static Task SpMVAsync<T>(CscMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, float alpha = 1, float beta = 0, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CscMatrix<T>

Sparse CSR matrix A.

x DeviceBuffer<T>

Dense vector x on device.

y DeviceBuffer<T>

Dense vector y on device; updated in place.

alpha float

Scalar multiplier for the product. Default: 1.

beta float

Scalar multiplier for existing y. Default: 0.

transpose bool

If true, uses the transpose of the sparse matrix.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpMVAsync<T>(CsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, T, T, bool, CudaStream?, CancellationToken)

y = alpha · op(A) · x + beta · y for a CSR matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMVAsync<T>(CsrMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CsrMatrix<T>
x DeviceBuffer<T>
y DeviceBuffer<T>
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMVAsync<T>(CooMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, T, T, bool, CudaStream?, CancellationToken)

y = alpha · op(A) · x + beta · y for a COO matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMVAsync<T>(CooMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CooMatrix<T>
x DeviceBuffer<T>
y DeviceBuffer<T>
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMVAsync<T>(BsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, T, T, bool, CudaStream?, CancellationToken)

y = alpha · op(A) · x + beta · y for a BSR matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMVAsync<T>(BsrMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix BsrMatrix<T>
x DeviceBuffer<T>
y DeviceBuffer<T>
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpMVAsync<T>(CscMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, T, T, bool, CudaStream?, CancellationToken)

y = alpha · op(A) · x + beta · y for a CSC matrix with scalars of the element type, which allows complex scalars for System.Numerics.Complex matrices.

public static Task SpMVAsync<T>(CscMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, T alpha, T beta, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CscMatrix<T>
x DeviceBuffer<T>
y DeviceBuffer<T>
alpha T
beta T
transpose bool
stream CudaStream?
ct CancellationToken

Returns

Task

Type Parameters

T

SpSMAsync<T>(CsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, SparseTriangle, SparseDiagonal, T?, bool, CudaStream?, CancellationToken)

Sparse triangular solve with a dense matrix right-hand side: solves op(A) · C = alpha · B for c.

public static Task SpSMAsync<T>(CsrMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, SparseTriangle triangle = SparseTriangle.Lower, SparseDiagonal diagonal = SparseDiagonal.NonUnit, T? alpha = null, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CsrMatrix<T>

Square sparse CSR matrix A (m × m).

b DeviceBuffer<T>

Dense right-hand side (m × n), column-major on device.

c DeviceBuffer<T>

Dense solution (m × n), column-major on device.

n long

Number of right-hand-side columns.

triangle SparseTriangle

Triangle of A to read.

diagonal SparseDiagonal

Whether the diagonal is implicit ones.

alpha T?

Scale applied to B. Default: 1.

transpose bool

Solve with the transpose of A.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpSMAsync<T>(CooMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, long, SparseTriangle, SparseDiagonal, T?, bool, CudaStream?, CancellationToken)

Triangular solve op(A) · C = alpha · B for a COO matrix.

public static Task SpSMAsync<T>(CooMatrix<T> matrix, DeviceBuffer<T> b, DeviceBuffer<T> c, long n, SparseTriangle triangle = SparseTriangle.Lower, SparseDiagonal diagonal = SparseDiagonal.NonUnit, T? alpha = null, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CooMatrix<T>

Square sparse CSR matrix A (m × m).

b DeviceBuffer<T>

Dense right-hand side (m × n), column-major on device.

c DeviceBuffer<T>

Dense solution (m × n), column-major on device.

n long

Number of right-hand-side columns.

triangle SparseTriangle

Triangle of A to read.

diagonal SparseDiagonal

Whether the diagonal is implicit ones.

alpha T?

Scale applied to B. Default: 1.

transpose bool

Solve with the transpose of A.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpSVAsync<T>(CsrMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, SparseTriangle, SparseDiagonal, T?, bool, CudaStream?, CancellationToken)

Sparse triangular solve with a vector right-hand side: solves op(A) · y = alpha · x for y.

public static Task SpSVAsync<T>(CsrMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, SparseTriangle triangle = SparseTriangle.Lower, SparseDiagonal diagonal = SparseDiagonal.NonUnit, T? alpha = null, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CsrMatrix<T>

Square sparse CSR matrix A whose triangle is referenced.

x DeviceBuffer<T>

Right-hand side vector (device).

y DeviceBuffer<T>

Solution vector (device); must not alias x.

triangle SparseTriangle

Triangle of A to read.

diagonal SparseDiagonal

Whether the diagonal is implicit ones.

alpha T?

Scale applied to x. Default: 1.

transpose bool

Solve with the transpose of A.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SpSVAsync<T>(CooMatrix<T>, DeviceBuffer<T>, DeviceBuffer<T>, SparseTriangle, SparseDiagonal, T?, bool, CudaStream?, CancellationToken)

Triangular solve op(A) · y = alpha · x for a COO matrix (row-major sorted entries).

public static Task SpSVAsync<T>(CooMatrix<T> matrix, DeviceBuffer<T> x, DeviceBuffer<T> y, SparseTriangle triangle = SparseTriangle.Lower, SparseDiagonal diagonal = SparseDiagonal.NonUnit, T? alpha = null, bool transpose = false, CudaStream? stream = null, CancellationToken ct = default) where T : unmanaged, INumberBase<T>

Parameters

matrix CooMatrix<T>

Square sparse CSR matrix A whose triangle is referenced.

x DeviceBuffer<T>

Right-hand side vector (device).

y DeviceBuffer<T>

Solution vector (device); must not alias x.

triangle SparseTriangle

Triangle of A to read.

diagonal SparseDiagonal

Whether the diagonal is implicit ones.

alpha T?

Scale applied to x. Default: 1.

transpose bool

Solve with the transpose of A.

stream CudaStream?

Optional CUDA stream. null creates a private stream.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T