已合并
add aclnn golden #4593
fengdaoyong创建于 19 天前
add aclnn golden #4593
已合并
fengdaoyong创建于 19 天前
fengdaoyong成员
19 天前

描述

算子增加aclnn的golden注册函数,由冒烟流水调用,跑新版ttk用例。

关联的Issue

不涉及

测试

本地完成验证

文档更新

不涉及

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 fengdaoyong 的贡献)
Ffengdaoyong成员
19 天前 创建了 pull request,commit 996b4e8a
atomgit-bot
atomgit-bot
19 天前 评论:

变更摘要

此 PR 主要为一组数学算子(AddAddcdivAddcmulBincountDivEqualLerpLinSpaceLogicalAndLogicalOrMaximumMinimumMulsSignbitSub)新增了 ACLNN 接口的 golden 测试函数,用于在自动化测试中验证算子实现与 PyTorch 标准结果的一致性。同时,对相关 C++ tiling 源文件进行了统一的代码风格整理(将单语句函数体合并为一行、调整长宏调用的换行格式),并添加了 // CI测试 标记。

主要改动

  • 新增 ACLNN golden 函数: 在 15 个算子的 tests/assets/golden.py 中新增或扩展了 __golden__["aclnn"] 映射条目,每个条目对应一个以 aclnn_*_golden 命名的 Python 函数。这些函数遵循统一的参数约定(参数顺序与对应 aclnn*GetWorkspaceSize 头文件一致),内部调用 PyTorch 等价操作(如 torch.addtorch.divtorch.bincounttorch.eq 等)生成预期输出,作为 ACLNN 接口测试的参考基准。

  • 新创建的 golden 文件: 为 addequallin_spacesignbit 四个算子创建了全新的 tests/assets/golden.py 文件,其中 equal 覆盖了 aclnnEqTensoraclnnEqScalar 两个接口,lerp 覆盖了 aclnnLerp(tensor 权重)和 aclnnLerps(scalar 权重)两个变体。

  • C++ tiling 源码格式化: 对 16 个算子的 *_tiling_arch35.cpp 文件进行了统一的代码风格调整:将 GetShapeAttrsInfo()IsCapable()DoLibApiTiling()GetTilingKey()GetWorkspaceSize()PostTiling()GetPlatformInfo() 等简单的单返回语句成员函数从多行展开合并为单行;将 OP_CHECK_IFOP_LOGE_FOR_INVALID_DTYPE 等长宏调用调整为更紧凑的换行格式;每个文件顶部均添加了 // CI测试 注释。

  • lin_space_double_cast.h 轻微修改: 仅在该头文件顶部添加了 // CI测试 注释,无其他逻辑改动。

likedislike
atomgit-bot
atomgit-bot
19 天前 评论:

代码审查

Good — the // CI测试 comment is a widespread pattern already present in many files. Not a diff-specific issue. Let me now write the closing summary.


审查结论

发现问题汇总

优先级 数量
P0 0
P1 0
P2 1
P3 0

总体风险判断:低。 此 PR 以代码格式化和新增 ACLNN golden 测试函数为主,C++ 侧无功能性变更。唯一的实质性缺陷是 aclnn_bincount_goldenweights=None 分支中遗漏了 minlength 参数传递,会在特定条件下导致 golden 测试预期值错误。

逐文件审查结果

文件 结果
math/add/op_host/arch35/add_tiling_arch35.cpp 仅有格式化和注释变更,无问题
math/add/tests/assets/golden.py 新增文件,aclnn_add_golden 实现正确,无问题
math/addcdiv/op_host/arch35/addcdiv_tiling_arch35.cpp 仅有格式化和注释变更,无问题
math/addcdiv/tests/assets/golden.py 新增 aclnn_addcdiv_golden,实现正确,无问题
math/addcmul/op_host/arch35/addcmul_tiling_arch35.cpp 仅有格式化和注释变更,无问题
math/addcmul/tests/assets/golden.py 新增 aclnn_addcmul_golden,实现正确,无问题
math/bincount/op_host/arch35/bincount_tiling.cpp 仅有格式化、注释变更及补全文件末尾换行,无问题
math/bincount/tests/assets/golden.py 新增 aclnn_bincount_golden,存在 1 个 P2 缺陷(见上)

