Merged
fix(max_pool3d_grad): 修复 NDHWC C 轴切分 UB 越界 #13160
fix(max_pool3d_grad): 修复 NDHWC C 轴切分 UB 越界 #13160
Merged
小王!Add on 22 days ago
小王!
小王!Collaborators
22 days ago

描述

修复 MaxPool3DGrad NDHWC 路径下 C 轴切分错误下发 cOutputInner 导致的 UB 越界。

NDHWC + FP16 场景下,当 cX < moveDataNumCacheLine(FP16 为 64)且 D/H/W 对齐切分均不可行时,TrySplitAlignC() 会把已通过 IsMeetUBSize 校验的 cOutputInner=cX 覆盖为 64;同时二分搜索的 bestSplit 初值为 1,最终下发未通过 UB 校验的值。DoBufferCalculate() 据此以 cAligned=64 放大所有 UB Buffer,Kernel 的 MTE2/Vector 访问越界并触发 AIVEC。

修复保持原二分搜索上界 CeilDiv(cX / 2, moveDataNumCacheLine) 不变:将 bestInner 初值设为已通过 UB/CoreNum 校验的 tmpCAligned,仅允许通过校验的候选更新 bestInner,最终 cOutputInner = min(bestInner, cX) 并保留原 proDataNumInOneBeat 钳位。该约束保证 cX=15 时最终下发 15 而不是 64,且不改变大 C 场景的搜索策略。

同时修正两条仍按缺陷态 cOutputInner=64 写期望的 NDHWC big-kernel UT,使其与 C=8 的正确切分口径一致,并按新的 cAligned=16 重算 Buffer 期望值。

关联的Issue

#7806
https://gitcode.com/cann/ops-nn/issues/7806

测试

  • Host pre-push 门禁通过:ophost UT PASSED、ascend950 pkg PASSED。
  • 已覆盖 C=8 的 NDHWC big-kernel UT;修复后按 cInner=8、cAligned=16 校验 Buffer 期望值。
    本地复测批跑精度全pass,david冒烟通过

文档更新

不涉及

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 小王!'s contribution.)
小王!小王!Collaborators
22 days ago Created pull request, commit 1754d2b8
atomgit-bot
atomgit-bot
22 days ago Comments:

变更摘要

本 PR 修复 pool3d_grad_ndhwc_small_kernel_tiling.cpp 中 Pool3DGradNDHWCSmallKernelCommonTiling::TrySplitAlignC() 在 NDHWC + FP16 场景下的 C 轴切分问题:当 cX < moveDataNumCacheLine 且 D/H/W 对齐切分均不可行时,原逻辑会把已通过 IsMeetUBSize 校验的 cOutputInner 覆盖为 moveDataNumCacheLine(FP16 为 64),导致 DoBufferCalculate 以放大的对齐值申请 UB Buffer,Kernel 的 MTE2/Vector 访问越界并触发 AIVEC。修复仅涉及 tiling 计算逻辑,保持按 UB 尺寸校验结果兜底。

主要改动

  • 保留已校验的 cOutputInner 作为兜底:二分搜索的候选变量由 bestSplit = 1 改为 bestInner = tmpCAligned,使初始已通过 IsMeetUBSize/IsMeetTargetCoreNum 校验的切分值在找不到更大可行倍数时不被丢弃。
  • 调整二分搜索上界与候选赋值:right 由 CeilDiv(inputData->cX / 2, baseData.moveDataNumCacheLine) 改为 inputData->cX / baseData.moveDataNumCacheLine,命中时直接以 splitData.cOutputInner = mid * moveDataNumCacheLine 记录可行值,而非仅记录倍数。
  • 新增切分结果不超出 cX 的约束:二分命中条件增加 splitData.cOutputInner <= inputData->cX,避免下发超过实际 C 轴长度的 cOutputInner。
  • 统一最终钳位逻辑:以 splitData.cOutputInner = std::min(bestInner, baseData.proDataNumInOneBeat) 替代原先按 bestSplit 重新计算再条件判断的上限截断,保证下发的 cOutputInner 同时受已验证值与单拍处理量约束。

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

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

代码审查

审查结论

变更文件核查:

  • pooling/pool_grad_common/op_host/arch35/pool3d_grad_ndhwc_small_kernel_tiling.cpp:已逐行核查 TrySplitAlignC(198-226)以及 Pool3DGradNDHWCSmallKernelCommonTiling 的其余调用链(SearchBestTiling、DoUBTiling、AdjustInnerSplitForMultiCore、DoBlockTiling、SplitUnalignDHWC、IsMeetTargetCoreNum),并比对了同算法的孪生实现(pool_grad_tiling_split_helper.h 的 TrySplitAlignC / SearchMaxSplit)。共 3 个发现。

发现的优先级分布:P0=0,P1=0,P2=1,P3=2。

主要判断:

  1. 修复本身方向正确。bestInner 以第 208 行已通过 IsMeetUBSize && IsMeetTargetCoreNum 的 tmpCAligned 兜底,right = cX / moveDataNumCacheLine 保证 mid*CL <= cX,cX < CL 时循环直接跳过并保留 cX,因此“下发 64 > cX”的越界路径在 NDHWC 侧被消除;IsMeetUBSize/IsMeetTargetCoreNum 对 cOutputInner 单调,二分找最大可行倍数的前提成立;最后 min(bestInner, proDataNumInOneBeat) 只会把值调小(FP16 下 proDataNumInOneBeat == moveDataNumCacheLine == 64,FP32 下为其 2 倍),不会产出比已验证值更“大”的未校验配置。
  2. P2:该修复只覆盖了两份同算法实现中的一份——共享 helper(NHWC / max_pool_grad_with_argmax 路径)仍是“bestSplit 初值 1 + 下发 bestSplit*multiplier”的旧形态,cX < cacheline 时同样会下发 64 > cX,同型 AIVEC 越界在 NHWC 侧仍存在;本文件 SplitUnalignDHWC 亦保留同型写法。建议统一到共享实现。
  3. 两个 P3 分别为恒真判据(可选清理)与 C 轴边界分支缺少 UT(cX < moveDataNumCacheLine 的兜底路径无回归拦截)。

整体风险判断:中低。核心越界缺陷已按预期收敛,但同一 tiling 算法存在两套分叉实现,孪生路径的风险未随之关闭;建议合并前确认是否在本 PR 内同步 helper,或明确登记后续修复。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论


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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
22 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
22 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
pooling ✅ 上官秦南, 张志伟 (2/2) ✅ 上官秦南 (1/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
49 messages are collapsed here。 See more
sgqt12
sgqt12Collaborators
19 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
19 days ago Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
19 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
19 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
19 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike