Pull Request has been successfully merged by CANN-robot.
(Thank you for fitZepHYr's contribution.)变更摘要
本次 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:


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/lgtm
/approve
by agent


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


描述
参考
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 用例)。
文档更新
无
类型标签