Closed
[Bug-Report|缺陷反馈]: aclnnMatmul 非法 out shape/负维度被误报为 561103 内部异常(应为 161002,同仓 aclnnMm 正确拒绝) #7997
liuhanwen8Add on 19 days agoClosed at 10 days ago
19 days ago Added label: bug-report
19 days ago Assign fanqirui as responsible person
yuning_chen
19 days ago Comments:
19 days ago Comments:
yuning_chen
19 days ago Comments:
19 days ago Comments:
您好,该问题已收到,当前问题 @fanqirui 正在处理中


19 days ago Assign linzehui2058 as responsible person
19 days ago Removed responsible person fanqirui
16 days ago Associated pull request
16 days ago Deleted associated pull request: fix_issue_11_5
16 days ago Associated pull request
16 days ago Deleted associated pull request: fix_issue_11_5
16 days ago Associated pull request
10 days ago Close issue
10 days ago changed custom state from 进行中 to 已完成
chenjiayi_
10 days ago Comments:
10 days ago Comments:
补充修复结果(2026-11-12):
本问题由 PR#13786 修复并合入(作者 linzehui2058,合入时间 2026-11-12)。
修复内容:
matmul/mat_mul_v3/op_host/op_api/aclnn_matmul.cpp:247-305新增CheckOutputShapeValid():out 任一维为负时返回 161002;输入元素数大于 0 时按广播语义推导元素数,与 out 声明元素数相等时通过,存在差异时返回 161002。:330在CheckInputParams()中调用该检查,越界 out 在第一段GetWorkspaceSize即被拒绝。- 同 MR 一并修复 batch_matmul 空 batch 的对称场景(
aclnn_batch_matmul.cpp、batch_matmul_util.cpp)。
验证:UT matmul/mat_mul_v3/tests/ut/op_host/test_aclnn_matmul.cpp 已随 MR 更新。
如果还有后续需要,请重新提 issue。


