Closed
[Documentation|文档反馈]: aclnnInplaceZero 头文件 aclnn_zero.h 的 selfRef 注释声明支持 QINT8/UINT32/UINT64 等 7 个 dtype,实测第一段返回 161002 #4253
liuhanwen8Add on 11 days agoClosed at 7 days ago
11 days ago Added label: documentation
陈思
11 days ago Comments:
11 days ago Comments:
11 days ago Assign chen_0715 as responsible person
11 days ago Added label: pending-confirmation
11 days ago Removed label: pending-confirmation
7 days ago Assign VoyageZhou as responsible person
7 days ago Removed responsible person chen_0715
7 days ago Close issue
fitZepHYr
7 days ago Comments:
7 days ago Comments:
当前UINT32和UINT64已在A2/A3支持,PR:aclnnInplaceZero支持UINT32/UINT64类型,未涉及的其他类型请后续再评审是否支持,此Issue关闭


fitZepHYr
7 days ago Comments:
7 days ago Comments:
/close


7 days ago Added label: resolved
现象
aclnnInplaceZero的公开头文件include/aclnnop/aclnn_zero.h在aclnnInplaceZeroGetWorkspaceSize的@param [in] selfRef注释里声明 selfRef 支持 18 种数据类型:其中 QINT8 / QINT16 / QINT32 / UINT32 / UINT64 / QUINT8 / QUINT16 在实现里一项都不存在:实现白名单
math/zero_op/op_api/aclnn_zero.cpp的DTYPE_SUPPORT_LIST只有 13 项;实测ACL_UINT32的 selfRef两段式调用返回 161002,而按头文件注释它应当被接受。同仓资料
docs/aclnnInplaceZero.md的 dtype 表是对的(13 项 + 950 专属),即头文件注释与资料表互不一致,而下游通常直接读头文件注释。
期望
头文件
@param [in] selfRef的 dtype 列表与实现DTYPE_SUPPORT_LIST一致;或若这些 dtype 本应支持,则实现补齐(当前 uint32 在第一段就被拒)。
环境
$ASCEND_HOME_PATH指向 ascend-toolkit 安装目录,source set_env.sh即可)cann/ops-mathmaster584b2ea6(2026-10-29 浅克隆)math/zero_op/op_api/aclnn_zero.h:44-48、math/zero_op/op_api/aclnn_zero.cpp:36-41;安装包内同名头文件与仓内文件逐字节相同(
diff无输出)复现步骤
repro.cpp与build.sh存到同一目录。bash build.sh编译。export ASCEND_RT_VISIBLE_DEVICES=<空闲卡号>后执行./repro。rc1=0 rc2=0;uint32 组rc1=161002(与头文件注释冲突);selfRef=nullptr组rc1=161001;int16(AICPU 分支)组rc1=0 rc2=0。复现脚本
g++ -std=c++17 -O2 -o repro repro.cpp -I$ASCEND_HOME_PATH/include \ -I$ASCEND_HOME_PATH/include/aclnnop -L$ASCEND_HOME_PATH/lib64 \ -lascendcl -lnnopbase -lopapi#include <cstdint> #include <cstdio> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_zero.h" static void Call(aclTensor* t, int* r1, int* r2, aclrtStream s) { uint64_t ws = 0; aclOpExecutor* e = nullptr; *r1 = (int)aclnnInplaceZeroGetWorkspaceSize(t, &ws, &e); *r2 = 0; if (*r1 != 0) { return; } void* w = nullptr; if (ws > 0 && aclrtMalloc(&w, ws, ACL_MEM_MALLOC_HUGE_FIRST) != ACL_SUCCESS) { *r2 = -1; return; } *r2 = (int)aclnnInplaceZero(w, ws, e, s); if (*r2 == 0) { aclrtSynchronizeStream(s); } if (w) { aclrtFree(w); } } static aclTensor* Make(aclDataType dt, void** dev) { std::vector<int64_t> sh{4, 4}, st{4, 1}; size_t esz = (dt == ACL_INT16) ? 2 : 4, bytes = 16 * esz; if (aclrtMalloc(dev, bytes, ACL_MEM_MALLOC_HUGE_FIRST) != ACL_SUCCESS) { return nullptr; } std::vector<uint8_t> raw(bytes, 0x3f); // 非零金丝雀:只有写 0 才过 aclrtMemcpy(*dev, bytes, raw.data(), bytes, ACL_MEMCPY_HOST_TO_DEVICE); return aclCreateTensor(sh.data(), 2, dt, st.data(), 0, ACL_FORMAT_ND, sh.data(), 2, *dev); } int main() { if (aclInit(nullptr) != ACL_SUCCESS || aclrtSetDevice(0) != ACL_SUCCESS) { return -1; } aclrtStream s = nullptr; aclrtCreateStream(&s); const aclDataType dts[3] = {ACL_FLOAT, ACL_UINT32, ACL_INT16}; const char* names[3] = {"fp32(对照)", "uint32(头文件声明支持)", "int16(AICPU 分支)"}; for (int i = 0; i < 3; ++i) { void* dev = nullptr; aclTensor* t = Make(dts[i], &dev); int r1 = -1, r2 = -1; Call(t, &r1, &r2, s); printf("[%s] rc1=%d rc2=%d\n", names[i], r1, r2); aclDestroyTensor(t); aclrtFree(dev); } int r1 = -1, r2 = -1; Call(nullptr, &r1, &r2, s); printf("[selfRef=nullptr] rc1=%d\n", r1); aclrtDestroyStream(s); aclrtResetDevice(0); aclFinalize(); return 0; }实测输出(910B2 / CANN 9.2.0 / 2026-10-29):
影响
下游与用户通常直接按
$ASCEND_HOME_PATH/include/aclnnop/*.h的注释判断 dtype 是否可用。按本头文件,UINT32/UINT64/QINT8/QINT16/QINT32/QUINT8/QUINT16 的 selfRef 是「支持」的,实际第一段即返回 161002:
①用户按注释构造被拒却找不到原因;②从注释抽支持表的工具会把 7 个不存在的 dtype 写进下游支持矩阵;
③头文件与同仓资料两处口径不一致,后续维护容易以头文件为准改错资料。
建议
aclnn_zero.h的@param [in] selfRef注释改成与aclnn_zero.cpp:36-41的DTYPE_SUPPORT_LIST一致(INT8、INT32、INT64、UINT8、FLOAT16、FLOAT32、BOOL、DOUBLE、INT16、UINT16、COMPLEX128、COMPLEX64、BF16),
950 专属窄浮点单列一句;
DTYPE_SUPPORT_LIST与 ZerosLike 派发里补齐;op_api/aclnn_*.h的@param注释抽 dtype 列表与DTYPE_SUPPORT_LIST比对,差集非空即失败 —— 「注释照抄兄弟接口」在 CANN 头文件里普遍存在(本次顺带发现
aclnn_copy.h:44的注释里也写着
aclnnInplaceZeroGetWorkspaceSize)。