Sparse Matrix APIs

The cuSPARSE helper functions for sparse matrix descriptor are described in this section.

See the COO, CSR , CSC , SELL , BSR, Blocked-Ell sections for the detailed description of the storage formats.

Coordinate (COO)

cusparseCreateCoo()

cusparseStatus_t
cusparseCreateCoo(cusparseSpMatDescr_t* spMatDescr,
                  int64_t               rows,
                  int64_t               cols,
                  int64_t               nnz,
                  void*                 cooRowInd,
                  void*                 cooColInd,
                  void*                 cooValues,
                  cusparseIndexType_t   cooIdxType,
                  cusparseIndexBase_t   idxBase,
                  cudaDataType          valueType)

cusparseStatus_t
cusparseCreateConstCoo(cusparseConstSpMatDescr_t* spMatDescr,
                       int64_t                    rows,
                       int64_t                    cols,
                       int64_t                    nnz,
                       const void*                cooRowInd,
                       const void*                cooColInd,
                       const void*                cooValues,
                       cusparseIndexType_t        cooIdxType,
                       cusparseIndexBase_t        idxBase,
                       cudaDataType               valueType)

This function initializes the sparse matrix descriptor spMatDescr in the COO format (Structure of Arrays layout).

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

rows

HOST

IN

Number of rows of the sparse matrix

cols

HOST

IN

Number of columns of the sparse matrix

nnz

HOST

IN

Number of non-zero entries of the sparse matrix

cooRowInd

DEVICE

IN

Row indices of the sparse matrix. Array with nnz elements

cooColInd

DEVICE

IN

Column indices of the sparse matrix. Array with nnz elements

cooValues

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

cooIdxType

HOST

IN

Data type of cooRowInd and cooColInd

idxBase

HOST

IN

Index base of cooRowInd and cooColInd

valueType

HOST

IN

Datatype of cooValues

cusparseCreateCoo() has the following constraints:

  • cooRowInd, cooColInd, and cooValues must be aligned to the size of the datatypes specified by cooIdxType, cooIdxType, and valueType. respectively. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseCooGet()

cusparseStatus_t
cusparseCooGet(cusparseSpMatDescr_t spMatDescr,
               int64_t*             rows,
               int64_t*             cols,
               int64_t*             nnz,
               void**               cooRowInd,
               void**               cooColInd,
               void**               cooValues,
               cusparseIndexType_t* idxType,
               cusparseIndexBase_t* idxBase,
               cudaDataType*        valueType)

cusparseStatus_t
cusparseConstCooGet(cusparseConstSpMatDescr_t spMatDescr,
                    int64_t*                  rows,
                    int64_t*                  cols,
                    int64_t*                  nnz,
                    const void**              cooRowInd,
                    const void**              cooColInd,
                    const void**              cooValues,
                    cusparseIndexType_t*      idxType,
                    cusparseIndexBase_t*      idxBase,
                    cudaDataType*             valueType)

This function returns the fields of the sparse matrix descriptor spMatDescr stored in COO format (Array of Structures layout).

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

rows

HOST

OUT

Number of rows of the sparse matrix

cols

HOST

OUT

Number of columns of the sparse matrix

nnz

HOST

OUT

Number of non-zero entries of the sparse matrix

cooRowInd

DEVICE

OUT

Row indices of the sparse matrix. Array nnz elements

cooColInd

DEVICE

OUT

Column indices of the sparse matrix. Array nnz elements

cooValues

DEVICE

OUT

Values of the sparse matrix. Array nnz elements

cooIdxType

HOST

OUT

Data type of cooRowInd and cooColInd

idxBase

HOST

OUT

Index base of cooRowInd and cooColInd

valueType

HOST

OUT

Datatype of cooValues

See cusparseStatus_t for the description of the return status.


cusparseCooSetPointers()

cusparseStatus_t
cusparseCooSetPointers(cusparseSpMatDescr_t spMatDescr,
                       void*                cooRows,
                       void*                cooColumns,
                       void*                cooValues)

This function sets the pointers of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

cooRows

DEVICE

IN

Row indices of the sparse matrix. Array with nnz elements

cooColumns

DEVICE

IN

Column indices of the sparse matrix. Array with nnz elements

cooValues

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

