已合并
aclnnNormalTensorTensor 增加v3路径广播功能 #4175
sikaiwei创建于 25 天前
aclnnNormalTensorTensor 增加v3路径广播功能 #4175
已合并
sikaiwei创建于 25 天前
sikaiwei成员
25 天前

描述

aclnnNormalTensorTensor路径缺少广播功能,导致广播场景会报错,需要补充该功能场景

关联的Issue

https://gitcode.com/cann/ops-math/issues/2311

测试

冒烟已通过

文档更新

不涉及

类型标签

  • Bug修复
  • 新特性
  • 性能优化
  • 文档更新
  • 其他,请描述:
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 sikaiwei 的贡献)
Ssikaiwei成员
25 天前 创建了 pull request,commit d09d335c
atomgit-bot
atomgit-bot
25 天前 评论:

变更摘要

此 PR 为 CommonLogicGeneralNormal 函数中 V3 kernel 调用路径新增了张量广播功能。由于 V3 kernel 本身不支持广播,当输入张量的 shape 与输出 out 的 shape 不一致时,需要显式调用 l0op::BroadcastTo 进行广播后再传入。同时,对 Size()==1 的标量张量做了豁免处理,因为 V3 kernel 的原生标量路径可直接处理此类输入。此外,将原有的临时变量 meanFP32/stdFP32 重命名为 meanCasted/stdCasted,并针对 self 张量单独广播以保留其原始 dtype,从而确保 V3 kernel 的计算精度不受影响。

主要改动

  • V3 kernel 广播逻辑新增: 在调用 l0op::StatelessRandomNormalV3 前,对 selfmeanCastedstdCasted 三个张量逐一检查其 shape 是否与输出 out 一致,若不一致且该张量元素数大于 1,则通过 l0op::BroadcastTo 将其广播到输出 shape。
  • 标量豁免处理: 广播条件中加入 Size() > 1 判断,使得由标量转换而来的单元素张量(Size()==1)跳过广播,由 V3 kernel 原生标量路径处理。
  • self 张量独立广播: self 的广播在 Cast 之前单独进行,以保持其原始 dtype,避免广播过程中丢失 V3 kernel 所需的计算精度信息。
  • 变量重命名: 将 meanFP32/stdFP32 重命名为 meanCasted/stdCasted,使变量命名更清晰地表达"经过 cast 转换"的语义,而非固定暗示 FP32。
likedislike
atomgit-bot
atomgit-bot
25 天前 评论:

代码审查

审查总结

本次变更仅涉及 1 个文件:

  • random/stateless_random_normal_v2/op_api/aclnn_normal_out.cpp:在 V3 kernel 路径中新增了广播逻辑,将 selfmeanCastedstdCasted 三个张量在需要时广播到 out 的输出形状,以弥补 V3 kernel 不支持原生广播的限制。逻辑分析表明广播条件判断正确(Size()==1 的标量交由 V3 原生标量路径处理,多元素张量显式广播),各边界情况均已覆盖。

发现的问题

优先级 数量
P0 0
P1 0
P2 0
P3 1
  • P3:第 243 行的 const_cast<aclTensor*>(selfBroadcast) 破坏了 const 正确性,属于代码库既有模式的延续,不构成运行时缺陷。

整体风险评估

低风险。新增的广播逻辑语义正确,与 V3 kernel tiling 侧的约束(不支持广播,仅支持 Size==1 标量或 Size==outputSize 张量)一致。不存在逻辑错误、安全漏洞或可靠性问题。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

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

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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-cann/ops-math wangrui_, 宋恺 (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

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

likedislike
CANN-robotCANN-robot成员
25 天前 将zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为评审人
此处折叠了6条事件消息 查看更多
Ssikaiwei成员
24 天前 update merge request[project id: 7649531, iid: 4175, commit_id: c7d371f96648bef10a2c6e3110bdcd06cad1be38] virtual merging success
sikaiwei成员
23 天前 评论:

compile

likedislike
Ssikaiwei成员
23 天前 update merge request[project id: 7649531, iid: 4175, commit_id: 4d50ab65db382b164c498d4bf411152c8159da55] virtual merging success
Ssikaiwei成员
23 天前 修改了pull request 的描述
CANN-robotCANN-robot成员
23 天前 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
23 天前 评论:

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

任务名称状态日志下载链接
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 >>>>>
UT_Test_harmony-infer-chs-math ✅ SUCCESS

[2026-07-24 10:00:24]    CI执行结束

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

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

任务名称状态日志下载链接
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-07-24 09:51:51]    CI执行结束

likedislike
CANN-robotCANN-robot成员
23 天前 添加了label:api-check-pass
CANN-robotCANN-robot成员
23 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
23 天前 添加了label:ci-pipeline-passed
Ssikaiwei成员
23 天前 修改了pull request 的描述
Ssikaiwei成员
23 天前 修改了pull request 的描述
RRuiWang_成员
23 天前 变更了标题
RuiWang_成员
23 天前 评论:

/lgtm

likedislike
Ssongkai111成员
23 天前 添加了 squash commit 备注:/approve
songkai111成员
23 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
23 天前 添加了label:lgtmapproved
CANN-robotCANN-robot成员
23 天前 关闭了关联的issue
CANN-robotCANN-robot成员
23 天前 合入了pull request