已合并
fix(op_graph): 5 个算子原型头补 OPS_PROTO_DEF 隔离宏 #5066
fix(op_graph): 5 个算子原型头补 OPS_PROTO_DEF 隔离宏 #5066
已合并
zl_hw创建于 8月25日
zl_hw成员
8月25日

描述

改动原因

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.h 已有隔离宏,且宏名刻意用蛇形 OPS_PROTO_DEF_RAGGED_BIN_COUNT,以便与 ops_proto_legacy.h 逐字节对齐。改成常规拼法反而会让配对失效
experimental/math/add_v2/op_graph/add_v2_proto.h 正式目录 math/add_v2 已有隔离宏。experimental 副本 dtype 支持面更窄(4 种 vs 11 种),共用同一宏名会让并入顺序决定最终 IR,存在悄悄收窄支持面的风险
experimental/math/mul_no_nan/op_graph/mul_no_nan_proto.h 同上,experimental 副本 3 种 dtype vs 正式目录 4 种

变更范围:5 个文件,+15 −0,纯条件编译指令,不改动任何 IR 的输入/输出/属性/dtype 定义,无功能与支持面变化。未改动 common/inc/op_graph/op_math_proto_extend.h。

关联的Issue

关联 Issue #2875

测试

  1. 合并产物验证:对 5 个改动文件跑 python3 scripts/util/merge_proto.py,合并产物中 REG_OP 5 个、#ifndef OPS_PROTO_DEF_ 5 个,隔离宏 5/5 全部正确带出。
  2. 宏名配对验证:与发布包 cann-9.2.0/opp/built-in/op_graph/inc/*.h 中同名算子的既有隔离宏逐个比对,宏名不一致项 0 处。
  3. 重名检查:5 个新增宏无跨文件重名,每个文件内 OPS_PROTO_DEF_ 宏数恰为 1(无嵌套/重复保护)。
  4. 格式与合规门禁:clang-format 18.1.8 --style=file --dry-run -Werror 整文件检查全部通过;OAT 许可头检查全部合规。

文档更新

无。本 PR 不涉及文档变更。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zl_hw 的贡献)
Zzl_hw成员
8月25日 创建了 pull request,commit cd641724
atomgit-bot
atomgit-bot
8月25日 评论:

变更摘要

本 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 个算子原型头文件,全部为纯新增宏定义语句,不影响各算子原有的输入/输出/属性定义及注册逻辑。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月25日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
8月25日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月25日 评论:

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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
CANN-robotCANN-robot成员
8月25日 将FelixTang7,yu-xinjie62,yue-ma,zhou-qilong,wangrui_,wei-peng-1991,renruhai,su-yueming,zhajianqing123,rxtfeng,luowen203_gg123,loov1,tang-lei01,zhangzijie,jia0liang,chenqi317,liu-wei,LiuXinxin23,fullt,LiWei79,songkai111,chenxingyu18,demoauguste,pingchuantang,llimwang,gubaocheng,andong_hw,wangyongguang,xuejinghui,zhanw_coding设为评审人
CANN-robotCANN-robot成员
8月25日 将FelixTang7,yu-xinjie62,yue-ma,zhou-qilong,wangrui_,wei-peng-1991,renruhai,su-yueming,zhajianqing123,rxtfeng,luowen203_gg123,loov1,tang-lei01,zhangzijie,jia0liang,chenqi317,liu-wei,LiuXinxin23,fullt,LiWei79,songkai111,chenxingyu18,demoauguste,pingchuantang,llimwang,gubaocheng,andong_hw,wangyongguang,xuejinghui,zhanw_coding设为审查人
zl_hw成员
8月25日 评论:

compile

likedislike
Zzl_hw成员
8月25日 预合并成功(commit_id: 97b0b26355a50a43270279692abe077966f11d6f)
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
8月25日 评论:

流水线任务触发成功
任务链接 [fd1905a6a6874f5487524800bf087084][流水线指导]

任务名称状态日志下载链接
pre_comment ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>

[2026-08-25 21:05:40]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
8月25日 评论:

流水线任务触发成功
任务链接 [c2cff53d286e4eb29eb7c0cb7d98bbd1][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_precommit ❌ FAILED >>>>> >>>>>
StaticCheck_md ✅ SUCCESS
likedislike
Zzl_hw成员
8月25日 预合并成功(commit_id: b2c3331d21b74cfc68117547a361c6f10adca953)
此处折叠了5条事件消息 查看更多
CANN-robotCANN-robot成员
8月25日 移除了审查人FelixTang7,yu-xinjie62,yue-ma,zhou-qilong,wangrui_,wei-peng-1991,renruhai,su-yueming,zhajianqing123,rxtfeng,luowen203_gg123,loov1,zhangzijie,jia0liang,chenqi317,liu-wei,LiuXinxin23,fullt,LiWei79,songkai111,chenxingyu18,demoauguste,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding
zl_hw成员
8月25日 评论:

compile

likedislike
Zzl_hw成员
8月25日 预合并成功(commit_id: cfda908348b986ccf963d45bac60b1bfdcc75ab7)
CANN-robotCANN-robot成员
8月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-failed
CANN-robotCANN-robot成员
8月25日 删除了label:ci-pipeline-failed
CANN-robot
CANN-robot成员
8月25日 评论:

流水线任务触发成功
任务链接 [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执行结束

likedislike
CANN-robot
CANN-robot成员
8月25日 评论:

流水线任务触发成功
任务链接 [3d28734e533e450aa60b7ad155134f82][流水线指导]

任务名称状态日志下载链接
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
codecheck_precommit ✅ SUCCESS >>>>>
StaticCheck_md ✅ SUCCESS

[2026-08-25 21:07:59]    CI执行结束

likedislike
CANN-robotCANN-robot成员
8月25日 添加了label:api-check-failed
CANN-robotCANN-robot成员
8月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-passed
TangPCTangPC成员
8月26日 修改标题为 “fix(op_graph): 5 个算子原型头补 OPS_PROTO_DEF 隔离宏”,原标题为“fix(op_graph): 8 个算子原型头补 OPS_PROTO_DEF 隔离宏”
TangPCTangPC成员
8月26日 修改了pull request 的描述
TangPC
TangPC成员
8月26日 评论:

/lgtm
/approve

likedislike
wangyongguang成员
8月26日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月26日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
8月26日 关闭了关联的issue
CANN-robotCANN-robot成员
8月26日 合入了pull request