cusparseCooSetPointers() has the following constraints:

  • cooRows, cooColumns, and cooValues must be aligned to the size of their corresponding datatypes specified in spMatDescr. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseCooSetStridedBatch()

cusparseStatus_t
cusparseCooSetStridedBatch(cusparseSpMatDescr_t spMatDescr,
                           int                  batchCount,
                           int64_t              batchStride)

This function sets the batchCount and the batchStride fields of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

batchCount

HOST

IN

Number of batches of the sparse matrix

batchStride

HOST

IN

address offset between consecutive batches

See cusparseStatus_t for the description of the return status.


Compressed Sparse Row (CSR)

cusparseCreateCsr()

cusparseStatus_t
cusparseCreateCsr(cusparseSpMatDescr_t* spMatDescr,
                  int64_t               rows,
                  int64_t               cols,
                  int64_t               nnz,
                  void*                 csrRowOffsets,
                  void*                 csrColInd,
                  void*                 csrValues,
                  cusparseIndexType_t   csrRowOffsetsType,
                  cusparseIndexType_t   csrColIndType,
                  cusparseIndexBase_t   idxBase,
                  cudaDataType          valueType)

cusparseStatus_t
cusparseCreateConstCsr(cusparseConstSpMatDescr_t* spMatDescr,
                       int64_t                    rows,
                       int64_t                    cols,
                       int64_t                    nnz,
                       const void*                csrRowOffsets,
                       const void*                csrColInd,
                       const void*                csrValues,
                       cusparseIndexType_t        csrRowOffsetsType,
                       cusparseIndexType_t        csrColIndType,
                       cusparseIndexBase_t        idxBase,
                       cudaDataType               valueType)

This function initializes the sparse matrix descriptor spMatDescr in the CSR format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

rows

HOST

IN

Number of rows of the sparse matrix

cols

HOST

IN

Number of columns of the sparse matrix

nnz

HOST

IN

Number of non-zero entries of the sparse matrix

csrRowOffsets

DEVICE

IN

Row offsets of the sparse matrix. Array with rows + 1 elements

csrColInd

DEVICE

IN

Column indices of the sparse matrix. Array with nnz elements

csrValues

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

csrRowOffsetsType

HOST

IN

Data type of csrRowOffsets

csrColIndType

HOST

IN

Data type of csrColInd

idxBase

HOST

IN

Index base of csrRowOffsets and csrColInd

valueType

HOST

IN

Datatype of csrValues

cusparseCreateCsr() has the following constraints:

  • csrRowOffsets, csrColInd, and csrValues must be aligned to the size of the datatypes specified by csrRowOffsetsType, csrColIndType, and valueType, respectively. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseCsrGet()

cusparseStatus_t
cusparseCsrGet(cusparseSpMatDescr_t spMatDescr,
               int64_t*             rows,
               int64_t*             cols,
               int64_t*             nnz,
               void**               csrRowOffsets,
               void**               csrColInd,
               void**               csrValues,
               cusparseIndexType_t* csrRowOffsetsType,
               cusparseIndexType_t* csrColIndType,
               cusparseIndexBase_t* idxBase,
               cudaDataType*        valueType)

cusparseStatus_t
cusparseConstCsrGet(cusparseConstSpMatDescr_t spMatDescr,
                    int64_t*                  rows,
                    int64_t*                  cols,
                    int64_t*                  nnz,
                    const void**              csrRowOffsets,
                    const void**              csrColInd,
                    const void**              csrValues,
                    cusparseIndexType_t*      csrRowOffsetsType,
                    cusparseIndexType_t*      csrColIndType,
                    cusparseIndexBase_t*      idxBase,
                    cudaDataType*             valueType)

This function returns the fields of the sparse matrix descriptor spMatDescr stored in CSR format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

rows

HOST

OUT

Number of rows of the sparse matrix

cols

HOST

OUT

Number of columns of the sparse matrix

nnz

HOST

OUT

Number of non-zero entries of the sparse matrix

csrRowOffsets

DEVICE

OUT

Row offsets of the sparse matrix. Array with rows + 1 elements

csrColInd

DEVICE

OUT

Column indices of the sparse matrix. Array with nnz elements

csrValues

DEVICE

OUT

Values of the sparse matrix. Array with nnz elements

csrRowOffsetsType

HOST

OUT

Data type of csrRowOffsets

