Cusparse Library
Cusparse Library
Chapter 1. Introduction.........................................................................................1
1.1. Naming Conventions...................................................................................... 1
1.2. Asynchronous Execution................................................................................. 2
1.3. Static Library support....................................................................................2
Chapter 2. Using the cuSPARSE API.......................................................................... 4
2.1. Thread Safety............................................................................................. 4
2.2. Scalar Parameters........................................................................................ 4
2.3. Parallelism with Streams................................................................................ 4
Chapter 3. cuSPARSE Indexing and Data Formats......................................................... 6
3.1. Index Base Format........................................................................................6
3.2. Vector Formats............................................................................................ 6
3.2.1. Dense Format........................................................................................ 6
3.2.2. Sparse Format........................................................................................6
3.3. Matrix Formats............................................................................................ 7
3.3.1. Dense Format........................................................................................ 7
3.3.2. Coordinate Format (COO).......................................................................... 8
3.3.3. Compressed Sparse Row Format (CSR)...........................................................8
3.3.4. Compressed Sparse Column Format (CSC)...................................................... 9
3.3.5. Ellpack-Itpack Format (ELL)......................................................................10
3.3.6. Hybrid Format (HYB).............................................................................. 11
3.3.7. Block Compressed Sparse Row Format (BSR).................................................. 11
3.3.8. Extended BSR Format (BSRX).................................................................... 13
Chapter 4. cuSPARSE Types Reference.....................................................................15
4.1. Data types................................................................................................ 15
4.2. cusparseAction_t.........................................................................................15
4.3. cusparseDirection_t..................................................................................... 15
4.4. cusparseHandle_t........................................................................................ 16
4.5. cusparseHybMat_t....................................................................................... 16
4.5.1. cusparseHybPartition_t............................................................................ 16
4.6. cusparseMatDescr_t..................................................................................... 16
4.6.1. cusparseDiagType_t................................................................................ 17
4.6.2. cusparseFillMode_t.................................................................................17
4.6.3. cusparseIndexBase_t............................................................................... 17
4.6.4. cusparseMatrixType_t..............................................................................17
4.7. cusparseOperation_t.................................................................................... 18
4.8. cusparsePointerMode_t................................................................................. 18
4.9. cusparseSolvePolicy_t................................................................................... 18
4.10. cusparseSolveAnalysisInfo_t.......................................................................... 19
4.11. cusparseSolveAnalysisInfo_t.......................................................................... 19
4.12. csrsv2Info_t............................................................................................. 19
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | ii
4.13. csric02Info_t............................................................................................ 19
4.14. csrilu02Info_t........................................................................................... 19
4.15. bsrsv2Info_t............................................................................................. 19
4.16. bsrsm2Info_t............................................................................................ 19
4.17. bsric02Info_t............................................................................................ 20
4.18. bsrilu02Info_t........................................................................................... 20
4.19. csrgemm2Info_t........................................................................................ 20
4.20. cusparseStatus_t....................................................................................... 20
Chapter 5. cuSPARSE Helper Function Reference....................................................... 22
5.1. cusparseCreate().........................................................................................22
5.2. cusparseCreateSolveAnalysisInfo().................................................................... 22
5.3. cusparseCreateHybMat()................................................................................23
5.4. cusparseCreateMatDescr()..............................................................................23
5.5. cusparseCreateSolveAnalysisInfo().................................................................... 23
5.6. cusparseDestroy()........................................................................................24
5.7. cusparseDestroySolveAnalysisInfo()................................................................... 24
5.8. cusparseDestroyHybMat()...............................................................................24
5.9. cusparseDestroyMatDescr().............................................................................25
5.10. cusparseDestroySolveAnalysisInfo()..................................................................25
5.11. cusparseGetLevelInfo()................................................................................ 25
5.12. cusparseGetMatDiagType()............................................................................26
5.13. cusparseGetMatFillMode()............................................................................ 26
5.14. cusparseGetMatIndexBase().......................................................................... 26
5.15. cusparseGetMatType()................................................................................. 27
5.16. cusparseGetPointerMode()............................................................................ 27
5.17. cusparseGetVersion().................................................................................. 27
5.18. cusparseSetMatDiagType()............................................................................ 28
5.19. cusparseSetMatFillMode()............................................................................. 28
5.20. cusparseSetMatIndexBase()........................................................................... 29
5.21. cusparseSetMatType()................................................................................. 29
5.22. cusparseSetPointerMode()............................................................................ 29
5.23. cusparseSetStream()................................................................................... 30
5.24. cusparseGetStream().................................................................................. 30
5.25. cusparseCreateCsrsv2Info()........................................................................... 31
5.26. cusparseDestroyCsrsv2Info().......................................................................... 31
5.27. cusparseCreateCsric02Info().......................................................................... 31
5.28. cusparseDestroyCsric02Info().........................................................................32
5.29. cusparseCreateCsrilu02Info()......................................................................... 32
5.30. cusparseDestroyCsrilu02Info()........................................................................ 32
5.31. cusparseCreateBsrsv2Info()........................................................................... 33
5.32. cusparseDestroyBsrsv2Info().......................................................................... 33
5.33. cusparseCreateBsrsm2Info().......................................................................... 33
5.34. cusparseDestroyBsrsm2Info()......................................................................... 34
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | iii
5.35. cusparseCreateBsric02Info().......................................................................... 34
5.36. cusparseDestroyBsric02Info()......................................................................... 34
5.37. cusparseCreateBsrilu02Info()......................................................................... 35
5.38. cusparseDestroyBsrilu02Info()........................................................................ 35
5.39. cusparseCreateCsrgemm2Info()...................................................................... 35
5.40. cusparseDestroyCsrgemm2Info()..................................................................... 36
Chapter 6. cuSPARSE Level 1 Function Reference...................................................... 37
6.1. cusparse<t>axpyi()...................................................................................... 37
6.2. cusparse<t>doti()........................................................................................ 38
6.3. cusparse<t>dotci().......................................................................................40
6.4. cusparse<t>gthr()........................................................................................ 41
6.5. cusparse<t>gthrz().......................................................................................42
6.6. cusparse<t>roti()........................................................................................ 43
6.7. cusparse<t>sctr()........................................................................................ 44
Chapter 7. cuSPARSE Level 2 Function Reference...................................................... 46
7.1. cusparse<t>bsrmv()......................................................................................47
7.2. cusparse<t>bsrxmv().................................................................................... 50
7.3. cusparse<t>csrmv()...................................................................................... 54
7.4. cusparseCsrmvEx().......................................................................................56
7.5. cusparseCsrmvEx_bufferSize()......................................................................... 57
7.6. cusparse<t>csrmv_mp().................................................................................58
7.7. cusparse<t>gemvi()......................................................................................60
7.8. cusparse<t>gemvi_bufferSize()........................................................................ 62
7.9. cusparse<t>bsrsv2_bufferSize()........................................................................64
7.10. cusparse<t>bsrsv2_analysis()......................................................................... 67
7.11. cusparse<t>bsrsv2_solve()............................................................................ 70
7.12. cusparseXbsrsv2_zeroPivot()..........................................................................74
7.13. cusparse<t>csrsv_analysis()...........................................................................75
7.14. cusparseCsrsv_analysisEx()........................................................................... 77
7.15. cusparse<t>csrsv_solve().............................................................................. 78
7.16. cusparseCsrsv_solveEx()...............................................................................80
7.17. cusparse<t>csrsv2_bufferSize()...................................................................... 81
7.18. cusparse<t>csrsv2_analysis()......................................................................... 83
7.19. cusparse<t>csrsv2_solve().............................................................................86
7.20. cusparseXcsrsv2_zeroPivot().......................................................................... 90
7.21. cusparse<t>hybmv()....................................................................................91
7.22. cusparse<t>hybsv_analysis().......................................................................... 92
7.23. cusparse<t>hybsv_solve()............................................................................. 94
Chapter 8. cuSPARSE Level 3 Function Reference...................................................... 96
8.1. cusparse<t>csrmm()..................................................................................... 97
8.2. cusparse<t>csrmm2().................................................................................. 100
8.3. cusparse<t>csrsm_analysis()..........................................................................104
8.4. cusparse<t>csrsm_solve()............................................................................. 106
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | iv
8.5. cusparse<t>bsrmm()................................................................................... 109
8.6. cusparse<t>bsrsm2_bufferSize()..................................................................... 113
8.7. cusparse<t>bsrsm2_analysis()........................................................................ 116
8.8. cusparse<t>bsrsm2_solve()........................................................................... 120
8.9. cusparseXbsrsm2_zeroPivot().........................................................................123
Chapter 9. cuSPARSE Extra Function Reference........................................................124
9.1. cusparse<t>csrgeam()................................................................................. 125
9.2. cusparse<t>csrgemm().................................................................................129
9.3. cusparse<t>csrgemm2()............................................................................... 133
Chapter 10. cuSPARSE Preconditioners Reference.....................................................138
10.1. cusparse<t>csric0()................................................................................... 139
10.2. cusparse<t>csric02_bufferSize()....................................................................141
10.3. cusparse<t>csric02_analysis().......................................................................143
10.4. cusparse<t>csric02()..................................................................................146
10.5. cusparseXcsric02_zeroPivot()....................................................................... 150
10.6. cusparse<t>csrilu0().................................................................................. 151
10.7. cusparseCsrilu0Ex()................................................................................... 153
10.8. cusparse<t>csrilu02_numericBoost()...............................................................154
10.9. cusparse<t>csrilu02_bufferSize()................................................................... 155
10.10. cusparse<t>csrilu02_analysis().................................................................... 157
10.11. cusparse<t>csrilu02()............................................................................... 160
10.12. cusparseXcsrilu02_zeroPivot()..................................................................... 164
10.13. cusparse<t>bsric02_bufferSize().................................................................. 165
10.14. cusparse<t>bsric02_analysis()..................................................................... 168
10.15. cusparse<t>bsric02()................................................................................ 171
10.16. cusparseXbsric02_zeroPivot()......................................................................175
10.17. cusparse<t>bsrilu02_numericBoost()............................................................. 176
10.18. cusparse<t>bsrilu02_bufferSize()................................................................. 178
10.19. cusparse<t>bsrilu02_analysis().................................................................... 181
10.20. cusparse<t>bsrilu02()............................................................................... 184
10.21. cusparseXbsrilu02_zeroPivot().....................................................................188
10.22. cusparse<t>gtsv()....................................................................................189
10.23. cusparse<t>gtsv_nopivot()......................................................................... 191
10.24. cusparse<t>gtsvStridedBatch().................................................................... 192
Chapter 11. cuSPARSE Reorderings Reference..........................................................195
11.1. cusparse<t>csrcolor()................................................................................ 195
Chapter 12. cuSPARSE Format Conversion Reference.................................................198
12.1. cusparse<t>bsr2csr()................................................................................. 199
12.2. cusparse<t>gebsr2gebsc_bufferSize()............................................................. 202
12.3. cusparse<t>gebsr2gebsc()........................................................................... 204
12.4. cusparse<t>gebsr2gebsr_bufferSize().............................................................. 207
12.5. cusparse<t>gebsr2gebsr()............................................................................209
12.6. cusparse<t>gebsr2csr()...............................................................................213
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | v
12.7. cusparse<t>csr2gebsr_bufferSize()................................................................. 216
12.8. cusparse<t>csr2gebsr()...............................................................................218
12.9. cusparse<t>coo2csr()................................................................................. 221
12.10. cusparse<t>csc2dense()............................................................................ 223
12.11. cusparse<t>csc2hyb()............................................................................... 224
12.12. cusparse<t>csr2bsr()................................................................................ 226
12.13. cusparse<t>csr2coo()............................................................................... 228
12.14. cusparse<t>csr2csc()................................................................................ 230
12.15. cusparseCsr2cscEx().................................................................................231
12.16. cusparse<t>csr2dense().............................................................................232
12.17. cusparse<t>csr2csr_compress()................................................................... 234
12.18. cusparse<t>csr2hyb()............................................................................... 236
12.19. cusparse<t>dense2csc()............................................................................ 238
12.20. cusparse<t>dense2csr().............................................................................239
12.21. cusparse<t>dense2hyb()............................................................................ 241
12.22. cusparse<t>hyb2csc()............................................................................... 242
12.23. cusparse<t>hyb2csr()............................................................................... 244
12.24. cusparse<t>hyb2dense()............................................................................ 245
12.25. cusparse<t>nnz().................................................................................... 246
12.26. cusparseCreateIdentityPermutation()............................................................ 247
12.27. cusparseXcoosort().................................................................................. 248
12.28. cusparseXcsrsort()................................................................................... 250
12.29. cusparseXcscsort()...................................................................................252
12.30. cusparseXcsru2csr()................................................................................. 255
Chapter 13. Appendix A: cuSPARSE Library C++ Example............................................259
Chapter 14. Appendix B: cuSPARSE Fortran Bindings................................................. 261
14.1. Example B, Fortran Application....................................................................263
Chapter 15. Appendix C: Acknowledgements...........................................................264
Chapter 16. Bibliography.................................................................................... 265
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | vi
Chapter 1.
INTRODUCTION
The cuSPARSE library contains a set of basic linear algebra subroutines used for
handling sparse matrices. It is implemented on top of the NVIDIA® CUDA™ runtime
(which is part of the CUDA Toolkit) and is designed to be called from C and C++. The
library routines can be classified into four categories:
‣ Level 1: operations between a vector in sparse format and a vector in dense format
‣ Level 2: operations between a matrix in sparse format and a vector in dense format
‣ Level 3: operations between a matrix in sparse format and a set of vectors in dense
format (which can also usually be viewed as a dense tall matrix)
‣ Conversion: operations that allow conversion between different matrix formats, and
compression of csr matrices.
The cuSPARSE library allows developers to access the computational resources of the
NVIDIA graphics processing unit (GPU), although it does not auto-parallelize across
multiple GPUs. The cuSPARSE API assumes that input and output data reside in GPU
(device) memory, unless it is explicitly indicated otherwise by the string DevHostPtr in
a function parameter's name (for example, the parameter *resultDevHostPtr in the
function cusparse<t>doti()).
It is the responsibility of the developer to allocate memory and to copy data between
GPU memory and CPU memory using standard CUDA runtime API routines, such as
cudaMalloc(), cudaFree(), cudaMemcpy(), and cudaMemcpyAsync().
The cuSPARSE library requires hardware with compute capability (CC) of at least 2.0
or higher. Please see the NVIDIA CUDA C Programming Guide, Appendix A for a list of
the compute capabilities corresponding to all NVIDIA GPUs.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 1
Introduction
Whereas to compile against the static cuSPARSE library, the following command has to
be used:
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 2
Introduction
It is also possible to use the native Host C++ compiler. Depending on the Host Operating
system, some additional libraries like pthread or dl might be needed on the linking
line. The following command on Linux is suggested :
Note that in the latter case, the library cuda is not needed. The CUDA Runtime will try
to open explicitly the cuda library if needed. In the case of a system which does not have
the CUDA driver installed, this allows the application to gracefully manage this issue
and potentially run if a CPU-only path is available.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 3
Chapter 2.
USING THE CUSPARSE API
This chapter describes how to use the cuSPARSE library API. It is not a reference for the
cuSPARSE API data types and functions; that is provided in subsequent chapters.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 4
Using the cuSPARSE API
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 5
Chapter 3.
CUSPARSE INDEXING AND DATA FORMATS
The cuSPARSE library supports dense and sparse vector, and dense and sparse matrix
formats.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 6
cuSPARSE Indexing and Data Formats
In each example, the top row is the data array and the bottom row is the index array,
and it is assumed that the indices are provided in increasing order and that each index
appears only once.
For example, m×n dense matrix X with leading dimension ldX can be stored with one-
based indexing as shown.
This format and notation are similar to those used in the NVIDIA CUDA cuBLAS library.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 7
cuSPARSE Indexing and Data Formats
A sparse matrix in COO format is assumed to be stored in row-major format: the index
arrays are first sorted by row indices and then within the same row by compressed
column indices. It is assumed that each pair of row and column indices appears only
once.
For example, consider the following matrix A.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 8
cuSPARSE Indexing and Data Formats
csrColIndA (pointer) Points to the integer array of length nnz that contains the column
indices of the corresponding elements in array csrValA.
Sparse matrices in CSR format are assumed to be stored in row-major CSR format, in
other words, the index arrays are first sorted by row indices and then within the same
row by column indices. It is assumed that each pair of row and column indices appears
only once.
Consider again the matrixA.
The matrix A in CSR format has exactly the same memory layout as its transpose in
CSC format (and vice versa).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 9
cuSPARSE Indexing and Data Formats
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 10
cuSPARSE Indexing and Data Formats
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 11
cuSPARSE Indexing and Data Formats
As with CSR format, (row, column) indices of BSR are stored in row-major order. The
index arrays are first sorted by row indices and then within the same row by column
indices.
For example, consider again the 4×5 matrix A.
The basic element of BSR is a nonzero block, one that contains at least one nonzero
element of A. Five of six blocks are nonzero in .
BSR format only stores the information of nonzero blocks, including block indices
and values . Also row indices are compressed in CSR format.
There are two ways to arrange the data element of block : row-major order and
column-major order. Under column-major order, the physical storage of bsrValA is this.
Similarly, in BSR format with one-based indexing and column-major order, A can be
represented by the following.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 12
cuSPARSE Indexing and Data Formats
The general BSR format has two parameters, rowBlockDim and colBlockDim.
rowBlockDim is number of rows within a block and colBlockDim is number of
columns within a block. If rowBlockDim=colBlockDim, general BSR format is the
same as BSR format. If rowBlockDim=colBlockDim=1, general BSR format is the
same as CSR format. The conversion routine gebsr2gebsr is used to do conversion
among CSR, BSR and general BSR.
In the cuSPARSE Library, the storage format of blocks in BSR format can be column-
major or row-major, independently of the base index. However, if the developer uses
BSR format from the Math Kernel Library (MKL) and wants to directly interface with
the cuSPARSE Library, then cusparseDirection_t CUSPARSE_DIRECTION_COLUMN
should be used if the base index is one; otherwise, cusparseDirection_t
CUSPARSE_DIRECTION_ROW should be used.
A simple conversion between BSR and BSRX can be done as follows. Suppose the
developer has a 2×3 block sparse matrix represented as shown.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 13
cuSPARSE Indexing and Data Formats
The bsrRowPtrA of the BSRX format is simply the first two elements of the bsrRowPtrA
BSR format. The bsrEndPtrA of BSRX format is the last two elements of the
bsrRowPtrA of BSR format.
The advantage of the BSRX format is that the developer can specify a submatrix in
the original BSR format by modifying bsrRowPtrA and bsrEndPtrA while keeping
bsrColIndA and bsrValA unchanged.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 14
Chapter 4.
CUSPARSE TYPES REFERENCE
4.2. cusparseAction_t
This type indicates whether the operation is performed only on indices or on data and
indices.
Value Meaning
4.3. cusparseDirection_t
This type indicates whether the elements of a dense matrix should be parsed by rows or
by columns (assuming column-major storage in memory of the dense matrix) in function
cusparse[S|D|C|Z]nnz. Besides storage format of blocks in BSR format is also controlled
by this type.
Value Meaning
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 15
cuSPARSE Types Reference
4.4. cusparseHandle_t
This is a pointer type to an opaque cuSPARSE context, which the user must initialize
by calling prior to calling cusparseCreate() any other library function. The handle
created and returned by cusparseCreate() must be passed to every cuSPARSE
function.
4.5. cusparseHybMat_t
This is a pointer type to an opaque structure holding the matrix in HYB format, which is
created by cusparseCreateHybMat and destroyed by cusparseDestroyHybMat.
4.5.1. cusparseHybPartition_t
This type indicates how to perform the partitioning of the matrix into regular (ELL) and
irregular (COO) parts of the HYB format.
The partitioning is performed during the conversion of the matrix from a dense or
sparse format into the HYB format and is governed by the following rules. When
CUSPARSE_HYB_PARTITION_AUTO is selected, the cuSPARSE library automatically
decides how much data to put into the regular and irregular parts of the HYB format.
When CUSPARSE_HYB_PARTITION_USER is selected, the width of the regular part of the
HYB format should be specified by the caller. When CUSPARSE_HYB_PARTITION_MAX
is selected, the width of the regular part of the HYB format equals to the maximum
number of non-zero elements per row, in other words, the entire matrix is stored in the
regular part of the HYB format.
The default is to let the library automatically decide how to split the data.
Value Meaning
4.6. cusparseMatDescr_t
This structure is used to describe the shape and properties of a matrix.
typedef struct {
cusparseMatrixType_t MatrixType;
cusparseFillMode_t FillMode;
cusparseDiagType_t DiagType;
cusparseIndexBase_t IndexBase;
} cusparseMatDescr_t;
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 16
cuSPARSE Types Reference
4.6.1. cusparseDiagType_t
This type indicates if the matrix diagonal entries are unity. The diagonal elements are
always assumed to be present, but if CUSPARSE_DIAG_TYPE_UNIT is passed to an API
routine, then the routine assumes that all diagonal entries are unity and will not read or
modify those entries. Note that in this case the routine assumes the diagonal entries are
equal to one, regardless of what those entries are actually set to in memory.
Value Meaning
4.6.2. cusparseFillMode_t
This type indicates if the lower or upper part of a matrix is stored in sparse storage.
Value Meaning
4.6.3. cusparseIndexBase_t
This type indicates if the base of the matrix indices is zero or one.
Value Meaning
4.6.4. cusparseMatrixType_t
This type indicates the type of matrix stored in sparse storage. Notice that for symmetric,
Hermitian and triangular matrices only their lower or upper part is assumed to be
stored.
The whole idea of matrix type and fill mode is to keep minimum storage for symmetric/
Hermitian matrix, and also to take advantage of symmetric property on SpMV
(Sparse Matrix Vector multiplication). To compute y=A*x when A is symmetric and
only lower triangular part is stored, two steps are needed. First step is to compute
y=(L+D)*x and second step is to compute y=L^T*x + y. Given the fact that the
transpose operation y=L^T*x is 10x slower than non-transpose version y=L*x, the
symmetric property does not show up any performance gain. It is better for the user
to extend the symmetric matrix to a general matrix and apply y=A*x with matrix type
CUSPARSE_MATRIX_TYPE_GENERAL.
In general, SpMV, preconditioners (incomplete Cholesky or incomplete LU) and
triangular solver are combined together in iterative solvers, for example PCG and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 17
cuSPARSE Types Reference
GMRES. If the user always uses general matrix (instead of symmetric matrix), there
is no need to support other than general matrix in preconditioners. Therefore the
new routines, [bsr|csr]sv2 (triangular solver), [bsr|csr]ilu02 (incomplete
LU) and [bsr|csr]ic02 (incomplete Cholesky), only support matrix type
CUSPARSE_MATRIX_TYPE_GENERAL.
Value Meaning
4.7. cusparseOperation_t
This type indicates which operations need to be performed with the sparse matrix.
Value Meaning
CUSPARSE_OPERATION_CONJUGATE_TRANSPOSE
the conjugate transpose operation is selected.
4.8. cusparsePointerMode_t
This type indicates whether the scalar values are passed by reference on the host or
device. It is important to point out that if several scalar values are passed by reference
in the function call, all of them will conform to the same single pointer mode. The
pointer mode can be set and retrieved using cusparseSetPointerMode() and
cusparseGetPointerMode() routines, respectively.
Value Meaning
4.9. cusparseSolvePolicy_t
This type indicates whether level information is generated and used in csrsv2,
csric02, csrilu02, bsrsv2, bsric02 and bsrilu02.
Value Meaning
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 18
cuSPARSE Types Reference
Value Meaning
4.10. cusparseSolveAnalysisInfo_t
This is a pointer type to an opaque structure holding the information collected in the
analysis phase of the solution of the sparse triangular linear system. It is expected to be
passed unchanged to the solution phase of the sparse triangular linear system.
4.11. cusparseSolveAnalysisInfo_t
This is a pointer type to an opaque structure holding the information collected in the
analysis phase of the solution of the sparse triangular linear system. It is expected to be
passed unchanged to the solution phase of the sparse triangular linear system.
4.12. csrsv2Info_t
This is a pointer type to an opaque structure holding the information used in
csrsv2_bufferSize(), csrsv2_analysis(), and csrsv2_solve().
4.13. csric02Info_t
This is a pointer type to an opaque structure holding the information used in
csric02_bufferSize(), csric02_analysis(), and csric02().
4.14. csrilu02Info_t
This is a pointer type to an opaque structure holding the information used in
csrilu02_bufferSize(), csrilu02_analysis(), and csrilu02().
4.15. bsrsv2Info_t
This is a pointer type to an opaque structure holding the information used in
bsrsv2_bufferSize(), bsrsv2_analysis(), and bsrsv2_solve().
4.16. bsrsm2Info_t
This is a pointer type to an opaque structure holding the information used in
bsrsm2_bufferSize(), bsrsm2_analysis(), and bsrsm2_solve().
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 19
cuSPARSE Types Reference
4.17. bsric02Info_t
This is a pointer type to an opaque structure holding the information used in
bsric02_bufferSize(), bsric02_analysis(), and bsric02().
4.18. bsrilu02Info_t
This is a pointer type to an opaque structure holding the information used in
bsrilu02_bufferSize(), bsrilu02_analysis(), and bsrilu02().
4.19. csrgemm2Info_t
This is a pointer type to an opaque structure holding the information used in
csrgemm2_bufferSizeExt(), and csrgemm2().
4.20. cusparseStatus_t
This is a status type returned by the library functions and it can have the following
values.
CUSPARSE_STATUS_SUCCESS
The operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED
The cuSPARSE library was not initialized. This is usually caused by the
lack of a prior call, an error in the CUDA Runtime API called by the
cuSPARSE routine, or an error in the hardware setup.
To correct: call cusparseCreate() prior to the function call; and
check that the hardware, an appropriate version of the driver, and the
cuSPARSE library are correctly installed.
CUSPARSE_STATUS_ALLOC_FAILED
Resource allocation failed inside the cuSPARSE library. This is usually
caused by a cudaMalloc() failure.
To correct: prior to the function call, deallocate previously allocated
memory as much as possible.
CUSPARSE_STATUS_INVALID_VALUE
An unsupported value or parameter was passed to the function (a
negative vector size, for example).
To correct: ensure that all the parameters being passed have valid
values.
CUSPARSE_STATUS_ARCH_MISMATCH
The function requires a feature absent from the device architecture;
usually caused by the lack of support for atomic operations or double
precision.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 20
cuSPARSE Types Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 21
Chapter 5.
CUSPARSE HELPER FUNCTION REFERENCE
5.1. cusparseCreate()
cusparseStatus_t
cusparseCreate(cusparseHandle_t *handle)
This function initializes the cuSPARSE library and creates a handle on the cuSPARSE
context. It must be called before any other cuSPARSE API function is invoked. It
allocates hardware resources necessary for accessing the GPU.
Output
handle the pointer to the handle to the cuSPARSE context.
Status Returned
CUSPARSE_STATUS_SUCCESS the initialization succeeded.
CUSPARSE_STATUS_NOT_INITIALIZED the CUDA Runtime initialization failed.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_ARCH_MISMATCH the device compute capability (CC) is less than
1.1. The CC of at least 1.1 is required.
5.2. cusparseCreateSolveAnalysisInfo()
cusparseStatus_t
cusparseCreateSolveAnalysisInfo(cusparseSolveAnalysisInfo_t *info)
This function creates and initializes the solve and analysis structure to default values.
Input
info the pointer to the solve and analysis structure.
Status Returned
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 22
cuSPARSE Helper Function Reference
5.3. cusparseCreateHybMat()
cusparseStatus_t
cusparseCreateHybMat(cusparseHybMat_t *hybA)
This function creates and initializes the hybA opaque data structure.
Input
hybA the pointer to the hybrid format storage structure.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.4. cusparseCreateMatDescr()
cusparseStatus_t
cusparseCreateMatDescr(cusparseMatDescr_t *descrA)
This function initializes the matrix descriptor. It sets the fields MatrixType
and IndexBase to the default values CUSPARSE_MATRIX_TYPE_GENERAL and
CUSPARSE_INDEX_BASE_ZERO , respectively, while leaving other fields uninitialized.
Input
descrA the pointer to the matrix descriptor.
Status Returned
CUSPARSE_STATUS_SUCCESS the descriptor was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.5. cusparseCreateSolveAnalysisInfo()
cusparseStatus_t
cusparseCreateSolveAnalysisInfo(cusparseSolveAnalysisInfo_t *info)
This function creates and initializes the solve and analysis structure to default values.
Input
info the pointer to the solve and analysis structure.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 23
cuSPARSE Helper Function Reference
5.6. cusparseDestroy()
cusparseStatus_t
cusparseDestroy(cusparseHandle_t handle)
This function releases CPU-side resources used by the cuSPARSE library. The release of
GPU-side resources may be deferred until the application shuts down.
Input
handle the handle to the cuSPARSE context.
Status Returned
CUSPARSE_STATUS_SUCCESS the shutdown succeeded.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
5.7. cusparseDestroySolveAnalysisInfo()
cusparseStatus_t
cusparseDestroySolveAnalysisInfo(cusparseSolveAnalysisInfo_t info)
This function destroys and releases any memory required by the structure.
Input
info the solve and analysis structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.8. cusparseDestroyHybMat()
cusparseStatus_t
cusparseDestroyHybMat(cusparseHybMat_t hybA)
This function destroys and releases any memory required by the hybA structure.
Input
hybA the hybrid format storage structure.
Status Returned
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 24
cuSPARSE Helper Function Reference
5.9. cusparseDestroyMatDescr()
cusparseStatus_t
cusparseDestroyMatDescr(cusparseMatDescr_t descrA)
This function releases the memory allocated for the matrix descriptor.
Input
descrA the matrix descriptor.
Status Returned
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.10. cusparseDestroySolveAnalysisInfo()
cusparseStatus_t
cusparseDestroySolveAnalysisInfo(cusparseSolveAnalysisInfo_t info)
This function destroys and releases any memory required by the structure.
Input
info the solve and analysis structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.11. cusparseGetLevelInfo()
cusparseStatus_t
cusparseGetLevelInfo(cusparseHandle_t handle,
cusparseSolveAnalysisInfo_t info,
int *nlevels,
int **levelPtr,
int **levelInd)
This function returns the number of levels and the assignment of rows into the levels
computed by either the csrsv_analysis, csrsm_analysis or hybsv_analysis routines.
Input
handle handle to the cuSPARSE library context.
info the pointer to the solve and analysis structure.
Output
nlevels number of levels.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 25
cuSPARSE Helper Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library or the solve analysis structure was not
initialized.
5.12. cusparseGetMatDiagType()
cusparseDiagType_t
cusparseGetMatDiagType(const cusparseMatDescr_t descrA)
This function returns the DiagType field of the matrix descriptor descrA.
Input
descrA the matrix descriptor.
Returned
One of the enumerated diagType types.
5.13. cusparseGetMatFillMode()
cusparseFillMode_t
cusparseGetMatFillMode(const cusparseMatDescr_t descrA)
This function returns the FillMode field of the matrix descriptor descrA.
Input
descrA the matrix descriptor.
Returned
One of the enumerated fillMode types.
5.14. cusparseGetMatIndexBase()
cusparseIndexBase_t
cusparseGetMatIndexBase(const cusparseMatDescr_t descrA)
This function returns the IndexBase field of the matrix descriptor descrA.
Input
descrA the matrix descriptor.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 26
cuSPARSE Helper Function Reference
Returned
One of the enumerated indexBase types.
5.15. cusparseGetMatType()
cusparseMatrixType_t
cusparseGetMatType(const cusparseMatDescr_t descrA)
This function returns the MatrixType field of the matrix descriptor descrA.
Input
descrA the matrix descriptor.
Returned
One of the enumerated matrix types.
5.16. cusparseGetPointerMode()
cusparseStatus_t
cusparseGetPointerMode(cusparseHandlet handle,
cusparsePointerMode_t *mode)
This function obtains the pointer mode used by the cuSPARSE library. Please see the
section on the cusparsePointerMode_t type for more details.
Input
handle the handle to the cuSPARSE context.
Output
mode One of the enumerated pointer mode types.
Status Returned
CUSPARSE_STATUS_SUCCESS the pointer mode was returned successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
5.17. cusparseGetVersion()
cusparseStatus_t
cusparseGetVersion(cusparseHandle_t handle, int *version)
Output
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 27
cuSPARSE Helper Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the version was returned successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
5.18. cusparseSetMatDiagType()
cusparseStatus_t
cusparseSetMatDiagType(cusparseMatDescr_t descrA,
cusparseDiagType_t diagType)
This function sets the DiagType field of the matrix descriptor descrA.
Input
diagType One of the enumerated diagType types.
Output
descrA the matrix descriptor.
Status Returned
CUSPARSE_STATUS_SUCCESS the field DiagType was set successfully.
CUSPARSE_STATUS_INVALID_VALUE An invalid diagType parameter was passed.
5.19. cusparseSetMatFillMode()
cusparseStatus_t
cusparseSetMatFillMode(cusparseMatDescr_t descrA,
cusparseFillMode_t fillMode)
This function sets the FillMode field of the matrix descriptor descrA.
Input
fillMode One of the enumerated fillMode types.
Output
descrA the matrix descriptor.
Status Returned
CUSPARSE_STATUS_SUCCESS the FillMode field was set successfully.
CUSPARSE_STATUS_INVALID_VALUE An invalid fillMode parameter was passed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 28
cuSPARSE Helper Function Reference
5.20. cusparseSetMatIndexBase()
cusparseStatus_t
cusparseSetMatIndexBase(cusparseMatDescr_t descrA,
cusparseIndexBase_t base)
This function sets the IndexBase field of the matrix descriptor descrA.
Input
base One of the enumerated indexBase types.
Output
descrA the matrix descriptor.
Status Returned
CUSPARSE_STATUS_SUCCESS the IndexBase field was set successfully.
CUSPARSE_STATUS_INVALID_VALUE An invalid base parameter was passed.
5.21. cusparseSetMatType()
cusparseStatus_t
cusparseSetMatType(cusparseMatDescr_t descrA, cusparseMatrixType_t type)
This function sets the MatrixType field of the matrix descriptor descrA.
Input
type One of the enumerated matrix types.
Output
descrA the matrix descriptor.
Status Returned
CUSPARSE_STATUS_SUCCESS the MatrixType field was set successfully.
CUSPARSE_STATUS_INVALID_VALUE An invalid type parameter was passed.
5.22. cusparseSetPointerMode()
cusparseStatus_t
cusparseSetPointerMode(cusparseHandle_t handle,
cusparsePointerMode_t mode)
This function sets the pointer mode used by the cuSPARSE library. The default is
for the values to be passed by reference on the host. Please see the section on the
cublasPointerMode_t type for more details.
Input
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 29
cuSPARSE Helper Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the pointer mode was set successfully.
CUSPARSE_STATUS_INVALID_VALUE the library was not initialized.
5.23. cusparseSetStream()
cusparseStatus_t
cusparseSetStream(cusparseHandle_t handle, cudaStream_t streamId)
This function sets the stream to be used by the cuSPARSE library to execute its routines.
Input
handle the handle to the cuSPARSE context.
streamId the stream to be used by the library.
Status Returned
CUSPARSE_STATUS_SUCCESS the stream was set successfully.
CUSPARSE_STATUS_INVALID_VALUE the library was not initialized.
5.24. cusparseGetStream()
cusparseStatus_t
cusparseGetStream(cusparseHandle_t handle, cudaStream_t *streamId)
This function gets the cuSPARSE library stream, which is being used to to execute all
calls to the cuSPARSE library functions. If the cuSPARSE library stream is not set, all
kernels use the default NULL stream.
Input
handle the handle to the cuSPARSE context.
Output
streamId the stream to be used by the library.
Status Returned
CUSPARSE_STATUS_SUCCESS the stream was returned successfully.
CUSPARSE_STATUS_INVALID_VALUE the library was not initialized.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 30
cuSPARSE Helper Function Reference
5.25. cusparseCreateCsrsv2Info()
cusparseStatus_t
cusparseCreateCsrsv2Info(csrsv2Info_t *info);
This function creates and initializes the solve and analysis structure of csrsv2 to default
values.
Input
info the pointer to the solve and analysis structure of
csrsv2.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.26. cusparseDestroyCsrsv2Info()
cusparseStatus_t
cusparseDestroyCsrsv2Info(csrsv2Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (csrsv2_solve) and analysis
(csrsv2_analysis) structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.27. cusparseCreateCsric02Info()
cusparseStatus_t
cusparseCreateCsric02Info(csric02Info_t *info);
This function creates and initializes the solve and analysis structure of incomplete
Cholesky to default values.
Input
info the pointer to the solve and analysis structure of
incomplete Cholesky.
Status Returned
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 31
cuSPARSE Helper Function Reference
5.28. cusparseDestroyCsric02Info()
cusparseStatus_t
cusparseDestroyCsric02Info(csric02Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (csric02_solve) and analysis
(csric02_analysis) structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.29. cusparseCreateCsrilu02Info()
cusparseStatus_t
cusparseCreateCsrilu02Info(csrilu02Info_t *info);
This function creates and initializes the solve and analysis structure of incomplete LU to
default values.
Input
info the pointer to the solve and analysis structure of
incomplete LU.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.30. cusparseDestroyCsrilu02Info()
cusparseStatus_t
cusparseDestroyCsrilu02Info(csrilu02Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (csrilu02_solve) and analysis
(csrilu02_analysis) structure.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 32
cuSPARSE Helper Function Reference
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.31. cusparseCreateBsrsv2Info()
cusparseStatus_t
cusparseCreateBsrsv2Info(bsrsv2Info_t *info);
This function creates and initializes the solve and analysis structure of bsrsv2 to default
values.
Input
info the pointer to the solve and analysis structure of
bsrsv2.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.32. cusparseDestroyBsrsv2Info()
cusparseStatus_t
cusparseDestroyBsrsv2Info(bsrsv2Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (bsrsv2_solve) and analysis
(bsrsv2_analysis) structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.33. cusparseCreateBsrsm2Info()
cusparseStatus_t
cusparseCreateBsrsm2Info(bsrsm2Info_t *info);
This function creates and initializes the solve and analysis structure of bsrsm2 to default
values.
Input
info the pointer to the solve and analysis structure of
bsrsm2.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 33
cuSPARSE Helper Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.34. cusparseDestroyBsrsm2Info()
cusparseStatus_t
cusparseDestroyBsrsm2Info(bsrsm2Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (bsrsm2_solve) and analysis
(bsrsm2_analysis) structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.35. cusparseCreateBsric02Info()
cusparseStatus_t
cusparseCreateBsric02Info(bsric02Info_t *info);
This function creates and initializes the solve and analysis structure of block incomplete
Cholesky to default values.
Input
info the pointer to the solve and analysis structure of
block incomplete Cholesky.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.36. cusparseDestroyBsric02Info()
cusparseStatus_t
cusparseDestroyBsric02Info(bsric02Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (bsric02_solve) and analysis
(bsric02_analysis) structure.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 34
cuSPARSE Helper Function Reference
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.37. cusparseCreateBsrilu02Info()
cusparseStatus_t
cusparseCreateBsrilu02Info(bsrilu02Info_t *info);
This function creates and initializes the solve and analysis structure of block incomplete
LU to default values.
Input
info the pointer to the solve and analysis structure of
block incomplete LU.
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.38. cusparseDestroyBsrilu02Info()
cusparseStatus_t
cusparseDestroyBsrilu02Info(bsrilu02Info_t info);
This function destroys and releases any memory required by the structure.
Input
info the solve (bsrilu02_solve) and analysis
(bsrilu02_analysis) structure.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
5.39. cusparseCreateCsrgemm2Info()
cusparseStatus_t
cusparseCreateCsrgemm2Info(csrgemm2Info_t *info);
This function creates and initializes analysis structure of general sparse matrix-matrix
multiplication.
Input
info the pointer to the analysis structure of general
sparse matrix-matrix multiplication.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 35
cuSPARSE Helper Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the structure was initialized successfully.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
5.40. cusparseDestroyCsrgemm2Info()
cusparseStatus_t
cusparseDestroyCsrgemm2Info(csrgemm2Info_t info);
This function destroys and releases any memory required by the structure.
Input
info opaque structure of csrgemm2.
Status Returened
CUSPARSE_STATUS_SUCCESS the resources were released successfully.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 36
Chapter 6.
CUSPARSE LEVEL 1 FUNCTION REFERENCE
This chapter describes sparse linear algebra functions that perform operations between
dense and sparse vectors.
6.1. cusparse<t>axpyi()
cusparseStatus_t
cusparseSaxpyi(cusparseHandle_t handle, int nnz,
const float *alpha,
const float *xVal, const int *xInd,
float *y, cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDaxpyi(cusparseHandle_t handle, int nnz,
const double *alpha,
const double *xVal, const int *xInd,
double *y, cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseCaxpyi(cusparseHandle_t handle, int nnz,
const cuComplex *alpha,
const cuComplex *xVal, const int *xInd,
cuComplex *y, cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseZaxpyi(cusparseHandle_t handle, int nnz,
const cuDoubleComplex *alpha,
const cuDoubleComplex *xVal, const int *xInd,
cuDoubleComplex *y, cusparseIndexBase_t idxBase)
This function multiplies the vector x in sparse format by the constant and adds the
result to the vector y in dense format. This operation can be written as
In other words,
for i=0 to nnz-1
y[xInd[i]-idxBase] = y[xInd[i]-idxBase] + alpha*xVal[i]
This function requires no extra storage. It is executed asynchronously with respect to the
host, and it may return control to the application on the host before the result is ready.
Input
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 37
cuSPARSE Level 1 Function Reference
Output
y <type> updated vector in dense format (that is
unchanged if nnz == 0).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the idxBase is neither
CUSPARSE_INDEX_BASE_ZERO nor
CUSPARSE_INDEX_BASE_ONE.
6.2. cusparse<t>doti()
cusparseStatus_t
cusparseSdoti(cusparseHandle_t handle, int nnz,
const float *xVal,
const int *xInd, const float *y,
float *resultDevHostPtr,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDdoti(cusparseHandle_t handle, int nnz,
const double *xVal,
const int *xInd, const double *y,
double *resultDevHostPtr,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseCdoti(cusparseHandle_t handle, int nnz,
const cuComplex *xVal,
const int *xInd, const cuComplex *y,
cuComplex *resultDevHostPtr,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseZdoti(cusparseHandle_t handle, int nnz, const
cuDoubleComplex *xVal,
const int *xInd, const cuDoubleComplex *y,
cuDoubleComplex *resultDevHostPtr,
cusparseIndexBase_t idxBase)
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 38
cuSPARSE Level 1 Function Reference
This function returns the dot product of a vector x in sparse format and vector y in dense
format. This operation can be written as
In other words,
for i=0 to nnz-1
resultDevHostPtr += xVal[i]*y[xInd[i-idxBase]]
This function requires some temporary extra storage that is allocated internally. It
is executed asynchronously with respect to the host and may return control to the
application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
nnz number of elements in vector x.
xVal <type> vector with nnz nonzero values of vector x.
xInd integer vector with nnz indices of the nonzero
values of vector x.
y <type> vector in dense format.
resultDevHostPtr pointer to the location of the result in the device
or host memory.
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
resultDevHostPtr scalar result in the device or host memory (that is
zero if nnz == 0).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the reduction buffer could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE the idxBase is neither
CUSPARSE_INDEX_BASE_ZERO nor
CUSPARSE_INDEX_BASE_ONE.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 39
cuSPARSE Level 1 Function Reference
6.3. cusparse<t>dotci()
cusparseStatus_t
cusparseCdotci(cusparseHandle_t handle, int nnz,
const cuComplex *xVal,
const int *xInd, const cuComplex *y,
cuComplex *resultDevHostPtr, cusparseIndexBase_t
idxBase)
cusparseStatus_t
cusparseZdotci(cusparseHandle_t handle, int nnz,
const cuDoubleComplex *xVal,
const int *xInd, const cuDoubleComplex *y,
cuDoubleComplex *resultDevHostPtr, cusparseIndexBase_t
idxBase)
This function returns the dot product of a complex conjugate of vector x in sparse format
and vector y in dense format. This operation can be written as
In other words,
for i=0 to nnz-1
resultDevHostPtr += *y[xInd[i-idxBase]]
This function requires some temporary extra storage that is allocated internally. It
is executed asynchronously with respect to the host and may return control to the
application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
nnz number of elements in vector x.
xVal <type> vector with nnz nonzero values of vector x.
xInd integer vector with nnz indices of the nonzero
values of vector x.
y <type> vector in dense format.
resultDevHostPtr pointer to the location of the result in the device
or host memory.
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
resultDevHostPtr scalar result in the device or host memory (that is
zero if nnz == 0).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the reduction buffer could not be allocated.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 40
cuSPARSE Level 1 Function Reference
6.4. cusparse<t>gthr()
cusparseStatus_t
cusparseSgthr(cusparseHandle_t handle, int nnz,
const float *y,
float *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDgthr(cusparseHandle_t handle, int nnz,
const double *y,
double *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseCgthr(cusparseHandle_t handle, int nnz,
const cuComplex *y,
cuComplex *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseZgthr(cusparseHandle_t handle, int nnz,
const cuDoubleComplex *y,
cuDoubleComplex *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
This function gathers the elements of the vector y listed in the index array xInd into the
data array xVal.
This function requires no extra storage. It is executed asynchronously with respect to the
host and it may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
nnz number of elements in vector x.
y <type> vector in dense format (of
size≥max(xInd)-idxBase+1).
Output
xVal <type> vector with nnz nonzero values that were
gathered from vector y (that is unchanged if nnz
== 0).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 41
cuSPARSE Level 1 Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the idxBase is neither
CUSPARSE_INDEX_BASE_ZERO nor
CUSPARSE_INDEX_BASE_ONE.
6.5. cusparse<t>gthrz()
cusparseStatus_t
cusparseSgthrz(cusparseHandle_t handle, int nnz, float *y,
float *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDgthrz(cusparseHandle_t handle, int nnz, double *y,
double *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseCgthrz(cusparseHandle_t handle, int nnz, cuComplex *y,
cuComplex *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseZgthrz(cusparseHandle_t handle, int nnz, cuDoubleComplex *y,
cuDoubleComplex *xVal, const int *xInd,
cusparseIndexBase_t idxBase)
This function gathers the elements of the vector y listed in the index array xInd into the
data array xVal. Also, it zeros out the gathered elements in the vector y.
This function requires no extra storage. It is executed asynchronously with respect to the
host, and it may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
nnz number of elements in vector x.
y <type> vector in dense format (of
size≥max(xInd)-idxBase+1).
Output
xVal <type> vector with nnz nonzero values that were
gathered from vector y (that is unchanged if nnz
== 0).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 42
cuSPARSE Level 1 Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the idxBase is neither
CUSPARSE_INDEX_BASE_ZERO nor
CUSPARSE_INDEX_BASE_ONE.
6.6. cusparse<t>roti()
cusparseStatus_t
cusparseSroti(cusparseHandle_t handle, int nnz, float *xVal,
const int *xInd,
float *y, const float *c, const float *s,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDroti(cusparseHandle_t handle, int nnz, double *xVal,
const int *xInd,
double *y, const double *c, const double *s,
cusparseIndexBase_t idxBase)
Input
handle handle to the cuSPARSE library context.
nnz number of elements in vector x.
xVal <type> vector with nnz nonzero values of vector x.
xInd integer vector with nnz indices of the nonzero
values of vector x.
y <type> vector in dense format.
c cosine element of the rotation matrix.
s sine element of the rotation matrix.
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 43
cuSPARSE Level 1 Function Reference
Output
xVal <type> updated vector in sparse format (that is
unchanged if nnz == 0).
y <type> updated vector in dense format (that is
unchanged if nnz == 0).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the idxBase is neither
CUSPARSE_INDEX_BASE_ZERO nor
CUSPARSE_INDEX_BASE_ONE.
6.7. cusparse<t>sctr()
cusparseStatus_t
cusparseSsctr(cusparseHandle_t handle, int nnz,
const float *xVal,
const int *xInd, float *y,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDsctr(cusparseHandle_t handle, int nnz,
const double *xVal,
const int *xInd, double *y,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseCsctr(cusparseHandle_t handle, int nnz,
const cuComplex *xVal,
const int *xInd, cuComplex *y,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseZsctr(cusparseHandle_t handle, int nnz,
const cuDoubleComplex *xVal,
const int *xInd, cuDoubleComplex *y,
cusparseIndexBase_t idxBase)
This function scatters the elements of the vector x in sparse format into the vector y in
dense format. It modifies only the elements of y whose indices are listed in the array
xInd.
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
nnz number of elements in vector x.
xVal <type> vector with nnz nonzero values of vector x.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 44
cuSPARSE Level 1 Function Reference
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
y <type> vector with nnz nonzero values that were
scattered from vector x (that is unchanged if nnz
== 0).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the idxBase is neither
CUSPARSE_INDEX_BASE_ZERO nor
CUSPARSE_INDEX_BASE_ONE..
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 45
Chapter 7.
CUSPARSE LEVEL 2 FUNCTION REFERENCE
This chapter describes the sparse linear algebra functions that perform operations
between sparse matrices and dense vectors.
In particular, the solution of sparse triangular linear systems is implemented in two
phases. First, during the analysis phase, the sparse triangular matrix is analyzed
to determine the dependencies between its elements by calling the appropriate
csrsv_analysis() function. The analysis is specific to the sparsity pattern of the given
matrix and to the selected cusparseOperation_t type. The information from the
analysis phase is stored in the parameter of type cusparseSolveAnalysisInfo_t that
has been initialized previously with a call to cusparseCreateSolveAnalysisInfo().
Second, during the solve phase, the given sparse triangular linear system is solved using
the information stored in the cusparseSolveAnalysisInfo_t parameter by calling
the appropriate csrsv_solve() function. The solve phase may be performed multiple
times with different right-hand sides, while the analysis phase needs to be performed
only once. This is especially useful when a sparse triangular linear system must be
solved for a set of different right-hand sides one at a time, while its coefficient matrix
remains the same.
Finally, once all the solves have completed, the opaque data structure pointed to
by the cusparseSolveAnalysisInfo_t parameter can be released by calling
cusparseDestroySolveAnalysisInfo(). For more information please refer to [3].
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 46
cuSPARSE Level 2 Function Reference
7.1. cusparse<t>bsrmv()
cusparseStatus_t
cusparseSbsrmv(cusparseHandle_t handle, cusparseDirection_t dir,
cusparseOperation_t trans, int mb, int nb, int nnzb,
const float *alpha, const cusparseMatDescr_t descr,
const float *bsrVal, const int *bsrRowPtr, const int *bsrColInd,
int blockDim, const float *x,
const float *beta, float *y)
cusparseStatus_t
cusparseDbsrmv(cusparseHandle_t handle, cusparseDirection_t dir,
cusparseOperation_t trans, int mb, int nb, int nnzb,
const double *alpha, const cusparseMatDescr_t descr,
const double *bsrVal, const int *bsrRowPtr, const int *bsrColInd,
int blockDim, const double *x,
const double *beta, double *y)
cusparseStatus_t
cusparseCbsrmv(cusparseHandle_t handle, cusparseDirection_t dir,
cusparseOperation_t trans, int mb, int nb, int nnzb,
const cuComplex *alpha, const cusparseMatDescr_t descr,
const cuComplex *bsrVal, const int *bsrRowPtr, const int *bsrColInd,
int blockDim, const cuComplex *x,
const cuComplex *beta, cuComplex *y)
cusparseStatus_t
cusparseZbsrmv(cusparseHandle_t handle, cusparseDirection_t dir,
cusparseOperation_t trans, int mb, int nb, int nnzb,
const cuDoubleComplex *alpha, const cusparseMatDescr_t descr,
const cuDoubleComplex *bsrVal, const int *bsrRowPtr, const int
*bsrColInd,
int blockDim, const cuDoubleComplex *x,
const cuDoubleComplex *beta, cuDoubleComplex *y)
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 47
cuSPARSE Level 2 Function Reference
For example, suppose the user has a CSR format and wants to try bsrmv(), the
following code demonstrates how to use csr2bsr() conversion and bsrmv()
multiplication in single precision.
// Suppose that A is m x n sparse matrix represented by CSR format,
// hx is a host vector of size n, and hy is also a host vector of size m.
// m and n are not multiple of blockDim.
// step 1: transform CSR to BSR with column-major order
int base, nnz;
int nnzb;
cusparseDirection_t dirA = CUSPARSE_DIRECTION_COLUMN;
int mb = (m + blockDim-1)/blockDim;
int nb = (n + blockDim-1)/blockDim;
cudaMalloc((void**)&bsrRowPtrC, sizeof(int) *(mb+1));
cusparseXcsr2bsrNnz(handle, dirA, m, n,
descrA, csrRowPtrA, csrColIndA, blockDim,
descrC, bsrRowPtrC, &nnzb);
cudaMalloc((void**)&bsrColIndC, sizeof(int)*nnzb);
cudaMalloc((void**)&bsrValC, sizeof(float)*(blockDim*blockDim)*nnzb);
cusparseScsr2bsr(handle, dirA, m, n,
descrA, csrValA, csrRowPtrA, csrColIndA, blockDim,
descrC, bsrValC, bsrRowPtrC, bsrColIndC);
// step 2: allocate vector x and vector y large enough for bsrmv
cudaMalloc((void**)&x, sizeof(float)*(nb*blockDim));
cudaMalloc((void**)&y, sizeof(float)*(mb*blockDim));
cudaMemcpy(x, hx, sizeof(float)*n, cudaMemcpyHostToDevice);
cudaMemcpy(y, hy, sizeof(float)*m, cudaMemcpyHostToDevice);
// step 3: perform bsrmv
cusparseSbsrmv(handle, dirA, transA, mb, nb, nnzb, &alpha,
descrC, bsrValC, bsrRowPtrC, bsrColIndC, blockDim, x, &beta, y);
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 48
cuSPARSE Level 2 Function Reference
Output
y <type> updated vector.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were
passed (m,n,nnz<0, trans !=
CUSPARSE_OPERATION_NON_TRANSPOSE,
, dir is not row-major or column-
major, or IndexBase of descr is not base-0 or
base-1 ).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 49
cuSPARSE Level 2 Function Reference
7.2. cusparse<t>bsrxmv()
cusparseStatus_t
cusparseSbsrxmv(cusparseHandle_t handle,
cusparseDirection_t dir,
cusparseOperation_t trans,
int sizeOfMask,
int mb,
int nb,
int nnzb,
const float *alpha,
const cusparseMatDescr_t descr,
const float *bsrVal,
const int *bsrMaskPtr,
const int *bsrRowPtr,
const int *bsrEndPtr,
const int *bsrColInd,
int blockDim,
const float *x,
const float *beta,
float *y)
cusparseStatus_t
cusparseDbsrxmv(cusparseHandle_t handle,
cusparseDirection_t dir,
cusparseOperation_t trans,
int sizeOfMask,
int mb,
int nb,
int nnzb,
const double *alpha,
const cusparseMatDescr_t descr,
const double *bsrVal,
const int *bsrMaskPtr,
const int *bsrRowPtr,
const int *bsrEndPtr,
const int *bsrColInd,
int blockDim,
const double *x,
const double *beta,
double *y)
cusparseStatus_t
cusparseCbsrxmv(cusparseHandle_t handle,
cusparseDirection_t dir,
cusparseOperation_t trans,
int sizeOfMask,
int mb,
int nb,
int nnzb,
const cuComplex *alpha,
const cusparseMatDescr_t descr,
const cuComplex *bsrVal,
const int *bsrMaskPtr,
const int *bsrRowPtr,
const int *bsrEndPtr,
const int *bsrColInd,
int blockDim,
const cuComplex *x,
const cuComplex *beta,
cuComplex *y)
cusparseStatus_t
cusparseZbsrxmv(cusparseHandle_t handle,
www.nvidia.com cusparseDirection_t dir,
cuSPARSE Library cusparseOperation_t trans, DU-06709-001_v8.0 | 50
int sizeOfMask,
cuSPARSE Level 2 Function Reference
The mask operation is defined by array bsrMaskPtr which contains updated block row
indices of . If row is not specified in bsrMaskPtr, then bsrxmv() does not touch row
block of and .
For example, consider the block matrix :
We don’t need to create another BSR format for the new matrix , all that we should
do is to keep bsrVal and bsrColInd unchanged, but modify bsrRowPtr and add an
additional array bsrEndPtr which points to the last nonzero elements per row of plus
1.
For example, the following bsrRowPtr and bsrEndPtr can represent matrix :
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 51
cuSPARSE Level 2 Function Reference
If a block row is not present in the bsrMaskPtr, then no calculation is performed on that
row, and the corresponding value in y is unmodified. The question mark "?" is used to
inidcate row blocks not in bsrMaskPtr.
In this case, first row block is not present in bsrMaskPtr, so bsrRowPtr[0] and
bsrEndPtr[0] are not touched also.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 52
cuSPARSE Level 2 Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were
passed (m,n,nnz<0, trans !=
CUSPARSE_OPERATION_NON_TRANSPOSE,
, dir is not row-major or column-
major, or IndexBase of descr is not base-0 or
base-1 ).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 53
cuSPARSE Level 2 Function Reference
7.3. cusparse<t>csrmv()
cusparseStatus_t
cusparseScsrmv(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz, const float *alpha,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const float *x, const float *beta,
float *y)
cusparseStatus_t
cusparseDcsrmv(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz, const double *alpha,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const double *x, const double *beta,
double *y)
cusparseStatus_t
cusparseCcsrmv(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz, const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const cuComplex *x, const cuComplex *beta,
cuComplex *y)
cusparseStatus_t
cusparseZcsrmv(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz, const cuDoubleComplex *alpha,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const cuDoubleComplex *x, const cuDoubleComplex *beta,
cuDoubleComplex *y)
A is an m×n sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); x and y are vectors; are scalars; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 54
cuSPARSE Level 2 Function Reference
1. Convert the matrix from CSR to CSC format using one of the csr2csc() functions.
Notice that by interchanging the rows and columns of the result you are implicitly
transposing the matrix.
2. Call the csrmv() function with the cusparseOperation_t parameter set to
CUSPARSE_OPERATION_NON_TRANSPOSE and with the interchanged rows and columns
of the matrix stored in CSC format. This (implicitly) multiplies the vector by the
transpose of the matrix in the original CSR format.
This function requires no extra storage for the general matrices when operation
CUSPARSE_OPERATION_NON_TRANSPOSE is selected. It requires some extra storage for
Hermitian/symmetric matrices and for the general matrices when an operation different
than CUSPARSE_OPERATION_NON_TRANSPOSE is selected. It is executed asynchronously
with respect to the host and may return control to the application on the host before the
result is ready.
Input
handle handle to the cuSPARSE library context.
trans the operation .
m number of rows of matrix A.
n number of columns of matrix A.
nnz number of nonzero elements of matrix A.
alpha <type> scalar used for multiplication.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL,
CUSPARSE_MATRIX_TYPE_SYMMETRIC,
and CUSPARSE_MATRIX_TYPE_HERMITIAN.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
y <type> updated vector.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 55
cuSPARSE Level 2 Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision
(compute capability (c.c.) >= 1.3 required),
symmetric/Hermitian matrix (c.c. >= 1.2
required), or transpose operation (c.c. >= 1.1
required).
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
7.4. cusparseCsrmvEx()
cusparseStatus_t
cusparseCsrmvEx(cusparseHandle_t handle,
cusparseAlgMode_t alg,
cusparseOperation_t transA,
int m, int n, int nnz,
const void *alpha, cudaDataType alphatype,
const cusparseMatDescr_t descrA,
const void *csrValA, cudaDataType csrValAtype,
const int *csrRowPtrA,
const int *csrColIndA,
const void *x, cudaDataType xtype,
const void *beta, cudaDataType betatype,
void *y, cudaDataType ytype,
cudaDataType executiontype,
void* buffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 56
cuSPARSE Level 2 Function Reference
7.5. cusparseCsrmvEx_bufferSize()
cusparseCsrmvEx_bufferSize(cusparseHandle_t handle,
cusparseAlgMode_t alg,
cusparseOperation_t
transA,
int m, int n, int nnz,
const void *alpha,
cudaDataType alphatype,
const
cusparseMatDescr_t descrA,
const void *csrValA,
cudaDataType csrValAtype,
const int *csrRowPtrA,
const int *csrColIndA,
const void *x,
cudaDataType xtype,
const void *beta,
cudaDataType betatype,
void *y, cudaDataType
ytype,
cudaDataType
executiontype,
size_t
*bufferSizeInBytes);
This function returns the size of the workspace needed by cusparseCsrmvEx. User
needs to allocate a buffer of this size and give that buffer to cusparseCsrmvEx as an
argument. All the arguments are similar to cusparseCsrmvEx except the following
output argument.
Output specifically required by cusparseCsrmvEx_bufferSize
bufferSizeInBytes Pointer to a size_t variable, which will be
assigned with the size of workspace needed by
cusparseCsrmv. Since workspace is not currently
used by cusparseCsrmv, this function returns the
number 16 as an arbitrary number.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 57
cuSPARSE Level 2 Function Reference
7.6. cusparse<t>csrmv_mp()
cusparseStatus_t
cusparseScsrmv_mp(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz,
const float *alpha,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const float *x, const float *beta,
float *y)
cusparseStatus_t
cusparseDcsrmv_mp(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz,
const double *alpha,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const double *x, const double *beta,
double *y)
cusparseStatus_t
cusparseCcsrmv_mp(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const cuComplex *x, const cuComplex *beta,
cuComplex *y)
cusparseStatus_t
cusparseZcsrmv_mp(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, int nnz,
const cuDoubleComplex *alpha,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const cuDoubleComplex *x, const cuDoubleComplex *beta,
cuDoubleComplex *y)
A is an m×n sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); x and y are vectors; are scalars; and
This routine was introduced specifically to address some of the loss of performance in
the regular csrmv() code due to irregular sparsity patterns and transpose operations. The
core kernels are based on the "MergePath" approach created by Duanne Merril. By using
this approach, we are able to provide performance independent of a sparsity pattern,
transpose or non-transpose, across data types.
Input
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 58
cuSPARSE Level 2 Function Reference
Output
y <type> updated vector.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision
(compute capability (c.c.) >= 1.3 required),
symmetric/Hermitian matrix (c.c. >= 1.2
required), or transpose operation (c.c. >= 1.1
required).
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 59
cuSPARSE Level 2 Function Reference
7.7. cusparse<t>gemvi()
cusparseStatus_t
cusparseSgemvi(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, const float *alpha,
const float *A,
int lda, int nnz,
const float *x,
const int *xInd,
const float *beta,
float *y,
cusparseIndexBase_t idxBase,
void *pBuffer)
cusparseStatus_t
cusparseDgemvi(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, const double *alpha,
const double *A,
int lda, int nnz,
const double *x,
const int *xInd,
const double *beta,
double *y,
cusparseIndexBase_t idxBase,
void *pBuffer)
cusparseStatus_t
cusparseCgemvi(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, const cuComplex *alpha,
const cuComplex *A,
int lda, int nnz,
const cuComplex *x,
const int *xInd,
const cuComplex *beta,
cuComplex *y,
cusparseIndexBase_t idxBase,
void *pBuffer)
cusparseStatus_t
cusparseZgemvi(cusparseHandle_t handle, cusparseOperation_t transA,
int m, int n, const cuDoubleComplex *alpha,
const cuDoubleComplex *A,
int lda, int nnz,
const cuDoubleComplex *x,
const int *xInd,
const cuDoubleComplex *beta,
cuDoubleComplex *y,
cusparseIndexBase_t idxBase,
void *pBuffer)
A is an m×n dense matrix and a sparse vector x that is defined in a sparse storage format
by the two arrays xVal, xInd of length nnz, and y is a dense vector; are scalars;
and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 60
cuSPARSE Level 2 Function Reference
To simplify the implementation, we have not (yet) optimized the transpose multiple
case. We recommend the following for users interested in this case.
1. Convert the matrix from CSR to CSC format using one of the csr2csc() functions.
Notice that by interchanging the rows and columns of the result you are implicitly
transposing the matrix.
2. Call the gemvi() function with the cusparseOperation_t parameter set to
CUSPARSE_OPERATION_NON_TRANSPOSE and with the interchanged rows and columns
of the matrix stored in CSC format. This (implicitly) multiplies the vector by the
transpose of the matrix in the original CSR format.
This function requires no extra storage for the general matrices when operation
CUSPARSE_OPERATION_NON_TRANSPOSE is selected. It requires some extra storage for
Hermitian/symmetric matrices and for the general matrices when an operation different
than CUSPARSE_OPERATION_NON_TRANSPOSE is selected. It is executed asynchronously
with respect to the host and may return control to the application on the host before the
result is ready.
Input
handle handle to the cuSPARSE library context.
trans the operation .
m number of rows of matrix A.
n number of columns of matrix A.
alpha <type> scalar used for multiplication.
A the pointer to dense matrix A.
lda size of the leading dimension of A.
nnz number of nonzero elements of vector x.
x <type> sparse vector of nnz elements of size n if
, and size m if or
xInd Indices of non-zero values in x
beta <type> scalar used for multiplication. If beta is
zero, y does not have to be a valid input.
y <type> dense vector of m elements if ,
and n elements if or
idxBase 0 or 1, for 0 based or 1 based indexing,
respectively
pBuffer working space buffer, of size given by
Xgemvi_getBufferSize()
Output
y <type> updated dense vector.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 61
cuSPARSE Level 2 Function Reference
7.8. cusparse<t>gemvi_bufferSize()
cusparseStatus_t
cusparseSgemvi_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int nnz,
int *pBufferSize)
cusparseStatus_t
cusparseDgemvi_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int nnz,
int *pBufferSize)
cusparseStatus_t
cusparseCgemvi_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int nnz,
int *pBufferSize)
cusparseStatus_t
cusparseZgemvi_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int nnz,
int *pBufferSize)
Input
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 62
cuSPARSE Level 2 Function Reference
Output
pBufferSize number of elements needed the buffer used in
gemvi().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n, nnz<=0)
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 63
cuSPARSE Level 2 Function Reference
7.9. cusparse<t>bsrsv2_bufferSize()
cusparseStatus_t
cusparseSbsrsv2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseDbsrsv2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseCbsrsv2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseZbsrsv2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
int *pBufferSizeInBytes);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 64
cuSPARSE Level 2 Function Reference
This function returns size of the buffer used in bsrsv2, a new sparse triangular linear
system op(A)*y = x.
A is an (mb*blockDim)x(mb*blockDim) sparse matrix that is defined in BSR storage
format by the three arrays bsrValA, bsrRowPtrA, and bsrColIndA); x and y are the
right-hand-side and the solution vectors; is a scalar; and
Although there are six combinations in terms of parameter trans and the upper (lower)
triangular part of A, bsrsv2_bufferSize() returns the maximum size buffer among
these combinations. The buffer size depends on the dimensions mb, blockDim, and
the number of nonzero blocks of the matrix nnzb. If the user changes the matrix, it is
necessary to call bsrsv2_bufferSize() again to have the correct buffer size; otherwise
a segmentation fault may occur.
Input
handle handle to the cuSPARSE library context.
dirA storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
info record of internal states based on different
algorithms.
pBufferSizeInBytes number of bytes of the buffer used in the
bsrsv2_analysis() and bsrsv2_solve().
Status Returned
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 65
cuSPARSE Level 2 Function Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 66
cuSPARSE Level 2 Function Reference
7.10. cusparse<t>bsrsv2_analysis()
cusparseStatus_t
cusparseSbsrsv2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDbsrsv2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCbsrsv2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZbsrsv2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 67
cuSPARSE Level 2 Function Reference
This function performs the analysis phase of bsrsv2, a new sparse triangular linear
system op(A)*y = x.
A is an (mb*blockDim)x(mb*blockDim) sparse matrix that is defined in BSR storage
format by the three arrays bsrValA, bsrRowPtrA, and bsrColIndA); x and y are the
right-hand side and the solution vectors; is a scalar; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 68
cuSPARSE Level 2 Function Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0).
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 69
cuSPARSE Level 2 Function Reference
7.11. cusparse<t>bsrsv2_solve()
cusparseStatus_t
cusparseSbsrsv2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const float *alpha,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
const float *x,
float *y,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDbsrsv2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const double *alpha,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
const double *x,
double *y,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCbsrsv2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
int nnzb,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsv2Info_t info,
const cuComplex *x,
cuComplex *y,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZbsrsv2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
int mb,
www.nvidia.com int nnzb,
cuSPARSE Library const cuDoubleComplex *alpha, DU-06709-001_v8.0 | 70
const cusparseMatDescr_t descrA,
cuSPARSE Level 2 Function Reference
This function performs the solve phase of bsrsv2, a new sparse triangular linear system
op(A)*y = x.
A is an (mb*blockDim)x(mb*blockDim) sparse matrix that is defined in BSR storage
format by the three arrays bsrValA, bsrRowPtrA, and bsrColIndA); x and y are the
right-hand-side and the solution vectors; is a scalar; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 71
cuSPARSE Level 2 Function Reference
For example, suppose L is a lower triangular matrix with unit diagonal, then the
following code solves L*y=x by level information.
// step 3: query how much memory used in bsrsv2, and allocate the buffer
cusparseDbsrsv2_bufferSize(handle, dir, trans, mb, nnzb, descr,
d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, &pBufferSize);
Input
handle handle to the cuSPARSE library context.
dirA storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
y <type> solution vector of size m.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0).
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_MAPPING_ERROR the texture binding failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 73
cuSPARSE Level 2 Function Reference
7.12. cusparseXbsrsv2_zeroPivot()
cusparseStatus_t
cusparseXbsrsv2_zeroPivot(cusparseHandle_t handle,
bsrsv2Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1;
otherwise if A(j,j) is missing or U(j,j) is zero,
position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 74
cuSPARSE Level 2 Function Reference
7.13. cusparse<t>csrsv_analysis()
cusparseStatus_t
cusparseScsrsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseDcsrsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseCcsrsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseZcsrsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
This function performs the analysis phase of the solution of a sparse triangular linear
system
where A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); x and y are the right-hand-side and the
solution vectors; is a scalar; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 75
cuSPARSE Level 2 Function Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 76
cuSPARSE Level 2 Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
7.14. cusparseCsrsv_analysisEx()
cusparseStatus_t cusparseCsrsv_analysisEx(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int nnz,
const cusparseMatDescr_t
descrA,
const void *csrSortedValA,
cudaDataType csrSortedValAtype,
const int *csrSortedRowPtrA,
const int *csrSortedColIndA,
cusparseSolveAnalysisInfo_t
info,
cudaDataType executiontype);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 77
cuSPARSE Level 2 Function Reference
7.15. cusparse<t>csrsv_solve()
cusparseStatus_t cusparseScsrsv_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, const float *alpha,
const cusparseMatDescr_t descrA,
const float *csrSortedValA,
const int *csrSortedRowPtrA, const
int *csrSortedColIndA,
cusparseSolveAnalysisInfo_t info,
const float *f, float *x);
This function performs the solve phase of the solution of a sparse triangular linear
system
where A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrSortedValA, csrSortedRowPtrA, and csrSortedColIndA); f and x are the right-
hand-side and the solution vectors; is a scalar; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 78
cuSPARSE Level 2 Function Reference
This function may be executed multiple times for a given matrix and a particular
operation type.
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
trans the operation
m number of rows and columns of matrix A.
alpha <type> scalar used for multiplication.
descrA the descriptor of matrix A. The supported matrix
types are CUSPARSE_MATRIX_TYPE_TRIANGULAR
and CUSPARSE_MATRIX_TYPE_GENERAL,
while the supported diagonal types
are CUSPARSE_DIAG_TYPE_UNIT and
CUSPARSE_DIAG_TYPE_NON_UNIT.
Output
x <type> solution vector of size m.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_MAPPING_ERROR the texture binding failed.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 79
cuSPARSE Level 2 Function Reference
7.16. cusparseCsrsv_solveEx()
cusparseStatus_t cusparseCsrsv_solveEx(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
const void *alpha, cudaDataType
alphatype,
const cusparseMatDescr_t descrA,
const void *csrSortedValA,
cudaDataType csrSortedValAtype,
const int *csrSortedRowPtrA,
const int *csrSortedColIndA,
cusparseSolveAnalysisInfo_t
info,
const void *f, cudaDataType
ftype,
void *x, cudaDataType xtype,
cudaDataType executiontype);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 80
cuSPARSE Level 2 Function Reference
7.17. cusparse<t>csrsv2_bufferSize()
cusparseStatus_t
cusparseScsrsv2_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseDcsrsv2_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseCcsrsv2_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseZcsrsv2_bufferSize(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
int *pBufferSizeInBytes);
This function returns the size of the buffer used in csrsv2, a new sparse triangular
linear system op(A)*y = x.
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); x and y are the right-hand-side and the
solution vectors; is a scalar; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 81
cuSPARSE Level 2 Function Reference
Although there are six combinations in terms of the parameter trans and the upper
(lower) triangular part of A, csrsv2_bufferSize() returns the maximum size buffer
of these combinations. The buffer size depends on the dimension and the number of
nonzero elements of the matrix. If the user changes the matrix, it is necessary to call
csrsv2_bufferSize() again to have the correct buffer size; otherwise, a segmentation
fault may occur.
Input
handle handle to the cuSPARSE library context.
transA the operation .
m number of rows of matrix A.
nnz number of nonzero elements of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL,
while the supported diagonal types
are CUSPARSE_DIAG_TYPE_UNIT and
CUSPARSE_DIAG_TYPE_NON_UNIT.
Output
info record of internal states based on different
algorithms.
pBufferSizeInBytes number of bytes of the buffer used in the
csrsv2_analysis and csrsv2_solve.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0), base
index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 82
cuSPARSE Level 2 Function Reference
7.18. cusparse<t>csrsv2_analysis()
cusparseStatus_t
cusparseScsrsv2_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDcsrsv2_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCcsrsv2_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZcsrsv2_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
This function performs the analysis phase of csrsv2, a new sparse triangular linear
system op(A)*y = x.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 83
cuSPARSE Level 2 Function Reference
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); x and y are the right-hand-side and the
solution vectors; is a scalar; and
It is expected that this function will be executed only once for a given matrix and a
particular operation type.
This function requires a buffer size returned by csrsv2_bufferSize(). The address of
pBuffer must be multiple of 128 bytes. If it is not, CUSPARSE_STATUS_INVALID_VALUE
is returned.
Function csrsv2_analysis() reports a structural zero and computes level information
that is stored in opaque structure info. The level information can extract more
parallelism for a triangular solver. However csrsv2_solve() can be done without
level information. To disable level information, the user needs to specify the policy of the
triangular solver as CUSPARSE_SOLVE_POLICY_NO_LEVEL.
Function csrsv2_analysis() always reports the first structural zero, even if the
policy is CUSPARSE_SOLVE_POLICY_NO_LEVEL. No structural zero is reported if
CUSPARSE_DIAG_TYPE_UNIT is specified, even if A(j,j) is missing for some j. The
user needs to call cusparseXcsrsv2_zeroPivot() to know where the structural zero
is.
It is the user's choice whether to call csrsv2_solve() if csrsv2_analysis() reports
a structural zero. In this case, the user can still call csrsv2_solve() which will return
a numerical zero in the same position as the structural zero. However the result x is
meaningless.
Input
handle handle to the cuSPARSE library context.
transA the operation .
m number of rows of matrix A.
nnz number of nonzero elements of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL,
while the supported diagonal types
are CUSPARSE_DIAG_TYPE_UNIT and
CUSPARSE_DIAG_TYPE_NON_UNIT.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 84
cuSPARSE Level 2 Function Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0).
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 85
cuSPARSE Level 2 Function Reference
7.19. cusparse<t>csrsv2_solve()
cusparseStatus_t
cusparseScsrsv2_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const float *alpha,
const cusparseMatDescr_t descra,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
const float *x,
float *y,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDcsrsv2_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const double *alpha,
const cusparseMatDescr_t descra,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
const double *x,
double *y,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCcsrsv2_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cuComplex *alpha,
const cusparseMatDescr_t descra,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
const cuComplex *x,
cuComplex *y,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZcsrsv2_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int nnz,
const cuDoubleComplex *alpha,
const cusparseMatDescr_t descra,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrsv2Info_t info,
www.nvidia.com const cuDoubleComplex *x,
cuSPARSE Library cuDoubleComplex *y, DU-06709-001_v8.0 | 86
cusparseSolvePolicy_t policy,
cuSPARSE Level 2 Function Reference
This function performs the solve phase of csrsv2, a new sparse triangular linear system
op(A)*y = x.
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); x and y are the right-hand-side and the
solution vectors; is a scalar; and
This function may be executed multiple times for a given matrix and a particular
operation type.
This function requires the buffer size returned by csrsv2_bufferSize().
The address of pBuffer must be multiple of 128 bytes. If it is not,
CUSPARSE_STATUS_INVALID_VALUE is returned.
Although csrsv2_solve() can be done without level information, the user
still needs to be aware of consistency. If csrsv2_analysis() is called with
policy CUSPARSE_SOLVE_POLICY_USE_LEVEL, csrsv2_solve() can be run
with or without levels. On the contrary, if csrsv2_analysis() is called with
CUSPARSE_SOLVE_POLICY_NO_LEVEL, csrsv2_solve() can only accept
CUSPARSE_SOLVE_POLICY_NO_LEVEL; otherwise, CUSPARSE_STATUS_INVALID_VALUE
is returned.
The level information may not improve the performance but spend extra
time doing analysis. For example, a tridiagonal matrix has no parallelism.
In this case, CUSPARSE_SOLVE_POLICY_NO_LEVEL performs better than
CUSPARSE_SOLVE_POLICY_USE_LEVEL. If the user has an iterative solver, the best
approach is to do csrsv2_analysis() with CUSPARSE_SOLVE_POLICY_USE_LEVEL
once. Then do csrsv2_solve() with CUSPARSE_SOLVE_POLICY_NO_LEVEL in the first
run and with CUSPARSE_SOLVE_POLICY_USE_LEVEL in the second run, picking faster
one to perform the remaining iterations.
Function csrsv2_solve() reports the first numerical zero, including a structural zero.
If status is 0, no numerical zero was found. Furthermore, no numerical zero is reported
if CUSPARSE_DIAG_TYPE_UNIT is specified, even if A(j,j) is zero for some j. The user
needs to call cusparseXcsrsv2_zeroPivot() to know where the numerical zero is.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 87
cuSPARSE Level 2 Function Reference
For example, suppose L is a lower triangular matrix with unit diagonal, the following
code solves L*y=x by level information.
cusparseMatDescr_t descr = 0;
csrsv2Info_t info = 0;
int pBufferSize;
void *pBuffer = 0;
int structural_zero;
int numerical_zero;
const double alpha = 1.;
const cusparseSolvePolicy_t policy = CUSPARSE_SOLVE_POLICY_USE_LEVEL;
const cusparseOperation_t trans = CUSPARSE_OPERATION_NON_TRANSPOSE;
// step 3: query how much memory used in csrsv2, and allocate the buffer
cusparseDcsrsv2_bufferSize(handle, trans, m, nnz, descr,
d_csrVal, d_csrRowPtr, d_csrColInd, &pBufferSize);
// pBuffer returned by cudaMalloc is automatically aligned to 128 bytes.
cudaMalloc((void**)&pBuffer, pBufferSize);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 88
cuSPARSE Level 2 Function Reference
Remark: csrsv2_solve() needs more nonzeros per row to achieve good performance.
It would perform better if more than 16 nonzeros per row in average.
Input
handle handle to the cuSPARSE library context.
transA the operation .
m number of rows and columns of matrix A.
alpha <type> scalar used for multiplication.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL,
while the supported diagonal types
are CUSPARSE_DIAG_TYPE_UNIT and
CUSPARSE_DIAG_TYPE_NON_UNIT.
Output
y <type> solution vector of size m.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0).
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_MAPPING_ERROR the texture binding failed.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 89
cuSPARSE Level 2 Function Reference
7.20. cusparseXcsrsv2_zeroPivot()
cusparseStatus_t
cusparseXcsrsv2_zeroPivot(cusparseHandle_t handle,
csrsv2Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1;
otherwise, if A(j,j) is missing or U(j,j) is zero,
position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 90
cuSPARSE Level 2 Function Reference
7.21. cusparse<t>hybmv()
cusparseStatus_t
cusparseShybmv(cusparseHandle_t handle, cusparseOperation_t transA,
const float *alpha,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA, const float *x,
const float *beta, float *y)
cusparseStatus_t
cusparseDhybmv(cusparseHandle_t handle, cusparseOperation_t transA,
const double *alpha,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA, const double *x,
const double *beta, double *y)
cusparseStatus_t
cusparseChybmv(cusparseHandle_t handle, cusparseOperation_t transA,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA, const cuComplex *x,
const cuComplex *beta, cuComplex *y)
cusparseStatus_t
cusparseZhybmv(cusparseHandle_t handle, cusparseOperation_t transA,
const cuDoubleComplex *alpha,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA, const cuDoubleComplex *x,
const cuDoubleComplex *beta, cuDoubleComplex *y)
A is an m×n sparse matrix that is defined in the HYB storage format by an opaque data
structure hybA, x and y are vectors, are scalars, and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 91
cuSPARSE Level 2 Function Reference
Output
y <type> updated vector.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE the internally stored HYB format parameters are
invalid.
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
7.22. cusparse<t>hybsv_analysis()
cusparseStatus_t
cusparseShybsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseDhybsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseChybsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseZhybsv_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info)
This function performs the analysis phase of the solution of a sparse triangular linear
system
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 92
cuSPARSE Level 2 Function Reference
A is an m×m sparse matrix that is defined in HYB storage format by an opaque data
structure hybA, x and y are the right-hand-side and the solution vectors, is a scalar,
and
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE the internally stored HYB format parameters are
invalid.
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 93
cuSPARSE Level 2 Function Reference
7.23. cusparse<t>hybsv_solve()
cusparseStatus_t
cusparseShybsv_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
const float *alpha,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info,
const float *x, float *y)
cusparseStatus_t
cusparseDhybsv_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
const double *alpha,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info,
const double *x, double *y)
cusparseStatus_t
cusparseChybsv_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info,
const cuComplex *x, cuComplex *y)
cusparseStatus_t
cusparseZhybsv_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
const cuDoubleComplex *alpha,
const cusparseMatDescr_t descrA,
cusparseHybMat_t hybA,
cusparseSolveAnalysisInfo_t info,
const cuDoubleComplex *x, cuDoubleComplex *y)
This function performs the solve phase of the solution of a sparse triangular linear
system:
A is an m×m sparse matrix that is defined in HYB storage format by an opaque data
structure hybA, x and y are the right-hand-side and the solution vectors, is a scalar,
and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 94
cuSPARSE Level 2 Function Reference
Output
y <type> solution vector of size m.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the internally stored hyb format parameters are
invalid.
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_MAPPING_ERROR the texture binding failed.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 95
Chapter 8.
CUSPARSE LEVEL 3 FUNCTION REFERENCE
This chapter describes sparse linear algebra functions that perform operations between
sparse and (usually tall) dense matrices.
In particular, the solution of sparse triangular linear systems with multiple right-
hand sides is implemented in two phases. First, during the analysis phase, the sparse
triangular matrix is analyzed to determine the dependencies between its elements
by calling the appropriate csrsm_analysis() function. The analysis is specific to
the sparsity pattern of the given matrix and to the selected cusparseOperation_t
type. The information from the analysis phase is stored in the parameter of type
cusparseSolveAnalysisInfo_t that has been initialized previously with a call to
cusparseCreateSolveAnalysisInfo().
Second, during the solve phase, the given sparse triangular linear system is solved using
the information stored in the cusparseSolveAnalysisInfo_t parameter by calling
the appropriate csrsm_solve() function. The solve phase may be performed multiple
times with different multiple right-hand sides, while the analysis phase needs to be
performed only once. This is especially useful when a sparse triangular linear system
must be solved for different sets of multiple right-hand sides one at a time, while its
coefficient matrix remains the same.
Finally, once all the solves have completed, the opaque data structure pointed to
by the cusparseSolveAnalysisInfo_t parameter can be released by calling
cusparseDestroySolveAnalysisInfo(). For more information please refer to [3].
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 96
cuSPARSE Level 3 Function Reference
8.1. cusparse<t>csrmm()
cusparseStatus_t
cusparseScsrmm(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int k,
int nnz,
const float *alpha,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const float *B,
int ldb,
const float *beta,
float *C,
int ldc)
cusparseStatus_t
cusparseDcsrmm(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int k,
int nnz,
const double *alpha,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const double *B,
int ldb,
const double *beta,
double *C,
int ldc)
cusparseStatus_t
cusparseCcsrmm(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int k,
int nnz,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cuComplex *B,
int ldb,
const cuComplex *beta,
cuComplex *C,
int ldc)
cusparseStatus_t
cusparseZcsrmm(cusparseHandle_t handle,
cusparseOperation_t transA,
int m,
int n,
int k,
int nnz,
const cuDoubleComplex *alpha,
const cusparseMatDescr_t descrA,
www.nvidia.com
const cuDoubleComplex *csrValA,
const
cuSPARSE Libraryint *csrRowPtrA, DU-06709-001_v8.0 | 97
const int *csrColIndA,
cuSPARSE Level 3 Function Reference
A is an m×k sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); B and C are dense matrices; are
scalars; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 98
cuSPARSE Level 3 Function Reference
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
C <type> updated array of dimensions (ldc, n).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n, k, nnz<0
or ldb and ldc are incorrect).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 99
cuSPARSE Level 3 Function Reference
8.2. cusparse<t>csrmm2()
cusparseStatus_t
cusparseScsrmm2(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
int k,
int nnz,
const float *alpha,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const float *B,
int ldb,
const float *beta,
float *C,
int ldc)
cusparseStatus_t
cusparseDcsrmm2(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
int k,
int nnz,
const double *alpha,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const double *B,
int ldb,
const double *beta,
double *C,
int ldc)
cusparseStatus_t
cusparseCcsrmm2(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
int k,
int nnz,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cuComplex *B,
int ldb,
const cuComplex *beta,
cuComplex *C,
int ldc)
cusparseStatus_t
cusparseZcsrmm2(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
www.nvidia.com int k,
cuSPARSE Library int nnz, DU-06709-001_v8.0 | 100
const cuDoubleComplex *alpha,
cuSPARSE Level 3 Function Reference
A is an m×k sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA); B and C are dense matrices; are
scalars; and
and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 101
cuSPARSE Level 3 Function Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 102
cuSPARSE Level 3 Function Reference
Output
C <type> updated array of dimensions (ldc, n).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n, k, nnz<0
or ldb and ldc are incorrect).
CUSPARSE_STATUS_ARCH_MISMATCH if op(B)=B, the device does not support double
precision or if op(B)=transpose(B) the device is
below compute capability 2.0.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED only CUSPARSE_MATRIX_TYPE_GENERAL is
supported otherwise.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 103
cuSPARSE Level 3 Function Reference
8.3. cusparse<t>csrsm_analysis()
cusparseStatus_t
cusparseScsrsm_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int nnz,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseDcsrsm_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int nnz,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseCcsrsm_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int nnz,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseZcsrsm_analysis(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int nnz,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
This function performs the analysis phase of the solution of a sparse triangular linear
system
with multiple right-hand sides, where A is an m×m sparse matrix that is defined in CSR
storage format by the three arrays csrValA, csrRowPtrA, and csrColIndA; X and Y are
the right-hand-side and the solution dense matrices; is a scalar; and
It is expected that this function will be executed only once for a given matrix and a
particular operation type.
This function requires a significant amount of extra storage that is proportional to the
matrix size. It is executed asynchronously with respect to the host and may return
control to the application on the host before the result is ready.
Input
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 104
cuSPARSE Level 3 Function Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 105
cuSPARSE Level 3 Function Reference
8.4. cusparse<t>csrsm_solve()
cusparseStatus_t
cusparseScsrsm_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int n, const float *alpha,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info,
const float *X, int ldx,
float *Y, int ldy)
cusparseStatus_t
cusparseDcsrsm_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int n, const double *alpha,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info,
const double *X, int ldx,
double *Y, int ldy)
cusparseStatus_t
cusparseCcsrsm_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int n, const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info,
const cuComplex *X, int ldx,
cuComplex *Y, int ldy)
cusparseStatus_t
cusparseZcsrsm_solve(cusparseHandle_t handle,
cusparseOperation_t transA,
int m, int n, const cuDoubleComplex *alpha,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseSolveAnalysisInfo_t info,
const cuDoubleComplex *X, int ldx,
cuDoubleComplex *Y, int ldy)
This function performs the solve phase of the solution of a sparse triangular linear
system
with multiple right-hand sides, where A is an m×n sparse matrix that is defined in CSR
storage format by the three arrays csrValA, csrRowPtrA, and csrColIndA); X and Y
are the right-hand-side and the solution dense matrices; is a scalar; and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 106
cuSPARSE Level 3 Function Reference
This function may be executed multiple times for a given matrix and a particular
operation type.
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
transA the operation op(A).
m number of rows and columns of matrix A.
n number of columns of matrix X and Y.
alpha <type> scalar used for multiplication.
descrA the descriptor of matrix A. The supported matrix
types are CUSPARSE_MATRIX_TYPE_TRIANGULAR
and CUSPARSE_MATRIX_TYPE_GENERAL,
while the supported diagonal types
are CUSPARSE_DIAG_TYPE_UNIT and
CUSPARSE_DIAG_TYPE_NON_UNIT.
Output
Y <type> solution array of dimensions (ldy, n).
ldy leading dimension of Y (that is ≥ ).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_MAPPING_ERROR the texture binding failed.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 107
cuSPARSE Level 3 Function Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 108
cuSPARSE Level 3 Function Reference
8.5. cusparse<t>bsrmm()
cusparseStatus_t
cusparseSbsrmm(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transB,
int mb,
int n,
int kb,
int nnzb,
const float *alpha,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
const int blockDim,
const float *B,
const int ldb,
const float *beta,
float *C,
int ldc)
cusparseStatus_t
cusparseDbsrmm(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transB,
int mb,
int n,
int kb,
int nnzb,
const double *alpha,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
const int blockDim,
const double *B,
const int ldb,
const double *beta,
double *C,
int ldc)
cusparseStatus_t
cusparseCbsrmm(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transB,
int mb,
int n,
int kb,
int nnzb,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
const int blockDim,
const cuComplex *B,
const int ldb,
www.nvidia.com const cuComplex *beta,
cuSPARSE Library cuComplex *C, DU-06709-001_v8.0 | 109
int ldc)
cuSPARSE Level 3 Function Reference
A is an mb×kb sparse matrix that is defined in BSR storage format by the three arrays
bsrValA, bsrRowPtrA, and bsrColIndA; B and C are dense matrices; are
scalars; and
and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 110
cuSPARSE Level 3 Function Reference
// step 1: Bt := transpose(B)
const int m = mb*blockSize;
const int k = kb*blockSize;
double *Bt;
const int ldb_Bt = n; // leading dimension of Bt
cudaMalloc((void**)&Bt, sizeof(double)*ldb_Bt*k);
double one = 1.0;
double zero = 0.0;
cublasSetPointerMode(cublas_handle, CUBLAS_POINTER_MODE_HOST);
cublasDgeam(cublas_handle, CUBLAS_OP_T, CUBLAS_OP_T,
n, k, &one, B, int ldb_B, &zero, B, int ldb_B, Bt, ldb_Bt);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 111
cuSPARSE Level 3 Function Reference
Output
C <type> updated array of dimensions (ldc, n).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE Either invalid parameters were passed (mb, n,
kb, nnzb<0; or ldb and ldc are incorrect).
Either invalid or unsupported operations
were passed (op(A) is different from
CUSPARSE_OPERATION_NON_TRANSPOSE,
or op(B) is different from
CUSPARSE_OPERATION_NON_TRANSPOSE or
CUSPARSE_OPERATION_TRANSPOSE).
CUSPARSE_STATUS_ARCH_MISMATCH if device is below compute capability 2.0.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED only CUSPARSE_MATRIX_TYPE_GENERAL is
supported otherwise.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 112
cuSPARSE Level 3 Function Reference
8.6. cusparse<t>bsrsm2_bufferSize()
cusparseStatus_t
cusparseSbsrsm2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transX,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsm2Info_t info,
int *pBufferSizeInBytes)
cusparseStatus_t
cusparseDbsrsm2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transX,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsm2Info_t info,
int *pBufferSizeInBytes)
cusparseStatus_t
cusparseCbsrsm2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transX,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrsm2Info_t info,
int *pBufferSizeInBytes)
cusparseStatus_t
cusparseZbsrsm2_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transX,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
www.nvidia.com const int *bsrColIndA,
cuSPARSE Library int blockDim, DU-06709-001_v8.0 | 113
bsrsm2Info_t info,
cuSPARSE Level 3 Function Reference
This function returns size of buffer used in bsrsm2(), a new sparse triangular linear
system op(A)*Y = op(X).
A is an (mb*blockDim)x(mb*blockDim) sparse matrix that is defined in BSR storage
format by the three arrays bsrValA, bsrRowPtrA, and bsrColIndA); X and Y are the
right-hand-side and the solution matrices; is a scalar; and
Although there are six combinations in terms of parameter trans and the upper (and
lower) triangular part of A, bsrsm2_bufferSize() returns the maximum size of the
buffer among these combinations. The buffer size depends on dimension mb,blockDim
and the number of nonzeros of the matrix, nnzb. If the user changes the matrix, it is
necessary to call bsrsm2_bufferSize() again to get the correct buffer size, otherwise a
segmentation fault may occur.
Input
handle handle to the cuSPARSE library context.
dirA storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
info record internal states based on different
algorithms.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 114
cuSPARSE Level 3 Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb, n,
nnzb<=0); base index is not 0 or 1.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 115
cuSPARSE Level 3 Function Reference
8.7. cusparse<t>bsrsm2_analysis()
cusparseStatus_t
cusparseSbsrsm2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
const float *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int blockDim,
bsrsm2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer)
cusparseStatus_t
cusparseDbsrsm2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
const double *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int blockDim,
bsrsm2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer)
cusparseStatus_t
cusparseCbsrsm2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
const cusparseMatDescr_t descrA,
const cuComplex *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int blockDim,
bsrsm2Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer)
cusparseStatus_t
cusparseZbsrsm2_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
www.nvidia.com const cusparseMatDescr_t descrA,
cuSPARSE Library const cuDoubleComplex *bsrVal, DU-06709-001_v8.0 | 116
const int *bsrRowPtr,
cuSPARSE Level 3 Function Reference
This function performs the analysis phase of bsrsm2(), a new sparse triangular linear
system op(A)*op(Y) = op(X).
A is an (mb*blockDim)x(mb*blockDim) sparse matrix that is defined in BSR storage
format by the three arrays bsrValA, bsrRowPtrA, and bsrColIndA); X and Y are the
right-hand-side and the solution matrices; is a scalar; and
and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 117
cuSPARSE Level 3 Function Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE Either invalid parameters were passed (mb, n,
nnzb<=0).
Either invalid or unsupported operations were
passed (op(X) and op(Y) are different from
CUSPARSE_OPERATION_NON_TRANSPOSE or
CUSPARSE_OPERATION_TRANSPOSE).
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 118
cuSPARSE Level 3 Function Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 119
cuSPARSE Level 3 Function Reference
8.8. cusparse<t>bsrsm2_solve()
cusparseStatus_t
cusparseSbsrsm2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
const float *alpha,
const cusparseMatDescr_t descrA,
const float *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int blockDim,
bsrsm2Info_t info,
const float *X,
int ldx,
float *Y,
int ldy,
cusparseSolvePolicy_t policy,
void *pBuffer)
cusparseStatus_t
cusparseDbsrsm2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
const double *alpha,
const cusparseMatDescr_t descrA,
const double *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int blockDim,
bsrsm2Info_t info,
const double *X,
int ldx,
double *Y,
int ldy,
cusparseSolvePolicy_t policy,
void *pBuffer)
cusparseStatus_t
cusparseCbsrsm2_solve(cusparseHandle_t handle,
cusparseDirection_t dirA,
cusparseOperation_t transA,
cusparseOperation_t transXY,
int mb,
int n,
int nnzb,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
const cuComplex *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int blockDim,
bsrsm2Info_t info,
www.nvidia.com const cuComplex *X,
cuSPARSE Library int ldx, DU-06709-001_v8.0 | 120
cuComplex *Y,
cuSPARSE Level 3 Function Reference
This function performs the solve phase of the solution of a sparse triangular linear
system:
and
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 121
cuSPARSE Level 3 Function Reference
Output
Y <type> solution array of dimensions (ldy, n).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 122
cuSPARSE Level 3 Function Reference
8.9. cusparseXbsrsm2_zeroPivot()
cusparseStatus_t
cusparseXbsrsm2_zeroPivot(cusparseHandle_t handle,
bsrsm2Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1;
otherwise, if A(j,j) is missing or U(j,j) is zero,
position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 123
Chapter 9.
CUSPARSE EXTRA FUNCTION REFERENCE
This chapter describes the extra routines used to manipulate sparse matrices.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 124
cuSPARSE Extra Function Reference
9.1. cusparse<t>csrgeam()
cusparseStatus_t
cusparseXcsrgeamNnz(cusparseHandle_t handle,
int m,
int n,
const cusparseMatDescr_t descrA,
int nnzA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
int nnzB,
const int *csrRowPtrB,
const int *csrColIndB,
const cusparseMatDescr_t descrC,
int *csrRowPtrC,
int *nnzTotalDevHostPtr)
cusparseStatus_t
cusparseScsrgeam(cusparseHandle_t handle,
int m,
int n,
const float *alpha,
const cusparseMatDescr_t descrA,
int nnzA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const float *beta,
const cusparseMatDescr_t descrB,
int nnzB,
const float *csrValB,
const int *csrRowPtrB,
const int *csrColIndB,
const cusparseMatDescr_t descrC,
float *csrValC,
int *csrRowPtrC,
int *csrColIndC)
cusparseStatus_t
cusparseDcsrgeam(cusparseHandle_t handle,
int m,
int n,
const double *alpha,
const cusparseMatDescr_t descrA,
int nnzA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const double *beta,
const cusparseMatDescr_t descrB,
int nnzB,
const double *csrValB,
const int *csrRowPtrB,
const int *csrColIndB,
const cusparseMatDescr_t descrC,
double *csrValC,
int *csrRowPtrC,
int *csrColIndC)
cusparseStatus_t
cusparseCcsrgeam(cusparseHandle_t handle,
int m,
int n,
www.nvidia.com const cuComplex *alpha,
cuSPARSE Library const cusparseMatDescr_t descrA, DU-06709-001_v8.0 | 125
int nnzA,
cuSPARSE Extra Function Reference
where A, B, and C are m×n sparse matrices (defined in CSR storage format by the three
arrays csrValA|csrValB|csrValC, csrRowPtrA|csrRowPtrB|csrRowPtrC, and
csrColIndA|csrColIndB|csrcolIndC respectively), and are scalars.
Since A and B have different sparsity patterns, cuSPARSE adopts a two-step approach
to complete sparse matrix C. In the first step, the user allocates csrRowPtrC of m
+1elements and uses function cusparseXcsrgeamNnz() to determine csrRowPtrC
and the total number of nonzero elements. In the second step, the user gathers nnzC
(number of nonzero elements of matrix C) from either (nnzC=*nnzTotalDevHostPtr)
or (nnzC=csrRowPtrC(m)-csrRowPtrC(0)) and allocates csrValC, csrColIndC of
nnzC elements respectively, then finally calls function cusparse[S|D|C|Z]csrgeam()
to complete matrix C.
The general procedure is as follows:
int baseC, nnzC;
// nnzTotalDevHostPtr points to host memory
int *nnzTotalDevHostPtr = &nnzC;
cusparseSetPointerMode(handle, CUSPARSE_POINTER_MODE_HOST);
cudaMalloc((void**)&csrRowPtrC, sizeof(int)*(m+1));
cusparseXcsrgeamNnz(handle, m, n,
descrA, nnzA, csrRowPtrA, csrColIndA,
descrB, nnzB, csrRowPtrB, csrColIndB,
descrC, csrRowPtrC, nnzTotalDevHostPtr);
if (NULL != nnzTotalDevHostPtr){
nnzC = *nnzTotalDevHostPtr;
}else{
cudaMemcpy(&nnzC, csrRowPtrC+m, sizeof(int), cudaMemcpyDeviceToHost);
cudaMemcpy(&baseC, csrRowPtrC, sizeof(int), cudaMemcpyDeviceToHost);
nnzC -= baseC;
}
cudaMalloc((void**)&csrColIndC, sizeof(int)*nnzC);
cudaMalloc((void**)&csrValC, sizeof(float)*nnzC);
cusparseScsrgeam(handle, m, n,
alpha,
descrA, nnzA,
csrValA, csrRowPtrA, csrColIndA,
beta,
descrB, nnzB,
csrValB, csrRowPtrB, csrColIndB,
descrC,
csrValC, csrRowPtrC, csrColIndC);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 126
cuSPARSE Extra Function Reference
The user can call function cusparseXcsrgeamNnz() once to set up the sparsity
pattern of C, then call function cusparse[S|D|C|Z]geam() only for each iteration.
‣ The pointers alpha and beta must be valid.
‣ When alpha or beta is zero, it is not considered a special case by cuSPARSE. The
sparsity pattern of C is independent of the value of alpha and beta. If the user
wants , then csr2csc() is better than csrgeam().
Input
handle handle to the cuSPARSE library context.
m number of rows of sparse matrix A,B,C.
n number of columns of sparse matrix A,B,C.
alpha <type> scalar used for multiplication.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL only.
nnzA number of nonzero elements of sparse matrix A.
csrValA <type> array of nnzA csrRowPtrA(m)
csrRowPtrA(0) nonzero elements of matrix A.
Output
csrValC <type> array of nnzC csrRowPtrC(m)
csrRowPtrC(0) nonzero elements of matrix C.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 127
cuSPARSE Extra Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,nnz<0,
IndexBase of descrA,descrB,descrC is not
base-0 or base-1, or alpha or beta is nil )).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 128
cuSPARSE Extra Function Reference
9.2. cusparse<t>csrgemm()
cusparseStatus_t
cusparseXcsrgemmNnz(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
int k,
const cusparseMatDescr_t descrA,
const int nnzA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
const int nnzB,
const int *csrRowPtrB,
const int *csrColIndB,
const cusparseMatDescr_t descrC,
int *csrRowPtrC,
int *nnzTotalDevHostPtr )
cusparseStatus_t
cusparseScsrgemm(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
int k,
const cusparseMatDescr_t descrA,
const int nnzA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
const int nnzB,
const float *csrValB,
const int *csrRowPtrB,
const int *csrColIndB,
const cusparseMatDescr_t descrC,
float *csrValC,
const int *csrRowPtrC,
int *csrColIndC )
cusparseStatus_t
cusparseDcsrgemm(cusparseHandle_t handle,
cusparseOperation_t transA,
cusparseOperation_t transB,
int m,
int n,
int k,
const cusparseMatDescr_t descrA,
const int nnzA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
const int nnzB,
const double *csrValB,
const int *csrRowPtrB,
const int *csrColIndB,
const cusparseMatDescr_t descrC,
double *csrValC,
const int *csrRowPtrC,
www.nvidia.com int *csrColIndC )
cusparseStatus_t
cuSPARSE Library DU-06709-001_v8.0 | 129
cusparseCcsrgemm(cusparseHandle_t handle,
cuSPARSE Extra Function Reference
where , and C are m×k, k×n, and m×n sparse matrices (defined in CSR storage
format by the three arrays csrValA|csrValB|csrValC, csrRowPtrA|csrRowPtrB|
csrRowPtrC, and csrColIndA|csrColIndB|csrcolIndC respectively. The operation
is defined by
There are four versions, NN, NT, TN, and TT. NN stands for , NT stands for
, TN stands for and TT stands for .
The cuSPARSE library adopts a two-step approach to complete sparse matrix. In
the first step, the user allocates csrRowPtrC of m+1 elements and uses the function
cusparseXcsrgemmNnz() to determine csrRowPtrC and the total number of nonzero
elements. In the second step, the user gathers nnzC (the number of nonzero elements
of matrix C) from either (nnzC=*nnzTotalDevHostPtr) or (nnzC=csrRowPtrC(m)-
csrRowPtrC(0)) and allocates csrValC and csrColIndC of nnzC elements
respectively, then finally calls function cusparse[S|D|C|Z]csrgemm() to complete
matrix C.
The general procedure is as follows:
int baseC, nnzC;
// nnzTotalDevHostPtr points to host memory
int *nnzTotalDevHostPtr = &nnzC;
cusparseSetPointerMode(handle, CUSPARSE_POINTER_MODE_HOST);
cudaMalloc((void**)&csrRowPtrC, sizeof(int)*(m+1));
cusparseXcsrgemmNnz(handle, transA, transB, m, n, k,
descrA, nnzA, csrRowPtrA, csrColIndA,
descrB, nnzB, csrRowPtrB, csrColIndB,
descrC, csrRowPtrC, nnzTotalDevHostPtr );
if (NULL != nnzTotalDevHostPtr){
nnzC = *nnzTotalDevHostPtr;
}else{
cudaMemcpy(&nnzC, csrRowPtrC+m, sizeof(int), cudaMemcpyDeviceToHost);
cudaMemcpy(&baseC, csrRowPtrC, sizeof(int), cudaMemcpyDeviceToHost);
nnzC -= baseC;
}
cudaMalloc((void**)&csrColIndC, sizeof(int)*nnzC);
cudaMalloc((void**)&csrValC, sizeof(float)*nnzC);
cusparseScsrgemm(handle, transA, transB, m, n, k,
descrA, nnzA,
csrValA, csrRowPtrA, csrColIndA,
descrB, nnzB,
csrValB, csrRowPtrB, csrColIndB,
descrC,
csrValC, csrRowPtrC, csrColIndC);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 130
cuSPARSE Extra Function Reference
Output
csrValC <type> array of nnzC csrRowPtrC(m)
csrRowPtrC(0) nonzero elements of matrix C.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 131
cuSPARSE Extra Function Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,k<0;
IndexBase of descrA,descrB,descrC is not
base-0 or base-1; or alpha or beta is nil )).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 132
cuSPARSE Extra Function Reference
9.3. cusparse<t>csrgemm2()
cusparseStatus_t
cusparseScsrgemm2_bufferSizeExt(cusparseHandle_t handle,
int m,
int n,
int k,
const float *alpha,
const cusparseMatDescr_t descrA,
int nnzA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
int nnzB,
const int *csrRowPtrB,
const int *csrColIndB,
const float *beta,
const cusparseMatDescr_t descrD,
int nnzD,
const int *csrRowPtrD,
const int *csrColIndD,
csrgemm2Info_t info,
size_t *pBufferSizeInBytes );
cusparseStatus_t
cusparseDcsrgemm2_bufferSizeExt(cusparseHandle_t handle,
int m,
int n,
int k,
const double *alpha,
const cusparseMatDescr_t descrA,
int nnzA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
int nnzB,
const int *csrRowPtrB,
const int *csrColIndB,
const double *beta,
const cusparseMatDescr_t descrD,
int nnzD,
const int *csrRowPtrD,
const int *csrColIndD,
csrgemm2Info_t info,
size_t *pBufferSizeInBytes );
cusparseStatus_t
cusparseCcsrgemm2_bufferSizeExt(cusparseHandle_t handle,
int m,
int n,
int k,
const cuComplex *alpha,
const cusparseMatDescr_t descrA,
int nnzA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrB,
int nnzB,
const int *csrRowPtrB,
const int *csrColIndB,
const cuComplex *beta,
www.nvidia.com const cusparseMatDescr_t descrD,
cuSPARSE Library int nnzD, DU-06709-001_v8.0 | 133
const int *csrRowPtrD,
cuSPARSE Extra Function Reference
where A, B, D and C are m×k, k×n, m×n and m×n sparse matrices (defined in CSR storage
format by the three arrays csrValA|csrValB|csrValD|csrValC, csrRowPtrA|
csrRowPtrB|csrRowPtrD|csrRowPtrC, and csrColIndA|csrColIndB|
csrColIndD|csrcolIndC respectively.
We provide csrgemm2 as a generalization of csrgemm. It provides more operations in
terms of alpha and beta. For example, C = -A*B+D can be done by csrgemm2.
The csrgemm2 uses alpha and beta to support the following operations:
alpha beta operation
The numerical value of alpha and beta only affects the numerical values of C, not its
sparsity pattern. For example, if alpha and beta are not zero, the sparsity pattern of C is
union of A*B and D, independent of numerical value of alpha and beta.
The following table shows different operations according to the value of m, n and k
m,n,k operation
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 134
cuSPARSE Extra Function Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 135
cuSPARSE Extra Function Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 136
cuSPARSE Extra Function Reference
Output
csrValC <type> array of nnzC nonzero elements of matrix
C.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,k<0;
IndexBase of descrA,descrB,descrD,descrC is
not base-0 or base-1 ).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 137
Chapter 10.
CUSPARSE PRECONDITIONERS REFERENCE
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 138
cuSPARSE Preconditioners Reference
10.1. cusparse<t>csric0()
cusparseStatus_t
cusparseScsric0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
float *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseDcsric0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
double *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseCcsric0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
cuComplex *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseZcsric0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
Notice that only a lower or upper Hermitian/symmetric part of the matrix A is actually
stored. It is overwritten by the lower or upper triangular factors and , respectively.
A call to this routine must be preceded by a call to the csrsv_analysis() routine.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 139
cuSPARSE Preconditioners Reference
The matrix descriptor for csrsv_analysis() and csric0() must be the same.
Otherwise, runtime error would occur.
This function requires some extra storage. It is executed asynchronously with respect to
the host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
trans the operation op .
m number of rows and columns of matrix A.
descrA the descriptor of matrix A. The supported matrix
types are CUSPARSE_MATRIX_TYPE_SYMMETRIC
and CUSPARSE_MATRIX_TYPE_HERMITIAN.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
csrValM <type> matrix containing the incomplete-Cholesky
lower or upper triangular factor.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 140
cuSPARSE Preconditioners Reference
10.2. cusparse<t>csric02_bufferSize()
cusparseStatus_t
cusparseScsric02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseDcsric02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseCcsric02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseZcsric02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
int *pBufferSizeInBytes);
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 141
cuSPARSE Preconditioners Reference
The buffer size depends on dimension m and nnz, the number of nonzeros of the matrix.
If the user changes the matrix, it is necessary to call csric02_bufferSize() again to
have the correct buffer size; otherwise, a segmentation fault may occur.
Input
handle handle to the cuSPARSE library context.
m number of rows and columns of matrix A.
nnz number of nonzeros of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
info record internal states based on different
algorithms.
pBufferSizeInBytes number of bytes of the buffer used in
csric02_analysis() and csric02().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0), base
index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 142
cuSPARSE Preconditioners Reference
10.3. cusparse<t>csric02_analysis()
cusparseStatus_t
cusparseScsric02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDcsric02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCcsric02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZcsric02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
This function performs the analysis phase of the incomplete-Cholesky factorization with
fill-in and no pivoting:
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 143
cuSPARSE Preconditioners Reference
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA.
This function requires a buffer size returned by csric02_bufferSize(). The address
of pBuffer must be multiple of 128 bytes. If not, CUSPARSE_STATUS_INVALID_VALUE is
returned.
Function csric02_analysis() reports a structural zero and computes level
information stored in the opaque structure info. The level information can extract more
parallelism during incomplete Cholesky factorization. However csric02() can be done
without level information. To disable level information, the user must specify the policy
of csric02_analysis() and csric02() as CUSPARSE_SOLVE_POLICY_NO_LEVEL.
Function csric02_analysis() always reports the first structural zero, even
if the policy is CUSPARSE_SOLVE_POLICY_NO_LEVEL. The user needs to call
cusparseXcsric02_zeroPivot() to know where the structural zero is.
It is the user's choice whether to call csric02() if csric02_analysis() reports
a structural zero. In this case, the user can still call csric02(), which will return
a numerical zero at the same position as the structural zero. However the result is
meaningless.
Input
handle handle to the cuSPARSE library context.
m number of rows and columns of matrix A.
nnz number of nonzeros of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 144
cuSPARSE Preconditioners Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0), base
index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 145
cuSPARSE Preconditioners Reference
10.4. cusparse<t>csric02()
cusparseStatus_t
cusparseScsric02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
float *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDcsric02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
double *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCcsric02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuComplex *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZcsric02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
This function performs the solve phase of the computing the incomplete-Cholesky
factorization with fill-in and no pivoting:
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 146
cuSPARSE Preconditioners Reference
For example, suppose A is a real m × m matrix, the following code solves the
precondition system M*y = x where M is the product of Cholesky factorization L and its
transpose.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 147
cuSPARSE Preconditioners Reference
cusparseMatDescr_t descr_M = 0;
cusparseMatDescr_t descr_L = 0;
csric02Info_t info_M = 0;
csrsv2Info_t info_L = 0;
csrsv2Info_t info_Lt = 0;
int pBufferSize_M;
int pBufferSize_L;
int pBufferSize_Lt;
int pBufferSize;
void *pBuffer = 0;
int structural_zero;
int numerical_zero;
const double alpha = 1.;
const cusparseSolvePolicy_t policy_M = CUSPARSE_SOLVE_POLICY_NO_LEVEL;
const cusparseSolvePolicy_t policy_L = CUSPARSE_SOLVE_POLICY_NO_LEVEL;
const cusparseSolvePolicy_t policy_Lt = CUSPARSE_SOLVE_POLICY_USE_LEVEL;
const cusparseOperation_t trans_L = CUSPARSE_OPERATION_NON_TRANSPOSE;
const cusparseOperation_t trans_Lt = CUSPARSE_OPERATION_TRANSPOSE;
cusparseCreateMatDescr(&descr_L);
cusparseSetMatIndexBase(descr_L, CUSPARSE_INDEX_BASE_ONE);
cusparseSetMatType(descr_L, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descr_L, CUSPARSE_FILL_MODE_LOWER);
cusparseSetMatDiagType(descr_L, CUSPARSE_DIAG_TYPE_NON_UNIT);
// step 3: query how much memory used in csric02 and csrsv2, and allocate the
buffer
cusparseDcsric02_bufferSize(handle, m, nnz,
descr_M, d_csrVal, d_csrRowPtr, d_csrColInd, info_M, &bufferSize_M);
cusparseDcsrsv2_bufferSize(handle, trans_L, m, nnz,
descr_L, d_csrVal, d_csrRowPtr, d_csrColInd, info_L, &pBufferSize_L);
cusparseDcsrsv2_bufferSize(handle, trans_Lt, m, nnz,
descr_L, d_csrVal, d_csrRowPtr, d_csrColInd, info_Lt,&pBufferSize_Lt);
cusparseDcsric02_analysis(handle,
www.nvidia.com m, nnz, descr_M,
d_csrVal,
cuSPARSE Library d_csrRowPtr, d_csrColInd, info_M, DU-06709-001_v8.0 | 148
policy_M, pBuffer);
status = cusparseXcsric02_zeroPivot(handle, info_M, &structural_zero);
cuSPARSE Preconditioners Reference
Input
handle handle to the cuSPARSE library context.
m number of rows and columns of matrix A.
nnz number of nonzeros of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
csrValA_valM <type> matrix containing the incomplete-Cholesky
lower triangular factor.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0), base
index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 149
cuSPARSE Preconditioners Reference
10.5. cusparseXcsric02_zeroPivot()
cusparseStatus_t
cusparseXcsric02_zeroPivot(cusparseHandle_t handle,
csric02Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1;
otherwise, if A(j,j) is missing or L(j,j) is zero,
position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 150
cuSPARSE Preconditioners Reference
10.6. cusparse<t>csrilu0()
cusparseStatus_t
cusparseScsrilu0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
float *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseDcsrilu0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
double *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseCcsrilu0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
cuComplex *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
cusparseStatus_t
cusparseZcsrilu0(cusparseHandle_t handle,
cusparseOperation_t trans,
int m,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValM,
const int *csrRowPtrA,
const int *csrColIndA,
cusparseSolveAnalysisInfo_t info)
This function computes the incomplete-LU factorization with fill-in and no pivoting:
A is an m m sparse matrix that is defined in CSR storage format by the three arrays
csrValM, csrRowPtrA, and csrColIndA; and
Notice that the diagonal of lower triangular factor is unitary and need not be stored.
Therefore, the input matrix is overwritten with the resulting lower and upper triangular
factors and , respectively.
A call to this routine must be preceded by a call to the csrsv_analysis() routine.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 151
cuSPARSE Preconditioners Reference
The matrix descriptor for csrsv_analysis() and csrilu0() must be the same.
Otherwise, runtime error would occur.
This function requires some extra storage. It is executed asynchronously with respect to
the host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
trans the operation op .
m number of rows and columns of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
csrValM <type> matrix containing the incomplete-LU lower
and upper triangular factors.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 152
cuSPARSE Preconditioners Reference
10.7. cusparseCsrilu0Ex()
cusparseStatus_t CUSPARSEAPI cusparseCsrilu0Ex(cusparseHandle_t handle,
cusparseOperation_t
trans,
int m,
const cusparseMatDescr_t
descrA,
void *csrSortedValA_ValM,
cudaDataType csrSortedValA_ValMtype,
const int
*csrSortedRowPtrA,
const int
*csrSortedColIndA,
cusparseSolveAnalysisInfo_t info,
cudaDataType
executiontype);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 153
cuSPARSE Preconditioners Reference
10.8. cusparse<t>csrilu02_numericBoost()
cusparseStatus_t
cusparseScsrilu02_numericBoost(cusparseHandle_t handle,
csrilu02Info_t info,
int enable_boost,
double *tol,
float *boost_val);
cusparseStatus_t
cusparseDcsrilu02_numericBoost(cusparseHandle_t handle,
csrilu02Info_t info,
int enable_boost,
double *tol,
double *boost_val);
cusparseStatus_t
cusparseCcsrilu02_numericBoost(cusparseHandle_t handle,
csrilu02Info_t info,
int enable_boost,
double *tol,
cuComplex *boost_val);
cusparseStatus_t
cusparseZcsrilu02_numericBoost(cusparseHandle_t handle,
csrilu02Info_t info,
int enable_boost,
double *tol,
cuDoubleComplex *boost_val);
The user can use a boost value to replace a numerical value in incomplete LU
factorization. The tol is used to determine a numerical zero, and the boost_val is used
to replace a numerical zero. The behavior is
if tol >= fabs(A(j,j)), then A(j,j)=boost_val.
To enable a boost value, the user has to set parameter enable_boost to 1 before calling
csrilu02(). To disable a boost value, the user can call csrilu02_numericBoost()
again with parameter enable_boost=0.
If enable_boost=0, tol and boost_val are ignored.
Both tol and boost_val can be in the host memory or device memory. The user can set
the proper mode with cusparseSetPointerMode().
Input
handle handle to the cuSPARSE library context.
info structure initialized using
cusparseCreateCsrilu02Info().
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 154
cuSPARSE Preconditioners Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info or pointer mode is not valid.
10.9. cusparse<t>csrilu02_bufferSize()
cusparseStatus_t
cusparseScsrilu02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseDcsrilu02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseCcsrilu02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseZcsrilu02_bufferSize(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
int *pBufferSizeInBytes);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 155
cuSPARSE Preconditioners Reference
This function returns size of the buffer used in computing the incomplete-LU
factorization with fill-in and no pivoting:
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA.
The buffer size depends on the dimension m and nnz, the number of nonzeros of the
matrix. If the user changes the matrix, it is necessary to call csrilu02_bufferSize()
again to have the correct buffer size; otherwise, a segmentation fault may occur.
Input
handle handle to the cuSPARSE library context.
m number of rows and columns of matrix A.
nnz number of nonzeros of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
info record internal states based on different
algorithms.
pBufferSizeInBytes number of bytes of the buffer used in
csrilu02_analysis() and csrilu02().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0), base
index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 156
cuSPARSE Preconditioners Reference
10.10. cusparse<t>csrilu02_analysis()
cusparseStatus_t
cusparseScsrilu02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDcsrilu02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCcsrilu02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZcsrilu02_analysis(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
This function performs the analysis phase of the incomplete-LU factorization with fill-
in and no pivoting:
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 157
cuSPARSE Preconditioners Reference
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA, csrRowPtrA, and csrColIndA.
This function requires the buffer size returned by csrilu02_bufferSize().
The address of pBuffer must be a multiple of 128 bytes. If not,
CUSPARSE_STATUS_INVALID_VALUE is returned.
Function csrilu02_analysis() reports a structural zero and computes level
information stored in the opaque structure info. The level information can extract more
parallelism during incomplete LU factorization; however csrilu02() can be done
without level information. To disable level information, the user must specify the policy
of csrilu02() as CUSPARSE_SOLVE_POLICY_NO_LEVEL.
It is the user's choice whether to call csrilu02() if csrilu02_analysis() reports
a structural zero. In this case, the user can still call csrilu02(), which will return
a numerical zero at the same position as the structural zero. However the result is
meaningless.
Input
handle handle to the cuSPARSE library context.
m number of rows and columns of matrix A.
nnz number of nonzeros of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 158
cuSPARSE Preconditioners Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 159
cuSPARSE Preconditioners Reference
10.11. cusparse<t>csrilu02()
cusparseStatus_t
cusparseScsrilu02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
float *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDcsrilu02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
double *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCcsrilu02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuComplex *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZcsrilu02(cusparseHandle_t handle,
int m,
int nnz,
const cusparseMatDescr_t descrA,
cuDoubleComplex *csrValA_valM,
const int *csrRowPtrA,
const int *csrColIndA,
csrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
This function performs the solve phase of the incomplete-LU factorization with fill-in
and no pivoting:
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 160
cuSPARSE Preconditioners Reference
A is an m×m sparse matrix that is defined in CSR storage format by the three arrays
csrValA_valM, csrRowPtrA, and csrColIndA.
This function requires a buffer size returned by csrilu02_bufferSize(). The address
of pBuffer must be a multiple of 128 bytes. If not, CUSPARSE_STATUS_INVALID_VALUE
is returned.
The matrix type must be CUSPARSE_MATRIX_TYPE_GENERAL. The fill mode and
diagonal type are ignored.
Although csrilu02() can be done without level information, the user still
needs to be aware of consistency. If csrilu02_analysis() is called with
policy CUSPARSE_SOLVE_POLICY_USE_LEVEL, csrilu02() can be run with
or without levels. On the other hand, if csrilu02_analysis() is called
with CUSPARSE_SOLVE_POLICY_NO_LEVEL, csrilu02() can only accept
CUSPARSE_SOLVE_POLICY_NO_LEVEL; otherwise, CUSPARSE_STATUS_INVALID_VALUE
is returned.
Function csrilu02() reports the first numerical zero, including a structural zero. The
user must call cusparseXcsrilu02_zeroPivot() to know where the numerical zero
is.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 161
cuSPARSE Preconditioners Reference
For example, suppose A is a real m × m matrix, the following code solves precondition
system M*y = x where M is the product of LU factors L and U.
// Suppose that A is m x m sparse matrix represented by CSR format,
// Assumption:
// - handle is already created by cusparseCreate(),
// - (d_csrRowPtr, d_csrColInd, d_csrVal) is CSR of A on device memory,
// - d_x is right hand side vector on device memory,
// - d_y is solution vector on device memory.
// - d_z is intermediate result on device memory.
cusparseMatDescr_t descr_M = 0;
cusparseMatDescr_t descr_L = 0;
cusparseMatDescr_t descr_U = 0;
csrilu02Info_t info_M = 0;
csrsv2Info_t info_L = 0;
csrsv2Info_t info_U = 0;
int pBufferSize_M;
int pBufferSize_L;
int pBufferSize_U;
int pBufferSize;
void *pBuffer = 0;
int structural_zero;
int numerical_zero;
const double alpha = 1.;
const cusparseSolvePolicy_t policy_M = CUSPARSE_SOLVE_POLICY_NO_LEVEL;
const cusparseSolvePolicy_t policy_L = CUSPARSE_SOLVE_POLICY_NO_LEVEL;
const cusparseSolvePolicy_t policy_U = CUSPARSE_SOLVE_POLICY_USE_LEVEL;
const cusparseOperation_t trans_L = CUSPARSE_OPERATION_NON_TRANSPOSE;
const cusparseOperation_t trans_U = CUSPARSE_OPERATION_NON_TRANSPOSE;
cusparseCreateMatDescr(&descr_L);
cusparseSetMatIndexBase(descr_L, CUSPARSE_INDEX_BASE_ONE);
cusparseSetMatType(descr_L, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descr_L, CUSPARSE_FILL_MODE_LOWER);
cusparseSetMatDiagType(descr_L, CUSPARSE_DIAG_TYPE_UNIT);
cusparseCreateMatDescr(&descr_U);
cusparseSetMatIndexBase(descr_U, CUSPARSE_INDEX_BASE_ONE);
cusparseSetMatType(descr_U, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descr_U, CUSPARSE_FILL_MODE_UPPER);
cusparseSetMatDiagType(descr_U, CUSPARSE_DIAG_TYPE_NON_UNIT);
// step 3: query how much memory used in csrilu02 and csrsv2, and allocate the
buffer
cusparseDcsrilu02_bufferSize(handle, m, nnz,
descr_M, d_csrVal, d_csrRowPtr, d_csrColInd, info_M, &pBufferSize_M);
cusparseDcsrsv2_bufferSize(handle, trans_L, m, nnz,
descr_L, d_csrVal, d_csrRowPtr, d_csrColInd, info_L, &pBufferSize_L);
cusparseDcsrsv2_bufferSize(handle, trans_U, m, nnz,
descr_U, d_csrVal, d_csrRowPtr, d_csrColInd, info_U, &pBufferSize_U);
Input
handle handle to the cuSPARSE library context.
m number of rows and columns of matrix A.
nnz number of nonzeros of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
csrValA_valM <type> matrix containing the incomplete-LU lower
and upper triangular factors.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<=0), base
index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 163
cuSPARSE Preconditioners Reference
10.12. cusparseXcsrilu02_zeroPivot()
cusparseStatus_t
cusparseXcsrilu02_zeroPivot(cusparseHandle_t handle,
csrilu02Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1;
otherwise if A(j,j) is missing or U(j,j) is zero,
position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 164
cuSPARSE Preconditioners Reference
10.13. cusparse<t>bsric02_bufferSize()
cusparseStatus_t
cusparseSbsric02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseDbsric02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseCbsric02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseZbsric02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
int *pBufferSizeInBytes);
This function returns the size of a buffer used in computing the incomplete-Cholesky
factorization with 0 fill-in and no pivoting
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 165
cuSPARSE Preconditioners Reference
Output
info record internal states based on different
algorithms.
pBufferSizeInBytes number of bytes of the buffer used in
bsric02_analysis() and bsric02().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0); the
base index is not 0 or 1.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 166
cuSPARSE Preconditioners Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 167
cuSPARSE Preconditioners Reference
10.14. cusparse<t>bsric02_analysis()
cusparseStatus_t
cusparseSbsric02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDbsric02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCbsric02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZbsric02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 168
cuSPARSE Preconditioners Reference
This function performs the analysis phase of the incomplete-Cholesky factorization with
0 fill-in and no pivoting
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 169
cuSPARSE Preconditioners Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0); the
base index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 170
cuSPARSE Preconditioners Reference
10.15. cusparse<t>bsric02()
cusparseStatus_t
cusparseSbsric02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDbsric02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCbsric02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZbsric02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsric02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 171
cuSPARSE Preconditioners Reference
This function performs the solve phase of the incomplete-Cholesky factorization with 0
fill-in and no pivoting
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 172
cuSPARSE Preconditioners Reference
cusparseCreateMatDescr(&descr_L);
cusparseSetMatIndexBase(descr_L, CUSPARSE_INDEX_BASE_ONE);
cusparseSetMatType(descr_L, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descr_L, CUSPARSE_FILL_MODE_LOWER);
cusparseSetMatDiagType(descr_L, CUSPARSE_DIAG_TYPE_NON_UNIT);
// step 3: query how much memory used in bsric02 and bsrsv2, and allocate the
buffer
cusparseDbsric02_bufferSize(handle, dir, mb, nnzb,
descr_M, d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, info_M,
&bufferSize_M);
cusparseDbsrsv2_bufferSize(handle, dir, trans_L, mb, nnzb,
descr_L, d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, info_L,
&pBufferSize_L);
cusparseDbsrsv2_bufferSize(handle, dir, trans_Lt, mb, nnzb,
descr_L, d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, info_Lt,
&pBufferSize_Lt);
Input
handle handle to the cuSPARSE library context.
dirA storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
bsrValA <type> matrix containing the incomplete-Cholesky
lower triangular factor.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0); the
base index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 174
cuSPARSE Preconditioners Reference
10.16. cusparseXbsric02_zeroPivot()
cusparseStatus_t
cusparseXbsric02_zeroPivot(cusparseHandle_t handle,
bsric02Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1,
otherwise if A(j,j) is missing or L(j,j) is not
positive definite, position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 175
cuSPARSE Preconditioners Reference
10.17. cusparse<t>bsrilu02_numericBoost()
cusparseStatus_t
cusparseSbsrilu02_numericBoost(cusparseHandle_t handle,
bsrilu02Info_t info,
int enable_boost,
double *tol,
float *boost_val);
cusparseStatus_t
cusparseDbsrilu02_numericBoost(cusparseHandle_t handle,
bsrilu02Info_t info,
int enable_boost,
double *tol,
double *boost_val);
cusparseStatus_t
cusparseCbsrilu02_numericBoost(cusparseHandle_t handle,
bsrilu02Info_t info,
int enable_boost,
double *tol,
cuComplex *boost_val);
cusparseStatus_t
cusparseZbsrilu02_numericBoost(cusparseHandle_t handle,
bsrilu02Info_t info,
int enable_boost,
double *tol,
cuDoubleComplex *boost_val);
The user can use a boost value to replace a numerical value in incomplete LU
factorization. Parameter tol is used to determine a numerical zero, and boost_val is
used to replace a numerical zero. The behavior is as follows:
if tol >= fabs(A(j,j)), then reset each diagonal element of block A(j,j) by
boost_val.
To enable a boost value, the user sets parameter enable_boost to 1 before calling
bsrilu02(). To disable the boost value, the user can call bsrilu02_numericBoost()
with parameter enable_boost=0.
If enable_boost=0, tol and boost_val are ignored.
Both tol and boost_val can be in host memory or device memory. The user can set the
proper mode with cusparseSetPointerMode().
Input
handle handle to the cuSPARSE library context.
info structure initialized using
cusparseCreateBsrilu02Info().
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 176
cuSPARSE Preconditioners Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info or pointer mode is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 177
cuSPARSE Preconditioners Reference
10.18. cusparse<t>bsrilu02_bufferSize()
cusparseStatus_t
cusparseSbsrilu02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseDbsrilu02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseCbsrilu02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
int *pBufferSizeInBytes);
cusparseStatus_t
cusparseZbsrilu02_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
int *pBufferSizeInBytes);
This function returns the size of the buffer used in computing the incomplete-LU
factorization with 0 fill-in and no pivoting
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 178
cuSPARSE Preconditioners Reference
Output
info record internal states based on different
algorithms.
pBufferSizeInBytes number of bytes of the buffer used in
bsrilu02_analysis() and bsrilu02().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0),
base index is not 0 or 1.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 179
cuSPARSE Preconditioners Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 180
cuSPARSE Preconditioners Reference
10.19. cusparse<t>bsrilu02_analysis()
cusparseStatus_t
cusparseSbsrilu02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDbsrilu02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCbsrilu02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZbsrilu02_analysis(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descrA,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 181
cuSPARSE Preconditioners Reference
This function performs the analysis phase of the incomplete-LU factorization with 0 fill-
in and no pivoting
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 182
cuSPARSE Preconditioners Reference
Output
info structure filled with information collected during
the analysis phase (that should be passed to the
solve phase unchanged).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0); the
base index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 183
cuSPARSE Preconditioners Reference
10.20. cusparse<t>bsrilu02()
cusparseStatus_t
cusparseSbsrilu02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descry,
float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseDbsrilu02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descry,
double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseCbsrilu02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descry,
cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
cusparseStatus_t
cusparseZbsrilu02(cusparseHandle_t handle,
cusparseDirection_t dirA,
int mb,
int nnzb,
const cusparseMatDescr_t descry,
cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
bsrilu02Info_t info,
cusparseSolvePolicy_t policy,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 184
cuSPARSE Preconditioners Reference
This function performs the solve phase of the incomplete-LU factorization with 0 fill-in
and no pivoting
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 185
cuSPARSE Preconditioners Reference
For example, suppose A is a real m-by-m matrix where m=mb*blockDim. The following
code solves precondition system M*y = x, where M is the product of LU factors L and U.
cusparseCreateMatDescr(&descr_L);
cusparseSetMatIndexBase(descr_L, CUSPARSE_INDEX_BASE_ONE);
cusparseSetMatType(descr_L, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descr_L, CUSPARSE_FILL_MODE_LOWER);
cusparseSetMatDiagType(descr_L, CUSPARSE_DIAG_TYPE_UNIT);
cusparseCreateMatDescr(&descr_U);
cusparseSetMatIndexBase(descr_U, CUSPARSE_INDEX_BASE_ONE);
cusparseSetMatType(descr_U, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descr_U, CUSPARSE_FILL_MODE_UPPER);
cusparseSetMatDiagType(descr_U, CUSPARSE_DIAG_TYPE_NON_UNIT);
// step 3: query how much memory used in bsrilu02 and bsrsv2, and allocate the
buffer
cusparseDbsrilu02_bufferSize(handle, dir, mb, nnzb,
descr_M, d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, info_M,
&pBufferSize_M);
cusparseDbsrsv2_bufferSize(handle, dir, trans_L, mb, nnzb,
descr_L, d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, info_L,
www.nvidia.com
&pBufferSize_L);
cuSPARSE Library DU-06709-001_v8.0 | 186
cusparseDbsrsv2_bufferSize(handle, dir, trans_U, mb, nnzb,
descr_U, d_bsrVal, d_bsrRowPtr, d_bsrColInd, blockDim, info_U,
cuSPARSE Preconditioners Reference
Input
handle handle to the cuSPARSE library context.
dirA storage format of blocks: either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
bsrValA <type> matrix containing the incomplete-LU lower
and upper triangular factors.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nnzb<=0); the
base index is not 0 or 1.
CUSPARSE_STATUS_ARCH_MISMATCH the device only supports compute capability 2.0
and above.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 187
cuSPARSE Preconditioners Reference
10.21. cusparseXbsrilu02_zeroPivot()
cusparseStatus_t
cusparseXbsrilu02_zeroPivot(cusparseHandle_t handle,
bsrilu02Info_t info,
int *position);
Output
position if no structural or numerical zero, position is -1;
otherwise if A(j,j) is missing or U(j,j) is not
invertible, position=j.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE info is not valid.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 188
cuSPARSE Preconditioners Reference
10.22. cusparse<t>gtsv()
cusparseStatus_t
cusparseSgtsv(cusparseHandle_t handle,
int m,
int n,
const float *dl,
const float *d,
const float *du,
float *B,
int ldb)
cusparseStatus_t
cusparseDgtsv(cusparseHandle_t handle,
int m,
int n,
const double *dl,
const double *d,
const double *du,
double *B,
int ldb)
cusparseStatus_t
cusparseCgtsv(cusparseHandle_t handle,
int m,
int n,
const cuComplex *dl,
const cuComplex *d,
const cuComplex *du,
cuComplex *B,
int ldb)
cusparseStatus_t
cusparseZgtsv(cusparseHandle_t handle,
int m,
int n,
const cuDoubleComplex *dl,
const cuDoubleComplex *d,
const cuDoubleComplex *du,
cuDoubleComplex *B,
int ldb)
This function computes the solution of a tridiagonal linear system with multiple right-
hand sides:
The coefficient matrix A of each of these tri-diagonal linear system is defined with three
vectors corresponding to its lower (dl), main (d), and upper (du) matrix diagonals; the
right-hand sides are stored in the dense matrix X. Notice that solution Y overwrites right-
hand-side matrix X on exit.
Assuming A is of size m and base-1, dl, d and du are defined by the following formula:
dl(i) := A(i, i-1) for i=1,2,...,m
The first element of dl is out-of-bound (dl(1) := A(1,0)), so dl(1) = 0.
d(i) = A(i,i) for i=1,2,...,m
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 189
cuSPARSE Preconditioners Reference
Output
B <type> dense solution array of dimensions (ldb,
n).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<3, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 190
cuSPARSE Preconditioners Reference
10.23. cusparse<t>gtsv_nopivot()
cusparseStatus_t
cusparseSgtsv_nopivot(cusparseHandle_t handle, int m, int n,
const float *dl, const float *d,
const float *du, float *B, int ldb)
cusparseStatus_t
cusparseDgtsv_nopivot(cusparseHandle_t handle, int m, int n,
const double *dl, const double *d,
const double *du, double *B, int ldb)
cusparseStatus_t
cusparseCgtsv_nopivot(cusparseHandle_t handle, int m, int n,
const cuComplex *dl, const cuComplex *d,
const cuComplex *du, cuComplex *B, int ldb)
cusparseStatus_t
cusparseZgtsv_nopivot(cusparseHandle_t handle, int m, int n,
const cuDoubleComplex *dl, const cuDoubleComplex *d,
const cuDoubleComplex *du, cuDoubleComplex *B, int ldb)
This function computes the solution of a tridiagonal linear system with multiple right-
hand sides:
The coefficient matrix A of each of these tri-diagonal linear system is defined with three
vectors corresponding to its lower (dl), main (d), and upper (du) matrix diagonals; the
right-hand sides are stored in the dense matrix X. Notice that solution Y overwrites right-
hand-side matrix X on exit.
The routine does not perform any pivoting and uses a combination of the Cyclic
Reduction (CR) and the Parallel Cyclic Reduction (PCR) algorithms to find the solution.
It achieves better performance when m is a power of 2.
This routine requires a significant amount of temporary extra storage
(m×(3+n)×sizeof(<type>)). It is executed asynchronously with respect to the host
and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m the size of the linear system (must be ≥ 3).
n number of right-hand sides, columns of matrix B.
dl <type> dense array containing the lower diagonal
of the tri-diagonal linear system. The first element
of each lower diagonal must be zero.
d <type> dense array containing the main diagonal of
the tri-diagonal linear system.
du <type> dense array containing the upper diagonal
of the tri-diagonal linear system. The last element
of each upper diagonal must be zero.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 191
cuSPARSE Preconditioners Reference
Output
B <type> dense solution array of dimensions (ldb,
n).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<3, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
10.24. cusparse<t>gtsvStridedBatch()
cusparseStatus_t
cusparseSgtsvStridedBatch(cusparseHandle_t handle, int m,
const float *dl,
const float *d,
const float *du, float *x,
cusparseStatus_t
cusparseCgtsvStridedBatch(cusparseHandle_t handle, int m,
const cuComplex *dl,
const cuComplex *d,
const cuComplex *du, cuComplex *x,
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 192
cuSPARSE Preconditioners Reference
This function computes the solution of multiple tridiagonal linear systems for i=0,
…,batchCount:
The coefficient matrix A of each of these tri-diagonal linear system is defined with three
vectors corresponding to its lower (dl), main (d), and upper (du) matrix diagonals; the
right-hand sides are stored in the dense matrix X. Notice that solution Y overwrites right-
hand-side matrix X on exit. The different matrices are assumed to be of the same size and
are stored with a fixed batchStride in memory.
The routine does not perform any pivoting and uses a combination of the Cyclic
Reduction (CR) and the Parallel Cyclic Reduction (PCR) algorithms to find the solution.
It achieves better performance when m is a power of 2.
This routine requires a significant amount of temporary extra storage
((batchCount×(4×m+2048)×sizeof(<type>))). It is executed asynchronously with
respect to the host and may return control to the application on the host before the result
is ready.
Input
handle handle to the cuSPARSE library context.
m the size of the linear system (must be ≥ 3).
dl <type> dense array containing the lower diagonal
of the tri-diagonal linear system. The lower
th
diagonal that corresponds to the i linear
system starts at location dl+batchStride×i in
memory. Also, the first element of each lower
diagonal must be zero.
d <type> dense array containing the main diagonal of
the tri-diagonal linear system. The main diagonal
th
that corresponds to the i linear system starts
at location d+batchStride×i in memory.
du <type> dense array containing the upper diagonal
of the tri-diagonal linear system. The upper
th
diagonal that corresponds to the i linear
system starts at location du+batchStride×i in
memory. Also, the last element of each upper
diagonal must be zero.
x <type> dense array that contains the right-hand-
side of the tri-diagonal linear system. The right-
th
hand-side that corresponds to the i linear
system starts at location x+batchStride×iin
memory.
batchCount number of systems to solve.
batchStride stride (number of elements) that separates the
vectors of every system (must be at least m).
Output
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 193
cuSPARSE Preconditioners Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m<3,
batchCount≤0, batchStride<m).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 194
Chapter 11.
CUSPARSE REORDERINGS REFERENCE
This chapter describes the reordering routines used to manipulate sparse matrices.
11.1. cusparse<t>csrcolor()
cusparseStatus_t
cusparseScsrcolor(cusparseHandle_t handle, int m, int nnz,
const cusparseMatDescr_t descrA, const float *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const float *fractionToColor, int *ncolors, int *coloring,
int *reordering,cusparseColorInfo_t info);
cusparseStatus_t
cusparseDcsrcolor(cusparseHandle_t handle, int m, int nnz,
const cusparseMatDescr_t descrA, const double *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const double *fractionToColor,int *ncolors, int *coloring,
int *reordering, cusparseColorInfo_t info);
cusparseStatus_t
cusparseCcsrcolor(cusparseHandle_t handle, int m, int nnz,
const cusparseMatDescr_t descrA, const cuComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const float *fractionToColor, int *ncolors, int *coloring,
int *reordering, cusparseColorInfo_t info);
cusparseStatus_t
cusparseZcsrcolor(cusparseHandle_t handle, int m, int nnz,
const cusparseMatDescr_t descrA, const cuDoubleComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
const double *fractionToColor,int *ncolors, int *coloring,
int *reordering, cusparseColorInfo_t info);
This function performs the coloring of the adjacency graph associated with the matrix
A stored in CSR format. The coloring is an assignment of colors (integer numbers)
to nodes, such that neighboring nodes have distinct colors. An approximate coloring
algorithm is used in this routine, and is stopped when a certain percentage of nodes has
been colored. The rest of the nodes are assigned distinct colors (an increasing sequence
of integers numbers, starting from the last integer used previously). The last two
auxiliary routines can be used to extract the resulting number of colors, their assignment
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 195
cuSPARSE Reorderings Reference
and the associated reordering. The reordering is such that nodes that have been assigned
the same color are reordered to be next to each other.
The matrix A passed to this routine, must be stored as a general matrix and have a
symmetric sparsity pattern. If the matrix is nonsymmetric the user should pass A+A^T
as a parameter to this routine.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix A.
nnz number of nonzero elements of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
ncolors The number of distinct colors used (at most the
size of the matrix, but likely much smaller).
coloring The resulting coloring permutation
reordering The resulting reordering permutation (untouched if
NULL)
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision
(compute capability (c.c.) >= 1.3 required).
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 196
cuSPARSE Reorderings Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 197
Chapter 12.
CUSPARSE FORMAT CONVERSION
REFERENCE
This chapter describes the conversion routines between different sparse and dense
storage formats.
coosort, csrsort, cscsort, csru2csr and csr2csc_indexOnly are sorting routines
without malloc inside, the following table estimates the buffer size
routine buffer size maximum problem size if buffer is
limited by 2GB
csru2csr 'd' > 28*n bytes ; 'z' 71M for 'd' and 55M for 'z'
> 36*n bytes
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 198
cuSPARSE Format Conversion Reference
12.1. cusparse<t>bsr2csr()
cusparseStatus_t
cusparseSbsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
float *csrValC,
int *csrRowPtrC,
int *csrColIndC)
cusparseStatus_t
cusparseDbsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
double *csrValC,
int *csrRowPtrC,
int *csrColIndC)
cusparseStatus_t
cusparseCbsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
cuComplex *csrValC,
int *csrRowPtrC,
int *csrColIndC)
cusparseStatus_t
cusparseZbsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
cuDoubleComplex *csrValC,
int *csrRowPtrC,
int *csrColIndC)
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 199
cuSPARSE Format Conversion Reference
This function converts a sparse matrix in BSR format that is defined by the three arrays
bsrValA, bsrRowPtrA, and bsrColIndA) into a sparse matrix in CSR format that is
defined by arrays csrValC, csrRowPtrC, and csrColIndC.
Let m(=mb*blockDim) be the number of rows of A and n(=nb*blockDim) be number
of columns of A, then A and C are m*n sparse matrices. The BSR format of A contains
nnzb(=bsrRowPtrA[mb] - bsrRowPtrA[0]) nonzero blocks, whereas the sparse
matrix A contains nnz(=nnzb*blockDim*blockDim) elements. The user must allocate
enough space for arrays csrRowPtrC, csrColIndC, and csrValC. The requirements are
as follows:
csrRowPtrC of m+1 elements
csrValC of nnz elements
csrColIndC of nnz elements
The general procedure is as follows:
// Given BSR format (bsrRowPtrA, bsrcolIndA, bsrValA) and
// blocks of BSR format are stored in column-major order.
cusparseDirection_t dir = CUSPARSE_DIRECTION_COLUMN;
int m = mb*blockDim;
int nnzb = bsrRowPtrA[mb] - bsrRowPtrA[0]; // number of blocks
int nnz = nnzb * blockDim * blockDim; // number of elements
cudaMalloc((void**)&csrRowPtrC, sizeof(int)*(m+1));
cudaMalloc((void**)&csrColIndC, sizeof(int)*nnz);
cudaMalloc((void**)&csrValC, sizeof(float)*nnz);
cusparseSbsr2csr(handle, dir, mb, nb,
descrA,
bsrValA, bsrRowPtrA, bsrColIndA,
blockDim,
descrC,
csrValC, csrRowPtrC, csrColIndC);
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 200
cuSPARSE Format Conversion Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb,nb<0,
IndexBase of descrA, descrC is not base-0 or
base-1, dir is not row-major or column-major, or
blockDim<1).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 201
cuSPARSE Format Conversion Reference
12.2. cusparse<t>gebsr2gebsc_bufferSize()
cusparseStatus_t
cusparseSgebsr2gebsc_bufferSize(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const float *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
cusparseStatus_t
cusparseDgebsr2gebsc_bufferSize(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const double *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
cusparseStatus_t
cusparseCgebsr2gebsc_bufferSize(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const cuComplex *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
cusparseStatus_t
cusparseZgebsr2gebsc_bufferSize(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const cuDoubleComplex *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 202
cuSPARSE Format Conversion Reference
Output
pBufferSize host pointer containing number of bytes of the
buffer used in gebsr2gebsc().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb, nb,
nnzb<0, or rowBlockDim, colBlockDim<1).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 203
cuSPARSE Format Conversion Reference
12.3. cusparse<t>gebsr2gebsc()
cusparseStatus_t
cusparseSgebsr2gebsc(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const float *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
float *bscVal,
int *bscRowInd,
int *bscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t baseIdx,
void *pBuffer)
cusparseStatus_t
cusparseDgebsr2gebsc(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const double *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
double *bscVal,
int *bscRowInd,
int *bscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t baseIdx,
void *pBuffer)
cusparseStatus_t
cusparseCgebsr2gebsc(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const cuComplex *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
int rowBlockDim,
int colBlockDim,
cuComplex *bscVal,
int *bscRowInd,
int *bscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t baseIdx,
void *pBuffer)
cusparseStatus_t
cusparseZgebsr2gebsc(cusparseHandle_t handle,
int mb,
int nb,
int nnzb,
const cuDoubleComplex *bsrVal,
const int *bsrRowPtr,
const int *bsrColInd,
www.nvidia.com
int rowBlockDim,
int
cuSPARSE colBlockDim,
Library DU-06709-001_v8.0 | 204
cuDoubleComplex *bscVal,
cuSPARSE Format Conversion Reference
This function can be seen as the same as csr2csc() when each block of size
rowBlockDim*colBlockDim is regarded as a scalar.
This sparsity pattern of the result matrix can also be seen as the transpose of the original
sparse matrix, but the memory layout of a block does not change.
The user must call gebsr2gebsc_bufferSize() to determine the size of the buffer
required by gebsr2gebsc(), allocate the buffer, and pass the buffer pointer to
gebsr2gebsc().
Input
handle handle to the cuSPARSE library context.
mb number of block rows of sparse matrix A.
nb number of block columns of sparse matrix A.
nnzb number of nonzero blocks of matrix A.
bsrVal <type> array of
nnzb*rowBlockDim*colBlockDim nonzero
elements of matrix A.
bsrRowPtr integer array of mb+1 elements that contains the
start of every block row and the end of the last
block row plus one.
bsrColInd integer array of nnzb column indices of the non-
zero blocks of matrix A.
rowBlockDim number of rows within a block of A.
colBlockDim number of columns within a block of A.
copyValues CUSPARSE_ACTION_SYMBOLIC or
CUSPARSE_ACTION_NUMERIC.
baseIdx CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
bscVal <type> array of
nnzb*rowBlockDim*colBlockDim
non-zero elements of matrix A. It is
only filled-in if copyValues is set to
CUSPARSE_ACTION_NUMERIC.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 205
cuSPARSE Format Conversion Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 206
cuSPARSE Format Conversion Reference
12.4. cusparse<t>gebsr2gebsr_bufferSize()
cusparseStatus_t
cusparseSgebsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
int colBlockDimA,
int rowBlockDimC,
int colBlockDimC,
int *pBufferSize )
cusparseStatus_t
cusparseDgebsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
int colBlockDimA,
int rowBlockDimC,
int colBlockDimC,
int *pBufferSize )
cusparseStatus_t
cusparseCgebsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
int colBlockDimA,
int rowBlockDimC,
int colBlockDimC,
int *pBufferSize )
cusparseStatus_t
cusparseZgebsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
www.nvidia.com
int colBlockDimA,
int
cuSPARSE rowBlockDimC,
Library DU-06709-001_v8.0 | 207
int colBlockDimC,
cuSPARSE Format Conversion Reference
This function returns size of the buffer used in computing gebsr2gebsrNnz() and
gebsr2gebsr().
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
pBufferSize host pointer containing number of bytes of the
buffer used in gebsr2gebsr().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb, nb,
nnzb<0; or rowBlockDimA, colBlockDimA,
rowBlockDimC, colBlockDimC<1).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 208
cuSPARSE Format Conversion Reference
12.5. cusparse<t>gebsr2gebsr()
cusparseStatus_t
cusparseXgebsr2gebsrNnz(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
int colBlockDimA,
const cusparseMatDescr_t descrC,
int *bsrRowPtrC,
int rowBlockDimC,
int colBlockDimC,
int *nnzTotalDevHostPtr,
void *pBuffer)
cusparseStatus_t
cusparseSgebsr2gebsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
int colBlockDimA,
const cusparseMatDescr_t descrC,
float *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC,
int rowBlockDimC,
int colBlockDimC,
void *pBuffer)
cusparseStatus_t
cusparseDgebsr2gebsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
int nnzb,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDimA,
int colBlockDimA,
const cusparseMatDescr_t descrC,
double *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC,
int rowBlockDimC,
int colBlockDimC,
void *pBuffer)
cusparseStatus_t
cusparseCgebsr2gebsr(cusparseHandle_t handle,
www.nvidia.com
cusparseDirection_t dir,
int
cuSPARSE mb,
Library DU-06709-001_v8.0 | 209
int nb,
cuSPARSE Format Conversion Reference
This function converts a sparse matrix in general BSR format that is defined by the three
arrays bsrValA, bsrRowPtrA, and bsrColIndA into a sparse matrix in another general
BSR format that is defined by arrays bsrValC, bsrRowPtrC, and bsrColIndC.
If rowBlockDimA=1 and colBlockDimA=1, cusparse[S|D|C|Z]gebsr2gebsr() is the
same as cusparse[S|D|C|Z]csr2gebsr().
If rowBlockDimC=1 and colBlockDimC=1, cusparse[S|D|C|Z]gebsr2gebsr() is the
same as cusparse[S|D|C|Z]gebsr2csr().
A is an m*n sparse matrix where m(=mb*rowBlockDim) is the number of rows of A,
and n(=nb*colBlockDim) is the number of columns of A. The general BSR format of A
contains nnzb(=bsrRowPtrA[mb] - bsrRowPtrA[0]) nonzero blocks. The matrix C
is also general BSR format with a different block size, rowBlockDimC*colBlockDimC.
If m is not a multiple of rowBlockDimC, or n is not a multiple of colBlockDimC,
zeros are filled in. The number of block rows of C is mc(=(m+rowBlockDimC-1)/
rowBlockDimC). The number of block rows of C is nc(=(n+colBlockDimC-1)/
colBlockDimC). The number of nonzero blocks of C is nnzc.
The implementation adopts a two-step approach to do the conversion.
First, the user allocates bsrRowPtrC of mc+1 elements and uses function
cusparseXgebsr2gebsrNnz() to determine the number of nonzero block
columns per block row of matrix C. Second, the user gathers nnzc (number of non-
zero block columns of matrix C) from either (nnzc=*nnzTotalDevHostPtr)
or (nnzc=bsrRowPtrC[mc]-bsrRowPtrC[0]) and allocates bsrValC of
nnzc*rowBlockDimC*colBlockDimC elements and bsrColIndC of nnzc integers.
Finally the function cusparse[S|D|C|Z]gebsr2gebsr() is called to complete the
conversion.
The user must call gebsr2gebsr_bufferSize() to know the size of the buffer required
by gebsr2gebsr(), allocate the buffer, and pass the buffer pointer to gebsr2gebsr().
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 210
cuSPARSE Format Conversion Reference
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 211
cuSPARSE Format Conversion Reference
Output
bsrValC <type> array of
nnzc*rowBlockDimC*colBlockDimC non-zero
elements of matrix C.
bsrRowPtrC integer array of mc+1 elements that contains the
start of every block row and the end of the last
block row plus one of matrix C.
bsrColIndC integer array of nnzc block column indices of the
nonzero blocks of matrix C.
nnzTotalDevHostPtr total number of nonzero blocks of C.
*nnzTotalDevHostPtr is the same as
bsrRowPtrC[mc]-bsrRowPtrC[0].
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb, nb,
nnzb<0, baseIdx is not base-0 or base-1; or
rowBlockDimA, colBlockDimA, rowBlockDimC,
colBlockDimC<1).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 212
cuSPARSE Format Conversion Reference
12.6. cusparse<t>gebsr2csr()
cusparseStatus_t
cusparseSgebsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const float *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDim,
int colBlockDim,
const cusparseMatDescr_t descrC,
float *csrValC,
int *csrRowPtrC,
int *csrColIndC )
cusparseStatus_t
cusparseDgebsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const double *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDim,
int colBlockDim,
const cusparseMatDescr_t descrC,
double *csrValC,
int *csrRowPtrC,
int *csrColIndC )
cusparseStatus_t
cusparseCgebsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const cuComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDim,
int colBlockDim,
const cusparseMatDescr_t descrC,
cuComplex *csrValC,
int *csrRowPtrC,
int *csrColIndC )
cusparseStatus_t
cusparseZgebsr2csr(cusparseHandle_t handle,
cusparseDirection_t dir,
int mb,
int nb,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *bsrValA,
const int *bsrRowPtrA,
const int *bsrColIndA,
int rowBlockDim,
int colBlockDim,
const cusparseMatDescr_t descrC,
cuDoubleComplex *csrValC,
int *csrRowPtrC,
int *csrColIndC )
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 213
cuSPARSE Format Conversion Reference
This function converts a sparse matrix in general BSR format that is defined by the three
arrays bsrValA, bsrRowPtrA, and bsrColIndA into a sparse matrix in CSR format that
is defined by arrays csrValC, csrRowPtrC, and csrColIndC.
Let m(=mb*rowBlockDim) be number of rows of A and n(=nb*colBlockDim) be
number of columns of A, then A and C are m*n sparse matrices. The general BSR format
of A contains nnzb(=bsrRowPtrA[mb] - bsrRowPtrA[0]) non-zero blocks, whereas
sparse matrix A contains nnz(=nnzb*rowBlockDim*colBlockDim) elements. The user
must allocate enough space for arrays csrRowPtrC, csrColIndC, and csrValC. The
requirements are as follows:
csrRowPtrC of m+1 elements
csrValC of nnz elements
csrColIndC of nnz elements
The general procedure is as follows:
// Given general BSR format (bsrRowPtrA, bsrColIndA, bsrValA) and
// blocks of BSR format are stored in column-major order.
cusparseDirection_t dir = CUSPARSE_DIRECTION_COLUMN;
int m = mb*rowBlockDim;
int n = nb*colBlockDim;
int nnzb = bsrRowPtrA[mb] - bsrRowPtrA[0]; // number of blocks
int nnz = nnzb * rowBlockDim * colBlockDim; // number of elements
cudaMalloc((void**)&csrRowPtrC, sizeof(int)*(m+1));
cudaMalloc((void**)&csrColIndC, sizeof(int)*nnz);
cudaMalloc((void**)&csrValC, sizeof(float)*nnz);
cusparseSgebsr2csr(handle, dir, mb, nb,
descrA,
bsrValA, bsrRowPtrA, bsrColIndA,
rowBlockDim, colBlockDim,
descrC,
csrValC, csrRowPtrC, csrColIndC);
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 214
cuSPARSE Format Conversion Reference
Output
csrValC <type> array of nnz non-zero elements of matrix
C.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (mb, nb<0
is not base-0 or base-1, or rowBlockDim,
colBlockDim<1).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 215
cuSPARSE Format Conversion Reference
12.7. cusparse<t>csr2gebsr_bufferSize()
cusparseStatus_t
cusparseScsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
cusparseStatus_t
cusparseDcsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
cusparseStatus_t
cusparseCcsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
cusparseStatus_t
cusparseZcsr2gebsr_bufferSize(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int rowBlockDim,
int colBlockDim,
int *pBufferSize)
This function returns the size of the buffer used in computing csr2gebsrNnz and
csr2gebsr.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 216
cuSPARSE Format Conversion Reference
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
Output
pBufferSize host pointer containing number of bytes of
the buffer used in csr2gebsrNnz() and
csr2gebsr().
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n<0, or
rowBlockDim, colBlockDim<1).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 217
cuSPARSE Format Conversion Reference
12.8. cusparse<t>csr2gebsr()
cusparseStatus_t
cusparseXcsr2gebsrNnz(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrC,
int *bsrRowPtrC,
int rowBlockDim,
int colBlockDim,
int *nnzTotalDevHostPtr,
void *pBuffer )
cusparseStatus_t
cusparseScsr2gebsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrC,
float *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC,
int rowBlockDim,
int colBlockDim,
void *pBuffer)
cusparseStatus_t
cusparseDcsr2gebsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrC,
double *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC,
int rowBlockDim,
int colBlockDim,
void *pBuffer)
cusparseStatus_t
cusparseCcsr2gebsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
const cusparseMatDescr_t descrC,
www.nvidia.com
cuComplex *bsrValC,
int
cuSPARSE *bsrRowPtrC,
Library DU-06709-001_v8.0 | 218
int *bsrColIndC,
cuSPARSE Format Conversion Reference
This function converts a sparse matrix A in CSR format (that is defined by arrays
csrValA, csrRowPtrA, and csrColIndA) into a sparse matrix C in general BSR format
(that is defined by the three arrays bsrValC, bsrRowPtrC, and bsrColIndC).
The matrix A is a m*n sparse matrix and matrix C is a
(mb*rowBlockDim)*(nb*colBlockDim) sparse matrix, where mb(=(m
+rowBlockDim-1)/rowBlockDim) is the number of block rows of C, and nb(=(n
+colBlockDim-1)/colBlockDim) is the number of block columns of C.
The block of C is of size rowBlockDim*colBlockDim. If m is not multiple of
rowBlockDim or n is not multiple of colBlockDim, zeros are filled in.
The implementation adopts a two-step approach to do the conversion. First, the user
allocates bsrRowPtrC of mb+1 elements and uses function cusparseXcsr2gebsrNnz()
to determine the number of nonzero block columns per block row. Second, the
user gathers nnzb (number of nonzero block columns of matrix C) from either
(nnzb=*nnzTotalDevHostPtr) or (nnzb=bsrRowPtrC[mb]-bsrRowPtrC[0]) and
allocates bsrValC of nnzb*rowBlockDim*colBlockDim elements and bsrColIndC of
nnzb integers. Finally function cusparse[S|D|C|Z]csr2gebsr() is called to complete
the conversion.
The user must obtain the size of the buffer required by csr2gebsr() by calling
csr2gebsr_bufferSize(), allocate the buffer, and pass the buffer pointer to
csr2gebsr().
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 219
cuSPARSE Format Conversion Reference
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 220
cuSPARSE Format Conversion Reference
Output
bsrValC <type> array of
nnzb*rowBlockDim*colBlockDim nonzero
elements of matrix C.
bsrRowPtrC integer array of mb+1 elements that contains the
start of every block row and the end of the last
block row plus one of matrix C.
bsrColIndC integer array of nnzb column indices of the
nonzero blocks of matrix C.
nnzTotalDevHostPtr total number of nonzero blocks of matrix C.
Pointer nnzTotalDevHostPtr can point to a
device memory or host memory.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n<0, baseIdx
is not base-0 or base-1, or rowBlockDim,
colBlockDim<1).
12.9. cusparse<t>coo2csr()
cusparseStatus_t
cusparseXcoo2csr(cusparseHandle_t handle, const int *cooRowInd,
int nnz, int m, int *csrRowPtr, cusparseIndexBase_t
idxBase)
This function converts the array containing the uncompressed row indices
(corresponding to COO format) into an array of compressed row pointers
(corresponding to CSR format).
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 221
cuSPARSE Format Conversion Reference
It can also be used to convert the array containing the uncompressed column indices
(corresponding to COO format) into an array of column pointers (corresponding to CSC
format).
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
cooRowInd integer array of nnz uncompressed row indices.
nnz number of non-zeros of the sparse matrix (that is
also the length of array cooRowInd).
m number of rows of matrix A.
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
csrRowPtr integer array of m+1 elements that contains the
start of every row and the end of the last row plus
one.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE idxBase is neither CUSPARSE_INDEX_BASE_ZERO
nor CUSPARSE_INDEX_BASE_ONE.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 222
cuSPARSE Format Conversion Reference
12.10. cusparse<t>csc2dense()
cusparseStatus_t
cusparseScsc2dense(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const float *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
float *A, int lda)
cusparseStatus_t
cusparseDcsc2dense(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const double *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
double *A, int lda)
cusparseStatus_t
cusparseCcsc2dense(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuComplex *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
cuComplex *A, int lda)
cusparseStatus_t
cusparseZcsc2dense(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
cuDoubleComplex *A, int lda)
This function converts the sparse matrix in CSC format that is defined by the three
arrays cscValA, cscColPtrA, and cscRowIndA into the matrix A in dense format. The
dense matrix A is filled in with the values of the sparse matrix and with zeros elsewhere.
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix A.
n number of columns of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 223
cuSPARSE Format Conversion Reference
Output
A array of dimensions (lda, n) that is filled in with
the values of the sparse matrix.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.11. cusparse<t>csc2hyb()
cusparseStatus_t
cusparseScsc2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const float *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseDcsc2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const double *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseCcsc2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuComplex *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseZcsc2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *cscValA,
const int *cscRowIndA, const int *cscColPtrA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
This function converts a sparse matrix in CSC format into a sparse matrix in
HYB format. It assumes that the hybA parameter has been initialized with the
cusparseCreateHybMat() routine before calling this function.
This function requires some amount of temporary storage and a significant amount of
storage for the matrix in HYB format. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 224
cuSPARSE Format Conversion Reference
Output
hybA the matrix A in HYB storage format.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 225
cuSPARSE Format Conversion Reference
12.12. cusparse<t>csr2bsr()
cusparseStatus_t
cusparseXcsr2bsrNnz(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const int *csrRowPtrA,
const int *csrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
int *bsrRowPtrC,
int *nnzTotalDevHostPtr)
cusparseStatus_t
cusparseScsr2bsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
float *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC)
cusparseStatus_t
cusparseDcsr2bsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
double *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC)
cusparseStatus_t
cusparseCcsr2bsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
int blockDim,
const cusparseMatDescr_t descrC,
cuComplex *bsrValC,
int *bsrRowPtrC,
int *bsrColIndC)
cusparseStatus_t
cusparseZcsr2bsr(cusparseHandle_t handle,
cusparseDirection_t dir,
int m,
int n,
const cusparseMatDescr_t descrA,
www.nvidia.com
const cuDoubleComplex *csrValA,
const int *csrRowPtrA,
cuSPARSE Library DU-06709-001_v8.0 | 226
const int *csrColIndA,
cuSPARSE Format Conversion Reference
This function converts a sparse matrix in CSR format that is defined by the three arrays
csrValA, csrRowPtrA, and csrColIndA into a sparse matrix in BSR format that is
defined by arrays bsrValC, bsrRowPtrC, and bsrColIndC.
A is an m*n sparse matrix. The BSR format of A has mb block rows, nb block columns,
and nnzb nonzero blocks, where mb=((m+blockDim-1)/blockDim) and nb=(n
+blockDim-1)/blockDim.
If m or n is not multiple of blockDim, zeros are filled in.
The conversion in cuSPARSE entails a two-step approach. First, the user allocates
bsrRowPtrC of mb+1 elements and uses function cusparseXcsr2bsrNnz()
to determine the number of nonzero block columns per block row. Second, the
user gathers nnzb (number of non-zero block columns of matrix C) from either
(nnzb=*nnzTotalDevHostPtr) or (nnzb=bsrRowPtrC[mb]-bsrRowPtrC[0]) and
allocates bsrValC of nnzb*blockDim*blockDim elements and bsrColIndC of nnzb
elements. Finally function cusparse[S|D|C|Z]csr2bsr90 is called to complete the
conversion.
The general procedure is as follows:
// Given CSR format (csrRowPtrA, csrcolIndA, csrValA) and
// blocks of BSR format are stored in column-major order.
cusparseDirection_t dir = CUSPARSE_DIRECTION_COLUMN;
int base, nnzb;
int mb = (m + blockDim-1)/blockDim;
cudaMalloc((void**)&bsrRowPtrC, sizeof(int) *(mb+1));
// nnzTotalDevHostPtr points to host memory
int *nnzTotalDevHostPtr = &nnzb;
cusparseXcsr2bsrNnz(handle, dir, m, n,
descrA, csrRowPtrA, csrColIndA,
blockDim,
descrC, bsrRowPtrC,
nnzTotalDevHostPtr);
if (NULL != nnzTotalDevHostPtr){
nnzb = *nnzTotalDevHostPtr;
}else{
cudaMemcpy(&nnzb, bsrRowPtrC+mb, sizeof(int), cudaMemcpyDeviceToHost);
cudaMemcpy(&base, bsrRowPtrC, sizeof(int), cudaMemcpyDeviceToHost);
nnzb -= base;
}
cudaMalloc((void**)&bsrColIndC, sizeof(int)*nnzb);
cudaMalloc((void**)&bsrValC, sizeof(float)*(blockDim*blockDim)*nnzb);
cusparseScsr2bsr(handle, dir, m, n,
descrA,
csrValA, csrRowPtrA, csrColIndA,
blockDim,
descrC,
bsrValC, bsrRowPtrC, bsrColIndC);
If blockDim is large (typically, a block cannot fit into shared memory), cusparse[S|
D|C|Z]csr2bsr() allocates a temporary integer array of size mb*blockDim integers. If
device memory is not available, CUSPARSE_STATUS_ALLOC_FAILED is returned.
Input
handle handle to the cuSPARSE library context.
dir storage format of blocks, either
CUSPARSE_DIRECTION_ROW or
CUSPARSE_DIRECTION_COLUMN.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 227
cuSPARSE Format Conversion Reference
Output
bsrValC <type> array of nnzb*blockDim*blockDim
nonzero elements of matrix C.
bsrRowPtrC integer array of mb+1 elements that contains the
start of every block row and the end of the last
block row plus one of matrix C.
bsrColIndC integer array of nnzb column indices of the non-
zero blocks of matrix C.
nnzTotalDevHostPtr total number of nonzero elements in device or
host memory. It is equal to (bsrRowPtrC[mb]-
bsrRowPtrC[0]).
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
IndexBase field of descrA, descrC is not base-0
or base-1, dir is not row-major or column-major,
or blockDim is not between 1 and min(m,n).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.13. cusparse<t>csr2coo()
cusparseStatus_t
cusparseXcsr2coo(cusparseHandle_t handle, const int *csrRowPtr,
int nnz, int m, int *cooRowInd,
cusparseIndexBase_t idxBase)
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 228
cuSPARSE Format Conversion Reference
This function converts the array containing the compressed row pointers (corresponding
to CSR format) into an array of uncompressed row indices (corresponding to COO
format).
It can also be used to convert the array containing the compressed column indices
(corresponding to CSC format) into an array of uncompressed column indices
(corresponding to COO format).
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
csrRowPtr integer array of m+1 elements that contains the
start of every row and the end of the last row plus
one.
nnz number of nonzeros of the sparse matrix (that is
also the length of array cooRowInd).
m number of rows of matrix A.
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
cooRowInd integer array of nnz uncompressed row indices.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE idxBase is neither CUSPARSE_INDEX_BASE_ZERO
nor CUSPARSE_INDEX_BASE_ONE.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 229
cuSPARSE Format Conversion Reference
12.14. cusparse<t>csr2csc()
cusparseStatus_t
cusparseScsr2csc(cusparseHandle_t handle, int m, int n, int nnz,
const float *csrVal, const int *csrRowPtr,
const int *csrColInd, float *cscVal,
int *cscRowInd, int *cscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseDcsr2csc(cusparseHandle_t handle, int m, int n, int nnz,
const double *csrVal, const int *csrRowPtr,
const int *csrColInd, double *cscVal,
int *cscRowInd, int *cscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseCcsr2csc(cusparseHandle_t handle, int m, int n, int nnz,
const cuComplex *csrVal, const int *csrRowPtr,
const int *csrColInd, cuComplex *cscVal,
int *cscRowInd, int *cscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t idxBase)
cusparseStatus_t
cusparseZcsr2csc(cusparseHandle_t handle, int m, int n, int nnz,
const cuDoubleComplex *csrVal, const int *csrRowPtr,
const int *csrColInd, cuDoubleComplex *cscVal,
int *cscRowInd, int *cscColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t idxBase)
This function converts a sparse matrix in CSR format (that is defined by the three
arrays csrVal, csrRowPtr, and csrColInd) into a sparse matrix in CSC format (that is
defined by arrays cscVal, cscRowInd, and cscColPtr). The resulting matrix can also
be seen as the transpose of the original sparse matrix. Notice that this routine can also be
used to convert a matrix in CSC format into a matrix in CSR format.
This function requires a significant amount of extra storage that is proportional to the
matrix size. It is executed asynchronously with respect to the host, and it may return
control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix .
n number of columns of matrix .
nnz number of nonzero elements of matrix .
csrVal <type> array of nnz csrRowPtr(m)
csrRowPtr(0) nonzero elements of matrix .
csrRowPtr integer array of m+1 elements that contains the
start of every row and the end of the last row plus
one.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 230
cuSPARSE Format Conversion Reference
idxBase CUSPARSE_INDEX_BASE_ZERO or
CUSPARSE_INDEX_BASE_ONE.
Output
cscVal <type> array of nnz cscColPtr(n)
cscColPtr(0) nonzero elements of matrix
. It is only filled in if copyValues is set to
CUSPARSE_ACTION_NUMERIC.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
12.15. cusparseCsr2cscEx()
cusparseStatus_t cusparseCsr2cscEx(cusparseHandle_t handle,
int m, int n, int nnz,
const void *csrSortedVal,
cudaDataType csrSortedValtype,
const int *csrSortedRowPtr,
const int *csrSortedColInd,
void *cscSortedVal, cudaDataType
cscSortedValtype,
int *cscSortedRowInd,
int *cscSortedColPtr,
cusparseAction_t copyValues,
cusparseIndexBase_t idxBase,
cudaDataType executiontype);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 231
cuSPARSE Format Conversion Reference
This function does not support half-precision execution type, but it supports half-
precision IO with single precision execution.
Input specifically required by cusparseCsr2cscEx
csrSortedValAtype Data type of csrSortedValA.
cscSortedValAtype Data type of cscSortedValA.
executiontype Data type used for computation.
12.16. cusparse<t>csr2dense()
cusparseStatus_t cusparseScsr2dense(cusparseHandle_t handle,
int m,
int n,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA,
const int *csrColIndA,
float *A,
int lda)
This function converts the sparse matrix in CSR format (that is defined by the three
arrays csrValA, csrRowPtrA, and csrColIndA) into the matrix A in dense format. The
dense matrix A is filled in with the values of the sparse matrix and with zeros elsewhere.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 232
cuSPARSE Format Conversion Reference
This function requires no extra storage. It is executed asynchronously with respect to the
host, and it may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix .
n number of columns of matrix .
descrA the descriptor of matrix . The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
A array of dimensions (lda,n) that is filled in with
the values of the sparse matrix.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 233
cuSPARSE Format Conversion Reference
12.17. cusparse<t>csr2csr_compress()
cusparseStatus_t cusparseScsr2csr_compress(cusparseHandle_t handle,
int m,
int n,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrColIndA,
const int *csrRowPtrA,
int inNnz,
int *nnzPerRow,
float *outVal,
int *outColInd,
int *outRowPtr,
float tol);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 234
cuSPARSE Format Conversion Reference
This function compresses the sparse matrix in CSR format (that is defined by the three
arrays csrValA, csrRowPtrA, and csrColIndA) into the matrix A in csr format, but
with small values removed. The csr matrix on output is filled with the values of the
sparse matrix which have magnitude exceeding the tol threshold. Note, in the case of
complex values, only the magnitude of the real part is used in the check.
This function requires the user to allocate one integer for the output nnzPerRow value, a
typed value array for the outVal array, and two integer arrays for the column indices and
row pointer arrays. It is executed asynchronously with respect to the host, and it may
return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix .
n number of columns of matrix .
descrA the descriptor of matrix . The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
nnzPerRow On output, this array contains the number of
elements kept in the compressed matrix, by row.
An associated totalNnz is used internally to size
the return values and column indices arrays.
outVal On output, this array contains the typed values of
elements kept in the compressed matrix. Size =
totalNnz
outColInd On output, this integer array contains the column
indices of elements kept in the compressed matrix.
Size = totalNnz
outRowPtr On output, this integer array contains the row
pointers for elements kept in the compressed
matrix. Size = m+1
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 235
cuSPARSE Format Conversion Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.18. cusparse<t>csr2hyb()
cusparseStatus_t
cusparseScsr2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const float *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseDcsr2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const double *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseCcsr2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseZcsr2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *csrValA,
const int *csrRowPtrA, const int *csrColIndA,
cusparseHybMat_t hybA, int userEllWidth,
cusparseHybPartition_t partitionType)
This function converts a sparse matrix in CSR format into a sparse matrix in
HYB format. It assumes that the hybA parameter has been initialized with
cusparseCreateHybMat() routine before calling this function.
This function requires some amount of temporary storage and a significant amount of
storage for the matrix in HYB format. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix A.
n number of columns of matrix A.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 236
cuSPARSE Format Conversion Reference
Output
hybA the matrix A in HYB storage format.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 237
cuSPARSE Format Conversion Reference
12.19. cusparse<t>dense2csc()
cusparseStatus_t
cusparseSdense2csc(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const float *A,
int lda, const int *nnzPerCol,
float *cscValA,
int *cscRowIndA, int *cscColPtrA)
cusparseStatus_t
cusparseDdense2csc(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const double *A,
int lda, const int *nnzPerCol,
double *cscValA,
int *cscRowIndA, int *cscColPtrA)
cusparseStatus_t
cusparseCdense2csc(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuComplex *A,
int lda, const int *nnzPerCol,
cuComplex *cscValA,
int *cscRowIndA, int *cscColPtrA)
cusparseStatus_t
cusparseZdense2csc(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *A,
int lda, const int *nnzPerCol,
cuDoubleComplex *cscValA,
int *cscRowIndA, int *cscColPtrA)
This function converts the matrix A in dense format into a sparse matrix in CSC format.
All the parameters are assumed to have been pre-allocated by the user, and the arrays
are filled in based on nnzPerCol, which can be precomputed with cusparse<t>nnz().
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix A.
n number of columns of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 238
cuSPARSE Format Conversion Reference
Output
cscValA <type> array of nnz cscRowPtrA(m)
cscRowPtrA(0) nonzero elements of matrix
A. It is only filled in if copyValues is set to
CUSPARSE_ACTION_NUMERIC.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.20. cusparse<t>dense2csr()
cusparseStatus_t
cusparseSdense2csr(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const float *A,
int lda, const int *nnzPerRow,
float *csrValA,
int *csrRowPtrA, int *csrColIndA)
cusparseStatus_t
cusparseDdense2csr(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const double *A,
int lda, const int *nnzPerRow,
double *csrValA,
int *csrRowPtrA, int *csrColIndA)
cusparseStatus_t
cusparseCdense2csr(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuComplex *A,
int lda, const int *nnzPerRow,
cuComplex *csrValA,
int *csrRowPtrA, int *csrColIndA)
cusparseStatus_t
cusparseZdense2csr(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *A,
int lda, const int *nnzPerRow,
cuDoubleComplex *csrValA,
int *csrRowPtrA, int *csrColIndA)
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 239
cuSPARSE Format Conversion Reference
This function converts the matrix A in dense format into a sparse matrix in CSR format.
All the parameters are assumed to have been pre-allocated by the user and the arrays are
filled in based on nnzPerRow, which can be pre-computed with cusparse<t>nnz().
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix A.
n number of columns of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
Also, the supported index bases are
CUSPARSE_INDEX_BASE_ZERO and
CUSPARSE_INDEX_BASE_ONE.
Output
csrValA <type> array of nnz csrRowPtrA(m)
csrRowPtrA(0) nonzero elements of matrix A.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 240
cuSPARSE Format Conversion Reference
12.21. cusparse<t>dense2hyb()
cusparseStatus_t
cusparseSdense2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const float *A,
int lda, const int *nnzPerRow, cusparseHybMat_t hybA,
int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseDdense2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const double *A,
int lda, const int *nnzPerRow, cusparseHybMat_t
hybA,
int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseCdense2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuComplex *A,
int lda, const int *nnzPerRow, cusparseHybMat_t hybA,
int userEllWidth,
cusparseHybPartition_t partitionType)
cusparseStatus_t
cusparseZdense2hyb(cusparseHandle_t handle, int m, int n,
const cusparseMatDescr_t descrA,
const cuDoubleComplex *A,
int lda, const int *nnzPerRow, cusparseHybMat_t hybA,
int userEllWidth,
cusparseHybPartition_t partitionType)
This function converts matrix A in dense format into a sparse matrix in HYB format.
It assumes that the routine cusparseCreateHybMat() was used to initialize the
opaque structure hybA and that the array nnzPerRow was pre-computed with
cusparse<t>nnz().
This function requires some amount of temporary storage and a significant amount of
storage for the matrix in HYB format. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
m number of rows of matrix .
n number of columns of matrix A.
descrA the descriptor of matrix A. The supported matrix
type is CUSPARSE_MATRIX_TYPE_GENERAL.
A array of dimensions (lda, n).
lda leading dimension of dense array A.
nnzPerRow array of size m containing the number of nonzero
elements per row.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 241
cuSPARSE Format Conversion Reference
Output
hybA the matrix A in HYB storage format.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.22. cusparse<t>hyb2csc()
cusparseStatus_t
cusparseShyb2csc(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
float *cscValA, int *cscRowIndA, int *cscColPtrA)
cusparseStatus_t
cusparseDhyb2csc(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
double *cscValA, int *cscRowIndA, int *cscColPtrA)
cusparseStatus_t
cusparseChyb2csc(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
cuComplex *cscValA, int *cscRowIndA, int *cscColPtrA)
cusparseStatus_t
cusparseZhyb2csc(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
cuDoubleComplex *cscValA, int *cscRowIndA, int
*cscColPtrA)
This function converts a sparse matrix in HYB format into a sparse matrix in CSC
format.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 242
cuSPARSE Format Conversion Reference
Output
cscValA <type> array of nnz cscColPtrA(m)
cscColPtrA(0) nonzero elements of matrix A.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 243
cuSPARSE Format Conversion Reference
12.23. cusparse<t>hyb2csr()
cusparseStatus_t
cusparseShyb2csr(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
float *csrValA, int *csrRowPtrA, int *csrColIndA)
cusparseStatus_t
cusparseDhyb2csr(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
double *csrValA, int *csrRowPtrA, int *csrColIndA)
cusparseStatus_t
cusparseChyb2csr(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
cuComplex *csrValA, int *csrRowPtrA, int *csrColIndA)
cusparseStatus_t
cusparseZhyb2csr(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
cuDoubleComplex *csrValA, int *csrRowPtrA, int
*csrColIndA)
This function converts a sparse matrix in HYB format into a sparse matrix in CSR
format.
This function requires some amount of temporary storage. It is executed asynchronously
with respect to the host and may return control to the application on the host before the
result is ready.
Input
handle handle to the cuSPARSE library context.
descrA the descriptor of matrix A in Hyb
format. The supported matrix type is
CUSPARSE_MATRIX_TYPE_GENERAL.
Output
csrValA <type> array of nnz csrRowPtrA(m)
csrRowPtrA(0) nonzero elements of matrix A.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 244
cuSPARSE Format Conversion Reference
12.24. cusparse<t>hyb2dense()
cusparseStatus_t
cusparseShyb2dense(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
float *A,
int lda)
cusparseStatus_t
cusparseDhyb2dense(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
double *A,
int lda)
cusparseStatus_t
cusparseChyb2dense(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
cuComplex *A,
int lda)
cusparseStatus_t
cusparseZhyb2dense(cusparseHandle_t handle,
const cusparseMatDescr_t descrA,
const cusparseHybMat_t hybA,
cuDoubleComplex *A,
int lda)
This function converts a sparse matrix in HYB format (contained in the opaque
structure ) into matrix A in dense format. The dense matrix A is filled in with the values
of the sparse matrix and with zeros elsewhere.
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
descrA the descriptor of matrix A in Hyb
format. The supported matrix type is
CUSPARSE_MATRIX_TYPE_GENERAL.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 245
cuSPARSE Format Conversion Reference
Output
A array of dimensions (lda, n) that is filled in with
the values of the sparse matrix.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE the internally stored hyb format parameters are
invalid.
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.25. cusparse<t>nnz()
cusparseStatus_t
cusparseSnnz(cusparseHandle_t handle, cusparseDirection_t dirA, int m,
int n, const cusparseMatDescr_t descrA,
const float *A,
int lda, int *nnzPerRowColumn, int *nnzTotalDevHostPtr)
cusparseStatus_t
cusparseDnnz(cusparseHandle_t handle, cusparseDirection_t dirA, int m,
int n, const cusparseMatDescr_t descrA,
const double *A,
int lda, int *nnzPerRowColumn, int *nnzTotalDevHostPtr)
cusparseStatus_t
cusparseCnnz(cusparseHandle_t handle, cusparseDirection_t dirA, int m,
int n, const cusparseMatDescr_t descrA,
const cuComplex *A,
int lda, int *nnzPerRowColumn, int *nnzTotalDevHostPtr)
cusparseStatus_t
cusparseZnnz(cusparseHandle_t handle, cusparseDirection_t dirA, int m,
int n, const cusparseMatDescr_t descrA,
const cuDoubleComplex *A,
int lda, int *nnzPerRowColumn, int *nnzTotalDevHostPtr)
This function computes the number of nonzero elements per row or column and the
total number of nonzero elements in a dense matrix.
This function requires no extra storage. It is executed asynchronously with respect to the
host and may return control to the application on the host before the result is ready.
Input
handle handle to the cuSPARSE library context.
dirA direction that specifies whether to count nonzero
elements by CUSPARSE_DIRECTION_ROW or by
CUSPARSE_DIRECTION_COLUMN.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 246
cuSPARSE Format Conversion Reference
Output
nnzPerRowColumn array of size m or n containing the number of
nonzero elements per row or column, respectively.
nnzTotalDevHostPtr total number of nonzero elements in device or host
memory.
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_ALLOC_FAILED the resources could not be allocated.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m, n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.26. cusparseCreateIdentityPermutation()
cusparseStatus_t
cusparseCreateIdentityPermutation(cusparseHandle_t handle,
int n,
int *p);
This function creates an identity map. The output parameter p represents such map by p
= 0:1:(n-1).
This function is typically used with coosort, csrsort, cscsort, csr2csc_indexOnly.
Input
parameter device or host description
Output
parameter device or host description
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 247
cuSPARSE Format Conversion Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
12.27. cusparseXcoosort()
cusparseStatus_t
cusparseXcoosort_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
const int *cooRows,
const int *cooCols,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseXcoosortByRow(cusparseHandle_t handle,
int m,
int n,
int nnz,
int *cooRows,
int *cooCols,
int *P,
void *pBuffer);
cusparseStatus_t
cusparseXcoosortByColumn(cusparseHandle_t handle,
int m,
int n,
int nnz,
int *cooRows,
int *cooCols,
int *P,
void *pBuffer);
This function sorts COO format. The stable sorting is in-place. Also the user can sort by
row or sort by column.
A is an m×n sparse matrix that is defined in COO storage format by the three arrays
cooVals, cooRows, and cooCols.
The matrix must be base 0.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 248
cuSPARSE Format Conversion Reference
Input
parameter device or host description
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 249
cuSPARSE Format Conversion Reference
Output
parameter device or host description
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (n<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
12.28. cusparseXcsrsort()
cusparseStatus_t
cusparseXcsrsort_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
const int *csrRowPtr,
const int *csrColInd,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseXcsrsort(cusparseHandle_t handle,
int m,
int n,
int nnz,
const cusparseMatDescr_t descrA,
const int *csrRowPtr,
int *csrColInd,
int *P,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 250
cuSPARSE Format Conversion Reference
The parameter P is both input and output. If the user wants to compute sorted csrVal,
P must be set as 0:1:(nnz-1) before csrsort(), and after csrsort(), new sorted value
array satisfies csrVal_sorted = csrVal(P).
The general procedure is as follows:
Input
parameter device or host description
Output
parameter device or host description
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 251
cuSPARSE Format Conversion Reference
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED the matrix type is not supported.
12.29. cusparseXcscsort()
cusparseStatus_t
cusparseXcscsort_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
const int *cscColPtr,
const int *cscRowInd,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseXcscsort(cusparseHandle_t handle,
int m,
int n,
int nnz,
const cusparseMatDescr_t descrA,
const int *cscColPtr,
int *cscRowInd,
int *P,
void *pBuffer);
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 252
cuSPARSE Format Conversion Reference
Input
parameter device or host description
Output
parameter device or host description
Status Returned
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 253
cuSPARSE Format Conversion Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 254
cuSPARSE Format Conversion Reference
12.30. cusparseXcsru2csr()
cusparseStatus_t
cusparseScsru2csr_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
float *csrVal,
const int *csrRowPtr,
int *csrColInd,
csru2csrInfo_t info,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseDcsru2csr_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
double *csrVal,
const int *csrRowPtr,
int *csrColInd,
csru2csrInfo_t info,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseCcsru2csr_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
cuComplex *csrVal,
const int *csrRowPtr,
int *csrColInd,
csru2csrInfo_t info,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseZcsru2csr_bufferSizeExt(
cusparseHandle_t handle,
int m,
int n,
int nnz,
cuDoubleComplex *csrVal,
const int *csrRowPtr,
int *csrColInd,
csru2csrInfo_t info,
size_t *pBufferSizeInBytes);
cusparseStatus_t
cusparseScsru2csr(cusparseHandle_t handle,
int m,
int n,
int nnz,
const cusparseMatDescr_t descrA,
www.nvidia.com float *csrVal,
cuSPARSE Library const int *csrRowPtr, DU-06709-001_v8.0 | 255
int *csrColInd,
cuSPARSE Format Conversion Reference
This function transfers unsorted CSR format to CSR format, and vice versa. The
operation is in-place.
This function is a wrapper of csrsort and gthr. The usecase is the following scenario.
If the user has a matrix A of CSR format which is unsorted, and implements his own
code (which can be CPU or GPU kernel) based on this special order (for example,
diagonal first, then lower triangle, then upper triangle), and wants to convert it to CSR
format when calling CUSPARSE library, and then convert it back when doing something
else on his/her kernel. For example, suppose the user wants to solve a linear system
Ax=b by the following iterative scheme
The code heavily uses SpMv and triangular solve. Assume that the user has an in-
house design of SpMV (Sparse Matrix-Vector multiplication) based on special order
of A. However the user wants to use CUSAPRSE library for triangular solver. Then the
following code can work.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 256
cuSPARSE Format Conversion Reference
csrRowsPtr device integer array of m+1 elements that contains the start of
every row and the end of the last row plus one.
csrColInd device integer array of nnz unsorted column indices of A.
info host opaque structure initialized using
cusparseCreateCsru2csrInfo().
Output
parameter device or host description
Status Returned
CUSPARSE_STATUS_SUCCESS the operation completed successfully.
CUSPARSE_STATUS_NOT_INITIALIZED the library was not initialized.
CUSPARSE_STATUS_INVALID_VALUE invalid parameters were passed (m,n,nnz<0).
CUSPARSE_STATUS_ARCH_MISMATCH the device does not support double precision.
CUSPARSE_STATUS_EXECUTION_FAILED the function failed to launch on the GPU.
CUSPARSE_STATUS_INTERNAL_ERROR an internal operation failed.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 257
cuSPARSE Format Conversion Reference
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 258
Chapter 13.
APPENDIX A: CUSPARSE LIBRARY C++
EXAMPLE
For sample code reference please see the example code below. It shows an application
written in C++ using the cuSPARSE library API. The code performs the following
actions:
1. Creates a sparse test matrix in COO format.
2. Creates a sparse and dense vector.
3. Allocates GPU memory and copies the matrix and vectors into it.
4. Initializes the cuSPARSE library.
5. Creates and sets up the matrix descriptor.
6. Converts the matrix from COO to CSR format.
7. Exercises Level 1 routines.
8. Exercises Level 2 routines.
9. Exercises Level 3 routines.
10. Destroys the matrix descriptor.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 259
Appendix A: cuSPARSE Library C++ Example
#define CLEANUP(s) \
do { \
printf ("%s\n", s); \
if (yHostPtr) free(yHostPtr); \
if (zHostPtr) free(zHostPtr); \
if (xIndHostPtr) free(xIndHostPtr); \
if (xValHostPtr) free(xValHostPtr); \
if (cooRowIndexHostPtr) free(cooRowIndexHostPtr);\
if (cooColIndexHostPtr) free(cooColIndexHostPtr);\
if (cooValHostPtr) free(cooValHostPtr); \
if (y) cudaFree(y); \
if (z) cudaFree(z); \
if (xInd) cudaFree(xInd); \
if (xVal) cudaFree(xVal); \
if (csrRowPtr) cudaFree(csrRowPtr); \
if (cooRowIndex) cudaFree(cooRowIndex); \
if (cooColIndex) cudaFree(cooColIndex); \
if (cooVal) cudaFree(cooVal); \
if (descr) cusparseDestroyMatDescr(descr);\
if (handle) cusparseDestroy(handle); \
cudaDeviceReset(); \
fflush (stdout); \
} while (0)
int main(){
cudaError_t cudaStat1,cudaStat2,cudaStat3,cudaStat4,cudaStat5,cudaStat6;
cusparseStatus_t status;
cusparseHandle_t handle=0;
cusparseMatDescr_t descr=0;
int * cooRowIndexHostPtr=0;
int * cooColIndexHostPtr=0;
double * cooValHostPtr=0;
int * cooRowIndex=0;
int * cooColIndex=0;
double * cooVal=0;
int * xIndHostPtr=0;
double * xValHostPtr=0;
double * yHostPtr=0;
int * xInd=0;
double * xVal=0;
double * y=0;
int * csrRowPtr=0;
double * zHostPtr=0;
double * z=0;
int n, nnz, nnz_vector;
double dzero =0.0;
double dtwo =2.0;
double dthree=3.0;
double dfive =5.0;
printf("testing example\n");
/* create the following sparse test matrix in COO format */
/* |1.0 2.0 3.0|
| 4.0 |
|5.0 6.0 7.0|
| 8.0 9.0| */
n=4; nnz=9;
cooRowIndexHostPtr = (int *) malloc(nnz*sizeof(cooRowIndexHostPtr[0]));
cooColIndexHostPtr = (int *) malloc(nnz*sizeof(cooColIndexHostPtr[0]));
cooValHostPtr = (double *)malloc(nnz*sizeof(cooValHostPtr[0]));
if ((!cooRowIndexHostPtr) || (!cooColIndexHostPtr) || (!cooValHostPtr)){
CLEANUP("Host malloc failed (matrix)");
return 1;
www.nvidia.com
}
cuSPARSE Library
cooRowIndexHostPtr[0]=0; DU-06709-001_v8.0 | 260
cooColIndexHostPtr[0]=0; cooValHostPtr[0]=1.0;
cooRowIndexHostPtr[1]=0; cooColIndexHostPtr[1]=2; cooValHostPtr[1]=2.0;
cooRowIndexHostPtr[2]=0; cooColIndexHostPtr[2]=3; cooValHostPtr[2]=3.0;
Chapter 14.
APPENDIX B: CUSPARSE FORTRAN
BINDINGS
The cuSPARSE library is implemented using the C-based CUDA toolchain, and it thus
provides a C-style API that makes interfacing to applications written in C or C++ trivial.
There are also many applications implemented in Fortran that would benefit from using
cuSPARSE, and therefore a cuSPARSE Fortran interface has been developed.
Unfortunately, Fortran-to-C calling conventions are not standardized and differ by
platform and toolchain. In particular, differences may exist in the following areas:
Symbol names (capitalization, name decoration)
Argument passing (by value or reference)
Passing of pointer arguments (size of the pointer)
To provide maximum flexibility in addressing those differences, the cuSPARSE Fortran
interface is provided in the form of wrapper functions, which are written in C and
are located in the file cusparse_fortran.c. This file also contains a few additional
wrapper functions (for cudaMalloc(), cudaMemset, and so on) that can be used to
allocate memory on the GPU.
The cuSPARSE Fortran wrapper code is provided as an example only and needs to be
compiled into an application for it to call the cuSPARSE API functions. Providing this
source code allows users to make any changes necessary for a particular platform and
toolchain.
The cuSPARSE Fortran wrapper code has been used to demonstrate interoperability
with the compilers g95 0.91 (on 32-bit and 64-bit Linux) and g95 0.92 (on 32-bit and 64-
bit Mac OS X). In order to use other compilers, users have to make any changes to the
wrapper code that may be required.
The direct wrappers, intended for production code, substitute device pointers for vector
and matrix arguments in all cuSPARSE functions. To use these interfaces, existing
applications need to be modified slightly to allocate and deallocate data structures
in GPU memory space (using CUDA_MALLOC() and CUDA_FREE()) and to copy data
between GPU and CPU memory spaces (using the CUDA_MEMCPY() routines). The
sample wrappers provided in cusparse_fortran.c map device pointers to the OS-
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 261
Appendix B: cuSPARSE Fortran Bindings
dependent type size_t, which is 32 bits wide on 32-bit platforms and 64 bits wide on a
64-bit platforms.
One approach to dealing with index arithmetic on device pointers in Fortran code is to
use C-style macros and to use the C preprocessor to expand them. On Linux and Mac
OS X, preprocessing can be done by using the option '-cpp' with g95 or gfortran. The
function GET_SHIFTED_ADDRESS(), provided with the cuSPARSE Fortran wrappers,
can also be used, as shown in example B.
Example B shows the the C++ of example A implemented in Fortran 77 on the host. This
example should be compiled with ARCH_64 defined as 1 on a 64-bit OS system and as
undefined on a 32-bit OS system. For example, on g95 or gfortran, it can be done directly
on the command line using the option -cpp -DARCH_64=1.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 262
Appendix B: cuSPARSE Fortran Bindings
program cusparse_fortran_example
implicit none
integer cuda_malloc
external cuda_free
integer cuda_memcpy_c2fort_int
integer cuda_memcpy_c2fort_real
integer cuda_memcpy_fort2c_int
integer cuda_memcpy_fort2c_real
integer cuda_memset
integer cusparse_create
external cusparse_destroy
integer cusparse_get_version
integer cusparse_create_mat_descr
external cusparse_destroy_mat_descr
integer cusparse_set_mat_type
integer cusparse_get_mat_type
integer cusparse_get_mat_fill_mode
integer cusparse_get_mat_diag_type
integer cusparse_set_mat_index_base
integer cusparse_get_mat_index_base
integer cusparse_xcoo2csr
integer cusparse_dsctr
integer cusparse_dcsrmv
integer cusparse_dcsrmm
external get_shifted_address
#if ARCH_64
integer*8 handle
integer*8 descrA
integer*8 cooRowIndex
integer*8 cooColIndex
integer*8 cooVal
integer*8 xInd
integer*8 xVal
integer*8 y
integer*8 z
integer*8 csrRowPtr
integer*8 ynp1
#else
integer*4 handle
integer*4 descrA
integer*4 cooRowIndex
integer*4 cooColIndex
integer*4 cooVal
integer*4 xInd
integer*4 xVal
integer*4 y
integer*4 z
integer*4 csrRowPtr
integer*4 ynp1
#endif
integer status
integer cudaStat1,cudaStat2,cudaStat3
integer cudaStat4,cudaStat5,cudaStat6
integer n, nnz, nnz_vector
parameter (n=4, nnz=9, nnz_vector=3)
integer cooRowIndexHostPtr(nnz)
integer cooColIndexHostPtr(nnz)
real*8 cooValHostPtr(nnz)
integer xIndHostPtr(nnz_vector)
real*8 xValHostPtr(nnz_vector)
real*8 yHostPtr(2*n)
real*8 zHostPtr(2*(n+1))
integer i, j
integer version, mtype, fmode, dtype, ibase
real*8 dzero,dtwo,dthree,dfive
www.nvidia.com
cuSPARSEreal*8
Library epsilon DU-06709-001_v8.0 | 263
Chapter 15.
APPENDIX C: ACKNOWLEDGEMENTS
NVIDIA would like to thank the following individuals and institutions for their
contributions:
‣ The cusparse<t>gtsv implementation is derived from a version developed by Li-Wen
Chang from the University of Illinois.
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 264
Chapter 16.
BIBLIOGRAPHY
www.nvidia.com
cuSPARSE Library DU-06709-001_v8.0 | 265
Notice
ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS,
DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY,
"MATERIALS") ARE BEING PROVIDED "AS IS." NVIDIA MAKES NO WARRANTIES,
EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE
MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF
NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR
PURPOSE.
Information furnished is believed to be accurate and reliable. However, NVIDIA
Corporation assumes no responsibility for the consequences of use of such
information or for any infringement of patents or other rights of third parties
that may result from its use. No license is granted by implication of otherwise
under any patent rights of NVIDIA Corporation. Specifications mentioned in this
publication are subject to change without notice. This publication supersedes and
replaces all other information previously supplied. NVIDIA Corporation products
are not authorized as critical components in life support devices or systems
without express written approval of NVIDIA Corporation.
Trademarks
NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA
Corporation in the U.S. and other countries. Other company and product names
may be trademarks of the respective companies with which they are associated.
Copyright
© 2007-2017 NVIDIA Corporation. All rights reserved.
www.nvidia.com