Closed
[Documentation|文档反馈]: aclnnInplaceFloorDivide 资料未声明「selfRef 的 shape 须等于广播结果」(按资料构造即 161002) #4130
liuhanwen8Add on  17 days agoClosed at  4 days ago
liuhanwen8
liuhanwen8
17 days ago Create

环境

  • 硬件:Ascend 910B2(Atlas A2 系列,单卡);CANN 9.2.0(npu-smi 26.1.1)
  • 算子仓版本:cann/ops-math master d04d2af9(git fetch 后 git rev-parse HEAD 取得)
  • 资料文件:math/floor_div/docs/aclnnFloorDivide&aclnnInplaceFloorDivide.md(共 17030 字符)

现象

资料 aclnnInplaceFloorDivideGetWorkspaceSize 的参数表里,selfRef 的「使用说明」只写:

数据类型需要与other满足数据类型推导规则(参见互推导关系),shape需要与other满足broadcast关系。

但原地接口实际上还要求 selfRef 的 shape 恰好等于 selfRef 与 other 广播之后的 shape,
否则第一段返回 161002。这句话资料里没有。按资料字面构造的合法用例
(selfRef=[1,3]、other=[2,3],二者可广播)在两段式第一段就被拒。

## 约束说明 一节只写了「确定性计算:默认确定性实现」与「FLOAT16/BFLOAT16 精度有限」,
也没有涉及原地写回的 shape 约束。

复现步骤

  1. 进入算子仓根目录(math/floor_div/docs/ 的上级);
  2. 保存下方脚本为 doc_assert_broadcast.py;
  3. IFD_DOC=math/floor_div/docs/aclnnFloorDivide&aclnnInplaceFloorDivide.md python3 doc_assert_broadcast.py
  4. 观察退出码与输出(1 + [DEFECT] 表示资料缺该声明)。

复现脚本

import io, os, re, sys

PATH = os.environ.get("IFD_DOC",
                      "math/floor_div/docs/aclnnFloorDivide&aclnnInplaceFloorDivide.md")
text = io.open(PATH, encoding="utf-8", errors="replace").read()
m = re.search(r"## aclnnInplaceFloorDivideGetWorkspaceSize(.*?)(?=\n## )", text, re.S)
sect = m.group(1) if m else ""
flat = re.sub(r"<[^>]+>", "", sect)          # 表格单元格里有 <a href=...>
assert "selfRef" in flat and "broadcast" in flat, "资料措辞已变,需人工复核"
assert re.search(r"shape\s*需要与\s*other\s*满足", flat), "找不到广播关系声明"

pats = [r"selfRef[^。]{0,80}(等于|一致|相同)[^。]{0,40}(广播|broadcast)",
        r"selfRef[^。]{0,80}(广播|broadcast)[^。]{0,40}(之后|后)[^。]{0,20}(形状|shape)[^。]{0,20}(等于|一致)",
        r"(原地|原地写回|inplace)[^。]{0,60}(形状|shape)[^。]{0,30}(等于|一致)[^。]{0,30}(广播|broadcast)",
        r"(广播|broadcast)[^。]{0,30}(结果|后)[^。]{0,30}(存储|写回|容纳)[^。]{0,40}selfRef"]
hit = [mm.group(0) for p in pats for mm in re.finditer(p, text, re.S)]
if hit:
    print("[OK] 资料已声明原地约束:%s" % hit[0].replace("\n", " ")[:80])
    sys.exit(0)
print("[DEFECT] 资料未声明「原地接口要求 selfRef 的 shape 恰等于广播结果」,"
      "而实现按此校验(selfRef=[1,3]/other=[2,3] 第一段返回 161002)")
sys.exit(1)

实测输出:

[DEFECT] 资料未声明「原地接口要求 selfRef 的 shape 恰等于广播结果」,而实现按此校验(selfRef=[1,3]/other=[2,3] 第一段返回 161002)
$ echo $?
1

上板补充证据(C++ 两段式直调,同仓 op_api 校验链):

