Closed
[Documentation|文档反馈]: foreach 八接口对「x与out的shape不满足约束」给出 161002/561002 两种码,RoundOffNumber V1 与 V2 互相矛盾(Sqrt 实测方向相反) #8009
liuhanwen8Add on 19 days agoClosed at 8 days ago
19 days ago Added label: documentation
18 days ago Assign tramp-ll as responsible person
yuning_chen
18 days ago Comments:
18 days ago Comments:
初步分析
感谢反馈,我们已开始核对这个问题。
现象理解:foreach 八个接口对「x 与 out 的 shape 不满足约束」给出的错误码不统一,161002 与 561002 两种都有;RoundOffNumber V1 与 V2 之间互相矛盾,Sqrt 实测方向还与资料相反。
当前判断:初步判断是各接口校验落点不一致(部分在首段 host 校验、部分落到第二段),导致对外错误码不统一,待逐接口复现确认。
涉及范围:foreach 同族八接口的 op_api shape 校验与对应 aclnn 资料的错误码表。
下一步:我们会逐个接口核对校验落点与资料声明,拉通成统一口径后再决定是改实现还是改资料。


yuning_chen
18 days ago Comments:
18 days ago Comments:
您好,该问题已收到,当前问题 @tramp-ll 正在处理中


11 days ago Assign east_yang as responsible person, remove original responsible person: tramp-ll
11 days ago Assign east_yang as responsible person, remove original responsible person: tramp-ll
11 days ago Assign tramp-ll as responsible person
11 days ago Removed responsible person east_yang
tramp-ll
10 days ago Comments:
10 days ago Comments:
当前最新代码中,只有aclnnForeachSqrt存在说明错误,已经修改md


