Merged
fix(foreach): 加固 foreach_erfc arch35 校验与 aclnn 健壮性并修正资料口径 #13805
fix(foreach): 加固 foreach_erfc arch35 校验与 aclnn 健壮性并修正资料口径 #13805
Merged
duxinleiAdd on 16 days ago
duxinlei
duxinleiCollaborators
16 days ago

描述

fix(foreach): 加固长尾算子 foreach_erfc arch35 校验与 aclnn 健壮性并修正资料口径

关联的Issue

关联Issue #8035

测试

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for duxinlei's contribution.)
duxinleiduxinleiCollaborators
16 days ago Created pull request, commit 98197ed5
atomgit-bot
atomgit-bot
16 days ago Comments:

变更摘要

本 PR 主要针对 foreach_erfc 算子的 arch35 Tiling 校验与 aclnn 接口健壮性进行加固。核心改动是新增 ValidateForeachErfc 统一校验流程,覆盖 Tensor 数量一致性、维度上限、元素数、dtype 合法性及列表内一致性、输出 shape/dtype 对齐等约束,并在 instanceNum 窄化前完成上限判断;同时在 aclnnForeachErfcGetWorkspaceSize 中补充公共入参空指针检查,并将示例与 UT 调整为可覆盖失败路径与参数异常场景。

主要改动

  • 新增 Tiling 输入校验函数: 新增 ValidateForeachErfc,逐项校验 x 与 y 的 Tensor 数量一致、desc/shape 非空、维度不超过 MAX_DIM_NUM(8 维)、GetShapeSize() 非负、输入 dtype 仅限 DT_FLOAT/DT_FLOAT16/DT_BF16 且列表内一致,以及 y 的 dtype 和 shape 与对应 x 严格一致。
  • 数量上限校验前移: 将 MAX_TENSOR_NUM_FOREACH_ERFC 比较改为在 instanceNum(uint64_t)上先判断再窄化为 int32_t,避免超界实例数经整型截断绕过定长数组边界,并改用 OP_LOGE_FOR_INVALID_TENSORNUM 输出错误信息。
  • aclnn 接口入参检查: 在 aclnnForeachErfcGetWorkspaceSize 入口增加 OP_CHECK_COMM_INPUT(workspaceSize, executor),使 workspaceSize 或 executor 为空时直接返回参数错误。
  • 示例资源管理改造: test_aclnn_foreach_erfc.cpp 将主体逻辑抽为 ForeachErfcExample,对 device 内存、aclTensorList、workspace 使用 unique_ptr 自定义删除器自动释放,main 仅负责 init/销毁与返回值透传,保证失败提前返回路径也能释放资源。
  • UT 覆盖扩展: arch35 单测重构出 RunTilingCase 与 MakeStorageShape 辅助函数和完整平台 JSON,新增多实例成功、混合 dtype、非支持 dtype、负 shape size、Tensor 数超 256、输出数量/dtype/shape 不匹配、超 8 维等失败用例;op_api 单测新增 workspaceSize 与 executor 为空的返回码断言。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
16 days ago Comments:

代码审查

检视结论

本次改动方向正确(tiling 侧补 dtype/shape/数量校验、aclnn 补公共入参判空、示例改 RAII、UT 补负向用例),核心逻辑未发现明确的功能性回归;问题集中在宏名一致性、示例 RAII 收尾不完整以及新增负向用例的覆盖有效性上。

