MLIR 24.0.0git
PadTilingInterface.cpp File Reference

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "pad-tiling-interface"
#define DBGS()
#define DBGSNL()

Functions

static SmallVector< OpFoldResult > getFullRankPaddingSizes (Builder &b, ArrayRef< OpFoldResult > indexingSizes, const PadTilingInterfaceOptions &options)
 Form a "full-rank" padding specification so that the application is easy.
static int64_t extractConstantMultiplier (AffineExpr expr)
 Extracts the constant multiplier from an affine expression of the form d * c or c * d, where d is an AffineDimExpr and c is an AffineConstantExpr.
static Value padOperand (OpBuilder &builder, TilingInterface opToPad, TypedValue< RankedTensorType > v, ArrayRef< OpFoldResult > paddedShape, Attribute paddingValueAttr)
 Pad a single operand to paddedShape using paddingValueAttr as padding Value.
static bool isReducedOperand (linalg::LinalgOp linalgOp, OpOperand *operand, ArrayRef< utils::IteratorType > iterTypes)
 Returns true if operand is indexed along at least one reduction dimension of linalgOp
static FailureOr< SmallVector< Attribute > > inferContractionPaddingValues (OpBuilder &builder, linalg::LinalgOp linalgOp, ArrayRef< utils::IteratorType > iterTypes, ArrayRef< Attribute > defaultPadVals)
 On success, returns a vector with pad values for every operand of linalgOp.
static FailureOr< SmallVector< Attribute > > inferPaddingValues (OpBuilder &builder, TilingInterface toPad)
 Infers a semantics-preserving padding value for every operand of toPad (indexed by operand number).

Macro Definition Documentation

◆ DBGS

#define DBGS ( )
Value:
(llvm::dbgs() << "[" DEBUG_TYPE << "]: ")
#define DEBUG_TYPE

Definition at line 35 of file PadTilingInterface.cpp.

Referenced by mlir::linalg::computePaddedShape(), getFullRankPaddingSizes(), padOperand(), and mlir::linalg::rewriteAsPaddedOp().

◆ DBGSNL

#define DBGSNL ( )
Value:
(llvm::dbgs() << "\n")

Definition at line 36 of file PadTilingInterface.cpp.

◆ DEBUG_TYPE

#define DEBUG_TYPE   "pad-tiling-interface"

Definition at line 29 of file PadTilingInterface.cpp.

Function Documentation

◆ extractConstantMultiplier()

int64_t extractConstantMultiplier ( AffineExpr expr)
static

Extracts the constant multiplier from an affine expression of the form d * c or c * d, where d is an AffineDimExpr and c is an AffineConstantExpr.

Returns 1 if the expression is not a simple multiplication of a dimension and a constant.

Definition at line 66 of file PadTilingInterface.cpp.

References mlir::Mul.

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

◆ getFullRankPaddingSizes()

SmallVector< OpFoldResult > getFullRankPaddingSizes ( Builder & b,
ArrayRef< OpFoldResult > indexingSizes,
const PadTilingInterfaceOptions & options )
static

Form a "full-rank" padding specification so that the application is easy.

Definition at line 40 of file PadTilingInterface.cpp.

References b, DBGS, mlir::isZeroInteger(), and options.

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

◆ inferContractionPaddingValues()

FailureOr< SmallVector< Attribute > > inferContractionPaddingValues ( OpBuilder & builder,
linalg::LinalgOp linalgOp,
ArrayRef< utils::IteratorType > iterTypes,
ArrayRef< Attribute > defaultPadVals )
static

On success, returns a vector with pad values for every operand of linalgOp.

Fails if the body of linalgOp is not contraction-like, or if its elemwise/reduce pair admits no padding value.

Definition at line 287 of file PadTilingInterface.cpp.

References mlir::getElementTypeOrSelf(), mlir::Operation::getResult(), mlir::Value::getType(), mlir::Builder::getZeroAttr(), mlir::linalg::detail::isContractionBody(), mlir::Type::isInteger(), isReducedOperand(), and reduce().

Referenced by inferPaddingValues().

◆ inferPaddingValues()

FailureOr< SmallVector< Attribute > > inferPaddingValues ( OpBuilder & builder,
TilingInterface toPad )
static

Infers a semantics-preserving padding value for every operand of toPad (indexed by operand number).

Operands that are reduced are padded with the neutral element of their reduction combiner (e.g. -inf for maximumf, 1 for mulf); every other operand is padded with the zero value of its element type.

Inference is conservative: it returns failure when a semantics-preserving value cannot be determined (a non-LinalgOp reduction, or a reduction whose neutral element is unknown), letting callers set options.paddingValues explicitly instead.

Definition at line 348 of file PadTilingInterface.cpp.

References mlir::getElementTypeOrSelf(), mlir::arith::getNeutralElement(), mlir::Operation::getOperandTypes(), mlir::Builder::getZeroAttr(), inferContractionPaddingValues(), isReducedOperand(), and mlir::matchReduction().

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

◆ isReducedOperand()

bool isReducedOperand ( linalg::LinalgOp linalgOp,
OpOperand * operand,
ArrayRef< utils::IteratorType > iterTypes )
static

Returns true if operand is indexed along at least one reduction dimension of linalgOp

Definition at line 271 of file PadTilingInterface.cpp.

References mlir::detail::IROperandBase::getOwner(), and mlir::AffineMap::isFunctionOfDim().

Referenced by inferContractionPaddingValues(), and inferPaddingValues().

◆ padOperand()

Value padOperand ( OpBuilder & builder,
TilingInterface opToPad,
TypedValue< RankedTensorType > v,
ArrayRef< OpFoldResult > paddedShape,
Attribute paddingValueAttr )
static

Pad a single operand to paddedShape using paddingValueAttr as padding Value.

Definition at line 230 of file PadTilingInterface.cpp.

References DBGS, mlir::getConstantIntValue(), mlir::getElementTypeOrSelf(), mlir::ub::m_Poison(), mlir::linalg::makeComposedPadHighOp(), and mlir::matchPattern().

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