diff options
author | Nicolas Vasilache <nicolas.vasilache@gmail.com> | 2023-05-12 09:12:28 -0700 |
---|---|---|
committer | Nicolas Vasilache <nicolas.vasilache@gmail.com> | 2023-05-12 09:27:31 -0700 |
commit | 0047b1779eca0fc97e75eac4c3f99d161b1c28da (patch) | |
tree | 79a3ba930c31a2ba82a6755291de5b00cb25d86f /mlir/lib | |
parent | 26b5b064f066519096fb556f99b6e2dc163b9283 (diff) | |
download | llvm-0047b1779eca0fc97e75eac4c3f99d161b1c28da.tar.gz |
[mlir][Linalg] NFC - Retire dead tilePadOp
Diffstat (limited to 'mlir/lib')
-rw-r--r-- | mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp index 57798fc78ea4..1293d03f15bf 100644 --- a/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp @@ -804,18 +804,6 @@ FailureOr<linalg::ForallReductionTilingResult> linalg::tileReductionUsingForall( return results; } -// Insert a tile `source` into the destination tensor `dest`. The position at -// which the tile is inserted (as well as size of tile) is taken from a given -// ExtractSliceOp `sliceOp`. -static Value insertSliceIntoTensor(OpBuilder &b, Location loc, - tensor::ExtractSliceOp sliceOp, Value source, - Value dest) { - return b.create<tensor::InsertSliceOp>( - loc, sliceOp.getSource().getType(), source, dest, sliceOp.getOffsets(), - sliceOp.getSizes(), sliceOp.getStrides(), sliceOp.getStaticOffsets(), - sliceOp.getStaticSizes(), sliceOp.getStaticStrides()); -} - template <typename LoopTy> FailureOr<TiledLinalgOp> static tileLinalgOpImpl( RewriterBase &b, LinalgOp op, const LinalgTilingOptions &options) { @@ -851,93 +839,6 @@ mlir::linalg::tileLinalgOp(RewriterBase &b, LinalgOp op, return failure(); } -/// Generate a loop nest around a given tensor::PadOp (for tiling). `newPadOp` -/// and `loopNest` are output parameters that return the new (tiled) -/// tensor::PadOp and the loop nest. -static LogicalResult tilePadOp(RewriterBase &builder, tensor::PadOp op, - tensor::PadOp &newPadOp, LoopNest &loopNest, - const LinalgTilingOptions &options) { - Location loc = op.getLoc(); - OpBuilder::InsertionGuard g(builder); - builder.setInsertionPoint(op); - - // Clone tensor::PadOp so that the existing op can be replaced more easily. - newPadOp = cast<tensor::PadOp>(builder.clone(*op.getOperation())); - // Get rank and tile sizes. - int64_t rank = op.getResultType().getRank(); - SmallVector<OpFoldResult> tileSizes = - getAsOpFoldResult(options.tileSizeComputationFunction(builder, op)); - // Normalize untiled padding dimensions to 0. - tileSizes.append(rank - tileSizes.size(), builder.getIndexAttr(0)); - // Compute lower and upper bounds of the loop nest. - TilingInterface tilingInterface = - dyn_cast<TilingInterface>(op.getOperation()); - SmallVector<Range> ranges = tilingInterface.getIterationDomain(builder); - SmallVector<Value> lbs, dims, steps; - SmallVector<OpFoldResult> allDims; - for (int64_t i = 0; i < rank; ++i) { - allDims.push_back(ranges[i].size); - if (!isZero(tileSizes[i])) { - lbs.push_back( - getValueOrCreateConstantIndexOp(builder, loc, ranges[i].offset)); - dims.push_back( - getValueOrCreateConstantIndexOp(builder, loc, ranges[i].size)); - steps.push_back( - getValueOrCreateConstantIndexOp(builder, loc, tileSizes[i])); - } - } - SmallVector<Value> destinationTensors; - if (failed(tensor::getOrCreateDestinations(builder, loc, tilingInterface, - destinationTensors))) - return failure(); - - loopNest = mlir::scf::buildLoopNest( - builder, loc, lbs, /*ubs=*/dims, steps, ValueRange(destinationTensors), - [&](OpBuilder &b, Location loc, ValueRange localIvs, - ValueRange iterArgs) -> scf::ValueVector { - // Compute offsets and sizes of ExtractSliceOp. - SmallVector<Value> localIVVector = llvm::to_vector(localIvs); - SmallVector<OpFoldResult> offsets = computeTileOffsets( - b, loc, getAsOpFoldResult(localIVVector), tileSizes); - SmallVector<OpFoldResult> sizes = - computeTileSizes(b, loc, tileSizes, allDims); - // Create ExtractSliceOp: Extract a tile from the tensor::PadOp. - // Note: The tensor::PadOp is located outside of the loop nest. It is - // later moved inside by ExtractSliceOfPadTensorSwapPattern. - auto map = AffineMap::getMultiDimIdentityMap(rank, b.getContext()); - Value tiledOutput = makeTiledShape( - b, loc, newPadOp->getResult(0), tileSizes, map, offsets, allDims, - sizes, /*omitPartialTileCheck=*/false); - auto sliceOp = tiledOutput.getDefiningOp<tensor::ExtractSliceOp>(); - assert(sliceOp && "expected ExtractSliceOp"); - // Insert the tile into the output tensor. - Value yieldValue = - insertSliceIntoTensor(b, loc, sliceOp, sliceOp, iterArgs[0]); - return scf::ValueVector({yieldValue}); - }); - return success(); -} - -namespace { -struct PadOpTilingPattern : public OpRewritePattern<tensor::PadOp> { - PadOpTilingPattern(MLIRContext *ctx, LinalgTilingOptions opt) - : OpRewritePattern<tensor::PadOp>(ctx), options(std::move(opt)) {} - - LogicalResult matchAndRewrite(tensor::PadOp op, - PatternRewriter &rewriter) const override { - tensor::PadOp newPadOp; - LoopNest loopNest; - if (failed(tilePadOp(rewriter, op, newPadOp, loopNest, options))) - return failure(); - // Replace all uses of the original tensor::PadOp. - rewriter.replaceOp(op, loopNest.results.front()); - return success(); - } - - LinalgTilingOptions options; -}; -} // namespace - namespace { /// Helper classes for type list expansion. template <typename... OpTypes> @@ -993,9 +894,3 @@ void mlir::linalg::populateLinalgTilingCanonicalizationPatterns( #include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc" >::insert(patterns); } - -void mlir::linalg::populatePadTensorTilingPatterns( - RewritePatternSet &patterns, const LinalgTilingOptions &options) { - auto *ctx = patterns.getContext(); - patterns.add<PadOpTilingPattern>(ctx, options); -} |