csrColIndType

HOST

OUT

Data type of csrColInd

idxBase

HOST

OUT

Index base of csrRowOffsets and csrColInd

valueType

HOST

OUT

Datatype of csrValues

See cusparseStatus_t for the description of the return status.


cusparseCsrSetPointers()

cusparseStatus_t
cusparseCsrSetPointers(cusparseSpMatDescr_t spMatDescr,
                       void*                csrRowOffsets,
                       void*                csrColInd,
                       void*                csrValues)

This function sets the pointers of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

csrRowOffsets

DEVICE

IN

Row offsets of the sparse matrix. Array with rows + 1 elements

csrColInd

DEVICE

IN

Column indices of the sparse matrix. Array with nnz elements

csrValues

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

cusparseCsrSetPointers() has the following constraints:

  • csrRowOffsets, csrColInd, and csrValues must be aligned to the size of their corresponding datatypes specified in spMatDescr. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseCsrSetStridedBatch()

cusparseStatus_t
cusparseCsrSetStridedBatch(cusparseSpMatDescr_t spMatDescr,
                           int                  batchCount,
                           int64_t              offsetsBatchStride,
                           int64_t              columnsValuesBatchStride)

This function sets the batchCount and the batchStride fields of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

batchCount

HOST

IN

Number of batches of the sparse matrix

offsetsBatchStride

HOST

IN

Address offset between consecutive batches for the row offset array

columnsValuesBatchStride

HOST

IN

Address offset between consecutive batches for the column and value arrays

See cusparseStatus_t for the description of the return status.


Compressed Sparse Column (CSC)

cusparseCreateCsc()

cusparseStatus_t
cusparseCreateCsc(cusparseSpMatDescr_t* spMatDescr,
                  int64_t               rows,
                  int64_t               cols,
                  int64_t               nnz,
                  void*                 cscColOffsets,
                  void*                 cscRowInd,
                  void*                 cscValues,
                  cusparseIndexType_t   cscColOffsetsType,
                  cusparseIndexType_t   cscRowIndType,
                  cusparseIndexBase_t   idxBase,
                  cudaDataType          valueType)

cusparseStatus_t
cusparseCreateConstCsc(cusparseConstSpMatDescr_t* spMatDescr,
                       int64_t                    rows,
                       int64_t                    cols,
                       int64_t                    nnz,
                       const void*                cscColOffsets,
                       const void*                cscRowInd,
                       const void*                cscValues,
                       cusparseIndexType_t        cscColOffsetsType,
                       cusparseIndexType_t        cscRowIndType,
                       cusparseIndexBase_t        idxBase,
                       cudaDataType               valueType)

This function initializes the sparse matrix descriptor spMatDescr in the CSC format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

rows

HOST

IN

Number of rows of the sparse matrix

cols

HOST

IN

Number of columns of the sparse matrix

nnz

HOST

IN

Number of non-zero entries of the sparse matrix

cscColOffsets

DEVICE

IN

Column offsets of the sparse matrix. Array with cols + 1 elements

cscRowInd

DEVICE

IN

Row indices of the sparse matrix. Array with nnz elements

cscValues

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

cscColOffsetsType

HOST

IN

Data type of cscColOffsets

cscRowIndType

HOST

IN

Data type of cscRowInd

idxBase

HOST

IN

Index base of cscColOffsets and cscRowInd

valueType

HOST

IN

Datatype of cscValues

cusparseCreateCsc() has the following constraints:

  • cscColOffsets, cscRowInd, and cscValues must be aligned to the size of the datatypes specified by cscColOffsetsType, cscRowIndType, and valueType, respectively. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseCscGet()

cusparseStatus_t
cusparseCscGet(cusparseSpMatDescr_t spMatDescr,
               int64_t*             rows,
               int64_t*             cols,
               int64_t*             nnz,
               void**               cscColOffsets,
               void**               cscRowInd,
               void**               cscValues,
               cusparseIndexType_t* cscColOffsetsType,
               cusparseIndexType_t* cscRowIndType,
               cusparseIndexBase_t* idxBase,
               cudaDataType*        valueType)

