Skip to content

Commit 77596b7

Browse files
authored
[mlir][vector] Add a new TD op to wrap unit-dim collapsing patterns (#157507)
Adds a new TD Op, * `apply_patterns.vector.drop_inner_most_unit_dims_from_xfer_ops`, which wraps the following Vector patterns: * `DropInnerMostUnitDimsTransferRead` * `DropInnerMostUnitDimsTransferWrite` This complements other existing unit-dimension–related patterns. To reduce duplication, the `TestVectorTransferCollapseInnerMostContiguousDims` pass has been removed. That pass was only used for testing, and its functionality is now covered by the newly added TD Op.
1 parent 0d65856 commit 77596b7

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

mlir/include/mlir/Dialect/Vector/TransformOps/VectorTransformOps.td

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ def ApplyDropUnitDimWithShapeCastPatternsOp : Op<Transform_Dialect,
8585
let assemblyFormat = "attr-dict";
8686
}
8787

88+
def ApplyDropInnerMostUnitDimsFromXferOpsPatternsOp : Op<Transform_Dialect,
89+
"apply_patterns.vector.drop_inner_most_unit_dims_from_xfer_ops",
90+
[DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {
91+
let description = [{
92+
Apply vector patterns to drop the inner most unit dims from
93+
vector.transfer_read and vector.transfer_write Ops by taking a subview (via
94+
memref.subview) of the original source/destination MemRef. Since it
95+
requires the input/ouptu to be MemRefs, this Op is only helpful
96+
past-bufferization.
97+
}];
98+
99+
let assemblyFormat = "attr-dict";
100+
}
101+
88102
def ApplyTransferPermutationPatternsOp : Op<Transform_Dialect,
89103
"apply_patterns.vector.transfer_permutation_patterns",
90104
[DeclareOpInterfaceMethods<PatternDescriptorOpInterface>]> {

mlir/lib/Dialect/Vector/TransformOps/VectorTransformOps.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ void transform::ApplyDropUnitDimWithShapeCastPatternsOp::populatePatterns(
8888
vector::populateDropUnitDimWithShapeCastPatterns(patterns);
8989
}
9090

91+
void transform::ApplyDropInnerMostUnitDimsFromXferOpsPatternsOp::
92+
populatePatterns(RewritePatternSet &patterns) {
93+
vector::populateDropInnerMostUnitDimsXferOpPatterns(patterns);
94+
}
95+
9196
void transform::ApplyLowerBitCastPatternsOp::populatePatterns(
9297
RewritePatternSet &patterns) {
9398
vector::populateVectorBitCastLoweringPatterns(patterns);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module @transforms attributes { transform.with_named_sequence } {
2+
transform.named_sequence @drop_unit_dims(%module: !transform.any_op {transform.readonly}) {
3+
4+
%func_op = transform.structured.match ops{["func.func"]} in %module : (!transform.any_op) -> !transform.op<"func.func">
5+
transform.apply_patterns to %func_op {
6+
transform.apply_patterns.vector.drop_inner_most_unit_dims_from_xfer_ops
7+
} : !transform.op<"func.func">
8+
9+
transform.yield
10+
}
11+
}

mlir/test/Dialect/Vector/vector-transfer-collapse-inner-most-dims.mlir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: mlir-opt %s -test-vector-transfer-collapse-inner-most-dims -split-input-file | FileCheck %s
1+
// RUN: mlir-opt -split-input-file \
2+
// RUN: -transform-preload-library='transform-library-paths=%p/td/xfer-drop-unit-dims.mlir' \
3+
// RUN: -transform-interpreter=entry-point=drop_unit_dims %s | FileCheck %s
24

35
//-----------------------------------------------------------------------------
46
// 1. vector.transfer_read

mlir/test/lib/Dialect/Vector/TestVectorTransforms.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -344,36 +344,6 @@ struct TestVectorTransferOpt
344344
}
345345
};
346346

347-
struct TestVectorTransferCollapseInnerMostContiguousDims
348-
: public PassWrapper<TestVectorTransferCollapseInnerMostContiguousDims,
349-
OperationPass<func::FuncOp>> {
350-
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(
351-
TestVectorTransferCollapseInnerMostContiguousDims)
352-
353-
TestVectorTransferCollapseInnerMostContiguousDims() = default;
354-
TestVectorTransferCollapseInnerMostContiguousDims(
355-
const TestVectorTransferCollapseInnerMostContiguousDims &pass) = default;
356-
357-
void getDependentDialects(DialectRegistry &registry) const override {
358-
registry.insert<memref::MemRefDialect, affine::AffineDialect>();
359-
}
360-
361-
StringRef getArgument() const final {
362-
return "test-vector-transfer-collapse-inner-most-dims";
363-
}
364-
365-
StringRef getDescription() const final {
366-
return "Test lowering patterns that reduces the rank of the vector "
367-
"transfer memory and vector operands.";
368-
}
369-
370-
void runOnOperation() override {
371-
RewritePatternSet patterns(&getContext());
372-
populateDropInnerMostUnitDimsXferOpPatterns(patterns);
373-
(void)applyPatternsGreedily(getOperation(), std::move(patterns));
374-
}
375-
};
376-
377347
struct TestVectorSinkPatterns
378348
: public PassWrapper<TestVectorSinkPatterns, OperationPass<func::FuncOp>> {
379349
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestVectorSinkPatterns)
@@ -1079,8 +1049,6 @@ void registerTestVectorLowerings() {
10791049

10801050
PassRegistration<TestVectorTransferOpt>();
10811051

1082-
PassRegistration<TestVectorTransferCollapseInnerMostContiguousDims>();
1083-
10841052
PassRegistration<TestVectorSinkPatterns>();
10851053

10861054
PassRegistration<TestVectorReduceToContractPatternsPatterns>();

0 commit comments

Comments
 (0)