ops-math 仓中 5 个算子的 GE IR 原型头 <算子>/op_graph/*_proto.h,其 REG_OP 外层缺少 OPS_PROTO_DEF_<OPTYPE> 条件编译隔离宏:
<算子>/op_graph/*_proto.h
REG_OP
OPS_PROTO_DEF_<OPTYPE>
CumulativeLogsumexp、FusedMulAdd、FusedMulAddAdd、FusedMulAddNL2loss、MulNoNan
这些原型会被 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 注册时,两份定义进入同一编译单元即构成重复定义。
scripts/util/merge_proto.py
ops_proto_math.h
.cpp
elewise_calculation_ops.h
selection_ops.h
ops_proto_legacy.h
本仓已有 math/bias、math/add_v2、math/square_sum_all、conversion/tensor_redirect、math/ragged_bin_count 等算子按此范式加了隔离宏,上述 5 个遗漏了该保护。
math/bias
math/add_v2
math/square_sum_all
conversion/tensor_redirect
math/ragged_bin_count
本问题属于头文件与构建期问题,与运行硬件型号无关,在任意昇腾产品形态下构建均可复现。
cann/ops-math
890971cad
.pre-commit-config.yaml
以 MulNoNan 为例:
git clone https://gitcode.com/cann/ops-math.git && cd ops-math # 1) 确认原型头没有隔离宏 grep -c "OPS_PROTO_DEF" math/mul_no_nan/op_graph/mul_no_nan_proto.h # 输出:0 # 2) 跑合并脚本,观察合并产物 python3 scripts/util/merge_proto.py D math/mul_no_nan/op_graph/mul_no_nan_proto.h \ --output-file /tmp/merged.h grep -c "REG_OP(" /tmp/merged.h # 1,原型已并入 grep -c "#ifndef OPS_PROTO_DEF_" /tmp/merged.h # 0,无隔离宏 # 3) 对照 canndev 侧同名注册源 grep -n "REG_OP(MulNoNan)" <CANN安装路径>/opp/built-in/op_graph/inc/elewise_calculation_ops.h
合并产物 ops_proto_math.h 与 elewise_calculation_ops.h 同时被包含时,REG_OP(MulNoNan) 展开出的类定义出现两次,构成重复定义。
REG_OP(MulNoNan)
op_graph/*_proto.h
#ifndef/#define OPS_PROTO_DEF_<OPTYPE>
#endif
merge_proto.py
merge_proto.py 合并产物对比(以 mul_no_nan_proto.h 为例):
mul_no_nan_proto.h
master 合并产物: REG_OP=1 隔离宏=0 ← 原型进去了,但没有隔离保护 修复后合并产物: REG_OP=1 隔离宏=1 ← 隔离宏正确带出
修复后全量校验:
ops-math: 改动文件=5 合并产物隔离宏=5/5 宏名与发布包不一致项=0 跨文件重名宏=0 每文件 OPS_PROTO_DEF 宏数=1(无嵌套/重复保护) clang-format(整文件)=5/5 通过 OAT 许可头=5/5 合规 trailing-whitespace / end-of-file-fixer / check-merge-conflict / detect-private-key / check-added-large-files 全部通过
有三处刻意不纳入修改范围,避免被误判为遗漏:
math/ragged_bin_count/op_graph/ragged_bin_count_proto.h
OPS_PROTO_DEF_RAGGED_BIN_COUNT
experimental/math/add_v2/op_graph/add_v2_proto.h
experimental/math/mul_no_nan/op_graph/mul_no_nan_proto.h
其他说明:
common/inc/op_graph/op_math_proto_extend.h
关联 PR:https://gitcode.com/cann/ops-math/pull/5066
Describe the current behavior / 问题描述
ops-math 仓中 5 个算子的 GE IR 原型头
<算子>/op_graph/*_proto.h,其REG_OP外层缺少OPS_PROTO_DEF_<OPTYPE>条件编译隔离宏:CumulativeLogsumexp、FusedMulAdd、FusedMulAddAdd、FusedMulAddNL2loss、MulNoNan
这些原型会被
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注册时,两份定义进入同一编译单元即构成重复定义。本仓已有
math/bias、math/add_v2、math/square_sum_all、conversion/tensor_redirect、math/ragged_bin_count等算子按此范式加了隔离宏,上述 5 个遗漏了该保护。Environment / 环境信息
本问题属于头文件与构建期问题,与运行硬件型号无关,在任意昇腾产品形态下构建均可复现。
cann/ops-mathmaster(复现基线 commit890971cad)scripts/util/merge_proto.py.pre-commit-config.yaml)Steps to reproduce the issue / 重现步骤
以 MulNoNan 为例:
git clone https://gitcode.com/cann/ops-math.git && cd ops-math # 1) 确认原型头没有隔离宏 grep -c "OPS_PROTO_DEF" math/mul_no_nan/op_graph/mul_no_nan_proto.h # 输出:0 # 2) 跑合并脚本,观察合并产物 python3 scripts/util/merge_proto.py D math/mul_no_nan/op_graph/mul_no_nan_proto.h \ --output-file /tmp/merged.h grep -c "REG_OP(" /tmp/merged.h # 1,原型已并入 grep -c "#ifndef OPS_PROTO_DEF_" /tmp/merged.h # 0,无隔离宏 # 3) 对照 canndev 侧同名注册源 grep -n "REG_OP(MulNoNan)" <CANN安装路径>/opp/built-in/op_graph/inc/elewise_calculation_ops.h合并产物
ops_proto_math.h与elewise_calculation_ops.h同时被包含时,REG_OP(MulNoNan)展开出的类定义出现两次,构成重复定义。Describe the expected behavior / 预期结果
op_graph/*_proto.h中,REG_OP外层带#ifndef/#define OPS_PROTO_DEF_<OPTYPE>…#endif,且宏名与发布包中同名算子的既有隔离宏逐字节一致。merge_proto.py正确带入合并产物(该正则要求 guard 与REG_OP严格相邻,位置写偏宏会被丢弃)。Related log / screenshot / 日志 / 截图
merge_proto.py合并产物对比(以mul_no_nan_proto.h为例):修复后全量校验:
Special notes for this issue/备注
有三处刻意不纳入修改范围,避免被误判为遗漏:
math/ragged_bin_count/op_graph/ragged_bin_count_proto.hOPS_PROTO_DEF_RAGGED_BIN_COUNT,与ops_proto_legacy.h逐字节对齐。改成常规拼法或在外层再套一层,都会让merge_proto.py只带出内层宏,反而使原有配对失效(已实测)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其他说明:
common/inc/op_graph/op_math_proto_extend.h。REG_OP也没有隔离宏。彻底闭环还需遗留侧同步补同名宏,该部分不在本 Issue 的修改范围内,供后续跟踪。关联 PR:https://gitcode.com/cann/ops-math/pull/5066