Closed
[Documentation|文档反馈]: aclnnInplaceRoundDecimals 头文件 selfRef 注释漏 BFLOAT16(同文件 L82 写了,资料与白名单均支持) #4142
liuhanwen8Add on  14 days agoClosed at  3 days ago
liuhanwen8
liuhanwen8
14 days ago Create

现象

结论:math/round/op_api/aclnn_round.h 里一对同源接口的 dtype 注释不一致——aclnnInplaceRoundDecimals 的 selfRef 注释(L121)漏了 BFLOAT16,而同文件 aclnnRoundDecimals 的 self 注释(L82)写了;资料参数表与源码白名单都支持 BFLOAT16。

来源 位置 是否含 BFLOAT16
头文件 aclnnRoundDecimals.self aclnn_round.h:82 含
头文件 aclnnInplaceRoundDecimals.selfRef aclnn_round.h:121 缺
资料 selfRef 参数表(Inplace 段) aclnnRoundDecimals&aclnnInplaceRoundDecimals.md:274 含
源码 910B 白名单 ASCEND910B_DTYPE_DTYPE_SUPPORT_LIST aclnn_round.cpp:33 含 DT_BF16

实测(A2 910B2 / CANN 9.2.0,独立 C++ 直调):bf16 输入 bits 3F00/3F80/C000/BF80(0.5, 1.0, -2.0, -1.0)→ 输出 0000/3F80/C000/BF80(0, 1, -2, -1),两段接口均返回 0。

同族 issue 差异:#4129 是 aclnnAffineGrid、#4118 是 aclnnInplaceCosh 的资料支持表;本条是 aclnnInplaceRoundDecimals 的头文件 selfRef 注释与同文件 aclnnRoundDecimals 注释不一致,接口与载体均不同。同接口的实现缺陷另见 #4121。

期望

aclnnInplaceRoundDecimalsGetWorkspaceSize 的 selfRef 注释应与同文件 aclnnRoundDecimals 的 self 注释、以及资料参数表 L274 一致,列出 BFLOAT16。两个接口共用同一个 CheckDtypeValid 与同一条 ExecRoundDecimalsGetWorkspaceSize 路径,dtype 白名单为同一份。

环境

  • 硬件:A2 910B2 ×8(单卡)
  • CANN:9.2.0
  • 仓库:cann/ops-math master 21848df4
  • 日期:2026-10-27

复现步骤

  1. 取仓库 cann/ops-math(master)。
  2. 保存下方 assert_bf16.py。
  3. 在仓库根目录执行 python3 assert_bf16.py --repo-root .。
  4. 看 5 条 [CHECK] 与末尾 [DEFECT]:退出码 1 即注释不一致成立。
  5. 反证:把 aclnn_round.h:121 补成与 L82 一致后重跑,退出码 0、输出 [OK]。

复现脚本

#!/usr/bin/env python3
"""断言 aclnnInplaceRoundDecimals 头文件 selfRef 的 dtype 注释漏了 BFLOAT16。"""
import argparse
import os
import sys


def rd(p):
    return open(p, encoding="utf-8").read().splitlines()


def dtype_after(lines, anchor):
    for i, l in enumerate(lines):
        if anchor in l:
            for j in range(i, min(i + 8, len(lines))):
                if "数据类型支持" in lines[j]:
                    return j + 1, lines[j]
    return None, ""


ap = argparse.ArgumentParser()
ap.add_argument("--repo-root", default=".")
root = ap.parse_args().repo_root
H = os.path.join(root, "math/round/op_api/aclnn_round.h")
C = os.path.join(root, "math/round/op_api/aclnn_round.cpp")
M = os.path.join(root, "math/round/docs/aclnnRoundDecimals&aclnnInplaceRoundDecimals.md")
for p in (H, C, M):
    if not os.path.exists(p):
        print("[SKIP] 缺文件 %s" % p)
        sys.exit(0)
hl, cl, ml = rd(H), rd(C), rd(M)
on, ot = dtype_after(hl, "const aclTensor* self;")
if on is None:
    on, ot = dtype_after(hl, "@param [in]   self")
