Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhangyiyi 的贡献)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 | ✅ 陈娇, zhangzijie, 周奇龙 (3/2) | ✅ 陈娇 (1/1) |
| */*/op_graph/*_proto.h | ✅ 汤磊, 周奇龙, zhangzijie (3/2) | ✅ 汤磊 (1/1) |
| */*/op_host/*_def.cpp | ✅ zhangzijie, 周奇龙, 汤磊 (3/2) | ✅ 汤磊 (1/1) |
| repo-cann/ops-cv | ✅ zhangzijie, 周奇龙 (2/2) | ✅ zhangzijie, 周奇龙 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ugzhangyiyi, thanks for your pull request. All authors of the commits have signed the CLA. 👍


变更摘要
本 PR 为 Ascend 950(arch35)平台新增 BoundingBoxEncode 算子支持。该算子计算锚框与真实边界框之间的编码偏移量,用于目标检测的回归目标生成。整体实现遵循 CANN 算子开发规范,涵盖 IR 原型定义、OpDef 注册、InferShape、Tiling 策略以及 AICore 内核四个层次,支持 FP16/FP32/BF16 三种数据类型,并启用动态编译、动态 Rank 和动态 Shape 特性。
主要改动
-
新增 IR 原型定义:在
bounding_box_encode_proto.h中通过REG_OP注册BoundingBoxEncode算子,声明anchor_box和ground_truth_box两个输入、delats一个输出,以及means和stds两个ListFloat属性(默认值分别为{0,0,0,0}和{1,1,1,1}),支持 FP16/FP32/BF16。 -
新增 OpDef 注册与 AICore 配置:在
bounding_box_encode_def.cpp中实现BoundingBoxEncode的 OpDef 类,明确输入输出的数据类型、格式(FORMAT_ND)及AutoContiguous策略;为ascend950配置DynamicCompileStatic、DynamicRankSupport、DynamicShapeSupport等特性,并关联内核文件bounding_box_encode_apt。 -
新增 Tiling 策略:在
bounding_box_encode_tiling_arch35.cpp中实现BoundingBoxEncodeTilingFunc,根据输入数据量、UB 大小和多核数量动态计算分块因子(blockFactor/ubFactor),从属性中读取means/stds并预计算其倒数(invStds)写入BoundingBoxEncodeTilingData,完成多核调度配置。 -
新增 AICore 内核实现:在
bounding_box_encode.h中实现BoundingBoxEncode<T>模板类,包含CopyIn/Compute/CopyOut/Process四个核心方法,使用 AscendC 的DataCopyExtParams避免大数据拷贝时的截断问题;Compute中完成编码公式计算(含 +1 偏移、对数运算及(delta - mean) / std归一化);通过bounding_box_encode_apt.cpp作为内核入口将模板实例化。 -
新增 Tiling 数据结构与类型分发:在
bounding_box_encode_tiling_data.h中定义 tiling 数据结构(含维度、分块因子、means 和 invStds);在bounding_box_encode_tiling_key.h中通过ASCENDC_TPL_ARGS_DECL声明 FP32/FP16/BF16 三种类型的模板参数分发。 -
新增 InferShape 与测试用例:
bounding_box_encode_infershape.cpp中将输出 shape 直接透传为输入anchor_box的 shape。同时提供了 aclnn 和 GEIR 两种推理方式的示例测试代码(通用版和 arch35 专版共 4 个文件)。


/lgtm


/approve


描述
本 MR 支持
bounding_box_encode算子,适配 Ascend 950(arch35)平台。算子功能
计算锚框(anchor box)与真实边界框(ground truth box)之间的编码偏移量,生成目标检测回归目标。计算公式(含 +1 偏移,与 canndev 内置定义一致):
代码结构(commit dabe4550)
bounding_box_encode_proto.hnn_detect_ops.h内置定义保持一致bounding_box_encode_def.cppbounding_box_encode_infershape.cpparch35/bounding_box_encode_tiling_arch35.cppattrs->GetListFloat(0/1)读取 means/stds 属性,计算 invStds 写入 TilingData;UB 容量感知的 ubFactor 计算 + MAX_DATACOPY_BLOCKLEN(65535) 双重约束防 blockLen 截断arch35/bounding_box_encode.harch35/bounding_box_encode_tiling_data.hbounding_box_encode_apt.cpptest_geir_bounding_box_encode.cppCMakeLists.txtREADME.mddocs/zh/op_list.md接口定义(与 canndev 一致)
// IR 原型(与 canndev nn_detect_ops.h 一致) REG_OP(BoundingBoxEncode) .INPUT(anchor_box, TensorType({DT_FLOAT16, DT_FLOAT})) .INPUT(ground_truth_box, TensorType({DT_FLOAT16, DT_FLOAT})) .OUTPUT(delats, TensorType({DT_FLOAT16, DT_FLOAT})) .ATTR(means, ListFloat, {0.0, 0.0, 0.0, 0.0}) .ATTR(stds, ListFloat, {1.0, 1.0, 1.0, 1.0}) .OP_END_FACTORY_REG(BoundingBoxEncode)关键设计决策
pw = px2 - px1 + 1,与 canndev tbe 实现一致,保证宽高至少为 1关联的Issue
https://gitcode.com/cann/ops-cv/issues/583
测试
bash build.sh -u --ops=bounding_box_encode --soc=ascend950 --noexec,全部 target 编译通过(cv_op_host_ut / cv_op_api_ut / cv_op_kernel_ut)test_geir_bounding_box_encode.cpp执行Session run ir compute graph success+Precision is ok文档更新
objdetect/bounding_box_encode/README.md:算子说明文档docs/zh/op_list.md:添加 bounding_box_encode 条目类型标签
重点说明
为了对齐原cann版本tbe接口,其拼写错误
delats不进行修复,保持与原版一致。