Pull Request已成功合入, 合并人@CANN-robot
(感谢 梅国晗954517 的贡献)变更摘要
此 PR 为 StatelessNormal 和 StatelessTruncatedNormalV2 两个算子新增了 op_api 层 L0 单元测试和 op_host 层 InferShape 单元测试,共新增 3 个测试文件、868 行代码,无任何业务逻辑修改。StatelessNormal 的 op_api UT 覆盖标量与 Tensor 两种 seed/offset 重载接口及 float32/float16/bfloat16 三种 dtype;两个算子的 InferShape UT 分别验证了 CommonInferShape 在不同维度、dtype、const data 缺失以及非法输入下的形状推导行为。
主要改动
-
新增
StatelessNormalop_api L0 单元测试: 在test_aclnn_stateless_normal_l0.cpp中添加 10 个测试用例,覆盖标量接口 (StatelessNormal(result, seed, offset, mean, stdev, executor)) 和 Tensor 接口两个重载,验证 float32/float16/bfloat16 输出 dtype、多维 shape 保留、非零 seed/offset 路径等场景。 -
新增
StatelessNormalInferShape 单元测试: 在test_stateless_normal_infershape.cpp中添加 10 个测试用例,覆盖 1D/2D/4D 输出、含1维度、fp16/bf16 dtype、INT32/INT64 shape tensor 分支、const data 为空时的 unknown shape ({-1})、以及非法 shape dtype 导致GRAPH_FAILED等推导路径。 -
新增
StatelessTruncatedNormalV2InferShape 单元测试: 在test_stateless_truncated_normal_v2_infershape.cpp中添加 13 个测试用例,覆盖 1D~5D 输出、0 维标量输出、INT32/INT64 shape tensor、const data 缺失、非法 shape dtype 等场景,输入布局包含shape/key/counter/alg四个张量,与本算子的 op_def 和 tiling UT 保持一致。


代码审查
我已经完成了对所有三个变更文件的逐文件审查。以下是审查结果汇总:
审查汇总
| 文件 | 审查结果 |
|---|---|
random/stateless_normal/tests/ut/op_api/test_aclnn_stateless_normal_l0.cpp |
3 个问题(1 个 P2,2 个 P3) |
random/stateless_normal/tests/ut/op_host/test_stateless_normal_infershape.cpp |
无问题 |
random/stateless_truncated_normal_v2/tests/ut/op_host/test_stateless_truncated_normal_v2_infershape.cpp |
无问题 |
问题按优先级统计:
- P2:1 个 —
CreateAclTensor返回值未做空指针检查,可能导致空指针解引用崩溃 - P3:2 个 — aclTensor 资源泄漏、aclCreateTensor 传入 Host 侧地址代替 Device 侧地址(均为可选改进)
整体风险评估:低风险。 主要问题集中在 L0 op_api 测试文件的健壮性上(空指针检查和资源管理),两个 infer shape 测试文件结构规范、覆盖完整、无逻辑或正确性问题。三个文件均不涉及生产代码变更,不会引入运行时回归。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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 | ✅ xuejinghui, 宋恺 (2/2) | ✅ 宋恺, xuejinghui (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
gh_M, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [79de0365fb53428b8aa2f62b06fce2a2][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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 | ⚠️ WARNING | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-math | ✅ SUCCESS | ||
| UT_Test_harmony-infer-cpro-math | ✅ SUCCESS |
[2026-08-04 17:06:20] CI执行结束


流水线任务触发成功
任务链接 [63655eeceeec42c5af53a8dc47c7debf][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| 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-04 16:57:31] CI执行结束


🟡 Medium Priority
在 test_aclnn_stateless_normal_l0.cpp 中,CreateAclTensor 方法内部调用 aclCreateTensor,该方法可能返回 nullptr(例如资源不足时)。但所有 10 个测试用例在调用 CreateAclTensor 后均未对返回值做空指针检查,直接将返回值传给 l0op::StatelessNormal。若任一 CreateAclTensor 调用失败返回 nullptr,后续以 nullptr 作为 tensor 参数调用 StatelessNormal 会导致崩溃或未定义行为。
影响范围:文件内所有测试用例(line 78-80, 89-91, 100-102, 113-117, 126-130, 139-143, 154-156, 168-170, 179-181, 190-192),每个 case 有 3~5 个未检查的 CreateAclTensor 调用。
建议:在每个 CreateAclTensor 调用后添加 ASSERT_NE(xxx, nullptr) 检查,确保在 tensor 创建失败时测试尽早终止并给出明确诊断,而非在后续代码中空指针解引用崩溃。
|
80 | + auto result = CreateAclTensor({256}, ACL_FLOAT); |
|
81 | + ASSERT_NE(result, nullptr); |
|
82 | + auto mean = CreateAclTensor({256}, ACL_FLOAT); |
|
83 | + ASSERT_NE(mean, nullptr); |
| 80
| - auto stdev = CreateAclTensor({256}, ACL_FLOAT); |
|
84 | + auto stdev = CreateAclTensor({256}, ACL_FLOAT); |
|
85 | + ASSERT_NE(stdev, nullptr); |


/lgtm
/approve


/approve


描述
StatelessNormal算子 opapi/ophost UT 覆盖率不足;StatelessTruncatedNormalV2 算子缺少 ophost UT 用例
补充UT用例
关联的Issue
https://gitcode.com/cann/ops-math/issues/2506
测试
UT测试
文档更新
不涉及
类型标签