Pull Request已成功合入, 合并人@CANN-robot
(感谢 huairuchen 的贡献)变更摘要
此 PR 为 StatelessUniform 算子补充了两个单元测试文件,覆盖 L0 算子的 API 调用路径与 InferShape 逻辑。新增的 test_aclnn_stateless_uniform_l0.cpp 对 l0op::StatelessUniform 的标量重载(A)和 Tensor 重载(B)共 6 条 dtype 分支(fp16/bf16/float32)进行了验证,并附加了多维输入、负值区间、非零 seed、dtype 保持等场景。新增的 test_stateless_uniform_infershape.cpp 则针对 CommonInferShape 中的 HandleShapeTensor<int64_t> / HandleShapeTensor<int32_t> 分支、const data 缺失时的 unknown shape 回退、以及非法 shape dtype 导致的 GRAPH_FAILED 路径提供了覆盖。
主要改动
- 新增 L0 API 测试文件
test_aclnn_stateless_uniform_l0.cpp:通过StatelessUniformL0Test测试夹具分别验证标量接口与 Tensor 接口在ACL_FLOAT、ACL_FLOAT16、ACL_BF16三种输入 dtype 下的输出 dtype 正确性,并附加覆盖了多维 shape 保持、负值from/to区间、非零seed/offset和 dtype 不被静默提升等边界场景。 - 新增 InferShape 测试文件
test_stateless_uniform_infershape.cpp:通过StatelessUniformInferShapeTest测试类,使用InfershapeContextPara构造不同 rank 的 shape tensor(1D/2D/4D/含1维度),验证CommonInferShape逐维写入输出 shape 的正确性,同时覆盖了DT_INT32shape tensor 分支和DT_FLOAT非法 dtype 触发GRAPH_FAILED的路径。 - 覆盖 InferShape 的 unknown shape 回退路径:新增
case_null_const_1d和case_null_const_2d两个用例,模拟 shape tensor 的 const data 为nullptr时SetUnknownShape产生{-1}/{-1, -1}的输出 shape。


代码审查
审查总结
已审查全部 2 个变更文件:
random/stateless_uniform/tests/ut/op_api/test_aclnn_stateless_uniform_l0.cpp:发现 2 个问题(1 个 P2 资源泄漏,1 个 P3 可选改进)。random/stateless_uniform/tests/ut/op_host/test_stateless_uniform_infershape.cpp:发现 2 个问题(均为 P2,涉及 case 8/9 的 nullptr 路径未触发和缓冲区大小不匹配)。
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 3 |
| P3 | 1 |
总体风险评估:该变更新增了 StatelessUniform 算子的 L0 和 InferShape 单元测试,覆盖较全面。主要问题集中在:op_api 测试文件存在 aclTensor 资源泄漏(每个测试用例泄漏 1~4 个 tensor),以及 infershape 测试中两个 "null const data" 用例因使用空 vector 的 data() 而非 nullptr,未能可靠验证目标代码路径,且存在 shape 声明与缓冲区大小不一致的越界风险。除上述问题外,未发现安全漏洞、数据损坏或严重逻辑错误。建议在合入前修复 P2 问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 3 |
💬 仅评论


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
huairuchen, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/approve


描述
补充StatelessUniform的opapi和infershape的UT
关联的Issue
https://gitcode.com/cann/ops-math/issues/2489
测试
成功通过新增21个UT测试,同时已有的11个ophost和4个opkernel测试也同样测试通过。
文档更新
类型标签