Merged
feat(zero_op): aclnnInplaceZero支持UINT32/UINT64数据类型 #7016
feat(zero_op): aclnnInplaceZero支持UINT32/UINT64数据类型 #7016
Merged
fitZepHYrAdd on 7 days ago
fitZepHYr
fitZepHYrCollaborators
7 days ago

描述

为aclnnInplaceZero接口新增UINT32、UINT64数据类型支持,满足Atlas A2/A3上无符号整型Tensor的就地清零需求。

ZerosLike内核仅支持int32/int64,因此实现上通过aclOpExecutor::CreateView为uint32/uint64输入构造同shape、同stride的int32/int64视图,复用现有Contiguous + ZerosLike + ViewCopy流程写回同一块内存。类型转换只作用于视图,不修改调用方selfRef的dtype描述。

关联的Issue

Issue 4419
Issue 4253

测试

  • A2(910B3)+ CANN 9.3.0 真机ATK验证:uint32/uint64覆盖[1,4]、[19,1]、[3,5,7]、空tensor共9条用例全部通过,输出全0且dtype保持uint32/uint64,输入探针确认非零
  • 存量289条ST用例回归全部通过(合计298/298)
  • 单元测试:l2ZeroTest 19/19通过(新增uint32/uint64用例,原以UINT32作为不支持类型的反例改为COMPLEX32);ZerosLike op_host UT 5/5通过
  • clang-format 18.1.8 检查通过

文档更新

同步更新 math/zero_op/docs/aclnnInplaceZero.md 与 math/zero_op/docs/aclnnInplaceZero_en.md,在Atlas A2/A3支持的数据类型中补充UINT32、UINT64。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for fitZepHYr's contribution.)
fitZepHYrfitZepHYrCollaborators
7 days ago Created pull request, commit b9ec2280
atomgit-bot
atomgit-bot
7 days ago Comments:

变更摘要

本 PR 为 aclnnInplaceZero 接口扩展数据类型支持,新增 DT_UINT32、DT_UINT64,使其可在 Atlas A2/A3 上对无符号整型 Tensor 就地清零。由于底层 ZerosLike 内核仅支持 int32/int64,实现在 aclnnInplaceZeroGetWorkspaceSize 中通过 aclOpExecutor::CreateView 为 uint32/uint64 输入构造同 shape、同 stride 的 int32/int64 视图,复用原有的 Contiguous + ZerosLike + ViewCopy 流程,且不修改调用方 selfRef 的 dtype 描述;同时补充了 UT 用例并同步更新中英文文档。

主要改动

  • 扩展数据类型白名单: 在 DTYPE_SUPPORT_LIST 中追加 op::DataType::DT_UINT32 与 op::DataType::DT_UINT64,使参数检查阶段放行这两类输入。
  • 视图方式复用 ZerosLike 实现: 新增静态函数 ViewDataType,通过 SetDataType 修改视图的数据类型;当输入为 DT_UINT64/DT_UINT32 时,将其映射为 DT_INT64/DT_INT32 视图。
  • 核心流程改用视图张量: CheckParams、空 Tensor 提前返回判断、l0op::Contiguous 以及最终写回的 l0op::ViewCopy 均由入参 selfRef 改为使用构造出的 self(视图失败时返回 ACLNN_ERR_INNER_NULLPTR),保证类型转换只作用于视图。
  • 调整并新增单元测试: l2ZeroTest 中「不支持类型」用例的反例由 ACL_UINT32 改为 ACL_COMPLEX32,并新增 uint32、uint64 两条正常路径用例,校验 aclnnInplaceZero 返回 ACLNN_SUCCESS。
  • 文档同步: 按 PR 描述,math/zero_op/docs/aclnnInplaceZero.md 与 aclnnInplaceZero_en.md 的 Atlas A2/A3 支持数据类型列表中补充了 UINT32、UINT64。

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

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

代码审查

审查结论

问题清单(共 5 项:P2 × 1,P3 × 4)

# 优先级 置信度 位置 问题
1 P2 0.62 math/zero_op/op_api/aclnn_zero.cpp:112 selfRef->GetDataType() 在 CheckParams/CheckNotNull 之前解引用,null 入参由返回 ACLNN_ERR_PARAM_NULLPTR 退化为空指针崩溃
2 P3 0.50 math/zero_op/op_api/aclnn_zero.cpp:41 新增的 DT_UINT32/DT_UINT64 白名单项实际不可达(校验对象已被改写成 INT32/INT64 视图),且顺带绕过 DTYPE_SUPPORT_950_LIST/DTYPE_SUPPORT_960dt_LIST 的平台门禁,三份列表口径出现新分歧
3 P3 0.80 math/zero_op/op_api/aclnn_zero.cpp:99 ViewDataType 中 input = tmpTensor; 是对值传参的无效赋值;其空指针分支亦不可达且返回 void 无法报错
4 P3 0.30 math/zero_op/op_api/aclnn_zero.cpp:97-98 通过 const_cast 改写框架 CreateView 返回的 const 视图 dtype;由于传入的 shape/stride/offset 与 selfRef 完全一致,若 CreateView 短路返回入参自身,将污染调用方 dtype
5 P3 0.35 math/zero_op/tests/ut/op_api/test_aclnn_zero.cpp:92-114 新增 uint32/uint64 用例仅断言返回码,未覆盖“结果写回 selfRef 内存”与“selfRef dtype 保持 uint32/uint64”这两条核心不变量

逐文件复核确认

  • math/zero_op/op_api/aclnn_zero.cpp:已检视(5 项中 4 项在此文件)。类型映射 UINT64→INT64、UINT32→INT32 的位宽一致,CreateView 的 viewShape/storageShape/viewStrides/viewOffset 传参顺序与来源正确,空 tensor 早返回与 ViewCopy 目标改为视图的逻辑本身自洽。
  • math/zero_op/tests/ut/op_api/test_aclnn_zero.cpp:已检视;反例由 ACL_UINT32 改为 ACL_COMPLEX32 是必要的(UINT32 已转为支持),COMPLEX32 在三份 dtype 列表中均不存在,负向用例语义仍成立;问题见第 5 项。

说明:审查工具的执行范围被限制在这两个变更文件及其父目录,无法读取 opdev 头文件核对 aclOpExecutor::CreateView 的精确签名(按 PR 描述真机与 UT 均已编译通过),因此对第 4 项给予了较低置信度。

总体风险判断

方向正确、改动集中,但“先改类型视图、后做参数校验”的顺序带来一个真实的入参边界回归(P2,null 指针保护失效),且平台 dtype 白名单因此形同虚设,建议至少修掉第 1 项并明确第 2 项的平台策略后再合入;其余为可维护性与测试覆盖层面的可选改进。

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

💬 仅评论


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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
7 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
7 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
*/*/docs/acl*.md ✅ 汤平川, 蔡雯雯, 陈兴宇 (3/2) ✅ 蔡雯雯 (1/1)
math/zero_op ✅ 汤平川, 陈兴宇 (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

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

likedislike
75 messages are collapsed here。 See more
chenyifengCollaborators
7 days ago Comments:

您好,PR已满足合入指标,请尽快联系Committer进行合入。如暂时不需要合入,请在PR标题前加[WIP]

likedislike
caiwenwenCollaborators
7 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
7 days ago Added label: approved
CANN-robotCANN-robotCollaborators
7 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
7 days ago Merged pull request