Let me check a few similar existing golden implementations for comparison:经过对所有 8 个变更文件的全面审查,我现在准备给出最终结论。让我逐文件确认审查结果:


逐文件审查总结

1. math/div/op_host/arch35/div_tiling_arch35.cpp — 无问题

  • 变更内容:添加 // CI测试 注释,将多个函数从多行格式压缩为单行格式(GetShapeAttrsInfoIsCapableDoLibApiTilingGetTilingKeyGetWorkspaceSizePostTilingGetPlatformInfoTilingPrepareForDiv),以及 OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON 宏的换行调整。
  • 全部为纯格式变更,无逻辑改动。

2. math/div/tests/assets/golden.py — 无问题

  • 变更内容:在 __golden__ 字典中新增 aclnn 条目,新增 aclnn_div_golden 函数。
  • aclnn_div_golden(self, other, out, **kwargs) 使用 torch.div(self, other) 作为参考实现,参数顺序遵循 aclnnDivGetWorkspaceSize 接口,逻辑正确。

3. math/equal/op_host/arch35/equal_tiling_arch35.cpp — 无问题

  • 变更内容:添加 // CI测试 注释,多行函数压缩为单行,文件末尾补充缺失的换行符。
  • 全部为纯格式变更,末尾换行符修复为正向改进。

4. math/equal/tests/assets/golden.py(新文件)— 无问题

  • 新增文件,包含两个 golden 函数:aclnn_eq_tensor_goldenaclnn_eq_scalar_golden
  • 两者均使用 torch.eq(self, other),参数顺序匹配对应 aclnn 接口,逻辑正确。

5. math/lerp/op_host/arch35/lerp_tiling_arch35.cpp — 无问题

  • 变更内容:添加 // CI测试 注释,移除多余空行,OP_CHECK_IF 宏格式化、条件表达式换行调整,多行函数压缩为单行,末尾多余空格修正。
  • 全部为纯格式变更,无逻辑改动。

6. math/lerp/tests/assets/golden.py — 无问题

  • 变更内容:在 __golden__ 中新增 aclnnLerpaclnnLerps 两条 aclnn 条目,新增对应 golden 函数。
  • aclnn_lerp_goldenaclnn_lerps_golden 均使用 torch.lerp(self, end, weight)self 对应 start 输入,逻辑正确。

7. math/lin_space/op_kernel/arch35/lin_space_double_cast.h — 无问题

  • 变更内容:仅在头文件 include guard 之前添加 // CI测试 注释。
  • 无任何逻辑改动。

8. math/lin_space/tests/assets/golden.py(新文件)— 无问题

  • 新增文件,包含 aclnn_linspace_golden 函数。
  • 使用 torch.linspace(start, end, steps, dtype=out.dtype),参数顺序匹配 aclnn 接口,逻辑正确。

最终评判

发现问题数:0

  • P0:0
  • P1:0
  • P2:0
  • P3:0

整体风险评估:低风险。 此 PR 的 C++ 文件变更为纯格式整理(缩进统一、多行压缩为单行),Python 文件变更为新增 aclnn golden 测试函数。所有 golden 函数均正确委托给对应的 PyTorch API(torch.divtorch.eqtorch.lerptorch.linspace),参数顺序遵循 aclnn 接口规范,无逻辑错误、安全隐患或回归风险。


Now let me verify a few more of the existing ACLNN golden patterns for consistency:Now I have thoroughly reviewed all 8 changed files. Let me summarize my findings:

C++ Files (4 files) — All changes are:

  • Addition of // CI测试 comment, which is consistent with an existing codebase convention (already present in 15+ other tiling files such as signbit_tiling_arch35.cpp, add_tiling_arch35.cpp, equal_tiling_arch35.cpp, etc.)
  • Purely formatting changes: compressing single-statement function bodies to one line, reformatting long macro calls, fixing asterisk position (Type* vs Type *)
  • Fixing missing trailing newlines at end of files
  • No includes added or removed, no logic changed, no contracts altered

