Merged
feat(cdist_grad): 补充 InferDataType RT2.0 推导并新增 UT 看护 #7246
feat(cdist_grad): 补充 InferDataType RT2.0 推导并新增 UT 看护 #7246
Merged
fitZepHYrAdd on 6 days ago
fitZepHYr
fitZepHYrCollaborators
6 days ago

描述

参考 math/abs/op_host/abs_infershape.cpp 中 InferDataType 的 RT2.0 内联注册写法,为 CdistGrad 算子补充输出 dtype 推导。

改动内容:

  • math/cdist_grad/op_host/cdist_grad_infershape.cpp:新增 InferDataType4CdistGrad,输出 y 的 dtype 透传输入 grad 的 dtype(grad/x1/x2/cdist 要求同 dtype),注册链调整为 IMPL_OP_INFERSHAPE(CdistGrad).InferShape(InferShape4CdistGrad).InferDataType(InferDataType4CdistGrad)。
  • math/cdist_grad/tests/ut/op_host/test_cdist_grad_infershape.cpp:新增 4 例 InferDataType UT,覆盖 float32、float16、bfloat16,以及输入 dtype 不一致时输出仍取 grad 的场景。

关联的Issue

Issue 4640

测试

执行 op_host UT:
bash build.sh -u --ophost --soc=ascend910b --ops=cdist_grad --gtest_filter='CdistGradInfershape.*'

结果:11/11 通过(7 例原 InferShape 用例 + 4 例新增 InferDataType 用例)。

文档更新

无

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for fitZepHYr's contribution.)
fitZepHYrfitZepHYrCollaborators
6 days ago Created pull request, commit 299b9121
atomgit-bot
atomgit-bot
6 days ago Comments:

变更摘要

本次 PR 为 CdistGrad 算子补齐了 RT2.0 的输出数据类型推导能力:在 math/cdist_grad/op_host/cdist_grad_infershape.cpp 中新增 InferDataType4CdistGrad,通过算子注册链将其与 InferShape4CdistGrad 一并挂载到 IMPL_OP_INFERSHAPE(CdistGrad) 上;同时在 math/cdist_grad/tests/ut/op_host/test_cdist_grad_infershape.cpp 中补充针对该推导逻辑的 op_host UT 看护。

主要改动

  • 新增 dtype 推导函数: 新增 InferDataType4CdistGrad,从 grad 输入读取 dtype 并设置到输出 y,与「grad/x1/x2/cdist 同 dtype」的约束保持一致,并补充起止 OP_LOGD 日志。
  • 常量索引定义: 新增 CDIST_GRAD_INPUT_GRAD_INDEX 与 CDIST_GRAD_OUTPUT_Y_INDEX 两个 size_t 常量,替代代码中的魔法数字,用于标识输入 grad 与输出 y 的位置。
  • 算子注册链调整: 将注册语句由仅 InferShape 扩展为 IMPL_OP_INFERSHAPE(CdistGrad).InferShape(InferShape4CdistGrad).InferDataType(InferDataType4CdistGrad),使算子同时具备 shape 与 dtype 推导入口。
  • 新增 InferDataType UT: 在 UT 中通过 DefaultOpImplSpaceRegistryV2 获取 CdistGrad 的 opImpl,校验 infer_datatype 存在,并用 OpInferDataTypeContextBuilder 构造 4 输入 1 输出的上下文,覆盖 float32、float16、bfloat16 三种一致 dtype 场景。
  • 输入 dtype 不一致场景看护: 新增用例将输入 0 设为 DT_FLOAT、其余输入设为 DT_FLOAT16,验证输出 dtype 仍取 grad 的 DT_FLOAT,并断言返回 ge::GRAPH_SUCCESS。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
6 days ago Comments:

代码审查

✅ 未发现问题,不过下面列了 1 处不太确定的地方,供你参考


🔍 另有 1 处,仅供参考(不影响合并)

下面这些地方 AI 觉得有点可疑,但把握不大,所以没有当成正式问题,也没有在代码行上留评论。列在这里只是多给你一个视角:觉得有道理可以顺手看看,觉得是误报直接忽略就行。

  • math/cdist_grad/op_host/cdist_grad_infershape.cpp:80 — suggest: 检查 SetOutputDataType 返回值,失败时返回 GRAPH_FAILED

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
6 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
6 days ago Comments:

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 ✅ 顾宝成, yue-ma (2/2) ✅ 顾宝成, yue-ma (2/1)

💡 Tip:

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

CLA Signature Pass

VoyageZhou, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
6 days ago Set yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,onanfield,zhanw_coding,jiangjiawei,clinglai0517 as approver
CANN-robotCANN-robotCollaborators
6 days ago Set yue-ma,zhou-qilong,wangrui_,rxtfeng,loov1,zhangzijie,jia0liang,zl_hw,songkai111,chenxingyu18,pingchuantang,llimwang,gubaocheng,andong_hw,xuejinghui,onanfield,zhanw_coding,jiangjiawei,clinglai0517 as approver
fitZepHYr
fitZepHYrCollaborators
6 days ago Comments:

compile

likedislike
fitZepHYrfitZepHYrCollaborators
6 days ago Pre merge succeeded (commit_id: fc25a770c27e2e474e691ba111e7dd89caa4999a)
CANN-robot
CANN-robotCollaborators
6 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
6 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
6 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
6 days ago Added label: ci-pipeline-passed
gubaochengCollaborators
6 days ago Comments:

/lgtm
/approve
by agent

likedislike
CANN-robotCANN-robotCollaborators
6 days ago Added label: approved
fitZepHYrfitZepHYrCollaborators
6 days ago Modify description of pull request
chenyifengCollaborators
5 days ago Comments:

您好,PR已满足合入指标,请尽快联系Committer进行合入。如暂时不需要合入,请在PR标题前加[WIP]

likedislike
yue-maCollaborators
3 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
3 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
3 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
3 days ago Merged pull request