-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][SVE] Add e2e for 1D depthwise WC convolution #85225
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 2 commits into
llvm:main
from
banach-space:andrzej/scalable_depthwise_conv_e2e
Mar 22, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
60 changes: 60 additions & 0 deletions
60
mlir/test/Integration/Dialect/Linalg/CPU/ArmSVE/1d-depthwise-conv.mlir
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,60 @@ | ||
// DEFINE: %{compile} = mlir-opt %s \ | ||
// DEFINE: -transform-interpreter -test-transform-dialect-erase-schedule \ | ||
// DEFINE: -one-shot-bufferize="bufferize-function-boundaries" -lower-vector-mask -cse -canonicalize -convert-vector-to-scf -arm-sve-legalize-vector-storage \ | ||
// DEFINE: -convert-vector-to-llvm="enable-arm-sve" -test-lower-to-llvm -o %t | ||
// DEFINE: %{entry_point} = conv | ||
// DEFINE: %{run} = %mcr_aarch64_cmd %t -e %{entry_point} -entry-point-result=void --march=aarch64 --mattr="+sve"\ | ||
// DEFINE: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils | ||
|
||
// RUN: %{compile} | %{run} | FileCheck %s | ||
|
||
func.func @conv() { | ||
// Define input/output tensors | ||
%input_init = tensor.empty() : tensor<1x8x6xi32> | ||
%output_init = tensor.empty() : tensor<1x7x6xi32> | ||
|
||
%five = arith.constant 5 : i32 | ||
%zero = arith.constant 0 : i32 | ||
%input = linalg.fill ins(%five : i32) outs(%input_init : tensor<1x8x6xi32>) -> tensor<1x8x6xi32> | ||
%output = linalg.fill ins(%zero : i32) outs(%output_init : tensor<1x7x6xi32>) -> tensor<1x7x6xi32> | ||
|
||
// Define the filter tensor | ||
%filter = arith.constant dense<[ | ||
[ 1, 2, 3, 4, 5, 6], | ||
[ 11, 12, 13, 14, 15, 16] | ||
]> : tensor<2x6xi32> | ||
|
||
// static sizes -> dynamic sizes | ||
%input_dyn = tensor.cast %input_init : tensor<1x8x6xi32> to tensor<1x8x?xi32> | ||
%output_dyn = tensor.cast %output : tensor<1x7x6xi32> to tensor<1x7x?xi32> | ||
%filter_dyn = tensor.cast %filter : tensor<2x6xi32> to tensor<2x?xi32> | ||
|
||
// Run the convolution | ||
%res = linalg.depthwise_conv_1d_nwc_wc | ||
ins(%input_dyn, %filter_dyn : tensor<1x8x?xi32>, tensor<2x?xi32>) | ||
outs(%output_dyn : tensor<1x7x?xi32>) -> tensor<1x7x?xi32> | ||
|
||
// Print the results | ||
// CHECK: SVE: START OF TEST OUTPUT | ||
vector.print str "SVE: START OF TEST OUTPUT\n" | ||
|
||
// CHECK-NEXT: Unranked Memref base@ = {{.*}} rank = 3 offset = 0 sizes = [1, 7, 6] strides = [42, 6, 1] data = | ||
// CHECK-COUNT-7: [60, 70, 80, 90, 100, 110] | ||
%xf = tensor.cast %res : tensor<1x7x?xi32> to tensor<*xi32> | ||
call @printMemrefI32(%xf) : (tensor<*xi32>) -> () | ||
|
||
// CHECK-NEXT: SVE: END OF TEST OUTPUT | ||
vector.print str "SVE: END OF TEST OUTPUT\n" | ||
|
||
return | ||
} | ||
|
||
module attributes {transform.with_named_sequence} { | ||
transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { | ||
%0 = transform.structured.match ops{["linalg.depthwise_conv_1d_nwc_wc"]} in %arg0 : (!transform.any_op) -> !transform.any_op | ||
transform.structured.vectorize %0 vector_sizes [1, 7, [8], 2] : !transform.any_op | ||
transform.yield | ||
} | ||
} | ||
|
||
func.func private @printMemrefI32(%ptr : tensor<*xi32>) attributes { llvm.emit_c_interface } |
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.
Here it's both using input + output files (via
-o
), but also piping things. This seems to work when%mcr_aarch64_cmd
is an emulator, but if you replace it withmlir-cpu-runner
(on SVE hardware) the test fails on the first run (but works on the second run).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.
P.s.
-convert-vector-to-scf -arm-sve-legalize-vector-storage -convert-vector-to-llvm="enable-arm-sve"
can be replaced with-convert-vector-to-scf=full-unroll
.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, good catch!
Yeah, the
RUN
should be something like this:// RUN: rm -f %t && %{compile} && %{run} | FileCheck %s
instead. However, the currentRUN
line, when fails, produces:rather than (from https://lab.llvm.org/buildbot/#/builders/176/builds/9331):
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.
A guess: It may depend on the shell/system if the result is an empty file or no file (
Error: entry point not found
seems to indicate the input was empty).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.
That could be the case 🤔
There's https://github.com/llvm/llvm-project/blob/main/mlir/test/Integration/Dialect/Linalg/CPU/ArmSVE/matmul.mlir that works fine with this configuration - we probably just missed that it failed first time it was run. Also a guess :)
If I don't hear back from Omair with other suggestion, I'll merge the updated version around Monday and just monitor the bots to see what happens. Thanks Ben!
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.
No worries, sounds good to me :)
In the matmul test there's a lone
// RUN: %{compile}
, with the run steps separate, which would not have this issue.