Pull Request已成功合入, 合并人@CANN-robot
(感谢 sikaiwei 的贡献)变更摘要
此 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前,对self、meanCasted、stdCasted三个张量逐一检查其 shape 是否与输出out一致,若不一致且该张量元素数大于 1,则通过l0op::BroadcastTo将其广播到输出 shape。 - 标量豁免处理: 广播条件中加入
Size() > 1判断,使得由标量转换而来的单元素张量(Size()==1)跳过广播,由 V3 kernel 原生标量路径处理。 self张量独立广播:self的广播在Cast之前单独进行,以保持其原始 dtype,避免广播过程中丢失 V3 kernel 所需的计算精度信息。- 变量重命名: 将
meanFP32/stdFP32重命名为meanCasted/stdCasted,使变量命名更清晰地表达"经过 cast 转换"的语义,而非固定暗示 FP32。


代码审查
审查总结
本次变更仅涉及 1 个文件:
random/stateless_random_normal_v2/op_api/aclnn_normal_out.cpp:在 V3 kernel 路径中新增了广播逻辑,将self、meanCasted、stdCasted三个张量在需要时广播到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 张量)一致。不存在逻辑错误、安全漏洞或可靠性问题。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


/approve


描述
aclnnNormalTensorTensor路径缺少广播功能,导致广播场景会报错,需要补充该功能场景
关联的Issue
https://gitcode.com/cann/ops-math/issues/2311
测试
冒烟已通过
文档更新
不涉及
类型标签