Closed
[Bug-Report|缺陷反馈]: (adjacent_difference): tiling 计入核内固定 UB 开销并修复整寄存器加载越界 #4717
wkx12138Add on  7 days agoClosed at  6 days ago
wkx12138Collaborators
7 days ago Create

一、问题描述 (必填)

Tiling UB 预算未计入 Kernel 追加分配:Tiling 以 ubSize/(sizeof(in)+sizeof(out)) 约束 tilingNum,未计入 Kernel 的 onesBuf_ 与 int64 输出 2*BLOCKSIZE 对齐余量;tilingNum 触顶时实际 UB 申请超出预算上限。

x1Queue_ 本地缓冲区整寄存器越界读:x1Queue_ 仅按 tilingNum_ 个元素分配,四个计算分支以整寄存器宽度 LoadAlign/LoadUnAlign 加载,最大物理读索引 nLoop*vLength_ 可超过 tilingNum_。

二、环境信息 (可选)

昇腾硬件型号:Ascend950

三、重现步骤 (可选)

在 tilingNum 触顶的大 shape(如 int64→int64、aivCoreNum=64 时 totalSize>=1587264≈1015808)下,最后一个 InitBuffer 越过 UB 上限:AscendC 实现以 TOTAL_UB_SIZE=2481024(arch3510)为池上限并在 InitBuffer 中做 maxAddr+len<=maxLen 断言,断言生效时内核报错终止,断言被裁剪时 yQueue_/onesBuf_ 越界占用相邻 UB 区域,可能造成数据破坏或未定义行为;返回值为 bool 且未被检查(kernel.h:44-53),失败也不可见。
向量加载读取超出 InitBuffer 声明范围的 UB(int32 例中约 56 个元素/224 字节;int64 因 int64 宽寄存器特征可能更多),读取未初始化或相邻缓冲数据。有效输出通道仅依赖已由 DataCopyPad 写入的元素,故在观察到的路径上数值结果不被污染;但该访问本身越过缓冲区边界,属本地缓冲越界读,若 x1Queue_ 位于 UB 分配末端则可能读到 UB 区域之外。

四、预期结果 (可选)

💡 备注(选填)

likedislike
Wwkx12138Collaborators
7 days ago Added label: bug-report
Wwkx12138Collaborators
7 days ago Assign wkx12138 as responsible person
CANN-robotCANN-robotCollaborators
6 days ago Close issue
CANN-robotCANN-robotCollaborators
6 days ago changed custom state from 待办的 to 已完成
CANN-robotCANN-robotCollaborators
6 days ago Added label: resolved