cusparseStatus_t
cusparseConstCscGet(cusparseConstSpMatDescr_t spMatDescr,
                    int64_t*                  rows,
                    int64_t*                  cols,
                    int64_t*                  nnz,
                    const void**              cscColOffsets,
                    const void**              cscRowInd,
                    const void**              cscValues,
                    cusparseIndexType_t*      cscColOffsetsType,
                    cusparseIndexType_t*      cscRowIndType,
                    cusparseIndexBase_t*      idxBase,
                    cudaDataType*             valueType)

This function returns the fields of the sparse matrix descriptor spMatDescr stored in CSC format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

rows

HOST

OUT

Number of rows of the sparse matrix

cols

HOST

OUT

Number of columns of the sparse matrix

nnz

HOST

OUT

Number of non-zero entries of the sparse matrix

cscColOffsets

DEVICE

OUT

Row offsets of the sparse matrix. Array with cols + 1 elements

cscRowInd

DEVICE

OUT

Column indices of the sparse matrix. Array with nnz elements

cscValues

DEVICE

OUT

Values of the sparse matrix. Array with nnz elements

cscColOffsetsType

HOST

OUT

Data type of cscColOffsets

cscRowIndType

HOST

OUT

Data type of cscRowInd

idxBase

HOST

OUT

Index base of cscColOffsets and cscRowInd

valueType

HOST

OUT

Datatype of cscValues

See cusparseStatus_t for the description of the return status.


cusparseCscSetPointers()

cusparseStatus_t
cusparseCscSetPointers(cusparseSpMatDescr_t spMatDescr,
                       void*                cscColOffsets,
                       void*                cscRowInd,
                       void*                cscValues)

This function sets the pointers of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

cscColOffsets

DEVICE

IN

Col offsets of the sparse matrix. Array with cols + 1 elements

cscRowInd

DEVICE

IN

Row indices of the sparse matrix. Array with nnz elements

cscValues

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

cusparseCscSetPointers() has the following constraints:

  • cscColOffsets, cscRowInd, and cscValues must be aligned to the size of their corresponding datatypes specified in spMatDescr. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


Blocked-Ellpack (Blocked-ELL)

cusparseCreateBlockedEll()

cusparseStatus_t
cusparseCreateBlockedEll(cusparseSpMatDescr_t* spMatDescr,
                         int64_t               rows,
                         int64_t               cols,
                         int64_t               ellBlockSize,
                         int64_t               ellCols,
                         void*                 ellColInd,
                         void*                 ellValue,
                         cusparseIndexType_t   ellIdxType,
                         cusparseIndexBase_t   idxBase,
                         cudaDataType          valueType)

cusparseStatus_t
cusparseCreateConstBlockedEll(cusparseConstSpMatDescr_t* spMatDescr,
                              int64_t                    rows,
                              int64_t                    cols,
                              int64_t                    ellBlockSize,
                              int64_t                    ellCols,
                              const void*                ellColInd,
                              const void*                ellValue,
                              cusparseIndexType_t        ellIdxType,
                              cusparseIndexBase_t        idxBase,
                              cudaDataType               valueType)

This function initializes the sparse matrix descriptor spMatDescr for the Blocked-Ellpack (ELL) format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

rows

HOST

IN

Number of rows of the sparse matrix

cols

HOST

IN

Number of columns of the sparse matrix

ellBlockSize

HOST

IN

Size of the ELL-Block

ellCols

HOST

IN

Actual number of columns of the Blocked-Ellpack format (ellValue columns)

ellColInd

DEVICE

IN

Blocked-ELL Column indices. Array with [ellCols / ellBlockSize][rows / ellBlockSize] elements

ellValue

DEVICE

IN

Values of the sparse matrix. Array with rows * ellCols elements

ellIdxType

HOST

IN

Data type of ellColInd

idxBase

HOST

IN

Index base of ellColInd

valueType

HOST

IN

Data type of ellValue

Blocked-ELL Column indices (ellColInd) are in the range [0, cols / ellBlockSize -1]. The array can contain -1 values for indicating empty blocks.

See cusparseStatus_t for the description of the return status.


cusparseBlockedEllGet()

cusparseStatus_t
cusparseBlockedEllGet(cusparseSpMatDescr_t spMatDescr,
                      int64_t*             rows,
                      int64_t*             cols,
                      int64_t*             ellBlockSize,
                      int64_t*             ellCols,
                      void**               ellColInd,
                      void**               ellValue,
                      cusparseIndexType_t* ellIdxType,
                      cusparseIndexBase_t* idxBase,
                      cudaDataType*        valueType)

