1 //===- Tiling.cpp - Implementation of linalg Tiling -----------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the linalg dialect Tiling pass. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "PassDetail.h" 14 #include "mlir/Dialect/Affine/EDSC/Intrinsics.h" 15 #include "mlir/Dialect/Linalg/EDSC/FoldedIntrinsics.h" 16 #include "mlir/Dialect/Linalg/IR/LinalgTypes.h" 17 #include "mlir/Dialect/Linalg/Passes.h" 18 #include "mlir/Dialect/Linalg/Utils/Utils.h" 19 #include "mlir/Dialect/LoopOps/EDSC/Builders.h" 20 #include "mlir/Dialect/StandardOps/EDSC/Intrinsics.h" 21 #include "mlir/IR/AffineExpr.h" 22 #include "mlir/IR/AffineExprVisitor.h" 23 #include "mlir/IR/AffineMap.h" 24 #include "mlir/Support/LLVM.h" 25 #include "mlir/Transforms/FoldUtils.h" 26 27 #include "llvm/Support/CommandLine.h" 28 29 using namespace mlir; 30 using namespace mlir::edsc; 31 using namespace mlir::edsc::intrinsics; 32 using namespace mlir::linalg; 33 using namespace mlir::loop; 34 35 using folded_affine_min = FoldedValueBuilder<AffineMinOp>; 36 37 #define DEBUG_TYPE "linalg-tiling" 38 39 static bool isZero(Value v) { 40 return isa_and_nonnull<ConstantIndexOp>(v.getDefiningOp()) && 41 cast<ConstantIndexOp>(v.getDefiningOp()).getValue() == 0; 42 } 43 44 using LoopIndexToRangeIndexMap = DenseMap<int, int>; 45 46 // Creates a number of ranges equal to the number of non-zero in `tileSizes`. 47 // One for each loop of the LinalgOp that is tiled. The `tileSizes` argument has 48 // one entry per surrounding loop. It uses zero as the convention that a 49 // particular loop is not tiled. This convention simplifies implementations by 50 // avoiding affine map manipulations. 51 // The returned ranges correspond to the loop ranges, in the proper order, that 52 // are tiled and for which new loops will be created. Also the function returns 53 // a map from loop indices of the LinalgOp to the corresponding non-empty range 54 // indices of newly created loops. 55 static std::tuple<SmallVector<SubViewOp::Range, 4>, LoopIndexToRangeIndexMap> 56 makeTiledLoopRanges(OpBuilder &b, Location loc, AffineMap map, 57 ArrayRef<Value> allViewSizes, ArrayRef<Value> allTileSizes, 58 OperationFolder *folder) { 59 assert(allTileSizes.size() == map.getNumResults()); 60 // Apply `map` to get view sizes in loop order. 61 auto viewSizes = applyMapToValues(b, loc, map, allViewSizes, folder); 62 SmallVector<Value, 4> tileSizes(allTileSizes.begin(), allTileSizes.end()); 63 64 // Traverse the tile sizes, which are in loop order, erase zeros everywhere. 65 LoopIndexToRangeIndexMap loopIndexToRangeIndex; 66 for (int idx = 0, e = tileSizes.size(), zerosCount = 0; idx < e; ++idx) { 67 if (isZero(tileSizes[idx - zerosCount])) { 68 viewSizes.erase(viewSizes.begin() + idx - zerosCount); 69 tileSizes.erase(tileSizes.begin() + idx - zerosCount); 70 ++zerosCount; 71 continue; 72 } 73 loopIndexToRangeIndex[idx] = idx - zerosCount; 74 } 75 76 // Create a new range with the applied tile sizes. 77 SmallVector<SubViewOp::Range, 4> res; 78 for (unsigned idx = 0, e = tileSizes.size(); idx < e; ++idx) { 79 res.push_back(SubViewOp::Range{folded_std_constant_index(folder, 0), 80 viewSizes[idx], tileSizes[idx]}); 81 } 82 return std::make_tuple(res, loopIndexToRangeIndex); 83 } 84 85 namespace { 86 87 // Helper visitor to determine whether an AffineExpr is tiled. 88 // This is achieved by traversing every AffineDimExpr with position `pos` and 89 // checking whether the corresponding `tileSizes[pos]` is non-zero. 90 // This also enforces only positive coefficients occur in multiplications. 91 // 92 // Example: 93 // `d0 + 2 * d1 + d3` is tiled by [0, 0, 0, 2] but not by [0, 0, 2, 0] 94 // 95 struct TileCheck : public AffineExprVisitor<TileCheck> { 96 TileCheck(ArrayRef<Value> tileSizes) : isTiled(false), tileSizes(tileSizes) {} 97 98 void visitDimExpr(AffineDimExpr expr) { 99 isTiled |= !isZero(tileSizes[expr.getPosition()]); 100 } 101 void visitAffineBinaryOpExpr(AffineBinaryOpExpr expr) { 102 visit(expr.getLHS()); 103 visit(expr.getRHS()); 104 if (expr.getKind() == mlir::AffineExprKind::Mul) 105 assert(expr.getRHS().cast<AffineConstantExpr>().getValue() > 0 && 106 "nonpositive multiplying coefficient"); 107 } 108 bool isTiled; 109 ArrayRef<Value> tileSizes; 110 }; 111 112 } // namespace 113 114 // IndexedGenericOp explicitly uses induction variables in the loop body. The 115 // values of the indices that are used in the loop body for any given access of 116 // input/output memref before `subview` op was applied should be invariant with 117 // respect to tiling. 118 // 119 // Therefore, if the operation is tiled, we have to transform the indices 120 // accordingly, i.e. offset them by the values of the corresponding induction 121 // variables that are captured implicitly in the body of the op. 122 // 123 // Example. `linalg.indexed_generic` before tiling: 124 // 125 // #id_2d = (i, j) -> (i, j) 126 // #pointwise_2d_trait = { 127 // indexing_maps = [#id_2d, #id_2d], 128 // iterator_types = ["parallel", "parallel"], 129 // n_views = [1, 1] 130 // } 131 // linalg.indexed_generic #pointwise_2d_trait %operand, %result { 132 // ^bb0(%i: index, %j: index, %operand_in: f32, %result_in: f32): 133 // <some operations that use %i, %j> 134 // }: memref<50x100xf32>, memref<50x100xf32> 135 // 136 // After tiling pass with tiles sizes 10 and 25: 137 // 138 // #strided = (i, j)[s0, s1, s2] -> (i * s1 + s0 + j * s2) 139 // 140 // %c1 = constant 1 : index 141 // %c0 = constant 0 : index 142 // %c25 = constant 25 : index 143 // %c10 = constant 10 : index 144 // operand_dim_0 = dim %operand, 0 : memref<50x100xf32> 145 // operand_dim_1 = dim %operand, 1 : memref<50x100xf32> 146 // loop.for %k = %c0 to operand_dim_0 step %c10 { 147 // loop.for %l = %c0 to operand_dim_1 step %c25 { 148 // %4 = std.subview %operand[%k, %l][%c10, %c25][%c1, %c1] 149 // : memref<50x100xf32> to memref<?x?xf32, #strided> 150 // %5 = std.subview %result[%k, %l][%c10, %c25][%c1, %c1] 151 // : memref<50x100xf32> to memref<?x?xf32, #strided> 152 // linalg.indexed_generic pointwise_2d_trait %4, %5 { 153 // ^bb0(%i: index, %j: index, %operand_in: f32, %result_in: f32): 154 // // Indices `k` and `l` are implicitly captured in the body. 155 // %transformed_i = addi %i, %k : index // index `i` is offset by %k 156 // %transformed_j = addi %j, %l : index // index `j` is offset by %l 157 // // Every use of %i, %j is replaced with %transformed_i, %transformed_j 158 // <some operations that use %transformed_i, %transformed_j> 159 // }: memref<?x?xf32, #strided>, memref<?x?xf32, #strided> 160 // } 161 // } 162 // 163 // TODO(pifon, ntv): Investigate whether mixing implicit and explicit indices 164 // does not lead to losing information. 165 static void transformIndexedGenericOpIndices( 166 OpBuilder &b, LinalgOp op, SmallVectorImpl<Value> &ivs, 167 const LoopIndexToRangeIndexMap &loopIndexToRangeIndex) { 168 assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics"); 169 auto indexedGenericOp = dyn_cast<IndexedGenericOp>(op.getOperation()); 170 if (!indexedGenericOp) 171 return; 172 173 // `linalg.indexed_generic` comes in two flavours. One has a region with a 174 // single block that defines the loop body. The other has a `fun` attribute 175 // that refers to an existing function symbol. The `fun` function call will be 176 // inserted in the loop body in that case. 177 // 178 // TODO(pifon): Add support for `linalg.indexed_generic` with `fun` attribute. 179 auto ®ion = indexedGenericOp.region(); 180 if (region.empty()) { 181 indexedGenericOp.emitOpError("expected a region"); 182 return; 183 } 184 auto &block = region.getBlocks().front(); 185 186 OpBuilder::InsertionGuard g(b); 187 b.setInsertionPointToStart(&block); 188 for (unsigned i = 0; i < indexedGenericOp.getNumLoops(); ++i) { 189 auto rangeIndex = loopIndexToRangeIndex.find(i); 190 if (rangeIndex == loopIndexToRangeIndex.end()) 191 continue; 192 Value oldIndex = block.getArgument(i); 193 // Offset the index argument `i` by the value of the corresponding induction 194 // variable and replace all uses of the previous value. 195 Value newIndex = b.create<AddIOp>(indexedGenericOp.getLoc(), oldIndex, 196 ivs[rangeIndex->second]); 197 for (auto &use : oldIndex.getUses()) { 198 if (use.getOwner() == newIndex.getDefiningOp()) 199 continue; 200 use.set(newIndex); 201 } 202 } 203 } 204 205 static bool isTiled(AffineExpr expr, ArrayRef<Value> tileSizes) { 206 if (!expr) 207 return false; 208 TileCheck t(tileSizes); 209 t.visit(expr); 210 return t.isTiled; 211 } 212 213 // Checks whether the view with index `viewIndex` within `linalgOp` varies with 214 // respect to a non-zero `tileSize`. 215 static bool isTiled(AffineMap map, ArrayRef<Value> tileSizes) { 216 if (!map) 217 return false; 218 for (unsigned r = 0; r < map.getNumResults(); ++r) 219 if (isTiled(map.getResult(r), tileSizes)) 220 return true; 221 return false; 222 } 223 224 static SmallVector<Value, 4> 225 makeTiledViews(OpBuilder &b, Location loc, LinalgOp linalgOp, 226 ArrayRef<Value> ivs, ArrayRef<Value> tileSizes, 227 ArrayRef<Value> viewSizes, OperationFolder *folder) { 228 assert(linalgOp.hasBufferSemantics() && 229 "expected linalg op with buffer semantics"); 230 assert(ivs.size() == static_cast<size_t>(llvm::count_if( 231 llvm::make_range(tileSizes.begin(), tileSizes.end()), 232 [](Value v) { return !isZero(v); })) && 233 "expected as many ivs as non-zero sizes"); 234 235 using namespace edsc::op; 236 237 // Construct (potentially temporary) mins and maxes on which to apply maps 238 // that define tile subviews. 239 SmallVector<Value, 8> lbs, subViewSizes; 240 for (unsigned idx = 0, idxIvs = 0, e = tileSizes.size(); idx < e; ++idx) { 241 bool isTiled = !isZero(tileSizes[idx]); 242 lbs.push_back(isTiled ? ivs[idxIvs++] 243 : (Value)folded_std_constant_index(folder, 0)); 244 subViewSizes.push_back(isTiled ? tileSizes[idx] : viewSizes[idx]); 245 } 246 247 auto *op = linalgOp.getOperation(); 248 249 SmallVector<Value, 4> res; 250 res.reserve(op->getNumOperands()); 251 auto viewIteratorBegin = linalgOp.getInputsAndOutputBuffers().begin(); 252 for (unsigned viewIndex = 0; viewIndex < linalgOp.getNumInputsAndOutputs(); 253 ++viewIndex) { 254 Value view = *(viewIteratorBegin + viewIndex); 255 auto viewType = view.getType().cast<MemRefType>(); 256 unsigned rank = viewType.getRank(); 257 auto mapAttr = linalgOp.indexing_maps()[viewIndex]; 258 auto map = mapAttr.cast<AffineMapAttr>().getValue(); 259 // If the view is not tiled, we can use it as is. 260 if (!isTiled(map, tileSizes)) { 261 res.push_back(view); 262 continue; 263 } 264 265 // Construct a new subview for the tile. 266 SmallVector<Value, 4> offsets, sizes, strides; 267 offsets.reserve(rank); 268 sizes.reserve(rank); 269 strides.reserve(rank); 270 for (unsigned r = 0; r < rank; ++r) { 271 if (!isTiled(map.getSubMap({r}), tileSizes)) { 272 offsets.push_back(folded_std_constant_index(folder, 0)); 273 sizes.push_back(std_dim(view, r)); 274 strides.push_back(folded_std_constant_index(folder, 1)); 275 continue; 276 } 277 278 // Tiling creates a new slice at the proper index, the slice step is 1 279 // (i.e. the slice view does not subsample, stepping occurs in the loop). 280 auto m = map.getSubMap({r}); 281 auto offset = applyMapToValues(b, loc, m, lbs, folder).front(); 282 offsets.push_back(offset); 283 auto size = applyMapToValues(b, loc, m, subViewSizes, folder).front(); 284 285 // The size of the subview should be trimmed to avoid out-of-bounds 286 // accesses, unless we statically know the subview size divides the view 287 // size evenly. 288 int64_t viewSize = viewType.getDimSize(r); 289 auto sizeCst = dyn_cast_or_null<ConstantIndexOp>(size.getDefiningOp()); 290 if (ShapedType::isDynamic(viewSize) || !sizeCst || 291 (viewSize % sizeCst.getValue()) != 0) { 292 // Compute min(size, dim - offset) to avoid out-of-bounds accesses. 293 auto minMap = AffineMap::get( 294 /*dimCount=*/3, /*symbolCount=*/0, 295 {getAffineDimExpr(/*position=*/0, b.getContext()), 296 getAffineDimExpr(/*position=*/1, b.getContext()) - 297 getAffineDimExpr(/*position=*/2, b.getContext())}, 298 b.getContext()); 299 auto d = folded_std_dim(folder, view, r); 300 size = folded_affine_min(folder, b.getIndexType(), minMap, 301 ValueRange{size, d, offset}); 302 } 303 304 sizes.push_back(size); 305 strides.push_back(folded_std_constant_index(folder, 1)); 306 } 307 308 res.push_back(b.create<SubViewOp>(loc, view, offsets, sizes, strides)); 309 } 310 311 // Traverse the mins/maxes and erase those that don't have uses left. 312 // This is a special type of folding that we only apply when `folder` is 313 // defined. 314 if (folder) 315 for (auto v : llvm::concat<Value>(lbs, subViewSizes)) 316 if (v.use_empty()) 317 v.getDefiningOp()->erase(); 318 319 return res; 320 } 321 322 template <typename LoopTy> 323 Optional<TiledLinalgOp> static tileLinalgOpImpl(OpBuilder &b, LinalgOp op, 324 ArrayRef<Value> tileSizes, 325 ArrayRef<unsigned> permutation, 326 OperationFolder *folder) { 327 assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics"); 328 // 1. Enforce the convention that "tiling by zero" skips tiling a particular 329 // dimension. This convention is significantly simpler to handle instead of 330 // adjusting affine maps to account for missing dimensions. 331 assert(op.getNumParallelLoops() + op.getNumReductionLoops() + 332 op.getNumWindowLoops() == 333 tileSizes.size() && 334 "expected matching number of tile sizes and loops"); 335 336 if (auto convOp = dyn_cast<linalg::ConvOp>(op.getOperation())) { 337 // For conv op only support tiling along batch dimension (which is the first 338 // loop). 339 if (convOp.padding() && 340 !llvm::all_of(tileSizes.drop_front(), 341 [](Value val) { return isZero(val); })) 342 return llvm::None; 343 } 344 345 // If permutation is empty, use the identity. Build the permutation map 346 // otherwise. 347 auto invPermutationMap = AffineMap::getMultiDimIdentityMap( 348 tileSizes.size(), ScopedContext::getContext()); 349 if (!permutation.empty()) 350 invPermutationMap = inversePermutation( 351 AffineMap::getPermutationMap(permutation, ScopedContext::getContext())); 352 if (!invPermutationMap) 353 return llvm::None; 354 355 OpBuilder::InsertionGuard g(b); 356 b.setInsertionPoint(op); 357 ScopedContext scope(b, op.getLoc()); 358 // 2. Build the tiled loop ranges. 359 auto viewSizes = getViewSizes(b, op); 360 // The flattened loopToOperandRangesMaps is expected to be an invertible 361 // permutation map (asserted in the inverse calculation). 362 auto mapsRange = op.indexing_maps().getAsRange<AffineMapAttr>(); 363 auto maps = llvm::to_vector<8>( 364 llvm::map_range(mapsRange, [](AffineMapAttr a) { return a.getValue(); })); 365 auto viewSizesToLoopsMap = inversePermutation(concatAffineMaps(maps)); 366 if (!viewSizesToLoopsMap) 367 return llvm::None; 368 369 SmallVector<SubViewOp::Range, 4> loopRanges; 370 LoopIndexToRangeIndexMap loopIndexToRangeIndex; 371 std::tie(loopRanges, loopIndexToRangeIndex) = 372 makeTiledLoopRanges(b, scope.getLocation(), viewSizesToLoopsMap, 373 viewSizes, tileSizes, folder); 374 if (!permutation.empty()) 375 applyPermutationToVector(loopRanges, permutation); 376 377 // 3. Create the tiled loops. 378 LinalgOp res = op; 379 SmallVector<Value, 4> ivs(loopRanges.size()); 380 // Convert SubViewOp::Range to linalg_range. 381 SmallVector<Value, 4> linalgRanges; 382 for (auto &range : loopRanges) { 383 linalgRanges.push_back( 384 linalg_range(range.offset, range.size, range.stride)); 385 } 386 GenericLoopNestRangeBuilder<LoopTy>(ivs, linalgRanges)([&] { 387 auto b = ScopedContext::getBuilder(); 388 auto loc = ScopedContext::getLocation(); 389 SmallVector<Value, 4> ivValues(ivs.begin(), ivs.end()); 390 391 // If we have to apply a permutation to the tiled loop nest, we have to 392 // reorder the induction variables This permutation is the right one 393 // assuming that loopRanges have previously been permuted by 394 // (i,j,k)->(k,i,j) So this permutation should be the inversePermutation of 395 // that one: (d0,d1,d2)->(d2,d0,d1) 396 if (!permutation.empty()) 397 ivValues = applyMapToValues(b, loc, invPermutationMap, ivValues, folder); 398 399 auto views = 400 makeTiledViews(b, loc, op, ivValues, tileSizes, viewSizes, folder); 401 auto operands = getAssumedNonViewOperands(op); 402 views.append(operands.begin(), operands.end()); 403 res = op.clone(b, loc, views); 404 }); 405 406 // 4. Transforms index arguments of `linalg.generic` w.r.t. to the tiling. 407 transformIndexedGenericOpIndices(b, res, ivs, loopIndexToRangeIndex); 408 409 // 5. Gather the newly created loops and return them with the new op. 410 SmallVector<Operation *, 8> loops; 411 loops.reserve(ivs.size()); 412 for (auto iv : ivs) { 413 loops.push_back(iv.cast<BlockArgument>().getOwner()->getParentOp()); 414 assert(loops.back() && "no owner found for induction variable!"); 415 } 416 417 return TiledLinalgOp{res, loops}; 418 } 419 420 template <typename LoopTy> 421 static Optional<TiledLinalgOp> 422 tileLinalgOpImpl(OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes, 423 ArrayRef<unsigned> permutation, OperationFolder *folder) { 424 assert(op.hasBufferSemantics() && "expected linalg op with buffer semantics"); 425 if (tileSizes.empty()) 426 return llvm::None; 427 428 // The following uses the convention that "tiling by zero" skips tiling a 429 // particular dimension. This convention is significantly simpler to handle 430 // instead of adjusting affine maps to account for missing dimensions. 431 auto nLoops = op.getNumParallelLoops() + op.getNumReductionLoops() + 432 op.getNumWindowLoops(); 433 tileSizes = tileSizes.take_front(nLoops); 434 // If only 0 tilings are left, then return. 435 if (llvm::all_of(tileSizes, [](int64_t v) { return v == 0; })) 436 return llvm::None; 437 438 if (auto convOp = dyn_cast<linalg::ConvOp>(op.getOperation())) { 439 // For conv op only support tiling along batch dimension (which is the first 440 // loop). 441 if (convOp.padding() && !llvm::all_of(tileSizes.drop_front(), 442 [](int64_t val) { return val == 0; })) 443 return llvm::None; 444 } 445 446 // Create a builder for tile size constants. 447 OpBuilder::InsertionGuard g(b); 448 b.setInsertionPoint(op); 449 ScopedContext scope(b, op.getLoc()); 450 451 // Materialize concrete tile size values to pass the generic tiling function. 452 SmallVector<Value, 8> tileSizeValues; 453 tileSizeValues.reserve(tileSizes.size()); 454 for (auto ts : tileSizes) 455 tileSizeValues.push_back(folded_std_constant_index(folder, ts)); 456 // Pad tile sizes with zero values to enforce our convention. 457 if (tileSizeValues.size() < nLoops) { 458 for (unsigned i = tileSizeValues.size(); i < nLoops; ++i) 459 tileSizeValues.push_back(folded_std_constant_index(folder, 0)); 460 } 461 462 return tileLinalgOpImpl<LoopTy>(b, op, tileSizeValues, permutation, folder); 463 } 464 465 Optional<TiledLinalgOp> 466 mlir::linalg::tileLinalgOp(OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes, 467 ArrayRef<unsigned> permutation, 468 OperationFolder *folder) { 469 return tileLinalgOpImpl<loop::ForOp>(b, op, tileSizes, permutation, folder); 470 } 471 472 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOpToParallelLoops( 473 OpBuilder &b, LinalgOp op, ArrayRef<Value> tileSizes, 474 ArrayRef<unsigned> permutation, OperationFolder *folder) { 475 return tileLinalgOpImpl<loop::ParallelOp>(b, op, tileSizes, permutation, 476 folder); 477 } 478 479 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOp( 480 OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes, 481 ArrayRef<unsigned> permutation, OperationFolder *folder) { 482 return tileLinalgOpImpl<loop::ForOp>(b, op, tileSizes, permutation, folder); 483 } 484 485 Optional<TiledLinalgOp> mlir::linalg::tileLinalgOpToParallelLoops( 486 OpBuilder &b, LinalgOp op, ArrayRef<int64_t> tileSizes, 487 ArrayRef<unsigned> permutation, OperationFolder *folder) { 488 return tileLinalgOpImpl<loop::ParallelOp>(b, op, tileSizes, permutation, 489 folder); 490 } 491 492 template <typename LoopTy> 493 static void tileLinalgOps(FuncOp f, ArrayRef<int64_t> tileSizes) { 494 OpBuilder b(f); 495 OperationFolder folder(f.getContext()); 496 f.walk([tileSizes, &b, &folder](LinalgOp op) { 497 if (!op.hasBufferSemantics()) 498 return; 499 auto opLoopsPair = 500 tileLinalgOpImpl<LoopTy>(b, op, tileSizes, /*permutation=*/{}, &folder); 501 // If tiling occurred successfully, erase old op. 502 if (opLoopsPair) 503 op.erase(); 504 }); 505 f.walk([](LinalgOp op) { 506 if (isOpTriviallyDead(op)) 507 op.erase(); 508 }); 509 } 510 511 namespace { 512 struct LinalgTilingPass : public LinalgTilingBase<LinalgTilingPass> { 513 LinalgTilingPass() = default; 514 LinalgTilingPass(ArrayRef<int64_t> sizes) { tileSizes = sizes; } 515 516 void runOnFunction() override { 517 tileLinalgOps<loop::ForOp>(getFunction(), tileSizes); 518 } 519 }; 520 521 struct LinalgTilingToParallelLoopsPass 522 : public LinalgTilingToParallelLoopsBase<LinalgTilingToParallelLoopsPass> { 523 LinalgTilingToParallelLoopsPass() = default; 524 LinalgTilingToParallelLoopsPass(ArrayRef<int64_t> sizes) { 525 tileSizes = sizes; 526 } 527 528 void runOnFunction() override { 529 tileLinalgOps<loop::ParallelOp>(getFunction(), tileSizes); 530 } 531 }; 532 533 } // namespace 534 535 std::unique_ptr<OperationPass<FuncOp>> 536 mlir::createLinalgTilingPass(ArrayRef<int64_t> tileSizes) { 537 return std::make_unique<LinalgTilingPass>(tileSizes); 538 } 539 540 std::unique_ptr<OperationPass<FuncOp>> 541 mlir::createLinalgTilingToParallelLoopsPass(ArrayRef<int64_t> tileSizes) { 542 return std::make_unique<LinalgTilingToParallelLoopsPass>(tileSizes); 543 } 544