Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
ops-cv 仓编包时,scripts/util/merge_proto.py 会将各算子 op_graph/*_proto.h 中的 REG_OP 定义提取合并生成 ops_proto_cv.h(安装至 opp/built-in/op_graph/inc/)。
当前版本的 merge_proto.py 在提取时使用 match.group("opdef"),只输出裸的 REG_OP(...) ... OP_END_FACTORY_REG(...) 本体,源文件中包裹的 #ifndef OPS_PROTO_DEF_XXX / #define / #endif 宏守卫虽然被正则匹配到,但在输出时被丢弃。
导致编包产物 ops_proto_cv.h 中所有算子的 REG_OP 定义均不带 OPS_PROTO_DEF_* 守卫。 当 ops_proto_cv.h 与 canndev 仓 ops/built-in/op_proto/inc/ops_proto_legacy.h (或各算子原始 *_proto.h)被包含进同一编译单元时,同名算子的 REG_OP 会出现两次, 造成 OP_END_FACTORY_REG 重复注册。
作为对比,ops-math 仓的同名脚本使用 match.group(0) 输出完整匹配(含守卫), 其编包产物 ops_proto_math.h 中守卫宏原样保留,不存在该问题。
cann-9.2.0 Ascend 950
根因定位:scripts/util/merge_proto.py 与 ops-math 仓同名脚本的唯一差异
ops-cv(问题版本):
L23-24: r"(?P<opdef>REG_OP\((?P<opname>.+?)\)" r".*?OP_END_FACTORY_REG\((?P=opname)\))" L38: op_def = match.group("opdef") # 只取裸本体,守卫被丢弃 L54: op_def = match.group("opdef")
ops-math(正确版本):
L38: op_def = match.group(0) # 取完整匹配,含守卫和#endif L54: op_def = match.group(0)
修复验证(修复后重新运行 merge_proto.py):
$ grep -n "OPS_PROTO_DEF_CROP" build/tbe/graph/ops_proto_cv.h 30:#ifndef OPS_PROTO_DEF_CROP 31:#define OPS_PROTO_DEF_CROP ... .OP_END_FACTORY_REG(Crop) #endif # 守卫及 #endif 完整保留
修复提交:fix_build 分支 73874a06 "fix: merge_proto合并时保留OPS_PROTO_DEF宏守卫,与ops-math对齐" (scripts/util/merge_proto.py,2 处 match.group("opdef") -> match.group(0))
全仓共 10 个头文件带 OPS_PROTO_DEF_* 守卫(如 crop/yolo/d_io_u_grad/g_io_u_grad/ stack_group_points/points_in_polygons/extract_glimpse_v2/paste_sub_img/ anchor_response_flags 的 *_proto.h 及 op_cv_proto_extend.h 的 Dilation2D), 均受本问题影响。修复改动仅 2 行,与 ops-math 仓实现对齐,无其他行为变化。
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Describe the current behavior / 问题描述 (Mandatory / 必填)
ops-cv 仓编包时,scripts/util/merge_proto.py 会将各算子 op_graph/*_proto.h 中的
REG_OP 定义提取合并生成 ops_proto_cv.h(安装至 opp/built-in/op_graph/inc/)。
当前版本的 merge_proto.py 在提取时使用 match.group("opdef"),只输出裸的
REG_OP(...) ... OP_END_FACTORY_REG(...) 本体,源文件中包裹的
#ifndef OPS_PROTO_DEF_XXX / #define / #endif 宏守卫虽然被正则匹配到,但在输出时被丢弃。
导致编包产物 ops_proto_cv.h 中所有算子的 REG_OP 定义均不带 OPS_PROTO_DEF_* 守卫。
当 ops_proto_cv.h 与 canndev 仓 ops/built-in/op_proto/inc/ops_proto_legacy.h
(或各算子原始 *_proto.h)被包含进同一编译单元时,同名算子的 REG_OP 会出现两次,
造成 OP_END_FACTORY_REG 重复注册。
作为对比,ops-math 仓的同名脚本使用 match.group(0) 输出完整匹配(含守卫),
其编包产物 ops_proto_math.h 中守卫宏原样保留,不存在该问题。
Environment / 环境信息 (Mandatory / 必填)
cann-9.2.0
Ascend 950
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
bash build.sh --package
vi build/tbe/graph/ops_proto_cv.h
(或安装后查看 opp/built-in/op_graph/inc/ops_proto_cv.h)
#ifndef OPS_PROTO_DEF_CROP / #define / #endif 包裹的 REG_OP(Crop),
在合并产物中仅剩裸 REG_OP 定义,守卫宏全部丢失;
common/inc/op_graph/op_cv_proto_extend.h 中 OPS_PROTO_DEF_DILATION2D 同样丢失。
#ifndef OPS_PROTO_DEF_SPARSEBINCOUNT 等守卫均原样保留。
Describe the expected behavior / 预期结果 (Mandatory / 必填)
bash build.sh --package
vi build/tbe/graph/ops_proto_cv.h
(或安装后查看 opp/built-in/op_graph/inc/ops_proto_cv.h)
#ifndef OPS_PROTO_DEF_CROP / #define / #endif 包裹的 REG_OP(Crop),
在合并产物中仅剩裸 REG_OP 定义,守卫宏全部丢失;
common/inc/op_graph/op_cv_proto_extend.h 中 OPS_PROTO_DEF_DILATION2D 同样丢失。
#ifndef OPS_PROTO_DEF_SPARSEBINCOUNT 等守卫均原样保留。
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
根因定位:scripts/util/merge_proto.py 与 ops-math 仓同名脚本的唯一差异
ops-cv(问题版本):
ops-math(正确版本):
修复验证(修复后重新运行 merge_proto.py):
修复提交:fix_build 分支 73874a06
"fix: merge_proto合并时保留OPS_PROTO_DEF宏守卫,与ops-math对齐"
(scripts/util/merge_proto.py,2 处 match.group("opdef") -> match.group(0))
Special notes for this issue/备注 (Optional / 选填)
全仓共 10 个头文件带 OPS_PROTO_DEF_* 守卫(如 crop/yolo/d_io_u_grad/g_io_u_grad/
stack_group_points/points_in_polygons/extract_glimpse_v2/paste_sub_img/
anchor_response_flags 的 *_proto.h 及 op_cv_proto_extend.h 的 Dilation2D),
均受本问题影响。修复改动仅 2 行,与 ops-math 仓实现对齐,无其他行为变化。