Merged
CombinedNMS 支持 FP16、统一参数值域并补充约束说明 #1627
wuxiyuanAdd on Sep 16
CombinedNMS 支持 FP16、统一参数值域并补充约束说明 #1627
Merged
wuxiyuanAdd on Sep 16
wuxiyuan
wuxiyuanCollaborators
Sep 16

描述

CombinedNonMaxSuppression 对每个 batch、每个类别独立执行贪心非极大值抑制(NMS),再按置信度从高到低合并各类别候选框,是目标检测后处理的核心算子。本 PR 在 Ascend 950 已有实现基础上支持 FP16 数据类型,统一 iouThreshold 参数值域,并放开 num_boxes 上限限制。

变更内容

  • FP16 数据类型支持:
    • combined_non_max_suppression_def.cpp:boxes/scores 输入及 nmsed_boxes/nmsed_scores/nmsed_classes 输出的 DataType 新增 DT_FLOAT16
    • combined_non_max_suppression_simt.h:CalcIou、LoadTaskHotData、SelectClassNms、MergeBatchResults 及 CombinedNonMaxSuppressionKernel 模板化为类型参数 T
    • combined_non_max_suppression.cpp:按 DTYPE_BOXES 实例化 kernel,输出缓冲与拷贝长度改用 sizeof(T)
  • 统一 iouThreshold 值域:tiling 校验由 [0, 1] 放宽为有限非负值(接受大于 1 的阈值,拒绝负数、NaN 与无穷),测试输入钩子 inputs.py 同步更新
  • 放开 num_boxes 限制:移除 MAX_NUM_BOXES = 200000 上限校验,改为校验 numBoxes 不超过 int32 最大值、boxes 元素总数不超过 int64 范围
  • suppressed 掩码写回优化:GM 上按 512 字节对齐(新增 CNMS_GM_ALIGN_BYTES),SelectClassNms 输出改为先写 UB、再经 MTE3 精确字节写回 GM,避免多核缓存行互相覆盖
  • 流程合并:ProcessHotUbTask 重命名为 ProcessClassTask,统一热数据 UB 路径与大数据量 SIMT 缓存路径的分发入口
  • Tiling 注册:由 InputsDataDependency 改为 TilingInputsDataDependency,兼容旧版本等价声明
  • 测试更新:golden 脚本按输入 dtype 生成输出,测试用例覆盖大 num_boxes 与新 iouThreshold 值域场景

关联的Issue

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

测试

已完成自验证

文档更新

更新了README.md文件(补充 FP16 数据类型支持及 iouThreshold 值域、num_boxes 约束变更说明)

类型标签

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

变更摘要

该 PR 为 CombinedNMS 算子增加 FP16 支持,统一 iou_threshold 参数值域(由 [0, 1] 放宽为「有限且非负」),移除 num_boxes 的 200000 硬上限并改为 int32/int64 范围校验,同时将每核抑制掩码工作区按 512 字节 GM 对齐以隔离多核缓存写入,并同步更新了单测与 golden 参考实现。

主要改动

  • 算子支持 FP16 输入输出:combined_non_max_suppression_def.cpp 中 boxes、scores 输入及 nmsed_boxes、nmsed_scores、nmsed_classes 输出的 DataType 增加 DT_FLOAT16;combined_non_max_suppression_simt.h 将 CombinedNonMaxSuppressionKernel 及 CalcIou、LoadTaskHotData、SelectClassNms、MergeBatchResults 等改造为 template <typename T>,UB 缓冲区按 sizeof(T) 分配,入口 combined_non_max_suppression.cpp 以 DTYPE_BOXES 实例化内核。
  • 统一 iou_threshold 参数值域:tiling 校验由 [0, 1] 区间改为「有限且非负」(!std::isfinite(iouThreshold) || iouThreshold < 0.0F),tests/assets/inputs.py 同步放宽,并新增「接受有限非负值」「拒绝负值/非有限值」两组单测。
  • 移除 num_boxes 上限并补充范围约束:删除 MAX_NUM_BOXES = 200000 常量及对应校验,改为校验 numBoxes 不超过 int32 最大值、boxes 元素总数不超 int64 范围(combined_non_max_suppression_tiling.cpp 与 combined_non_max_suppression_infershape.cpp),并新增接受 200000 以上 box 数量、拒绝超出 int32 范围的单测。
  • 抑制掩码工作区按 512 字节对齐:新增 CNMS_GM_ALIGN_BYTES = 512,suppressedOffset 及每核 suppressed 步长按该值对齐;同时 SelectClassNms 的结果(selectedScores、selectedIndices、selectedCounts)由直写 GM 改为先写 UB 再经 MTE3 精确写回,避免多核 SIMT 缓存行互相覆盖。
  • 测试与参考实现同步:tests/assets/golden.py 的输出数组 dtype 改为跟随输入 boxes 的 dtype,以匹配 FP16 支持;tiling 单测同步更新工作区偏移/大小断言(如 suppressedOffset 由 160 变为 512)。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 16 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 16 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 16 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.
