-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][vector] Propagate vector.extract
through elementwise ops
#131462
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
Changes from 8 commits
8f5ad58
11fe5a3
c92969b
eacec46
72ef7bb
dde1773
bf628cc
64ea88d
a65f072
d3281b5
c4104a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. Instead of adding a new file, could you try adding a new
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. done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// RUN: mlir-opt %s | ||
|
||
// This is smoke test for `transform.apply_patterns.vector.sink_ops` and this | ||
// file is also used in `vector-sink.mlir`. | ||
module attributes {transform.with_named_sequence} { | ||
transform.named_sequence @__transform_main(%module_op: !transform.any_op {transform.readonly}) { | ||
%func = transform.structured.match ops{["func.func"]} in %module_op : (!transform.any_op) -> !transform.any_op | ||
transform.apply_patterns to %func { | ||
transform.apply_patterns.vector.sink_ops | ||
} : !transform.any_op | ||
transform.yield | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// RUN: mlir-opt %s -test-vector-sink-patterns -split-input-file | FileCheck %s | ||
// RUN: mlir-opt -transform-preload-library='transform-library-paths=%p/vector-sink-transform.mlir' -transform-interpreter -split-input-file %s | FileCheck %s | ||
|
||
//----------------------------------------------------------------------------- | ||
// [Pattern: ReorderElementwiseOpsOnBroadcast] | ||
|
@@ -423,3 +424,80 @@ func.func @transpose_elementwise_diff_map_scalable(%a : vector<[4]x6x3x2xf32>, % | |
%r = arith.addf %at, %bt : vector<6x[4]x2x3xf32> | ||
return %r : vector<6x[4]x2x3xf32> | ||
} | ||
|
||
// ----- | ||
|
||
Comment on lines
+427
to
+429
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 block comment documenting which pattern is being tested. 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. done |
||
//----------------------------------------------------------------------------- | ||
// [Pattern: ExtractOpFromElementwise] | ||
//----------------------------------------------------------------------------- | ||
|
||
// CHECK-LABEL: @extract_elementwise_scalar | ||
// CHECK-SAME: (%[[ARG0:.*]]: vector<4xf32>, %[[ARG1:.*]]: vector<4xf32>) | ||
func.func @extract_elementwise_scalar(%arg0: vector<4xf32>, %arg1: vector<4xf32>) -> f32 { | ||
// CHECK: %[[EXT0:.*]] = vector.extract %[[ARG0]][1] : f32 from vector<4xf32> | ||
// CHECK: %[[EXT1:.*]] = vector.extract %[[ARG1]][1] : f32 from vector<4xf32> | ||
// CHECK: %[[RES:.*]] = arith.addf %[[EXT0]], %[[EXT1]] : f32 | ||
// CHECK: return %[[RES]] : f32 | ||
%0 = arith.addf %arg0, %arg1 : vector<4xf32> | ||
%1 = vector.extract %0[1] : f32 from vector<4xf32> | ||
return %1 : f32 | ||
} | ||
|
||
// CHECK-LABEL: @extract_elementwise_arg_res_different_types | ||
// CHECK-SAME: (%[[ARG0:.*]]: vector<4xindex>) | ||
func.func @extract_elementwise_arg_res_different_types(%arg0: vector<4xindex>) -> i64 { | ||
// CHECK: %[[EXT:.*]] = vector.extract %[[ARG0]][1] : index from vector<4xindex> | ||
// CHECK: %[[RES:.*]] = arith.index_cast %[[EXT]] : index to i64 | ||
// CHECK: return %[[RES]] : i64 | ||
%0 = arith.index_cast %arg0: vector<4xindex> to vector<4xi64> | ||
%1 = vector.extract %0[1] : i64 from vector<4xi64> | ||
return %1 : i64 | ||
} | ||
|
||
// CHECK-LABEL: @extract_elementwise_vec | ||
// CHECK-SAME: (%[[ARG0:.*]]: vector<2x4xf32>, %[[ARG1:.*]]: vector<2x4xf32>) | ||
func.func @extract_elementwise_vec(%arg0: vector<2x4xf32>, %arg1: vector<2x4xf32>) -> vector<4xf32> { | ||
// CHECK: %[[EXT0:.*]] = vector.extract %[[ARG0]][1] : vector<4xf32> from vector<2x4xf32> | ||
// CHECK: %[[EXT1:.*]] = vector.extract %[[ARG1]][1] : vector<4xf32> from vector<2x4xf32> | ||
// CHECK: %[[RES:.*]] = arith.addf %[[EXT0]], %[[EXT1]] : vector<4xf32> | ||
// CHECK: return %[[RES]] : vector<4xf32> | ||
%0 = arith.addf %arg0, %arg1 : vector<2x4xf32> | ||
%1 = vector.extract %0[1] : vector<4xf32> from vector<2x4xf32> | ||
return %1 : vector<4xf32> | ||
} | ||
|
||
// CHECK-LABEL: @negative_extract_elementwise_no_single_use | ||
// CHECK-SAME: (%[[ARG0:.*]]: vector<4xf32>, %[[ARG1:.*]]: vector<4xf32>) | ||
func.func @negative_extract_elementwise_no_single_use(%arg0: vector<4xf32>, %arg1: vector<4xf32>) -> (f32, vector<4xf32>) { | ||
// Do not propagate extract, as elementwise has other uses. | ||
// CHECK: %[[ELT:.*]] = arith.addf %[[ARG0]], %[[ARG1]] : vector<4xf32> | ||
// CHECK: %[[EXT:.*]] = vector.extract %[[ELT]][1] : f32 from vector<4xf32> | ||
// CHECK: return %[[EXT]], %[[ELT]] : f32, vector<4xf32> | ||
%0 = arith.addf %arg0, %arg1 : vector<4xf32> | ||
%1 = vector.extract %0[1] : f32 from vector<4xf32> | ||
return %1, %0 : f32, vector<4xf32> | ||
} | ||
|
||
// CHECK-LABEL: @negative_extract_elementwise_not_one_res | ||
// CHECK-SAME: (%[[ARG0:.*]]: vector<4xi32>, %[[ARG1:.*]]: vector<4xi32>) | ||
func.func @negative_extract_elementwise_not_one_res(%arg0: vector<4xi32>, %arg1: vector<4xi32>) -> i32 { | ||
// Do not propagate extract, as elementwise has more than 1 result. | ||
// CHECK: %[[LOW:.*]], %[[HIGH:.*]] = arith.mulsi_extended %[[ARG0]], %[[ARG1]] : vector<4xi32> | ||
// CHECK: %[[EXT:.*]] = vector.extract %[[LOW]][1] : i32 from vector<4xi32> | ||
// CHECK: return %[[EXT]] : i32 | ||
%low, %hi = arith.mulsi_extended %arg0, %arg1 : vector<4xi32> | ||
%1 = vector.extract %low[1] : i32 from vector<4xi32> | ||
return %1 : i32 | ||
} | ||
|
||
// CHECK-LABEL: @negative_extract_not_elementwise | ||
// CHECK-SAME: (%[[ARG0:.*]]: vector<4xi64>) | ||
func.func @negative_extract_not_elementwise(%arg0: vector<4xi64>) -> i64 { | ||
// `test.increment` is not an elemewise op. | ||
// CHECK: %[[INC:.*]] = test.increment %[[ARG0]] : vector<4xi64> | ||
// CHECK: %[[RES:.*]] = vector.extract %[[INC]][1] : i64 from vector<4xi64> | ||
// CHECK: return %[[RES]] : i64 | ||
%0 = test.increment %arg0: vector<4xi64> | ||
%1 = vector.extract %0[1] : i64 from vector<4xi64> | ||
return %1 : i64 | ||
} |
Uh oh!
There was an error while loading. Please reload this page.