按文件确认

  • foreach/foreach_erfc/examples/test_aclnn_foreach_erfc.cpp:已检视。发现 2 项(新增注释与 aclTensor 实际未释放不符;deviceId 形参未使用)。device 内存/TensorList 的 unique_ptr 声明顺序与析构顺序(先释放 workspace、再 TensorList、后 device 内存)正确,失败提前返回路径能正确释放已申请的 device 内存,无双重释放。
  • foreach/foreach_erfc/op_host/arch35/foreach_erfc_tiling_arch35.cpp:已检视。发现 1 项(OP_LOGE_FOR_INVALID_TENSORNUM 与同文件 OP_LOGE_FOR_INVALID_TENSORNUMS_WITH_REASON 拼写不一致,需核实宏定义)。ValidateForeachErfc 的 x/y 数量、desc/shape 判空、维度 ≤8、shapeSize 非负、列表内 dtype 一致、y 与 x dtype/shape 一致等校验顺序与边界(0 元素、256 实例)均自洽,与 aclnn_foreach_erfc.cpp 中已有的 OP_CHECK_DTYPE_NOT_MATCH / OP_CHECK_SHAPE_NOT_EQUAL 判据一致,未造成与 aclnn 侧的口径分叉。
  • foreach/foreach_erfc/op_host/op_api/aclnn_foreach_erfc.cpp:已检视,除被 UT 覆盖不足(见下)外无问题。新增 OP_CHECK_COMM_INPUT(workspaceSize, executor) 与仓库内同类 aclnn 封装写法一致。
  • foreach/foreach_erfc/tests/ut/op_host/arch35/test_foreach_erfc_tiling.cpp:已检视。发现 2 项(实例数超 256 用例未锁定新增检查;Build 后未校验 context 非空)。
  • foreach/foreach_erfc/tests/ut/op_host/op_api/test_aclnn_foreach_erfc.cpp:已检视。发现 1 项(executor 空指针用例同时传空 x,无法覆盖新增分支)。

计数

  • P0:0
  • P1:0
  • P2:1(错误码宏名单复数不一致,需核实实际定义)
  • P3:5(示例注释与 aclTensor 释放不符、未使用形参、两处 UT 覆盖有效性、UT 空指针断言缺失)

