Table of Contents

Class CuSparseNative

Namespace
NVMathNet.Interop
Assembly
NVMath.Net.dll

Raw P/Invoke bindings for cuSPARSE.

public static class CuSparseNative

Inheritance

Inherited Members

Methods

Check(CuSparseStatus, string?)

Throws NVMathNet.Interop.CuSparseException if status is not NVMathNet.Interop.CuSparseStatus.Success. Optionally prefixes the message with context.

public static void Check(CuSparseStatus status, string? context = null)

Parameters

status CuSparseStatus
context string?

Create()

Creates a cuSPARSE library handle. Caller must call cusparseDestroy when done.

public static nint Create()

Returns

nint

CreateBsr(long, long, long, long, long, void*, void*, void*, CuSparseIndexType, CuSparseIndexType, CuSparseIndexBase, CudaDataType, bool)

Creates a sparse matrix descriptor in Block Sparse Row (BSR) format. All data pointers must point to device memory.

public static nint CreateBsr(long brows, long bcols, long bnnz, long rowBlockDim, long colBlockDim, void* bsrRowOffsets, void* bsrColInd, void* bsrValues, CuSparseIndexType rowOffType, CuSparseIndexType colIndType, CuSparseIndexBase idxBase, CudaDataType valType, bool columnMajorBlocks = false)

Parameters

brows long

Number of block rows.

bcols long

Number of block columns.

bnnz long

Number of non-zero blocks.

rowBlockDim long

Number of rows per block.

colBlockDim long

Number of columns per block.

bsrRowOffsets void*

Block row offsets (length brows+1).

bsrColInd void*

Block column indices (length bnnz).

bsrValues void*

Non-zero block values (length bnnz * rowBlockDim * colBlockDim).

rowOffType CuSparseIndexType

Index type for row offsets.

colIndType CuSparseIndexType

Index type for column indices.

idxBase CuSparseIndexBase

Zero-based or one-based indexing.

valType CudaDataType

Element data type.

columnMajorBlocks bool

true if blocks are stored in column-major order; false for row-major. Default: false.

Returns

nint

CreateCoo(long, long, long, void*, void*, void*, CuSparseIndexType, CuSparseIndexBase, CudaDataType)

Creates a sparse matrix descriptor in COO format. All data pointers must point to device memory.

public static nint CreateCoo(long rows, long cols, long nnz, void* cooRowInd, void* cooColInd, void* cooValues, CuSparseIndexType idxType, CuSparseIndexBase idxBase, CudaDataType valType)

Parameters

rows long
cols long
nnz long
cooRowInd void*
cooColInd void*
cooValues void*
idxType CuSparseIndexType
idxBase CuSparseIndexBase
valType CudaDataType

Returns

nint

CreateCsc(long, long, long, void*, void*, void*, CuSparseIndexType, CuSparseIndexType, CuSparseIndexBase, CudaDataType)

Creates a CSC sparse matrix descriptor.

public static nint CreateCsc(long rows, long cols, long nnz, void* colOffsets, void* rowInd, void* values, CuSparseIndexType colOffType, CuSparseIndexType rowIndType, CuSparseIndexBase idxBase, CudaDataType valType)

Parameters

rows long
cols long
nnz long
colOffsets void*
rowInd void*
values void*
colOffType CuSparseIndexType
rowIndType CuSparseIndexType
idxBase CuSparseIndexBase
valType CudaDataType

Returns

nint

CreateCsr(long, long, long, void*, void*, void*, CuSparseIndexType, CuSparseIndexType, CuSparseIndexBase, CudaDataType)

Creates a sparse matrix descriptor in CSR format. All data pointers must point to device memory.

public static nint CreateCsr(long rows, long cols, long nnz, void* csrRowOffsets, void* csrColInd, void* csrValues, CuSparseIndexType rowOffType, CuSparseIndexType colIndType, CuSparseIndexBase idxBase, CudaDataType valType)

Parameters

rows long
cols long
nnz long
csrRowOffsets void*
csrColInd void*
csrValues void*
rowOffType CuSparseIndexType
colIndType CuSparseIndexType
idxBase CuSparseIndexBase
valType CudaDataType

Returns

nint

CreateDnMat(long, long, long, void*, CudaDataType, int)

Creates a dense matrix descriptor pointing to device memory.

