Pull Request已成功合入, 合并人@chenwenqiao
(感谢 hujiajun 的贡献)libing-pipeline创建中,请等待……


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
PR Approval Progress
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/AscendNPU-IR | ❌ (0/2)(You can also ask: ardazishvili, Zz_zl, blueyi, amywang1212, dainbow) | ❌ (0/1)(You can also ask: tarvlad, 周浩, michael_hliao, 海丽娟, dainbow) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Hu_JJN, thanks for your pull request. All authors of the commits have signed the CLA. 👍


变更摘要
此 PR 修复了 AscendNPU IR 中 PlanMemory 阶段因 0 大小临时缓冲区(temp buffer)导致的内存规划溢出问题。当内存使用量恰好等于 memory scope 大小时,原有的严格小于比较 iter->second < restBufferSize 会错误判定内存不足,导致 fallback 到无复用规划路径。同时,SpecAlloc 方法在遇到 alignedConstBits == 0 的 0 大小临时缓冲区时,因除零或溢出风险而缺少提前返回的防护。该修复通过两处代码调整和新增测试用例,确保 0 大小 temp buffer 场景下内存规划的正确性。
主要改动
IsEnoughForBuffersNoReuse比较条件修正: 将if (iter->second < restBufferSize)改为if (iter->second <= restBufferSize),使得当所需内存恰好等于 scope 可用大小时也能正确走无复用规划路径,而非错误地继续尝试复用。SpecAlloc增加 0 大小缓冲区保护: 在SpecAlloc中新增对e->alignedConstBits == 0的判断,将bitsOffset直接置为 0 并提前返回success(),避免对 0 大小临时缓冲区的不必要处理与潜在异常。- 新增测试用例
test_mem_noreuse_max: 验证当 temp buffer 为memref<0xi64>时,IsEnoughForBuffersNoReuse修复后不再错误分配新内存(CHECK-NOT: memref.alloc())。 - 新增测试用例
test_mem_specalloc_max: 验证SpecAlloc修复后,0 大小 temp buffer 的pointer_cast能正确获得偏移量 0(%[[CONST0]]),而其他正常缓冲区不受影响。


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


代码审查
经过全面审查,这两个变更都是正确的,没有发现任何问题。
关闭摘要
-
bishengir/lib/Dialect/HIVM/Transforms/PlanMemory.cpp:已审查,无问题。两处修改均为正确的边界条件修复:
IsEnoughForBuffersNoReuse中<改为<=(第 1761 行),修复了当 buffer 所需空间刚好等于可用空间时错误进入复用路径的边界 bug。SpecAlloc中新增alignedConstBits == 0的提前返回(第 2120-2123 行),防止 0-size temp buffer 进入 speculative allocation 循环导致溢出。
-
bishengir/test/Dialect/HIVM/plan-memory.mlir:已审查,无问题。两个新增测试用例正确验证了上述两项修复:
test_mem_noreuse_max:验证空间刚好填满时走 no-reuse 路径。test_mem_specalloc_max:验证含 0-size buffer 场景下 specalloc 路径的正确行为(0-size buffer 获得 offset=0,其他 buffer 正确复用)。
整体风险评估:低风险。变更为精准的边界条件修复,测试覆盖到位。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


描述 Description
请提供此 Pull Request 的高级别说明。
Please describe what this PR is about.
类型 Category
Checklist