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

描述

改动原因

op_graph/*_proto.h 中的 REG_OP 会被 scripts/util/merge_proto.py 合并进 ops_proto_nn.h/.cpp,再编成内置 op_proto 库(cmake/gen_ops_info.cmake 的 merge_graph_headers → cmake/symbol.cmake 的 gen_opgraph_symbol)。当同名算子在 canndev 侧的遗留原型头(nn_norm_ops.h、reduce_ops.h、ops_proto_legacy.h 等)也有 REG_OP 注册时,两份定义进入同一编译单元会重复定义。

仓库既有范式是在 REG_OP 外层加条件编译隔离宏,merge_proto.py 的匹配式会把该宏一并带入合并产物。本仓已有 activation/relu6_d、optim/sgd、norm/in_training_reduce_v2、vfusion/normalize_bbox 等先例,但本批 30 个算子的原型头遗漏了该保护。检视意见整改。

改动方法

对 30 个算子的 op_graph/*_proto.h,在 REG_OP 外层补 #ifndef/#define OPS_PROTO_DEF_<OPTYPE> … #endif:

#ifndef OPS_PROTO_DEF_DEEPNORM
#define OPS_PROTO_DEF_DEEPNORM
REG_OP(DeepNorm)
    ...
    .OP_END_FACTORY_REG(DeepNorm)
#endif // OPS_PROTO_DEF_DEEPNORM

宏名取 OPS_PROTO_DEF_ + 算子名大写去下划线,与发布包 opp/built-in/op_graph/inc 中已有 967 个同类隔离宏的拼法一致。位置严格贴在 REG_OP 前、OP_END_FACTORY_REG 后一行——merge_proto.py 的正则要求 guard 与 REG_OP 相邻,位置写偏宏会被丢弃。

涉及算子(30 个)

ApplyAdagrad、BatchNormExt2、BN3DTrainingUpdate、BNInfer、BNTrainingUpdateV2、BNTrainingUpdateV3、ChamferDistance、ClippedSwiglu、CosineEmbeddingLoss、DeepNorm、DeepNormGrad、DynamicQuantUpdateScatter、DynamicQuantUpdateScatterV2、GemmaRmsNorm、GroupNormSiluQuant、HardSigmoid、HardSwishGradV2、INInferV2、InplaceApplyRMSProp、InplaceSub、InstanceNormGrad、INTrainingUpdateGrad、L2NormalizeGrad、MultiAddRmsNormDynamicQuant、MultilabelMarginLoss、NonZeroWithValue、PoissonNllLoss、Relu6Grad、SoftmaxFocalLoss、SoftmaxFocalLossGrad

顺带修复:deep_norm、deep_norm_grad、gemma_rms_norm、multi_add_rms_norm_dynamic_quant、dynamic_quant_update_scatter_v2 这 5 个原型头文件末尾缺换行,属存量问题;pre-commit 的 end-of-file-fixer 钩子只扫改动文件,一旦改动即会被拦,故一并补齐。

变更范围:30 个文件,+95 −5,改动全部为条件编译指令与文件末尾换行,不改动任何 IR 的输入/输出/属性/dtype 定义,无功能与支持面变化。未改动 common/inc/op_graph/op_nn_proto_extend.h——merge_proto.py 会按算子名把聚合头中的重复项去重,改它不会进入合并产物。

关联的Issue

关联 Issue #5170

测试

  1. 合并产物验证:对 30 个改动文件跑 python3 scripts/util/merge_proto.py,合并产物中 REG_OP 30 个、#ifndef OPS_PROTO_DEF_ 30 个,隔离宏 30/30 全部正确带出。
  2. 宏名配对验证:与发布包 cann-9.2.0/opp/built-in/op_graph/inc/*.h 中同名算子的既有隔离宏逐个比对,宏名不一致项 0 处。
  3. 重名检查:30 个新增宏在三仓范围内无跨文件重名,每个文件内 OPS_PROTO_DEF_ 宏数恰为 1(无嵌套/重复保护)。
  4. 格式与合规门禁:按 .pre-commit-config.yaml 逐钩子本地复现 —— clang-format 18.1.8 --style=file --dry-run -Werror 整文件检查 30/30 通过、OAT 许可头 30/30 合规、trailing-whitespace / end-of-file-fixer / check-merge-conflict / detect-private-key / check-added-large-files 全部通过。

文档更新

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

类型标签

AI/Agent生成声明

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

变更摘要

本 PR 为 30 个算子原型头(op_graph/*_proto.h)的 REG_OP(...) 注册块统一补上 OPS_PROTO_DEF_* 隔离宏:在 REG_OP 前增加 #ifndef OPS_PROTO_DEF_<OP_NAME> / #define OPS_PROTO_DEF_<OP_NAME>,在 OP_END_FACTORY_REG 之后增加 #endif // OPS_PROTO_DEF_<OP_NAME>。改动为纯头文件宏包裹,不涉及算子定义、输入输出/属性等业务内容的变化,目标是让算子原型注册支持条件编译隔离,避免多文件包含时产生重复定义。

主要改动

  • 为激活类算子原型添加隔离宏:在 clipped_swiglu、hard_sigmoid、hard_swish_grad_v2、relu6_grad 等 4 个激活算子的 REG_OP 注册块外围添加 OPS_PROTO_DEF_* 条件编译宏。
  • 为 loss 类算子原型添加隔离宏:为 chamfer_distance、cosine_embedding_loss、multilabel_margin_loss、poisson_nll_loss、softmax_focal_loss 及 softmax_focal_loss_grad 等 6 个 loss 算子的注册块添加 #ifndef/#define/#endif 宏包裹。
  • 为 norm 类算子原型添加隔离宏:覆盖 batch_norm_ext2、bn3_d_training_update、bn_infer、bn_training_update_v2/v3、deep_norm、deep_norm_grad、gemma_rms_norm、group_norm_silu_quant、in_infer_v2、in_training_update_grad、instance_norm_grad、l2_normalize_grad、multi_add_rms_norm_dynamic_quant 等 14 个 norm 算子的注册块。
  • 为 index/optim/quant 类算子原型添加隔离宏:inplace_sub、non_zero_with_value(index),apply_adagrad、inplace_apply_rms_prop(optim),以及 dynamic_quant_update_scatter、dynamic_quant_update_scatter_v2(quant)的注册块同样套上 OPS_PROTO_DEF_* 条件编译宏。
  • 宏命名与注册块一一对应:每个宏名由 OPS_PROTO_DEF_ 前缀加上该算子名(去下划线并转为大写,如 OPS_PROTO_DEF_BATCHNORMEXT2、OPS_PROTO_DEF_SOFTMAXFOCALLOSSGRAD)组成,注释中同步标注对应宏名,便于识别与维护。
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日 将zengjuan,chaotang233,crystalhu,yangyang016,fanqirui,tang-lei01,chenqi317,liubo75,tangweiwei2,pingchuantang,wangyongguang设为评审人
CANN-robotCANN-robot成员
8月25日 将tang-lei01,wangyongguang设为审查人
zl_hw成员
8月25日 评论:

compile

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

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

任务名称状态日志下载链接
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_classify ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>

[2026-08-25 21:18:30]    CI执行结束

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

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

任务名称状态日志下载链接
antipoison ✅ SUCCESS >>>>>
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ❌ FAILED >>>>> >>>>>
SCA ✅ SUCCESS >>>>>
StaticCheck_md ✅ SUCCESS
likedislike
Zzl_hw成员
8月25日 预合并成功(commit_id: b126d86ce3fcc53c304ce4bcb05919a100a6d528)
Zzl_hw成员
8月25日 强制推送  1 个提交:6da5366f-fix(op_graph): 30 个算子原型头补 OPS_PROTO_DEF 隔离宏
Zzl_hw成员
8月25日 预合并成功(commit_id: caa69b22fb84abff7692ffd55e649ccc6d535a5f)
CANN-robotCANN-robot成员
8月25日 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
8月25日 添加了label:cann-cla/yes
zl_hw成员
8月25日 评论:

compile

likedislike
Zzl_hw成员
8月25日 预合并成功(commit_id: 01df2a25c3b48558b71f17111b9b48333532ef2c)
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-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
8月25日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950_ubuntu24 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_classify ✅ SUCCESS >>>>>
Compile_Ascend_X86_mobile_station_9030_ubuntu24 ✅ SUCCESS >>>>> >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
API_Check ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
UT_Test_report_lcov ⚠️ WARNING >>>>>

[2026-08-25 22:06:58]    CI执行结束

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

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

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

[2026-08-25 21:20:39]    CI执行结束

likedislike
CANN-robotCANN-robot成员
8月25日 添加了label:api-check-pass
CANN-robotCANN-robot成员
8月25日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月25日 添加了label:ci-pipeline-passed
TangPCTangPC成员
8月26日 修改了pull request 的描述
wangyongguang成员
8月26日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月26日 添加了label:approved
yangyang016成员
8月26日 评论:

/lgtm
/approve

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

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike