Pull Request已成功合入, 合并人@CANN-robot
(感谢 zl_hw 的贡献)变更摘要
本 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)组成,注释中同步标注对应宏名,便于识别与维护。


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. 👍


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


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


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


/approve


/lgtm
/approve


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


描述
改动原因
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
测试
python3 scripts/util/merge_proto.py,合并产物中REG_OP30 个、#ifndef OPS_PROTO_DEF_30 个,隔离宏 30/30 全部正确带出。cann-9.2.0/opp/built-in/op_graph/inc/*.h中同名算子的既有隔离宏逐个比对,宏名不一致项 0 处。OPS_PROTO_DEF_宏数恰为 1(无嵌套/重复保护)。.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生成声明