You can self-configure the PR merge rules for this repository. For more details, please refer to 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_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)
likedislike
CANN-robot
CANN-robotCollaborators
Sep 16 Comments:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Set yue-ma,zhou-qilong,gitee-duhuiping,rxtfeng,loov1,tang-lei01,zhangzijie,yourealize,zl_hw,liu-wei,gitcode-chenjiao,pingchuantang,llimwang,gubaocheng,wangyongguang,fengying555682,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
Sep 16 Set yue-ma,zhou-qilong,gitee-duhuiping,rxtfeng,loov1,tang-lei01,zhangzijie,yourealize,zl_hw,liu-wei,gitcode-chenjiao,pingchuantang,llimwang,gubaocheng,wangyongguang,fengying555682,caiwenwen,yanglu-1 as approver
wuxiyuanwuxiyuanCollaborators
Sep 16 Modify description of pull request
wuxiyuan
wuxiyuanCollaborators
Sep 16 Comments:

compile

likedislike
wuxiyuanwuxiyuanCollaborators
Sep 16 Pre merge succeeded (commit_id: 8a28d01e4b627449ac30f18b63e49862ceb43992)
CANN-robot
CANN-robotCollaborators
Sep 16 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 16 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 16 Added label: ci-pipeline-passed
wangyongguang
wangyongguangCollaboratorsSep 16Start code review2
image/combined_non_max_suppression/op_host/combined_non_max_suppression_def.cpp
@@ -21,3 +21,1 @@
21- .DataType({ge::DT_FLOAT})
22- .Format({ge::FORMAT_ND})
23- .UnknownShapeFormat({ge::FORMAT_ND})
21+ .DataType({ge::DT_FLOAT16, ge::DT_FLOAT})
wangyongguang
wangyongguangSep 16Comments:

【P0 跨文件一致性】此处为 boxes 新增 DT_FLOAT16,但算子原型 IR op_graph/combined_non_max_suppression_proto.h 的 REG_OP 仍声明 .INPUT(boxes, TensorType({DT_FLOAT})) 单一 dtype,未同步 FP16;scores / nmsed_boxes / nmsed_scores / nmsed_classes 同理。proto 是 GE 图编译契约,FP16 输入会被 proto 拒绝,def 声明的 FP16 无法生效。请同步在 proto 的 REG_OP 中为 boxes/scores/nmsed_boxes/nmsed_scores/nmsed_classes 补充 DT_FLOAT16(如 TensorType({DT_FLOAT16, DT_FLOAT}))。

likedislike
wuxiyuan
wuxiyuanCollaborators
Sep 16 Comments:

【P0 跨文件一致性】此处为 boxes 新增 DT_FLOAT16,但算子原型 IR op_graph/combined_non_max_suppression_proto.h 的 REG_OP 仍声明 .INPUT(boxes, TensorType({DT_FLOAT})) 单一 dtype,未同步 FP16;scores / nmsed_boxes / nmsed_scores / nmsed_classes 同理。proto 是 GE 图编译契约,FP16 输入会被 proto 拒绝,def 声明的 FP16 无法生效。请同步在 proto 的 REG_OP 中为 boxes/scores/nmsed_boxes/nmsed_scores/nmsed_classes 补充 DT_FLOAT16(如 TensorType({DT_FLOAT16, DT_FLOAT}))。

@wangyongguang

图模式保持和旧版本一致,不支持FP16

likedislike
wangyongguang
wangyongguangCollaborators
Sep 16 Comments:

/approve

likedislike
黄晓彬黄晓彬Collaborators
Sep 16 Resolved final issue
chenjiao
chenjiaoCollaborators
Sep 16 Comments:

/approve

likedislike
liu-wei
liu-weiCollaborators
Sep 16 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: approved
wuxiyuan
wuxiyuanCollaborators
Sep 16 Comments:
likedislike
rxtfeng
rxtfengCollaborators
Sep 16 Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 16 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 16 Merged pull request