public static nint CreateDnMat(long rows, long cols, long ld, void* values, CudaDataType valType, int order)

Parameters

rows long

Number of rows in the matrix.

cols long

Number of columns in the matrix.

ld long

Leading dimension of the matrix.

values void*

Pointer to the matrix values in device memory.

valType CudaDataType

Data type of the matrix elements.

order int

Storage order: 1 = column-major (CUSPARSE_ORDER_COL), 2 = row-major (CUSPARSE_ORDER_ROW).

Returns

nint

CreateDnVec(long, void*, CudaDataType)

Creates a dense vector descriptor pointing to device memory.

public static nint CreateDnVec(long size, void* values, CudaDataType valType)

Parameters

size long
values void*
valType CudaDataType

Returns

nint

Csr2CscEx2(nint, int, int, int, void*, int*, int*, void*, int*, int*, CudaDataType, void*)

Converts a CSR matrix to CSC (equivalently, the CSR of its transpose).

public static void Csr2CscEx2(nint handle, int m, int n, int nnz, void* csrVal, int* csrRowPtr, int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, CudaDataType valType, void* buffer)

Parameters

handle nint
m int
n int
nnz int
csrVal void*
csrRowPtr int*
csrColInd int*
cscVal void*
cscColPtr int*
cscRowInd int*
valType CudaDataType
buffer void*

Csr2CscEx2BufferSize(nint, int, int, int, void*, int*, int*, void*, int*, int*, CudaDataType)

Returns the workspace size for NVMathNet.Interop.CuSparseNative.Csr2CscEx2(System.IntPtr,System.Int32,System.Int32,System.Int32,System.Void*,System.Int32*,System.Int32*,System.Void*,System.Int32*,System.Int32*,NVMathNet.Interop.CudaDataType,System.Void*).

public static nuint Csr2CscEx2BufferSize(nint handle, int m, int n, int nnz, void* csrVal, int* csrRowPtr, int* csrColInd, void* cscVal, int* cscColPtr, int* cscRowInd, CudaDataType valType)

Parameters

handle nint
m int
n int
nnz int
csrVal void*
csrRowPtr int*
csrColInd int*
cscVal void*
cscColPtr int*
cscRowInd int*
valType CudaDataType

Returns

nuint

CsrSetPointers(nint, void*, void*, void*)

Rebinds the CSR arrays of a sparse matrix descriptor.

public static void CsrSetPointers(nint spMat, void* rowOffsets, void* colInd, void* values)

Parameters

spMat nint
rowOffsets void*
colInd void*
values void*

Destroy(nint)

Destroys a cuSPARSE library handle.

public static void Destroy(nint handle)

Parameters

handle nint

DestroyDnMat(nint)

Destroys a dense matrix descriptor.

public static void DestroyDnMat(nint desc)

Parameters

desc nint

DestroyDnVec(nint)

Destroys a dense vector descriptor.

public static void DestroyDnVec(nint desc)

Parameters

desc nint

DestroySpMat(nint)

Destroys a sparse matrix descriptor (CSR or COO).

public static void DestroySpMat(nint desc)

Parameters

desc nint

Sddmm(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSddmmAlg, void*)

Sampled dense-dense matrix product: C = alpha (op(A) op(B)) ∘ spy(C) + beta C.