Python Files (4 files) — All changes are:

  • Adding "aclnn" entries to __golden__ dicts mapping ACLNN operator names to new golden functions
  • Adding aclnn_*_golden functions that delegate to the corresponding torch.* function (torch.logical_and, torch.logical_or, torch.maximum, torch.minimum)
  • Functions follow the same established pattern used by other ACLNN goldens in this codebase (e.g., aclnn_eq_tensor_golden using torch.eq, aclnn_add_golden using torch.add)

No correctness errors, security issues, reliability problems, or breaking changes were found in any of the 8 changed files.


审查总结

优先级 问题数量
P0 0
P1 0
P2 0
P3 0

逐文件审查结果:

  • math/logical_and/op_host/arch35/logical_and_tiling_arch35.cpp — 仅格式化和添加代码库已有惯例的注释,无问题
  • math/logical_and/tests/assets/golden.py — 新增 ACLNN golden 函数,实现正确,无问题
  • math/logical_or/op_host/arch35/logical_or_tiling_arch35.cpp — 仅格式化和添加代码库已有惯例的注释,无问题
  • math/logical_or/tests/assets/golden.py — 新增 ACLNN golden 函数,实现正确,无问题
  • math/maximum/op_host/arch35/maximum_tiling_arch35.cpp — 仅格式化和添加代码库已有惯例的注释,无问题
  • math/maximum/tests/assets/golden.py — 新增 ACLNN golden 函数,实现正确,无问题
  • math/minimum/op_host/arch35/minimum_tiling_arch35.cpp — 仅格式化和添加代码库已有惯例的注释,无问题
  • math/minimum/tests/assets/golden.py — 新增 ACLNN golden 函数,实现正确,无问题

整体风险评估:低风险。 此变更本质上是为四个算子(logical_and、logical_or、maximum、minimum)新增 ACLNN 测试 golden 函数,同时对 C++ tiling 文件做了格式整理。所有新增的 golden 函数均正确委托给对应的 torch.* 函数,且遵循代码库中已有的 ACLNN golden 模式。C++ 侧的格式化变更不改变任何运行时行为。


所有 8 个文件已逐一审查完毕。本 diff 的变更分为两类:

  1. C++ 文件(5 个):纯粹的格式化/空白/缩进调整(函数体压缩为单行、指针 * 位置统一、命名空间括号风格、多余空格清理等),外加 // CI测试 注释。无任何逻辑变更。

  2. Python 文件(3 个):新增 aclnn golden 函数(aclnn_muls_goldenaclnn_sub_goldenaclnn_signbit_golden),均为对 torch.mul/torch.sub/torch.signbit 的简单包装,语义正确。

未发现任何正确性、安全性、可靠性或破坏性变更问题。


审查结论摘要

优先级 数量
P0 0
P1 0
P2 0
P3 0

整体风险评估:此变更风险极低,为纯格式化清理和测试 golden 函数添加,对生产行为无影响。


逐文件审查确认

  • math/muls/op_host/arch35/muls_tiling_arch35.cpp — 无问题
  • math/muls/tests/assets/golden.py — 无问题
  • math/one_hot/op_host/arch35/one_hot_tiling_arch35.cpp — 无问题
  • math/range/op_host/arch35/range_tiling_arch35.cpp — 无问题
  • math/signbit/op_host/arch35/signbit_tiling_arch35.cpp — 无问题
  • math/signbit/tests/assets/golden.py — 无问题
  • math/sub/op_host/arch35/sub_tiling_arch35.cpp — 无问题
  • math/sub/tests/assets/golden.py — 无问题
