MLIR  16.0.0git
Macros | Functions
Tiling.cpp File Reference
#include <utility>
#include "PassDetail.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Arithmetic/Utils/Utils.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Passes.h"
#include "mlir/Dialect/Linalg/Transforms/Transforms.h"
#include "mlir/Dialect/Linalg/Utils/Utils.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/SCF/Transforms/Transforms.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/IR/AffineExpr.h"
#include "mlir/IR/AffineMap.h"
#include "mlir/Transforms/FoldUtils.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/Support/CommandLine.h"
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
+ Include dependency graph for Tiling.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "linalg-tiling"
 
#define GET_OP_LIST
 
#define GET_OP_LIST
 

Functions

static bool isZero (OpFoldResult v)
 
static void emitIsPositiveIndexAssertion (ImplicitLocOpBuilder &b, OpFoldResult value)
 Asserts that the given index-typed value is strictly positive. More...
 
static void createMatchingParallelSubsetInsertOp (OpBuilder &b, Location loc, tensor::ExtractSliceOp subsetExtractOp, Value source, Value dest)
 Given a subsetExtractOp, a source and a dest, create a new ParallelInsertSlice op of source into dest at the same subset location as subsetExtractOp. More...
 
static bool canOmitTileOffsetInBoundsCheck (OpFoldResult tileSize, OpFoldResult numThreads, OpFoldResult iterationSize)
 Returns true if the maximum tile offset tileSize * numThreads-1 is less than iterationSize. More...
 
static OpFoldResult buildMax (OpBuilder &b, Location loc, ArrayRef< OpFoldResult > vals)
 Build an affine_max of all the vals. More...
 
static OpFoldResult buildMin (OpBuilder &b, Location loc, ArrayRef< OpFoldResult > vals)
 Build an affine_min of all the vals. More...
 
static FailureOr< ForeachThreadTilingResulttileToForeachThreadOpImpl (RewriterBase &b, TilingInterface op, ArrayRef< OpFoldResult > numThreads, Optional< ArrayRef< OpFoldResult >> nominalTileSizes, ArrayRef< int64_t > threadDimMapping, bool omitTileOffsetBoundsCheck)
 Rewrite a TilingInterface op to a tiled scf.foreach_thread. More...
 
static Value insertSliceIntoTensor (OpBuilder &b, Location loc, tensor::ExtractSliceOp sliceOp, Value source, Value dest)
 
template<typename LoopTy >
static FailureOr< TiledLinalgOptileLinalgOpImpl (RewriterBase &b, LinalgOp op, ArrayRef< OpFoldResult > tileSizes, const LinalgTilingOptions &options)
 
template<typename LoopTy >
static FailureOr< TiledLinalgOptileLinalgOpImpl (RewriterBase &b, LinalgOp op, const LinalgTilingOptions &options)
 
static LogicalResult tilePadOp (RewriterBase &builder, tensor::PadOp op, tensor::PadOp &newPadOp, LoopNest &loopNest, const LinalgTilingOptions &options)
 Generate a loop nest around a given tensor::PadOp (for tiling). More...
 
static void insertTilingPatterns (RewritePatternSet &patterns, const LinalgTilingOptions &options)
 Populate the given list with patterns that apply Linalg tiling. More...
 
static void applyExtractSliceOfPadTensorSwapPattern (func::FuncOp funcOp)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "linalg-tiling"

Definition at line 38 of file Tiling.cpp.

◆ GET_OP_LIST [1/2]

#define GET_OP_LIST

◆ GET_OP_LIST [2/2]

#define GET_OP_LIST

Function Documentation

◆ applyExtractSliceOfPadTensorSwapPattern()

static void applyExtractSliceOfPadTensorSwapPattern ( func::FuncOp  funcOp)
static

◆ buildMax()

static OpFoldResult buildMax ( OpBuilder b,
Location  loc,
ArrayRef< OpFoldResult vals 
)
static

Build an affine_max of all the vals.

Definition at line 206 of file Tiling.cpp.

References mlir::Location::getContext(), mlir::AffineMap::getMultiDimIdentityMap(), and mlir::makeComposedFoldedAffineMax().

Referenced by tileToForeachThreadOpImpl().

◆ buildMin()

static OpFoldResult buildMin ( OpBuilder b,
Location  loc,
ArrayRef< OpFoldResult vals 
)
static

Build an affine_min of all the vals.

Definition at line 214 of file Tiling.cpp.

References mlir::Location::getContext(), mlir::AffineMap::getMultiDimIdentityMap(), and mlir::makeComposedFoldedAffineMin().

Referenced by tileToForeachThreadOpImpl().

◆ canOmitTileOffsetInBoundsCheck()

static bool canOmitTileOffsetInBoundsCheck ( OpFoldResult  tileSize,
OpFoldResult  numThreads,
OpFoldResult  iterationSize 
)
static