9 days ago Added label: resolved
9 days ago Assign chenjiayi_ as responsible person
22 hours ago Removed responsible person chenjiayi_
现象
aclnnMatmul在out元素数与推导结果不符、或任一输入维度为负数时,第一段接口aclnnMatmulGetWorkspaceSize返回 561103(ACLNN_ERR_INNER_NULLPTR,内部异常),而非161002(ACLNN_ERR_PARAM_INVALID,参数非法)。同一份错误输入喂给同目录的aclnnMm,后者正确返回 161002。aclnnMmaclnnMatmul(2,4)@(4,2),out=(2,2)(2,4)@(4,2),out=(2,3)(-2,4)@(4,2),out=(-2,2)self=INT8(不支持)期望
docs/aclnnMatmul.md第一段接口「返回值」只声明161001(空指针)与161002(dtype/format 不支持、无法推导、推导类型无法转 out),未声明任何 561xxx 内部异常码;docs/zh/context/aclnn_return_code.md第 28 行把 561103 定义为「内部异常:出现了 nullptr 的异常」。故非法
out应返回161002,不应返回代表 API 自身故障的561103。环境
npu-smi26.1.1cann/ops-nn118c0c719ba37c65e984c8da707863ccce6c4fad(git fetch 后 master 最新,2026-11-03 核对)复现步骤
repro.cppg++ -std=c++17 -O2 repro.cpp -o repro -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lopapi -lnnopbase./repro161002,实测561103复现脚本
#include <acl/acl.h> #include <aclnn/acl_meta.h> #include "aclnnop/aclnn_matmul.h" #include "aclnnop/aclnn_mm.h" #include <cstdio> #include <vector> static aclTensor* mk(const int64_t* d, uint64_t n, aclDataType dt, void* p, const int64_t* so = nullptr) { std::vector<int64_t> st(n, 1); for (int i = (int)n - 2; i >= 0; i--) st[i] = st[i + 1] * d[i + 1]; return aclCreateTensor(d, n, dt, so ? so : st.data(), 0, ACL_FORMAT_ND, d, n, p); } int main() { aclInit(nullptr); aclrtSetDevice(0); const int64_t aD[2] = {2, 4}, bD[2] = {4, 2}, okD[2] = {2, 2}, badD[2] = {2, 3}; void *dA, *dB, *dOk, *dBad; aclrtMalloc(&dA, 16, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&dB, 16, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&dOk, 8, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&dBad, 12, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMemset(dA, 16, 0, 16); aclrtMemset(dB, 16, 0, 16); aclTensor* tA = mk(aD, 2, ACL_FLOAT16, dA); aclTensor* tB = mk(bD, 2, ACL_FLOAT16, dB); aclTensor* tOk = mk(okD, 2, ACL_FLOAT16, dOk); aclTensor* tBad = mk(badD, 2, ACL_FLOAT16, dBad); uint64_t ws = 0; aclOpExecutor* ex = nullptr; int r1 = (int)aclnnMatmulGetWorkspaceSize(tA, tB, tOk, 0, &ws, &ex); printf("Case1 correct out (2,2) -> %d (expect 0)\n", r1); ws = 0; ex = nullptr; int r2 = (int)aclnnMatmulGetWorkspaceSize(tA, tB, tBad, 0, &ws, &ex); printf("Case2 wrong out (2,3) -> %d (expect 161002)\n", r2); ws = 0; ex = nullptr; int r3 = (int)aclnnMmGetWorkspaceSize(tA, tB, tBad, 0, &ws, &ex); printf("Case3 aclnnMm same wrong out -> %d (expect 161002)\n", r3); const int64_t nA[2] = {-2, 4}, nO[2] = {-2, 2}, sA[2] = {-4, 1}, sO[2] = {-2, 1}; void *dNA, *dNO; aclrtMalloc(&dNA, 16, ACL_MEM_MALLOC_HUGE_FIRST); aclrtMalloc(&dNO, 16, ACL_MEM_MALLOC_HUGE_FIRST); aclTensor* tNA = mk(nA, 2, ACL_FLOAT16, dNA, sA); aclTensor* tNO = mk(nO, 2, ACL_FLOAT16, dNO, sO); ws = 0; ex = nullptr; int r4 = (int)aclnnMatmulGetWorkspaceSize(tNA, tB, tNO, 0, &ws, &ex); printf("Case4 negative dim (-2,4) -> %d (expect 161002)\n", r4); ws = 0; ex = nullptr; int r5 = (int)aclnnMatmulGetWorkspaceSize(mk(aD, 2, ACL_INT8, dA), tB, tOk, 0, &ws, &ex); printf("Case5 control int8 self -> %d (expect 161002)\n", r5); aclrtResetDevice(0); aclFinalize(); return 0; }实测输出:
影响
调用方普遍按返回码分支处理:收到 561xxx 会判定为 CANN 内部故障,去排查安装/环境/内存,而真实原因是自身
out传错。out元素数不符属易犯错误(多算少算一维、batch 维漏乘)。建议
三处配合修改,
matmul/mat_mul_v3/op_host/op_api/aclnn_matmul.cpp:CheckInputParams(第 229-249 行)目前只校验CheckNotNull、dtype 规则、CheckShapeValid(self, mat2)、CheckFormat,没有比对out与推导 shape。建议参照同目录aclnn_mm.cpp的CheckOutputShapeValid(第 55-71 行)新增等价函数并接入校验链;aclnnMatmul因支持 1~8 维与 1D 补维移除规则,推导需多一步,骨架可复用。CheckShapeValid(第 164-213 行)目前只校验维数上限、维数非 0、K 轴相等、batch 可广播,未校验任一维度< 0。建议增加该判断并返回ACLNN_ERR_PARAM_INVALID。matmul/common/op_host/op_api/matmul_util.cpp第 2483 行l0op::Reshape(convOut, output->GetViewShape(), executor)在元素数不符时返回nullptr,第 2477 行将其归为ACLNN_ERR_INNER_NULLPTR。元素数不符属可在第一段预判的用户错误,应在第一段拦截;第二段保留内部错误语义。