已合并
[AscendNPU IR] [PlanMemory] Fix: fix planmemory level1 reuse on pong buffers #1450
[AscendNPU IR] [PlanMemory] Fix: fix planmemory level1 reuse on pong buffers #1450
已合并
SL25创建于 7月8日
SL25成员
7月8日

描述 Description

  1. Only first buffer(not other relation entries) can reuse in level1. If current entry is not first buffer, stage1 should be conflict.
  2. Fix level1 multi-buffer reuse multi-buffer when buffer sizes are equal.

regbase: https://gitcode.com/Ascend/AscendNPU-IR/pull/1414

  1. Fix level1 multi-buffer reuse multi-buffer when buffer sizes are not equal.

类型 Category

Checklist

likedislike
Pull Request已成功合入, 合并人@tanshengshun
(感谢 SL25 的贡献)
SSL25成员
7月8日 创建了 pull request,commit 18e3ef3c
atomgit-bot
atomgit-bot
7月8日 评论:

变更摘要

此 PR 修复了 AscendNPU PlanMemory level1 复用阶段中关于 pong buffer 的两个缺陷:一是 level1 仅允许首个 buffer(非其他关联条目)参与复用,当前条目若非首个 buffer 则应标记为冲突;二是修复了当 buffer 大小相等时 level1 多 buffer 复用多 buffer 场景下判断条件不正确的问题。同时新增了三个测试用例覆盖单 buffer 复用、等大小多 buffer 复用和较少多 buffer 复用场景。

主要改动

  • VerifyConflictStage1 冲突判断逻辑修正:将多 buffer 复用时对 otherBufferEntries 数量的检查条件从 otherBufferEntries.size() < e->multiBufferNum 改为 otherBufferEntriesSize < e->multiBufferNum - 1 || e->otherBufferRelationEntries.empty(),确保仅首个 buffer 能在 level1 中复用,当前条目若非首个 buffer 则返回冲突,同时遍历上限从 e->multiBufferNum 改为 otherBufferEntriesSize 以适配调整后的逻辑。

  • PlanRelationOtherBufferEntryAddress 增加兜底分支:当 level1 复用中 e->otherBufferRelationEntries 无法匹配时,新增 else 分支触发 llvm_unreachable,明确 level1 不支持其他 buffer 条目的地址规划,防止未定义行为。

  • 新增三个 level1 复用测试用例:在 plan-memory.mlir 中添加 test_mem_level1_single_buffer_reusetest_mem_level1_equal_multi_buffers_reusetest_mem_level1_less_multi_buffers_reuse,均通过 CHECK-NOT: memref.alloc() 验证 buffer 被成功复用而非重新分配。

  • 代码格式化微调:修复了 report_fatal_error 的字符串拼接格式以及 IsDeadAfterOp 的参数对齐,无功能影响。

likedislike
ascend-robot
ascend-robot成员
7月8日 评论:

libing-pipeline创建中,请等待……

likedislike
atomgit-bot
atomgit-bot
7月8日 评论:

代码审查

关闭总结

审查文件

  • bishengir/lib/Dialect/HIVM/Transforms/PlanMemory.cpp:✅ 已审查,发现 2 个问题(均为 P3)
  • bishengir/test/Dialect/HIVM/plan-memory.mlir:✅ 已审查,无问题

问题统计

优先级 数量
P0 0
P1 0
P2 0
P3 2

总体风险评估

低风险。本次变更修复了 level1 multi-buffer 复用在 buffer 数量相等时的误判冲突问题,核心逻辑正确。但有 2 个 P3 级别的边界问题值得关注:

  1. 单 buffer 场景循环行为变更(confidence 0.7):VerifyConflictStage1 中循环上界从 e->multiBufferNum(单 buffer 时为 1)改为 otherBufferEntriesSize,可能导致单 buffer level1 复用出现误判冲突或产生多余的 relation 条目。该变更可能是 multi-buffer 修复的无意副作用。

  2. Multi-buffer 场景过度检查(confidence 0.5):当历史条目的 otherBufferRelationEntries 多于当前条目所需时,循环会检查多余条目,可能导致合法复用被拒绝。触发条件较罕见(需要不同 multiBufferNum 的条目间复用)。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
SSL25成员
7月8日 修改了pull request 的描述
此处折叠了91条消息 查看更多
ascend-robotascend-robot成员
7月10日 添加了label:approved
chenxiangting
chenxiangting成员
7月10日 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
7月10日 添加了label:lgtm
ascend-robot
ascend-robot成员
7月10日 评论:

You do not have permissions to push into target branch

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
Ttanshengshun成员
7月10日 合入了pull request,合并节点 SHA:783ac918ea1ddee5e43f34464148595ceebd2b69