Skip to content

Commit 53e607e

Browse files
[MLIR][SCF] Add an API to fuse consumer to a producer within scf loop
-- This commit adds an API to fuse consumer to a producer within scf.for/scf.forall loop. Signed-off-by: Abhishek Varma <[email protected]>
1 parent 2a47ee0 commit 53e607e

File tree

7 files changed

+831
-1
lines changed

7 files changed

+831
-1
lines changed

mlir/include/mlir/Dialect/SCF/Transforms/TileUsingInterface.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mlir/IR/PatternMatch.h"
1515
#include "mlir/Interfaces/LoopLikeInterface.h"
1616
#include "mlir/Interfaces/TilingInterface.h"
17+
#include "mlir/Interfaces/ViewLikeInterface.h"
1718

1819
#include <deque>
1920

@@ -239,6 +240,18 @@ tileConsumerAndFuseProducersUsingSCF(RewriterBase &rewriter,
239240
TilingInterface consumer,
240241
const SCFTileAndFuseOptions &options);
241242

243+
/// Fuse the consumer of the source of `candidateSliceOp` by computing the
244+
/// required slice of the consumer in-place. Note that the method
245+
/// replaces the uses of `candidateSliceOp` with the tiled and fused consumer
246+
/// value but does not delete the slice operation.
247+
struct SCFFuseConsumerOfSliceResult {
248+
Operation *origConsumer; // Original untiled consumer.
249+
Operation *tiledAndFusedConsumer; // Tiled and fused consumer op.
250+
SmallVector<Operation *> tiledOps;
251+
};
252+
FailureOr<scf::SCFFuseConsumerOfSliceResult>
253+
tileAndFuseConsumerOfSlice(RewriterBase &rewriter, Operation *candidateSliceOp);
254+
242255
/// Method to lower an `op` that implements the `TilingInterface` to
243256
/// loops/scalars.
244257
FailureOr<SmallVector<scf::ForOp>>

mlir/include/mlir/Dialect/Tensor/Transforms/Transforms.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "mlir/Dialect/Tensor/IR/Tensor.h"
1313
#include "mlir/IR/PatternMatch.h"
14+
#include "mlir/Interfaces/ViewLikeInterface.h"
1415

1516
namespace mlir {
1617

@@ -22,14 +23,24 @@ namespace tensor {
2223
// Patterns
2324
//===----------------------------------------------------------------------===//
2425

25-
/// Pattern to swap an `tensor.extract_slice` with its producer when the
26+
/// Method to swap an `tensor.extract_slice` with its producer when the
2627
/// producer implements the `TilingInterface`. The pattern itself does not
2728
/// provide a mechanism to control where the application happens. With use of
2829
/// transform dialect that control is done within the transform dialect. Other
2930
/// use cases can inherit from this pattern and add necessary controls.
3031
FailureOr<TilingResult> replaceExtractSliceWithTiledProducer(
3132
OpBuilder &builder, tensor::ExtractSliceOp sliceOp, OpResult producerOp);
3233

34+
/// Method to swap an `tensor.insert_slice` with its consumer when the
35+
/// consumer implements the `TilingInterface`. The pattern itself does not
36+
/// provide a mechanism to control where the application happens. With use of
37+
/// transform dialect that control is done within the transform dialect. Other
38+
/// use cases can inherit from this pattern and add necessary controls.
39+
FailureOr<TilingResult>
40+
replaceInsertSliceWithTiledConsumer(OpBuilder &builder,
41+
OffsetSizeAndStrideOpInterface sliceOp,
42+
OpOperand &consumerOp);
43+
3344
//===----------------------------------------------------------------------===//
3445
// Populate functions.
3546
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)