Returns true if the maximum tile offset tileSize * numThreads-1 is less than iterationSize.

Definition at line 194 of file Tiling.cpp.

References mlir::getConstantIntValue().

Referenced by tileToForeachThreadOpImpl().

◆ createMatchingParallelSubsetInsertOp()

static void createMatchingParallelSubsetInsertOp ( OpBuilder b,
Location  loc,
tensor::ExtractSliceOp  subsetExtractOp,
Value  source,
Value  dest 
)
static

Given a subsetExtractOp, a source and a dest, create a new ParallelInsertSlice op of source into dest at the same subset location as subsetExtractOp.

Definition at line 184 of file Tiling.cpp.

References mlir::OpBuilder::create().

Referenced by tileToForeachThreadOpImpl().

◆ emitIsPositiveIndexAssertion()

static void emitIsPositiveIndexAssertion ( ImplicitLocOpBuilder b,
OpFoldResult  value 
)
static

Asserts that the given index-typed value is strictly positive.

If the value is an attribute, asserts at compile time, otherwise emits an assertion checked at runtime.

Definition at line 97 of file Tiling.cpp.

References mlir::ImplicitLocOpBuilder::create(), and mlir::Builder::getStringAttr().

Referenced by mlir::linalg::computeMultiTileSizes().

◆ insertSliceIntoTensor()

static Value insertSliceIntoTensor ( OpBuilder b,
Location  loc,
tensor::ExtractSliceOp  sliceOp,
Value  source,
Value  dest 
)
static

Definition at line 386 of file Tiling.cpp.

References mlir::OpBuilder::create().

Referenced by tilePadOp().

◆ insertTilingPatterns()

static void insertTilingPatterns ( RewritePatternSet patterns,
const LinalgTilingOptions options 
)
static

Populate the given list with patterns that apply Linalg tiling.

Definition at line 702 of file Tiling.cpp.

References mlir::RewritePatternSet::add(), mlir::RewritePatternSet::getContext(), and options.

Referenced by applyExtractSliceOfPadTensorSwapPattern().

◆ isZero()

static bool isZero ( OpFoldResult  v)
static

◆ tileLinalgOpImpl() [1/2]

template<typename LoopTy >
static FailureOr<TiledLinalgOp> tileLinalgOpImpl ( RewriterBase b,
LinalgOp  op,
ArrayRef< OpFoldResult tileSizes,
const LinalgTilingOptions options 
)
static

◆ tileLinalgOpImpl() [2/2]

template<typename LoopTy >
static FailureOr<TiledLinalgOp> tileLinalgOpImpl ( RewriterBase b,
LinalgOp  op,
const LinalgTilingOptions options 
)
static

◆ tilePadOp()

static LogicalResult tilePadOp ( RewriterBase builder,
tensor::PadOp  op,
tensor::PadOp &  newPadOp,
LoopNest loopNest,
const LinalgTilingOptions options 
)
static

◆ tileToForeachThreadOpImpl()

static FailureOr<ForeachThreadTilingResult> tileToForeachThreadOpImpl ( RewriterBase b,
TilingInterface  op,
ArrayRef< OpFoldResult numThreads,
Optional< ArrayRef< OpFoldResult >>  nominalTileSizes,
ArrayRef< int64_t >  threadDimMapping,
bool  omitTileOffsetBoundsCheck 
)
static

Rewrite a TilingInterface op to a tiled scf.foreach_thread.

The tiling is specified by the number of tiles/threads numThreads and the optional nominal tile size nominalTileSizes. If nominalTilSizes is not specified, then it is derived from numThreads as ceilDiv(dimSize[i], numThreads[i]). If non-empty, the threadDimMapping is added as an attribute to the resulting scf.foreach_thread. A zero tile sizes indicate that the dimension is not tiled, and can be thought of as tiling by the full size of data. It is the user's responsibility to ensure that numThreads is a valid tiling specification (i.e. that only tiles parallel dimensions, e.g. in the Linalg case). If omitTileOffsetBoundsCheck is true, then the function will assume that tileSize[i] * (numThread[i] -1) <= dimSize[i] holds.

Definition at line 233 of file Tiling.cpp.

References mlir::bindDims(), mlir::bindSymbols(), buildMax(), buildMin(), canOmitTileOffsetInBoundsCheck(), mlir::AffineExpr::ceilDiv(), mlir::OpBuilder::create(), createMatchingParallelSubsetInsertOp(), mlir::Builder::getContext(), mlir::Builder::getIndexAttr(), mlir::isConstantIntValue(), isZero(), mlir::makeComposedFoldedAffineApply(), mlir::linalg::materializeOpFoldResult(), and mlir::OpBuilder::setInsertionPointToStart().

Referenced by mlir::linalg::tileToForeachThreadOp(), and mlir::linalg::tileToForeachThreadOpUsingTileSizes().