cusparseStatus_t
cusparseConstBlockedEllGet(cusparseConstSpMatDescr_t spMatDescr,
                           int64_t*                  rows,
                           int64_t*                  cols,
                           int64_t*                  ellBlockSize,
                           int64_t*                  ellCols,
                           const void**              ellColInd,
                           const void**              ellValue,
                           cusparseIndexType_t*      ellIdxType,
                           cusparseIndexBase_t*      idxBase,
                           cudaDataType*             valueType)

This function returns the fields of the sparse matrix descriptor spMatDescr stored in Blocked-Ellpack (ELL) format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

rows

HOST

OUT

Number of rows of the sparse matrix

cols

HOST

OUT

Number of columns of the sparse matrix

ellBlockSize

HOST

OUT

Size of the ELL-Block

ellCols

HOST

OUT

Actual number of columns of the Blocked-Ellpack format

ellColInd

DEVICE

OUT

Column indices for the ELL-Block. Array with [cols / ellBlockSize][rows / ellBlockSize] elements

ellValue

DEVICE

OUT

Values of the sparse matrix. Array with rows * ellCols elements

ellIdxType

HOST

OUT

Data type of ellColInd

idxBase

HOST

OUT

Index base of ellColInd

valueType

HOST

OUT

Datatype of ellValue

See cusparseStatus_t for the description of the return status.


Sliced-Ellpack (SELL)

cusparseCreateSlicedEll()

cusparseStatus_t
cusparseCreateSlicedEll(cusparseSpMatDescr_t*   spMatDescr,
                        int64_t                 rows,
                        int64_t                 cols,
                        int64_t                 nnz,
                        int64_t                 sellValuesSize,
                        int64_t                 sliceSize,
                        void*                   sellSliceOffsets,
                        void*                   sellColInd,
                        void*                   sellValues,
                        cusparseIndexType_t     sellSliceOffsetsType,
                        cusparseIndexType_t     sellColIndType,
                        cusparseIndexBase_t     idxBase,
                        cudaDataType            valueType)

cusparseStatus_t
cusparseCreateConstSlicedEll(cusparseConstSpMatDescr_t* spMatDescr,
                             int64_t                    rows,
                             int64_t                    cols,
                             int64_t                    nnz,
                             int64_t                    sellValuesSize,
                             int64_t                    sliceSize,
                             const void*                sellSliceOffsets,
                             const void*                sellColInd,
                             const void*                sellValues,
                             cusparseIndexType_t        sellSliceOffsetsType,
                             cusparseIndexType_t        sellColIndType,
                             cusparseIndexBase_t        idxBase,
                             cudaDataType               valueType)

This function initializes the sparse matrix descriptor spMatDescr for the Sliced Ellpack (SELL) format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

rows

HOST

IN

Number of rows of the sparse matrix

cols

HOST

IN

Number of columns of the sparse matrix

nnz

HOST

IN

Number of nonzero elements in the sparse matrix

sellValuesSize

HOST

IN

Total number of elements in sellValues array (nonzero and padding)

sliceSize

HOST

IN

The number of rows per slice

sellSliceOffsets

DEVICE

IN

Slice offsets of the sparse matrix. Array of size \(\left \lceil{\frac{rows}{sliceSize}}\right \rceil + 1\)

sellColInd

DEVICE

IN

Column indexes of the sparse matrix. Array of size sellValuesSize

sellValues

DEVICE

IN

Values of the sparse matrix. Array of size sellValuesSize elements

sellSliceOffsetsType

HOST

IN

Data type of sellSliceOffsets

sellColIndType

HOST

IN

Data type of sellColInd

idxBase

HOST

IN

Index base of sellColInd

valueType

HOST

IN

Data type of sellValues

Note

Sliced Ellpack Column array sellColInd contains -1 values for indicating padded entries.

cusparseCreateSlicedEll() has the following constraints:

  • sellSliceOffsets, sellColInd, and sellValues must be aligned to the size of the datatypes specified by sellSliceOffsetsType, sellColIndType, and valueType, respectively. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


Block Sparse Row (BSR)

cusparseCreateBsr()

