Merged
新增CombinedNonMaxSuppression算子Ascend950实现 #1219
wuxiyuanAdd on Aug 4
新增CombinedNonMaxSuppression算子Ascend950实现 #1219
Merged
wuxiyuanAdd on Aug 4
wuxiyuan
wuxiyuanCollaborators
Aug 4

描述

CombinedNonMaxSuppression 对每个 batch、每个类别独立执行贪心非极大值抑制(NMS),再按置信度从高到低合并各类别候选框,是目标检测后处理的核心算子。
变更内容

  • 算子原型定义:新增 combined_non_max_suppression_proto.h,定义输入/输出及属性(pad_per_class、clip_boxes)
  • Host 侧实现:
  • combined_non_max_suppression_def.cpp:算子注册与定义
  • combined_non_max_suppression_infershape.cpp:输出 shape 推导与参数校验
  • Kernel 侧实现(arch35):
  • combined_non_max_suppression_simt.h:基于 SIMT 架构的核函数实现,支持 float32 boxes/scores
  • combined_non_max_suppression_tiling.cpp:Tiling 切分逻辑
  • combined_non_max_suppression_tiling_data.h:Tiling 数据结构定义
  • Tiling 简化 Key:新增 combined_non_max_suppression_simplified_key.ini
  • README 文档:补充产品支持情况、功能说明、参数说明、约束说明、调用说明
  • 单元测试:
  • test_combined_non_max_suppression_tiling.cpp:Tiling 逻辑测试
  • test_combined_non_max_suppression_infershape.cpp:Infershape 逻辑测试
  • test_geir_combined_non_max_suppression.cpp:GEIR 图模式调用测试
  • 测试资产:golden.py(基准计算)、inputs.py(测试输入生成)
  • 清理:移除 op_cv_proto_extend.h 中旧的原型声明

关联的Issue

https://gitcode.com/cann/ops-cv/issues/710

测试

已完成自验证

文档更新

新增了README.md文件

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wuxiyuan's contribution.)
wuxiyuanwuxiyuanCollaborators
Aug 4 Created pull request, commit faa94579
atomgit-bot
atomgit-bot
Aug 4 Comments:

变更摘要

本 PR 为 CombinedNonMaxSuppression 算子新增了 Ascend 950 平台的完整实现,包括算子定义、形状推断、Tiling 逻辑和 SIMT 内核。原有的算子注册从公共头文件 op_cv_proto_extend.h 中移除,迁移至专属的 combined_non_max_suppression_proto.h。内核采用双路径设计:当 numBoxes ≤ 4096 时使用 UB 热路径,大数据量场景回退到 GM 路径并通过预留的 SIMT 数据缓存加速。

主要改动

  • 算子注册重构: 从 common/inc/op_graph/op_cv_proto_extend.h 中移除了 CombinedNonMaxSuppression 的 REG_OP 注册(删除 52 行),并将其迁移到 image/combined_non_max_suppression/op_graph/combined_non_max_suppression_proto.h 中独立定义,归属于 ge 命名空间。

  • Ascend 950 算子定义与配置: 新增 combined_non_max_suppression_def.cpp,通过 OpDef 类声明六个输入和四个输出,启用动态 Shape 支持 (DynamicShapeSupportFlag(true)),并关联 Ascend 950 平台的 aicoreConfig 及简化键配置文件 combined_non_max_suppression_simplified_key.ini。

  • 形状推断与校验: 新增 combined_non_max_suppression_infershape.cpp,实现 InferShapeCombinedNonMaxSuppression 和 InferDataTypeCombinedNonMaxSuppression,校验 boxes/scores 维度关系,根据 pad_per_class 属性计算输出尺寸,并约束 maxPerClass 和 maxTotal 不超过 1000。

  • Tiling 与工作空间管理: 新增 combined_non_max_suppression_tiling.cpp,在 ValidateAndFill 中校验输入形状和标量参数,计算 selectedScores/selectedIndices/selectedCounts/suppressed 四段 workspace 偏移量,填充 CombinedNonMaxSuppressionTilingData 结构体,并根据 numBoxes 是否超过 4096 动态划分 UB 本地内存(小数据量预留 32KB SIMT 缓存,大数据量限制 TPipe 本地内存为 64KB)。

  • SIMT 内核实现: 新增 combined_non_max_suppression_simt.h(595 行),包含 CombinedNonMaxSuppressionKernel 类和多个 SIMT VF 函数:LoadTaskHotData 负责 GM→UB 数据搬移,SelectClassNmsUb/SelectClassNms 分别实现 UB 热路径和 GM 回退路径的逐类 NMS 迭代与并行归约,MergeBatchResults 实现跨类结果归并、坐标裁剪与输出填充;同时定义 CombinedNonMaxSuppressionTilingData 结构体用于 Host-Kernel 数据传递。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 4 Comments:

代码审查

审查总结

对所有 16 个变更文件逐一审查完毕,发现 2 个 P2 级问题,无 P0/P1 严重问题。

各文件审查结果

文件 结果
common/inc/op_graph/op_cv_proto_extend.h 仅删除旧算子注册,无问题
image/combined_non_max_suppression/CMakeLists.txt 无问题
image/combined_non_max_suppression/README.md 无问题
image/combined_non_max_suppression/op_graph/combined_non_max_suppression_proto.h 无问题(与旧定义一致)
image/combined_non_max_suppression/op_host/arch35/combined_non_max_suppression_tiling.cpp 1 P2:缺少 batch×numClasses 乘积校验
image/combined_non_max_suppression/op_host/combined_non_max_suppression_def.cpp 无问题
image/combined_non_max_suppression/op_host/combined_non_max_suppression_infershape.cpp 无问题
image/combined_non_max_suppression/op_host/config/ascend950/combined_non_max_suppression_simplified_key.ini 无问题
image/combined_non_max_suppression/op_kernel/arch35/combined_non_max_suppression_simt.h 1 P2:kernel 侧 taskCount int32 乘法溢出
image/combined_non_max_suppression/op_kernel/arch35/combined_non_max_suppression_tiling_data.h 无问题
image/combined_non_max_suppression/op_kernel/combined_non_max_suppression.cpp 无问题
image/combined_non_max_suppression/tests/CMakeLists.txt 无问题
image/combined_non_max_suppression/tests/ut/CMakeLists.txt 无问题
image/combined_non_max_suppression/tests/ut/op_host/CMakeLists.txt 无问题
image/combined_non_max_suppression/tests/ut/op_host/arch35/test_combined_non_max_suppression_tiling.cpp 无问题
image/combined_non_max_suppression/tests/ut/op_host/test_combined_non_max_suppression_infershape.cpp 无问题

发现数统计

  • P0: 0
  • P1: 0
  • P2: 2(均为 int32 溢出相关,tiling 侧缺乘积校验 + kernel 侧乘法未提升)
  • P3: 0

整体风险评估

中等偏低。两个发现均围绕同一根本原因:batchSize × numClasses 在极端输入下可能发生 int32 有符号溢出。在当前 NPU 64GB 显存约束下实际无法触发(batch 无法接近 INT32_MAX),但作为算子代码应遵循 Ascend C 规范的防溢出保护要求。其他方面——输入验证、内存布局、核间同步(SyncAll)、事件同步(SetFlag/WaitFlag 模式与现有算子一致)、属性获取(使用 GetAttrs 而非 CompileInfo)、数据依赖声明等均正确。

类型 数量
🔴 阻塞 0
🟡 建议 3

💬 仅评论

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 4 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 4 Comments:

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
*/*/README.md ✅ 刘伟, 陈娇, 汤平川 (3/2) ✅ 陈娇 (1/1)
*/*/op_graph/*_proto.h ✅ 王永光, 汤平川, 刘伟 (3/2) ✅ 王永光 (1/1)
*/*/op_graph/*_proto_extend.h ✅ 王永光, 汤平川, 刘伟 (3/2) ✅ 王永光 (1/1)
*/*/op_host/*_def.cpp ✅ 王永光, 汤平川, 刘伟 (3/2) ✅ 王永光 (1/1)
repo-cann/ops-cv ✅ 汤平川, 刘伟 (2/2) ✅ 汤平川, 刘伟 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

wuxiyuan, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
86 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 7 Added label: approved
liu-wei
liu-weiCollaborators
Aug 7 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 7 Added label: lgtm
CANN-robotCANN-robotCollaborators
Aug 7 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 7 Merged pull request