[Mlir-commits] [mlir] 06c4f78 - [MLIR][Linalg] improve silenceable failure msg for `lower_pack` (NFC) (#75053)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Dec 12 04:06:21 PST 2023
Author: lorenzo chelini
Date: 2023-12-12T13:06:17+01:00
New Revision: 06c4f78b07aba34c155c792b71587720901ad144
URL: https://github.com/llvm/llvm-project/commit/06c4f78b07aba34c155c792b71587720901ad144
DIFF: https://github.com/llvm/llvm-project/commit/06c4f78b07aba34c155c792b71587720901ad144.diff
LOG: [MLIR][Linalg] improve silenceable failure msg for `lower_pack` (NFC) (#75053)
Adjust the silenceable failure message as we lower `tensor.unpack` as a
combination of `linalg.transpose` + `tensor.collapse_shape` and
`tensor.extract_slice`.
Added:
Modified:
mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
mlir/test/Dialect/Linalg/transform-lower-pack.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index 54055aefbc512..5254aac976f46 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -1125,8 +1125,11 @@ DiagnosedSilenceableFailure transform::LowerUnPackOp::applyToOne(
rewriter.setInsertionPoint(target);
FailureOr<LowerUnPackOpResult> res = lowerUnPack(rewriter, target);
if (failed(res)) {
- return mlir::emitSilenceableFailure(target->getLoc())
- << "cannot rewrite to pad + expand + transpose";
+ DiagnosedSilenceableFailure diag =
+ emitSilenceableError()
+ << "cannot lower to transpose + collapse + extract";
+ diag.attachNote(target->getLoc()) << "target payload op";
+ return diag;
}
transformResults.push_back(res->emptyOp);
transformResults.push_back(res->transposeOp);
diff --git a/mlir/test/Dialect/Linalg/transform-lower-pack.mlir b/mlir/test/Dialect/Linalg/transform-lower-pack.mlir
index 435ae1a1ae064..b9706eed54b60 100644
--- a/mlir/test/Dialect/Linalg/transform-lower-pack.mlir
+++ b/mlir/test/Dialect/Linalg/transform-lower-pack.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -transform-interpreter -cse --split-input-file | FileCheck %s
+// RUN: mlir-opt %s -transform-interpreter -cse -verify-diagnostics -split-input-file | FileCheck %s
// CHECK-LABEL: func.func @pack(
func.func @pack(%arg0: tensor<129x47x16x16xf32>, %arg1: tensor<17x2x16x16x32x8xf32>) -> tensor<17x2x16x16x32x8xf32> {
@@ -143,9 +143,9 @@ func.func @unpack(%arg0: tensor<17x2x16x16x32x8xf32>, %arg1: tensor<129x47x16x16
// CHECK-SAME: : tensor<136x64x16x16xf32> to tensor<129x47x16x16xf32>
// CHECK: linalg.copy ins(%[[SLICE]] : tensor<129x47x16x16xf32>)
// CHECK-SAME: outs(%[[ARG1]] : tensor<129x47x16x16xf32>)
- %pack = tensor.unpack %arg0 inner_dims_pos = [1, 0] inner_tiles = [32, 8] into %arg1
+ %unpack = tensor.unpack %arg0 inner_dims_pos = [1, 0] inner_tiles = [32, 8] into %arg1
: tensor<17x2x16x16x32x8xf32> -> tensor<129x47x16x16xf32>
- return %pack : tensor<129x47x16x16xf32>
+ return %unpack : tensor<129x47x16x16xf32>
}
module attributes {transform.with_named_sequence} {
@@ -162,6 +162,7 @@ module attributes {transform.with_named_sequence} {
}
// -----
+
// When an unpack is a plain 'unpad', lower it to a simple extract_slice.
// CHECK-LABEL: func.func @unpack_as_pad(
func.func @unpack_as_pad(%arg0: tensor<1x1x1x1x136x64x16x16xf32>, %arg1: tensor<129x47x16x16xf32>) -> tensor<129x47x16x16xf32> {
@@ -460,3 +461,27 @@ module attributes {transform.with_named_sequence} {
transform.yield
}
}
+
+// -----
+
+// At the moment, we cannot lower tensor.unpack with outer_dims_perm.
+func.func @diagnostic_unpack(%arg0: tensor<32x64xf32>, %arg1: tensor<2x4x32x8xf32>) -> tensor<32x64xf32> {
+ // expected-note @below {{target payload op}}
+ %unpack = tensor.unpack %arg1 outer_dims_perm = [1, 0]
+ inner_dims_pos = [1, 0] inner_tiles = [32, 8] into %arg0 : tensor<2x4x32x8xf32> -> tensor<32x64xf32>
+ return %unpack : tensor<32x64xf32>
+}
+
+module attributes {transform.with_named_sequence} {
+ transform.named_sequence @__transform_main(%module_op: !transform.any_op {transform.readonly}) {
+ %unpack = transform.structured.match ops{["tensor.unpack"]} in %module_op
+ : (!transform.any_op) -> !transform.op<"tensor.unpack">
+ // expected-error @below {{cannot lower to transpose + collapse + extract}}
+ transform.structured.lower_unpack %unpack : (!transform.op<"tensor.unpack">)
+ -> (!transform.op<"tensor.empty">,
+ !transform.op<"linalg.transpose">,
+ !transform.op<"tensor.collapse_shape">,
+ !transform.op<"tensor.extract_slice">)
+ transform.yield
+ }
+}
More information about the Mlir-commits
mailing list