Pull Request已成功合入, 合并人@ascend-robot
(感谢 kiansitov 的贡献)变更摘要
此 PR 主要包含两项核心修复:一是恢复了之前被回退的「enable flatten」功能,移除了 MixedCV 场景下自动禁用 flatten 的逻辑,并调整了 ProcessVsstbPass 在 pipeline 中的位置以确保 pass 顺序正确;二是修复了 TransferReadToGatheringLoadPattern 中处理三维循环置换排列映射(如 (d0, d1, d2) -> (d1, d2, d0))时的索引计算错误。此外还新增了一个 FoldWidenedTransferReadAfterWrite 优化模式,可将特定条件下被静态 mask 裁剪的宽 transfer_read 替换为 vector.broadcast,以及修复了 PropagateReshapePass 对 AIV 核心类型和空值检查的处理。
主要改动
-
恢复 flatten 并调整 pass 顺序:在
PassPipeline.cpp中移除了 MixedCV 下自动设置enableFlatten=false的约 12 行逻辑,恢复 flatten 的正常启用;同时在HIVMAVEPipelines.cpp中将createProcessVsstbPass()从OptimizeReductionLoop之前移至AveLoopOptimize之后,避免 reduction 分裂干扰相邻 store 模式的识别。 -
修复三维循环排列映射的索引逆推:在
NormalizeVector.cpp的TransferReadToGatheringLoadPattern中,对排列映射permMap调用新增的inversePermutation得到invPermMap,再用invPermMap.compose(composeIndices)替代原先错误的permMap.compose,正确恢复 memref 索引空间中的 gather 偏移量。 -
新增 FoldWidenedTransferReadAfterWrite 优化:在
RemoveRedundantWriteAndReadPair.cpp中新增getStaticMaskSizes辅助函数(支持vector.constant_mask和vector.create_mask)及FoldWidenedTransferReadAfterWrite重写模式,当transfer_read的 mask 静态可推导且读向量的有效区域完全被写向量覆盖时,将 read 替换为对写向量的vector.broadcast,消除冗余的 write-read 对。 -
PropagateReshapePass 扩展 AIV 跳过条件:在
PropagateReshape.cpp中将coreType检查从直接解引用改为has_value()安全判断,并将跳过条件从仅AIC扩展为AIC || AIV,使 AIV 核心类型的函数同样跳过 reshape 传播。 -
新增测试覆盖:在
remove-redundant-write-and-read-pair.mlir中新增 10 个测试用例(含 5 个正向折叠和 6 个负向不应折叠场景);新增normalize_vector_gather_perm.mlir测试文件,覆盖三维循环排列映射下 gather 生成的正确性。


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


代码审查
经过对所有 7 个变更文件的全面审查,我没有发现需要报告的真实问题。每个变更都是正确且有充分理由的:
-
RemoveRedundantWriteAndReadPair.cpp:新增的
FoldWidenedTransferReadAfterWrite模式逻辑正确,边界检查完备;getStaticMaskSizes辅助函数正确处理了ConstantMaskOp和CreateMaskOp,并对非静态掩码保守地返回空。测试用例覆盖了正面和负面场景。 -
HIVMAVEPipelines.cpp:
ProcessVsstbPass的 pass 重排序不引入正确性问题。 -
PropagateReshape.cpp:将 AIV core 类型加入跳过列表,是对 AIC 的合理扩展,同时将
coreType使用方式从指针式改为显式.has_value()/.value(),逻辑等价。 -
NormalizeVector.cpp:使用
inversePermutation(permMap)替代permMap.compose()是一个正确的 bug 修复——旧代码对(d0,d1,d2)→(d1,d2,d0)这样的循环置换计算了错误的 gather 索引。analyzeTransferRead中的isPermutation()守卫保证了inversePermutation不会返回空 map。新增的测试文件normalize_vector_gather_perm.mlir正确验证了该修复。 -
PassPipeline.cpp:移除了在 mixed CV 启用时禁用 flatten 的临时规避逻辑,直接传递原始
config。这是有意为之的变更,与其他修复一起使 flatten 能够正常运行。 -
remove-redundant-write-and-read-pair.mlir:新增的 9 个测试用例(3 个正面 + 6 个负面)充分覆盖了新模式的各种场景。
-
normalize_vector_gather_perm.mlir:新增的 2 个测试用例正确验证了 3D 循环置换的 gather 索引计算。
关闭总结
- P0: 0
- P1: 0
- P2: 0
- P3: 0
总体风险评估:该变更风险较低。所有改动逻辑正确,测试覆盖充分,不存在正确性、安全或可靠性回归。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Compile | ✅ | >>> |
| 开发者测试 | CVOps | ✅ | >>> |
| 流水线 | PR-pipeline_npuir-smoke | ✅ | >>> |


The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


title: "[AscendNPU IR]: Reapply "enable flatten by default" (!2326) and fix performance degradation caused this patch"
描述 Description
Revert "Revert "!2326 merge migration into master"".
Reapply previously reverted commit "[AscendNPU-IR] enable flatten by default" (af7a256c8d3e7e3cdbe4153b18a9fc747a07b2a8)
Fix performance degradation.
hfusion\FlattenOppass is applied only to MIX kernels, while the pre-flatteningPropagateReshapepass is also applied to AIV kernels.PropagateReshapeandhfusion\FlattenOpshould be applied consistently:PropagateReshapeshould be applied only whenhfusion\FlattenOpis also applicable.Applying
PropagateReshapewithouthfusion\FlattenOpleads to performance degradation becausePropagateReshapepass can affect operation fusion.Skip
PropagateReshapepass for AIV kernels (when flattening is not applicable)类型 Category
Checklist
feat:,fix:)I have correctly used type labels in the title (e.g., feat:, fix:)