CANN稀疏算子文档模板 {aclsparseXxx} 算子文档【免费下载链接】ops-sparse本项目是CANN提供的高性能稀疏矩阵计算的算子库专注于优化稀疏矩阵的计算效率。项目地址: https://gitcode.com/cann/ops-sparse算子概述{功能描述 数学表达式}接口列表接口名说明产品支持情况芯片系列支持情况Ascend910B✅Ascend910_93✅Ascend950✅Ascend310P✅接口详情{aclsparseXxx}函数原型aclsparseStatus_t {aclsparseXxx}(...);参数说明参数名输入/输出参数类型说明内存位置约束说明约束说明支持的稀疏格式格式支持说明CSR✅COOCSC调用示例Generic API 风格仅 Generic 算子保留删除 Legacy 示例// 1. 创建 handle aclsparseHandle_t handle; aclsparseCreate(handle); aclsparseSetStream(handle, stream); // 2. 创建稀疏矩阵描述符 aclsparseConstSpMatDescr_t matA; aclsparseCreateConstCsr(matA, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues, ACL_SPARSE_INDEX_32I, ACL_SPARSE_INDEX_32I, ACL_SPARSE_INDEX_BASE_ZERO, ACL_FLOAT); // 3. 创建稠密向量描述符 aclsparseConstDnVecDescr_t vecX; aclsparseCreateConstDnVec(vecX, n, x, ACL_FLOAT); aclsparseDnVecDescr_t vecY; aclsparseCreateDnVec(vecY, m, y, ACL_FLOAT); // 4. 获取缓冲区大小 size_t bufferSize; aclsparseXxxGetBufferSize(handle, ..., bufferSize); // 5. 分配缓冲区 void *buffer; aclrtMalloc(buffer, bufferSize, ACL_MEM_MALLOC_HUGE_FIRST); // 6. 预处理若需要 aclsparseXxxPreprocess(handle, ..., buffer); // 7. 执行计算 aclsparseXxx(handle, ..., buffer); // 8. 同步 aclrtSynchronizeStream(stream); // 9. 清理 aclsparseDestroySpMat(matA); aclsparseDestroyDnVec(vecX); aclsparseDestroyDnVec(vecY); aclrtFree(buffer); aclsparseDestroy(handle);Legacy API 风格仅 Legacy 算子保留删除 Generic 示例// 1. 创建 handle aclsparseHandle_t handle; aclsparseCreate(handle); aclsparseSetStream(handle, stream); // 2. 准备数据指针直接扁平传入无描述符 float *d_dl, *d_d, *d_du, *d_x; aclrtMalloc((void**)d_dl, (m-1) * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc((void**)d_d, m * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc((void**)d_du, (m-1) * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc((void**)d_x, m * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); aclrtMemcpy(d_dl, ..., h_dl, ..., ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(d_d, ..., h_d, ..., ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(d_du, ..., h_du, ..., ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(d_x, ..., h_b, ..., ACL_MEMCPY_HOST_TO_DEVICE); // 3. MatDescr若接口需要 aclsparseMatDescr_t matDescr; aclsparseCreateMatDescr(matDescr); aclsparseSetMatType(matDescr, ACL_SPARSE_MATRIX_TYPE_GENERAL); aclsparseSetMatIndexBase(matDescr, ACL_SPARSE_INDEX_BASE_ZERO); // 4. 获取 workspace 大小若接口提供 bufferSize 函数 size_t bufferSize 0; aclsparseS{xxx}_bufferSize(handle, ..., bufferSize); void *pBuffer nullptr; if (bufferSize 0) { aclrtMalloc(pBuffer, bufferSize, ACL_MEM_MALLOC_HUGE_FIRST); } // 5. 调用算子带精度前缀 aclsparseS{xxx}(handle, ..., pBuffer); // 6. 同步 aclrtSynchronizeStream(stream); // 7. 清理 if (pBuffer) aclrtFree(pBuffer); aclsparseDestroyMatDescr(matDescr); // 若有 aclrtFree(d_dl); aclrtFree(d_d); aclrtFree(d_du); aclrtFree(d_x); aclsparseDestroy(handle);【免费下载链接】ops-sparse本项目是CANN提供的高性能稀疏矩阵计算的算子库专注于优化稀疏矩阵的计算效率。项目地址: https://gitcode.com/cann/ops-sparse创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考