已合并
[HFusion] Replace isFillOp fusion guard with precise DpsInits check #2085
[HFusion] Replace isFillOp fusion guard with precise DpsInits check #2085
已合并
hujiajun创建于 16 天前
hujiajun成员
16 天前

描述 Description

findBestFusedNodeForProducer 中的 isFillOp 保护无条件地阻止了所有类似 fill 的操作作为 producer 参与融合。
将其替换为 canFuseProducer 中的 useAsDpsInits 检查,该检查在 producer 的输出是已存在于 FusedNode 中某个 op 的 DPS init 时阻止融合——因为 FuseIntoContainingOp 在这种模式下会崩溃。
原有的拦截不仅拦得过多,而且可能拦漏。

新增 3 个测试用例:fill-reduce、elementwise-reduce、elementwise-elementwise。

关联 issue : https://gitcode.com/Ascend/AscendNPU-IR/issues/368

类型 Category

  • Bug修复 Bugfix
  • 新功能 New feature
  • 代码风格更新(格式化,局部变量)Style changes
  • 重构(即不是新增功能,也不是修改bug的代码变动)Refactor
  • 构建过程或辅助工具的变动 Build-related
  • 文档内容更新 Docs

Checklist

  • 我的代码遵循这个项目的代码风格 My code follows the project's code style
  • 我已经自己测试过我的代码 I have self-tested my code
  • 我已经更新了相应的文档 I have updated the relevant documentation
  • 我已经根据需要更新了对应的变更日志 I have updated the changelog as needed
  • 我已经在标题中正确使用了类型标签(例如:feat:, fix:)I have correctly used type labels in the title (e.g., feat:, fix:)
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 hujiajun 的贡献)
Hhujiajun成员
16 天前 创建了 pull request,commit 339fa656
ascend-robot
ascend-robot成员
16 天前 评论:

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

likedislike
atomgit-bot
atomgit-bot
16 天前 评论:

变更摘要

此 PR 将 HFusion 融合流程中 findBestFusedNodeForProducerisFillOp 无条件拦截逻辑移除,替换为 FusedNode::canFuseProducer 中更精确的 useAsDpsInits 检查。旧逻辑粗暴地阻止所有类似 fill 的 operation 作为 producer 参与融合,存在过度拦截且可能漏拦的问题;新逻辑仅在 producer 的输出已被 FusedNode 中某个 linalg::LinalgOp 用作 DPS init 时才阻止融合,根本原因是 FuseIntoContainingOp 在此场景下会崩溃。同时新增 3 个测试用例覆盖融合正确性。

主要改动

  • 移除 isFillOp 无条件拦截:在 AutoVectorizeV2.cppfindBestFusedNodeForProducer 函数中删除了对 mlir::hfusion::isFillOp(producer) 的检查,不再阻止 fill 类 operation 作为 producer 参与融合。
  • 新增 FusedNode::useAsDpsInits 精确检查:在 FusedNode.h 中声明、FusedNode.cpp 中实现该方法,遍历 FusedNode 中已有的所有 op,检查 producer 的任一 output 是否被某个 linalg::LinalgOp 用作 DPS init(即 getDpsInits() 返回值),若命中则返回 true
  • canFuseProducer 中集成 DPS init 保护:在 canFuseProducer 开头调用 useAsDpsInits(producer),若返回 true 则直接返回 false 阻止融合,从而在 FuseIntoContainingOp 会崩溃的场景下精确拦截,同时允许其他安全的 fill 类 operation 正常融合。
  • 新增测试文件:添加 auto-vectorize-v2-fuse-into-dpsinits.mlir,包含 fill_reduceelementwise_reduceelementwise_elementwise 三个测试用例,验证 fill 及 elementwise 作为 producer 时的融合行为。
likedislike
atomgit-bot
atomgit-bot
16 天前 评论:

代码审查

审查总结

按优先级统计:

  • P0: 0 个
  • P1: 0 个
  • P2: 0 个
  • P3: 1 个(方法命名歧义)

整体风险判断:低。该变更用精确的 useAsDpsInits 检查替换了粗粒度的 isFillOp 拦截,逻辑正确,既解决了过度拦截(fill-like op 作为 input 时被误拦),也修复了漏拦(非 fill op 的输出作为 DPS init 时未被拦截导致 FuseIntoContainingOp 崩溃)。新增的三个测试用例覆盖了关键的回归场景。

各文件审查确认

文件 结论
bishengir/include/.../FusedNode.h 无问题(仅新增一行私有方法声明)
bishengir/lib/.../FusedNode.cpp 1 个 P3 命名建议
bishengir/lib/.../AutoVectorizeV2.cpp 无问题(仅删除旧的 isFillOp 拦截)
bishengir/test/.../auto-vectorize-v2-fuse-into-dpsinits.mlir 无问题(新增回归测试,覆盖三种关键场景)

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

likedislike
ascend-robotascend-robot成员
16 天前 添加了label:ascend-cla/yes
此处折叠了71条消息 查看更多
lingfeiwu
lingfeiwu成员
16 天前 评论:

/lgtm
/approve

likedislike
ascend-robotascend-robot成员
16 天前 添加了label:approved
NoBBAI成员
15 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
15 天前 添加了label:lgtm
ascend-robotascend-robot成员
15 天前 合入了pull request,合并节点 SHA:1e62c8f94913eff66fa068e44fdc3acef4de63dc