Closed
[Bug-Report|缺陷反馈]: broadcast tiling preferMultiCore 分块调整可越过 UB 容量上限 #561
hahaha22Add on  Oct 26Closed at  Oct 27
hahaha22
hahaha22Collaborators
Oct 26 Create

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

src/op_common/atvoss/broadcast/broadcast_tiling.cpp 的 DoBrodcastTiling 中,preferMultiCore 分块调整的恢复表达式 (maxElemNum + 2*CACHE_LINE - 1) / CACHE_LINE * CACHE_LINE(对齐上取整并补偿一条 CACHE_LINE)在对齐增量与补偿作用下,可越出进入该分支时的原始容量 BroadcastGetMaxElemNum(ubSize, computeParams):

  • 容量非 CACHE_LINE 对齐(minDtypeBits≥32 的 dtype,对齐粒度 2048/minDtypeBits)且循环执行一轮:roundup(M−128)+128 = M+64;
  • 容量对齐但循环未执行:roundup(M)+128 = M+128。

越出后的 maxElemNum 传入 ubFormer 与 DMA 尺寸计算,可产生物理 UB 越界。broadcast_tiling.h 中 Ascend960 侧 isAscend960_ 强制开启 preferMultiCore,该路径覆盖全部 broadcast 模板算子。

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

硬件:Ascend950PR(触发形态 950 真机实测)
CANN:opbase master(2026-10-23 基线 de414d0)
检查基线:src/op_common/atvoss/broadcast/broadcast_tiling.cpp DoBrodcastTiling
复现工具:TTK kernel 模式 tiling dump + tiling 日志观测

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

  1. 在 950(Ascend950PR)以 int32 FloorMod 构造触发 preferMultiCore 分块调整的广播形态(如 [3488,123]×[3488,1],k=1 恢复路径,容量 M=7872 ≡ 64 mod 128);
  2. 观测 tiling:进入分支时原始容量 7872,恢复表达式作用后 maxElemNum=7936(M+64);
  3. 按 7936 元素折算的 UB 占用越过物理 UB 1024B(原始容量下 UB 占用已饱和)。

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

preferMultiCore 分块调整后的 maxElemNum 不应越过进入分支时的原始容量(容量不变量 final ≤ BroadcastGetMaxElemNum(...)):恢复表达式之后应增加上界 clamp,clamp 命中时取原始容量(该值为容量推导结果,天然满足 dtype 对齐粒度,为合法容量);clamp 不命中时行为保持不变。

修复前 tiling 观测:origin maxElemNum: 7872 → maxElemNum: 7936(int32 触发形态,越过物理 UB 1024B)。


关联 PR:!1066(broadcast tiling preferMultiCore 分块调整增加上界clamp)
https://gitcode.com/cann/opbase/pull/1066

likedislike
hahaha22hahaha22Collaborators
Oct 26 Modify description of issue
陈思
陈思
Oct 27 Comments:

/assign @hahaha22

likedislike
CANN-robotCANN-robotCollaborators
Oct 27 Assign hahaha22 as responsible person
CANN-robotCANN-robotCollaborators
Oct 27 Close issue
CANN-robotCANN-robotCollaborators
Oct 27 Added label: resolved