-
Notifications
You must be signed in to change notification settings - Fork 27
Add multislice simplification #1958
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
+281
−0
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0a06aab
ReduceUnusedMultiSlice
jumerckx 0b8a86d
filecheck test
jumerckx 43c04a9
immediately erase
jumerckx 51e8ca4
keep sharding
jumerckx b2c180e
Merge branch 'main' into jm/multislice_opt
wsmoses e59fee1
fixes
jumerckx 5894144
fix
jumerckx 4924e9f
revert use of replaceOpWithNewOp
jumerckx a4a2cdf
remove addMultiSliceOpt
jumerckx d99ab52
Merge branch 'main' into jm/multislice_opt
jumerckx 28882b6
fix merge mistake
jumerckx 0d0f264
Merge branch 'main' into jm/multislice_opt
jumerckx 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // RUN: enzymexlamlir-opt --enzyme-hlo-generate-td="patterns=reduce_unused_multislice" --transform-interpreter --enzyme-hlo-remove-transform %s | FileCheck %s | ||
|
|
||
| // Test 1: Only center result used - should become a regular slice | ||
| func.func @multi_slice_only_center(%arg0: tensor<20x24x80xf64>) -> tensor<1x8x72xf64> { | ||
| %0, %1, %2, %3, %4, %5 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 1, 0, 3>, | ||
| limit_indices = array<i64: 2, 8, 75>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 2 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 3 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| return %2 : tensor<1x8x72xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_only_center( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> tensor<1x8x72xf64> { | ||
| // CHECK: %[[VAL_1:.*]] = stablehlo.slice %[[VAL_0]] [1:2, 0:8, 3:75] : (tensor<20x24x80xf64>) -> tensor<1x8x72xf64> | ||
| // CHECK: return %[[VAL_1]] : tensor<1x8x72xf64> | ||
| // CHECK: } | ||
|
|
||
|
|
||
| // Test 2: Only left-most result used - should become a regular slice | ||
| func.func @multi_slice_only_left(%arg0: tensor<20x24x80xf64>) -> tensor<1x8x72xf64> { | ||
| %0, %1, %2, %3, %4, %5 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 1, 0, 3>, | ||
| limit_indices = array<i64: 2, 8, 75>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 2 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 3 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| return %0 : tensor<1x8x72xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_only_left( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> tensor<1x8x72xf64> { | ||
| // CHECK: %[[VAL_1:.*]] = stablehlo.slice %[[VAL_0]] [1:2, 0:8, 1:73] : (tensor<20x24x80xf64>) -> tensor<1x8x72xf64> | ||
| // CHECK: return %[[VAL_1]] : tensor<1x8x72xf64> | ||
| // CHECK: } | ||
|
|
||
|
|
||
| // Test 3: Only right-most result used - should become a regular slice | ||
| func.func @multi_slice_only_right(%arg0: tensor<20x24x80xf64>) -> tensor<1x8x72xf64> { | ||
| %0, %1, %2, %3, %4, %5 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 1, 0, 3>, | ||
| limit_indices = array<i64: 2, 8, 75>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 2 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 3 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| return %5 : tensor<1x8x72xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_only_right( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> tensor<1x8x72xf64> { | ||
| // CHECK: %[[VAL_1:.*]] = stablehlo.slice %[[VAL_0]] [1:2, 0:8, 6:78] : (tensor<20x24x80xf64>) -> tensor<1x8x72xf64> | ||
| // CHECK: return %[[VAL_1]] : tensor<1x8x72xf64> | ||
| // CHECK: } | ||
|
|
||
|
|
||
| // Test 4: Two consecutive results used - should become smaller multi_slice | ||
| func.func @multi_slice_consecutive(%arg0: tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>) { | ||
| %0, %1, %2, %3, %4, %5 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 1, 0, 3>, | ||
| limit_indices = array<i64: 2, 8, 75>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 2 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 3 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| return %2, %3 : tensor<1x8x72xf64>, tensor<1x8x72xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_consecutive( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>) { | ||
| // CHECK: %[[VAL_1:.*]]:2 = "enzymexla.multi_slice"(%[[VAL_0]]) <{dimension = 2 : si32, left_amount = 0 : si32, limit_indices = array<i64: 2, 8, 75>, right_amount = 1 : si32, start_indices = array<i64: 1, 0, 3>, strides = array<i64: 1, 1, 1>}> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| // CHECK: return %[[VAL_1]]#0, %[[VAL_1]]#1 : tensor<1x8x72xf64>, tensor<1x8x72xf64> | ||
| // CHECK: } | ||
|
|
||
|
|
||
| // Test 5: Non-contiguous results used - should keep range between first and last used | ||
| func.func @multi_slice_non_contiguous(%arg0: tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>) { | ||
| %0, %1, %2, %3, %4, %5 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 1, 0, 3>, | ||
| limit_indices = array<i64: 2, 8, 75>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 2 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 3 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| return %2, %5 : tensor<1x8x72xf64>, tensor<1x8x72xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_non_contiguous( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>) { | ||
| // CHECK: %[[VAL_1:.*]]:4 = "enzymexla.multi_slice"(%[[VAL_0]]) <{dimension = 2 : si32, left_amount = 0 : si32, limit_indices = array<i64: 2, 8, 75>, right_amount = 3 : si32, start_indices = array<i64: 1, 0, 3>, strides = array<i64: 1, 1, 1>}> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| // CHECK: return %[[VAL_1]]#0, %[[VAL_1]]#3 : tensor<1x8x72xf64>, tensor<1x8x72xf64> | ||
| // CHECK: } | ||
|
|
||
|
|
||
| // Test 6: All results used - should not change | ||
| func.func @multi_slice_all_used(%arg0: tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) { | ||
| %0, %1, %2, %3, %4, %5 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 1, 0, 3>, | ||
| limit_indices = array<i64: 2, 8, 75>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 2 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 3 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| return %0, %1, %2, %3, %4, %5 : tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_all_used( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) { | ||
| // CHECK: %[[VAL_1:.*]]:6 = "enzymexla.multi_slice"(%[[VAL_0]]) <{dimension = 2 : si32, left_amount = 2 : si32, limit_indices = array<i64: 2, 8, 75>, right_amount = 3 : si32, start_indices = array<i64: 1, 0, 3>, strides = array<i64: 1, 1, 1>}> : (tensor<20x24x80xf64>) -> (tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>) | ||
| // CHECK: return %[[VAL_1]]#0, %[[VAL_1]]#1, %[[VAL_1]]#2, %[[VAL_1]]#3, %[[VAL_1]]#4, %[[VAL_1]]#5 : tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64>, tensor<1x8x72xf64> | ||
| // CHECK: } | ||
|
|
||
|
|
||
| // Test 7: Different dimension - test on dimension 0 | ||
| func.func @multi_slice_dim0(%arg0: tensor<20x24x80xf64>) -> tensor<4x24x80xf64> { | ||
| %0, %1, %2, %3, %4 = "enzymexla.multi_slice"(%arg0) <{ | ||
| start_indices = array<i64: 8, 0, 0>, | ||
| limit_indices = array<i64: 12, 24, 80>, | ||
| strides = array<i64: 1, 1, 1>, | ||
| dimension = 0 : si32, | ||
| left_amount = 2 : si32, | ||
| right_amount = 2 : si32 | ||
| }> : (tensor<20x24x80xf64>) -> (tensor<4x24x80xf64>, tensor<4x24x80xf64>, tensor<4x24x80xf64>, tensor<4x24x80xf64>, tensor<4x24x80xf64>) | ||
| return %2 : tensor<4x24x80xf64> | ||
| } | ||
|
|
||
| // CHECK-LABEL: func.func @multi_slice_dim0( | ||
| // CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: tensor<20x24x80xf64>) -> tensor<4x24x80xf64> { | ||
| // CHECK: %[[VAL_1:.*]] = stablehlo.slice %[[VAL_0]] [8:12, 0:24, 0:80] : (tensor<20x24x80xf64>) -> tensor<4x24x80xf64> | ||
| // CHECK: return %[[VAL_1]] : tensor<4x24x80xf64> | ||
| // CHECK: } |
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.
make sur eto keep sharding