[Mlir-commits] [mlir] 526dfe3 - [mlir][Linalg] Do not return failure when all tile sizes are zero.

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Nov 18 09:28:38 PST 2021


Author: MaheshRavishankar
Date: 2021-11-18T09:28:25-08:00
New Revision: 526dfe3f4d33eea3d32cd8730e5dcbc1b9010d3f

URL: https://github.com/llvm/llvm-project/commit/526dfe3f4d33eea3d32cd8730e5dcbc1b9010d3f
DIFF: https://github.com/llvm/llvm-project/commit/526dfe3f4d33eea3d32cd8730e5dcbc1b9010d3f.diff

LOG: [mlir][Linalg] Do not return failure when all tile sizes are zero.

Returning failure when tile sizes are all zero prevents the change in
the marker. This makes pattern rewriter run the pattern multiple times
only to exit when it hits a limit. Instead just clone the operation
(since tiling is essentially cloning in this case). Then the
transformation filter kicks in to avoid the pattern rewriter to be
invoked many times.

Differential Revision: https://reviews.llvm.org/D113949

Added: 
    mlir/test/Dialect/Linalg/tile-zero.mlir

Modified: 
    mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
index 8ccdb7f62246e..0a41153669083 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp
@@ -159,8 +159,13 @@ tileLinalgOpImpl(OpBuilder &b, LinalgOp op, ValueRange tileSizes,
   // Initial tile sizes may be too big, only take the first nLoops.
   tileSizes = tileSizes.take_front(nLoops);
 
-  if (llvm::all_of(tileSizes, isZero))
-    return failure();
+  if (llvm::all_of(tileSizes, isZero)) {
+    TiledLinalgOp tiledOp;
+    tiledOp.op = cast<LinalgOp>(b.clone(*op.getOperation()));
+    tiledOp.tensorResults.assign(tiledOp.op->result_begin(),
+                                 tiledOp.op->result_end());
+    return tiledOp;
+  }
 
   // 1. Build the tiled loop ranges.
   auto allShapeSizes = op.createFlatListOfOperandDims(b, op.getLoc());

diff  --git a/mlir/test/Dialect/Linalg/tile-zero.mlir b/mlir/test/Dialect/Linalg/tile-zero.mlir
new file mode 100644
index 0000000000000..1a09906e52ce7
--- /dev/null
+++ b/mlir/test/Dialect/Linalg/tile-zero.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt -test-linalg-transform-patterns=test-tile-pattern %s | FileCheck %s
+
+func @matmul_zero_tile(
+  %arg0: tensor<?x?xf32>, %arg1 : tensor<?x?xf32>, %arg2 : tensor<?x?xf32>) -> tensor<?x?xf32> {
+  %0 = linalg.matmul {__internal_linalg_transform__ = "tile"}
+      ins(%arg0, %arg1 : tensor<?x?xf32>, tensor<?x?xf32>)
+      outs(%arg2 : tensor<?x?xf32>) -> tensor<?x?xf32>
+  return %0 : tensor<?x?xf32>
+}
+// CHECK-LABEL: matmul_zero_tile
+//       CHECK:   linalg.matmul
+//   CHECK-NOT:   __internal_linalg_transform__


        


More information about the Mlir-commits mailing list