Merged
[bugfix] broadcast tiling preferMultiCore 分块调整增加上界clamp #1066
hahaha22Add on Oct 23
[bugfix] broadcast tiling preferMultiCore 分块调整增加上界clamp #1066
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for hahaha22's contribution.)atomgit-bot
Oct 23 Comments:
Oct 23 Comments:
变更摘要
本次变更修复 DoBrodcastTiling 中 preferMultiCore 分块调整逻辑的两处边界缺陷:一是在按 CACHE_LINE 递减 maxElemNum 的循环中,将下界判断前移到减法之前,避免初值小于 CACHE_LINE 时无符号减法回绕导致 tiling 无法返回;二是在最终对齐恢复表达式后增加上界钳制,保证 maxElemNum 不超过进入分支前保存的原始 UB 容量。改动集中在 broadcast_tiling.cpp,仅影响 preferMultiCore=true 且 blockNum < coreNum 的多核切分调整路径。
主要改动
- 保存原始容量基准:新增
originMaxElemNum记录进入多核调整分支前的maxElemNum,作为后续上界钳制的比较基准。 - 循环下界前置检测:将退出条件改为
maxElemNum <= CACHE_LINE_512 + CACHE_LINE并在减法前判断,消除无符号下溢死循环,同时保持原有“减后仍大于CACHE_LINE_512才继续”的推进语义。 - 恢复表达式简化与上界钳制:对齐上取整改为
(maxElemNum + CACHE_LINE - 1) / CACHE_LINE * CACHE_LINE,去掉额外的CACHE_LINE补偿,并在结果超过originMaxElemNum时回退为原始容量,维持maxElemNum不超过原始 UB 容量的不变量。 - 保证多核切分目标可达:通过上界钳制避免对齐增量抬高容量或使已达标的多核切分因子回落,使
fusedProduct、blockFormer与blockNum的后续更新基于合法容量计算。


Incorrect?
atomgit-bot
Oct 23 Comments:
Oct 23 Comments:
Oct 23 Added label: cann-cla/yes
CANN-robot
Oct 23 Comments:
Oct 23 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 |
|---|---|---|
| repo-cann/opbase | ✅ 宋恺, 汤平川 (2/2) | ✅ 宋恺, 汤平川 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
hahaha22, thanks for your pull request. All authors of the commits have signed the CLA. 👍


69 messages are collapsed here。 See more
Oct 27 Added label: approved
TangPC
Oct 27 Comments:
Oct 27 Comments:
/lgtm
/approve


Oct 27 Added label: lgtm
Oct 27 Closed associated issue
Oct 27 Merged pull request
描述
DoBrodcastTiling的 preferMultiCore 分块调整中,恢复表达式(maxElemNum + 2*CACHE_LINE - 1)/CACHE_LINE*CACHE_LINE(对齐上取整并补偿一条 CACHE_LINE)在对齐增量与补偿作用下可越出进入分支时的原始容量BroadcastGetMaxElemNum(ubSize, computeParams):越出后的 maxElemNum 传入 ubFormer 与 DMA 尺寸计算,破坏容量不变量,可产生物理 UB 越界。Ascend960 侧模板已强制开启 preferMultiCore(
isAscend960_),该路径覆盖全部 broadcast 模板算子。修复:进入分支时保存原始容量,恢复表达式保持不变,其后增加上界 clamp(+4 行):
const uint64_t originMaxElemNum = maxElemNum; ... maxElemNum = (maxElemNum + CACHE_LINE + CACHE_LINE - 1) / CACHE_LINE * CACHE_LINE; if (maxElemNum > originMaxElemNum) { maxElemNum = originMaxElemNum; }关联的Issue
修复 #561
https://gitcode.com/cann/opbase/issues/561
测试
origin maxElemNum: 7872 → maxElemNum: 7936,折合字节越过物理 UB 1024B;文档更新
无(纯 tiling 逻辑改动,不涉及对外文档)。
类型标签