Pull Request已成功合入, 合并人@CANN-robot
(感谢 zl_hw 的贡献)变更摘要
本 PR 针对 op_graph 模块下 8 个算子原型头文件(如 add_v2_proto.h、fused_mul_add_proto.h、mul_no_nan_proto.h、ragged_bin_count_proto.h 等),为每个 REG_OP(...) ... OP_END_FACTORY_REG(...) 算子注册块补上 OPS_PROTO_DEF_<OPNAME> 隔离宏(#ifndef / #define / #endif),仅新增宏包围代码、无删除行,用于防止头文件被重复包含时算子被重复注册。
主要改动
- 为 7 个算子原型添加隔离宏:在
AddV2、MulNoNan、CumulativeLogsumexp、FusedMulAdd、FusedMulAddAdd、FusedMulAddNL2loss的REG_OP注册块前后分别添加#ifndef OPS_PROTO_DEF_XXX/#define OPS_PROTO_DEF_XXX与#endif,使算子注册逻辑具备防重复包含保护。 RaggedBinCount采用嵌套宏隔离:因文件名使用下划线形式(ragged_bin_count),在既有OPS_PROTO_DEF_RAGGED_BIN_COUNT宏内部新增配套的OPS_PROTO_DEF_RAGGEDBINCOUNT宏包裹REG_OP(RaggedBinCount)注册块,避免重复注册。- 改动范围与影响:覆盖
experimental/math与math目录下的 8 个算子原型头文件,全部为纯新增宏定义语句,不影响各算子原有的输入/输出/属性定义及注册逻辑。


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 |
|---|---|---|
| */*/op_graph/*_proto.h | ✅ 王永光, 汤平川 (2/2) | ✅ 王永光 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
zl_hw, thanks for your pull request. All authors of the commits have signed the CLA. 👍


流水线任务触发成功
任务链接 [a8d1c2de2a584353b4cc8b398ef4e547][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ⚠️ WARNING | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-08-25 21:14:14] CI执行结束


流水线任务触发成功
任务链接 [3d28734e533e450aa60b7ad155134f82][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| StaticCheck_md | ✅ SUCCESS |
[2026-08-25 21:07:59] CI执行结束


/lgtm
/approve


/approve


描述
改动原因
op_graph/*_proto.h中的REG_OP会被scripts/util/merge_proto.py合并进ops_proto_math.h/.cpp,再编成内置 op_proto 库。当同名算子在 canndev 侧的遗留原型头(elewise_calculation_ops.h、selection_ops.h、ops_proto_legacy.h等)也有REG_OP注册时,两份定义进入同一编译单元会重复定义。仓库既有范式是在
REG_OP外层加条件编译隔离宏,merge_proto.py的匹配式会把该宏一并带入合并产物。本仓已有math/bias、math/add_v2、math/square_sum_all、conversion/tensor_redirect等先例,但本批 5 个算子的原型头遗漏了该保护。检视意见整改。改动方法
对 5 个算子的
op_graph/*_proto.h,在REG_OP外层补#ifndef/#define OPS_PROTO_DEF_<OPTYPE>…#endif:#ifndef OPS_PROTO_DEF_MULNONAN #define OPS_PROTO_DEF_MULNONAN REG_OP(MulNoNan) ... .OP_END_FACTORY_REG(MulNoNan) #endif // OPS_PROTO_DEF_MULNONAN宏名取
OPS_PROTO_DEF_+ 算子名大写去下划线,与发布包opp/built-in/op_graph/inc中已有同类隔离宏的拼法一致。位置严格贴在REG_OP前、OP_END_FACTORY_REG后一行——merge_proto.py的正则要求 guard 与REG_OP相邻,位置写偏宏会被丢弃。涉及算子(5 个)
CumulativeLogsumexp、FusedMulAdd、FusedMulAddAdd、FusedMulAddNL2loss、MulNoNan
刻意未纳入的三处,说明如下,避免评审时误判为遗漏:
math/ragged_bin_count/op_graph/ragged_bin_count_proto.hOPS_PROTO_DEF_RAGGED_BIN_COUNT,以便与ops_proto_legacy.h逐字节对齐。改成常规拼法反而会让配对失效experimental/math/add_v2/op_graph/add_v2_proto.hmath/add_v2已有隔离宏。experimental 副本 dtype 支持面更窄(4 种 vs 11 种),共用同一宏名会让并入顺序决定最终 IR,存在悄悄收窄支持面的风险experimental/math/mul_no_nan/op_graph/mul_no_nan_proto.h变更范围:5 个文件,+15 −0,纯条件编译指令,不改动任何 IR 的输入/输出/属性/dtype 定义,无功能与支持面变化。未改动
common/inc/op_graph/op_math_proto_extend.h。关联的Issue
关联 Issue #2875
测试
python3 scripts/util/merge_proto.py,合并产物中REG_OP5 个、#ifndef OPS_PROTO_DEF_5 个,隔离宏 5/5 全部正确带出。cann-9.2.0/opp/built-in/op_graph/inc/*.h中同名算子的既有隔离宏逐个比对,宏名不一致项 0 处。OPS_PROTO_DEF_宏数恰为 1(无嵌套/重复保护)。clang-format 18.1.8 --style=file --dry-run -Werror整文件检查全部通过;OAT 许可头检查全部合规。文档更新
无。本 PR 不涉及文档变更。
类型标签