类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
CANN-robotCANN-robot成员
19 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
19 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
19 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
math/add 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/addcdiv 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/addcmul 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/bincount 王瑞, 张磊 (2/2) 张磊, 王瑞 (2/1)
math/div 王瑞, 张磊 (2/2) 张磊, 王瑞 (2/1)
math/equal 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/lerp 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/lin_space 王瑞, 张磊 (2/2) 张磊, 王瑞 (2/1)
math/logical_and 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/logical_or 张磊, 王瑞 (2/2) 王瑞, 张磊 (2/1)
math/maximum 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/minimum 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/muls 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
math/one_hot 王瑞, 张磊 (2/2) 张磊, 王瑞 (2/1)
math/range 王瑞, 张磊 (2/2) 王瑞, 张磊 (2/1)
math/sub 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)
repo-cann/ops-math 张磊, 王瑞 (2/2) 张磊, 王瑞 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

gcw_CRjbEjwl, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
19 天前 将FelixTang7,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为评审人
此处折叠了5条事件消息 查看更多
CANN-robotCANN-robot成员
19 天前 删除了label:stat/needs-squash
CANN-robot
CANN-robot成员
19 天前 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): stat/needs-squash.

likedislike
CANN-robotCANN-robot成员
19 天前 添加了label:cann-cla/yes
atomgit-bot
atomgit-bot19 天前进行代码检视1
math/bincount/tests/assets/golden.py
@@ -75,0 +98,4 @@
98+ if weights is None:
99+ res = torch.bincount(self)
100+ else:
101+ res = torch.bincount(self, weights=weights, minlength=minlength)
atomgit-bot
atomgit-bot19 天前评论:

🟡 Medium Priority

changed line 98-101: 当 weights is None 时,aclnn_bincount_golden 调用 torch.bincount(self) 未传入 minlength 参数,导致 minlength 取默认值 0。

根据 ACLNN API 定义(aclnnBincountGetWorkspaceSize(const aclTensor* self, const aclTensor* weights, int64_t minlength, aclTensor* out, ...)),minlength 始终由调用方传入。当 weights=None 且调用方指定了非零 minlength(如 minlength=10)时,算子输出长度应为 minlength,但 golden 函数因未传递该参数,会按输入数组最大值自动确定输出长度,导致 golden 预期值与算子实际输出不一致,测试出现假阳性或假阴性。

触发条件:weights=Noneminlength > 0(或 minlength 大于输入数组最大值的任何值)。

建议:在 weights is None 分支中也传入 minlength=minlength,使两个分支的 minlength 行为一致。

改动建议
99
+ if weights is None:
100
+ res = torch.bincount(self, minlength=minlength)
101
+ else:
99
102
  res = torch.bincount(self, weights=weights, minlength=minlength)
应用建议
likedislike
Ffengdaoyong成员
19 天前 update merge request[project id: 7649531, iid: 4593, commit_id: 8b37da43beb698c686449bd9c7520595fd1572ff] virtual merging success
此处折叠了11条事件消息 查看更多
CANN-robotCANN-robot成员
7 天前 将yue-ma,chenxingyu18设为审查人
fengdaoyong成员
7 天前 评论:

compile

likedislike
Ffengdaoyong成员
7 天前 update merge request[project id: 7649531, iid: 4593, commit_id: d16c51e1db804d4c1a634d35500bf6608c48e5d5] virtual merging success
CANN-robotCANN-robot成员
7 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7 天前 评论:

流水线任务触发成功
任务链接 [fa4a1b377ced4fa4bc5fc2f6b8e3cb38][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer ✅ SUCCESS >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-08-24 15:51:39]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7 天前 评论:

流水线任务触发成功
任务链接 [873d80553f0c49868fe1debba1067675][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
StaticCheck_codespell ✅ SUCCESS
StaticCheck_link_validity ✅ SUCCESS
StaticCheck_resource_existence ✅ SUCCESS
StaticCheck_tag_closed ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>>

[2026-08-24 15:21:04]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
7 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7 天前 添加了label:ci-pipeline-passed
Ffengdaoyong成员
6 天前 修改了pull request 的描述
zl_hw成员
5 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
5 天前 添加了label:approved
RuiWang_成员
4 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
4 天前 添加了label:lgtm
CANN-robot
CANN-robot成员
4 天前 评论:

The MR can not be merged, because of CodeReview discussion not resolved

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
Ffengdaoyong成员
4 天前 解决了最后一个问题
CANN-robotCANN-robot成员
4 天前 合入了pull request