forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][vector] Add a new TD Op for patterns leveraging ShapeCastOp (l…
…lvm#110525) Adds a new Transform Dialect Op that collects patters for dropping unit dims from various Ops: * `transform.apply_patterns.vector.drop_unit_dims_with_shape_cast`. It excludes patterns for vector.transfer Ops - these are collected under: * `apply_patterns.vector.rank_reducing_subview_patterns`, and use ShapeCastOp _and_ SubviewOp to reduce the rank (and to eliminate unit dims). This new TD Ops allows us to test the "ShapeCast folder" pattern in isolation. I've extracted the only test that I could find for that folder from "vector-transforms.mlir" and moved it to a dedicated file: "shape-cast-folder.mlir". I also added a test case with scalable vectors. Changes in VectorTransforms.cpp are not needed (added a comment with a TODO + ordered the patterns alphabetically). I am Including them here to avoid a separate PR.
- Loading branch information
1 parent
9dad082
commit 17f6d51
Showing
5 changed files
with
66 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// RUN: mlir-opt %s --transform-interpreter --split-input-file | FileCheck %s | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// [Pattern: ShapeCastOpFolder] | ||
///---------------------------------------------------------------------------------------- | ||
|
||
// CHECK-LABEL: func @fixed_width | ||
// CHECK-SAME: %[[A0:.*0]]: vector<2x4xf32> | ||
// CHECK-NOT: vector.shape_cast | ||
// CHECK: return %[[A0]] : vector<2x4xf32> | ||
func.func @fixed_width(%arg0 : vector<2x4xf32>) -> vector<2x4xf32> { | ||
%0 = vector.shape_cast %arg0 : vector<2x4xf32> to vector<8xf32> | ||
%1 = vector.shape_cast %0 : vector<8xf32> to vector<2x4xf32> | ||
return %1 : vector<2x4xf32> | ||
} | ||
|
||
// CHECK-LABEL: func @scalable | ||
// CHECK-SAME: %[[A0:.*0]]: vector<2x[4]xf32> | ||
// CHECK-NOT: vector.shape_cast | ||
// CHECK: return %[[A0]] : vector<2x[4]xf32> | ||
func.func @scalable(%arg0 : vector<2x[4]xf32>) -> vector<2x[4]xf32> { | ||
%0 = vector.shape_cast %arg0 : vector<2x[4]xf32> to vector<[8]xf32> | ||
%1 = vector.shape_cast %0 : vector<[8]xf32> to vector<2x[4]xf32> | ||
return %1 : vector<2x[4]xf32> | ||
} | ||
|
||
// ============================================================================ | ||
// TD sequence | ||
// ============================================================================ | ||
module attributes {transform.with_named_sequence} { | ||
transform.named_sequence @__transform_main(%root : !transform.any_op {transform.readonly}) { | ||
%func_op = transform.structured.match ops{["func.func"]} in %root : (!transform.any_op) -> !transform.op<"func.func"> | ||
transform.apply_patterns to %func_op { | ||
transform.apply_patterns.vector.drop_unit_dims_with_shape_cast | ||
} : !transform.op<"func.func"> | ||
transform.yield | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters