@@ -37,6 +37,14 @@ struct TiledLinalgOp {
3737 SmallVector<Value, 4 > tensorResults;
3838};
3939
40+ struct TiledAndFusedLinalgOps {
41+ LinalgOp op;
42+ SmallVector<LinalgOp, 1 > fusedProducers;
43+ SmallVector<LinalgOp, 1 > originalProducers;
44+ SmallVector<Operation *, 4 > fusedLoops;
45+ SmallVector<Operation *, 4 > unfusedLoops;
46+ };
47+
4048// / Populates patterns for vectorization of all ConvN-D ops.
4149void populateConvVectorizationPatterns (
4250 MLIRContext *context, SmallVectorImpl<OwningRewritePatternList> &patterns,
@@ -65,11 +73,14 @@ void populateLinalgBufferizePatterns(MLIRContext *context,
6573Optional<TiledLinalgOp> tileLinalgOp (OpBuilder &b, LinalgOp op,
6674 const LinalgTilingOptions &options);
6775
68- // / Fuse a sequence of linalg operations (`ops`) using tile-and-fuse. This
69- // / proceeds as follows:
70- // / - Find outer parallel loops in these ops that can be fused.
71- // / - Tile fusable outer parallel loops of the last operation in the sequence.
72- // / - Fuse the remaining operations with the tiled operation
76+ // / Tile and fuse the `op` with its producers. The tile and fuse proceeds in
77+ // / three steps
78+ // / - Find tile loops that are fusable with its producer tile loops (a.k.a. tile
79+ // / + fuse loops).
80+ // / - Tile just these loops of the consumer (root operation) and fuse with
81+ // / the producer.
82+ // / - Tile again the tiled consumer operation produced above to do rest of
83+ // / the tiling specified by the `tilingOptions`.
7384// /
7485// / For example, consider the sequence of matmul below
7586// /
@@ -96,39 +107,36 @@ Optional<TiledLinalgOp> tileLinalgOp(OpBuilder &b, LinalgOp op,
96107// / : memref<256x32xf32> to memref<16x32xf32, #map0>
97108// / %3 = subview %arg1[0, 0] [32, 32] [1, 1]
98109// / : memref<32x32xf32> to memref<32x32xf32, #map1>
99- // / %4 = subview %arg3[0, 0] [32, 32] [1, 1]
100- // / : memref<32x32xf32> to memref<32x32xf32, #map1>
101110// / linalg.matmul
102111// / ins(%2, %3 : memref<16x32xf32, #map0>, memref<32x32xf32, #map1>)
103112// / outs(%0 : memref<16x32xf32, #map0>)
104- // / linalg.matmul
105- // / ins(%0, %4 : memref<16x4xf32, #map0>, memref<4x8xf32, #map0>)
106- // / outs(%1 : memref<16x8xf32, #map0>)
113+ // / scf.parallel (%arg6) = (%c0) to (%c32) step (%c8) {
114+ // / scf.for %arg7 = %c0 to %c32 step %c4 {
115+ // / %4 = subview %0[0, %arg7] [16, 4] [1, 1]
116+ // / : memref<16x32xf32, #map0> to memref<16x4xf32, #map0>
117+ // / %5 = subview %arg3[%arg7, %arg6] [4, 8] [1, 1]
118+ // / : memref<32x32xf32> to memref<4x8xf32, #map0>
119+ // / %6 = subview %1[0, %arg6] [16, 8] [1, 1]
120+ // / : memref<16x32xf32, #map0> to memref<16x8xf32, #map0>
121+ // / linalg.matmul
122+ // / ins(%4, %5 : memref<16x4xf32, #map0>, memref<4x8xf32, #map0>)
123+ // / outs(%6 : memref<16x8xf32, #map0>)
124+ // / }
125+ // / scf.yield
126+ // / }
127+ // / scf.yield
107128// / }
108129// /
109- // / `tilingOptions` are used to tile the corresponding operation in `ops` (the
110- // / size of the former should be same as size of the latter. Based on how
111- // / tile+fuse is implemented, the fused loops are generated based on the last
112- // / operation in the sequence. For example, the tile sizes for the fused loops
113- // / is obtained from `tilingOptions.back()`. The following tiling options are
114- // / handled differently in tile+fuse (compared to tile only)
130+ // / The following tiling options are handled differently in tile+fuse (compared
131+ // / to tile only)
115132// / - Interchange of the tiling loops is not supported right now.
116- // / - Only the fused loops are distributed.
117- struct TiledAndFusedLinalgOps {
118- // / Operation obtained by tiling the last operation in sequence of `ops`
119- // / passed to `tileAndFuseLinalgOps`.
120- LinalgOp op;
121- // / The dimension of the loops that are fused.
122- std::set<unsigned > fusedLoopDims;
123- // / The generated fused operations (created within the fused loops).
124- SmallVector<LinalgOp, 1 > fusedProducers;
125- // / The fused loop generated.
126- SmallVector<Operation *, 4 > fusedLoops;
127- };
133+ // / - Distribution is only done for the tile+fuse loops. The tiled loops
134+ // / generated by the second tiling is not distributed.
128135Optional<TiledAndFusedLinalgOps>
129- tileAndFuseLinalgOps (OpBuilder &builder, ArrayRef< LinalgOp> ops ,
136+ tileAndFuseLinalgOps (PatternRewriter &rewriter, LinalgOp op ,
130137 const LinalgDependenceGraph &dependenceGraph,
131- const LinalgTilingOptions &tilingOptions);
138+ const LinalgTilingOptions &tilingOptions,
139+ const LinalgFusionOptions &fusionOptions);
132140
133141// / Interchanges the `iterator_types` and `iterator_maps` dimensions of `op`.
134142// / This is an in-place transformation controlled by `interchangeVector`.
@@ -234,20 +242,6 @@ struct LinalgPromotionOptions {
234242 }
235243};
236244
237- // / Creates a new buffer using the `allocationFn` provided. The size of this
238- // / buffer is the smallest constant bounding size along each dimension that can
239- // / be computed for the size of the result of `subView`. Returns the allocated
240- // / buffer as `fullLocalView` and the view that matches the size of the result
241- // / of subview operation as `partialLocalView`.
242- struct PromotionInfo {
243- Value fullLocalView;
244- Value partialLocalView;
245- };
246- Optional<PromotionInfo>
247- promoteSubviewAsNewBuffer (OpBuilder &b, Location loc, SubViewOp subView,
248- AllocBufferCallbackFn allocationFn,
249- OperationFolder *folder = nullptr );
250-
251245// / Promotes the `subViews` into a new buffer allocated at the insertion point
252246// / `b`. Promotion occurs in 3 steps:
253247// / 1. Create a new buffer for a full tile (i.e. not clipped at the boundary).
0 commit comments