| Files | Last commit | Last update |
|---|---|---|
SpSV Operator
Product support
| Product | Supported | Implementation Description |
|---|---|---|
| Ascend 950PR&950DT products | √ | The Ascend 950PR&950DT products interface description on this page |
| Atlas A3 products | √ | arch22 |
| Atlas A2 products | √ | arch22 |
| Atlas 200I/500 A2 inference products | × | — |
| Atlas inference products | × | — |
| Atlas training products | × | — |
The ascend910b* of Atlas A2 products and the ascend910_93* of Atlas A3 products select arch22, supporting FP32 and complex64.
For the parameters, synchronization behavior, workspace, and invocation example of Atlas A2 products and Atlas A3 products, see arch22 Interface Description,
and for compilation and regression entries, see Test Description.
By default, arch22 submits the Host queue with torch_npu loaded; pure ACL callers can disable this interoperability with
OPS_SPARSE_SPSV_TORCH_QUEUE=0. See Framework Queue Interoperability for the trigger conditions, GIL behavior, alert degradation,
submission failure, and interpreter lifecycle constraints.
The detailed interfaces and examples below target the arch35 implementation of Ascend 950PR&950DT products; the constraints of different architectures are maintained separately.
Operator Overview
The SpSV (Sparse triangular Solve - Vector) operator implements solving the linear system of a sparse triangular matrix. The core operation is op(A)·Y = alpha·X, where A is an m×m sparse triangular matrix (CSR/CSC/COO/SLICED_ELL format), X is the input dense vector, and Y is the output dense vector.
Mathematical expression:
op(A) · Y = alpha · X
where:
- op(A) is the operation of sparse square matrix A:
ACL_SPARSE_OP_NON_TRANSPOSE(non-transpose),ACL_SPARSE_OP_TRANSPOSE(transpose), andACL_SPARSE_OP_CONJUGATE_TRANSPOSE(conjugate transpose, equivalent to transpose for float32) - The type of alpha follows
computeType:ACL_FLOATcorresponds tofloat, andACL_COMPLEX64corresponds toaclsparseComplex; the pointer location is controlled byaclsparseSetPointerMode(Host or Device memory) - Matrix attributes are set through
aclsparseSpMatSetAttribute: fillMode (LOWER/UPPER) and diagType (NON_UNIT/UNIT)
SpSV adopts the three-stage execution model (bufferSize → analysis → solve), targeting the cuSPARSE cusparseSpSV Generic API. The analysis stage completes Level Scheduling preprocessing on the device side, and the solve stage performs forward/backward substitution in level order (supporting single-core/multi-core adaptive execution). All interfaces support asynchronous execution, with no D2H synchronization on the host side.
It includes the following interfaces:
| Interface | Brief Function |
|---|---|
| aclsparseSpSV_createDescr | Creates the SpSV descriptor |
| aclsparseSpSV_destroyDescr | Destroys the SpSV descriptor |
| aclsparseSpSV_bufferSize | Queries the required workspace size |
| aclsparseSpSV_analysis | Preprocessing (Level Scheduling), builds the solving schedule information |
| aclsparseSpSV_solve | Executes the triangular solving (forward/backward substitution) |
| aclsparseSpSV_updateMatrix | Updates matrix values (no re-analysis needed) |
| aclsparseSpMatSetAttribute | Sets sparse matrix attributes (fillMode / diagType) |
| aclsparseSpMatGetAttribute | Obtains sparse matrix attributes |
Operator Execution Interface
aclsparseSpSV_createDescr
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpSV_createDescr(aclsparseSpSVDescr_t *spsvDescr)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| spsvDescr | Output | aclsparseSpSVDescr_t* | SpSV descriptor pointer; Host memory |
Constraints
- spsvDescr cannot be nullptr
- Pure host memory allocation, with no device operations
aclsparseSpSV_destroyDescr
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpSV_destroyDescr(aclsparseSpSVDescr_t spsvDescr)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| spsvDescr | Input | aclsparseSpSVDescr_t | SpSV descriptor to destroy; Host memory |
Constraints
- When spsvDescr is nullptr, SUCCESS is returned directly (idempotent semantics)
aclsparseSpSV_bufferSize
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpSV_bufferSize(
aclsparseHandle_t handle, aclsparseOperation_t opA, const void *alpha,
aclsparseConstSpMatDescr_t matA, aclsparseConstDnVecDescr_t vecX,
aclsparseDnVecDescr_t vecY, aclDataType computeType,
aclsparseSpSVAlg_t alg, aclsparseSpSVDescr_t spsvDescr, size_t *bufferSize)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| handle | Input | aclsparseHandle_t | ops-sparse library context handle; Host memory |
| opA | Input | aclsparseOperation_t | Operation type of sparse matrix A; Host memory |
| alpha | Input | const void* | Scalar alpha pointer; the type follows computeType: ACL_FLOAT corresponds to float, and ACL_COMPLEX64 corresponds to aclsparseComplex; Host or Device memory (controlled by aclsparseSetPointerMode). (bufferSize only validates that alpha is non-empty and does not read its value; this parameter is retained to keep the signature consistent with analysis/solve) |
| matA | Input | aclsparseConstSpMatDescr_t | Descriptor of sparse triangular matrix A; Host memory |
| vecX | Input | aclsparseConstDnVecDescr_t | Descriptor of the input dense vector x; can be NULL; Host memory |
| vecY | Input | aclsparseDnVecDescr_t | Descriptor of the output dense vector y; can be NULL; Host memory |
| computeType | Input | aclDataType | Computation precision type; supports ACL_FLOAT / ACL_COMPLEX64; Host memory |
| alg | Input | aclsparseSpSVAlg_t | Algorithm type; only ACL_SPARSE_SPSV_ALG_DEFAULT is supported; Host memory |
| spsvDescr | Input | aclsparseSpSVDescr_t | SpSV descriptor; Host memory |
| bufferSize | Output | size_t* | Required workspace size in bytes; Host memory |
Constraints
- handle cannot be nullptr
- alpha cannot be nullptr
- bufferSize cannot be nullptr
- vecX and vecY can be NULL (the bufferSize stage does not access vector data)
- Pure host arithmetic computation, with no device operations, asynchronous safe
matAcannot be nullptrspsvDescrcannot be nullptropAmust be one of ACL_SPARSE_OP_NON_TRANSPOSE / ACL_SPARSE_OP_TRANSPOSE / ACL_SPARSE_OP_CONJUGATE_TRANSPOSE
aclsparseSpSV_analysis
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpSV_analysis(
aclsparseHandle_t handle, aclsparseOperation_t opA, const void *alpha,
aclsparseConstSpMatDescr_t matA, aclsparseConstDnVecDescr_t vecX,
aclsparseDnVecDescr_t vecY, aclDataType computeType,
aclsparseSpSVAlg_t alg, aclsparseSpSVDescr_t spsvDescr, void *externalBuffer)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| handle | Input | aclsparseHandle_t | ops-sparse library context handle; Host memory |
| opA | Input | aclsparseOperation_t | Operation type of sparse matrix A; Host memory |
| alpha | Input | const void* | Scalar alpha pointer; the type follows computeType: ACL_FLOAT corresponds to float, and ACL_COMPLEX64 corresponds to aclsparseComplex; Host or Device memory (controlled by aclsparseSetPointerMode) |
| matA | Input | aclsparseConstSpMatDescr_t | Descriptor of sparse triangular matrix A; Host memory |
| vecX | Input | aclsparseConstDnVecDescr_t | Descriptor of the input dense vector x; can be NULL; Host memory |
| vecY | Input | aclsparseDnVecDescr_t | Descriptor of the output dense vector y; can be NULL; Host memory |
| computeType | Input | aclDataType | Computation precision type; supports ACL_FLOAT / ACL_COMPLEX64; Host memory |
| alg | Input | aclsparseSpSVAlg_t | Algorithm type; only ACL_SPARSE_SPSV_ALG_DEFAULT is supported; Host memory |
| spsvDescr | Input/Output | aclsparseSpSVDescr_t | SpSV descriptor; Host memory |
| externalBuffer | Input | void* | workspace buffer (allocated after querying the size with bufferSize), Device memory |
Constraints
- handle cannot be nullptr, and
aclsparseSetStreammust be called first to set the stream - alpha cannot be nullptr
- vecX and vecY can be NULL (the analysis stage does not access vector data)
- When nnz > 0, externalBuffer cannot be nullptr
- When nnz == 0, externalBuffer can be nullptr (no workspace needed)
- analysis launches the device kernel to asynchronously execute Level Scheduling and returns immediately
- When nnz == 0, analysis does not launch a device kernel, directly caches the matrix attributes on the host side, and returns SUCCESS
- analysis is needed only once for the same matrix structure (sparsity pattern); after matrix values change, update them through updateMatrix without re-analysis
matAcannot be nullptrspsvDescrcannot be nullptropAmust be one of ACL_SPARSE_OP_NON_TRANSPOSE / ACL_SPARSE_OP_TRANSPOSE / ACL_SPARSE_OP_CONJUGATE_TRANSPOSE
aclsparseSpSV_solve
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpSV_solve(
aclsparseHandle_t handle, aclsparseOperation_t opA, const void *alpha,
aclsparseConstSpMatDescr_t matA, aclsparseConstDnVecDescr_t vecX,
aclsparseDnVecDescr_t vecY, aclDataType computeType,
aclsparseSpSVAlg_t alg, aclsparseSpSVDescr_t spsvDescr)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| handle | Input | aclsparseHandle_t | ops-sparse library context handle; Host memory |
| opA | Input | aclsparseOperation_t | Operation type of sparse matrix A; Host memory |
| alpha | Input | const void* | Scalar alpha pointer; the type follows computeType: ACL_FLOAT corresponds to float, and ACL_COMPLEX64 corresponds to aclsparseComplex; Host or Device memory (controlled by aclsparseSetPointerMode) |
| matA | Input | aclsparseConstSpMatDescr_t | Descriptor of sparse triangular matrix A; Host memory |
| vecX | Input | aclsparseConstDnVecDescr_t | Descriptor of the input dense vector x; Host memory |
| vecY | Input/Output | aclsparseDnVecDescr_t | Descriptor of the output dense vector y; Host memory |
| computeType | Input | aclDataType | Computation precision type; supports ACL_FLOAT / ACL_COMPLEX64; Host memory |
| alg | Input | aclsparseSpSVAlg_t | Algorithm type; only ACL_SPARSE_SPSV_ALG_DEFAULT is supported; Host memory |
| spsvDescr | Input | aclsparseSpSVDescr_t | SpSV descriptor (analysis must be completed); Host memory |
Constraints
- handle cannot be nullptr, and
aclsparseSetStreammust be called first to set the stream - alpha, vecX, and vecY cannot be nullptr
aclsparseSpSV_analysismust be called first to complete preprocessing; otherwise, ACL_SPARSE_STATUS_INVALID_VALUE is returned- In-place operation is supported: vecX and vecY can point to the same device memory
- solve provides deterministic (bit-wise) results: identical inputs produce identical outputs
- solve launches the device kernel to execute asynchronously and returns immediately
- When
m == 0, solve returns SUCCESS directly and does not launch a device kernel. - When
m > 0andnnz == 0, solve does not execute the regular solving kernel:ACL_SPARSE_DIAG_TYPE_UNIT: implicit unit diagonal,Y = alpha * X.ACL_SPARSE_DIAG_TYPE_NON_UNIT: the diagonal is missing and the matrix is singular; the implementation propagates Inf/NaN according to IEEE-754 division by zero. Even whenalpha == 0, it does not specially rewrite the result to a zero solution and still follows the IEEE-754 results of division by zero and0 * Inf.
matAcannot be nullptrspsvDescrcannot be nullptropAmust be one of ACL_SPARSE_OP_NON_TRANSPOSE / ACL_SPARSE_OP_TRANSPOSE / ACL_SPARSE_OP_CONJUGATE_TRANSPOSE
aclsparseSpSV_updateMatrix
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpSV_updateMatrix(
aclsparseHandle_t handle, aclsparseSpSVDescr_t spsvDescr,
void *newValues, aclsparseSpSVUpdate_t updatePart)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| handle | Input | aclsparseHandle_t | ops-sparse library context handle; Host memory |
| spsvDescr | Input | aclsparseSpSVDescr_t | SpSV descriptor (analysis must be completed); Host memory |
| newValues | Input | void* | New matrix value pointer, Device memory. GENERAL mode: nnz elements; DIAGONAL mode: m elements |
| updatePart | Input | aclsparseSpSVUpdate_t | Update policy; Host memory |
Constraints
- handle cannot be nullptr
- spsvDescr cannot be nullptr, and analysis must have been completed
- newValues cannot be nullptr
- updatePart supports:
ACL_SPARSE_SPSV_UPDATE_GENERAL: updates all non-zero values (nnz elements), with the matrix structure unchangedACL_SPARSE_SPSV_UPDATE_DIAGONAL: updates only the diagonal values (m elements)
- No re-analysis is needed after the update (the Level Schedule depends only on the matrix structure, not values)
- CSR + NON_TRANSPOSE path: only the values pointer reference inside descr is updated (no device kernel launch), and solve reads the new values directly from the user values array; the other paths (COO/SLICED_ELL, transpose operations) copy the new values through a kernel to the CSR/transpose copy in the workspace according to perm
- Asynchronous execution, returns immediately
- When the cachedNnz cached by analysis is 0, updateMatrix does not launch a kernel and returns ACL_SPARSE_STATUS_SUCCESS directly
aclsparseSpMatSetAttribute
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpMatSetAttribute(
aclsparseSpMatDescr_t spMatDescr, aclsparseSpMatAttribute_t attribute,
const void *data, size_t dataSize)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| spMatDescr | Input | aclsparseSpMatDescr_t | Sparse matrix descriptor; Host memory |
| attribute | Input | aclsparseSpMatAttribute_t | Attribute type: ACL_SPARSE_SPMAT_FILL_MODE or ACL_SPARSE_SPMAT_DIAG_TYPE; Host memory |
| data | Input | const void* | Attribute value pointer; Host memory |
| dataSize | Input | size_t | Attribute value size (in bytes); must match the attribute type |
Constraints
- spMatDescr cannot be nullptr
- data cannot be nullptr
- When attribute is
ACL_SPARSE_SPMAT_FILL_MODE: data points toaclsparseFillMode_t, dataSize must besizeof(aclsparseFillMode_t), and the value isACL_SPARSE_FILL_MODE_LOWERorACL_SPARSE_FILL_MODE_UPPER - When attribute is
ACL_SPARSE_SPMAT_DIAG_TYPE: data points toaclsparseDiagType_t, dataSize must besizeof(aclsparseDiagType_t), and the value isACL_SPARSE_DIAG_TYPE_NON_UNITorACL_SPARSE_DIAG_TYPE_UNIT - Pure host field write, with no device operations
- The
datapointer must satisfy the natural alignment requirements of the corresponding enumeration type (alignof(aclsparseFillMode_t)oralignof(aclsparseDiagType_t)); otherwise, INVALID_VALUE is returned - It is recommended that you explicitly call aclsparseSpMatSetAttribute to set fillMode and diagType before using SpSV (the defaults are LOWER / NON_UNIT; if no change is needed, the default values can be used directly)
aclsparseSpMatGetAttribute
Product support
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported
- Atlas A2 products: Supported
Function prototype
aclsparseStatus_t aclsparseSpMatGetAttribute(
aclsparseConstSpMatDescr_t spMatDescr, aclsparseSpMatAttribute_t attribute,
void *data, size_t dataSize)
Parameter description
| Parameter | Input/Output | Parameter Type | Description |
|---|---|---|---|
| spMatDescr | Input | aclsparseConstSpMatDescr_t | Sparse matrix descriptor; Host memory |
| attribute | Input | aclsparseSpMatAttribute_t | Attribute type: ACL_SPARSE_SPMAT_FILL_MODE or ACL_SPARSE_SPMAT_DIAG_TYPE; Host memory |
| data | Output | void* | Attribute value output pointer; Host memory |
| dataSize | Input | size_t | Attribute value size (in bytes); must match the attribute type |
Constraints
- spMatDescr cannot be nullptr
- data cannot be nullptr
- dataSize must match the attribute type (same as SetAttribute)
- Pure host field read, with no device operations
- The
datapointer must satisfy the natural alignment requirements of the corresponding enumeration type (alignof(aclsparseFillMode_t)oralignof(aclsparseDiagType_t)); otherwise, INVALID_VALUE is returned
Supported Data Types
| matA Value Type | vecX Value Type | vecY Value Type | computeType | Description |
|---|---|---|---|---|
| ACL_FLOAT | ACL_FLOAT | ACL_FLOAT | ACL_FLOAT | Supports the three index width combinations in the following table |
| ACL_COMPLEX64 | ACL_COMPLEX64 | ACL_COMPLEX64 | ACL_COMPLEX64 | Supports only I32 row/column indices and 32-bit workspace layout, with nnz ≤ INT32_MAX |
Supported sparse formats
| Format | Supported | Description |
|---|---|---|
| CSR | ✅ | Main path, accessing directly by row |
| CSC | ✅ | Zero-copy implementation: pointer remapping (colPtr→rowPtr, rowInd→colInd), with implicit flipping of fillMode (LOWER↔UPPER) and opA (NON_TRANSPOSE↔TRANSPOSE/CONJ) at the same time, converted to the equivalent CSR path for processing |
| COO | ✅ | The analysis stage builds a CSR copy on the device side, requiring extra workspace |
| SLICED_ELL | ✅ | The analysis stage builds a CSR copy on the device side, requiring extra workspace |
Supported Index Types
| Index Type | Supported | Description |
|---|---|---|
| ACL_SPARSE_INDEX_32I | ✅ | 32-bit signed integer index |
| ACL_SPARSE_INDEX_64I | ✅ | 64-bit signed integer index |
The following table applies to ACL_FLOAT. ACL_COMPLEX64 supports only (I32, I32), and the workspace layout must be 32-bit (nnz ≤ INT32_MAX); bufferSize, analysis, and solve all return ACL_SPARSE_STATUS_NOT_SUPPORTED for unsupported widths.
SpSV allows rowOffsets (ptrType) and colInd (idxType) to specify index widths independently, but the following support matrix must be satisfied:
| rowOffsets Type | colInd Type | Supported | Typical Scenario |
|---|---|---|---|
| I32 | I32 | ✅ | Standard path; nnz ≤ INT32_MAX |
| I64 | I32 | ✅ | Mixed-width path; nnz can exceed INT32_MAX, colInd is limited by m ≤ INT32_MAX, so I32 suffices |
| I64 | I64 | ✅ | Full I64 path; nnz can exceed INT32_MAX |
| I32 | I64 | ❌ | Not supported: I32 rowPtr cannot address nnz > INT32_MAX, and this combination has no practical scenario |
Regardless of which index type combination is used, the matrix dimension m (rows/cols) must always be ≤ INT32_MAX (arrays such as levelRow/diagPtr inside the kernel use int32_t).
Supported Matrix Operations
| Operation | Enumeration Value | Description |
|---|---|---|
| Non-transpose | ACL_SPARSE_OP_NON_TRANSPOSE | op(A) = A |
| Transpose | ACL_SPARSE_OP_TRANSPOSE | op(A) = A^T |
| Conjugate transpose | ACL_SPARSE_OP_CONJUGATE_TRANSPOSE | op(A) = A^H (equivalent to A^T for float32) |
Supported Matrix Attributes
| fillMode | Enumeration Value | Description |
|---|---|---|
| Lower triangular | ACL_SPARSE_FILL_MODE_LOWER | The non-zero elements of the matrix are on and below the main diagonal |
| Upper triangular | ACL_SPARSE_FILL_MODE_UPPER | The non-zero elements of the matrix are on and above the main diagonal |
| diagType | Enumeration Value | Description |
|---|---|---|
| Non-unit diagonal | ACL_SPARSE_DIAG_TYPE_NON_UNIT | Diagonal elements participate in the computation (division required) |
| Unit diagonal | ACL_SPARSE_DIAG_TYPE_UNIT | Diagonal elements are treated as 1 (division skipped) |
Constraints
General Constraints
- handle cannot be nullptr, and
aclsparseSetStreammust be called first to set the stream - matA must be a square matrix (rows == cols)
- The index base of matA supports
ACL_SPARSE_INDEX_BASE_ZERO(C compatibility) andACL_SPARSE_INDEX_BASE_ONE(Fortran compatibility); for 1-based input, the analysis stage builds a 0-based workspace CSR copy on the device side, requiring extra workspace - computeType supports
ACL_FLOAT/ACL_COMPLEX64 - alg supports only
ACL_SPARSE_SPSV_ALG_DEFAULT - The value types of matA, vecX, and vecY must be consistent with computeType, supporting
ACL_FLOAT/ACL_COMPLEX64 - The index widths of rowOffsets and colInd of matA can be specified independently; see the preceding "Supported Index Types" section for supported combinations; ACL_FLOAT does not support (I32, I64), and ACL_COMPLEX64 supports only (I32, I32)
- The matrix dimension m (rows/cols) must not exceed INT32_MAX (2,147,483,647); the nnz of ACL_FLOAT can exceed INT32_MAX, but in that case I64 rowOffsets must be used (ptrType=ACL_SPARSE_INDEX_64I), and colInd can be I32 or I64
- Unsorted matA indices are allowed (colInd does not need to be in ascending order within a row)
- When m == 0 and the parameters satisfy the preceding type and index constraints, bufferSize returns 0, and analysis and solve do not launch device kernels and return SUCCESS directly
- All interfaces support asynchronous execution, with no D2H synchronization on the host side
Invocation Sequence Constraints
- Create the SpSV descriptor:
aclsparseSpSV_createDescr - Set the matrix attributes:
aclsparseSpMatSetAttribute(fillMode + diagType) - Query the workspace size:
aclsparseSpSV_bufferSize - Allocate the workspace (Device memory)
- Execute preprocessing:
aclsparseSpSV_analysis - Execute solving:
aclsparseSpSV_solve(can be called multiple times) - Optional: update matrix values:
aclsparseSpSV_updateMatrix(no re-analysis needed) - Destroy the descriptor:
aclsparseSpSV_destroyDescr
SpSVDescr Lifecycle
- After analysis completes, descr caches the following runtime constants internally:
- Matrix attribute cache (snapshot from matA at analysis time): cachedM, cachedNnz, cachedFormat, cachedFillMode, cachedDiagType, cachedOpA, cachedIndexType (rowPtr index width), cachedColIndType (colInd index width), cachedIdxBase (index base)
- Runtime context (used at solve/updateMatrix time): workspaceBuffer (workspace pointer), currentValues (weak reference to values, updated by updateMatrix), and the workspace internal offset fields (levelPtrOffset, levelRowOffset, diagPtrOffset, csrRowPtrOffset, csrColIndOffset, csrValuesOffset, permOffset, transValuesOffset, transPermOffset). Users should not directly access these internal fields.
Dimension Matching
- vecX size >= m (matrix order)
- vecY size >= m (matrix order)
Singular Matrix
- In NON_UNIT mode, if a diagonal element is 0 (or the matrix lacks explicit diagonal elements), IEEE-754 division by zero produces Inf/NaN
- Consistent with cuSPARSE behavior, with no special defense
Workspace Description
- Header TilingData area: the first 512 bytes of the workspace are reserved as the
SpsvTilingDataruntime data area. The analysis kernel writesnumLevels(number of levels) andmaxLevelWidth(maximum level width) into this area, and the solve kernel reads from it (rather than from the kernel parameters passed in by the host) - CSR/CSC format (0-based): the workspace stores Level Schedule data (diagPtr + levelPtr + levelRow + validCount)
validCount(m × int32_t): the count of valid dependency elements per row, used to skip processed dependencies in unsorted CSR scenarios, improving solving performance
- COO/SLICED_ELL format: the workspace additionally stores a CSR copy (rowPtr + colInd + values + perm) for format conversion
- 1-based CSR/CSC format (INDEX_BASE_ONE): the workspace additionally stores a 0-based CSR copy (rowPtr + colInd + values + perm) for normalizing 1-based input to 0-based for downstream processing
- Transpose operations (TRANSPOSE/CONJUGATE_TRANSPOSE): the workspace additionally stores the transposed CSR copy
- FP32 solving additionally retains the original RHS, the low words of the per-row solution and predecessor error envelopes, and an on-demand integer recomputation area. The solve-specific area is
5*m*sizeof(float) + 10*ceil((620*m+512)/16)*sizeof(uint16_t)bytes, rounded up according to internal alignment requirements; format conversion and level metadata are counted separately. Normal solving does not access the integer recomputation area. Dependency error scanning and on-demand recomputation are executed by subsequent single-block kernels on the same stream, isolating resource usage from regular solving. - The workspace size is computed by
aclsparseSpSV_bufferSize, and users allocate it themselves - The workspace must remain valid between analysis and solve and must not be released
- Alignment requirements: the start address of the workspace must be 512B aligned (satisfying GM base alignment), and each sub-allocation area inside the workspace is aligned to 64B
- When nnz == 0, bufferSize returns 0, and the workspace pointer can be NULL (neither analysis nor solve uses the workspace)
Return Values / Error Codes
| Return Value | Meaning |
|---|---|
| ACL_SPARSE_STATUS_SUCCESS | Operation completed successfully |
| ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR | handle is a null pointer |
| ACL_SPARSE_STATUS_INVALID_VALUE | Invalid parameter (nullptr, dimension mismatch, analysis not completed, and so on) |
| ACL_SPARSE_STATUS_NOT_SUPPORTED | Unsupported parameter combination (computeType, alg, format, indexType, and so on) |
| ACL_SPARSE_STATUS_ALLOC_FAILED | Memory allocation failed (createDescr) |
Invocation example
#include "acl/acl.h"
#include "cann_ops_sparse.h"
// Initialize the ACL environment
aclInit(nullptr);
aclrtSetDevice(0);
aclrtStream stream = nullptr;
aclrtCreateStream(&stream);
// Create the ops-sparse handle
aclsparseHandle_t handle = nullptr;
aclsparseCreate(&handle);
aclsparseSetStream(handle, stream);
// Assume that m×m lower triangular CSR matrix data already exists (Device memory)
// dRowOffsets: int32_t[m+1], dColInd: int32_t[nnz], dValues: float[nnz]
// dX: float[m] input vector, dY: float[m] output vector
int64_t m = 1024;
int64_t nnz = /* number of non-zero elements */;
// 1. Create the sparse matrix descriptor
aclsparseSpMatDescr_t matA = nullptr;
aclsparseCreateCsr(&matA, m, m, nnz,
dRowOffsets, dColInd, dValues,
ACL_SPARSE_INDEX_32I, ACL_SPARSE_INDEX_32I,
ACL_SPARSE_INDEX_BASE_ZERO, ACL_FLOAT);
// 2. Set the matrix attributes (required for SpSV)
aclsparseFillMode_t fillMode = ACL_SPARSE_FILL_MODE_LOWER;
aclsparseDiagType_t diagType = ACL_SPARSE_DIAG_TYPE_NON_UNIT;
aclsparseSpMatSetAttribute(matA, ACL_SPARSE_SPMAT_FILL_MODE, &fillMode, sizeof(fillMode));
aclsparseSpMatSetAttribute(matA, ACL_SPARSE_SPMAT_DIAG_TYPE, &diagType, sizeof(diagType));
// 3. Create the dense vector descriptors
aclsparseDnVecDescr_t vecX = nullptr, vecY = nullptr;
aclsparseCreateDnVec(&vecX, m, dX, ACL_FLOAT);
aclsparseCreateDnVec(&vecY, m, dY, ACL_FLOAT);
// 4. Create the SpSV descriptor
aclsparseSpSVDescr_t spsvDescr = nullptr;
aclsparseSpSV_createDescr(&spsvDescr);
// 5. Query the workspace size
float alpha = 1.0f;
aclsparseOperation_t opA = ACL_SPARSE_OP_NON_TRANSPOSE;
size_t bufferSize = 0;
aclsparseSpSV_bufferSize(handle, opA, &alpha, matA, vecX, vecY,
ACL_FLOAT, ACL_SPARSE_SPSV_ALG_DEFAULT, spsvDescr, &bufferSize);
// 6. Allocate the workspace
void *dWorkspace = nullptr;
if (bufferSize > 0) {
aclrtMalloc(&dWorkspace, bufferSize, ACL_MEM_MALLOC_HUGE_FIRST);
}
// 7. Execute analysis (preprocessing)
aclsparseSpSV_analysis(handle, opA, &alpha, matA, vecX, vecY,
ACL_FLOAT, ACL_SPARSE_SPSV_ALG_DEFAULT, spsvDescr, dWorkspace);
// 8. Execute solve (can be called multiple times)
aclsparseSpSV_solve(handle, opA, &alpha, matA, vecX, vecY,
ACL_FLOAT, ACL_SPARSE_SPSV_ALG_DEFAULT, spsvDescr);
// 9. Optional: solve again after updating matrix values (no re-analysis needed)
// aclsparseSpSV_updateMatrix(handle, spsvDescr, dNewValues, ACL_SPARSE_SPSV_UPDATE_GENERAL);
// aclsparseSpSV_solve(handle, opA, &alpha, matA, vecX, vecY,
// ACL_FLOAT, ACL_SPARSE_SPSV_ALG_DEFAULT, spsvDescr);
// 10. Synchronize and clean up
aclrtSynchronizeStream(stream);
aclsparseSpSV_destroyDescr(spsvDescr);
aclsparseDestroyDnVec(vecX);
aclsparseDestroyDnVec(vecY);
aclsparseDestroySpMat(matA);
if (dWorkspace) aclrtFree(dWorkspace);
aclsparseDestroy(handle);
aclrtDestroyStream(stream);
aclrtResetDevice(0);
aclFinalize();
Performance Data Reference
The following data is collected on Ascend 950PR, with the configuration CSR + LOWER + NON_UNIT + NON_TRANSPOSE + alpha=1.0 + sparsity=0.5, averaged over 100 iterations:
| Matrix Size (m) | Non-zero Count (nnz) | Average solve Time (us) | Effective Bandwidth (GB/s) |
|---|---|---|---|
| 64 | ~1K | Not measured | - |
| 256 | ~16K | Not measured | - |
| 1024 | ~262K | Not measured | - |
| 4096 | ~4.2M | Not measured | - |
| 8192 | ~16.8M | Not measured | - |
The current version does not provide measured data for the preceding sizes, and the table does not constitute a performance commitment; measured values will be updated after release.
Host Launch Configuration and Kernel Scheduling
The SelectNthreads of the Host selects 64 threads for FP32 when m <= 5000 and 256 threads for larger matrices; Complex64 is fixed to 256 threads. ComputeNumBlocks returns 1 when m <= nthreads, and otherwise returns min(ceil(m/nthreads), aivCoreNum). This is the launch resource configuration; the actual solving path is determined by the levels generated by analysis, and the level width is not estimated by m²/nnz.
The actual dispatch of the FP32 Kernel is as follows:
numLevels == m: block 0 executes the dependency chain with 32 threads.- When the average level width
floor(m/numLevels)is in 2–64 and the number of levels is greater than 3: block 0 solves; whennnz <= 4*m, the ordinary row-by-row path is used; otherwise, the grouped path with 256 threads and 8 threads per row is used. - When the number of launched blocks is greater than 1 and the average level width is at least 128: the multi-block path is selected, but when the number of levels does not exceed 3, block 0 still completes the entire level table. The other multi-block schedules use 1, 4, or 32 threads per row according to
nnz/m. - In the remaining cases, block 0 executes ordinary level scheduling. When the row length of a single-row level is at least 256, whole-block cooperation is used; the other single-row levels use one warp.
The Complex64 Kernel executes the chain path with block 0 when numLevels == m; multi-block solving level by level is used only when the number of launched blocks is greater than 1 and the average level width is at least 256; otherwise, block 0 solves. The single-block path also identifies wide prefixes, serial middle segments, and wide suffixes; within ordinary levels, short rows are processed by a single thread by default, 4-thread grouping is used when the medium/long row conditions are met, and single-row levels additionally have warp/whole-block cooperation paths. The specific row-length selection follows SpsvSolveComplexLevelRows and the single-row level branches.
Multi-block solving rendezvous between levels through CrossCoreSetFlag / CrossCoreWaitFlag and invalidates the in-core data cache before consuming cross-block predecessor values. Multi-core analysis uses the three kernels — serial, parallel, and finalization — and the execution order of the same stream guarantees cross-kernel GM visibility.
FP32 Predecessor Error and Dependency Recomputation
Fast solving passes both the high/low words of the solution and the forward error upper bound to successors, using round-outward non-negative multiply-accumulate accumulation sum(abs(a_ij)*error_j). After solving, the FP32 rounding interval and precision budget of finite outputs are checked; the budget is one quarter of the acceptance relative error threshold 2^-10 and absolute error threshold 2^-16, and is constrained by the 0.0005 absolute error upper limit. If a row cannot be certified, its non-zero predecessor dependency subgraph is marked from the original RHS and matrix, and the binary exponent is eliminated row by row to obtain an integer triangular system; the exact rational result is recovered through modular prime solving, diagonal determinant, and the Chinese remainder theorem, and finally rounded to FP32 at once. The recomputation retains the original dependency information until the target successor completes, and does not use the rounded predecessor high/low words instead of the original input.
Before exact reconstruction, the outward error with independent exponents is first recomputed and propagated from the original input using 128, 256, and 512-bit integer significant digits. It stops only when the error interval can certify the final FP32 rounding result; if certification fails, the precision is increased, and only rows that none of the three precision tiers can certify enter CRT. At most 8 target rows share the dependency subgraph, denominators, and modular prime solving. Exact reconstruction ends only after the product of moduli exceeds twice the proven integer determinant bound, and a fixed number of floating-point expansion words is not used as the precision certification condition. The integer buffer is O(m); dependency recomputation for ill-conditioned inputs may significantly increase the time cost. IEEE propagation for non-finite inputs or singular diagonals follows the original path, and integer recomputation accepts only finite, non-singular dependency subgraphs.
Supported Chips
| Chip | Architecture | Support Status |
|---|---|---|
| Ascend 950PR&950DT products | arch35 (DAV_3510) | ✅ Supported |
| Atlas A3 products | arch22 (DAV_2201) | ✅ Supported |
| Atlas A2 products | arch22 (DAV_2201) | ✅ Supported |
Algorithm Description
Level Scheduling
The core parallelization method of SpSV is Level Scheduling:
- Build the dependency DAG: extracts inter-row dependencies from the sparse matrix structure
- Topological layering: divides rows into several levels according to dependencies; rows within the same level do not depend on each other
- Solve in level order: serial between levels (guaranteeing dependencies), parallel within a level (thread level)
Three-Stage Execution Model
| Stage | Interface | Execution Location | Description |
|---|---|---|---|
| Query | bufferSize | Host | Pure arithmetic computation of the workspace size |
| Preprocessing | analysis | Device kernel | Level Scheduling + diagonal locating + format conversion (COO/SLICED_ELL→CSR) |
| Solving | solve | Device kernel | Performs forward/backward substitution in level order |
Solving Direction Decision
The solving direction (forward / backward) is jointly determined by fillMode, opA, and the matrix format:
Effective fillMode and opA (after CSC implicit flipping and transpose normalization):
| Effective fillMode | Effective opA | Solving Direction |
|---|---|---|
| LOWER | NON_TRANSPOSE | forward (forward substitution) |
| LOWER | TRANSPOSE/CONJ | backward (backward substitution) |
| UPPER | NON_TRANSPOSE | backward (backward substitution) |
| UPPER | TRANSPOSE/CONJ | forward (forward substitution) |
The CSC format uses a zero-copy implementation: colPtr is remapped to rowPtr and rowInd is remapped to colInd, with implicit flipping of fillMode (LOWER↔UPPER) and opA (NON_TRANSPOSE↔TRANSPOSE/CONJ) at the same time, so that CSC matrices are automatically converted to the equivalent CSR path for processing. Therefore, users do not need to perform extra operations on CSC matrices and can pass them in directly.
Solving Optimizations
- validCount optimization: the analysis stage pre-computes the count of valid dependency elements (validCount) for each row, and the solve stage uses this count to skip processed dependencies (the prefix sorted by column index), avoiding redundant traversal, with significant performance improvement for unsorted CSR scenarios
- Multi-core parallelism: the Host configures the number of thread blocks; the FP32 and Complex64 solving Kernels then select single-block or multi-block scheduling according to the actual number of levels, level width, and row length from Analysis. See Host Launch Configuration and Kernel Scheduling for the specific launch configuration and dispatch conditions
- Multi-core analysis: the multi-core path is split into three stages — serial (format conversion + sequential level computation), parallel (levelRow scatter + diagPtr/validCount), and finalization (levelPtr correction) — scheduled in sequence on the same stream, with stream ordering guaranteeing cross-kernel global memory visibility
Determinism Guarantee
The solve stage provides bit-wise deterministic results:
- Level Scheduling is deterministic: given the same matrix structure, the level computation result is unique
- The solving order of rows within a level does not affect the result: rows within the same level do not depend on each other
- No randomization or non-deterministic factors depending on runtime scheduling are introduced