已关闭
fix(op_host): FusedMulAdd/FusedMulAddAdd/MulNoNan 补齐 InferDataType 注册 #5263
zl_hw创建于 8月31日关闭于 9月1日
fix(op_host): FusedMulAdd/FusedMulAddAdd/MulNoNan 补齐 InferDataType 注册 #5263
已关闭
zl_hw创建于 8月31日关闭于 9月1日
zl_hw成员
8月31日

描述

问题

FusedMulAdd、FusedMulAddAdd、MulNoNan 这 3 个算子在 op_host/*_infershape.cpp 中只注册了 InferShape,没有注册 InferDataType,GE 图通路上输出 dtype 缺少显式推导来源。

方法

在各算子已有的 op_host/*_infershape.cpp 中新增 InferDataType4<OpType>,并将原有 IMPL_OP_INFERSHAPE 注册扩展为 .InferShape(...).InferDataType(...)。三个算子的输出 dtype 均跟随 x1,与 op_proto 一致:

算子 输出 dtype 来源
FusedMulAdd y ← x1
FusedMulAddAdd y ← x1
MulNoNan y ← x1

关联的Issue

关联 Issue #2987

测试

bash build.sh -u --ophost --ops=fused_mul_add,fused_mul_add_add,mul_no_nan

结果:47 tests PASSED,0 FAILED。其中包含本次新增的 10 条 infer_datatype 用例:

[       OK ] FusedMulAddInfershape.infer_datatype_fp16 / infer_datatype_fp32 / infer_datatype_int32
[       OK ] FusedMulAddAddInfershape.infer_datatype_fp16 / infer_datatype_fp32 / infer_datatype_int32
[       OK ] MulNoNanInfershape.infer_datatype_fp16 / infer_datatype_fp32 / infer_datatype_bf16 / infer_datatype_int32

用例中的 ASSERT_NE(opImpl->infer_datatype, nullptr) 实证该注册可被 OpImplSpaceRegistryV2 取到。

门禁自检:clang-format 18.1.8 --style=file 6 个文件全通过;仓内 scripts/oat_check.sh 6 个文件 All checks passed;trailing-whitespace / end-of-file / 冲突标记检查通过。

关于 diff 体积:三个 UT 文件的存量代码为非 clang-format 风格,本次触碰后被 pre-commit 的 clang-format 整文件重排,故 diff 中含大量纯格式行(每个文件约 300 行增删,实质改动约 90 行)。三个实现文件无格式变更。

未覆盖:本次仅验证到 op_host UT 层(用例通过注册表取到 infer_datatype 函数指针后直接调用),未做真机与 GE 图 e2e 验证。

文档更新

无。本次仅新增 InferDataType 注册与对应 UT,不涉及对外接口与算子资料变更。

类型标签

likedislike
当前Pull Request已关闭, 关闭人@zl_hw
Zzl_hw成员
8月31日 创建了 pull request,commit 435d92f0
atomgit-bot
atomgit-bot
8月31日 评论:

变更摘要

本 PR 为 FusedMulAdd、FusedMulAddAdd、MulNoNan 三个算子补齐 InferDataType 注册:在各自的 op_host 侧新增 InferDataType4Xxx 函数,将输出 Y 的数据类型设置为与输入 x1(索引 0)一致,并通过 IMPL_OP_INFERSHAPE(X).InferShape(...).InferDataType(...) 完成注册,使其与 op_proto 中"输出 dtype 与 x1 相同"的定义对齐。同时为三个算子补充了对应的 InferDataType 单测用例,覆盖 fp16/fp32/int32(MulNoNan 另有 bf16)等场景,并顺带将测试用例的构造代码统一为单行格式。

主要改动

  • 新增 InferDataType 推导函数: 在 fused_mul_add_infershape.cpp、fused_mul_add_add_infershape.cpp、mul_no_nan_infershape.cpp 中分别新增 InferDataType4FusedMulAdd、InferDataType4FusedMulAddAdd、InferDataType4MulNoNan,通过 context->SetOutputDataType(...) 将输出 Y 的 dtype 设置为输入 x1 的 dtype,并返回 ge::GRAPH_SUCCESS。
  • 扩展注册链: 三个算子的注册宏由 IMPL_OP_INFERSHAPE(X).InferShape(...) 扩展为 IMPL_OP_INFERSHAPE(X).InferShape(...).InferDataType(...),使注册的算子实现同时携带 infer_datatype 能力。
  • 新增输入/输出索引常量: 各文件引入 FUSED_MUL_ADD_INPUT_X1_INDEX/FUSED_MUL_ADD_OUTPUT_Y_INDEX(及 FusedMulAddAdd、MulNoNan 对应常量)等 constexpr 索引,用于明确输入 x1 与输出 Y 的位置。
  • 补充 InferDataType 单测: 三个测试文件引入 op_infer_datatype_context_builder.h 与 base/registry/op_impl_space_registry_v2.h,通过 OpInferDataTypeContextBuilder 构造上下文并断言输出 dtype 跟随输入 x1(fp16/fp32/int32,MulNoNan 另含 bf16)。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月31日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
8月31日 添加了label:cann-cla/no
CANN-robot
CANN-robot成员
8月31日 评论:

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
repo-cann/ops-math ✅ 宋恺, 汤平川 (2/2) ✅ 汤平川, 宋恺 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Guide

@zl_hw , thanks for your pull request.

The following commit(s) have not signed Contributor License Agreement (CLA).

Commit Reason
e8ed038d fix(op_host): FusedMulAdd/FusedM... the email is not signed for CLA! please check if it is correct and the same as your signed email.

If you need to sign CLA, you can click here to sign the CLA.

If you need to check if the email is set up correctly, you can click here to do it in the FAQs.

After signing the CLA or updating the email, you must comment /check-cla to check the CLA status again.

likedislike
CANN-robotCANN-robot成员
8月31日 将yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为评审人
CANN-robotCANN-robot成员
8月31日 将yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,zhanw_coding设为审查人
zl_hw成员
8月31日 评论:

compile

likedislike
Zzl_hw成员
8月31日 预合并成功(commit_id: dee95bc894617375b242d1621ea91d7bcdbabcff)
CANN-robotCANN-robot成员
8月31日 添加了label:ci-pipeline-running
Zzl_hw成员
8月31日 修改了pull request 的描述
CANN-robotCANN-robot成员
8月31日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
8月31日 添加了label:ci-pipeline-passed
songkai111成员
9月1日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
9月1日 添加了label:approved
TangPC
TangPC成员
9月1日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
9月1日 添加了label:lgtm
Zzl_hw成员
9月1日 关闭了 pull request