Sparse Operator Interfaces (aclsparse)
Usage instructions
To facilitate calling sparse operators, a set of C-based APIs (prefixed with aclsparse) is provided, mainly for sparse matrix operation scenarios.
When you call the sparse operator APIs, you need to include the dependent header files and library files.
- Dependent header file:
cann_ops_sparse.h - Dependent library file: the sparse operator library file
Interface list
The interfaces fall into two categories by purpose:
- General APIs: handle / stream / version operations, and the creation, query, and destruction of descriptors such as dense vectors, sparse vectors, sparse matrices, and dense matrices.
- Operator APIs: sparse computation, format conversion/sorting, tridiagonal solving, and operator-specific interfaces such as SpMVOp / SpMMOp.
For the platform-level operator coverage table, see README · Operator Support in the repository root directory.
General APIs
| Interface Name | Description |
|---|---|
| aclsparseCreate | Creates a sparse matrix processor |
| aclsparseDestroy | Destroys the sparse matrix processor |
| aclsparseSetStream | Sets the stream used by the processor |
| aclsparseGetStream | Gets the current stream of the processor |
| aclsparseGetVersion | Gets the version number |
| aclsparseCreateDnVec | Creates a dense vector |
| aclsparseDestroyDnVec | Destroys the dense vector descriptor |
| aclsparseDnVecGet | Gets all fields of the dense vector descriptor |
| aclsparseDnVecGetValues | Gets the values pointer of the dense vector descriptor |
| aclsparseDnVecSetValues | Sets the values pointer of the dense vector descriptor |
| aclsparseCreateSpVec | Creates a sparse vector |
| aclsparseDestroySpVec | Destroys the sparse vector descriptor |
| aclsparseSpVecGet | Gets all fields of the sparse vector descriptor |
| aclsparseSpVecGetIndexBase | Gets the index base of the sparse vector |
| aclsparseSpVecGetValues | Gets the values pointer of the sparse vector descriptor |
| aclsparseSpVecSetValues | Sets the values pointer of the sparse vector descriptor |
| aclsparseCreateCsr | Creates a sparse matrix in CSR format |
| aclsparseCsrSetStridedBatch | Sets the batch count and batch stride of the CSR descriptor |
| aclsparseCsrGet | Gets all fields of the CSR sparse matrix descriptor |
| aclsparseConstCsrGet | Gets all fields of the read-only (const) CSR sparse matrix descriptor |
| aclsparseCreateBsr | Creates a sparse matrix in BSR format |
| aclsparseCreateConstBsr | Creates a read-only (const) sparse matrix in BSR format |
| aclsparseBsrSetStridedBatch | Sets the strided-batch attribute of the BSR descriptor |
| aclsparseCreateCsc | Creates a sparse matrix in CSC format |
| aclsparseCreateConstCsc | Creates a read-only (const) sparse matrix in CSC format |
| aclsparseCscGet | Gets all fields of the CSC sparse matrix descriptor |
| aclsparseConstCscGet | Gets all fields of the read-only (const) CSC sparse matrix descriptor |
| aclsparseCreateCoo | Creates a sparse matrix in COO format |
| aclsparseCreateConstCoo | Creates a read-only (const) sparse matrix in COO format |
| aclsparseCooGet | Gets all fields of the COO sparse matrix descriptor |
| aclsparseConstCooGet | Gets all fields of the read-only (const) COO sparse matrix descriptor |
| aclsparseCooSetStridedBatch | Sets the batch count and batch stride of the COO descriptor |
| aclsparseCreateBlockedEll | Creates a sparse matrix in Blocked-ELL format |
| aclsparseBlockedEllGet | Gets all fields of the Blocked-ELL sparse matrix descriptor |
| aclsparseConstBlockedEllGet | Gets all fields of the read-only (const) Blocked-ELL sparse matrix descriptor |
| aclsparseDestroySpMat | Destroys the sparse matrix object |
| aclsparseSpMatGetFormat | Gets the storage format of the sparse matrix |
| aclsparseSpMatGetIndexBase | Gets the index base of the sparse matrix descriptor |
| aclsparseSpMatGetValues | Gets the values pointer of the sparse matrix descriptor |
| aclsparseSpMatSetValues | Sets the values pointer of the sparse matrix descriptor |
| aclsparseSpMatGetSize | Gets the number of rows, the number of columns, and the number of non-zero elements of the sparse matrix |
| aclsparseSpMatGetStridedBatch | Gets the batch count of the sparse matrix descriptor |
| aclsparseCreateDnMat | Creates a dense matrix |
| aclsparseDestroyDnMat | Destroys the dense matrix descriptor |
| aclsparseDnMatGet | Gets all fields of the dense matrix descriptor |
| aclsparseDnMatGetValues | Gets the values pointer of the dense matrix descriptor |
| aclsparseDnMatSetValues | Sets the values pointer of the dense matrix descriptor |
| aclsparseDnMatGetStridedBatch | Gets the strided-batch attribute of the dense matrix |
| aclsparseDnMatSetStridedBatch | Sets the strided-batch attribute of the dense matrix |
| aclsparseSetPointerMode | Sets the Host/Device mode of the alpha/beta scalar pointers |
| aclsparseGetPointerMode | Gets the Host/Device mode of the alpha/beta scalar pointers |
| aclsparseSetWorkspace | Sets the user workspace reused by the handle |
| aclsparseGetWorkspace | Gets the workspace currently in effect for the handle and its size |
| aclsparseCreateConstDnVec | Creates a read-only (const) dense vector descriptor |
| aclsparseConstDnVecGet | Gets all fields of the read-only (const) dense vector descriptor |
| aclsparseConstDnVecGetValues | Gets the values pointer of the read-only (const) dense vector descriptor |
| aclsparseDnVecSetStride | Sets the element stride of the dense vector descriptor |
| aclsparseDnVecGetStride | Gets the element stride of the dense vector descriptor |
| aclsparseCreateConstSpVec | Creates a read-only (const) sparse vector descriptor |
| aclsparseConstSpVecGet | Gets all fields of the read-only (const) sparse vector descriptor |
| aclsparseConstSpVecGetValues | Gets the values pointer of the read-only (const) sparse vector descriptor |
| aclsparseCreateConstCsr | Creates a read-only (const) sparse matrix in CSR format |
| aclsparseCsrSetPointers | Binds or updates the row offsets, column indices, and values pointer of the CSR descriptor |
| aclsparseCsrSetStrides | Sets the element strides of the three arrays in the CSR descriptor |
| aclsparseCsrGetStrides | Gets the element strides of the three arrays in the CSR descriptor |
| aclsparseCscSetPointers | Binds or updates the column offsets, row indices, and values pointer of the CSC descriptor |
| aclsparseCooSetPointers | Binds or updates the row indices, column indices, and values pointer of the COO descriptor |
| aclsparseConstSpMatGetValues | Gets the values pointer of the read-only (const) sparse matrix descriptor |
| aclsparseCreateSlicedEll | Creates a sparse matrix in Sliced-ELL format |
| aclsparseCreateConstSlicedEll | Creates a read-only (const) sparse matrix in Sliced-ELL format |
| aclsparseCreateConstDnMat | Creates a read-only (const) dense matrix descriptor |
| aclsparseConstDnMatGet | Gets all fields of the read-only (const) dense matrix descriptor |
| aclsparseConstDnMatGetValues | Gets the values pointer of the read-only (const) dense matrix descriptor |
| aclsparseCreateMatDescr | Creates a Legacy MatDescr (legacy matrix attribute descriptor) |
| aclsparseDestroyMatDescr | Destroys a Legacy MatDescr |
| aclsparseSetMatType | Sets the matrix type of a Legacy MatDescr |
| aclsparseGetMatType | Gets the matrix type of a Legacy MatDescr |
| aclsparseSetMatFillMode | Sets the fill mode of a Legacy MatDescr |
| aclsparseGetMatFillMode | Gets the fill mode of a Legacy MatDescr |
| aclsparseSetMatDiagType | Sets the diag type of a Legacy MatDescr |
| aclsparseGetMatDiagType | Gets the diag type of a Legacy MatDescr |
| aclsparseSetMatIndexBase | Sets the index base of a Legacy MatDescr |
| aclsparseGetMatIndexBase | Gets the index base of a Legacy MatDescr |
| aclsparseSpMatGetAttribute | Gets the fill mode / diag type attributes of the sparse matrix descriptor |
| aclsparseSpMatSetAttribute | Sets the fill mode / diag type attributes of the sparse matrix descriptor |
Operator APIs
| Interface Name | Description |
|---|---|
| aclsparseGather | Gathers elements from the dense vector by sparse indices |
| aclsparseSpMVGetBufferSize | Gets the SpMV buffer size |
| aclsparseSpMVPreprocess | SpMV preprocessing |
| aclsparseSpMV | Sparse matrix-vector multiplication |
| aclsparseSpMMGetBufferSize | Gets the SpMM buffer size |
| aclsparseSpMMPreprocess | SpMM preprocessing |
| aclsparseSpMM | Sparse matrix-dense matrix multiplication |
| aclsparseSpSV_createDescr | Creates an SpSV descriptor |
| aclsparseSpSV_destroyDescr | Destroys the SpSV descriptor |
| aclsparseSpSV_bufferSize | Queries the SpSV device workspace size |
| aclsparseSpSV_analysis | SpSV sparse matrix preprocessing |
| aclsparseSpSV_solve | Solves a sparse triangular linear system |
| aclsparseSpSV_updateMatrix | Updates the SpSV matrix values |
| aclsparseSDDMMBufferSize | Gets the SDDMM workspace size |
| aclsparseSDDMMPreprocess | SDDMM sparse pattern validation and preprocessing |
| aclsparseSDDMM | Sampled dense-dense matrix multiplication |
| aclsparseSpMVOp_bufferSize | Gets the SpMVOp workspace size |
| aclsparseSpMVOp_createDescr | Creates an SpMVOp descriptor and performs preprocessing |
| aclsparseSpMVOp_destroyDescr | Destroys the SpMVOp descriptor |
| aclsparseSpMVOp_createPlan | Creates an SpMVOp execution plan |
| aclsparseSpMVOp_destroyPlan | Destroys the SpMVOp execution plan |
| aclsparseSpMVOp_setGlobalUserData | Sets the SpMVOp epilogue user data (a no-op on the NPU side) |
| aclsparseSpMVOp | Performs sparse matrix-vector multiplication |
| aclsparseSpMMOp_bufferSize | Gets the workspace size |
| aclsparseSpMMOp_createDescr | Creates a descriptor and performs preprocessing |
| aclsparseSpMMOp_destroyDescr | Destroys the descriptor |
| aclsparseSpMMOp_createPlan | Creates an execution plan |
| aclsparseSpMMOp_destroyPlan | Destroys the execution plan |
| aclsparseSpMMOp_setGlobalUserData | Sets the epilogue user data (a no-op on the NPU side) |
| aclsparseSpMMOp | Sparse matrix-dense matrix multiplication (descriptor/plan lifecycle mode) |
| aclsparseSgtsv2 | Tridiagonal linear system solving with pivoting (FP32, Multiple RHS) |
| aclsparseSgtsv2_bufferSizeExt | Queries the workspace size required by aclsparseSgtsv2 |
| aclsparseCgtsv2 | Complex tridiagonal linear system solving with partial pivoting (complex64, Multiple RHS) |
| aclsparseCgtsv2_bufferSizeExt | Queries the workspace size required by aclsparseCgtsv2 |
| aclsparseXcscsort_bufferSizeExt | Gets the CSC sorting buffer size |
| aclsparseXcscsort | Stable sorting by column in CSC format |
| aclsparseXcoo2csr | Converts COO row indices to CSR row pointers |
| aclsparseSpGEMMCreateDescr | Creates an SpGEMM descriptor that is reused across stages |
| aclsparseSpGEMMWorkEstimation | Queries or performs SpGEMM work estimation (per-row and total intermediate product counts) |
| aclsparseSpGEMMGetNumProducts | Queries the total number of intermediate products obtained by WorkEstimation |
| aclsparseSpGEMMEstimateMemory | Queries the ALG2/ALG3 memory planning and the Compute workspace size |
| aclsparseSpGEMMCompute | Queries or performs the structure and value computation of SpGEMM and updates nnz(C) |
| aclsparseSpGEMMCopy | Writes the SpGEMM result column indices and values to the caller-provided C pointer |
| aclsparseSpGEMMDestroyDescr | Destroys the SpGEMM Host descriptor (does not release the caller workspace) |
| aclsparseSpGEMMSetCInValid | Provides compatibility for legacy calls with the C input validity flag |
| aclsparseSpGEMMGetBufferSize | Queries the shared workspace size of the legacy three-stage compatibility interfaces |
| aclsparseSpGEMMPreprocess | Performs structure preprocessing for the legacy three-stage compatibility interfaces |
| aclsparseSpGEMM | Performs value computation for the legacy three-stage compatibility interfaces (automatically preprocesses when the cache misses) |
| aclsparseSpSMCreateDescr | Creates an SpSM descriptor |
| aclsparseSpSMDestroyDescr | Destroys the SpSM descriptor |
| aclsparseSpSMBufferSize | Queries the SpSM device workspace size |
| aclsparseSpSMAnalysis | SpSM sparse triangular matrix preprocessing |
| aclsparseSpSM | Solves sparse triangular linear systems (multiple right-hand sides) |
| aclsparseSpSMUpdateMatrix | Updates the SpSM matrix values (the structure stays unchanged) |
| aclsparseSgtsv2Nopivot | Tridiagonal solving without pivoting (Thomas elimination), FP32, requires well-conditioned input |
| aclsparseSgtsv2Nopivot_bufferSizeExt | Queries the workspace size required by aclsparseSgtsv2Nopivot |
| aclsparseSgtsv2StridedBatch | Tridiagonal solving in stride-based batches, FP32, multiple right-hand sides |
| aclsparseSgtsv2StridedBatch_bufferSizeExt | Queries the workspace size required by aclsparseSgtsv2StridedBatch |
| aclsparseSgtsvInterleavedBatch | Batch tridiagonal solving in interleaved layout, FP32 |
| aclsparseSgtsvInterleavedBatch_bufferSizeExt | Queries the workspace size required by aclsparseSgtsvInterleavedBatch |
| aclsparseSgpsvInterleavedBatch | Batch pentadiagonal solving in interleaved layout, FP32 |
| aclsparseSgpsvInterleavedBatch_bufferSizeExt | Queries the workspace size required by aclsparseSgpsvInterleavedBatch |
| aclsparseScsrgeam2 | Weighted sum of two sparse matrices C=alphaA+betaB (CSR, FP32) |
| aclsparseScsrgeam2_bufferSizeExt | Queries the workspace size required by aclsparseScsrgeam2 |
| aclsparseXcsrgeam2Nnz | Computes the output nnz of csrgeam2 and writes it back to csrRowPtrC/nnzTotal |
| aclsparseScsr2gebsr | Converts CSR to GEBSR (FP32) |
| aclsparseScsr2gebsr_bufferSize | Queries the workspace size required by aclsparseScsr2gebsr |
| aclsparseXcsr2gebsrNnz | Computes the output block-level nnz of csr2gebsr and writes it back to bsrRowPtrC/nnzTotal |
| aclsparseHcsr2gebsr | Converts CSR to GEBSR (FP16) |
| aclsparseHcsr2gebsr_bufferSize | Queries the workspace size required by aclsparseHcsr2gebsr |
| aclsparseIcsr2gebsr | Converts CSR to GEBSR (INT32) |
| aclsparseIcsr2gebsr_bufferSize | Queries the workspace size required by aclsparseIcsr2gebsr |
| aclsparseBhcsr2gebsr | Converts CSR to GEBSR (BF16) |
| aclsparseBhcsr2gebsr_bufferSize | Queries the workspace size required by aclsparseBhcsr2gebsr |
| aclsparseGebsr2gebsc | Converts GEBSR to GEBSC (block-level transposition and rearrangement) |
| aclsparseGebsr2gebsc_bufferSize | Queries the workspace size required by aclsparseGebsr2gebsc |
| aclsparseCsr2cscEx2 | Converts CSR to CSC (type-generic: INT8/FP16/BF16/FP32) |
| aclsparseCsr2cscEx2_bufferSize | Queries the workspace size required by aclsparseCsr2cscEx2 |
| aclsparseDenseToSparseGetBufferSize | Queries the workspace size required by DenseToSparse Analysis/Convert |
| aclsparseDenseToSparseAnalysis | DenseToSparse structure analysis (counts non-zero elements and writes offsets) |
| aclsparseDenseToSparseConvert | DenseToSparse conversion execution (writes indices/values) |
| aclsparseSparseToDense | Converts sparse to dense (CSR/COO → dense matrix) |
| aclsparseSparseToDense_bufferSize | Queries the workspace size required by aclsparseSparseToDense |
| aclsparseCreateCubeSpmmMat | Creates the dedicated sparse matrix descriptor for CubeSpMM |
| aclsparseDestroyCubeSpmmMat | Destroys the CubeSpMM sparse matrix descriptor |
| aclsparseCubeSpmmPreprocess | CubeSpMM preprocessing (structure analysis and rearrangement) |
| aclsparseCubeSpmmGetBufferSize | Queries the workspace size required by CubeSpMM |
| aclsparseCubeSpmm | Performs CubeSpMM (Cube-accelerated sparse-dense matrix multiplication) |
| aclsparseCubeSpmmPadDenseMatrixB | Pads the dense matrix B to meet the CubeSpMM layout requirements |
| aclsparseCubeSpmm1dCreatePlan | Prepares the CubeSpMM 1D plan from the Host vector-CSR (only Atlas A2 products, Atlas A3 products, arch22) |
| aclsparseCubeSpmm1dCreateCsrPlan | Converts the Host standard CSR and prepares the CubeSpMM 1D plan (only Atlas A2 products, Atlas A3 products, arch22) |
| aclsparseCubeSpmm1dGetPlanInfo | Queries the logical/padded sizes, configuration, and memory requirements of CubeSpMM 1D (only arch22) |
| aclsparseCubeSpmm1dExecute | Asynchronously computes C=A×B with FP16 A/B and FP32 output, and clears C before execution (only arch22) |
| aclsparseCubeSpmm1dDestroyPlan | Releases the CubeSpMM 1D plan and the A matrix it holds, without waiting for the stream (only arch22) |
| aclsparseXcoosort_bufferSizeExt | Queries the workspace size required for COO sorting |
| aclsparseXcoosortByRow | Stably sorts COO coordinates by row |
| aclsparseXcoosortByColumn | Stably sorts COO coordinates by column |
| aclsparseXcsrsort | Stably sorts the CSR rows by the column indices within each row |
| aclsparseXcsrsort_bufferSizeExt | Queries the workspace size required for CSR sorting |
| aclsparseXcsr2coo | Expands the CSR row pointers into COO row indices |
| aclsparseSnnz | Counts the number of non-zero elements per row/column and in total for the dense matrix (FP32) |
| aclsparseGatherRaw | Gather raw form: collects elements by index and index base (no descriptor) |
| aclsparseScatter | Scatters the vector into the dense vector by sparse indices |
| aclsparseSpvv | Sparse vector dot product (SpVV) |
Interface details
aclsparseCreate
aclsparseStatus_t aclsparseCreate(aclsparseHandle_t *handle);
Function: Creates a sparse matrix processor. The stream of the processor defaults to nullptr (the default stream); if you need to specify a stream, call aclsparseSetStream.
Parameter Description:
handle(IN/OUT): HOST. Returns the handle of the created sparse matrix processor. Before the call,*handlemust benullptr.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseDestroy
aclsparseStatus_t aclsparseDestroy(aclsparseHandle_t handle);
Function: Destroys the sparse matrix processor. The stream is managed by the user, and this interface does not destroy the stream.
Parameter Description:
handle(IN): The sparse matrix processor handle.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSetStream
aclsparseStatus_t aclsparseSetStream(aclsparseHandle_t handle, aclrtStream stream);
Function: Sets the stream that the processor uses for subsequent operator execution.
Parameter Description:
handle(IN): The sparse matrix processor handle.stream(IN): The stream to bind;nullptrmeans to use the default stream.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseGetStream
aclsparseStatus_t aclsparseGetStream(aclsparseHandle_t handle, aclrtStream *stream);
Function: Gets the stream currently bound to the processor.
Parameter Description:
handle(IN): The sparse matrix processor handle.stream(OUT): Returns the current stream.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseGetVersion
aclsparseStatus_t aclsparseGetVersion(aclsparseHandle_t handle, int *version);
Function: Gets the version number of ops-sparse. The version number is encoded as MAJOR * 10000 + MINOR * 100 + PATCH. For example, 10000 indicates 1.0.0.
Parameter Description:
handle(IN): HOST. The sparse matrix processor handle, which can benullptr.version(OUT): HOST. An output parameter that receives the version number.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:versionis null- Other values: Failure
aclsparseCreateDnVec
aclsparseStatus_t aclsparseCreateDnVec(
aclsparseDnVecDescr_t *dnVecDescr,
int64_t size,
void *values,
aclDataType valueType
);
Function: Creates a dense vector.
Parameter Description:
dnVecDescr(IN/OUT): HOST. The sparse vector descriptor.size(IN): HOST. The size of the vector.values(IN): DEVICE. The values of the vector.valueType(IN): HOST. The data type of the values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseDestroyDnVec
aclsparseStatus_t aclsparseDestroyDnVec(aclsparseConstDnVecDescr_t dnVecDescr);
Function: Destroys the dense vector descriptor. When nullptr is passed, the interface performs no operation and returns ACL_SPARSE_STATUS_SUCCESS (null-tolerant contract, aligned with cuSPARSE).
Parameter Description:
dnVecDescr(IN): HOST. The dense vector descriptor to destroy, which can benullptr.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseDnVecGet
aclsparseStatus_t aclsparseDnVecGet(
aclsparseDnVecDescr_t dnVecDescr,
int64_t *size,
void **values,
aclDataType *valueType
);
Function: Gets all fields of the dense vector descriptor. The output parameters can be nullptr; in this case, only the requested fields are returned.
Parameter Description:
dnVecDescr(IN): HOST. The dense vector descriptor.size(OUT): HOST. The size of the vector. Optional.values(OUT): DEVICE. The values pointer of the vector.valueType(OUT): HOST. The data type of the values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:dnVecDescris a null pointer
aclsparseDnVecGetValues
aclsparseStatus_t aclsparseDnVecGetValues(
aclsparseDnVecDescr_t dnVecDescr,
void **values
);
Function: Gets the values pointer of the dense vector descriptor.
Parameter Description:
dnVecDescr(IN): HOST. The dense vector descriptor.values(OUT): DEVICE. The values pointer of the vector.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:dnVecDescris a null pointer
aclsparseDnVecSetValues
aclsparseStatus_t aclsparseDnVecSetValues(
aclsparseDnVecDescr_t dnVecDescr,
void *values
);
Function: Sets the values pointer of the dense vector descriptor.
Parameter Description:
dnVecDescr(IN): HOST. The dense vector descriptor.values(IN): DEVICE. The values pointer of the vector.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:dnVecDescris a null pointer
aclsparseCreateSpVec
aclsparseStatus_t aclsparseCreateSpVec(
aclsparseSpVecDescr_t *spVecDescr,
int64_t size,
int64_t nnz,
void *indices,
void *values,
aclsparseIndexType_t idxType,
aclsparseIndexBase_t idxBase,
aclDataType valueType
);
Description: Creates a sparse vector descriptor.
Parameter Description:
spVecDescr(IN/OUT): HOST, the sparse vector descriptor.size(IN): HOST, the size of the sparse vector (total number of elements).nnz(IN): HOST, the number of non-zero elements of the sparse vector.indices(IN): DEVICE, the index array, with a length ofnnz.values(IN): DEVICE, the values array, with a length ofnnz.idxType(IN): HOST, the data type ofindices.idxBase(IN): HOST, the index base ofindices.valueType(IN): HOST, the data type ofvalues.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spVecDescris a null pointer, orsize < 0, ornnz < 0, ornnz > sizeACL_SPARSE_STATUS_ALLOC_FAILED: Memory allocation fails
aclsparseDestroySpVec
aclsparseStatus_t aclsparseDestroySpVec(aclsparseConstSpVecDescr_t spVecDescr);
Description: Destroys a sparse vector descriptor. The API accepts const descriptors and also supports non-const descriptors. If nullptr is passed in, the API performs no operation and returns ACL_SPARSE_STATUS_SUCCESS (null-tolerance contract, aligned with cuSPARSE).
Parameter Description:
spVecDescr(IN): HOST, the sparse vector descriptor to destroy, which can benullptr.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success
aclsparseSpVecGet
aclsparseStatus_t aclsparseSpVecGet(
aclsparseSpVecDescr_t spVecDescr,
int64_t *size,
int64_t *nnz,
void **indices,
void **values,
aclsparseIndexType_t *idxType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Description: Obtains all fields of a sparse vector descriptor. Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameter Description:
spVecDescr(IN): HOST, the sparse vector descriptor.size(OUT): HOST, the size of the sparse vector.nnz(OUT): HOST, the number of non-zero elements.indices(OUT): DEVICE, pointer to the index array.values(OUT): DEVICE, pointer to the values array.idxType(OUT): HOST, data type of the indices.idxBase(OUT): HOST, the index base.valueType(OUT): HOST, data type of the values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spVecDescris a null pointer
aclsparseSpVecGetIndexBase
aclsparseStatus_t aclsparseSpVecGetIndexBase(
aclsparseConstSpVecDescr_t spVecDescr,
aclsparseIndexBase_t *idxBase
);
Description: Obtains the index base of a sparse vector descriptor. The API accepts const descriptors and also supports non-const descriptors.
Parameter Description:
spVecDescr(IN): HOST, the sparse vector descriptor.idxBase(OUT): HOST, the index base. If it is a null pointer, the API does not write back the value and still returns success.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spVecDescris a null pointer or has an invalid signature
aclsparseSpVecGetValues
aclsparseStatus_t aclsparseSpVecGetValues(
aclsparseSpVecDescr_t spVecDescr,
void **values
);
Description: Obtains the values pointer of a sparse vector descriptor.
Parameter Description:
spVecDescr(IN): HOST, the sparse vector descriptor.values(OUT): DEVICE, pointer to the values array, with a length ofnnz.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spVecDescris a null pointer
aclsparseSpVecSetValues
aclsparseStatus_t aclsparseSpVecSetValues(
aclsparseSpVecDescr_t spVecDescr,
void *values
);
Description: Sets the values pointer of a sparse vector descriptor.
Parameter Description:
spVecDescr(IN): HOST, the sparse vector descriptor.values(IN): DEVICE, pointer to the values array, with a length ofnnz.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spVecDescris a null pointer
aclsparseGather
aclsparseStatus_t aclsparseGather(
aclsparseHandle_t handle,
aclsparseConstDnVecDescr_t vecY,
aclsparseSpVecDescr_t vecX);
Description: Collects elements from dense vector Y according to the index array of sparse vector X, satisfying X.values[i] = Y[X.indices[i] - idxBase] (i = 0 .. nnz-1). After the call, X.values is overwritten with the values collected from Y. The API does not require a workspace and does not require a preprocess stage, and a single call completes the computation.
Product Support:
- Ascend 950PR&950DT products (arch35): Supported
- Atlas A3 products (arch22): Supported
- Atlas A2 products (arch22): Supported
Note: The dtype / index type ranges supported by arch22 and arch35 are different. For details, see
sparse/gather/README.md.
Parameter Description:
handle(IN): HOST, the context handle of the ops-sparse library, which carries a stream.aclsparseSetStreammust be called first.vecY(IN): HOST, the descriptor of dense vector Y (data source). Only the values are read.vecX(IN/OUT): HOST, the descriptor of sparse vector X: the API reads indices and idxBase, and writes values.
Constraints:
- handle cannot be nullptr; otherwise,
ACL_SPARSE_STATUS_HANDLE_IS_NULLPTRis returned - vecY and vecX cannot be nullptr; otherwise,
ACL_SPARSE_STATUS_INVALID_VALUEis returned - vecX.valueType must be consistent with vecY.valueType
- Cardinality constraint: arch35 (Ascend 950PR&950DT products) requires
vecX.size == vecY.sizeand0 <= nnz <= size; arch22 (Atlas A2 products and Atlas A3 products) does not impose a cardinality constraint, and validity depends on the landing position of each index (nnzcan be greater thanvecY.size) - Each index value
X.indices[i] - idxBasein vecX.indices must be within the range[0, vecY.size): arch22 performs per-index validation on the host side and explicitly returnsACL_SPARSE_STATUS_INVALID_VALUEfor out-of-range indices; arch35 follows the asynchronous error protocol, and valid indices are a precondition for the caller - Out-of-order indices are supported (indices do not need to be sorted)
- Duplicate elements in vecX.indices are supported
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_HANDLE_IS_NULLPTR: handle is nullACL_SPARSE_STATUS_INVALID_VALUE: invalid parameters (null pointers and so on)- Other values: Failure
read-only (const) sparse vector descriptor construction interfaces
For read-only (const) construction interfaces, the data pointers are const, and the constructed descriptors are const variants, which can be passed only to interfaces that accept const parameters. The destruction interface (aclsparseDestroySpVec) uniformly accepts const variants, so both const and non-const descriptors can be destroyed.
aclsparseStatus_t aclsparseCreateConstSpVec(aclsparseConstSpVecDescr_t *spVecDescr, int64_t size,
int64_t nnz, const void *indices, const void *values, aclsparseIndexType_t idxType,
aclsparseIndexBase_t idxBase, aclDataType valueType);
aclsparseStatus_t aclsparseConstSpVecGet(aclsparseConstSpVecDescr_t spVecDescr, int64_t *size,
int64_t *nnz, const void **indices, const void **values, aclsparseIndexType_t *idxType,
aclsparseIndexBase_t *idxBase, aclDataType *valueType);
aclsparseStatus_t aclsparseConstSpVecGetValues(aclsparseConstSpVecDescr_t spVecDescr,
const void **values);
aclsparseCreateCsr
aclsparseStatus_t aclsparseCreateCsr(
aclsparseSpMatDescr_t *spMatDescr,
int64_t rows,
int64_t cols,
int64_t nnz,
void *csrRowOffsets,
void *csrColInd,
void *csrValues,
aclsparseIndexType_t csrRowOffsetsType,
aclsparseIndexType_t csrColIndType,
aclsparseIndexBase_t idxBase,
aclDataType valueType
);
Description: Creates a sparse matrix in CSR (Compressed Sparse Row) format.
Index Type Support:
aclsparseCreateCsracceptsACL_SPARSE_INDEX_32IandACL_SPARSE_INDEX_64I, andcsrRowOffsetsTypeandcsrColIndTypeare independent of each other (all four combinations are accepted). For other values,ACL_SPARSE_STATUS_NOT_SUPPORTEDis returned (the accessor layer is consistent with cuSPARSE). Note: the CSR computation interfaces in this repository (the execute paths of SpMV / SpMM) currently support only 32I indices. When computation interfaces are used together, the constraints of the computation interfaces prevail.
Parameter Description:
spMatDescr(IN/OUT): HOST, the sparse matrix descriptor.rows(IN): HOST, the number of rows of the matrix.cols(IN): HOST, the number of columns of the matrix.nnz(IN): HOST, the number of non-zero elements of the matrix.csrRowOffsets(IN): DEVICE, pointer to the row offsets array in CSR format.csrColInd(IN): DEVICE, pointer to the column indices array in CSR format.csrValues(IN): DEVICE, pointer to the array of non-zero elements in CSR format.csrRowOffsetsType(IN): HOST, data type of the row offsets array (supportsACL_SPARSE_INDEX_32I/ACL_SPARSE_INDEX_64I).csrColIndType(IN): HOST, data type of the column indices array (supportsACL_SPARSE_INDEX_32I/ACL_SPARSE_INDEX_64I, independent ofcsrRowOffsetsType).idxBase(IN): HOST, the index base of the indices (0 or 1).valueType(IN): HOST, data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseCsrSetStridedBatch
aclsparseStatus_t aclsparseCsrSetStridedBatch(
aclsparseSpMatDescr_t spMatDescr,
int batchCount,
int64_t offsetsBatchStride,
int64_t columnsValuesBatchStride
);
Description: Sets the strided batch attributes of a CSR sparse matrix descriptor, modeled after cuSPARSE cusparseCsrSetStridedBatch. The API writes the batch count and the address intervals of the CSR arrays between adjacent batches into the descriptor, so that the descriptor can represent batched sparse matrices. Strides are counted in the number of elements: offsetsBatchStride applies to the row offsets array (length rows + 1), and columnsValuesBatchStride applies to both the column indices array and the values array (both of length nnz; the API writes the two descriptor fields columnsBatchStride and valuesBatchStride). A value of 0 for either stride indicates broadcast — all batches share the corresponding array (aligned with the official cuSPARSE samples and the 0=broadcast convention of aclsparseBsrSetStridedBatch / aclsparseCooSetStridedBatch in this repository). The API performs a pure host operation and does not launch an NPU kernel.
Parameter Description:
spMatDescr(IN/OUT): HOST, the CSR sparse matrix descriptor (must be created byaclsparseCreateCsr; itsbatchCount/offsetsBatchStride/columnsBatchStride/valuesBatchStridefields are written).batchCount(IN): HOST, batch count, in the range 1..65535.offsetsBatchStride(IN): HOST, the element offset between the row offsets arrays of adjacent batches; valid values are 0 (broadcast) or >= rows + 1, and negative values are invalid.columnsValuesBatchStride(IN): HOST, the element offset between the column indices/values arrays of adjacent batches; valid values are 0 (broadcast) or >= nnz, and negative values are invalid.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature (a handle of a wrong type),batchCountis out of the range [1, 65535], any stride is invalid (a negative value, or 0 < stride < the length of the corresponding array), the address range (batchCount-1)*stride+array length overflows int64, or rows + 1 overflows int64 (rows = INT64_MAX; creation is allowed under deferred binding)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: the descriptor is not in CSR format
Constraints:
- If this API is not called on a newly created descriptor, by default
batchCount = 1and both strides are 0 (a single matrix with batch semantics not enabled) - If validation fails, the API does not overwrite the existing batch attributes of the descriptor
- If the batch metadata actually changes, the API invalidates the existing preprocess caches of the descriptor (sddmm and so on), and the corresponding Preprocess must be executed again
- In the current version, computation APIs do not yet consume the batch attributes: SpMM/SpMV and so on compute with a single-matrix layout, and GetBufferSize does not scale up by batch; batch computation (for example, the
C_i = A_i · B_ibatched SpMM / SDDMM mode of cuSPARSE) awaits delivery of the operators that consume the attributes
aclsparseCreateBsr
aclsparseStatus_t aclsparseCreateBsr(
aclsparseSpMatDescr_t *spMatDescr,
int64_t blockRows, int64_t blockCols, int64_t blockNnz,
int64_t rowBlockSize, int64_t colBlockSize,
void *bsrRowOffsets, void *bsrColInd, void *bsrValues,
aclsparseIndexType_t bsrRowOffsetsType,
aclsparseIndexType_t bsrColIndType,
aclsparseIndexBase_t idxBase, aclDataType valueType,
aclsparseOrder_t order);
Description: Creates a BSR (Block Sparse Row) sparse matrix descriptor. The logical scalar shape is blockRows*rowBlockSize × blockCols*colBlockSize, blockNnz is the number of non-zero blocks, and order describes the ROW/COL storage order within each block.
Constraints: I32 offsets, column indices, and base 0/1 are currently supported, and only block sizes 2/4/8/16/32/64/128 are supported. The descriptor borrows the Device array pointers and does not take over their life cycle.
Parameter Description:
spMatDescr(OUT): HOST, the created writable BSR descriptor that is returned.blockRows(IN): HOST, the number of BSR block rows, which must be a non-negative number.blockCols(IN): HOST, the number of BSR block columns, which must be a non-negative number.blockNnz(IN): HOST, the number of non-zero blocks in each batch, which must be a non-negative number.rowBlockSize(IN): HOST, the number of rows in a block; 2/4/8/16/32/64/128 are supported.colBlockSize(IN): HOST, the number of columns in a block, which must be equal torowBlockSize.bsrRowOffsets(IN): DEVICE, the block row offsets array, with a length ofblockRows+1. It cannot be null even whenblockRows=0.bsrColInd(IN): DEVICE, the block column indices array, with a length ofblockNnz. It can be null whenblockNnz=0.bsrValues(IN): DEVICE, the block values array, with a length ofblockNnz*rowBlockSize*colBlockSize. It can be null whenblockNnz=0.bsrRowOffsetsType(IN): HOST, the block row offsets type. Currently, onlyACL_SPARSE_INDEX_32Iis supported.bsrColIndType(IN): HOST, the block column indices type. Currently, onlyACL_SPARSE_INDEX_32Iis supported.idxBase(IN): HOST, the index base.ACL_SPARSE_INDEX_BASE_ZEROandACL_SPARSE_INDEX_BASE_ONEare supported.valueType(IN): HOST, the block value type.ACL_FLOAT16,ACL_BF16,ACL_FLOAT, andACL_COMPLEX64are supported.order(IN): HOST, the storage order within a block.ACL_SPARSE_ORDER_ROWandACL_SPARSE_ORDER_COLare supported.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The creation succeeds.ACL_SPARSE_STATUS_INVALID_VALUE: The parameters, address range, or matrix geometry is invalid.ACL_SPARSE_STATUS_NOT_SUPPORTED: The block size, index type, data type, or implementation scope is not supported.ACL_SPARSE_STATUS_ALLOC_FAILED: Descriptor memory allocation fails.
aclsparseCreateConstBsr
aclsparseStatus_t aclsparseCreateConstBsr(
aclsparseConstSpMatDescr_t *spMatDescr,
int64_t blockRows, int64_t blockCols, int64_t blockNnz,
int64_t rowBlockSize, int64_t colBlockSize,
const void *bsrRowOffsets, const void *bsrColInd,
const void *bsrValues,
aclsparseIndexType_t bsrRowOffsetsType,
aclsparseIndexType_t bsrColIndType,
aclsparseIndexBase_t idxBase, aclDataType valueType,
aclsparseOrder_t order);
Description: The read-only variant of aclsparseCreateBsr; the geometry, index, data type, and pointer life cycle constraints are the same.
Parameter Description:
spMatDescr(OUT): HOST, the created read-only BSR descriptor that is returned.blockRows(IN): HOST, the number of BSR block rows, which must be a non-negative number.blockCols(IN): HOST, the number of BSR block columns, which must be a non-negative number.blockNnz(IN): HOST, the number of non-zero blocks in each batch, which must be a non-negative number.rowBlockSize(IN): HOST, the number of rows in a block; 2/4/8/16/32/64/128 are supported.colBlockSize(IN): HOST, the number of columns in a block, which must be equal torowBlockSize.bsrRowOffsets(IN): DEVICE, the read-only block row offsets array, with a length ofblockRows+1. It cannot be null even whenblockRows=0.bsrColInd(IN): DEVICE, the read-only block column indices array, with a length ofblockNnz. It can be null whenblockNnz=0.bsrValues(IN): DEVICE, the read-only block values array, with a length ofblockNnz*rowBlockSize*colBlockSize. It can be null whenblockNnz=0.bsrRowOffsetsType(IN): HOST, the block row offsets type. Currently, onlyACL_SPARSE_INDEX_32Iis supported.bsrColIndType(IN): HOST, the block column indices type. Currently, onlyACL_SPARSE_INDEX_32Iis supported.idxBase(IN): HOST, the index base.ACL_SPARSE_INDEX_BASE_ZEROandACL_SPARSE_INDEX_BASE_ONEare supported.valueType(IN): HOST, the block value type.ACL_FLOAT16,ACL_BF16,ACL_FLOAT, andACL_COMPLEX64are supported.order(IN): HOST, the storage order within a block.ACL_SPARSE_ORDER_ROWandACL_SPARSE_ORDER_COLare supported.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The creation succeeds.ACL_SPARSE_STATUS_INVALID_VALUE: The parameters, address range, or matrix geometry is invalid.ACL_SPARSE_STATUS_NOT_SUPPORTED: The block size, index type, data type, or implementation scope is not supported.ACL_SPARSE_STATUS_ALLOC_FAILED: Descriptor memory allocation fails.
aclsparseBsrSetStridedBatch
aclsparseStatus_t aclsparseBsrSetStridedBatch(
aclsparseSpMatDescr_t spMatDescr, int batchCount,
int64_t offsetsBatchStride, int64_t columnsBatchStride,
int64_t valuesBatchStride);
Description: Sets the strided-batch attributes of a BSR descriptor. All strides are measured in the number of elements of the corresponding arrays; a value of 0 for offsetsBatchStride/columnsBatchStride indicates that the sparse structure is broadcast across batches. batchCount is in the range 1..65535. When batchCount is greater than 1, values cannot be broadcast, and valuesBatchStride must cover all block values of one batch.
Parameter Description:
spMatDescr(IN/OUT): HOST, the writable BSR descriptor to update.batchCount(IN): HOST, batch count, in the range 1..65535.offsetsBatchStride(IN): HOST, the element interval between the start positions of the row offsets arrays of adjacent batches; 0 indicates broadcast, and otherwise the value is at leastblockRows+1.columnsBatchStride(IN): HOST, the element interval between the start positions of the column indices arrays of adjacent batches; 0 indicates broadcast, and otherwise the value is at leastblockNnz.valuesBatchStride(IN): HOST, the element interval between the start positions of the block values arrays of adjacent batches; the value cannot be 0 when there are multiple non-empty batches, and it must cover at least all block values of one batch.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The setting succeeds.ACL_SPARSE_STATUS_INVALID_VALUE: The descriptor, batch, stride, or array address range is invalid.
aclsparseCsrGet
aclsparseStatus_t aclsparseCsrGet(
aclsparseSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz,
void **csrRowOffsets,
void **csrColInd,
void **csrValues,
aclsparseIndexType_t *csrRowOffsetsType,
aclsparseIndexType_t *csrColIndType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of the CSR sparse matrix descriptor. The device pointers read back are exactly the same as the pointers passed in to aclsparseCreateCsr (the accessor does not copy or move device data). Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameters:
spMatDescr(IN): HOST, the CSR sparse matrix descriptor.rows(OUT): HOST, the number of rows of the matrix.cols(OUT): HOST, the number of columns of the matrix.nnz(OUT): HOST, the number of non-zero elements of the matrix.csrRowOffsets(OUT): DEVICE, the pointer to the row offsets array, with a length ofrows + 1.csrColInd(OUT): DEVICE, the pointer to the column indices array, with a length ofnnz.csrValues(OUT): DEVICE, the pointer to the array of non-zero element values, with a length ofnnz.csrRowOffsetsType(OUT): HOST, the data type of the row offsets array.csrColIndType(OUT): HOST, the data type of the column indices array (independent ofcsrRowOffsetsType; all four 32I/64I combinations can be read back).idxBase(OUT): HOST, the index base.valueType(OUT): HOST, the data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or not a sparse matrix descriptor handle (a descriptor of another type is passed in by mistake, such as a dense vector or dense matrix descriptor)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: The descriptor is not in CSR format- Other values: Failure
aclsparseConstCsrGet
aclsparseStatus_t aclsparseConstCsrGet(
aclsparseConstSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz,
const void **csrRowOffsets,
const void **csrColInd,
const void **csrValues,
aclsparseIndexType_t *csrRowOffsetsType,
aclsparseIndexType_t *csrColIndType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of the read-only (const) CSR sparse matrix descriptor. This function is the const variant of aclsparseCsrGet: the descriptor is aclsparseConstSpMatDescr_t, and the device pointers read back are const void**. Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameters:
spMatDescr(IN): HOST, the read-only (const) CSR sparse matrix descriptor.rows(OUT): HOST, the number of rows of the matrix.cols(OUT): HOST, the number of columns of the matrix.nnz(OUT): HOST, the number of non-zero elements of the matrix.csrRowOffsets(OUT): DEVICE, the pointer to the row offsets array, with a length ofrows + 1.csrColInd(OUT): DEVICE, the pointer to the column indices array, with a length ofnnz.csrValues(OUT): DEVICE, the pointer to the array of non-zero element values, with a length ofnnz.csrRowOffsetsType(OUT): HOST, the data type of the row offsets array.csrColIndType(OUT): HOST, the data type of the column indices array (independent ofcsrRowOffsetsType; all four 32I/64I combinations can be read back).idxBase(OUT): HOST, the index base.valueType(OUT): HOST, the data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or not a sparse matrix descriptor handle (a descriptor of another type is passed in by mistake, such as a dense vector or dense matrix descriptor)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: The descriptor is not in CSR format- Other values: Failure
aclsparseCreateCsc
Support status: This API creates a CSC sparse matrix descriptor. The current version of SpMV / SpMM supports only CSR sparse matrices, and CSC descriptors cannot be used for these two compute APIs.
aclsparseStatus_t aclsparseCreateCsc(
aclsparseSpMatDescr_t *spMatDescr,
int64_t rows,
int64_t cols,
int64_t nnz,
void *cscColOffsets,
void *cscRowInd,
void *cscValues,
aclsparseIndexType_t cscColOffsetsType,
aclsparseIndexType_t cscRowIndType,
aclsparseIndexBase_t idxBase,
aclDataType valueType
);
Function: Creates a sparse matrix in CSC (Compressed Sparse Column) format. The created descriptor can be used by APIs that support the CSC format, such as DenseToSparse, and all fields can be read back through aclsparseCscGet / aclsparseConstCscGet. Note: SpMV currently supports only the CSR format and returns ACL_SPARSE_STATUS_NOT_SUPPORTED when a CSC descriptor is passed in; SpMM currently supports only the CSR format and returns ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED when a CSC descriptor is passed in.
Index type support:
cscColOffsetsTypeandcscRowIndTypeare two independent index types; each of them supportsACL_SPARSE_INDEX_32IandACL_SPARSE_INDEX_64I(all four combinations are accepted).cscColOffsets/cscRowInd/cscValuescan be nullptr (deferred binding semantics), and can be re-bound throughaclsparseCscSetPointersbefore use.
Pointer requirements: When non-null pointers are passed in for
cscColOffsets/cscRowInd/cscValues, the pointers must be aligned to the size of the data type specified bycscColOffsetsType/cscRowIndType/valueTyperespectively (for example,ACL_SPARSE_INDEX_32IandACL_FLOATrequire 4-byte alignment,ACL_SPARSE_INDEX_64Irequires 8-byte alignment, andACL_FLOAT16requires 2-byte alignment). This requirement applies to the compute APIs that consume the descriptor later; descriptor accessor APIs (aclsparseCscGet/aclsparseConstCscGet) only access the pointers themselves and do not dereference device data.
Parameters:
spMatDescr(IN/OUT): HOST, the sparse matrix descriptor.rows(IN): HOST, the number of rows of the matrix.cols(IN): HOST, the number of columns of the matrix.nnz(IN): HOST, the number of non-zero elements of the matrix.cscColOffsets(IN): DEVICE, the pointer to the column offsets array, with a length ofcols + 1.cscRowInd(IN): DEVICE, the pointer to the row indices array, with a length ofnnz.cscValues(IN): DEVICE, the pointer to the array of non-zero element values, with a length ofnnz.cscColOffsetsType(IN): HOST, the data type of the column offsets array.cscRowIndType(IN): HOST, the data type of the row indices array.idxBase(IN): HOST, the index base.valueType(IN): HOST, the data type of the non-zero element values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer, orrows/cols/nnzis negative, or the index type is invalidACL_SPARSE_STATUS_ALLOC_FAILED: Memory allocation for the descriptor fails- Other values: Failure
aclsparseCreateConstCsc
aclsparseStatus_t aclsparseCreateConstCsc(
aclsparseConstSpMatDescr_t *spMatDescr,
int64_t rows,
int64_t cols,
int64_t nnz,
const void *cscColOffsets,
const void *cscRowInd,
const void *cscValues,
aclsparseIndexType_t cscColOffsetsType,
aclsparseIndexType_t cscRowIndType,
aclsparseIndexBase_t idxBase,
aclDataType valueType
);
Function: Creates a read-only (const) sparse matrix in CSC format. This function is the const variant of aclsparseCreateCsc: the data pointers are const, the constructed descriptor is aclsparseConstSpMatDescr_t, and it can only be passed to APIs that accept const parameters (such as aclsparseConstCscGet). Index type support is the same as that of aclsparseCreateCsc.
Parameters:
spMatDescr(IN/OUT): HOST, the read-only (const) sparse matrix descriptor.rows(IN): HOST, the number of rows of the matrix.cols(IN): HOST, the number of columns of the matrix.nnz(IN): HOST, the number of non-zero elements of the matrix.cscColOffsets(IN): DEVICE, the pointer to the column offsets array, with a length ofcols + 1.cscRowInd(IN): DEVICE, the pointer to the row indices array, with a length ofnnz.cscValues(IN): DEVICE, the pointer to the array of non-zero element values, with a length ofnnz.cscColOffsetsType(IN): HOST, the data type of the column offsets array.cscRowIndType(IN): HOST, the data type of the row indices array.idxBase(IN): HOST, the index base.valueType(IN): HOST, the data type of the non-zero element values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer, orrows/cols/nnzis negative, or the index type is invalidACL_SPARSE_STATUS_ALLOC_FAILED: Memory allocation for the descriptor fails- Other values: Failure
aclsparseCscGet
aclsparseStatus_t aclsparseCscGet(
aclsparseSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz,
void **cscColOffsets,
void **cscRowInd,
void **cscValues,
aclsparseIndexType_t *cscColOffsetsType,
aclsparseIndexType_t *cscRowIndType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of the CSC sparse matrix descriptor. Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameters:
spMatDescr(IN): HOST, the CSC sparse matrix descriptor.rows(OUT): HOST, the number of rows of the matrix.cols(OUT): HOST, the number of columns of the matrix.nnz(OUT): HOST, the number of non-zero elements of the matrix.cscColOffsets(OUT): DEVICE, the pointer to the column offsets array, with a length ofcols + 1.cscRowInd(OUT): DEVICE, the pointer to the row indices array, with a length ofnnz.cscValues(OUT): DEVICE, the pointer to the array of non-zero element values, with a length ofnnz.cscColOffsetsType(OUT): HOST, the data type of the column offsets array.cscRowIndType(OUT): HOST, the data type of the row indices array.idxBase(OUT): HOST, the index base.valueType(OUT): HOST, the data type of the non-zero element values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or not a sparse matrix descriptor handle (a descriptor of another type is passed in by mistake, such as a dense vector or dense matrix descriptor)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: The descriptor is not in CSC format- Other values: Failure
aclsparseConstCscGet
aclsparseStatus_t aclsparseConstCscGet(
aclsparseConstSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz,
const void **cscColOffsets,
const void **cscRowInd,
const void **cscValues,
aclsparseIndexType_t *cscColOffsetsType,
aclsparseIndexType_t *cscRowIndType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of the read-only (const) CSC sparse matrix descriptor. This function is the const variant of aclsparseCscGet: the descriptor is aclsparseConstSpMatDescr_t, and the device pointers read back are const void**. Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameters:
spMatDescr(IN): HOST, the read-only (const) CSC sparse matrix descriptor.rows(OUT): HOST, the number of rows of the matrix.cols(OUT): HOST, the number of columns of the matrix.nnz(OUT): HOST, the number of non-zero elements of the matrix.cscColOffsets(OUT): DEVICE, the pointer to the column offsets array, with a length ofcols + 1.cscRowInd(OUT): DEVICE, the pointer to the row indices array, with a length ofnnz.cscValues(OUT): DEVICE, the pointer to the array of non-zero element values, with a length ofnnz.cscColOffsetsType(OUT): HOST, the data type of the column offsets array.cscRowIndType(OUT): HOST, the data type of the row indices array.idxBase(OUT): HOST, the index base.valueType(OUT): HOST, the data type of the non-zero element values.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or not a sparse matrix descriptor handle (a descriptor of another type is passed in by mistake, such as a dense vector or dense matrix descriptor)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: The descriptor is not in CSC format- Other values: Failure
aclsparseCreateCoo
aclsparseStatus_t aclsparseCreateCoo(
aclsparseSpMatDescr_t *spMatDescr,
int64_t rows,
int64_t cols,
int64_t nnz,
void *cooRowInd,
void *cooColInd,
void *cooValues,
aclsparseIndexType_t cooIdxType,
aclsparseIndexBase_t idxBase,
aclDataType valueType
);
Function: Creates a sparse matrix in COO (Coordinate) format.
Index type support: COO descriptors support
ACL_SPARSE_INDEX_32IandACL_SPARSE_INDEX_64I, and cooIdxType constrains both the row and column indices. CooGet is a pure host accessor and does not involve NPU computation, so both index types are accepted (consistent with cuSPARSE cusparseCreateCoo).
Parameters:
spMatDescr(IN/OUT): HOST, the sparse matrix descriptor.rows(IN): HOST, the number of rows of the matrix.cols(IN): HOST, the number of columns of the matrix.nnz(IN): HOST, the number of non-zero elements of the matrix.cooRowInd(IN): DEVICE, the row indices array, with a length ofnnz.cooColInd(IN): DEVICE, the column indices array, with a length ofnnz.cooValues(IN): DEVICE, the array of non-zero element values, with a length ofnnz.cooIdxType(IN): HOST, the data type of the row/column indices.idxBase(IN): HOST, the index base.valueType(IN): HOST, the data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer, orrows/cols/nnzis negative- Other values: Failure
aclsparseCreateConstCoo
aclsparseStatus_t aclsparseCreateConstCoo(
aclsparseConstSpMatDescr_t *spMatDescr,
int64_t rows,
int64_t cols,
int64_t nnz,
const void *cooRowInd,
const void *cooColInd,
const void *cooValues,
aclsparseIndexType_t cooIdxType,
aclsparseIndexBase_t idxBase,
aclDataType valueType
);
Function: Creates a read-only (const) sparse matrix in COO format. This function is the const variant of aclsparseCreateCoo: the data pointers are const, the constructed descriptor is aclsparseConstSpMatDescr_t, and it can only be passed to APIs that accept const parameters. Index type support is the same as that of aclsparseCreateCoo.
Parameters:
spMatDescr(IN/OUT): HOST, the read-only (const) sparse matrix descriptor.rows(IN): HOST, the number of rows of the matrix.cols(IN): HOST, the number of columns of the matrix.nnz(IN): HOST, the number of non-zero elements of the matrix.cooRowInd(IN): DEVICE, the row indices array, with a length ofnnz.cooColInd(IN): DEVICE, the column indices array, with a length ofnnz.cooValues(IN): DEVICE, the array of non-zero element values, with a length ofnnz.cooIdxType(IN): HOST, the data type of the row/column indices.idxBase(IN): HOST, the index base.valueType(IN): HOST, the data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer, orrows/cols/nnzis negative- Other values: Failure
aclsparseCooGet
aclsparseStatus_t aclsparseCooGet(
aclsparseSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz,
void **cooRowInd,
void **cooColInd,
void **cooValues,
aclsparseIndexType_t *cooIdxType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of the COO sparse matrix descriptor. Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameters:
spMatDescr(IN): HOST, the COO sparse matrix descriptor.rows(OUT): HOST, the number of rows of the matrix.cols(OUT): HOST, the number of columns of the matrix.nnz(OUT): HOST, the number of non-zero elements of the matrix.cooRowInd(OUT): DEVICE, the pointer to the row indices array.cooColInd(OUT): DEVICE, the pointer to the column indices array.cooValues(OUT): DEVICE, the pointer to the array of non-zero element values.cooIdxType(OUT): HOST, the data type of the row/column indices.idxBase(OUT): HOST, the index base.valueType(OUT): HOST, the data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointerACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: The descriptor is not in COO format- Other values: Failure
aclsparseConstCooGet
aclsparseStatus_t aclsparseConstCooGet(
aclsparseConstSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz,
const void **cooRowInd,
const void **cooColInd,
const void **cooValues,
aclsparseIndexType_t *cooIdxType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of the read-only (const) COO sparse matrix descriptor. This function is the const variant of aclsparseCooGet: the descriptor is aclsparseConstSpMatDescr_t, and the device pointers read back are const void**. Output parameters can be nullptr; in this case, only the requested fields are returned.
Parameters:
spMatDescr(IN): HOST, the read-only (const) COO sparse matrix descriptor.rows(OUT): HOST, the number of rows of the matrix.cols(OUT): HOST, the number of columns of the matrix.nnz(OUT): HOST, the number of non-zero elements of the matrix.cooRowInd(OUT): DEVICE, the pointer to the row indices array.cooColInd(OUT): DEVICE, the pointer to the column indices array.cooValues(OUT): DEVICE, the pointer to the array of non-zero element values.cooIdxType(OUT): HOST, the data type of the row/column indices.idxBase(OUT): HOST, the index base.valueType(OUT): HOST, the data type of the non-zero elements.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointerACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: The descriptor is not in COO format- Other values: Failure
aclsparseCooSetStridedBatch
aclsparseStatus_t aclsparseCooSetStridedBatch(
aclsparseSpMatDescr_t spMatDescr,
int batchCount,
int64_t batchStride
);
Function: Sets the batch count and batch stride of the COO sparse matrix descriptor (modeled on cuSPARSE cusparseCooSetStridedBatch), so that a single COO descriptor can represent a batched sparse matrix. batchStride is the element offset (not a byte offset) between the start addresses of cooRowInd / cooColInd / cooValues of two adjacent batches; batchStride = 0 indicates broadcasting — all batches share the same set of row/col/values arrays (the same sparse pattern is broadcast to all batches, the array length is still nnz, aligned with the 0=broadcast convention of the official cuSPARSE samples and the BSR of this repository); every other valid value must satisfy batchStride >= nnz, that is, the user arrays are laid out as [batchStride * batchCount] elements, and the array start offset of batch i is batchStride * i. This is a pure host descriptor operation and does not launch an NPU kernel; this API can be called multiple times on the same descriptor, and the later value overwrites the earlier one.
Parameters:
spMatDescr(IN/OUT): HOST, the COO sparse matrix descriptor (created byaclsparseCreateCoo; the batchCount / batchStride fields are written).batchCount(IN): HOST, the batch count, in the range1..65535.batchStride(IN): HOST, the element offset between adjacent batches; valid values are0(broadcast) or>= nnz, and negative values are invalid; for a positive value, the address range(batchCount-1)*batchStride+nnzmust not overflow int64.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature,batchCountis out of the range[1, 65535],batchStrideis invalid (a negative value or0 < batchStride < nnz), or the address range overflows int64ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: the descriptor is not in COO format- Other values: Failure
Description: When the batch metadata actually changes, the API invalidates the existing preprocess caches of the descriptor (sddmm and so on).
aclsparseCreateBlockedEll
aclsparseStatus_t aclsparseCreateBlockedEll(
aclsparseSpMatDescr_t *descr,
int64_t rows,
int64_t cols,
int64_t ellBlockSize,
int64_t ellCols,
void *ellColInd,
void *ellValue,
aclsparseIndexType_t indexType,
aclsparseIndexBase_t indexBase,
aclDataType valueType
);
Function: Creates a sparse matrix descriptor in Blocked-ELL (Blocked Ellpack) format (aligned with cuSPARSE cusparseCreateBlockedEll), and stores the dimensions, the block size, the device pointers of the column-block index and the value array, together with the index type, the index base, and the value type, in the descriptor. This API is a pure host operation, does not launch an NPU kernel, and does not involve stream synchronization. The implementation resides in the common layer, is architecture-independent, and is built on all platforms together with the sparse operator library (a BELL descriptor can be used as the BELL input of DenseToSparse; see the densetosparse operator; the aclsparseBlockedEllGet / aclsparseConstBlockedEllGet accessors are provided only on arch35).
Data layout:
ellColIndis arranged in row-major order over the block grid (task = *block row index* * ceil(ellCols/ellBlockSize) + *slot index*), with a length ofceil(rows/ellBlockSize) * ceil(ellCols/ellBlockSize)and a value range of[idxBase, ceil(cols/ellBlockSize)-1+idxBase]; empty slots are represented by-1.ellValueis stored contiguously by task (in one-to-one correspondence with the slots ofellColInd); each task is one contiguousellBlockSize × ellBlockSizeblock, and the layout within a block is column-major (valuePos = task * ellBlockSize^2 + innerCol * ellBlockSize + innerRow). The total capacity isceil(rows/ellBlockSize) * ceil(ellCols/ellBlockSize) * ellBlockSize^2(the tail block is padded with zeros). Note: the physical layout ofellValuein aclsparse differs from that in cuSPARSE (row-major order with arows × ellColsstride and row-major within a block). When migrating from cuSPARSE, you need to rearrange the data according to the preceding formulas.Index type support:
indexTypesupportsACL_SPARSE_INDEX_32IandACL_SPARSE_INDEX_64I(the accessor layer performs no NPU computation, consistent with cuSPARSE).
Parameter Description:
descr(IN/OUT): HOST, the Blocked-ELL sparse matrix descriptor (output handle). No initialization is required before the call.rows(IN): HOST, the number of rows in the matrix.cols(IN): HOST, the number of columns in the matrix.ellBlockSize(IN): HOST, the ELL block size (side length of a square block).ellCols(IN): HOST, the actual number of columns in Blocked-ELL format (the number of columns ofellValue).ellColInd(IN): DEVICE, the column-block index array, with a length ofceil(rows/ellBlockSize) * ceil(ellCols/ellBlockSize).ellValue(IN): DEVICE, the array of non-zero element values, which storesellBlockSize × ellBlockSizeblocks contiguously in row-major order over the block grid (column-major within a block), with a total capacity ofceil(rows/ellBlockSize) * ceil(ellCols/ellBlockSize) * ellBlockSize^2.indexType(IN): HOST, the data type ofellColInd.indexBase(IN): HOST, the base value of the index.valueType(IN): HOST, the data type ofellValue.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:descris a null pointer; orrows/cols/ellColsare negative orellBlockSize <= 0; orindexType/indexBasehave invalid values; or the number of block slots ofellColsexceedsceil(cols/ellBlockSize); or the block-grid capacity after padding overflows int64; orellColInd/ellValueare null pointers when the capacity is > 0- Other values: Failure
aclsparseBlockedEllGet
aclsparseStatus_t aclsparseBlockedEllGet(
aclsparseSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *ellBlockSize,
int64_t *ellCols,
void **ellColInd,
void **ellValue,
aclsparseIndexType_t *ellIdxType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of a Blocked-ELL sparse matrix descriptor (aligned with cuSPARSE cusparseBlockedEllGet). Output parameters can be nullptr, in which case only the requested fields are returned. The device pointers read back are the pointers currently bound to the descriptor (initially the values passed in to aclsparseCreateBlockedEll; after values are rebound through aclsparseSpMatSetValues, the new pointers are read back).
Parameter Description:
spMatDescr(IN): HOST, the Blocked-ELL sparse matrix descriptor.rows(OUT): HOST, the number of rows in the matrix.cols(OUT): HOST, the number of columns in the matrix.ellBlockSize(OUT): HOST, the ELL block size.ellCols(OUT): HOST, the actual number of columns in Blocked-ELL format (the number of columns ofellValue).ellColInd(OUT): DEVICE, the pointer to the column-block index array, with a length ofceil(rows/ellBlockSize) * ceil(ellCols/ellBlockSize).ellValue(OUT): DEVICE, the pointer to the array of non-zero element values, which storesellBlockSize × ellBlockSizeblocks contiguously in row-major order over the block grid (column-major within a block), with a total capacity ofceil(rows/ellBlockSize) * ceil(ellCols/ellBlockSize) * ellBlockSize^2.ellIdxType(OUT): HOST, the data type ofellColInd.idxBase(OUT): HOST, the index base value ofellColInd.valueType(OUT): HOST, the data type ofellValue.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature (a handle of the wrong type)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: the descriptor is not in Blocked-ELL format- Other values: Failure
aclsparseConstBlockedEllGet
aclsparseStatus_t aclsparseConstBlockedEllGet(
aclsparseConstSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *ellBlockSize,
int64_t *ellCols,
const void **ellColInd,
const void **ellValue,
aclsparseIndexType_t *ellIdxType,
aclsparseIndexBase_t *idxBase,
aclDataType *valueType
);
Function: Obtains all fields of a read-only (const) Blocked-ELL sparse matrix descriptor. It is the const variant of aclsparseBlockedEllGet (aligned with cuSPARSE cusparseConstBlockedEllGet): the descriptor is aclsparseConstSpMatDescr_t, and the device pointers read back are const void**. Output parameters can be nullptr, in which case only the requested fields are returned.
Parameter Description:
spMatDescr(IN): HOST, the read-only (const) Blocked-ELL sparse matrix descriptor.rows(OUT): HOST, the number of rows in the matrix.cols(OUT): HOST, the number of columns in the matrix.ellBlockSize(OUT): HOST, the ELL block size.ellCols(OUT): HOST, the actual number of columns in Blocked-ELL format (the number of columns ofellValue).ellColInd(OUT): DEVICE, the pointer to the column-block index array.ellValue(OUT): DEVICE, the pointer to the array of non-zero element values.ellIdxType(OUT): HOST, the data type ofellColInd.idxBase(OUT): HOST, the index base value ofellColInd.valueType(OUT): HOST, the data type ofellValue.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature (a handle of the wrong type)ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: the descriptor is not in Blocked-ELL format- Other values: Failure
aclsparseDestroySpMat
aclsparseStatus_t aclsparseDestroySpMat(aclsparseConstSpMatDescr_t spMatDescr);
Function: Destroys a sparse matrix object. If nullptr is passed, the API performs no operation and returns ACL_SPARSE_STATUS_SUCCESS (null-tolerance contract, aligned with cuSPARSE).
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor, which can benullptr.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMatGetFormat
aclsparseStatus_t aclsparseSpMatGetFormat(
aclsparseConstSpMatDescr_t spMatDescr,
aclsparseFormat_t *format
);
Function: Obtains the storage format of a sparse matrix descriptor. The API accepts a const descriptor, and a non-const descriptor is also supported.
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor.format(OUT): HOST, the storage format. When it is a null pointer, no write-back occurs and the API still returns success.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature
aclsparseSpMatGetIndexBase
aclsparseStatus_t aclsparseSpMatGetIndexBase(
aclsparseConstSpMatDescr_t spMatDescr,
aclsparseIndexBase_t *idxBase
);
Function: Obtains the index base value (ACL_SPARSE_INDEX_BASE_ZERO / ACL_SPARSE_INDEX_BASE_ONE) of a sparse matrix descriptor, that is, the idxBase passed in when the descriptor was created. The API is aligned with cuSPARSE cusparseSpMatGetIndexBase. The API accepts a const descriptor, and a non-const descriptor is also supported.
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor.idxBase(OUT): HOST, the index base value. When it is a null pointer, no write-back occurs and the API still returns success.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature
aclsparseSpMatGetValues
aclsparseStatus_t aclsparseSpMatGetValues(
aclsparseSpMatDescr_t spMatDescr,
void **values
);
Function: Obtains the values pointer of a sparse matrix descriptor.
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor.values(OUT): DEVICE, the pointer to the value array, with a length ofnnz.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer
aclsparseSpMatSetValues
aclsparseStatus_t aclsparseSpMatSetValues(
aclsparseSpMatDescr_t spMatDescr,
void *values
);
Function: Sets the values pointer of a sparse matrix descriptor.
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor.values(IN): DEVICE, the pointer to the value array, with a length ofnnz.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer
aclsparseSpMatGetSize
aclsparseStatus_t aclsparseSpMatGetSize(
aclsparseConstSpMatDescr_t spMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *nnz
);
Function: Obtains the number of rows, the number of columns, and the number of non-zero elements of a sparse matrix. The API accepts a const descriptor, and a non-const descriptor is also supported. Output parameters can be nullptr, in which case only the requested fields are returned.
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor.rows(OUT): HOST, the number of rows in the sparse matrix.cols(OUT): HOST, the number of columns in the sparse matrix.nnz(OUT): HOST, the number of non-zero elements in the sparse matrix.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer
aclsparseSpMatGetStridedBatch
aclsparseStatus_t aclsparseSpMatGetStridedBatch(
aclsparseConstSpMatDescr_t spMatDescr,
int *batchCount
);
Function: Obtains the batch count of a sparse matrix descriptor (aligned with cuSPARSE cusparseSpMatGetStridedBatch). The API applies to sparse matrix descriptors in any format (COO/CSR/CSC and so on), accepts a const descriptor, and also supports a non-const descriptor. A newly created descriptor for which aclsparseCooSetStridedBatch / aclsparseBsrSetStridedBatch / aclsparseCsrSetStridedBatch has never been called returns 1 (not batched). The API is a pure host descriptor operation and does not launch an NPU kernel.
Parameter Description:
spMatDescr(IN): HOST, the sparse matrix descriptor.batchCount(OUT): HOST, the batch count.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:spMatDescris a null pointer or has an invalid signature (a handle of the wrong type or a corrupted handle), orbatchCountis a null pointer- Other values: Failure
Read-Only (const) Descriptor Construction APIs
The read-only (const) construction APIs take const data pointers. The constructed descriptors are const variants and can be passed only to APIs that accept const parameters. aclsparseCreateConstCsc can create a read-only CSC descriptor, which serves as the CSC input of SparseToDense. The destruction APIs (aclsparseDestroyDnVec / aclsparseDestroySpMat / aclsparseDestroyDnMat / aclsparseDestroySpVec) uniformly accept const variants, so both const and non-const descriptors can be destroyed.
aclsparseStatus_t aclsparseCreateConstDnVec(aclsparseConstDnVecDescr_t *dnVecDescr, int64_t size,
const void *values, aclDataType valueType);
aclsparseStatus_t aclsparseCreateConstCsr(aclsparseConstSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz,
const void *csrRowOffsets, const void *csrColInd, const void *csrValues, aclsparseIndexType_t csrRowOffsetsType,
aclsparseIndexType_t csrColIndType, aclsparseIndexBase_t idxBase, aclDataType valueType);
aclsparseStatus_t aclsparseConstCsrGet(aclsparseConstSpMatDescr_t spMatDescr, int64_t *rows, int64_t *cols,
int64_t *nnz, const void **csrRowOffsets, const void **csrColInd, const void **csrValues,
aclsparseIndexType_t *csrRowOffsetsType, aclsparseIndexType_t *csrColIndType,
aclsparseIndexBase_t *idxBase, aclDataType *valueType);
aclsparseStatus_t aclsparseCreateConstCsc(aclsparseConstSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz,
const void *cscColOffsets, const void *cscRowInd, const void *cscValues, aclsparseIndexType_t cscColOffsetsType,
aclsparseIndexType_t cscRowIndType, aclsparseIndexBase_t idxBase, aclDataType valueType);
aclsparseStatus_t aclsparseCreateConstDnMat(aclsparseConstDnMatDescr_t *dnMatDescr,
int64_t rows, int64_t cols, int64_t ld, const void *values,
aclDataType valueType, aclsparseOrder_t order);
aclsparseStatus_t aclsparseConstSpMatGetValues(aclsparseConstSpMatDescr_t spMatDescr,
const void **values);
aclsparseStatus_t aclsparseCreateConstCoo(aclsparseConstSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz,
const void *cooRowInd, const void *cooColInd, const void *cooValues, aclsparseIndexType_t cooIdxType,
aclsparseIndexBase_t idxBase, aclDataType valueType);
aclsparseStatus_t aclsparseConstCooGet(aclsparseConstSpMatDescr_t spMatDescr, int64_t *rows, int64_t *cols,
int64_t *nnz, const void **cooRowInd, const void **cooColInd, const void **cooValues,
aclsparseIndexType_t *cooIdxType, aclsparseIndexBase_t *idxBase, aclDataType *valueType);
aclsparseStatus_t aclsparseConstCscGet(aclsparseConstSpMatDescr_t spMatDescr, int64_t *rows, int64_t *cols,
int64_t *nnz, const void **cscColOffsets, const void **cscRowInd, const void **cscValues,
aclsparseIndexType_t *cscColOffsetsType, aclsparseIndexType_t *cscRowIndType,
aclsparseIndexBase_t *idxBase, aclDataType *valueType);
Support status:
aclsparseCreateConstCsccan create a read-only CSC descriptor. The current version of SpMV / SpMM supports only CSR sparse matrices, and a CSC descriptor cannot be used for these two computation APIs.
aclsparseSpMVGetBufferSize
aclsparseStatus_t aclsparseSpMVGetBufferSize(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
const void *alpha,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnVecDescr_t vecX,
const void *beta,
aclsparseDnVecDescr_t vecY,
aclDataType computeType,
aclsparseSpMVAlg_t alg,
size_t *bufferSize
);
Function: Obtains the buffer size required for the sparse matrix-vector multiplication (SpMV) operation.
Parameter Description:
handle(IN): HOST, the sparse computation handle.opA(IN): HOST, the sparse operation type.alpha(IN): HOST/DEVICE, the scalar alpha parameter.matA(IN): HOST, the sparse matrix descriptor.vecX(IN): HOST, the descriptor of input vector x.beta(IN): HOST/DEVICE, the scalar beta parameter.vecY(IN): HOST, the descriptor of output vector y.computeType(IN): HOST, the data type of the computation.alg(IN): HOST, the SpMV algorithm type.bufferSize(OUT): HOST, the required buffer size.
Description: For ACL_SPARSE_SPMV_ALG_DEFAULT (the vector version), all intermediate quantities reside in the UB, and the API returns 0.
ACL_SPARSE_SPMV_CSR_ALG_CUBE returns the workspace size required for segmented summation. The caller must allocate
device memory of this size and pass it in as the externalBuffer of aclsparseSpMV. An empty matrix (nnz == 0) falls back to
the vector version implementation, which also returns 0.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVPreprocess
aclsparseStatus_t aclsparseSpMVPreprocess(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
const void *alpha,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnVecDescr_t vecX,
const void *beta,
aclsparseDnVecDescr_t vecY,
aclDataType computeType,
aclsparseSpMVAlg_t alg,
void *externalBuffer
);
Function: Preprocesses a sparse matrix so that subsequent SpMV computations can reuse the working buffer and the computation is accelerated.
Parameter Description:
handle(IN): HOST, the sparse computation handle.opA(IN): HOST, the sparse matrix operation type.alpha(IN): HOST/DEVICE, the scalar alpha parameter.matA(IN): HOST, the sparse matrix descriptor.vecX(IN): HOST, the descriptor of input vector x.beta(IN): HOST/DEVICE, the scalar beta parameter.vecY(IN): HOST, the descriptor of output vector y.computeType(IN): HOST, the data type of the computation.alg(IN): HOST, the SpMV algorithm type.externalBuffer(IN): DEVICE, the working buffer (which must be allocated by callingaclsparseSpMVGetBufferSizefirst).
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMV
aclsparseStatus_t aclsparseSpMV(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
const void *alpha,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnVecDescr_t vecX,
const void *beta,
aclsparseDnVecDescr_t vecY,
aclDataType computeType,
aclsparseSpMVAlg_t alg,
void *externalBuffer
);
Function: Performs sparse matrix-vector multiplication (SpMV). The sparse matrix matA must be in CSR format (formats such as CSC / COO return ACL_SPARSE_STATUS_NOT_SUPPORTED).
Parameter Description:
handle(IN): HOST, the sparse matrix processor handle.opA(IN): HOST, the sparse matrix operator.alpha(IN): HOST/DEVICE, the scalar alpha.matA(IN): HOST, the sparse matrix descriptor.vecX(IN): HOST, the dense vector x descriptor.beta(IN): HOST/DEVICE, the scalar beta.vecY(IN/OUT): HOST, the dense vector y descriptor.computeType(IN): HOST, the computation type.alg(IN): HOST, the sparse matrix-vector multiplication algorithm.externalBuffer(IN): DEVICE, the pointer to the working buffer.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseCreateDnMat
aclsparseStatus_t aclsparseCreateDnMat(
aclsparseDnMatDescr_t *dnMatDescr,
int64_t rows,
int64_t cols,
int64_t ld,
void *values,
aclDataType valueType,
aclsparseOrder_t order
);
Function: Creates a dense matrix descriptor, which is used to describe the B/C dense matrices in SpMM.
Parameter Description:
dnMatDescr(IN/OUT): HOST, the output dense matrix descriptor.rows(IN): HOST, the number of rows in the matrix, which can be 0 but cannot be negative.cols(IN): HOST, the number of columns in the matrix, which can be 0 but cannot be negative.ld(IN): HOST, leading dimension. It must be >= cols in row-major order and >= rows in column-major order. It must be greater than 0, and this constraint also applies to zero-dimension matrices.values(IN): DEVICE, the matrix data pointer. It must be non-empty when both rows and cols are greater than 0, and it can be empty when either is 0.valueType(IN): HOST, the data type of elements.ACL_FLOAT/ACL_FLOAT16/ACL_INT8are supported when the matrix serves as matrix B;ACL_FLOAT/ACL_FLOAT16/ACL_INT32are supported when the matrix serves as matrix C (ACL_INT32is used as the matrix C type only in the int8 computation path).order(IN): HOST, the layout:ACL_SPARSE_ORDER_ROW(row-major order) /ACL_SPARSE_ORDER_COL(column-major order).
Description: A zero-dimension dense matrix descriptor with rows/cols of 0 can be created normally. The aclsparseSDDMM API on arch35 returns successfully when m/n is 0 and the pattern is empty, and performs beta scaling when k is 0. The aclsparseSDDMM API on arch22 returns ACL_SPARSE_STATUS_INVALID_VALUE for zero-dimension input. For the zero-dimension semantics of other computation APIs, see the documentation of the corresponding operators.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseDestroyDnMat
aclsparseStatus_t aclsparseDestroyDnMat(aclsparseConstDnMatDescr_t dnMatDescr);
Function: Destroys a dense matrix descriptor. If nullptr is passed, the API performs no operation and returns ACL_SPARSE_STATUS_SUCCESS (null-tolerance contract, aligned with cuSPARSE).
Parameter Description:
dnMatDescr(IN): HOST, the dense matrix descriptor to destroy, which can benullptr.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseDnMatGet
aclsparseStatus_t aclsparseDnMatGet(
aclsparseDnMatDescr_t dnMatDescr,
int64_t *rows,
int64_t *cols,
int64_t *ld,
void **values,
aclDataType *valueType,
aclsparseOrder_t *order
);
Function: Obtains all fields of a dense matrix descriptor. Output parameters can be nullptr, in which case only the requested fields are returned.
Parameter Description:
dnMatDescr(IN): HOST, the dense matrix descriptor.rows(OUT): HOST, the number of rows in the matrix.cols(OUT): HOST, the number of columns in the matrix.ld(OUT): HOST, leading dimension.values(OUT): DEVICE, the matrix data pointer.valueType(OUT): HOST, the data type of elements.order(OUT): HOST, the memory layout.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:dnMatDescris a null pointer
aclsparseDnMatGetValues
aclsparseStatus_t aclsparseDnMatGetValues(
aclsparseDnMatDescr_t dnMatDescr,
void **values
);
Function: Obtains the values pointer of a dense matrix descriptor.
Parameter Description:
dnMatDescr(IN): HOST, the dense matrix descriptor.values(OUT): DEVICE, the matrix data pointer.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:dnMatDescris a null pointer
aclsparseDnMatSetValues
aclsparseStatus_t aclsparseDnMatSetValues(
aclsparseDnMatDescr_t dnMatDescr,
void *values
);
Function: Sets the values pointer of a dense matrix descriptor.
Parameter Description:
dnMatDescr(IN): HOST, the dense matrix descriptor.values(IN): DEVICE, the matrix data pointer.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_INVALID_VALUE:dnMatDescris a null pointer
aclsparseDnMatGetStridedBatch
aclsparseStatus_t aclsparseDnMatGetStridedBatch(
aclsparseConstDnMatDescr_t dnMatDescr,
int *batchCount, int64_t *batchStride);
Function: Obtains the batch count and the batch start interval of a dense matrix descriptor. batchStride is measured in matrix elements. A newly created descriptor uses batchCount=1 and batchStride=0 by default.
Parameter Description:
dnMatDescr(IN): HOST, the dense matrix descriptor to query.batchCount(OUT): HOST, returns the batch count.batchStride(OUT): HOST, returns the element interval between the start positions of adjacent batches.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The query is successful.ACL_SPARSE_STATUS_INVALID_VALUE: The descriptor or output pointer is empty or invalid.
aclsparseDnMatSetStridedBatch
aclsparseStatus_t aclsparseDnMatSetStridedBatch(
aclsparseDnMatDescr_t dnMatDescr,
int batchCount, int64_t batchStride);
Function: Sets the strided-batch attributes of a dense matrix. The value range of batchCount is 1..65535. When batchCount is greater than 1, the ROW layout requires batchStride >= rows*ld, and the COL layout requires batchStride >= cols*ld. A single batch allows a non-negative stride, and a newly created descriptor uses 0 by default.
Parameter Description:
dnMatDescr(IN/OUT): HOST, the writable dense matrix descriptor to update.batchCount(IN): HOST, the batch count, in the range of 1..65535.batchStride(IN): HOST, the element interval between the start positions of adjacent batches; any non-negative value is allowed for a single batch.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The setting is successful.ACL_SPARSE_STATUS_INVALID_VALUE: The descriptor, batch, stride, layout, or array address range is invalid.
aclsparseSpMMGetBufferSize
aclsparseStatus_t aclsparseSpMMGetBufferSize(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
aclsparseOperation_t opB,
const void *alpha,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnMatDescr_t matB,
const void *beta,
aclsparseDnMatDescr_t matC,
aclDataType computeType,
aclsparseSpMMAlg_t alg,
size_t *size
);
Function: Obtains the size of the workspace buffer required for the sparse matrix-dense matrix multiplication (SpMM) operation.
Parameter Description:
handle(IN): HOST, the sparse computation handle.opA(IN): HOST, the operation type of sparse matrix A, which supports non-transpose, transpose, and conjugate transpose. CSR_ALG3 supports only non-transpose.opB(IN): HOST, the operation type of dense matrix B, which supports non-transpose, transpose, and conjugate transpose under valid algorithm combinations.alpha(IN): HOST/DEVICE, the scalar alpha parameter.matA(IN): HOST, the descriptor of CSR sparse matrix A.matB(IN): HOST, the descriptor of the input dense matrix B.beta(IN): HOST/DEVICE, the scalar beta parameter.matC(IN): HOST, the descriptor of the input/output dense matrix C.computeType(IN): HOST, the data type for computation.alg(IN): HOST, the SpMM algorithm type.size(OUT): HOST, the required workspace buffer size (in bytes).
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMPreprocess
aclsparseStatus_t aclsparseSpMMPreprocess(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
aclsparseOperation_t opB,
const void *alpha,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnMatDescr_t matB,
const void *beta,
aclsparseDnMatDescr_t matC,
aclDataType computeType,
aclsparseSpMMAlg_t alg,
void *buffer
);
Function: Preprocesses a CSR sparse matrix (row reordering and bucketing) so that the matrix can be used in subsequent SpMM computation.
Parameter Description:
handle(IN): HOST, the sparse computation handle.opA(IN): HOST, the operation type of sparse matrix A.opB(IN): HOST, the operation type of dense matrix B.alpha(IN): HOST/DEVICE, the scalar alpha parameter.matA(IN): HOST, the descriptor of CSR sparse matrix A.matB(IN): HOST, the descriptor of the input dense matrix B.beta(IN): HOST/DEVICE, the scalar beta parameter.matC(IN): HOST, the descriptor of the input/output dense matrix C.computeType(IN): HOST, the data type for computation.alg(IN): HOST, the SpMM algorithm type.buffer(IN): DEVICE, the workspace buffer used to store preprocessing results.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMM
aclsparseStatus_t aclsparseSpMM(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
aclsparseOperation_t opB,
const void *alpha,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnMatDescr_t matB,
const void *beta,
aclsparseDnMatDescr_t matC,
aclDataType computeType,
aclsparseSpMMAlg_t alg,
void *buffer
);
Function: Performs sparse matrix-dense matrix multiplication (SpMM) and computes C = alpha * op(A) * op(B) + beta * C. Sparse matrix A must be in CSR format (passing CSC, COO, and other formats to matA returns ACL_SPARSE_STATUS_NOT_SUPPORTED). Zero-dimension input: on arch35, the API returns ACL_SPARSE_STATUS_INVALID_VALUE when any of matA.rows / matA.cols / matC.cols (that is, m/k/n) is 0. Atlas A2 products and Atlas A3 products (arch22) behave differently — M/K/N can all be 0, and zero-length output directly returns ACL_SPARSE_STATUS_SUCCESS (when K=0, the result follows C = beta * C). The three entry points (GetBufferSize / Preprocess / SpMM) behave consistently. For details, see sparse/spmm/README.md.
Parameter Description:
handle(IN): HOST, the sparse matrix processor handle.opA(IN): HOST, the operation type of sparse matrix A, which supports non-transpose, transpose, and conjugate transpose. CSR_ALG3 supports only non-transpose.opB(IN): HOST, the operation type of dense matrix B.alpha(IN): HOST/DEVICE, the scalar alpha.matA(IN): HOST, the descriptor of CSR sparse matrix A.matB(IN): HOST, the descriptor of the input dense matrix B.beta(IN): HOST/DEVICE, the scalar beta.matC(IN/OUT): HOST, the descriptor of the input/output dense matrix C.computeType(IN): HOST, the computation type.alg(IN): HOST, the SpMM algorithm type.buffer(IN): DEVICE, the working buffer pointer (you need to callaclsparseSpMMGetBufferSizefirst to allocate the buffer, and it is recommended that you callaclsparseSpMMPreprocessfirst for preprocessing).
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseCubeSpmm1dCreatePlan
aclsparseStatus_t aclsparseCubeSpmm1dCreatePlan(
aclsparseHandle_t handle, int32_t m, int32_t n, int32_t k,
const int32_t *hostOffsets, size_t offsetCount,
const int32_t *hostColumns, const uint16_t *hostValues, size_t vectors,
const aclsparseCubeSpmm1dOptions *options, aclsparseCubeSpmm1dPlan_t *plan);
Function: Creates a reusable plan from a d=16 vector-CSR array on the host and copies and uploads A.
m must be a multiple of 16; the row-block pointer length is m/16+1; the column indices in each block are strictly increasing;
and the values are 16*vectors finite FP16 bit patterns. plan is a host output parameter, and *plan must be empty before the call.
Product Support: Atlas A2 products and Atlas A3 products, arch22. Board-level testing has been completed only on Ascend910B3;
this API family is not compiled or exported in builds of Ascend 950PR&950DT products (arch35) or other builds without the corresponding implementation.
The following four APIs use the same product boundary.
If options == NULL, adaptive selection is used; if options is not NULL, structSize, tilingKey,
reserved, and workspaceLimitBytes must be correctly set. The preparation phase can allocate and upload device data, and you need to prepare again after A changes.
For complete parameters, options, restrictions, and return values, see
Operator API Description.
aclsparseCubeSpmm1dCreateCsrPlan
aclsparseStatus_t aclsparseCubeSpmm1dCreateCsrPlan(
aclsparseHandle_t handle, int32_t m, int32_t n, int32_t k,
const int64_t *hostOffsets, size_t offsetCount,
const int64_t *hostColumns, const uint16_t *hostValues, size_t nnz,
const aclsparseCubeSpmm1dOptions *options, aclsparseCubeSpmm1dPlan_t *plan);
Function: Converts and prepares the same CubeSpMM 1D plan from a standard CSR on the host. Indices start from 0,
the row pointers are int64_t[m+1], the column indices are int64_t[nnz], and the values are finite FP16 bit patterns.
Unsorted sequences, duplicate entries, explicit zeros, and empty rows are supported, and M is padded to a multiple of 16.
Duplicate entries are summed in FP64 in input order and re-quantized to FP16 with RNE, then zeros are removed and the result is converted to vector-CSR; re-quantization may produce different rounding results from item-by-item CSR multiply-add and cannot be regarded as a lossless conversion for all duplicate entries. The input arrays are copied during preparation; A is fixed, and updating A requires re-creating the plan. For parameters and return values, see CSR API Description.
aclsparseCubeSpmm1dGetPlanInfo
aclsparseStatus_t aclsparseCubeSpmm1dGetPlanInfo(
aclsparseCubeSpmm1dPlan_t plan, aclsparseCubeSpmm1dPlanInfo *info);
Function: Writes the information of a valid plan to non-empty host info, including the logical M/N/K, paddedM,
paddedN, configuration key, device/number of cores, number of vectors, and the device byte sizes of B/C/workspace/A.
The caller must allocate buffers based on the query result and must not use logical sizes in place of physical capacity. For fields and return values, see
Plan Query Description.
aclsparseCubeSpmm1dExecute
aclsparseStatus_t aclsparseCubeSpmm1dExecute(
aclsparseHandle_t handle, aclsparseCubeSpmm1dPlan_t plan,
const void *b, size_t bBytes, void *c, size_t cBytes,
void *workspace, size_t workspaceBytes);
Function: Zeros the physical C first on the stream bound to handle and then asynchronously submits C=A×B;
only finite FP16 A/B and FP32 C are supported, and transpose, alpha/beta scaling, or batch semantics are not provided.
- B is Device row-major
[K,paddedN]with the trailing columns padded with zeros; C is Device column-major[paddedM,paddedN]. - B/C/workspace must be non-empty, 32-byte aligned, located on the device/context used at preparation time, and not overlap with each other; capacities are passed in bytes.
- Execution does not perform device allocation or tensor H2D/D2H. The caller must synchronize the stream to check asynchronous errors and ensure that the plan and all buffers remain alive before the work is completed.
For precise capacity, layout, and lifecycle constraints and return values, see Execution API Description.
aclsparseCubeSpmm1dDestroyPlan
aclsparseStatus_t aclsparseCubeSpmm1dDestroyPlan(aclsparseCubeSpmm1dPlan_t plan);
Function: Releases the plan and the device A it holds, does not release the caller's B/C/workspace, and does not wait for the stream.
The caller must complete all executions that use the plan first and destroy the plan in the context where the plan was created.
A null plan returns ACL_SPARSE_STATUS_SUCCESS. For detailed constraints and return values, see
Plan Destruction Description.
aclsparseSDDMMBufferSize
aclsparseStatus_t aclsparseSDDMMBufferSize(
aclsparseHandle_t handle,
aclsparseOperation_t opX, aclsparseOperation_t opY,
const void *alpha, aclsparseConstDnMatDescr_t matX,
aclsparseConstDnMatDescr_t matY, const void *beta,
aclsparseSpMatDescr_t matC, aclDataType computeType,
aclsparseSDDMMAlg_t alg, size_t *size);
Function: Validates the SDDMM call metadata and returns the number of Device workspace bytes required for preprocessing and execution. The return value can be 0. A non-zero workspace must be allocated with 64-byte alignment.
Parameter Description:
handle(IN): HOST, the sparse operator handle.opX(IN): HOST, the operation type of X, which supportsACL_SPARSE_OP_NON_TRANSPOSEandACL_SPARSE_OP_TRANSPOSE.opY(IN): HOST, the operation type of Y, which supportsACL_SPARSE_OP_NON_TRANSPOSEandACL_SPARSE_OP_TRANSPOSE.alpha(IN): HOST/DEVICE, the product coefficient ofcomputeType; the location is determined by the handle pointer mode.matX(IN): HOST, a read-only dense matrix X descriptor.matY(IN): HOST, a read-only dense matrix Y descriptor.beta(IN): HOST/DEVICE, the coefficient of the old value of C ofcomputeType; the location is determined by the handle pointer mode.matC(IN): HOST, a writable CSR/BSR sparse matrix C descriptor; this API does not modify its data.computeType(IN): HOST, the data type for accumulation and foralpha/beta;ACL_FLOATfor the real-number path andACL_COMPLEX64for the complex-number path.alg(IN): HOST, the algorithm type. Currently onlyACL_SPARSE_SDDMM_ALG_DEFAULTis supported.size(OUT): HOST, returns the number of Device workspace bytes required by Preprocess and Execute.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The query is successful.ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR:handleis empty.ACL_SPARSE_STATUS_INVALID_VALUE: The descriptor, dimensions, pointer, batch, or layout is invalid.ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:matCis not CSR or BSR.ACL_SPARSE_STATUS_NOT_SUPPORTED: The combination of operation, algorithm, index, or data type is not supported.
aclsparseSDDMMPreprocess
aclsparseStatus_t aclsparseSDDMMPreprocess(
aclsparseHandle_t handle,
aclsparseOperation_t opX, aclsparseOperation_t opY,
const void *alpha, aclsparseConstDnMatDescr_t matX,
aclsparseConstDnMatDescr_t matY, const void *beta,
aclsparseSpMatDescr_t matC, aclDataType computeType,
aclsparseSDDMMAlg_t alg, void *buffer);
Function: Validates the CSR/BSR pattern on the stream bound to handle and binds the prepared state to matC, the shape/layout/data type parameters of this call, and buffer. This phase reads only X, Y, and the sparse structure of C, and does not modify C values.
Preprocess can be called explicitly. If you call aclsparseSDDMM directly and the prepared key does not match, the execution API automatically performs the equivalent preprocessing. After changing the offsets/indices content in place, the caller must call this API again.
Parameter Description:
handle(IN): HOST, the sparse operator handle; pattern validation is submitted to the stream bound to it.opX(IN): HOST, the operation type of X, which supportsACL_SPARSE_OP_NON_TRANSPOSEandACL_SPARSE_OP_TRANSPOSE.opY(IN): HOST, the operation type of Y, which supportsACL_SPARSE_OP_NON_TRANSPOSEandACL_SPARSE_OP_TRANSPOSE.alpha(IN): HOST/DEVICE, the product coefficient ofcomputeType; the location is determined by the handle pointer mode.matX(IN): HOST, a read-only dense matrix X descriptor; X values are not read in this phase.matY(IN): HOST, a read-only dense matrix Y descriptor; Y values are not read in this phase.beta(IN): HOST/DEVICE, the coefficient of the old value of C ofcomputeType; the location is determined by the handle pointer mode.matC(IN/OUT): HOST/DEVICE, a writable CSR/BSR sparse matrix C descriptor; the API reads the sparse pattern and updates the prepared state in the descriptor, and does not modify C values.computeType(IN): HOST, the data type for accumulation and foralpha/beta;ACL_FLOATfor the real-number path andACL_COMPLEX64for the complex-number path.alg(IN): HOST, the algorithm type. Currently onlyACL_SPARSE_SDDMM_ALG_DEFAULTis supported.buffer(IN/OUT): DEVICE, the workspace returned byaclsparseSDDMMBufferSize; when the size is non-zero, it must be 64-byte aligned and its lifecycle must cover subsequent Execute calls, and it can be empty when the required size is 0.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The preprocessing is successful.ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR:handleis empty.ACL_SPARSE_STATUS_INVALID_VALUE: The parameters, sparse pattern, or workspace alignment is invalid.ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:matCis not CSR or BSR.ACL_SPARSE_STATUS_NOT_SUPPORTED: The combination of operation, algorithm, index, or data type is not supported.ACL_SPARSE_STATUS_INSUFFICIENT_RESOURCES: The required workspace is missing.ACL_SPARSE_STATUS_EXECUTION_FAILED: The Runtime operation for pattern validation fails.
aclsparseSDDMM
aclsparseStatus_t aclsparseSDDMM(
aclsparseHandle_t handle,
aclsparseOperation_t opX, aclsparseOperation_t opY,
const void *alpha, aclsparseConstDnMatDescr_t matX,
aclsparseConstDnMatDescr_t matY, const void *beta,
aclsparseSpMatDescr_t matC, aclDataType computeType,
aclsparseSDDMMAlg_t alg, void *buffer);
Function: Computes
C = (alpha * op(X) * op(Y) + beta * C) ⊙ spy(C) only at the stored positions of matC and updates C values in place. Assume that the logical shape of C is m×n:
- When
opX=NON_TRANSPOSE, X is m×k; whenopX=TRANSPOSE, X is k×m. - When
opY=NON_TRANSPOSE, Y is k×n; whenopY=TRANSPOSE, Y is n×k. - When
alpha==0, the product term is not read; whenbeta==0, the old value of C is not read, and NaN/Inf values suppressed by zero coefficients do not propagate.
Support Scope: CSR/BSR, I32 indices, base 0/1, ROW/COL dense layouts, and ACL_SPARSE_SDDMM_ALG_DEFAULT. Data type combinations include FP32→FP32, FP16→FP16/FP32, and COMPLEX64→COMPLEX64. BF16 input supports FP32 output in CSR and BF16/FP32 output in BSR. The real-number path uses FP32 compute, and the complex-number path uses COMPLEX64 compute. BSR supports 1..65535 batches, and the batch count of X/Y must be 1 (broadcast) or the same as that of C. CSR currently supports a single batch.
Pointers and Concurrency: The location of alpha/beta is determined by the handle pointer mode. X, Y, and the C pattern are read-only, and C values and the workspace are writable. Multiple-stream calls with the same matC must be serialized. Concurrent calls must use different matC descriptors and non-overlapping workspaces. Different streams must also use separate handles and comply with the data lifecycle of each stream.
Parameter Description:
handle(IN): HOST, the sparse operator handle; the computation is submitted to the stream bound to it.opX(IN): HOST, the operation type of X, which supportsACL_SPARSE_OP_NON_TRANSPOSEandACL_SPARSE_OP_TRANSPOSE.opY(IN): HOST, the operation type of Y, which supportsACL_SPARSE_OP_NON_TRANSPOSEandACL_SPARSE_OP_TRANSPOSE.alpha(IN): HOST/DEVICE, the product coefficient ofcomputeType; the location is determined by the handle pointer mode.matX(IN): HOST/DEVICE, the read-only dense matrix X descriptor and data.matY(IN): HOST/DEVICE, the read-only dense matrix Y descriptor and data.beta(IN): HOST/DEVICE, the coefficient of the old value of C ofcomputeType; the location is determined by the handle pointer mode.matC(IN/OUT): HOST/DEVICE, a writable CSR/BSR sparse matrix C descriptor; the pattern is read-only, and values are updated in place.computeType(IN): HOST, the data type for accumulation and foralpha/beta;ACL_FLOATfor the real-number path andACL_COMPLEX64for the complex-number path.alg(IN): HOST, the algorithm type. Currently onlyACL_SPARSE_SDDMM_ALG_DEFAULTis supported.buffer(IN/OUT): DEVICE, the workspace matching the current parameters; when the size is non-zero, it must be 64-byte aligned. When the prepared state does not match, this API automatically performs the equivalent Preprocess.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The submission is successful.ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR:handleis empty.ACL_SPARSE_STATUS_INVALID_VALUE: The parameters, sparse pattern, or workspace is invalid.ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:matCis not CSR or BSR.ACL_SPARSE_STATUS_NOT_SUPPORTED: The combination of operation, algorithm, index, or data type is not supported.ACL_SPARSE_STATUS_INSUFFICIENT_RESOURCES: Device core or workspace resources are insufficient.ACL_SPARSE_STATUS_EXECUTION_FAILED: The Runtime operation for automatic pattern validation fails.
aclsparseSpMVOp_bufferSize
aclsparseStatus_t aclsparseSpMVOp_bufferSize(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnVecDescr_t vecX,
aclsparseConstDnVecDescr_t vecY,
aclsparseDnVecDescr_t vecZ,
aclDataType computeType,
aclsparseSpMVOpAlg_t alg,
size_t *bufferSize);
Function: Obtains the workspace size (in bytes) required by SpMVOp. ALG1 / DEFAULT returns 0. ALG2 returns the total size of the reorder table, temporary reorder table, scratch, temporary scratch, and bin_edge table (including the 64-byte alignment overhead).
The SpMVOp API family follows the descriptor/plan lifecycle pattern, and the calling sequence is: aclsparseSpMVOp_bufferSize → aclsparseSpMVOp_createDescr → aclsparseSpMVOp_createPlan → [optional aclsparseSpMVOp_setGlobalUserData] → aclsparseSpMVOp → aclsparseSpMVOp_destroyPlan → aclsparseSpMVOp_destroyDescr.
Parameter Description:
handle(IN): HOST, the aclsparse handle.opA(IN): HOST, the operation type of matrix A. OnlyACL_SPARSE_OP_NON_TRANSPOSEis supported.matA(IN): HOST, a CSR sparse matrix descriptor.vecX(IN): HOST, the input dense vector descriptor.vecY(IN): HOST, the input dense vector descriptor for the additional addition.vecZ(IN/OUT): HOST, the output dense vector descriptor.computeType(IN): HOST, the computation type. OnlyACL_FLOATis supported.alg(IN): HOST, the SpMVOp algorithm type.bufferSize(OUT): HOST, returns the required number of workspace bytes.
Constraints: matA must be in CSR format, the value type must be FP32, the column index type must be int32, and the row offset type can be int32 or int64.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVOp_createDescr
aclsparseStatus_t aclsparseSpMVOp_createDescr(
aclsparseHandle_t handle,
aclsparseSpMVOpDescr_t *descr,
aclsparseOperation_t opA,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnVecDescr_t vecX,
aclsparseConstDnVecDescr_t vecY,
aclsparseDnVecDescr_t vecZ,
aclDataType computeType,
aclsparseSpMVOpAlg_t alg,
void *buffer);
Function: Creates an internal SpMVOp descriptor and performs preprocessing. For ALG2, preprocessing asynchronously performs sorting and bin_edge load-balancing partitioning on the stream associated with handle.
Parameter Description:
handle(IN): HOST, the aclsparse handle.descr(OUT): HOST, returns the SpMVOp descriptor.opA(IN): HOST, the operation type of matrix A. OnlyACL_SPARSE_OP_NON_TRANSPOSEis supported.matA(IN): HOST, a CSR sparse matrix descriptor.vecX(IN): HOST, the input dense vector descriptor.vecY(IN): HOST, the input dense vector descriptor for the additional addition.vecZ(IN/OUT): HOST, the output dense vector descriptor.computeType(IN): HOST, the computation type. OnlyACL_FLOATis supported.alg(IN): HOST, the SpMVOp algorithm type.buffer(IN): DEVICE, the workspace buffer, for which the caller first queries the size throughaclsparseSpMVOp_bufferSizeand then allocates.
Constraints: For ALG2, buffer cannot be NULL and its size cannot be smaller than the value returned by aclsparseSpMVOp_bufferSize; buffer must remain valid until descr is destroyed.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVOp_destroyDescr
aclsparseStatus_t aclsparseSpMVOp_destroyDescr(aclsparseSpMVOpDescr_t descr);
Function: Destroys an SpMVOp descriptor and releases the host resources it manages. If descr is nullptr, the API directly returns SUCCESS. The execution plan must be destroyed before the descriptor.
Parameter Description: descr (IN): HOST, the SpMVOp descriptor to destroy.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVOp_createPlan
aclsparseStatus_t aclsparseSpMVOp_createPlan(
aclsparseHandle_t handle,
aclsparseSpMVOpDescr_t descr,
aclsparseSpMVOpPlan_t *plan,
const void *epilogueLTOBuffer,
size_t epilogueLTOBufferSize);
Function: Creates an execution plan based on descr. The NPU side uses the identity epilogue. epilogueLTOBuffer must be NULL and epilogueLTOBufferSize must be 0; otherwise, the API returns ACL_SPARSE_STATUS_NOT_SUPPORTED.
Parameter Description:
handle(IN): HOST, the aclsparse handle.descr(IN): HOST, the descriptor fromaclsparseSpMVOp_createDescr.plan(OUT): HOST, returns the execution plan.epilogueLTOBuffer(IN): HOST, the epilogue LTO-IR buffer, which must be NULL on the NPU side.epilogueLTOBufferSize(IN): HOST, the epilogue LTO-IR size, which must be 0 on the NPU side.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVOp_destroyPlan
aclsparseStatus_t aclsparseSpMVOp_destroyPlan(aclsparseSpMVOpPlan_t plan);
Function: Destroys an SpMVOp execution plan. If plan is nullptr, the API directly returns SUCCESS. The API must be called before aclsparseSpMVOp_destroyDescr.
Parameter Description: plan (IN): HOST, the SpMVOp execution plan to destroy.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVOp_setGlobalUserData
aclsparseStatus_t aclsparseSpMVOp_setGlobalUserData(
aclsparseHandle_t handle,
aclsparseSpMVOpPlan_t plan,
const char *epilogueDataName,
void *epilogueData,
size_t epilogueDataSize);
Function: Sets the global user data in the epilogue module. The NPU side uses the identity epilogue. This API is a no-op and directly returns SUCCESS.
Parameter Description:
handle(IN): HOST, the aclsparse handle.plan(IN): HOST, the SpMVOp execution plan.epilogueDataName(IN): HOST, the variable name of the epilogue data.epilogueData(IN): HOST, the pointer to the epilogue data.epilogueDataSize(IN): HOST, the number of data bytes.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMVOp
aclsparseStatus_t aclsparseSpMVOp(
aclsparseHandle_t handle,
aclsparseSpMVOpPlan_t plan,
const void *alpha,
const void *beta,
aclsparseConstDnVecDescr_t vecX,
aclsparseConstDnVecDescr_t vecY,
aclsparseDnVecDescr_t vecZ);
Function: Performs sparse matrix-vector multiplication Z = alpha * A * X + beta * Y. The call is asynchronously enqueued to the stream associated with handle. Both ALG1 and ALG2 provide bit-wise reproducible results.
Parameter Description:
handle(IN): HOST, the aclsparse handle.plan(IN): HOST, the SpMVOp execution plan.alpha(IN): HOST/DEVICE, an FP32 scalar. The pointer mode is determined byaclsparseSetPointerMode.beta(IN): HOST/DEVICE, an FP32 scalar. The pointer mode is determined byaclsparseSetPointerMode.vecX(IN): HOST, the input dense vector descriptor.vecY(IN): HOST, the input dense vector descriptor for the additional addition.vecZ(IN/OUT): HOST, the output dense vector descriptor, which can share device values with vecY to implement in-place operations.
Constraints: Only the CSR format is supported; colIndType must be int32, rowOffsetsType can be int32 or int64, and FP32 is the only supported data type.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp_bufferSize
aclsparseStatus_t aclsparseSpMMOp_bufferSize(
aclsparseHandle_t handle,
aclsparseOperation_t opA,
aclsparseOperation_t opB,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnMatDescr_t matB,
aclsparseDnMatDescr_t matC,
aclDataType computeType,
aclsparseSpMMOpAlg_t alg,
size_t *bufferSize);
Function: Obtains the workspace size (in bytes) required by SpMMOp. ALG1 / DEFAULT returns 0 (no workspace is required). ALG2 returns the total size of the reorder table + bin_edge table (including the alignment overhead).
The seven SpMMOp APIs follow the descriptor/plan lifecycle pattern, and the calling sequence must be: aclsparseSpMMOp_bufferSize → aclsparseSpMMOp_createDescr → aclsparseSpMMOp_createPlan → [optional aclsparseSpMMOp_setGlobalUserData] → aclsparseSpMMOp (can be executed repeatedly) → aclsparseSpMMOp_destroyPlan → aclsparseSpMMOp_destroyDescr.
Parameter Description:
handle(IN): HOST, the aclsparse handle.opA(IN): HOST, the operation type of sparse matrix A. OnlyACL_SPARSE_OP_NON_TRANSPOSEis supported.opB(IN): HOST, the operation type of dense matrix B, which supportsACL_SPARSE_OP_NON_TRANSPOSE/ACL_SPARSE_OP_TRANSPOSE.matA(IN): HOST, the descriptor of CSR sparse matrix A.matB(IN): HOST, the descriptor of the input dense matrix B (cannot be NULL).matC(IN): HOST, the descriptor of dense matrix C (cannot be NULL; the signature is the non-constaclsparseDnMatDescr_t, which is consistent with the in-place semantics of the execution phase).computeType(IN): HOST, the computation type. OnlyACL_FLOATis supported.alg(IN): HOST, the SpMMOp algorithm type.bufferSize(OUT): HOST, returns the required number of workspace bytes.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp_createDescr
aclsparseStatus_t aclsparseSpMMOp_createDescr(
aclsparseHandle_t handle,
aclsparseSpMMOpDescr_t *descr,
aclsparseOperation_t opA,
aclsparseOperation_t opB,
aclsparseConstSpMatDescr_t matA,
aclsparseConstDnMatDescr_t matB,
aclsparseDnMatDescr_t matC,
aclDataType computeType,
aclsparseSpMMOpAlg_t alg,
void *buffer);
Function: Creates an internal SpMMOp descriptor, performs preprocessing, and binds matA / opB / alg. The CSR pointers of matA are stored in descr as weak references (the CSR pattern is fixed for the plan lifecycle); opB is bound in this phase and remains fixed during the plan lifecycle. In this phase, ALG2 synchronously performs host-side preprocessing (D2H reads rowOffsets → sorts with std::stable_sort → computes the bin_edge load-balancing partitioning → writes to the workspace with H2D); DEFAULT is normalized to ALG1.
Parameter Description:
handle(IN): HOST, the aclsparse handle.descr(OUT): HOST, the output SpMMOp descriptor.opA(IN): HOST, the operation type of sparse matrix A. OnlyACL_SPARSE_OP_NON_TRANSPOSEis supported.opB(IN): HOST, the operation type of dense matrix B, which supportsACL_SPARSE_OP_NON_TRANSPOSE/ACL_SPARSE_OP_TRANSPOSE.matA(IN): HOST, the descriptor of CSR sparse matrix A.matB(IN): HOST, the descriptor of the input dense matrix B (can be NULL).matC(IN): HOST, the descriptor of dense matrix C (can be NULL).computeType(IN): HOST, the computation type. OnlyACL_FLOATis supported.alg(IN): HOST, the SpMMOp algorithm type.buffer(IN): DEVICE, the workspace buffer, for which the caller first queries the size throughaclsparseSpMMOp_bufferSizeand then allocates (required for ALG2).
Constraints:
- For ALG2,
buffercannot be NULL and its size cannot be smaller than the value returned byaclsparseSpMMOp_bufferSize;buffermust remain valid until descr is destroyed. - ALG1 allows updating the data pointed to by csrValues in place without re-creating descr/plan. For ALG2, modifying csrValues in place is unsupported undefined behavior (the caller's responsibility, with no runtime detection). Modifying the CSR structure (rowOffsets / colInd) invalidates reorder / bin_edge.
- The CSR content contract (the value range of colInd ∈ [indexBase, indexBase+k), rowOffsets being monotonically non-decreasing, and rowOffsets[0] and rowOffsets[m] being consistent with nnz) is guaranteed by the caller, and the library does not perform runtime validation.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp_destroyDescr
aclsparseStatus_t aclsparseSpMMOp_destroyDescr(aclsparseSpMMOpDescr_t descr);
Function: Destroys an SpMMOp descriptor and releases the host resources it manages. Idempotent semantics: if descr is nullptr, the API directly returns SUCCESS. You must call aclsparseSpMMOp_destroyPlan first to destroy the execution plan and then call this API to destroy the descriptor.
Parameter Description:
descr(IN): HOST, the SpMMOp descriptor to destroy.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp_createPlan
aclsparseStatus_t aclsparseSpMMOp_createPlan(
aclsparseHandle_t handle,
aclsparseSpMMOpDescr_t descr,
aclsparseSpMMOpPlan_t *plan,
const void *epilogueLTOBuffer,
size_t epilogueLTOBufferSize);
Function: Creates an execution plan based on descr. The epilogue on the NPU side is fixed to identity (no elementwise operations are attached). epilogueLTOBuffer must be NULL and epilogueLTOBufferSize must be 0; otherwise, the API returns ACL_SPARSE_STATUS_NOT_SUPPORTED.
Parameter Description:
handle(IN): HOST, the aclsparse handle.descr(IN): HOST, the descriptor fromaclsparseSpMMOp_createDescr(non-const, aligned with cuSPARSE semantics; createPlan can modify descr).plan(OUT): HOST, the output execution plan.epilogueLTOBuffer(IN): HOST, the epilogue LTO-IR buffer, which must be NULL on the NPU side.epilogueLTOBufferSize(IN): HOST, the epilogue LTO-IR size (in bytes), which must be 0 on the NPU side.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp_destroyPlan
aclsparseStatus_t aclsparseSpMMOp_destroyPlan(aclsparseSpMMOpPlan_t plan);
Function: Destroys an SpMMOp execution plan. Idempotent semantics: if plan is nullptr, the API directly returns SUCCESS. The API must be called before aclsparseSpMMOp_destroyDescr; otherwise, the descr weakly referenced inside the plan becomes a dangling pointer.
Parameter Description:
plan(IN): HOST, the execution plan to destroy.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp_setGlobalUserData
aclsparseStatus_t aclsparseSpMMOp_setGlobalUserData(
aclsparseHandle_t handle,
aclsparseSpMMOpPlan_t plan,
const char *epilogueDataName,
void *epilogueData,
size_t epilogueDataSize);
Function: Sets the __constant__ variable in the epilogue module to the specified data (aligned with cuSPARSE). The NPU side uses the identity epilogue and does not require auxiliary data, so this API is a no-op: the API validates only parameter consistency (epilogueData and epilogueDataSize must be either both valid or both invalid) and then directly returns SUCCESS.
Parameter Description:
handle(IN): HOST, the aclsparse handle.plan(IN): HOST, the execution plan.epilogueDataName(IN): HOST, the variable name of the epilogue data.epilogueData(IN): HOST, the pointer to the epilogue data.epilogueDataSize(IN): HOST, the number of data bytes.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSpMMOp
aclsparseStatus_t aclsparseSpMMOp(
aclsparseHandle_t handle,
aclsparseSpMMOpPlan_t plan,
const void *alpha,
const void *beta,
aclsparseConstDnMatDescr_t matB,
aclsparseDnMatDescr_t matC);
Function: Performs the sparse matrix-dense matrix multiplication: C = alpha * op(A) * op(B) + beta * C, where A is a CSR (m×k) sparse matrix, B is a dense matrix, and C is a dense matrix (in-place: reads in beta * C and writes out the result). Asynchronous execution: The function returns immediately after the kernel is enqueued to the stream associated with the handle, and the caller is responsible for synchronization through the stream. matB / matC are passed in at the execute stage and can be replaced across multiple execute calls (n / ldb / ldc / order can vary), but m / k / opB must be consistent with the values bound to descr.
Parameters:
handle(IN): HOST, aclsparse handle.plan(IN): HOST, execution plan.alpha(IN): HOST/DEVICE, scalar alpha (FP32; the pointer mode is determined byaclsparseSetPointerMode).beta(IN): HOST/DEVICE, scalar beta (FP32; the pointer mode is determined byaclsparseSetPointerMode).matB(IN): HOST, descriptor of the input dense matrix B.matC(IN/OUT): HOST, descriptor of the input/output dense matrix C (in-place).
Constraints:
opAonly supportsACL_SPARSE_OP_NON_TRANSPOSE;opBsupportsACL_SPARSE_OP_NON_TRANSPOSE/ACL_SPARSE_OP_TRANSPOSE.- dtype supports FP32 / FP16, and the valueType of matA / matB / matC must be consistent; accumulation is fixed to FP32 (for FP16 output, values are saturated and truncated to ±65504 to avoid Inf/NaN); computeType is fixed to
ACL_FLOAT. - matB / matC independently support the
ACL_SPARSE_ORDER_ROW/ACL_SPARSE_ORDER_COLmajor order. - Both ALG1 / ALG2 guarantee bit-wise reproducible results.
- Dimension and stride limits: if m / k / n or matB.ld / matC.ld exceeds INT32_MAX,
ACL_SPARSE_STATUS_NOT_SUPPORTEDis returned; the stride limit is constrained by dtype — FP32 uses UINT32_MAX / 4 and FP16 uses UINT32_MAX / 2 (ld is counted in elements), and if the limit is exceeded,ACL_SPARSE_STATUS_NOT_SUPPORTEDis returned.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseSgtsv2
aclsparseStatus_t aclsparseSgtsv2(
aclsparseHandle_t handle,
int m, int n,
const float *dl, const float *d, const float *du,
float *B, int ldb, void *pBuffer);
Function: Solves the tridiagonal linear system A · X = B (FP32, with support for multiple right-hand sides (Multiple RHS)), where A is an m × m tridiagonal matrix represented by the subdiagonal dl, the main diagonal d, and the superdiagonal du; B is the m × n dense right-hand-side matrix (column-major), and the solution X overwrites B in place.
The operator uses the Thomas algorithm with partial pivoting. In forward elimination, |d'[i-1]| and |dl[i]| are compared row by row to select the pivot; when necessary, rows are swapped and two types of fill-in, du' and du2', are produced; backward substitution solves with the modified coefficients that include the fill-in. On arch22, each RHS reuses the common matrix factors; on the extended exponent path, the factorization mode is determined by a backward error check on the initial solution, and when necessary, row equilibration or the original scale is used and the system is refactored. For finite systems that are strongly diagonally dominant and whose normalized RHS range is limited, the fast path with 40 fixed-vector Jacobi iterations is used, direct solving is retained for other inputs, and two compensated residual corrections are added for finite systems that are not strongly diagonally dominant. The precision standard and the public FP32 ABI remain unchanged; for detailed numerical gates and the UB layout, see the operator README. Its workspace is align_up(align_up(17*m,128)+85*m,128) bytes and is independent of n; when n=0, it is 0. The 85-byte-per-row scratch contains five extended numeric arrays (80 bytes/row), the original RHS (4 bytes/row), and an independent pivot (1 byte/row). For example, m=3,n=1 returns 384 B; on the two sides of the 128-byte alignment boundary of the factor region, m=7 and m=8 return 768 B and 1024 B respectively. The caller must allocate the workspace with the current bufferSizeExt query value and must not hard-code the capacity based on historical formulas. On arch35, the existing implementation with 3 sets of FP32 workspace per RHS is retained.
Product Support:
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported (arch22 / DAV_2201)
- Atlas A2 products: Supported (arch22 / DAV_2201)
Parameters:
handle(IN): HOST, context handle of the ops-sparse library, which carries the stream.m(IN): HOST, size of the linear system (number of rows = number of columns), must be ≥ 3 (validated when n > 0; the validation is skipped when n=0).n(IN): HOST, number of right-hand-side columns, must be ≥ 0; when n=0, the function returns SUCCESS early and performs no computation.dl(IN): DEVICE, subdiagonal array [m];dl[0]must be set to 0 before the call.d(IN): DEVICE, main diagonal array [m].du(IN): DEVICE, superdiagonal array [m];du[m-1]must be set to 0 before the call.B(IN/OUT): DEVICE, right-hand side b (input) / solution X (output), with a size of ldb × n (column-major). After the computation completes, it is overwritten in place with the solution matrix X.ldb(IN): HOST, leading dimension of B, must be ≥ max(1, m).pBuffer(IN): DEVICE, workspace buffer whose address must be 128-byte aligned. When n > 0, it must be a valid pointer with a size no less than the number of bytes returned byaclsparseSgtsv2_bufferSizeExt.
Constraints:
- m ≥ 3 (validated when n > 0; the validation is skipped when n=0)
- n ≥ 0 (when n = 0, the function returns SUCCESS early and performs no computation)
- ldb ≥ max(1, m)
- When n > 0, dl, d, du, and B cannot be nullptr
- When n > 0, pBuffer cannot be nullptr, and its address must be a multiple of 128 bytes
- The size of pBuffer must be ≥ the value returned by
aclsparseSgtsv2_bufferSizeExt dl[0]must be set to 0 before the calldu[m-1]must be set to 0 before the call- The Thomas algorithm with partial pivoting is numerically stable for general non-singular tridiagonal systems. The operator does not provide any protection for singular matrices: if any pivot is zero or close to zero during forward elimination or backward substitution, IEEE-754 division by zero will produce Inf/NaN in the output. The caller must ensure that the input tridiagonal matrix is well-conditioned; otherwise, the precision of that RHS column is unpredictable
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_HANDLE_IS_NULLPTR: handle is nullACL_SPARSE_STATUS_INVALID_VALUE: invalid parameter (m/n/ldb out of range, null pointer, pBuffer not aligned, and so on)- Other values: Failure
aclsparseSgtsv2_bufferSizeExt
aclsparseStatus_t aclsparseSgtsv2_bufferSizeExt(
aclsparseHandle_t handle,
int m, int n,
const float *dl, const float *d, const float *du,
const float *B, int ldb,
size_t *pBufferSizeInBytes);
Function: Queries the workspace size (in bytes) required by aclsparseSgtsv2. The returned value already includes 128-byte alignment.
Product Support:
- Ascend 950PR&950DT products: Supported
- Atlas A3 products: Supported (arch22 / DAV_2201)
- Atlas A2 products: Supported (arch22 / DAV_2201)
Parameters:
handle(IN): HOST, context handle of the ops-sparse library.m(IN): HOST, size of the linear system (number of rows = number of columns), must be ≥ 3 (validated when n > 0; the validation is skipped when n=0).n(IN): HOST, number of right-hand-side columns, must be ≥ 0; when n=0, the function returns 0.dl(IN): DEVICE, subdiagonal array [m];dl[0]must be 0.d(IN): DEVICE, main diagonal array [m].du(IN): DEVICE, superdiagonal array [m];du[m-1]must be 0.B(IN): DEVICE, right-hand-side matrix [ldb × n] (column-major); the query API does not use its values, and it can be nullptr.ldb(IN): HOST, leading dimension of B, must be ≥ max(1, m).pBufferSizeInBytes(OUT): HOST, outputs the workspace size (in bytes) required byaclsparseSgtsv2; it cannot be nullptr.
Constraints:
- m ≥ 3 (validated when n > 0; the validation is skipped when n=0)
- n ≥ 0 (when n = 0, the function returns 0 and no workspace is required)
- ldb ≥ max(1, m)
- dl, d, du, and pBufferSizeInBytes cannot be nullptr
- B can be nullptr (the query API does not use the values of B)
- The returned workspace size already includes 128-byte alignment
Return Values:
ACL_SPARSE_STATUS_SUCCESS: SuccessACL_SPARSE_STATUS_HANDLE_IS_NULLPTR: handle is nullACL_SPARSE_STATUS_INVALID_VALUE: invalid parameter (m/n/ldb out of range, null pointer, and so on)- Other values: Failure
aclsparseCgtsv2
aclsparseStatus_t aclsparseCgtsv2(
aclsparseHandle_t handle, int m, int n,
const aclsparseComplex_t* dl, const aclsparseComplex_t* d,
const aclsparseComplex_t* du, aclsparseComplex_t* B,
int ldb, void* pBuffer);
Function: Solves the complex tridiagonal linear system A · X = B with support for multiple right-hand sides. A is represented by the read-only subdiagonal dl, main diagonal d, and superdiagonal du, with adjacent partial pivoting. The solution X is written back to B in place, and the padding after row m in each column remains unchanged.
The complex type is aclsparseComplex_t (an alias of aclsparseComplex), which consists of two consecutive FP32 fields x and y and has a size of 8 bytes. B is stored in column-major order, and element (i, j) is located at B[i + j * ldb].
Product Support:
- Ascend 950PR&950DT products: Supported (arch35 / DAV_3510)
- Atlas A2 products: Supported (arch22 / DAV_2201)
- Atlas A3 products: Supported (arch22 / DAV_2201)
Parameters:
handle(IN): HOST, valid ops-sparse handle; the computation is submitted to the stream bound to the handle.m(IN): HOST, number of rows and columns of the tridiagonal matrix, must be ≥ 3; the validation still applies when n=0.n(IN): HOST, number of right-hand-side columns, must be ≥ 0.dl(IN): DEVICE, complex64 subdiagonal array [m]; the caller must setdl[0] = 0.d(IN): DEVICE, complex64 main diagonal array [m].du(IN): DEVICE, complex64 superdiagonal array [m]; the caller must setdu[m-1] = 0.B(IN/OUT): DEVICE, column-major right-hand-side and solution matrix [ldb × n]; the first m elements of each column are overwritten by the solution.ldb(IN): HOST, leading dimension of B, counted in complex elements, must be ≥ m; the validation still applies when n=0.pBuffer(IN): DEVICE, caller workspace with 128-byte alignment, with a capacity no less than the query result ofaclsparseCgtsv2_bufferSizeExt.
Constraints:
- When n > 0,
dl,d,du,B, andpBuffercannot be nullptr. - A valid n=0 call does not launch a kernel, and the data pointers and the workspace pointer can be nullptr; the handle and the integer dimensions must still be valid.
- The caller is responsible for providing sufficient device storage and for keeping the input, output, and workspace valid until the stream finishes execution; concurrent calls use separate writable workspaces.
- This API executes asynchronously. Returning SUCCESS indicates that Host parameter validation and submission succeed; the caller still needs to check for asynchronous errors when synchronizing the stream. The output for singular or non-finite inputs cannot be used as the basis for passing the precision verification of ordinary finite values.
- The workspace size is subject to the value returned by the current query API, and the capacity should not be hard-coded. For detailed API conventions, see Cgtsv2 Operator Description.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Host parameter validation and submission succeed; a valid n=0 call returns directly.ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR: handle is null.ACL_SPARSE_STATUS_INVALID_VALUE: invalid dimension, required pointer, address span, or workspace alignment.ACL_SPARSE_STATUS_EXECUTION_FAILED: the arch35 Probe, generic solve, or PCR stage fails to be dispatched.ACL_SPARSE_STATUS_INTERNAL_ERROR: platform resources are unavailable.- Other values: calling the handle or a runtime API fails.
aclsparseCgtsv2_bufferSizeExt
aclsparseStatus_t aclsparseCgtsv2_bufferSizeExt(
aclsparseHandle_t handle, int m, int n,
const aclsparseComplex_t* dl, const aclsparseComplex_t* d,
const aclsparseComplex_t* du, const aclsparseComplex_t* B,
int ldb, size_t* pBufferSizeInBytes);
Function: Queries the number of workspace bytes required by aclsparseCgtsv2 for the caller. The query does not read device data, does not modify B, and does not launch a computation kernel. On arch22, the workspace for non-empty RHS is determined by m and is independent of the number of RHS columns n; on arch35, a bounded slot layout of 128 + align_up(96*m*min(n,128),128) bytes is used. A valid n=0 call returns 0, and the capacity is always subject to the current query value.
Product Support:
- Ascend 950PR&950DT products: Supported (arch35 / DAV_3510)
- Atlas A2 products: Supported (arch22 / DAV_2201)
- Atlas A3 products: Supported (arch22 / DAV_2201)
Parameters:
handle(IN): HOST, valid ops-sparse handle.m(IN): HOST, number of rows and columns of the tridiagonal matrix, must be ≥ 3; the validation still applies when n=0.n(IN): HOST, number of right-hand-side columns, must be ≥ 0.dl,d,du(IN): DEVICE, read-only complex64 coefficient arrays of length m, with a layout consistent with the solve API.B(IN): DEVICE, column-major right-hand-side matrix [ldb × n]; it must be a non-null pointer when n > 0.ldb(IN): HOST, leading dimension of B, must be ≥ m; the validation still applies when n=0.pBufferSizeInBytes(OUT): HOST, output pointer for the number of workspace bytes; it cannot be nullptr.
Constraints:
- When n > 0,
dl,d,du, andBcannot be nullptr; integer arithmetic or address span overflow returns INVALID_VALUE. - When n=0, the data pointers can be nullptr, but the handle, dimensions, and output pointer must still be valid.
- The returned non-zero workspace size includes 128-byte alignment; the caller should allocate by the query value and pass a 128-byte-aligned device address to the solve API.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: The query succeeds.ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR: handle is null.ACL_SPARSE_STATUS_INVALID_VALUE: invalid dimension, required pointer, or address span.- Other values: calling a handle API fails.
aclsparseXcscsort_bufferSizeExt
aclsparseStatus_t aclsparseXcscsort_bufferSizeExt(
aclsparseHandle_t handle,
int m,
int n,
int nnz,
const int *cscColPtr,
const int *cscRowInd,
size_t *pBufferSizeInBytes
);
Function: Queries the size of the workspace buffer required for the stable column-wise sort in the CSC format (aclsparseXcscsort). It only performs parameter validation and byte count calculation, does not launch a kernel, and does not introduce Device synchronization.
Parameters:
handle(IN): HOST, aclsparse handle.m(IN): HOST, number of rows of the matrix.n(IN): HOST, number of columns of the matrix.nnz(IN): HOST, number of non-zero elements.cscColPtr(IN): DEVICE, CSC column offsets array, with a length ofn + 1.cscRowInd(IN): DEVICE, CSC row indices array, with a length ofnnz; it can benullptrwhennnz == 0.pBufferSizeInBytes(OUT): HOST, returns the required number of workspace bytes. It is set to 0 whennnz == 0; otherwise, it is2 * nnz * sizeof(int32_t).
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
aclsparseXcscsort
aclsparseStatus_t aclsparseXcscsort(
aclsparseHandle_t handle,
int m,
int n,
int nnz,
const aclsparseMatDescr_t descrA,
const int *cscColPtr,
int *cscRowInd,
int *P,
void *pBuffer
);
Function: Performs an in-place stable ascending sort (single-key sort) on the row indices of each column of a sparse matrix in the CSC format, and reorders P with the same permutation. cscColPtr is not modified; P serves as both the input (the caller must preset it to 0, 1, ..., nnz - 1) and the output (records the final permutation, satisfying sortedVal[i] = origVal(P[i])). pBuffer must be 128-byte aligned. This API executes asynchronously; you must synchronize the stream bound to the handle before reading the results.
Parameters:
handle(IN): HOST, aclsparse handle.m(IN): HOST, number of rows of the matrix.n(IN): HOST, number of columns of the matrix.nnz(IN): HOST, number of non-zero elements.descrA(IN): HOST, Legacy matrix descriptor, which providesindexBase; other attributes do not participate in the sort, and the matrix type is implicitly regarded asGENERAL.cscColPtr(IN): DEVICE, CSC column offsets array, with a length ofn + 1, which is not modified during the sort.cscRowInd(IN/OUT): DEVICE, row indices array, with a length ofnnz; in the output, the indices within each column are in stable ascending order.P(IN/OUT): DEVICE, permutation array, with a length ofnnz; the caller must first initialize it to0, 1, ..., nnz - 1, and after the sort,sortedVal[i] = origVal(P[i]).pBuffer(IN): DEVICE, workspace whose size is queried byaclsparseXcscsort_bufferSizeExtand which is allocated by the caller; the address must be 128-byte aligned.
Return Values:
ACL_SPARSE_STATUS_SUCCESS: Success- Other values: Failure
Enumerations
aclsparseOperation_t
Sparse operation type enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_OP_NON_TRANSPOSE |
Non-transpose operation |
ACL_SPARSE_OP_TRANSPOSE |
Transpose operation |
ACL_SPARSE_OP_CONJUGATE_TRANSPOSE |
Conjugate transpose operation |
aclsparseMatrixType_t
Matrix type enumeration (Legacy MatDescr attribute; operators currently support only GENERAL):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_MATRIX_TYPE_GENERAL |
General matrix (= 0) |
ACL_SPARSE_MATRIX_TYPE_SYMMETRIC |
Symmetric matrix |
ACL_SPARSE_MATRIX_TYPE_HERMITIAN |
Hermitian matrix |
ACL_SPARSE_MATRIX_TYPE_TRIANGULAR |
Triangular matrix |
aclsparseDiagType_t
Triangular diagonal type enumeration (SpMat attribute):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_DIAG_TYPE_NON_UNIT |
Non-unit diagonal (= 0) |
ACL_SPARSE_DIAG_TYPE_UNIT |
Unit diagonal |
aclsparseFillMode_t
Triangular fill mode enumeration (SpMat attribute):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_FILL_MODE_LOWER |
Lower triangular fill (= 0) |
ACL_SPARSE_FILL_MODE_UPPER |
Upper triangular fill |
aclsparseDirection_t
Storage direction enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_DIRECTION_ROW |
Row direction (= 0) |
ACL_SPARSE_DIRECTION_COLUMN |
Column direction |
aclsparseAction_t
Conversion operation enumeration (format conversion interfaces such as CSR→GEBSC):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_ACTION_SYMBOLIC |
Compute only the output structure (colPtr/rowInd) (= 0) |
ACL_SPARSE_ACTION_NUMERIC |
Compute the structure and copy the values |
aclsparsePointerMode_t
Scalar pointer mode enumeration (Host/Device location of alpha/beta):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_POINTER_MODE_HOST |
Scalar in Host memory (= 0, by default) |
ACL_SPARSE_POINTER_MODE_DEVICE |
Scalar in Device memory |
aclsparseSpMVOpAlg_t
SpMVOp algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPMVOP_ALG_DEFAULT |
Routes to ALG1 (= 0, no workspace) |
ACL_SPARSE_SPMVOP_ALG1 |
Host-side static row partitioning, no workspace, supports in-place updates |
ACL_SPARSE_SPMVOP_ALG2 |
Host-side merge sort + bin_edge load balancing, requires a workspace |
aclsparseSpGEMMAlg_t
SpGEMM algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPGEMM_ALG_DEFAULT |
Deterministic full-candidate path (= 0) |
ACL_SPARSE_SPGEMM_ALG1 |
Same path as DEFAULT (compatibility placeholder) |
ACL_SPARSE_SPGEMM_ALG2 |
Multi-phase memory planning path |
ACL_SPARSE_SPGEMM_ALG3 |
Multi-phase memory planning path |
aclsparseSpSVAlg_t
SpSV algorithm enumeration (currently only the default value):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPSV_ALG_DEFAULT |
Default algorithm (= 0) |
aclsparseSpSMAlg_t
SpSM algorithm enumeration (currently only the default value):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPSM_ALG_DEFAULT |
Default algorithm (= 0) |
aclsparseSpSVUpdate_t
SpSV value update mode enumeration (updateMatrix interface):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPSV_UPDATE_GENERAL |
General update (= 0) |
ACL_SPARSE_SPSV_UPDATE_DIAGONAL |
Diagonal update |
aclsparseSpSMUpdate_t
SpSM value update mode enumeration (updateMatrix interface):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPSM_UPDATE_GENERAL |
General update (= 0) |
ACL_SPARSE_SPSM_UPDATE_DIAGONAL |
Diagonal update (= 1) |
aclsparseSDDMMAlg_t
SDDMM algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SDDMM_ALG_DEFAULT |
Default algorithm (= 0) |
aclsparseDenseToSparseAlg_t
DenseToSparse algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_DENSETOSPARSE_ALG_DEFAULT |
Default algorithm (= 0) |
aclsparseSparseToDenseAlg_t
SparseToDense algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPARSETODENSE_ALG_DEFAULT |
Default algorithm (= 0) |
aclsparseCsr2CscAlg_t
CSR→CSC (Csr2cscEx2) algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_CSR2CSC_ALG_DEFAULT |
Default algorithm (= 0) |
ACL_SPARSE_CSR2CSC_ALG1 |
ALG1 |
aclsparseSpMatAttribute_t
SpMat attribute enumeration (Get/SetAttribute interfaces):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPMAT_FILL_MODE |
Triangular fill mode (aclsparseFillMode_t) |
ACL_SPARSE_SPMAT_DIAG_TYPE |
Triangular diagonal type (aclsparseDiagType_t) |
aclsparseStatus_t
Return status enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_STATUS_SUCCESS |
The operation completes successfully |
ACL_SPARSE_STATUS_NOT_INITIALIZED |
The aclSPARSE library is not initialized |
ACL_SPARSE_STATUS_ALLOC_FAILED |
Resource allocation failed |
ACL_SPARSE_STATUS_INVALID_VALUE |
The parameter value is invalid |
ACL_SPARSE_STATUS_ARCH_MISMATCH |
The device architecture does not match |
ACL_SPARSE_STATUS_EXECUTION_FAILED |
NPU program execution failed |
ACL_SPARSE_STATUS_INTERNAL_ERROR |
An internal aclSPARSE operation failed |
ACL_SPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED |
The matrix type is not supported |
ACL_SPARSE_STATUS_NOT_SUPPORTED |
The operation or data type combination is currently not supported |
ACL_SPARSE_STATUS_INSUFFICIENT_RESOURCES |
The resources are insufficient |
ACL_SPARSE_STATUS_HANDLE_IS_NULLPTR |
The handle is null |
aclsparseSpMVAlg_t
SpMV algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPMV_ALG_DEFAULT |
Default algorithm |
ACL_SPARSE_SPMV_COO_ALG1 |
Default algorithm for the COO format |
ACL_SPARSE_SPMV_COO_ALG2 |
Deterministic algorithm for the COO format |
ACL_SPARSE_SPMV_CSR_ALG1 |
Default algorithm for the CSR/CSC format |
ACL_SPARSE_SPMV_CSR_ALG2 |
Deterministic algorithm for the CSR/CSC format |
ACL_SPARSE_SPMV_SELL_ALG1 |
Default algorithm for the SELL format |
ACL_SPARSE_SPMV_CSR_ALG_CUBE |
Cube (matrix unit) segment sum algorithm for the CSR format; supports only non-transpose computation; matA/vecX are fp32 or fp16, and vecY is fp32 |
aclsparseSpMMAlg_t
SpMM algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPMM_ALG_DEFAULT |
Default CSR algorithm; arch22 automatically selects the fast path or the general path according to the layout |
ACL_SPARSE_SPMM_CSR_ALG1 |
Layout-aware general CSR algorithm; preferred for column-major dense matrices |
ACL_SPARSE_SPMM_CSR_FP32_HIGH_PRECISION_ALG |
fp32 high-precision algorithm; fp32 accumulation uses Kahan compensated summation; takes effect only for fp32 |
ACL_SPARSE_SPMM_CSR_ALG2 |
CSR row-major algorithm; arch22 selects the fast path for compact row-major N/N, and falls back to the general path for other valid layouts |
ACL_SPARSE_SPMM_CSR_ALG3 |
Deterministic algorithm that preserves the original CSR row order; opA supports only non-transpose, and opB does not support conjugate transpose |
aclsparseSpMMOpAlg_t
SpMMOp algorithm enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_SPMMOP_ALG_DEFAULT |
Default algorithm, normalized to ALG1, no workspace |
ACL_SPARSE_SPMMOP_ALG1 |
Deterministic algorithm; host-side static uniform row partitioning, no workspace; supports in-place updates of the CSR value array without rebuilding descr/plan |
ACL_SPARSE_SPMMOP_ALG2 |
Deterministic algorithm; host-side merge sort (std::stable_sort) + bin_edge load-balanced partitioning by nnz per row; requires a workspace; does not support in-place updates of CSR values |
ACL_SPARSE_SPMMOP_ALG1_HIGH_PRECISION |
FP32 high-precision algorithm with Kahan compensated summation; takes effect only for the FP32 dtype (FP16 is silently ignored and falls back to ALG1 behavior); workspace semantics are the same as those of ALG1 (no workspace) |
aclsparseOrder_t
Dense matrix layout enumeration (used by B / C in SpMM):
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_ORDER_ROW |
Row-major order |
ACL_SPARSE_ORDER_COL |
Column-major order |
aclsparseIndexType_t
Index type enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_INDEX_32I |
32-bit signed integer [0, 2^31 - 1]; currently implemented by SpMV / SpMM |
ACL_SPARSE_INDEX_64I |
64-bit signed integer [0, 2^63 - 1]; aclsparseCreateCsr can create it, but computation paths such as SpMV/SpMM currently support only ACL_SPARSE_INDEX_32I |
aclsparseIndexBase_t
Index base value enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_INDEX_BASE_ZERO |
Indexes start from 0 (C language compatible) |
ACL_SPARSE_INDEX_BASE_ONE |
Indexes start from 1 (Fortran compatible) |
aclsparseFormat_t
Sparse matrix format enumeration:
| Enumeration Value | Description |
|---|---|
ACL_SPARSE_FORMAT_COO |
COO (Coordinate) format |
ACL_SPARSE_FORMAT_CSR |
CSR (Compressed Sparse Row) format |
ACL_SPARSE_FORMAT_CSC |
CSC (Compressed Sparse Column) format |
ACL_SPARSE_FORMAT_BLOCKED_ELL |
Blocked-ELL format |
ACL_SPARSE_FORMAT_SLICED_ELL |
Sliced-ELL format |
ACL_SPARSE_FORMAT_BSR |
BSR (Block Sparse Row) format |
Recommended call flow
Single-phase interfaces (SpMM as an example)
- Call
aclsparseCreateto create a handle, and bind the stream by callingaclsparseSetStream. - Use
aclsparseCreateCsrto create the CSR sparse matrix A, and useaclsparseCreateDnMatto create the dense matrices B and C. - Call
aclsparseSpMMGetBufferSizeto obtain the workspace size, and allocate device memory. - Call
aclsparseSpMMPreprocessto preprocess the sparse matrix (the same sparsity pattern can reuse the workspace). - Call
aclsparseSpMMto perform sparse matrix-dense matrix multiplication. - Destroy the matrix descriptors and the handle in sequence, and release the workspace and ACL resources.
Multi-phase descriptor interfaces (SpSV / SpSM as examples, explicit lifecycle)
The multi-phase solve interfaces (aclsparseSpSV_* / aclsparseSpSM_*) and the SpGEMM multi-phase interfaces
(WorkEstimation → EstimateMemory → Compute → Copy) use explicit descriptors to manage phase state,
and the call order has hard prerequisite constraints (calls that skip the order return ACL_SPARSE_STATUS_INVALID_VALUE):
aclsparseCreate+aclsparseSetStreamcreate and bind a handle;aclsparseSpSV_createDescr/aclsparseSpSMCreateDescrcreate the solve descriptors.- Create the CSR sparse matrix A (
aclsparseCreateCsr) and the dense vectors X / Y (aclsparseCreateDnVec). aclsparseSpSV_bufferSize/aclsparseSpSMBufferSizequery the workspace size and allocate it.aclsparseSpSV_analysis/aclsparseSpSMAnalysisperform preprocessing (this step binds the CSR pattern of A; multiple solves on the same pattern can reuse the analysis result).aclsparseSpSV_solve/aclsparseSpSMperform the solve (X/Y are read-only/write descriptors, asynchronous on the same stream).- When values change but the structure does not, update the values through
aclsparseSpSV_updateMatrix/aclsparseSpSMUpdateMatrixwithout repeating analysis; synchronize the stream before reading the result. - Destroy the solve descriptors, matrix descriptors, and handle in sequence.
The SpGEMM multi-phase flow (aclsparseSpGEMMWorkEstimation → aclsparseSpGEMMEstimateMemory →
aclsparseSpGEMMCompute → aclsparseSpGEMMCopy) works the same way: the descriptor holds state across phases,
and WorkEstimation must run again after the structure changes; the legacy three-phase entry point (aclsparseSpGEMM)
automatically performs one full preprocessing pass when the cache misses.
Minimal example (pseudocode)
aclsparseHandle_t handle = nullptr;
aclsparseCreate(&handle);
aclsparseSetStream(handle, stream);
// C = alpha * A * B + beta * C: A is rows × cols, B is cols × colsOut, C is rows × colsOut
aclsparseSpMatDescr_t matA;
aclsparseCreateCsr(&matA, rows, cols, nnz,
dA_csrOffsets, dA_columns, dA_values,
ACL_SPARSE_INDEX_32I, ACL_SPARSE_INDEX_32I,
ACL_SPARSE_INDEX_BASE_ZERO, ACL_FLOAT);
aclsparseDnMatDescr_t matB, matC;
aclsparseCreateDnMat(&matB, cols, colsOut, colsOut, dB, ACL_FLOAT, ACL_SPARSE_ORDER_ROW);
aclsparseCreateDnMat(&matC, rows, colsOut, colsOut, dC, ACL_FLOAT, ACL_SPARSE_ORDER_ROW);
size_t bufferSize = 0;
float alpha = 1.0f, beta = 0.0f;
aclsparseSpMMGetBufferSize(handle,
ACL_SPARSE_OP_NON_TRANSPOSE, ACL_SPARSE_OP_NON_TRANSPOSE,
&alpha, matA, matB, &beta, matC,
ACL_FLOAT, ACL_SPARSE_SPMM_ALG_DEFAULT, &bufferSize);
void *dBuffer = nullptr;
aclrtMalloc(&dBuffer, bufferSize, ACL_MEM_MALLOC_HUGE_FIRST);
aclsparseSpMMPreprocess(handle,
ACL_SPARSE_OP_NON_TRANSPOSE, ACL_SPARSE_OP_NON_TRANSPOSE,
&alpha, matA, matB, &beta, matC,
ACL_FLOAT, ACL_SPARSE_SPMM_ALG_DEFAULT, dBuffer);
aclsparseSpMM(handle,
ACL_SPARSE_OP_NON_TRANSPOSE, ACL_SPARSE_OP_NON_TRANSPOSE,
&alpha, matA, matB, &beta, matC,
ACL_FLOAT, ACL_SPARSE_SPMM_ALG_DEFAULT, dBuffer);
aclsparseDestroyDnMat(matB);
aclsparseDestroyDnMat(matC);
aclsparseDestroySpMat(matA);
aclsparseDestroy(handle);
aclrtFree(dBuffer);
Notes
- The interface capabilities and attribute support scope are subject to the current implementation version. For detailed restrictions, see the README documents in each operator directory (for example,
test/spmv/README.mdandtest/spmm/README.md) and the comments in the header files. - If the document description is inconsistent with the header file declarations, the header file declarations and the actual implementation behavior prevail.