Pull Request已成功合入, 合并人@CANN-robot
(感谢 hahaha22 的贡献)变更摘要
本 PR 按图模式交付件要求,为 26 个算子补齐 InferDataType 交付件(op_graph/<op>_graph_infer.cpp),通过 IMPL_OP(Op).InferDataType(f) 注册,将 dtype 推导规则从 canndev v1.0 旧式 IMPLEMT_COMMON_INFERFUNC 语义迁移到图模式。其中 19 个透传类算子复用仓内共享模板 ops::InferDataTypeOutputSameAsInput,3 个比较类算子直接输出 DT_BOOL,Select/SelectV2 以输入 1 为 dtype 基准,Mul/TanhGrad 自带与部署包一致的提升表。此外还调整了 ClipByValue 的 infershape 实现与相关 UT 期望形状,并为位运算算子补充 infershape UT。
主要改动
- 新增透传类 dtype 推导交付件: 为
Addcdiv、Addcmul、Axpy、BiasAdd、BitwiseAnd、BitwiseOr、BitwiseXor、SquaredDifference、Div、DivNoNan、FloorDiv、FloorMod、Lerp、Maximum、Minimum、Mod、Muls、Sub、ClipByValue等算子新增op_graph/*_graph_infer.cpp,统一注册InferDataTypeOutputSameAsInput<>,实现输出 dtype 与输入 0 一致。 - 新增比较类与索引锚定 dtype 推导:
GreaterEqual、LessEqual、LogicalAnd各自定义InferDataType4Xxx回调并通过SetOutputDataType(0, DT_BOOL)固定输出为布尔型;Select、SelectV2注册InferDataTypeOutputSameAsInput<0, 1>,以输入 1(then/x1)作为 dtype 基准。 - 新增 Promote 提升类 dtype 推导:
Mul、TanhGrad分别在独立命名空间中内置 33×33 的kPromoteTypesLookup提升表及PromoteType函数,对提升结果为DT_UNDEFINED的非法组合通过OP_LOGE报错并返回GRAPH_FAILED。 - 调整
ClipByValue的 infershape 逻辑:clip_by_value_infershape.cpp由直接调用Ops::Base::InferShape4Broadcast改为经InferShape4ClipByValue传入INPUT_NUM_THREE,对应 UT 中两个用例的期望输出形状由具体维度改为{-2}。 - 补充位运算算子 infershape UT: 新增
test_bitwise_and_infershape.cpp、test_bitwise_or_infershape.cpp、test_bitwise_xor_infershape.cpp,覆盖同形状与广播两种场景的形状推导校验。


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 |
|---|---|---|
| math/addcdiv | ✅ 宋恺, 王瑞 (2/2) | ✅ 王瑞 (1/1) |
| math/addcmul | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/axpy | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/bitwise_and | ✅ 宋恺, 王瑞 (2/2) | ✅ 王瑞 (1/1) |
| math/bitwise_or | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/bitwise_xor | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/div | ✅ 宋恺, 王瑞 (2/2) | ✅ 王瑞 (1/1) |
| math/floor_div | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/floor_mod | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/greater_equal | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/lerp | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/less_equal | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/logical_and | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/maximum | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/minimum | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/mod | ✅ 宋恺, 王瑞 (2/2) | ✅ 王瑞 (1/1) |
| math/mul | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/muls | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/select | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| math/sub | ✅ 宋恺, 王瑞 (2/2) | ✅ 王瑞 (1/1) |
| math/tanh_grad | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
| repo-cann/ops-math | ✅ 王瑞, 宋恺 (2/2) | ✅ 王瑞 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
hahaha22, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/lgtm


描述
按
graph_develop_guide.md图模式交付件要求,为 26 个算子补齐 InferDataType 交付件op_graph/<op>_graph_infer.cpp(IMPL_OP(Op).InferDataType(f)注册),dtype 推导规则迁移自 canndev v1.0 旧式IMPLEMT_COMMON_INFERFUNC的类型推导语义:ops::InferDataTypeOutputSameAsInput(truncate_mod/invert 同款);InferDataType 仅做纯推导,不增加输入 dtype 一致性校验:混合 dtype 组合沿用既有防线,由 tiling 侧 dtype 组合查表(arch35 DTYPE_MAP、CheckDtype 等)在编译期拦截,与仓内 add/axpy/sub 等存量算子行为一致。
CMake 无需改动(构建宏
GLOB_RECURSE op_graph/*.cpp自动收编)。关联的Issue
测试
g++ -fsyntax-only全部通过;bash build.sh --opgraph -j16全量构建通过,26 个新 .o 均进入 graph_plugin_math_obj 并链接入 libopgraph_math.so(2026-10-13 校验回退后重新全量构建通过);类型标签