-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][vector] Group re-order patterns together #102856
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
Merged
banach-space
merged 4 commits into
llvm:main
from
banach-space:andrzej/group_reorder_tests
Aug 16, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ad558f0
[mlir][vector] Group tests for re-order patterns
banach-space 90797f1
fixup! [mlir][vector] Group tests for re-order patterns
banach-space 7eef40d
fixup! fixup! [mlir][vector] Group tests for re-order patterns
banach-space b2a70dd
fixup! fixup! fixup! [mlir][vector] Group tests for re-order patterns
banach-space File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// RUN: mlir-opt %s -test-sink-vector-broadcast -split-input-file | FileCheck %s | ||
// RUN: mlir-opt %s -test-vector-sink-patterns -split-input-file | FileCheck %s | ||
|
||
//----------------------------------------------------------------------------- | ||
// [Pattern: ReorderElementwiseOpsOnBroadcast] | ||
|
@@ -208,3 +208,115 @@ func.func @negative_op_only_supports_vectors(%arg0 : f32) -> vector<1xf32> { | |
%1 = vector.fma %0, %0, %0 : vector<1xf32> | ||
return %1 : vector<1xf32> | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
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. Diff-ed moved tests. Looks good. 👍 |
||
// [Pattern: ReorderCastOpsOnBroadcast] | ||
// | ||
// Reorder casting ops and vector ops. The casting ops have almost identical | ||
// pattern, so only arith.extsi op is tested. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// ----- | ||
|
||
func.func @broadcast_vector_extsi(%a : vector<4xi8>) -> vector<2x4xi32> { | ||
// CHECK: %[[EXT:.+]] = arith.extsi %{{.+}} : vector<4xi8> to vector<4xi32> | ||
// CHECK: vector.broadcast %[[EXT:.+]] : vector<4xi32> to vector<2x4xi32> | ||
%b = vector.broadcast %a : vector<4xi8> to vector<2x4xi8> | ||
%r = arith.extsi %b : vector<2x4xi8> to vector<2x4xi32> | ||
return %r : vector<2x4xi32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @broadcast_scalar_extsi(%a : i8) -> vector<2x4xi32> { | ||
// CHECK: %[[EXT:.+]] = arith.extsi %{{.+}} : i8 to i32 | ||
// CHECK: vector.broadcast %[[EXT]] : i32 to vector<2x4xi32> | ||
%b = vector.broadcast %a : i8 to vector<2x4xi8> | ||
%r = arith.extsi %b : vector<2x4xi8> to vector<2x4xi32> | ||
return %r : vector<2x4xi32> | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// [Pattern: ReorderElementwiseOpsOnTranspose] | ||
//===----------------------------------------------------------------------===// | ||
|
||
func.func @transpose_extsi(%a : vector<4x2xi8>) -> vector<2x4xi32> { | ||
// CHECK: %[[EXT:.+]] = arith.extsi %{{.+}} : vector<4x2xi8> to vector<4x2xi32> | ||
// CHECK: vector.transpose %[[EXT]], [1, 0] : vector<4x2xi32> to vector<2x4xi32> | ||
%b = vector.transpose %a, [1, 0]: vector<4x2xi8> to vector<2x4xi8> | ||
%r = arith.extsi %b : vector<2x4xi8> to vector<2x4xi32> | ||
return %r : vector<2x4xi32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @transpose_elementwise_same_type | ||
// CHECK-SAME: (%[[A:.+]]: vector<4x2xf32>, %[[B:.+]]: vector<4x2xf32>) | ||
// CHECK: %[[ADD:.+]] = arith.addf %[[A]], %[[B]] : vector<4x2xf32> | ||
// CHECK: %[[T:.+]] = vector.transpose %[[ADD]], [1, 0] | ||
// CHECK: return %[[T]] | ||
|
||
func.func @transpose_elementwise_same_type(%a : vector<4x2xf32>, %b : vector<4x2xf32>) -> vector<2x4xf32> { | ||
%at = vector.transpose %a, [1, 0]: vector<4x2xf32> to vector<2x4xf32> | ||
%bt = vector.transpose %b, [1, 0]: vector<4x2xf32> to vector<2x4xf32> | ||
%r = arith.addf %at, %bt : vector<2x4xf32> | ||
return %r : vector<2x4xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @transpose_elementwise_diff_operand_types | ||
// CHECK-SAME: (%[[COND:.+]]: vector<4x2xi1>, %[[A:.+]]: vector<4x2xf32>, %[[B:.+]]: vector<4x2xf32>) | ||
// CHECK: %[[S:.+]] = arith.select %[[COND]], %[[A]], %[[B]] : vector<4x2xi1>, vector<4x2xf32> | ||
// CHECK: %[[T:.+]] = vector.transpose %[[S]], [1, 0] : vector<4x2xf32> to vector<2x4xf32> | ||
// CHECK: return %[[T]] | ||
func.func @transpose_elementwise_diff_operand_types(%cond: vector<4x2xi1>, %a : vector<4x2xf32>, %b : vector<4x2xf32>) -> vector<2x4xf32> { | ||
%condt = vector.transpose %cond, [1, 0]: vector<4x2xi1> to vector<2x4xi1> | ||
%at = vector.transpose %a, [1, 0]: vector<4x2xf32> to vector<2x4xf32> | ||
%bt = vector.transpose %b, [1, 0]: vector<4x2xf32> to vector<2x4xf32> | ||
%r = arith.select %condt, %at, %bt : vector<2x4xi1>, vector<2x4xf32> | ||
return %r : vector<2x4xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @transpose_elementwise_diff_operand_result_type | ||
// CHECK-SAME: (%[[A:.+]]: vector<4x2xf32>, %[[B:.+]]: vector<4x2xf32>) | ||
// CHECK: %[[CMP:.+]] = arith.cmpf olt, %[[A]], %[[B]] : vector<4x2xf32> | ||
// CHECK: %[[T:.+]] = vector.transpose %[[CMP]], [1, 0] : vector<4x2xi1> to vector<2x4xi1> | ||
// CHECK: return %[[T]] | ||
func.func @transpose_elementwise_diff_operand_result_type(%a : vector<4x2xf32>, %b : vector<4x2xf32>) -> vector<2x4xi1> { | ||
%at = vector.transpose %a, [1, 0]: vector<4x2xf32> to vector<2x4xf32> | ||
%bt = vector.transpose %b, [1, 0]: vector<4x2xf32> to vector<2x4xf32> | ||
%r = arith.cmpf olt, %at, %bt : vector<2x4xf32> | ||
return %r : vector<2x4xi1> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @transpose_elementwise_splat_constant | ||
// CHECK-SAME: (%[[A:.+]]: vector<4x6x3x2xf32>) | ||
// CHECK: %[[B:.+]] = arith.constant dense<5.000000e+00> : vector<4x6x3x2xf32> | ||
// CHECK: %[[ADD:.+]] = arith.addf %[[A]], %[[B]] : vector<4x6x3x2xf32> | ||
// CHECK: %[[T:.+]] = vector.transpose %[[ADD]], [1, 0, 3, 2] : vector<4x6x3x2xf32> to vector<6x4x2x3xf32> | ||
// CHECK: return %[[T:.+]] : vector<6x4x2x3xf32> | ||
|
||
func.func @transpose_elementwise_splat_constant(%a : vector<4x6x3x2xf32>) -> vector<6x4x2x3xf32> { | ||
%b = arith.constant dense<5.0> : vector<6x4x2x3xf32> | ||
%at = vector.transpose %a, [1, 0, 3, 2]: vector<4x6x3x2xf32> to vector<6x4x2x3xf32> | ||
%r = arith.addf %at, %b : vector<6x4x2x3xf32> | ||
return %r : vector<6x4x2x3xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @transpose_elementwise_diff_map | ||
// CHECK: vector.transpose | ||
// CHECK: vector.transpose | ||
// CHECK: arith.addf | ||
func.func @transpose_elementwise_diff_map(%a : vector<4x6x3x2xf32>, %b: vector<6x2x4x3xf32>) -> vector<6x4x2x3xf32> { | ||
%at = vector.transpose %a, [1, 0, 3, 2]: vector<4x6x3x2xf32> to vector<6x4x2x3xf32> | ||
%bt = vector.transpose %b, [0, 2, 1, 3]: vector<6x2x4x3xf32> to vector<6x4x2x3xf32> | ||
%r = arith.addf %at, %bt : vector<6x4x2x3xf32> | ||
return %r : vector<6x4x2x3xf32> | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note:
populateVectorReductionToContractPatterns()
is used a few times in IREE, so this change will likely cause some breakages there. You should probably share a fix on the Discord before landing this 🙂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.
Thanks for the heads up! So is the expectation that you run the sink before you run contract conversion patterns.
I agree the current grouping of patterns is adhoc, but what is the expected path for users (iree and others) to get back the same code that this one method would give?
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.
See the summary :)
I checked MLIR and IREE and in both cases these were required after. In IREE, I run
ctest -R Codegen/SPIRV/
andctest -R Codegen/LLVMCPU
and both pass 100%. This is my diff:@MaheshRavishankar anything else that I should check?
Btw, this re-grouping has been a bit tricky to verify 100% - there are no tests that would require these patterns to be run together (otherwise I wouldn't be able to move the tests around as I did).
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.
Thanks so much for doing this! Part of my concern here as well was that this combination of things wasnt tested properly in tree. Not your fault, it is just how this was done (there are implicit assumptions of what patterns go together that isnt always clear in the vector dialect).