MLIR  17.0.0git
Namespaces | Macros | Functions
Tiling.cpp File Reference
#include "mlir/Dialect/Linalg/Passes.h"
#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/Affine/LoopUtils.h"
#include "mlir/Dialect/Arith/Utils/Utils.h"
#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Linalg/Transforms/Transforms.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/IR/BuiltinOps.h"
#include "mlir/IR/ValueRange.h"
#include "mlir/Transforms/FoldUtils.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/CommandLine.h"
#include <utility>
#include "mlir/Dialect/Linalg/Passes.h.inc"
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"

Go to the source code of this file.

Namespaces

 mlir
 This header declares functions that assist transformations in the MemRef dialect.
 

Macros

#define GEN_PASS_DEF_LINALGTILINGPASS
 
#define DEBUG_TYPE   "linalg-tiling"
 
#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 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 void calculateTileOffsetsAndSizes (RewriterBase &b, Location loc, scf::ForallOp forallOp, ArrayRef< OpFoldResult > numThreads, SmallVector< Range > loopRanges, bool omitTileOffsetBoundsCheck, std::optional< ArrayRef< OpFoldResult >> nominalTileSizes, SmallVector< OpFoldResult > &tiledOffsets, SmallVector< OpFoldResult > &tiledSizes)
 Fill out the tiledOffsets and tiledSizes to be used to tile to a given number of threads. More...
 
static FailureOr< ForallTilingResulttileToForallOpImpl (RewriterBase &b, TilingInterface op, ArrayRef< OpFoldResult > numThreads, std::optional< ArrayRef< OpFoldResult >> nominalTileSizes, std::optional< ArrayAttr > mapping, bool omitTileOffsetBoundsCheck)
 Rewrite a TilingInterface op to a tiled scf.forall. More...
 
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)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "linalg-tiling"

Definition at line 46 of file Tiling.cpp.

◆ GEN_PASS_DEF_LINALGTILINGPASS

#define GEN_PASS_DEF_LINALGTILINGPASS

Definition at line 37 of file Tiling.cpp.

◆ GET_OP_LIST

#define GET_OP_LIST

Function Documentation

◆ buildMax()

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

Build an affine_max of all the vals.

Definition at line 230 of file Tiling.cpp.

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

Referenced by calculateTileOffsetsAndSizes().

◆ buildMin()

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

Build an affine_min of all the vals.

Definition at line 238 of file Tiling.cpp.

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

Referenced by calculateTileOffsetsAndSizes().

◆ calculateTileOffsetsAndSizes()

static void calculateTileOffsetsAndSizes ( RewriterBase b,
Location  loc,
scf::ForallOp  forallOp,
ArrayRef< OpFoldResult numThreads,
SmallVector< Range loopRanges,
bool  omitTileOffsetBoundsCheck,
std::optional< ArrayRef< OpFoldResult >>  nominalTileSizes,
SmallVector< OpFoldResult > &  tiledOffsets,
SmallVector< OpFoldResult > &  tiledSizes 
)
static

◆ 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 218 of file Tiling.cpp.

References mlir::getConstantIntValue().

Referenced by calculateTileOffsetsAndSizes().

◆ 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 105 of file Tiling.cpp.

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

◆ 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

Definition at line 460 of file Tiling.cpp.

◆ tileLinalgOpImpl() [2/2]

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

Definition at line 808 of file Tiling.cpp.

◆ tileToForallOpImpl()

static FailureOr<ForallTilingResult> tileToForallOpImpl ( RewriterBase b,
TilingInterface  op,
ArrayRef< OpFoldResult numThreads,
std::optional< ArrayRef< OpFoldResult >>  nominalTileSizes,
std::optional< ArrayAttr >  mapping,
bool  omitTileOffsetBoundsCheck 
)
static

Rewrite a TilingInterface op to a tiled scf.forall.

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 mapping is added as an attribute to the resulting scf.forall. 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 330 of file Tiling.cpp.