inn, it = dtype_after(hl, "@param [in]   selfRef")
h = next((i for i, l in enumerate(ml)
          if l.startswith("## aclnnInplaceRoundDecimalsGetWorkspaceSize")), 0)
mdn = next((i + 1 for i in range(h, min(h + 120, len(ml)))
            if "FLOAT、BFLOAT16、FLOAT16、DOUBLE、INT32、INT64" in ml[i]), None)
wln = next((i + 1 for i, l in enumerate(cl) if "ASCEND910B_DTYPE_DTYPE_SUPPORT_LIST" in l), None)
wlok = wln is not None and "DT_BF16" in "\n".join(cl[wln - 1:wln + 6])
shared = any("CheckDtypeValid" in l for l in cl)
print("[CHECK] 头文件 aclnnRoundDecimals.self          L%s %s" % (on, ot.strip()))
print("[CHECK] 头文件 aclnnInplaceRoundDecimals.selfRef L%s %s" % (inn, it.strip()))
print("[CHECK] 资料参数表 L%s 含 BFLOAT16:%s" % (mdn, mdn is not None))
print("[CHECK] 源码白名单 L%s 含 DT_BF16:%s" % (wln, wlok))
print("[CHECK] 两接口共用 CheckDtypeValid:%s" % shared)
if "BFLOAT16" in ot and "BFLOAT16" not in it and mdn and wlok and shared:
    print("\n[DEFECT] L%s 写 BFLOAT16、L%s 漏写;资料 L%s 与白名单 L%s 均支持,两接口共用同一 CheckDtypeValid。"
          % (on, inn, mdn, wln))
    sys.exit(1)
print("\n[OK] 无注释不一致(若已补全,本条不成立)")
sys.exit(0)

实测输出:

[CHECK] 头文件 aclnnRoundDecimals.self          L82 * 输入Tensor,数据类型支持FLOAT,BFLOAT16,FLOAT16,DOUBLE,INT32,INT64。
[CHECK] 头文件 aclnnInplaceRoundDecimals.selfRef L121 * 输入Tensor,数据类型支持FLOAT,FLOAT16,DOUBLE,INT32,INT64。
[CHECK] 资料参数表 L274 含 BFLOAT16:True
[CHECK] 源码白名单 L33 含 DT_BF16:True
[CHECK] 两接口共用 CheckDtypeValid:True

[DEFECT] L82 写 BFLOAT16、L121 漏写;资料 L274 与白名单 L33 均支持,两接口共用同一 CheckDtypeValid。

影响

按头文件注释判断能力的调用方(含 IDE 补全与头文件检索)会认为该接口不支持 bf16,从而主动规避或改用 fp32,丢掉 bf16 的带宽与精度收益。

建议

把 math/round/op_api/aclnn_round.h:121 的 selfRef dtype 列表补成与 L82 一致的 FLOAT,BFLOAT16,FLOAT16,DOUBLE,INT32,INT64。

likedislike
liuhanwen8liuhanwen8
14 days ago Added label: documentation
xujiachen8Collaborators
13 days ago Comments:

您好,感谢反馈!核对当前 master(b08e885e7fac),同一头文件中 aclnnRoundDecimals 的输入注释已列 BFLOAT16,而 aclnnInplaceRoundDecimals 的 selfRef 注释仍遗漏该类型;原地接口资料也已将 BFLOAT16 列入参数表。

实现的 A2 支持列表包含 BF16,两个接口共用 CheckDtypeValid 和 ExecRoundDecimalsGetWorkspaceSize,原地入口仅把输入张量同时作为输出。因此本条可以明确为头文件注释漏项,与 #4121 的负 decimals 数值行为是不同问题。

一个可行调整是在 selfRef 注释中补齐 BFLOAT16,并与已有平台类型限制保持一致,避免把某一平台的支持无条件扩展到所有产品。我们会持续跟踪这一文档缺项。

likedislike
Xxujiachen8Collaborators
13 days ago Assign jiaoyiming as responsible person
Xxujiachen8Collaborators
13 days ago Added label: pending-confirmation
陈思陈思Collaborators
13 days ago Removed label: pending-confirmation
CANN-robotCANN-robotCollaborators
3 days ago Close issue
CANN-robotCANN-robotCollaborators
3 days ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
3 days ago Added label: resolved