cusparseStatus_t
cusparseCreateBsr(cusparseSpMatDescr_t* spMatDescr,
                  int64_t               brows,
                  int64_t               bcols,
                  int64_t               bnnz,
                  int64_t               rowBlockSize,
                  int64_t               colBlockSize,
                  void*                 bsrRowOffsets,
                  void*                 bsrColInd,
                  void*                 bsrValues,
                  cusparseIndexType_t   bsrRowOffsetsType,
                  cusparseIndexType_t   bsrColIndType,
                  cusparseIndexBase_t   idxBase,
                  cudaDataType          valueType,
                  cusparseOrder_t       order)

cusparseStatus_t
cusparseCreateConstBsr(cusparseConstSpMatDescr_t* spMatDescr,
                       int64_t                    brows,
                       int64_t                    bcols,
                       int64_t                    bnnz,
                       int64_t                    rowBlockSize,
                       int64_t                    colBlockSize,
                       const void*                bsrRowOffsets,
                       const void*                bsrColInd,
                       const void*                bsrValues,
                       cusparseIndexType_t        bsrRowOffsetsType,
                       cusparseIndexType_t        bsrColIndType,
                       cusparseIndexBase_t        idxBase,
                       cudaDataType               valueType,
                       cusparseOrder_t            order)

This function initializes the sparse matrix descriptor spMatDescr for the Block Compressed Row (BSR) format.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

brows

HOST

IN

Number of block rows of the sparse matrix

bcols

HOST

IN

Number of block columns of the sparse matrix

bnnz

HOST

IN

Number of blocks of the sparse matrix

rowBlockSize

HOST

IN

Number of rows of each block

colBlockSize

HOST

IN

Number of columns of each block

bsrRowOffsets

DEVICE

IN

Block row offsets of the sparse matrix. Array of size brows + 1

bsrColInd

DEVICE

IN

Block column indices of the sparse matrix. Array of size bnnz

bsrValues

DEVICE

IN

Values of the sparse matrix. Array of size bnnz * rowBlockSize * colBlockSize

bsrRowOffsetsType

HOST

IN

Data type of bsrRowOffsets

bsrColIndType

HOST

IN

Data type of bsrColInd

idxBase

HOST

IN

Base index of bsrRowOffsets and bsrColInd

valueType

HOST

IN

Datatype of bsrValues

order

HOST

IN

Enumerator specifying the memory layout of values in each block

cusparseCreateBsr() has the following constraints:

  • bsrRowOffsets, bsrColInd, and bsrValues must be aligned to the size of the datatypes specified by bsrRowOffsetsType, bsrColIndType, and valueType, respectively. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseBsrSetStridedBatch()

cusparseStatus_t
cusparseBsrSetStridedBatch(cusparseSpMatDescr_t spMatDescr,
                           int                  batchCount,
                           int64_t              offsetsBatchStride,
                           int64_t              columnsBatchStride,
                           int64_t              valuesBatchStride)

This function sets the batchCount and the batchStride fields of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

batchCount

HOST

IN

Number of batches of the sparse matrix

offsetsBatchStride

HOST

IN

Address offset between consecutive batches for the row offset array

columnsBatchStride

HOST

IN

Address offset between consecutive batches for the column array

valuesBatchStride

HOST

IN

Address offset between consecutive batches for the values array

See cusparseStatus_t for the description of the return status.


All Sparse Formats

cusparseDestroySpMat()

cusparseStatus_t
cusparseDestroySpMat(cusparseConstSpMatDescr_t spMatDescr) // non-const descriptor supported

This function releases the host memory allocated for the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

See cusparseStatus_t for the description of the return status.


cusparseSpMatGetSize()

cusparseStatus_t
cusparseSpMatGetSize(cusparseConstSpMatDescr_t spMatDescr,  // non-const descriptor supported
                     int64_t*                  rows,
                     int64_t*                  cols,
                     int64_t*                  nnz)

This function returns the sizes of the sparse matrix spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

rows

HOST

OUT

Number of rows of the sparse matrix

cols

HOST

OUT

Number of columns of the sparse matrix

nnz

HOST

OUT

Number of non-zero entries of the sparse matrix

See cusparseStatus_t for the description of the return status.


cusparseSpMatGetFormat()

