-
Notifications
You must be signed in to change notification settings - Fork 14.4k
feat(linalg): add a way to pass controlFn to foldIntoPackUnpackPatterns
#143685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// RUN: mlir-opt -split-input-file -test-linalg-transform-patterns=test-fold-into-pack-and-unpack %s | FileCheck %s | ||
// RUN: mlir-opt -split-input-file -test-linalg-transform-patterns=test-fold-into-pack-and-unpack-control %s | FileCheck %s --check-prefix=CONTROL | ||
|
||
func.func @fold_unpack_slice(%arg0 : tensor<?x?x8x4xf32>, %arg1 : tensor<?x?xf32>, | ||
%arg2 : index, %arg3 : index) -> tensor<?x?xf32> { | ||
|
@@ -373,6 +374,36 @@ func.func @linalg_transpose_linalg.pack_fold(%arg0: tensor<56x57x1x64xf32>) -> t | |
|
||
// ----- | ||
|
||
func.func @linalg_transpose_linalg.pack_fold_multi_result(%arg0: tensor<56x57x1x64xf32>) -> (tensor<1x56x57x64xf32>, tensor<1x57x56x2x32xf32>) { | ||
%0 = tensor.empty() : tensor<1x56x57x64xf32> | ||
%transposed = linalg.transpose | ||
ins(%arg0 : tensor<56x57x1x64xf32>) | ||
outs(%0 : tensor<1x56x57x64xf32>) | ||
permutation = [2, 0, 1, 3] | ||
|
||
%1 = tensor.empty() : tensor<1x57x56x2x32xf32> | ||
%pack = linalg.pack %transposed | ||
outer_dims_perm = [0, 2, 1, 3] | ||
inner_dims_pos = [3] | ||
inner_tiles = [32] | ||
into %1 : tensor<1x56x57x64xf32> -> tensor<1x57x56x2x32xf32> | ||
return %transposed, %pack : tensor<1x56x57x64xf32>, tensor<1x57x56x2x32xf32> | ||
} | ||
// CHECK-LABEL: func @linalg_transpose_linalg.pack_fold_multi_result( | ||
// CHECK-SAME: %[[ARG0:.+]]: tensor<56x57x1x64xf32>) | ||
// CHECK: %[[TRANSPOSE:.+]] = linalg.transpose | ||
// CHECK: %[[PACK:.+]] = linalg.pack %[[ARG0]] | ||
// CHECK-SAME: outer_dims_perm = [2, 1, 0, 3] | ||
// CHECK: return %[[TRANSPOSE]], %[[PACK]] | ||
|
||
// CONTROL-LABEL: func @linalg_transpose_linalg.pack_fold_multi_result( | ||
// CONTROL: %[[TRANSPOSE:.+]] = linalg.transpose | ||
// CONTROL: %[[PACK:.+]] = linalg.pack %[[TRANSPOSE]] | ||
// CONTROL-SAME: outer_dims_perm = [0, 2, 1, 3] | ||
// CONTROL: return %[[TRANSPOSE]], %[[PACK]] | ||
|
||
// ----- | ||
|
||
func.func @linalg_transpose_linalg.pack_fold_with_padding(%arg0: tensor<56x57x1x55xf32>, %padding: f32) -> tensor<1x57x56x2x32xf32> { | ||
%0 = tensor.empty() : tensor<1x56x57x55xf32> | ||
%transpose = linalg.transpose | ||
|
@@ -550,6 +581,36 @@ func.func @linalg_transpose_linalg.unpack_fold(%arg0: tensor<1x1x4x16xi32>) -> t | |
|
||
// ----- | ||
|
||
func.func @linalg_transpose_linalg.unpack_fold_multi_result(%arg0: tensor<1x1x4x16xi32>) -> (tensor<1x1x16x4xi32>, tensor<16x4xi32>) { | ||
%0 = tensor.empty() : tensor<1x1x16x4xi32> | ||
%transposed = linalg.transpose ins(%arg0 : tensor<1x1x4x16xi32>) | ||
outs(%0 : tensor<1x1x16x4xi32>) | ||
permutation = [1, 0, 3, 2] | ||
%1 = tensor.empty() : tensor<16x4xi32> | ||
%unpack = linalg.unpack %transposed | ||
outer_dims_perm = [0, 1] | ||
inner_dims_pos = [0, 1] | ||
inner_tiles = [16, 4] into | ||
%1 : tensor<1x1x16x4xi32> -> tensor<16x4xi32> | ||
return %transposed, %unpack : tensor<1x1x16x4xi32>, tensor<16x4xi32> | ||
} | ||
//CHECK-LABEL: func.func @linalg_transpose_linalg.unpack_fold_multi_result( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests can be less verbose in the checks. The main thing this is testing is whether or not the fusion happened with mutli-result, so you don't need to check all the shapes/op metadata. You could just check the operands and results of the operations to verify the producers/consumers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made them less verbose, thanks! I definitely got a little caught up while writing those 😂 |
||
// CHECK-SAME: %[[ARG0:.+]]: tensor<1x1x4x16xi32>) | ||
// CHECK: %[[TRANSPOSE:.+]] = linalg.transpose | ||
// CHECK: %[[UNPACK:.+]] = linalg.unpack %[[ARG0]] | ||
// CHECK-SAME: outer_dims_perm = [1, 0] | ||
// CHECK: return %[[TRANSPOSE]], %[[UNPACK]] | ||
// CHECK: } | ||
|
||
//CONTROL-LABEL: func.func @linalg_transpose_linalg.unpack_fold_multi_result( | ||
// CONTROL: %[[TRANSPOSE:.+]] = linalg.transpose | ||
// CONTROL: %[[UNPACK:.+]] = linalg.unpack %[[TRANSPOSE]] | ||
// CONTROL-SAME: outer_dims_perm = [0, 1] | ||
// CONTROL: return %[[TRANSPOSE]], %[[UNPACK]] | ||
// CONTROL: } | ||
|
||
// ----- | ||
|
||
func.func @linalg_transpose_linalg.unpack_fold_partial_tile(%arg0: tensor<1x1x4x16xi32>) -> tensor<15x3xi32> { | ||
%0 = tensor.empty() : tensor<1x1x16x4xi32> | ||
%transposed = linalg.transpose ins(%arg0 : tensor<1x1x4x16xi32>) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with these tests. The checks can be less verbose.