已合并
feat(graph): 补齐26个算子InferDataType交付件(op_graph/*_graph_infer.cpp) #5904
feat(graph): 补齐26个算子InferDataType交付件(op_graph/*_graph_infer.cpp) #5904
已合并
hahaha22创建于 9月21日
hahaha22成员
9月21日

描述

按 graph_develop_guide.md 图模式交付件要求,为 26 个算子补齐 InferDataType 交付件 op_graph/<op>_graph_infer.cpp(IMPL_OP(Op).InferDataType(f) 注册),dtype 推导规则迁移自 canndev v1.0 旧式 IMPLEMT_COMMON_INFERFUNC 的类型推导语义:

  • 透传类(out=in0,19个):Addcdiv/Addcmul/Axpy/BiasAdd/BitwiseAnd/BitwiseOr/BitwiseXor/SquaredDifference/Div/DivNoNan/FloorDiv/FloorMod/Lerp/Maximum/Minimum/Mod/Muls/Sub/ClipByValue,复用仓内共享模板 ops::InferDataTypeOutputSameAsInput(truncate_mod/invert 同款);
  • 比较类输出 DT_BOOL(3个):GreaterEqual/LessEqual/LogicalAnd(对齐 logical_or/not_equal 现有写法);
  • 非0索引锚定(out=in1,2个):Select/SelectV2(v1.0 以 x1/then 为 dtype 基准,输入0 是 condition);
  • Promote 提升(2个):Mul/TanhGrad,与 add_graph_infer 既有实现完全一致的写法(同款 33×33 提升表,对齐部署包 opcommon::PromoteType);非法组合(提升结果 DT_UNDEFINED)不做后置校验,由 tiling 侧 dtype 组合查表兜底,行为与 add 相同。

InferDataType 仅做纯推导,不增加输入 dtype 一致性校验:混合 dtype 组合沿用既有防线,由 tiling 侧 dtype 组合查表(arch35 DTYPE_MAP、CheckDtype 等)在编译期拦截,与仓内 add/axpy/sub 等存量算子行为一致。

CMake 无需改动(构建宏 GLOB_RECURSE op_graph/*.cpp 自动收编)。

关联的Issue

测试

  1. 语法检查:26 个新文件 g++ -fsyntax-only 全部通过;
  2. 构建:bash build.sh --opgraph -j16 全量构建通过,26 个新 .o 均进入 graph_plugin_math_obj 并链接入 libopgraph_math.so(2026-10-13 校验回退后重新全量构建通过);
  3. 行为验证:按 KernelRunContext ABI 构造 mock InferDataTypeContext 直接调用注册函数,26 算子覆盖透传(F16/BF16,含混合 dtype 取 in0)、BOOL、in1 锚定、Promote 组合及 Mul 提升表边界(输出 DT_UNDEFINED,行为与 add 一致),全部通过(2026-10-13 回退后全量重跑)。

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 hahaha22 的贡献)
Hhahaha22成员
9月21日 创建了 pull request,commit 5eb69871
atomgit-bot
atomgit-bot
9月21日 评论:

变更摘要

本 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,覆盖同形状与广播两种场景的形状推导校验。
likedislike
不准确?
atomgit-bot
atomgit-bot
9月21日 评论:

代码审查

✅ 未发现问题

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

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

likedislike
此处折叠了84条消息 查看更多
Hhahaha22成员
9 天前 设置为草稿状态
Hhahaha22成员
9 天前 取消了草稿状态
songkai111成员
9 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
9 天前 添加了label:lgtm
CANN-robotCANN-robot成员
9 天前 合入了pull request