| Files | Last commit | Last update |
|---|---|---|
fix(adjacent_difference): tiling 计入核内固定 UB 开销并修复整寄存器加载越界 Co-authored-by: wangrunfa<wangrunfa1@huawei.com> Co-authored-by: wkx12138<weikaixuan@h-partners.com> # message auto-generated for no-merge-commit merge: !7302 merge adj into master fix(adjacent_difference): tiling 计入核内固定 UB 开销并修复整寄存器加载越界 Created-by: wkx12138 Commit-by: wangrunfa;wkx12138 Merged-by: cann-robot Description: ## 描述 修复 adjacent_difference 算子两个 UB 越界问题: 1. **Tiling UB 预算与 Kernel 实际申请不符**:tiling 以 ubSize/(sizeof(in)+sizeof(out)) 约束 tilingNum,未计入 kernel 侧 onesBuf_(sizeof(OUT_TYPE))与 int64 输出 yQueue_ 的 2*BLOCKSIZE 对齐余量,大 shape 触顶时三段 InitBuffer 总量超出 UB(int64 出全 dtype 组合超 8~72B,int32 入/int32 出超 4B)。修复:上限公式改为 (ubSize - 预留) / (sizeof(in)+sizeof(out)),预留 = 2*BLOCKSIZE(x1Queue_ 加载余量 + onesBuf_),int64 出再 +2*BLOCKSIZE(yQueue_ 对齐余量)。 2. **x1Queue_ 整寄存器加载越界**:x1Queue_ 仅按 tilingNum_ 个元素分配,四个计算分支以整寄存器宽度 LoadAlign/LoadUnAlign(+1 偏移)加载,满块 tile 时最大物理读索引 nLoop*vLength_ 可超过 tilingNum_(最多 224B);且 mask 以总长 UpdateMask(copyLen>vLength_ 时饱和为全 mask),尾轮越界读入的垃圾以整寄存器宽度写回 yQueue_,连带越界写。修复: - tiling 取整粒度从 32B(blockNum)提升为整寄存器 256B(vRegNum)倍数,满块 tile 物理读越界收敛为恰好 +1 元素; - x1Queue_ 增加 +BLOCKSIZE 余量覆盖该 +1 元素(LoadUnAlign 的 +1 偏移); - 四个计算分支 mask 改为按每轮剩余元素数更新,store 严格收敛于 copyLen 内。 ## 关联的Issue https://gitcode.com/cann/ops-math/issues/4717 ## 测试 - ophost UT 13/13 通过:新增 int64 出(16352)/int32 出(32704)两个 UB 触顶用例(旧代码下分别产出超限的 16384/32768);原 tiling 与 8 个 infershape 用例期望值不受影响 - bash build.sh --opkernel --soc=ascend950 --ops=adjacent_difference 编译通过(22 个 dtype 变体全部生成) - 核算 8 种 dtype 组合触顶 tilingNum 的核内实际 UB 分配,全部 ≤ ubSize;4 个 SoC(950/350/960dt/960pr)同为 dav_3510,host/device GetVRegSize 恒 256B,对齐不变量全域成立 - 本地已跑st,精度pass - 冒烟已跑 ## 文档更新 无 ## 类型标签 - [x] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/ops-math!7302 | 7 days ago |