已合并
[Vector] preserve strided layout when collapsing to 1D #2743
[Vector] preserve strided layout when collapsing to 1D #2743
已合并
hujiajun创建于 14 天前
hujiajun成员
14 天前

[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

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 hujiajun 的贡献)
Hhujiajun成员
14 天前 创建了 pull request,commit bac196f0
atomgit-bot
atomgit-bot
14 天前 评论:

变更摘要

本 PR 修复了 bishengir/lib/Dialect/Vector/Transforms/FlattenVectorOps.cppcollapseAllDims 将向量折叠为 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: ?>, ...> 时保留布局与动态偏移。
likedislike
ascend-robot
ascend-robot成员
14 天前 评论:

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

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

代码审查

✅ 未发现问题

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:SC-RUNNING
ascend-robotascend-robot成员
14 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
14 天前 评论:

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 /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
ascend-robot
ascend-robot成员
14 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
14 天前 评论:

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

likedislike
ascend-robotascend-robot成员
14 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
14 天前 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
14 天前 删除了label:SC-RUNNING
ascend-robotascend-robot成员
14 天前 添加了label:SC-FAIL
ascend-robotascend-robot成员
14 天前 删除了label:SC-FAIL
ascend-robotascend-robot成员
14 天前 添加了label:SC-SUCC
ascend-robotascend-robot成员
14 天前 删除了label:SC-SUCC
ascend-robotascend-robot成员
14 天前 添加了label:SC-SUCC
hujiajun成员
14 天前 评论:

/check-pr

likedislike
ascend-robot
ascend-robot成员
14 天前 评论:

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.

likedislike
hujiajun成员
14 天前 评论:

compile

likedislike
hujiajun成员
14 天前 评论:

npuir-smoke

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
14 天前 添加了label:NPUIR-DT-RUNNING
ascend-robot
ascend-robot成员
14 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
14 天前 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
14 天前 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
14 天前 评论:

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

likedislike
ascend-robotascend-robot成员
14 天前 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
14 天前 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
14 天前 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
14 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
14 天前 评论:
流水线 PR-pipeline_ascendnpu-ir#4833 已完成
阶段 任务名 状态 详情
编译构建 Build_x86_llvm_19 >>>
Build_x86_llvm_20 >>>
Build_x86_llvm_22 >>>
恶意代码检查 Antipoison >>>
流水线 PR-pipeline_ascendnpu-ir >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
PpCSICompileDV成员
14 天前 通过测试
ascend-robotascend-robot成员
14 天前 删除了label:NPUIR-DT-RUNNING
ascend-robotascend-robot成员
14 天前 添加了label:NPUIR-DT-SUCC
ascend-robot
ascend-robot成员
14 天前 评论:
流水线 pipeline_npuir-smoke#2077 已完成
阶段 任务名 状态 详情
编译构建 Compile >>>
开发者测试 CVOps >>>
流水线 pipeline_npuir-smoke >>>
likedislike
lingfeiwu
lingfeiwu成员
14 天前 评论:

/approve
/lgtm

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:approved
zhuyichen成员
14 天前 评论:

/check-pr

likedislike
ascend-robot
ascend-robot成员
14 天前 评论:

The following label is not ready.

lgtm: Please wait for reviewers to review the code.

likedislike
Zz_zl成员
14 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
14 天前 添加了label:lgtm
ascend-robotascend-robot成员
14 天前 合入了pull request,合并节点 SHA:e040074b860ee57825abd2b96cec10408f00f646
chenxiangtingchenxiangting成员
14 天前 修改了pull request 的描述