已合并
refactor(pooling): share ascend950 host and kernel helpers #10034
refactor(pooling): share ascend950 host and kernel helpers #10034
已合并
小王!创建于 9月8日
小王!
小王!成员
9月8日

描述

  1. Host/Tiling 公共逻辑收编:统一 AvgPoolGrad/AvgPoolV2Grad 的公共结构、Padding 计算、Shape/Dtype 解析及维度常量。
  2. AdaptivePool3D 参数结构收编:抽取 Avg/Max AdaptivePool3D 共用的 ComputeInfo 字段,保持原有内存布局和序列化行为不变。
  3. Big Kernel 公共能力收编:复用 Pool3D 公共的 Cast、数据读写、索引计算、ReduceMaxWithIndex 及 Sum 计算逻辑。
  4. 数据搬运逻辑收编:统一 AvgPool/MaxPoolV3 的多行 CopyIn、UB Strided Copy 等重复搬运实现,保持偏移和 DataCopy 参数不变。
  5. Small Kernel 与 3D Grad 基类收编:抽取公共 IO 初始化、队列、Buffer、Tiling 解析及成员字段,减少多个 Kernel 类重复代码。
  6. 严格限定等价代码整改:仅合并完全一致逻辑,不修改 IsCapable、TilingKey、UB 公式、切分策略、Workspace、精度及跨芯片实现。

关联的Issue

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

测试

受影响的算子复跑门槛用例均无引入功能问题,性能无劣化,线上David冒烟和OBP冒烟均已通过

文档更新

不涉及

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 小王! 的贡献)
小王!小王!成员
9月8日 创建了 pull request,commit 1ceb39b2
atomgit-bot
atomgit-bot
9月8日 评论:

变更摘要

本 PR 是 ascend950(arch35)pooling 系列算子的重构:将 host tiling 与 kernel 中重复的公共逻辑抽取为共享基础类与工具函数,并大规模重命名结构体以避免跨算子符号冲突。kernel 侧新增 Pool3DGradNcdhwKernelBase(收编 3D 池化梯度 NCDHW kernel 的 46 项公共 tiling 字段与 ParseTilingData 解析)、MaxPoolGradNchwCommonFields(NCHW scatter/backward 基类共用字段)、Pool2DSmallKernelIoBase(二维池化 small kernel 共用 pipe/队列/buffer 与 InitIo 逻辑)以及 PoolUtils::Compute::AccumulateSumFp32、PoolUtils::DataMove::CustomCopy、PoolUtils::DataMove::BigKernel::CopyInMultiRowsNhwc 等工具接口;host 侧将 avg_pool_grad 与 avg_pool_v2_grad 的公共计算(CalcAvgPoolGradSamePad、CalcAvgPoolGradShapeInfo、AvgPoolV2GradCommon)下沉到 avg_pool_v2_grad_tiling_common.h,并在 adaptive_pool3d_tiling.h 中抽取 AdaptivePool3dComputeInfo。整体上通过删除各算子内的重复实现、改调共享接口,降低了跨算子维护成本。

主要改动

  • 新增 kernel 公共基类收编公共字段与解析逻辑:新增 pool_3d_grad_kernel_base.h(Pool3DGradNcdhwKernelBase)、max_pool_grad_nchw_fields_common.h(MaxPoolGradNchwCommonFields)、pool_2d_small_kernel_base.h(Pool2DSmallKernelIoBase),max_pool3d_grad、max_pool3d_grad_with_argmax、max_pool_grad NCHW、avg_pool/max_pool_v3 small kernel 等派生类改为继承这些基类,删除各自重复声明的成员字段与 ParseTilingData/Init 实现。
  • 抽取 kernel 级共享工具函数:新增 pool_sum_compute.h(AccumulateSumFp32,供 avg_pool 与 pool_3d_common big kernel 的非 fp32 部分和累加复用)、pool_ub_strided_copy.h(CustomCopy,替换 avg_pool/max_pool_v3 pad kernel 内重复的 UB 跨步拷贝实现)、pool_2d_row_data_move.h 新增 CopyInMultiRowsNhwc(替换 avg_pool/max_pool_v3 NHWC big kernel 各自的 CopyInMultiRows/CopyInMultiRowsContiguous),max_pool_with_argmax_v3 big kernel 改为复用 pool_big_kernel_utils.h 的 CalcRealIndex、ReduceMaxWithIndex 等辅助函数。
  • host tiling 侧公共逻辑下沉:在 avg_pool_v2_grad_tiling_common.h 中集中定义 AvgPoolV2GradCommon、CalcAvgPoolGradSamePad、CalcAvgPoolGradShapeInfo,删除 avg_pool_grad_tiling_base 与 avg_pool_v2_grad_tiling_base 中各自重复的 pad 计算与 shape 解析实现;在 adaptive_pool3d_tiling.h 中新增 AdaptivePool3dComputeInfo,adaptive_avg_pool3d_para_tiling/adaptive_max_pool3d_para_tiling 改以继承方式复用,并统一将 avgComptuteInfo_ 更名为 avgComputeInfo_。
  • 跨算子结构体类型重命名避免符号冲突:将多文件内通用的 BaseInput、InputInfo、ComputeInfo、InputSIMTInfo 等改为带算子前缀的唯一类型名,如 AdaptivePool2dBaseInput、AdaptivePool3dBaseInput、AdaptiveMaxPool2dInputInfo、MaxPoolWithArgmaxInputInfo、MaxPoolV3InputInfo、MaxPool3DGradWithArgmaxDhwInputInfo、MaxPoolWithArgmaxV3InputSIMTInfo 等,并同步更新对应类成员与函数参数类型。
  • 同步更新单测引用:max_pool_grad 的 UT(test_max_pool_grad_tiling.cpp)删除本地重复定义的 MaxPoolGradWithArgmaxCompileInfo,改为直接包含 max_pool_grad_tiling.h 头文件。
likedislike
不准确?
atomgit-bot
atomgit-bot
9月8日 评论:

代码审查

✅ 未发现问题

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

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
pooling ✅ 钱泽洪, 刘闯 (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 Pass

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

likedislike
CANN-robotCANN-robot成员
9月8日 将zengjuan,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,su-yueming,chenqi317,wang-xing001,liubo75,tangweiwei2,chenxingyu18,pingchuantang,qianzehong,liuchuangdev设为评审人
CANN-robotCANN-robot成员
9月8日 将kevin_huang1234,su-yueming,wang-xing001,chenxingyu18,pingchuantang,qianzehong,liuchuangdev设为审查人
小王!
小王!成员
9月8日 评论:

compile

likedislike
小王!小王!成员
9月8日 预合并成功(commit_id: 833dac7b1defac82fc7cb9f5659eaf614699460e)
CANN-robot
CANN-robot成员
9月8日 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
9月8日 添加了label:ci-pipeline-running
小王!小王!成员
9月8日 修改了pull request 的描述
小王!小王!成员
9月8日 修改了pull request 的描述
yuning_chen
yuning_chen成员
9月8日 评论:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike
CANN-robotCANN-robot成员
9月8日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
9月8日 添加了label:ci-pipeline-passed
qianzehong成员
9月9日 评论:

/approve

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

/approve

likedislike
CANN-robotCANN-robot成员
9月9日 添加了label:lgtm
CANN-robotCANN-robot成员
9月9日 合入了pull request