[Mlir-commits] [mlir] [MLIR][SCF] Add an API to fuse consumer to a producer within scf loop (PR #88712)

Quinn Dawkins llvmlistbot at llvm.org
Tue May 21 06:37:24 PDT 2024


================
@@ -160,6 +215,21 @@ struct LinalgOpTilingInterface
     return success();
   }
 
+  FailureOr<TilingResult> getTiledImplementationFromOperandTile(
+      Operation *op, OpBuilder &b, unsigned operandNumber,
+      ArrayRef<OpFoldResult> offsets, ArrayRef<OpFoldResult> sizes) const {
+    SmallVector<OpFoldResult> mappedOffsets, mappedSizes;
+    auto tilingInterfaceOp = cast<TilingInterface>(op);
+    if (failed(tilingInterfaceOp.getIterationDomainTileFromOperandTile(
+            b, operandNumber, offsets, sizes, mappedOffsets, mappedSizes))) {
+      return emitError(
+          op->getLoc(),
+          "unable to obtain the iter domain position of the operation.");
+    }
+    return tilingInterfaceOp.getTiledImplementation(b, mappedOffsets,
+                                                    mappedSizes);
----------------
qedawkins wrote:

> As you said above, the root cause comes from using tensor.extract_slice to extract the tiled result. But NOTE that, this IR is not the FINAL result, after redirecting operand of tiled consumer, there is no use for %4 any more as I illustrated https://github.com/llvm/llvm-project/pull/88712#:~:text=Then%2C%20the%20resulting%20IR%20will%20become%3A. You can also check the latest test mlir [result](https://github.com/llvm/llvm-project/blob/41123a2871c752cdbbdece54cd7fb11a9a95c768/mlir/test/Interfaces/TilingInterface/tile-and-fuse-consumer.mlir#L102-L110) whether meet your expectation?

The problem is not that there was temporarily invalid IR (that's common to have in patterns that manipulate regions) but instead that the consumer fusion pattern was responsible for fixing the potentially invalid IR in a way that was dependent on the tiling implementation.

> During the downstream integration we don't want to add additional overhead of sending std::nullopt in all invocations of getTiledImplementation - please let me know if there's a way that I can achieve the following if you feel the above design is not welcomed :-

Agree. I'm definitely open to other suggestions but what you added here makes the most sense to me. The other option is to omit the default implementation of `getTiledImplementationFromOperandTile` and do the extract_slice fixup per tiling implementation, but for that I'd like feedback from @ftynse and @MaheshRavishankar following the discussion above (although I don't think that this new API is even a valid composition of `getTiledImplementation` and `getIterationDomainTileFromOperandTile`).

https://github.com/llvm/llvm-project/pull/88712


More information about the Mlir-commits mailing list