已合并
[CANNBot]ROIPooling算子支持Ascend950 #1244
m0_46386992创建于 8月6日
[CANNBot]ROIPooling算子支持Ascend950 #1244
已合并
m0_46386992创建于 8月6日
m0_46386992
m0_46386992
8月6日

算子简介

RoiPooling(Region of Interest Pooling)算子,用于目标检测任务中对 ROI 区域进行固定大小的最大值池化。

初始提交

新增 ROIPooling 算子,支持 Ascend950 SIMT 架构。

验证结果

  • TTK 黑盒通过率: 99.0% (203/205)
  • TTK 白盒通过率: 100%
  • TTK 网络用例通过率: 100%
  • golden numpy vs torchvision: max_diff=0.0
  • 本地编译: PASS
  • 二级冒烟通过
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 m0_46386992 的贡献)
m0_46386992m0_46386992
8月6日 创建了 pull request,commit 27bf3130
atomgit-bot
atomgit-bot
8月6日 评论:

变更摘要

本 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.hREG_OP 原型定义)及 roi_pooling_def.cppOpDef 配置,启用 DynamicRankSupportFlagDynamicShapeSupportFlag),构成从 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.cppValidateDtypeValidateShapeValidateAttr 使用 OP_LOGE_FOR_INVALID_DTYPES_WITH_REASONOP_LOGE_FOR_INVALID_SHAPEDIMOP_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 实现精度对齐。

likedislike
不准确?
atomgit-bot
atomgit-bot
8月6日 评论:

代码审查

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

💬 仅评论

likedislike
不准确?
CANN-robotCANN-robot成员
8月6日 添加了label:cann-cla/no
CANN-robot
CANN-robot成员
8月6日 评论:

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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
此处折叠了363条消息 查看更多
m0_46386992
m0_46386992
27 天前 评论:

@zhangzijie 帮忙加一下分

likedislike
rxtfeng成员
27 天前 评论:

/lgtm

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