From 526dfe3f4d33eea3d32cd8730e5dcbc1b9010d3f Mon Sep 17 00:00:00 2001 From: MaheshRavishankar Date: Thu, 18 Nov 2021 09:27:27 -0800 Subject: [PATCH] [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 --- mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp | 9 +++++++-- mlir/test/Dialect/Linalg/tile-zero.mlir | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 mlir/test/Dialect/Linalg/tile-zero.mlir diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp index 8ccdb7f62246..0a4115366908 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(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 000000000000..1a09906e52ce --- /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, %arg1 : tensor, %arg2 : tensor) -> tensor { + %0 = linalg.matmul {__internal_linalg_transform__ = "tile"} + ins(%arg0, %arg1 : tensor, tensor) + outs(%arg2 : tensor) -> tensor + return %0 : tensor +} +// CHECK-LABEL: matmul_zero_tile +// CHECK: linalg.matmul +// CHECK-NOT: __internal_linalg_transform__