8 days ago Close issue
8 days ago changed custom state from 进行中 to 已完成
8 days ago Added label: resolved
现象
foreach族的同一条语义「x与out的 shape 不满足约束」,在八个接口的资料里被归到两种不同的错误码下,而同机同构造的实测又给出第三种组合。调用方按资料做错误码分流(161002=参数非法直接改参 / 561002=内部 tiling 失败可重试)会走错路。同一构造
x=fp32[2x3]ND|out=fp32[2x2]ND(out 比 x 小,同 dtype、同 rank)在 910B2 上逐接口实测:aclnnForeachReciprocalaclnnForeachSinaclnnForeachSignaclnnForeachSigmoidaclnnForeachSinhaclnnForeachSqrtaclnnForeachRoundOffNumber(V1)aclnnForeachRoundOffNumberV2三个层面的不一致
1. 同一条语义,两种码
资料侧:Reciprocal / Sin / Sign / RoundOffNumberV2 归 161002;Sigmoid / Sinh / Sqrt / RoundOffNumber(V1) 归 561002。
2. 同一个算子,两个入口互相矛盾
aclnnForeachRoundOffNumber(V1)与aclnnForeachRoundOffNumberV2是同一个 l0 kernel(l0op::ForeachRoundOffNumberV2)的两个 aclnn 入口,实测分别是 561002 与 161002,各自的资料也分别写成 561002 与 161002 —— 即文档跟着实现走,但两个实现本身不一致。3. 实现侧与资料都不对齐
八个接口的
CheckShape失败一律映射到ACLNN_ERR_PARAM_INVALID(161002):// 例:foreach/foreach_sqrt/op_host/op_api/aclnn_foreach_sqrt.cpp:127-129 for (uint64_t i = 0; i < self->Size(); i++) { OP_CHECK_SHAPE_NOT_EQUAL((*self)[i], (*out)[i], return false); } ... CHECK_RET(CheckShape(self, out), ACLNN_ERR_PARAM_INVALID); // 统一 PARAM_INVALID但实测有 6 个接口返 561002,说明 shape 违规在 host 层没被拦住,落到了 tiling 层上报 —— 与资料写 161002 的那几个接口(Reciprocal / Sin / Sign)直接冲突。
期望
统一该子项的错误码归属,并让资料与实现一致。建议口径(与
CheckShape的实际位置一致):若采纳该口径,需要同时修正:Reciprocal / Sin / Sign 的资料(改 161002→561002,或补 host 层拦截),以及 Sqrt 的实现(补 host 层 shape 校验,使其返 161002),并统一 V1/V2。
环境
opp/version.info→Version=9.2.0,文件时间 2026-10-20)cann/ops-nnmaster12ad726c(2026-11-03 fetch)-std=c++17复现步骤
probe.cpp。g++ -O1 -std=c++17 -o probe probe.cpp \ -I${ASCEND_HOME_PATH}/include -I${ASCEND_HOME_PATH}/include/aclnnop \ -L${ASCEND_HOME_PATH}/lib64 -lascendcl -lnnopbase -lopapi -lpthread复现脚本
实测输出(A2 / CANN 9.2.0 /
12ad726c,device 2,同构造x=fp32[2x3]ND|out=fp32[2x2]ND):(
RoundOffNumber族需额外构造roundMode,实测 V1=561002、V2=161002。)// probe.cpp —— foreach 族八接口:out shape 小于 x 时的返回码 // 用法: ./probe <device_id> <ShortName> // ShortName ∈ {Reciprocal, Sin, Sign, Sigmoid, Sinh, Sqrt} #include <acl/acl.h> #include <aclnnop/aclnn_foreach_reciprocal.h> #include <aclnnop/aclnn_foreach_sigmoid.h> #include <aclnnop/aclnn_foreach_sign.h> #include <aclnnop/aclnn_foreach_sin.h> #include <aclnnop/aclnn_foreach_sinh.h> #include <aclnnop/aclnn_foreach_sqrt.h> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #include <vector> typedef aclnnStatus (*GwsFn)(const aclTensorList *, aclTensorList *, uint64_t *, aclOpExecutor **); int main(int argc, char **argv) { if (argc < 3) { printf("usage: %s <device_id> <ShortName>\n", argv[0]); return 2; } int dev = atoi(argv[1]); std::string name = argv[2]; GwsFn fn = nullptr; int expect = 0; if (name == "Reciprocal") { fn = aclnnForeachReciprocalGetWorkspaceSize; expect = 161002; } else if (name == "Sin") { fn = aclnnForeachSinGetWorkspaceSize; expect = 161002; } else if (name == "Sign") { fn = aclnnForeachSignGetWorkspaceSize; expect = 161002; } else if (name == "Sigmoid") { fn = aclnnForeachSigmoidGetWorkspaceSize; expect = 561002; } else if (name == "Sinh") { fn = aclnnForeachSinhGetWorkspaceSize; expect = 561002; } else if (name == "Sqrt") { fn = aclnnForeachSqrtGetWorkspaceSize; expect = 561002; } else { printf("unknown op %s\n", name.c_str()); return 2; } aclInit(nullptr); aclrtSetDevice(dev); aclrtStream stream = nullptr; aclrtCreateStream(&stream); // x = [2,3],out = [2,2](同 dtype / 同 rank,只有 shape 不满足) int64_t inDims[2] = {2, 3}; int64_t outDims[2] = {2, 2}; void *inDev = nullptr, *outDev = nullptr; aclrtMalloc(&inDev, 6 * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&outDev, 4 * sizeof(float), ACL_MEM_MALLOC_HUGE_FIRST); std::vector<float> hostIn(6, 1.0f); aclrtMemcpy(inDev, 6 * sizeof(float), hostIn.data(), 6 * sizeof(float), ACL_MEMCPY_HOST_TO_DEVICE); aclTensor *xT = aclCreateTensor(inDims, 2, ACL_FLOAT, nullptr, 0, ACL_FORMAT_ND, inDims, 2, inDev); aclTensor *outT = aclCreateTensor(outDims, 2, ACL_FLOAT, nullptr, 0, ACL_FORMAT_ND, outDims, 2, outDev); aclTensorList *xList = aclCreateTensorList(&xT, 1); aclTensorList *outList = aclCreateTensorList(&outT, 1); uint64_t wsSize = 0; aclOpExecutor *executor = nullptr; int ret = fn(xList, outList, &wsSize, &executor); printf("[%s] expect=%d actual=%d %s\n", name.c_str(), expect, ret, (ret == expect) ? "consistent" : "MISMATCH"); if (ret == 0) { void *ws = nullptr; if (wsSize > 0) { aclrtMalloc(&ws, wsSize, ACL_MEM_MALLOC_HUGE_FIRST); } aclrtFree(ws); } aclDestroyTensorList(xList); aclDestroyTensorList(outList); aclrtFree(inDev); aclrtFree(outDev); aclrtDestroyStream(stream); aclrtResetDevice(dev); aclFinalize(); return (ret == expect) ? 0 : 1; }