-
Notifications
You must be signed in to change notification settings - Fork 645
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
Add pass to bubble-up extract_slice operations. #18332
Add pass to bubble-up extract_slice operations. #18332
Conversation
This adds pass to replace a `tensor.extract_slice` operation with a slice of the producer. In general there might be more opportunities to use this pass more aggressively (like when an operation has a single use which is a slice), but for now this is being done only for bit-extend operations. Signed-off-by: MaheshRavishankar <[email protected]>
Signed-off-by: MaheshRavishankar <[email protected]>
Signed-off-by: MaheshRavishankar <[email protected]>
75dbd33
to
0df11d3
Compare
I tried https://gist.github.com/monorimet/3a0a4310c1ed09265353ce747599d502 but it seems like there is a %4 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2) -> (d0, d1, d2)>, affine_map<(d0, d1, d2) -> (d0, d1, d2)>], iterator_types = ["parallel", "parallel", "parallel"]} ins(%collapsed : tensor<24x4608x128xf16>) outs(%3 : tensor<24x4608x128xf32>) {
^bb0(%in: f16, %out: f32):
%21 = arith.extf %in : f16 to f32
linalg.yield %21 : f32
} -> tensor<24x4608x128xf32>
%expanded = tensor.expand_shape %4 [[0, 1], [2], [3, 4, 5]] output_shape [1, 24, 4608, 64, 1, 2] : tensor<24x4608x128xf32> into tensor<1x24x4608x64x1x2xf32>
%extracted_slice_7 = tensor.extract_slice %expanded[0, 0, 0, 0, 0, 1] [1, 24, 4608, 64, 1, 1] [1, 1, 1, 1, 1, 1] : tensor<1x24x4608x64x1x2xf32> to tensor<24x4608x64xf32>
%expanded_8 = tensor.expand_shape %extracted_slice_7 [[0, 1], [2], [3, 4]] output_shape [1, 24, 4608, 64, 1] : tensor<24x4608x64xf32> into tensor<1x24x4608x64x1xf32> also, iree/compiler/Dialect/Flow/Transforms/test/bubble_up_extract_slice.mlir just needs to be updated to use Edit: It seems like the expand/extracts should be foldable |
That makes sense. I should just run this after bubble up expand shapes. |
Signed-off-by: Ian Wood <[email protected]>
Signed-off-by: Ian Wood <[email protected]>
Signed-off-by: Ian Wood <[email protected]>
Signed-off-by: Ian Wood <[email protected]>
Probably needs more tests. I added a rank reduced slice test, we want without rank reduction |
Someone else should review this since I co-authored this commit. Probably needs more tests. I added a rank reduced slice test, we want without rank reduction slice test always |
Signed-off-by: Ian Wood <[email protected]>
9e1d446
to
5748e9f
Compare
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.
Overall looks good, I have some concerns about the ordering of some of the failure cases within the pattern though.
compiler/src/iree/compiler/DispatchCreation/BubbleUpExtractSlices.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/DispatchCreation/BubbleUpExtractSlices.cpp
Outdated
Show resolved
Hide resolved
if (tilingResult->tiledOps.size() != 1 || | ||
!isa<linalg::GenericOp>(tilingResult->tiledOps[0])) { | ||
return rewriter.notifyMatchFailure( | ||
linalgOp, "expected extract_slice to generate a `linalg.generic`"); |
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.
Failure after generating IR in a pattern is problematic. At a minimum I would restrict to generics like I said above, but also would be worth adding checks for isProjectedPermutation(indexingMaps)
and !hasIndexSemantics
.
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.
Good point, I removed this check and added the checks you suggested before IR mutation. I also changed the failed
checks so asserts since there is no graceful way to exit at that point
Signed-off-by: Ian Wood <[email protected]>
Signed-off-by: Ian Wood <[email protected]>
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.
Nice, this looks good to me!
@ScottTodd
I don't think it is related to this pr because I was getting a segfault during torch conversion, Should the rdna3 config be updated similar to what was done in #18357? |
THis is existing error. We've been hitting this all week |
Oh, you can merge even with the failure |
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 @IanWood1 !
Great, I wasn't sure! |
This adds pass to replace a `tensor.extract_slice` operation with a slice of the producer. In general there might be more opportunities to use this pass more aggressively (like when an operation has a single use which is a slice), but for now this is being done only for bit-extend operations. Co-authored-by: Ian Wood <[email protected]>
This adds pass to replace a
tensor.extract_slice
operation with aslice of the producer. In general there might be more opportunities to
use this pass more aggressively (like when an operation has a single
use which is a slice), but for now this is being done only for
bit-extend operations.
Fixes #18254
Signed-off-by: MaheshRavishankar [email protected]