Pull Request已成功合入, 合并人@ascend-robot
(感谢 hujiajun 的贡献)变更摘要
本 PR 修复了 bishengir/lib/Dialect/Vector/Transforms/FlattenVectorOps.cpp 中 collapseAllDims 将向量折叠为 1D 时丢失 strided 布局的问题。原实现用 mlir::MemRefType::get() 直接构造折叠后的 memref 类型,会丢弃降秩子视图(rank-reduced subview)源缓冲区的 strided 布局和动态偏移量,从而生成无效的 collapse_shape 并触发 verifier 报错。改为使用 memref::CollapseShapeOp::computeCollapsedType 构造结果类型以保留布局属性,并通过 isGuaranteedCollapsible 拒绝非连续(non-contiguous)的 strided 源,避免触发 computeCollapsedType 内部的断言;同时保留 setUBMemScopeAttr 作为防御性兜底(在 normalize-vector 流程中源始终为 UB 地址空间,该调用实际为 no-op)。
主要改动
- 静态形状检查改写:将手工累乘计算
collapsedDimSize的逻辑替换为用llvm::any_of配合ShapedType::isDynamic检测动态维度,存在动态维度时直接返回std::nullopt,不再折叠。 - 折叠可行性前置校验:在构造结果类型前调用
memref::CollapseShapeOp::isGuaranteedCollapsible(inputType, reassociations),对非连续的 strided 源返回std::nullopt,防止触发computeCollapsedType的断言;身份(identity)布局仍保持原有的可折叠行为。 - 结果类型构造方式变更:将
mlir::MemRefType::get({collapsedDimSize}, ...)替换为memref::CollapseShapeOp::computeCollapsedType(inputType, reassociations),使折叠后的 1D memref 保留源缓冲区的 strided 布局与动态 offset(如memref<128xf32, strided<[1], offset: ?>, #hivm.address_space<ub>>)。 - 新增回归测试:在
bishengir/test/Dialect/Vector/flatten-vector.mlir增加merge_16x16_to_64x64_inverse_kernel_mix_aiv_outlined_merged_merged_vf_2用例,通过 CHECK 断言memref.collapse_shape将带 strided 布局的8x16xf32源折叠为memref<128xf32, strided<[1], offset: ?>, ...>时保留布局与动态偏移。


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
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/AscendNPU-IR | ✅ 吴凌飞, Zz_zl (2/2) | ✅ 吴凌飞 (1/1) |
💡 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. 👍


ascend docs pipeline is running...


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


The following labels are not ready.
lgtm: Please wait for reviewers to review the code.
approved: Please wait for committers to review the code.
ci-pipeline-passed: Please wait for the CI test to be completed.
NPUIR-DT-SUCC: Please wait for the npuir dt to be completed.


ascend docs pipeline is running...


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


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


/approve
/lgtm


The following label is not ready.
lgtm: Please wait for reviewers to review the code.


[AscendNPU IR]:[Vector] 折叠到 1D 时保留 strided 布局
描述 Description
collapseAllDims使用MemRefType::get()构建折叠后的 memref 类型,这会丢弃降秩子视图(rank-reduced subview)源缓冲区的 strided 布局和动态偏移量,从而生成无效的collapse_shape,导致 verifier 报错。应改用memref::CollapseShapeOp::computeCollapsedType来保留这些属性,并通过isGuaranteedCollapsible拒绝非连续(non-contiguous)的 strided 源,以避免触发computeCollapsedType中的断言(assert)。类型 Category
Checklist