MLIR  16.0.0git
TileUsingInterface.h
Go to the documentation of this file.
1 //===- TileUsingInterface.h - Tiling ops using TilingInterface --*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef MLIR_DIALECT_SCF_TRANSFORMS_TILEUSINGINTERFACE_H
10 #define MLIR_DIALECT_SCF_TRANSFORMS_TILEUSINGINTERFACE_H
11
14 #include "mlir/IR/PatternMatch.h"
16
17 #include <deque>
18
19 namespace mlir {
20 class Operation;
21 class PatternRewriter;
22 class TilingInterface;
23 } // namespace mlir
24
25 namespace mlir {
26 namespace scf {
27
29  std::function<SmallVector<Value>(OpBuilder &, Operation *)>;
30
31 /// Options to use to control tiling.
33  /// Computation function that returns the tile sizes for each operation.
34  /// Delayed construction of constant tile sizes should occur to interoperate
35  /// with folding.
37
40  tileSizeComputationFunction = std::move(fun);
41  return *this;
42  }
43  /// Set the tileSizeComputationFunction to return the values ts. The
44  /// values must not fold away when tiling. Otherwise, use a more robust
45  /// tileSizeComputationFunction.
47  tileSizeComputationFunction = [=](OpBuilder &, Operation *) { return ts; };
48  return *this;
49  }
50  /// Convenience function to set the tileSizeComputationFunction to a
51  /// function that computes tile sizes at the point they are needed. Allows
52  /// proper interaction with folding.
54
55  /// The interchange vector to reorder the tiled loops.
58  interchangeVector = llvm::to_vector(interchange);
59  return *this;
60  }
61 };
62
63 /// Transformation information returned after tiling.
65  /// The tiled operation generated.
67  /// The scf.for operations that iterate over the tiles.
69  /// Values to use as replacements for the untiled op. Is the same size as the
70  /// number of results of the untiled op.
72 };
73
74 /// Method to tile an op that implements the TilingInterface using
75 /// scf.for for iterating over the tiles.
77  TilingInterface op,
79
80 /// Options used to control tile + fuse.
82  /// The tiling options used to control the tiling of the consumer.
85  tilingOptions = options;
86  return *this;
87  }
88 };
89
90 /// Transformation information returned after tile and fuse.
92  /// List of untiled operations that were fused with the tiled consumer.
94  /// List of tiled and fused operations generated. The first one in this list
95  /// is guaranteed to be the tiled operations generated during tiling of the
96  /// generated operation.
98  /// The scf.for operations that iterate over the tiles.
100  /// The replacement values to use for the tiled and fused operations.
102 };
103
104 /// Method to tile and fuse a sequence of operations, by tiling the consumer
105 /// and fusing its producers. Note that this assumes that it is valid to
106 /// tile+fuse the producer into the innermost tiled loop. Its up to the caller
107 /// to ensure that the tile sizes provided make this fusion valid.
108 ///
109 /// For example, for the following sequence
110 ///
111 /// mlir
112 /// %0 =
113 /// %1 = linalg.fill ... outs(%0 : ... )
114 /// %2 = linalg.matmul ... outs(%1 : ...) ...
115 /// 
116 ///
117 /// it is legal to fuse the fill with the matmul only if the matmul is tiled
118 /// along the parallel dimensions and not the reduction dimension, i.e. the tile
119 /// size for the reduction dimension should be 0. The resulting fused
120 /// transformation is
121 ///
122 /// mlir
123 /// %1 = scf.for ... iter_args(%arg0 = %0)
124 /// %2 = tensor.extract_slice %arg0
125 /// %3 = linalg.fill .. outs(%2 : ... )
126 /// %4 = linalg.matmul .. outs(%3 : ...)
127 /// }
128 /// 
131  TilingInterface consumer,
133
134 /// Method to lower an op that implements the TilingInterface to
135 /// loops/scalars.
137 lowerToLoopsUsingSCFForOp(RewriterBase &rewriter, TilingInterface op);
138
139 } // namespace scf
140 } // namespace mlir
141
142 #endif // MLIR_DIALECT_SCF_TRANSFORMS_TILEUSINGINTERFACE_H
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
Definition: Operation.h:28
SCFTilingOptions tilingOptions
The tiling options used to control the tiling of the consumer.
std::function< SmallVector< Value >(OpBuilder &, Operation *)> SCFTileSizeComputationFunction
Transformation information returned after tile and fuse.
SmallVector< scf::ForOp > loops
The scf.for operations that iterate over the tiles.
FailureOr< SCFTileAndFuseResult > tileConsumerAndFuseProducerGreedilyUsingSCFForOp(RewriterBase &rewriter, TilingInterface consumer, SCFTileAndFuseOptions options)
Method to tile and fuse a sequence of operations, by tiling the consumer and fusing its producers...
SmallVector< Value > replacements
Values to use as replacements for the untiled op.
SCFTileSizeComputationFunction tileSizeComputationFunction
Computation function that returns the tile sizes for each operation.
llvm::SetVector< Operation * > tiledAndFusedOps
List of tiled and fused operations generated.
llvm::SetVector< Operation * > fusedProducers
List of untiled operations that were fused with the tiled consumer.
Transformation information returned after tiling.
SCFTileAndFuseOptions & setTilingOptions(SCFTilingOptions options)
This class provides support for representing a failure result, or a valid value of type T...
Definition: LogicalResult.h:78
FailureOr< SmallVector< scf::ForOp > > lowerToLoopsUsingSCFForOp(RewriterBase &rewriter, TilingInterface op)
Method to lower an op that implements the TilingInterface to loops/scalars.
FailureOr< SCFTilingResult > tileUsingSCFForOp(RewriterBase &rewriter, TilingInterface op, SCFTilingOptions options)
Method to tile an op that implements the TilingInterface using scf.for for iterating over the tiles...
SmallVector< unsigned > interchangeVector
The interchange vector to reorder the tiled loops.
llvm::DenseMap< Value, Value > replacements
The replacement values to use for the tiled and fused operations.
SCFTilingOptions & setTileSizeComputationFunction(SCFTileSizeComputationFunction fun)
static llvm::ManagedStatic< PassManagerOptions > options
Options to use to control tiling.
SmallVector< scf::ForOp > loops
The scf.for operations that iterate over the tiles.
SCFTilingOptions & setTileSizes(const SmallVector< Value, 4 > &ts)
Set the tileSizeComputationFunction to return the values ts.
This class helps build Operations.
Definition: Builders.h:197
SCFTilingOptions & setInterchange(ArrayRef< unsigned > interchange)
Operation * tiledOp
The tiled operation generated.
Options used to control tile + fuse.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
Definition: PatternMatch.h:398