Pull Request已成功合入, 合并人@CANN-robot
(感谢 m0_46386992 的贡献)变更摘要
本 PR 为 Ascend950 平台新增 RoiPooling 算子完整实现,涵盖 API 层、图编译层、Host 层(infershape/tiling)及 SIMT Kernel 层的全部代码。同时针对 CodeReview 反馈进行了多项修复:infershape 中增加 IsUnknownRank 动态 rank 保护、tiling 中将 OP_LOGE 替换为 OP_LOGE_FOR_INVALID_* 系列宏并删除历史 K/N 上限、修复 unused parameter 编译警告。附带新增 examples、单元测试及 golden 脚本。
主要改动
-
新增算子完整调用链: 添加
aclnn_roi_pooling.cpp/h(对外接口,含参数校验与Contiguous/ViewCopy调度)、roi_pooling.cpp/h(L0 层RoiPooling函数,内部调用RoiPoolingAiCore注册到ADD_TO_LAUNCHER_LIST_AICORE)、roi_pooling_proto.h(REG_OP原型定义)及roi_pooling_def.cpp(OpDef配置,启用DynamicRankSupportFlag与DynamicShapeSupportFlag),构成从 API 到 Host 再到 Kernel 的完整算子注册与调度路径。 -
Infershape 动态 rank 保护:
roi_pooling_infershape.cpp中在维度校验前调用Ops::Base::IsUnknownRank判断输入 shape,若为 unknown rank 则跳过 4D/2D 维度检查,并将输出 dim 设为ge::UNKNOWN_DIM,避免图模式下 dynamic rank 场景的误报失败。 -
Tiling 校验与日志宏规范化:
roi_pooling_tiling_arch35.cpp中ValidateDtype、ValidateShape、ValidateAttr使用OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON、OP_LOGE_FOR_INVALID_SHAPEDIM、OP_LOGE_FOR_INVALID_VALUE_WITH_REASON等封装宏替代原始OP_LOGE,并删除对 K≤6000/N≤1024 的历史硬限制,与 torchvision 行为对齐。 -
SIMT Kernel 实现:
roi_pooling_simt.h使用 Grid-Stride 模式(THREAD_NUM=512)实现ProcessOneOutputElement,直接访问 GM 完成 ROI 坐标映射(含 +1 偏移、malformed roi 强制非空、bin 边界 floor/ceil + clip、float 域 max 比较),并通过Process模板函数按DTYPE_X自动实例化 float/float16 两路。 -
Golden 脚本与双路径精度对齐:
golden.py实现等比缩放(spatial_scale_h == spatial_scale_w)优先调用torchvision.ops.roi_pool、非等比缩放走 numpy 兜底的策略,两路径均含 +1 偏移与 malformed roi 强制非空逻辑,确保与 Ascend Kernel 实现精度对齐。


代码审查
All 26 files have been reviewed. Here is my closing summary:
审查总结
发现的问题
| 优先级 | 数量 | 说明 |
|---|---|---|
| P0 | 0 | 无 |
| P1 | 0 | 无 |
| P2 | 2 | int32 溢出导致 stride 计算错误(kernel);GenOnesData 中字节数误用为数组大小(示例代码) |
| P3 | 2 | 宏参数拼写错误(intput→input);未使用的死代码变量 |
各文件审查结果
| 文件 | 结果 |
|---|---|
objdetect/roi_pooling/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/examples/test_aclnn_roi_pooling.cpp |
无问题 |
objdetect/roi_pooling/examples/test_geir_roi_pooling.cpp |
P2: GenOnesData 过度分配; P3: 宏拼写 intput |
objdetect/roi_pooling/op_api/aclnn_roi_pooling.cpp |
无问题 |
objdetect/roi_pooling/op_api/aclnn_roi_pooling.h |
无问题 |
objdetect/roi_pooling/op_api/roi_pooling.cpp |
无问题 |
objdetect/roi_pooling/op_api/roi_pooling.h |
无问题 |
objdetect/roi_pooling/op_graph/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/op_graph/roi_pooling_graph_infer.cpp |
无问题 |
objdetect/roi_pooling/op_graph/roi_pooling_proto.h |
无问题 |
objdetect/roi_pooling/op_host/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/op_host/roi_pooling_def.cpp |
无问题 |
objdetect/roi_pooling/op_host/roi_pooling_infershape.cpp |
无问题 |
objdetect/roi_pooling/op_host/roi_pooling_tiling_arch35.cpp |
无问题 |
objdetect/roi_pooling/op_kernel/arch35/roi_pooling_simt.h |
P2: strideC/strideN int32 溢出 |
objdetect/roi_pooling/op_kernel/arch35/roi_pooling_tiling_data.h |
无问题 |
objdetect/roi_pooling/op_kernel/arch35/roi_pooling_tiling_key.h |
无问题 |
objdetect/roi_pooling/op_kernel/roi_pooling_apt.cpp |
无问题 |
objdetect/roi_pooling/tests/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/tests/assets/golden.py |
无问题 |
objdetect/roi_pooling/tests/ut/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/tests/ut/op_api/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/tests/ut/op_api/test_aclnn_roi_pooling.cpp |
无问题 |
objdetect/roi_pooling/tests/ut/op_host/CMakeLists.txt |
无问题 |
objdetect/roi_pooling/tests/ut/op_host/arch35/test_roi_pooling_tiling.cpp |
P3: 未使用变量 soc_version_infos |
objdetect/roi_pooling/tests/ut/op_host/test_roi_pooling_infershape.cpp |
无问题 |
总体风险评估:低风险
核心算子逻辑(tiling、kernel、infershape、ACLNN 接口)实现正确,参数校验完整。唯一的 P2 问题(stride 溢出)需要极端大尺寸输入才能触发,且修复简单。示例代码中的过度分配不影响生产运行。可以合入,建议修复 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.
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 |
|---|---|---|
| */*/README.md | ✅ 陈娇, 刘伟, 冯彤 (3/2) | ✅ 陈娇 (1/1) |
| */*/op_graph/*_proto.h | ✅ 汤磊, 刘伟, 冯彤 (3/2) | ✅ 汤磊 (1/1) |
| */*/op_host/*_def.cpp | ✅ 汤磊, 刘伟, 冯彤 (3/2) | ✅ 汤磊 (1/1) |
| repo-cann/ops-cv | ✅ 刘伟, 冯彤 (2/2) | ✅ 刘伟 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
m0_46386992, thanks for your pull request. All authors of the commits have signed the CLA. 👍


@zhangzijie 帮忙加一下分


算子简介
RoiPooling(Region of Interest Pooling)算子,用于目标检测任务中对 ROI 区域进行固定大小的最大值池化。
初始提交
新增 ROIPooling 算子,支持 Ascend950 SIMT 架构。
验证结果