整体风险判断:低。生产代码改动是校验增强而非算法/调度变更,未见越界、资源泄漏或参数契约破坏;唯一需要立刻确认的是 P2 那处宏名是否真实存在(若不存在会编译失败),其余为示例与测试质量问题。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
16 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
16 days ago Comments:

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
*/*/README.md ✅ 杜慧萍, 上官秦南 (2/2) ✅ 杜慧萍 (1/1)
*/*/docs/acl*.md ✅ 杜慧萍, 上官秦南 (2/2) ✅ 杜慧萍 (1/1)
foreach ✅ 陈展熹, 上官秦南 (2/2) ✅ 陈展熹 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
16 days ago Set zengjuan,u010470851,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,yourealize,chenqi317,wang-xing001,liubo75,tangweiwei2,gitcode-chenjiao,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong,fengying555682,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
16 days ago Set u010470851,kevin_huang1234,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,yourealize,wang-xing001,gitcode-chenjiao,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong,fengying555682,caiwenwen,yanglu-1 as approver
duxinleiduxinleiCollaborators
16 days ago Pre merge succeeded (commit_id: 2e9d35d1dfa1e00af884c222250788ef23e4ffc4)
duxinleiduxinleiCollaborators
16 days ago Force-pushed 1 commits:3431b870-fix(foreach): 加固 foreach_erfc arch35 校验与 aclnn 健壮性并修正资料口径
duxinleiduxinleiCollaborators
16 days ago Pre merge succeeded (commit_id: 748344dbce33ec30a45df4c950a7b02d45226b93)
atomgit-bot
atomgit-bot16 days agoStart code review1
foreach/foreach_erfc/op_host/arch35/foreach_erfc_tiling_arch35.cpp
@@ -87,1 +178,3 @@
87- MAX_TENSOR_NUM_FOREACH_ERFC),
178+ uint64_t instanceNum = idxInstanceInfoPtr->GetInstanceNum();
179+ // 窄化前校验数量上限,防止超界实例数经 int32 截断绕过定长数组边界
180+ OP_CHECK_IF(instanceNum > static_cast<uint64_t>(MAX_TENSOR_NUM_FOREACH_ERFC),
atomgit-bot
atomgit-bot16 days agoComments:

🟡 Medium Priority

建议:核对 op_host 日志宏头文件中 tensor 数量非法对应的宏名(含 _WITH_REASON 变体),将第 178 行改成与第 80 行一致的名字(如 OP_LOGE_FOR_INVALID_TENSORNUMS),并确认实参顺序与宏定义一致。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
16 days ago Removed label: cann-cla/yes
CANN-robotCANN-robotCollaborators
16 days ago Added label: cann-cla/yes
duxinleiduxinleiCollaborators
16 days ago Resolved final issue
duxinlei
duxinleiCollaborators
16 days ago Comments:

/compile

likedislike
duxinleiduxinleiCollaborators
16 days ago Pre merge succeeded (commit_id: 7dd434796ccc564cc184c49a6b54f23986e2fc9b)
CANN-robot
CANN-robotCollaborators
16 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
16 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
16 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
16 days ago Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
16 days ago Comments:
gitee-duhuiping
gitee-duhuipingCollaborators16 days agoStart code review1
foreach/foreach_erfc/README.md
@@ -66,3 +66,3 @@
6666## 约束说明
6767 
68-- 输出不支持非连续Tensor。
68+- x与out的Tensor数量一致,且out中对应位置Tensor的shape size大于等于x中对应位置Tensor的shape size。
gitee-duhuiping
gitee-duhuiping16 days agoComments:

后半句在参数说明中已有,这里不需要重复体现了吧

likedislike
gitee-duhuiping
gitee-duhuipingCollaborators16 days agoStart code review2
foreach/foreach_erfc/README.md
Outdated
@@ -67,2 +67,3 @@
6767 
68-- 输出不支持非连续Tensor。
68+- x与out的Tensor数量一致,且out中对应位置Tensor的shape size大于等于x中对应位置Tensor的shape size。
69+- x或out的单个Tensor列表内所有Tensor的数据类型保持一致,且x与out的数据类型一致,均须在参数表声明的支持范围内。
gitee-duhuiping
gitee-duhuiping16 days agoComments:

这个约束在参数说明中已有,不要重复呈现

likedislike
System
System MessageSystem
16 days ago Comments:

changed this line on 5912ce40 view diff detail

likedislike
duxinleiduxinleiCollaborators
16 days ago Pre merge succeeded (commit_id: a9445a9c7c4a6d791d6ee62927a54429302f3c9c)
duxinleiduxinleiCollaborators
16 days ago Force-pushed 1 commits:5912ce40-fix(foreach): 加固 foreach_erfc arch35 校验与 aclnn 健壮性并修正资料口径
duxinleiduxinleiCollaborators
16 days ago Pre merge succeeded (commit_id: 7f9f8ac5158ed5ececa28cf099905ac3269d78d2)
CANN-robotCANN-robotCollaborators
16 days ago Removed label: cann-cla/yes
CANN-robotCANN-robotCollaborators
16 days ago Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
16 days ago Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robotCollaborators
16 days ago Added label: cann-cla/yes
duxinleiduxinleiCollaborators
16 days ago Resolved final issue
duxinleiduxinleiCollaborators
16 days ago Modify description of pull request
duxinleiduxinleiCollaborators
16 days ago Associated issue: [Bug-Report|缺陷反馈]: foreach_erfc 质量加固
duxinleiduxinleiCollaborators
16 days ago Modify description of pull request
gitee-duhuiping
gitee-duhuipingCollaborators
16 days ago Comments:

/lgtm
/approve

likedislike
sgqt12
sgqt12Collaborators
16 days ago Comments:

/lgtm

likedislike
duxinlei
duxinleiCollaborators
16 days ago Comments:

/compile

likedislike
duxinleiduxinleiCollaborators
16 days ago Pre merge succeeded (commit_id: fee0cd7794b4cd8e35ba6a1d2d0932942eaa8ed8)
CANN-robot
CANN-robotCollaborators
16 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
16 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
16 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
16 days ago Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
16 days ago Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!
@gitee-duhuiping @u010470851 @kevin_huang1234 @su-yueming @wangrui_ @Chen_HaoWen @renruhai @zhajianqing123

likedislike
陈展熹
陈展熹Collaborators
16 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
16 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
16 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
16 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike