已合并
relu6 算子 dtype 分发机制修改为由def驱动,补全 InferShape/InferDataType 规范化实现。 #8721
relu6 算子 dtype 分发机制修改为由def驱动,补全 InferShape/InferDataType 规范化实现。 #8721
已合并
张伟伟创建于 23 天前
张伟伟
23 天前

描述

relu6 算子存在两类规范化问题:dtype 分发机制与仓内标准模式不一致、InferShape/InferDataType 实现不完整。本 PR 仅针对这两方面进行整改,不涉及算法逻辑变更。

关联的Issue

https://gitcode.com/cann/ops-nn/issues/4811

测试

  • UT 编译验证:tests/ut/op_kernel/CMakeLists.txt 已配置 -DDTYPE_X=half + MULTI_KERNEL_TARGET,验证 DTYPE_X 宏方式编译通过
  • UT 用例一致性:test_relu6.cpp 中 6 个测试用例(fp32_small、fp32_multi_loop、fp16_small、int32_small、bf16_small、fp16_multi_loop)同步移除 dataType 赋值,与 TilingData 结构体定义一致
  • InferShape UT:test_relu6_infershape.cpp 覆盖 float16/float/int32/bf16 四种 dtype + scalar/empty shape 场景,验证 InferShape 正确性
  • 参考算子对齐:改动后与 celu_v2(def 驱动 dtype + InferDataType)实现模式完全一致

文档更新

无。本次改动不涉及 README.md 或其他文档更新。

类型标签

  • [x ] 其他,请描述:规范化整改(dtype 分发机制对齐 + InferShape/InferDataType 补全)

AI/Agent生成声明

  • [ x] AI辅助编写
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 张伟伟 的贡献)
张伟伟
23 天前 创建了 pull request,commit 05ad486f
张伟伟
23 天前 关联了issue:[Bug-Report|缺陷反馈]: relu6 算子 dtype 分发机制不是由def驱动,且缺少 InferDataType 图模式推理实现。
atomgit-bot
atomgit-bot
23 天前 评论:

变更摘要

本次 PR 对 relu6 算子进行规范化整改,重点对齐仓内标准的 dtype 分发机制并补全形状/类型推导实现。核心改动包括:新增 InferDataType 实现,使输出 dtype 直接继承输入 x 的 dtype;移除原先通过 TilingData.dataTypeASCENDC_TPL 模板参数进行 dtype 编码分发的机制,改为由 def 文件声明 DataType 列表、构建系统注入 DTYPE_X 宏的方式驱动 Kernel 类型;同时整理 InferShape 实现并同步更新相关 UT 用例,未涉及算法逻辑变更。

主要改动

  • 新增 InferDataType 实现: 新增 relu6_graph_infer.cpp,注册 InferDataTypeForRelu6,通过 context->GetInputDataType(0) 取输入 x 的 dtype 并设置到输出 y,复用 canndev 仓 InferDtype4SameInput 通用模式。
  • dtype 分发机制对齐: 在 relu6.cpp 中移除模板参数 D_T,Kernel 直接使用 DTYPE_X 实例化 NsRelu6::Relu6,并在 relu6_tiling_key.h 中删除 ASCENDC_TPL_ARGS_DECLASCENDC_TPL_SEL 的 dtype 模板声明。
  • Tiling 侧移除 dataType: relu6_tiling_arch35.cpp 删除 tiling->dataType 赋值和 ASCENDC_TPL_SEL_PARAM 调用,relu6_tiling_data.h 同步移除 int32_t dataType 字段,TilingData 不再存储 dtype。
  • InferShape 规范化: relu6_infershape.cpp 中将 input_shape/output_shape 重命名为 inputShape/outputShape,保持输出形状复制输入形状的逻辑不变。
  • UT 用例同步调整: test_relu6.cpp 中 6 个测试用例移除 tilingData->dataType 赋值,与更新后的 Relu6TilingData 结构体保持一致。
likedislike
atomgit-bot
atomgit-bot
23 天前 评论:

代码审查

✅ 未发现问题

likedislike
CANN-robot
CANN-robot成员
23 天前 评论:

Hi @zhangweiwei11, welcome to submitting your first PR to ops-nn!

PR Merge Steps

1. CLA Signing

If the current PR label includes cann-cla/yes, it means you have signed the CLA and can proceed to the next step. If the label includes cann-cla/no, please sign the CLA first. If you have any questions, please refer to the FAQ.

2. CI Check

Please comment /compile to trigger the CI pipeline check. If the CI run is successful, the PR will be tagged with ci-pipeline-passed and you can proceed to the next step. If the CI run fails, the PR will be tagged with ci-pipeline-failed, please check the CI logs to fix the issues in the PR. If you have any questions, please refer to the FAQ.

3. Code Review

After CI passes, please refer to the PR Approval Progress and proactively @ the committers in the table to review the code. After approval, committers will comment /lgtm and /approve. Once the lgtm and approved labels are successfully added, the PR will be merged automatically.

likedislike
此处折叠了54条消息 查看更多
RuiWang_成员
19 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
19 天前 添加了label:lgtmapproved
CANN-robotCANN-robot成员
19 天前 关闭了关联的issue
CANN-robotCANN-robot成员
19 天前 合入了pull request
CANN-robot
CANN-robot成员
19 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike