-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir] Canonicalize tensor.extract_slice (linalg.fill) #112619
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 |
|---|---|---|
|
|
@@ -352,6 +352,20 @@ func.func @fold_fill_extract(%arg0 : i1) -> i1 { | |
|
|
||
| // ----- | ||
|
|
||
| func.func @fold_fill_extract_slice() -> tensor<2x1920x64x66xf32> { | ||
|
Contributor
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. Please add a negative test, e.g.
Author
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. Could you elaborate why we may need such a test here? To test that such a pattern wouldn't get folded?
Contributor
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.
Indeed. IMHO, we should always try covering "interesting" corner cases (within reason). These tests effectively document the code and its design - a negative test is an example of where the fold should not work. And if anything changes, we will almost immediately know (the test will start failing), |
||
| %c0 = arith.constant 0. : f32 | ||
| %0 = tensor.empty() : tensor<2x1920x66x66xf32> | ||
| %1 = linalg.fill ins(%c0 : f32) outs(%0 : tensor<2x1920x66x66xf32>) -> tensor<2x1920x66x66xf32> | ||
|
Contributor
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. What if this
Contributor
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. It doesnt matter. You will have two fills, one larger, and one smaller. Fills are always better I think (especially in tensor semantics). |
||
| %extracted_slice = tensor.extract_slice %1[0, 0, 1, 0] [2, 1920, 64, 66] [1, 1, 1, 1] : tensor<2x1920x66x66xf32> to tensor<2x1920x64x66xf32> | ||
| return %extracted_slice : tensor<2x1920x64x66xf32> | ||
| } | ||
| // CHECK-LABEL: func.func @fold_fill_extract_slice | ||
| // CHECK: %[[EMPTY_TENSOR:.+]] = tensor.empty() : tensor<2x1920x64x66xf32> | ||
| // CHECK: %[[FILL:.+]] = linalg.fill ins(%{{.+}}) outs(%[[EMPTY_TENSOR]] | ||
| // CHECK: return %[[FILL]] | ||
|
|
||
| // ----- | ||
|
|
||
| func.func @fill_pack() -> tensor<24x32x16x16xf32> { | ||
| %dest = tensor.empty() : tensor<384x512xf32> | ||
| %cst = arith.constant 0.000000e+00 : f32 | ||
|
|
||
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.
[nit] Add a note that this triggers only when there's only one use "by design" (with one use this is obviously beneficial, with multiple uses it is not so clear)