selfRef=fp32[1x3] other=fp32[2x3]  ->  GetWorkspaceSize=161002
selfRef=fp32[2x3] other=fp32[1x3]  ->  GetWorkspaceSize=0(正常)
selfRef=fp32[3]   other=fp32[2x3]  ->  GetWorkspaceSize=161002

期望

在 selfRef 的「使用说明」列(或 ## 约束说明)补一句,例如:

原地接口要求 selfRef 的 shape 等于 selfRef 与 other 广播之后的 shape;若广播结果比
selfRef 大,第一段返回 161002。

这样调用方才能从资料判断「我能广播到更大形状吗」。

影响

  • 首次集成即被拦:用户按资料把 [1,3] 与 [2,3] 组合(资料允许的广播关系)传进来,
    第一段直接 161002,而资料没有任何一句能解释原因。
  • 错误码表只写「selfRef和other的shape无法做broadcast」——本用例的 shape 可以广播,
    报错文案与真实原因不符,进一步增加排障成本。

建议

  1. 参数表 selfRef 行补上述约束(最省事的落点);
  2. 或在 ## 约束说明 增一条「原地接口的 shape 约束」;
  3. 顺带修正报错文案:CheckInplace() 里该分支的 OP_LOGE 用的是
    ACLNN_ERR_PARAM_NULLPTR(math/floor_div/op_api/aclnn_floor_divide.cpp:388 附近),
    plog 会打印「空指针」而返回码是 161002,与本条资料缺陷同源,建议一并澄清。
likedislike
liuhanwen8liuhanwen8
17 days ago Added label: documentation
xujiachen8Collaborators
17 days ago Comments:

您好,感谢反馈及三个广播用例的对照!

问题分析

核对 cann/ops-math master b08e885e7fac370203a51904fd0680523b9a9205,原地接口参数表只写 selfRef 与 other 满足广播关系,错误码表也只描述“无法做 broadcast”,没有说明广播结果必须保持 selfRef 原有形状,这一资料缺项可以确认。参数与错误码

实现中的 CheckInplace 分两步检查:先确认两输入可广播,再要求广播结果的 shape 等于 selfRef。后者保证结果能够按原有张量形状写回。因此 [1,3] 与 [2,3] 虽可广播为 [2,3],仍会在第二项检查返回 ACLNN_ERR_PARAM_INVALID;反过来 selfRef 为 [2,3]、other 为 [1,3] 才满足这项原地约束。这与您在 A2 / CANN 9.2.0 提供的返回码一致。原地检查

该 shape 不匹配分支的日志标识确实使用 ACLNN_ERR_PARAM_NULLPTR,但函数实际返回的是 ACLNN_ERR_PARAM_INVALID,两者需要分别看待,不能将日志标识当作接口返回码。

处理方向

可考虑在 selfRef 使用说明及错误码表中明确补充“广播结果的 shape 必须等于 selfRef 的 shape”,并将这一分支的日志标识与实际参数错误含义对齐。已有广播检查有其原地写回约束,不宜为满足较简略的文字而允许 selfRef 自动扩形。我们会继续核对资料与诊断信息的一致性。

likedislike
Xxujiachen8Collaborators
17 days ago Assign sun-yibo1 as responsible person
Xxujiachen8Collaborators
17 days ago Added label: pending-confirmation
陈思陈思Collaborators
17 days ago Removed label: pending-confirmation
陈思陈思Collaborators
16 days ago Assign chen_0715 as responsible person
陈思陈思Collaborators
16 days ago Removed responsible person sun-yibo1
陈思陈思Collaborators
16 days ago Added label: pending-confirmation
CchenyifengCollaborators
15 days ago Assign gcw_SUaZx3UQ as responsible person
CchenyifengCollaborators
15 days ago Removed responsible person chen_0715
Zzhangqijia1Collaborators
11 days ago Associated pull request
CANN-robotCANN-robotCollaborators
4 days ago Close issue
CANN-robotCANN-robotCollaborators
4 days ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
4 days ago Added label: resolved