cusparseStatus_t
cusparseSpMatGetFormat(cusparseConstSpMatDescr_t spMatDescr, // non-const descriptor supported
                       cusparseFormat_t*         format)

This function returns the format field of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

format

HOST

OUT

Storage format of the sparse matrix

See cusparseStatus_t for the description of the return status.


cusparseSpMatGetIndexBase()

cusparseStatus_t
cusparseSpMatGetIndexBase(cusparseConstSpMatDescr_t spMatDescr, // non-const descriptor supported
                          cusparseIndexBase_t*      idxBase)

This function returns the idxBase field of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

idxBase

HOST

OUT

Index base of the sparse matrix

See cusparseStatus_t for the description of the return status.


cusparseSpMatGetValues()

cusparseStatus_t
cusparseSpMatGetValues(cusparseSpMatDescr_t spMatDescr,
                       void**               values)

cusparseStatus_t
cusparseConstSpMatGetValues(cusparseConstSpMatDescr_t spMatDescr,
                            const void**              values)

This function returns the values field of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

values

DEVICE

OUT

Values of the sparse matrix. Array with nnz elements

See cusparseStatus_t for the description of the return status.


cusparseSpMatSetValues()

cusparseStatus_t
cusparseSpMatSetValues(cusparseSpMatDescr_t spMatDescr,
                       void*                values)

This function sets the values field of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

values

DEVICE

IN

Values of the sparse matrix. Array with nnz elements

cusparseSpMatSetValues() has the following constraints:

  • values must be aligned to the size of its corresponding datatype specified in spMatDescr. See cudaDataType_t for the description of the datatypes.

See cusparseStatus_t for the description of the return status.


cusparseSpMatGetStridedBatch()

cusparseStatus_t
cusparseSpMatGetStridedBatch(cusparseConstSpMatDescr_t spMatDescr, // non-const descriptor supported
                             int*                      batchCount)

This function returns the batchCount field of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

batchCount

HOST

OUT

Number of batches of the sparse matrix

See cusparseStatus_t for the description of the return status.


cusparseSpMatGetAttribute()

cusparseStatus_t
cusparseSpMatGetAttribute(cusparseConstSpMatDescr_t spMatDescr, // non-const descriptor supported
                          cusparseSpMatAttribute_t  attribute,
                          void*                     data,
                          size_t                    dataSize)

The function gets the attributes of the sparse matrix descriptor spMatDescr.

Param.

Memory

In/out

Meaning

spMatDescr

HOST

IN

Sparse matrix descriptor

attribute

HOST

IN

Attribute enumerator

data

HOST

OUT

Attribute value

dataSize

HOST

IN

Size of the attribute in bytes for safety

Attribute

Meaning

Possible Values

CUSPARSE_SPMAT_FILL_MODE

Indicates if the lower or upper part of a matrix is stored in sparse storage

CUSPARSE_FILL_MODE_LOWER   CUSPARSE_FILL_MODE_UPPER

CUSPARSE_SPMAT_DIAG_TYPE

Indicates if the matrix diagonal entries are unity

CUSPARSE_DIAG_TYPE_NON_UNIT   CUSPARSE_DIAG_TYPE_UNIT

See cusparseStatus_t for the description of the return status.


cusparseSpMatSetAttribute()

cusparseStatus_t
cusparseSpMatSetAttribute(cusparseSpMatDescr_t     spMatDescr,
                          cusparseSpMatAttribute_t attribute,
                          const void*              data,
                          size_t                   dataSize)

The function sets the attributes of the sparse matrix descriptor spMatDescr

Param.

Memory

In/out

Meaning

spMatDescr

HOST

OUT

Sparse matrix descriptor

attribute

HOST

IN

Attribute enumerator

data

HOST

IN

Attribute value

dataSize

HOST

IN

Size of the attribute in bytes for safety

Attribute

Meaning

Possible Values

CUSPARSE_SPMAT_FILL_MODE

Indicates if the lower or upper part of a matrix is stored in sparse storage

CUSPARSE_FILL_MODE_LOWER   CUSPARSE_FILL_MODE_UPPER

CUSPARSE_SPMAT_DIAG_TYPE

Indicates if the matrix diagonal entries are unity

CUSPARSE_DIAG_TYPE_NON_UNIT   CUSPARSE_DIAG_TYPE_UNIT

See cusparseStatus_t for the description of the return status.