public static void Sddmm(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSddmmAlg alg, void* buffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSddmmAlg
buffer void*

SddmmBufferSize(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSddmmAlg)

Returns the workspace size for SDDMM.

public static nuint SddmmBufferSize(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSddmmAlg alg)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSddmmAlg

Returns

nuint

SddmmPreprocess(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSddmmAlg, void*)

Optional SDDMM preprocessing.

public static void SddmmPreprocess(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSddmmAlg alg, void* buffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSddmmAlg
buffer void*

SetStream(nint, nint)

Associates a CUDA stream with the cuSPARSE handle.

public static void SetStream(nint handle, nint stream)

Parameters

handle nint
stream nint

SpGemmCompute(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpGemmAlg, nint, ref nuint, void*)

SpGEMM compute phase. Pass buffer = null to query the size, then call again with an allocated buffer.

public static void SpGemmCompute(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSpGemmAlg alg, nint descr, ref nuint bufferSize, void* buffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSpGemmAlg
descr nint
bufferSize nuint
buffer void*

SpGemmCopy(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpGemmAlg, nint)

SpGEMM copy phase: writes the result into the arrays bound to matC.

public static void SpGemmCopy(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSpGemmAlg alg, nint descr)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSpGemmAlg
descr nint

SpGemmCreateDescr()

Creates an SpGEMM descriptor.

public static nint SpGemmCreateDescr()

Returns

nint

SpGemmDestroyDescr(nint)

Destroys an SpGEMM descriptor.

public static void SpGemmDestroyDescr(nint descr)

Parameters

descr nint

SpGemmWorkEstimation(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpGemmAlg, nint, ref nuint, void*)

SpGEMM work-estimation phase. Pass buffer = null to query the size, then call again with an allocated buffer.

public static void SpGemmWorkEstimation(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSpGemmAlg alg, nint descr, ref nuint bufferSize, void* buffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSpGemmAlg
descr nint
bufferSize nuint
buffer void*

SpMM(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpMMAlg, void*)

Sparse matrix-matrix product: C = alpha * op(A) * op(B) + beta * C. All pointers must reside in device memory.

public static void SpMM(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSpMMAlg alg, void* externalBuffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSpMMAlg
externalBuffer void*

SpMMBufferSize(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpMMAlg)

Returns the size of the external workspace buffer required for NVMathNet.Interop.CuSparseNative.SpMM(System.IntPtr,NVMathNet.Interop.CuSparseOperation,NVMathNet.Interop.CuSparseOperation,System.Void*,System.IntPtr,System.IntPtr,System.Void*,System.IntPtr,NVMathNet.Interop.CudaDataType,NVMathNet.Interop.CuSparseSpMMAlg,System.Void*).

public static nuint SpMMBufferSize(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSpMMAlg alg)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSpMMAlg

Returns

nuint

SpMMPreprocess(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpMMAlg, void*)

Optional preprocessing step for NVMathNet.Interop.CuSparseNative.SpMM(System.IntPtr,NVMathNet.Interop.CuSparseOperation,NVMathNet.Interop.CuSparseOperation,System.Void*,System.IntPtr,System.IntPtr,System.Void*,System.IntPtr,NVMathNet.Interop.CudaDataType,NVMathNet.Interop.CuSparseSpMMAlg,System.Void*) that may improve performance when the same sparse matrix is multiplied against multiple dense matrices.

public static void SpMMPreprocess(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, void* beta, nint matC, CudaDataType computeType, CuSparseSpMMAlg alg, void* externalBuffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
beta void*
matC nint
computeType CudaDataType
alg CuSparseSpMMAlg
externalBuffer void*

SpMV(nint, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpMVAlg, void*)

Sparse matrix-vector product: y = alpha * op(A) * x + beta * y. All pointers must reside in device memory.

public static void SpMV(nint handle, CuSparseOperation opA, void* alpha, nint matA, nint vecX, void* beta, nint vecY, CudaDataType computeType, CuSparseSpMVAlg alg, void* externalBuffer)

Parameters

handle nint
opA CuSparseOperation
alpha void*
matA nint
vecX nint
beta void*
vecY nint
computeType CudaDataType
alg CuSparseSpMVAlg
externalBuffer void*

SpMVBufferSize(nint, CuSparseOperation, void*, nint, nint, void*, nint, CudaDataType, CuSparseSpMVAlg)

Returns the size of the external workspace buffer required for NVMathNet.Interop.CuSparseNative.SpMV(System.IntPtr,NVMathNet.Interop.CuSparseOperation,System.Void*,System.IntPtr,System.IntPtr,System.Void*,System.IntPtr,NVMathNet.Interop.CudaDataType,NVMathNet.Interop.CuSparseSpMVAlg,System.Void*) with the given configuration.

public static nuint SpMVBufferSize(nint handle, CuSparseOperation opA, void* alpha, nint matA, nint vecX, void* beta, nint vecY, CudaDataType computeType, CuSparseSpMVAlg alg)

Parameters

handle nint
opA CuSparseOperation
alpha void*
matA nint
vecX nint
beta void*
vecY nint
computeType CudaDataType
alg CuSparseSpMVAlg

Returns

nuint

SpMatGetSize(nint, out long, out long, out long)

Gets rows, columns and non-zero count of a sparse matrix descriptor.

public static void SpMatGetSize(nint spMat, out long rows, out long cols, out long nnz)

Parameters

spMat nint
rows long
cols long
nnz long

SpMatSetAttribute(nint, CuSparseSpMatAttribute, int)

Sets a sparse matrix attribute (fill mode or diagonal type).

public static void SpMatSetAttribute(nint spMat, CuSparseSpMatAttribute attribute, int value)

Parameters

spMat nint
attribute CuSparseSpMatAttribute
value int

SpSMAnalysis(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, nint, CudaDataType, CuSparseSpSMAlg, nint, void*)

Runs the SpSM analysis phase.

public static void SpSMAnalysis(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, nint matC, CudaDataType computeType, CuSparseSpSMAlg alg, nint descr, void* buffer)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
matC nint
computeType CudaDataType
alg CuSparseSpSMAlg
descr nint
buffer void*

SpSMBufferSize(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, nint, CudaDataType, CuSparseSpSMAlg, nint)

Returns the workspace size for SpSM analysis.

public static nuint SpSMBufferSize(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, nint matC, CudaDataType computeType, CuSparseSpSMAlg alg, nint descr)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
matC nint
computeType CudaDataType
alg CuSparseSpSMAlg
descr nint

Returns

nuint

SpSMCreateDescr()

Creates an SpSM (sparse triangular solve, matrix RHS) descriptor.

public static nint SpSMCreateDescr()

Returns

nint

SpSMDestroyDescr(nint)

Destroys an SpSM descriptor.

public static void SpSMDestroyDescr(nint descr)

Parameters

descr nint

SpSMSolve(nint, CuSparseOperation, CuSparseOperation, void*, nint, nint, nint, CudaDataType, CuSparseSpSMAlg, nint)

Solves op(A) C = alpha op(B).

public static void SpSMSolve(nint handle, CuSparseOperation opA, CuSparseOperation opB, void* alpha, nint matA, nint matB, nint matC, CudaDataType computeType, CuSparseSpSMAlg alg, nint descr)

Parameters

handle nint
opA CuSparseOperation
opB CuSparseOperation
alpha void*
matA nint
matB nint
matC nint
computeType CudaDataType
alg CuSparseSpSMAlg
descr nint

SpSVAnalysis(nint, CuSparseOperation, void*, nint, nint, nint, CudaDataType, CuSparseSpSVAlg, nint, void*)

Runs the SpSV analysis phase.

public static void SpSVAnalysis(nint handle, CuSparseOperation opA, void* alpha, nint matA, nint vecX, nint vecY, CudaDataType computeType, CuSparseSpSVAlg alg, nint descr, void* buffer)

Parameters

handle nint
opA CuSparseOperation
alpha void*
matA nint
vecX nint
vecY nint
computeType CudaDataType
alg CuSparseSpSVAlg
descr nint
buffer void*

SpSVBufferSize(nint, CuSparseOperation, void*, nint, nint, nint, CudaDataType, CuSparseSpSVAlg, nint)

Returns the workspace size for SpSV analysis.

public static nuint SpSVBufferSize(nint handle, CuSparseOperation opA, void* alpha, nint matA, nint vecX, nint vecY, CudaDataType computeType, CuSparseSpSVAlg alg, nint descr)

Parameters

handle nint
opA CuSparseOperation
alpha void*
matA nint
vecX nint
vecY nint
computeType CudaDataType
alg CuSparseSpSVAlg
descr nint

Returns

nuint

SpSVCreateDescr()

Creates an SpSV (sparse triangular solve, vector RHS) descriptor.

public static nint SpSVCreateDescr()

Returns

nint

SpSVDestroyDescr(nint)

Destroys an SpSV descriptor.

public static void SpSVDestroyDescr(nint descr)

Parameters

descr nint

SpSVSolve(nint, CuSparseOperation, void*, nint, nint, nint, CudaDataType, CuSparseSpSVAlg, nint)

Solves op(A) y = alpha x.

public static void SpSVSolve(nint handle, CuSparseOperation opA, void* alpha, nint matA, nint vecX, nint vecY, CudaDataType computeType, CuSparseSpSVAlg alg, nint descr)

Parameters

handle nint
opA CuSparseOperation
alpha void*
matA nint
vecX nint
vecY nint
computeType CudaDataType
alg CuSparseSpSVAlg
descr nint