Closed
[Bug-Report|缺陷反馈]: MaxPool3DGrad NDHWC C 轴切分错误下发 cOutputInner 导致 UB 越界 #7806
小王!Add on  22 days agoClosed at  19 days ago
小王!
小王!Collaborators
22 days ago Create

Describe the current behavior / 问题描述 (Mandatory / 必填)

MaxPool3DGrad 在 NDHWC + FP16 场景下,当 cX < moveDataNumCacheLine(FP16 为 64)且 D/H/W 对齐切分均不可行时,TrySplitAlignC() 会把已通过 IsMeetUBSize 校验的 cOutputInner=cX 覆盖为 64;同时二分搜索的 bestSplit 初值为 1,最终下发未通过 UB 校验的 cOutputInner。

DoBufferCalculate() 据此以 cAligned=64 放大所有 UB Buffer,Kernel 的 MTE2/Vector 访问越界,触发 AIVEC。

复现用例(FP16、NDHWC、VALID、TilingKey=513):

  • x=(16,26,26,22,15), grads=(16,3,2,4,15), k=[1,3,1,4,1], s=[1,11,19,5,1] → cX=15,small kernel
  • x=(2,149,2,1593,2), grads=(2,7,1,106,2), k=[1,17,2,12,1], s=[1,20,8,15,1] → cX=2,big kernel

Environment Information / 环境信息 (Mandatory / 必填)

  • 昇腾硬件型号:Ascend950PR_958b(arch35 / AIV 64 核,ub_size=253952 B)
  • CANN 版本:9.3.0
  • Python 版本:3.x
  • 数据类型/格式:FP16 / NDHWC
  • 运行方式:TTK kernel,Dynamic/Const/Release 三种模式

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 使用上述 Shape、ksize、strides、padding=VALID 构造 MaxPool3DGrad(max_pool3d_grad)用例。
  2. 执行 Dynamic/Const/Release Kernel。
  3. 观察 Host Tiling 中 cOutputInner 被下发为 64(正确值应为 cX=15/2),cAligned 由 16 变为 64,inputBufferSize/outputBufferSize 被放大。
  4. 观察 Kernel 出现 AIVEC / MTE2 写 UB 越界。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

TrySplitAlignC() 应保留已经通过 UB/CoreNum 校验的 cOutputInner=min(cX, moveDataNumCacheLine) 作为兜底,二分搜索只允许用通过校验的候选更新最优值,最终下发值不得大于 cX。上述用例应得到 cOutputInner=15/2、cAligned=16,TilingKey/BlockDim 保持不变,不出现 UB 越界。

EZ9999: Internal error!
aivec error
error code = 263, 82
subErrType: 0x4
The address for scalar to use is unaligned or out of bounds.
The GM address exceeds 48 bits, or the on-chip buffer
address exceeds the size of the buffer.
The address for MTE2 to write UB and MTE3 to write L1/UB
is out of bounds.

静态分析关键证据:

  • TrySplitAlignC() 中初始 tmpCAligned=cX 已通过 IsMeetUBSize() && IsMeetTargetCoreNum();
  • bestSplit=1 的非法默认值导致最终无条件写回 bestSplit * moveDataNumCacheLine;
  • cX=15 时最终下发 64,DoBufferCalculate() 以 cAligned=64 计算 Buffer;
  • Case01 inputBufferSize=274560 B、Case02 outputBufferSize=614400 B,均超过 UB 预算。

Special notes for this issue/备注 (Optional / 选填)

  • 修复 PR:https://gitcode.com/cann/ops-nn/pull/13160
  • 修复思路:保留已验证的 tmpCAligned 作为兜底;二分搜索仅在候选通过原有 UB/CoreNum 校验时更新最优值;最终 min(bestInner, cX) 并保留原 proDataNumInOneBeat 钳位;不改变原二分搜索上界。
  • 同类风险:FP32 下 moveDataNumCacheLine=32,cX<32 也存在同类路径,建议一并覆盖回归。
likedislike
小王!小王!Collaborators
22 days ago Added label: bug
yuning_chenyuning_chenCollaborators
22 days ago Assign qq_52056150 as responsible person
CANN-robotCANN-robotCollaborators
19 days ago Close issue
CANN-robotCANN-robotCollaborators
19 days ago Added label: resolved