Pull Request已成功合入, 合并人@CANN-robot
(感谢 leaving__ 的贡献)变更摘要
该 PR 主要针对 HardShrink 算子做了两方面的重构:一是将 dtype 推导改为由 def 驱动,新增图模式的 InferDataType4HardShrink 使输出 dtype 等于输入 dtype,并在 kernel 入口使用 DTYPE_SELF 宏注入 IO 类型,tiling_key 不再编码 dtype 及其衍生的 NEED_UPCAST 维度;二是将计算公式从「三次 Compare+Select(含 NaN 透传)」改为「Abs + Compare(LE) + Select」,即 |x| <= lambd ? 0 : x,与竞品 canndev/torch 的公式顺序对齐。
主要改动
- 新增 dtype 推导实现: 新增
hard_shrink_graph_infer.cpp,通过InferDataType4HardShrink设置输出 dtype 为输入 dtype,并注册到IMPL_OP(HardShrink).InferDataType。 - 复用公共形状推导:
hard_shrink_infershape.cpp中InferShape4HardShrink改为调用Ops::Base::InferShape4Elewise,去掉手写的输入输出 shape 拷贝逻辑。 - tiling_key 去除 dtype/升精维度:
hard_shrink_tiling_key.h与hard_shrink_tiling_arch35.cpp的ASCENDC_TPL_SEL_PARAM只保留BUFFER_MODE,不再编码D_T与NEED_UPCAST。 - kernel 编译期推导升精策略:
hard_shrink.h的模板参数由<T, BUFFER_MODE, NEED_UPCAST>简化为<T, BUFFER_MODE>,NEED_UPCAST改为static constexpr,按T == float推导(fp16/bf16 升精为 fp32,fp32 直通)。 - 计算公式对齐竞品:
hard_shrink.h中计算流程改为Abs、Compare(LE)、Select三步,边界|x| == lambd归 0,NaN/inf依赖 IEEE754 比较语义天然透传;同时复用negLambdBuf作为全零 buffer、tmpBuf存放|x|临时结果。 - kernel 入口接入
DTYPE_SELF:hard_shrink.cpp中hard_shrink入口模板参数只保留BUFFER_MODE,实例化时使用DTYPE_SELF作为 IO 类型。


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.
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 |
|---|---|---|
| activation | ✅ 王星, 唐玮玮 (2/2) | ✅ 王星 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
leaving__, thanks for your pull request. All authors of the commits have signed the CLA. 👍


compile


流水线任务触发成功
任务链接 [3f8661032fac4d3ab79470d7e517feb7][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_report_lcov | ✅ SUCCESS | >>>>> |
[2026-08-17 10:18:08] CI执行结束


流水线任务触发成功
任务链接 [e2d5b97a38614324abb4fd5f919f0c8c][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> |
[2026-08-17 10:09:37] CI执行结束


/lgtm
/approve


/lgtm


描述
关联的Issue
https://gitcode.com/cann/ops-nn/issues/4871
测试
文档更新
类型标签
AI/Agent生成声明