MLIR  19.0.0git
Classes | Typedefs | Functions
mlir::tensor Namespace Reference

Classes

class  ExtractSliceFromCollapseHelper
 This class assists with generating IR required to materialize an arbitrary-sized slice from the result of a CollapseShapeOp. More...
 

Typedefs

using ControlConstantExtractSliceFusionFn = std::function< bool(ExtractSliceOp)>
 Function to control the folding of constant and extract slice. More...
 

Functions

bool preservesStaticInformation (Type source, Type target)
 Returns true if target is a ranked tensor type that preserves static information available in the source ranked tensor type. More...
 
bool canFoldIntoConsumerOp (CastOp castOp)
 Determines whether tensor::CastOp casts to a more dynamic version of the source tensor. More...
 
bool canFoldIntoProducerOp (CastOp castOp)
 Determines whether the tensor::CastOp casts to a more static version of the source tensor. More...
 
LogicalResult foldTensorCast (Operation *op)
 Performs folding of any operand of op if it comes from a tensor::CastOp that can be folded. More...
 
OpFoldResult getMixedSize (OpBuilder &builder, Location loc, Value value, int64_t dim)
 Return the dimension of the given tensor value. More...
 
SmallVector< OpFoldResultgetMixedSizes (OpBuilder &builder, Location loc, Value value)
 Return the dimensions of the given tensor value. More...
 
Value createCanonicalRankReducingExtractSliceOp (OpBuilder &b, Location loc, Value tensor, RankedTensorType targetType)
 Create a rank-reducing ExtractSliceOp @[0 . More...
 
Value createCanonicalRankReducingInsertSliceOp (OpBuilder &b, Location loc, Value tensor, Value dest)
 Create a rank-reducing InsertSliceOp @[0 . More...
 
FailureOr< ValuegetOrCreateDestination (OpBuilder &b, Location loc, OpResult opResult)
 This is a helper function for DestinationStyleOpInterface. More...
 
LogicalResult getOrCreateDestinations (OpBuilder &b, Location loc, Operation *op, SmallVector< Value > &result)
 This is a helper function for DestinationStyleOpInterface. More...
 
bool isSameTypeWithoutEncoding (Type tp1, Type tp2)
 Tests if types are the same when ignoring encoding on ranked tensors. More...
 
void populateFoldConstantExtractSlicePatterns (RewritePatternSet &patterns, const ControlConstantExtractSliceFusionFn &controlFn=[](ExtractSliceOp op) { return false;})
 Patterns to fold the extract slice op with its constant operand. More...
 
void registerInferTypeOpInterfaceExternalModels (mlir::DialectRegistry &registry)
 Registers external models for Infer Type interfaces for tensor ops. More...
 
FailureOr< TilingResultbubbleUpPadSlice (OpBuilder &b, tensor::PadOp padOp, ArrayRef< OpFoldResult > offsets, ArrayRef< OpFoldResult > sizes, bool generateZeroSliceGuard=true)
 Bubbles up a slice of this pad by taking the slice first and then performing the padding. More...
 
void registerTilingInterfaceExternalModels (mlir::DialectRegistry &registry)
 Registers external models for Tiling interface for tensor ops. More...
 
void registerTilingInterfaceExternalModelsForPackUnPackOps (DialectRegistry &registry)
 Similar to the above registeration, but it is only for tensor.pack and tensor.unpack ops. More...
 
void registerValueBoundsOpInterfaceExternalModels (DialectRegistry &registry)
 
void registerTransformDialectExtension (DialectRegistry &registry)
 
void registerFindPayloadReplacementOpInterfaceExternalModels (DialectRegistry &registry)
 
void registerBufferizableOpInterfaceExternalModels (DialectRegistry &registry)
 
std::unique_ptr< PasscreateFoldTensorSubsetOpsPass ()
 Creates an instance of the tensor subset folding pass. More...
 
std::unique_ptr< PasscreateTensorBufferizePass ()
 Creates an instance of the tensor dialect bufferization pass. More...
 
void registerSubsetOpInterfaceExternalModels (DialectRegistry &registry)
 
FailureOr< TilingResultreplaceExtractSliceWithTiledProducer (OpBuilder &builder, tensor::ExtractSliceOp sliceOp, OpResult producerOp)
 Pattern to swap an tensor.extract_slice with its producer when the producer implements the TilingInterface. More...
 
void populateFoldTensorSubsetOpPatterns (RewritePatternSet &patterns)
 Appends patterns for folding tensor subset ops into consumer load/store ops into patterns. More...
 
void populateFoldTensorSubsetIntoVectorTransferPatterns (RewritePatternSet &patterns)
 Appends patterns for folding tensor subset ops into vector transfer ops. More...
 
void populateMergeConsecutiveInsertExtractSlicePatterns (RewritePatternSet &patterns)
 Collects patterns to merge consecutive tensor.insert_slice/extract_slice into one. More...
 
void populateDropRedundantInsertSliceRankExpansionPatterns (RewritePatternSet &patterns)
 Populates patterns with patterns that drop redundant tensor.insert_slice rank expansions. More...
 
void populateReassociativeReshapeFoldingPatterns (RewritePatternSet &patterns)
 Populates patterns with patterns that fold tensor.expand_shape and tensor.collapse_shape into other ops. More...
 
void populateFoldTensorEmptyPatterns (RewritePatternSet &patterns, bool foldSingleUseOnly=false)
 Populates patterns with patterns that fold tensor.empty with tensor. More...
 
void populateDecomposeTensorConcatPatterns (RewritePatternSet &patterns)
 Populates patterns with patterns that decompose tensor.concat into tensor.empty of a tensor of the concatenated size, followed by a chain of tensor.insert_slice operations on the inputs. More...
 
void populateSimplifyPackAndUnpackPatterns (RewritePatternSet &patterns)
 Populates patterns with patterns that simplify tensor.pack and tensor.unpack operations. More...
 
void populateFoldIntoPackAndUnpackPatterns (RewritePatternSet &patterns)
 Populates patterns with patterns that fold operations like tensor.pad and tensor.extract_slice into tensor.pack and tensor.unpack operations respectively. More...
 
void populateRewriteAsConstantPatterns (RewritePatternSet &patterns)
 Populates patterns with patterns that replace tensor ops (such as tensor.generate) with constants when possible. More...
 
FailureOr< ValuebuildIndependentOp (OpBuilder &b, tensor::PadOp padOp, ValueRange independencies)
 Build a new tensor::PadOp with low/high padding that is independent of all given independencies. More...
 
FailureOr< ValuebuildIndependentOp (OpBuilder &b, tensor::EmptyOp emptyOp, ValueRange independencies)
 Build a new tensor::EmptyOp who's dynamic sizes are independent of all given independencies. More...
 
FailureOr< Operation * > simplifyCollapseShapeWithRankReducingExtractSlice (tensor::CollapseShapeOp op, RewriterBase &rewriter)
 Tries to simplify a tensor.collapse_shape operation by inserting a single rank-reducing tensor.extract_slice operation. More...
 
PadOp createPadHighOp (RankedTensorType type, Value source, Value pad, bool nofold, Location loc, OpBuilder &builder)
 
SmallVector< ValuecreateDynamicDimValues (OpBuilder &b, Location loc, Value rankedTensor)
 
FailureOr< RankedTensorType > computeTransposedType (RankedTensorType rankedTensorType, ArrayRef< int64_t > transposeVector)
 Returns the transposed rankedTensorType if transposeVector is non-empty. More...
 
SmallVector< int64_t > getPackInverseDestPerm (tensor::PackOp packOp)
 
SmallVector< int64_t > getUnPackInverseSrcPerm (tensor::UnPackOp unpackOp)
 
SmallVector< int64_t > getUnPackInverseSrcPerm (tensor::UnPackOp, PackingMetadata &metadata)
 
bool isCastLikeInsertSliceOp (InsertSliceOp op)
 A tensor.insert_slice is a cast-like operation if it merely rank-extends the source tensor or inserts the source tensor into a destination tensor with the same shape. More...
 
bool isCastLikeExtractSliceOp (ExtractSliceOp op)
 A tensor.extract_slice is a cast-like operation if it merely rank-reduces unit dimensions of the source tensor or extracts the entire source tensor. More...
 

Typedef Documentation

◆ ControlConstantExtractSliceFusionFn

using mlir::tensor::ControlConstantExtractSliceFusionFn = typedef std::function<bool(ExtractSliceOp)>

Function to control the folding of constant and extract slice.

Definition at line 154 of file Tensor.h.

Function Documentation

◆ bubbleUpPadSlice()

FailureOr< TilingResult > mlir::tensor::bubbleUpPadSlice ( OpBuilder b,
tensor::PadOp  padOp,
ArrayRef< OpFoldResult offsets,
ArrayRef< OpFoldResult sizes,
bool  generateZeroSliceGuard = true 
)

Bubbles up a slice of this pad by taking the slice first and then performing the padding.

offsets and strides specifies each dimension's start offset and size for the slice. The slice has unit strides along all dimensions.

Specifically, this function converts:

%0 = tensor.pad %source low[...] high[...] { linalg.yield %cst }
%1 = <extract-slice> %0 offsets=[...], sizes[...]

into

%0 = tensor.extract_slice %source ...
%0 = tensor.pad %0 low[...] high[...] { linalg.yield %cst }

If generateZeroSliceGuard is true, the generated IR will contain logic to guard against the case that we might take a zero-sized slice from the original source. For such cases, we tensor.generate to generate the full tensor.

Definition at line 476 of file TensorTilingInterfaceImpl.cpp.

References mlir::bindDims(), mlir::OpBuilder::create(), mlir::dispatchIndexOpFoldResults(), mlir::failure(), mlir::AffineMap::get(), mlir::get(), mlir::Builder::getContext(), mlir::Builder::getIndexAttr(), getMixedSize(), mlir::AffineMap::getMultiDimIdentityMap(), mlir::getPrunedAttributeList(), mlir::Operation::getResult(), mlir::getValueOrCreateConstantIndexOp(), mlir::isConstantIntValue(), mlir::affine::makeComposedFoldedAffineApply(), mlir::affine::makeComposedFoldedAffineMax(), mlir::affine::makeComposedFoldedAffineMin(), max(), and min().

Referenced by mlir::linalg::ExtractSliceOfPadTensorSwapPattern::matchAndRewrite().

◆ buildIndependentOp() [1/2]

FailureOr< Value > mlir::tensor::buildIndependentOp ( OpBuilder b,
tensor::EmptyOp  emptyOp,
ValueRange  independencies 
)

Build a new tensor::EmptyOp who's dynamic sizes are independent of all given independencies.

If the op is already independent of all independencies, the same EmptyOp result is returned.

Failure indicates the no suitable upper bound for the dynamic sizes could be found.

Definition at line 107 of file IndependenceTransforms.cpp.

References mlir::OpBuilder::create(), mlir::failed(), mlir::failure(), mlir::Builder::getIndexAttr(), makeIndependent(), and mlir::OpBuilder::setInsertionPoint().

◆ buildIndependentOp() [2/2]

FailureOr< Value > mlir::tensor::buildIndependentOp ( OpBuilder b,
tensor::PadOp  padOp,
ValueRange  independencies 
)

Build a new tensor::PadOp with low/high padding that is independent of all given independencies.

If the op is already independent of all independencies, the same PadOp result is returned.

Failure indicates the no suitable upper bound for low/high padding could be found.

Example: scf.for iv = lb to ub step step { high = affine.apply affine_map<(d0)[s0] -> (s0 - d0)> (i)[ub] p = tensor.pad t low[5] high[high] ... ... }

The function builds IR such as: high_new = affine.apply affine_map<()[s0, s1] -> (-s0 + s1)> ()[lb, ub] p_hoistable = tensor.pad t low[5] high[high_new] dim = tensor.dim t, c0 size = affine.apply affine_map<(d0)[s0, s1] -> (-d0 + s0 + s1 + 5)> (iv)[ub, dim] slice = tensor.extract_slice p_hoistable [0] [size] [1]

The slice is returned.

Definition at line 37 of file IndependenceTransforms.cpp.

References mlir::OpBuilder::create(), mlir::failed(), mlir::failure(), mlir::Builder::getAffineDimExpr(), mlir::Builder::getIndexAttr(), mlir::Operation::getResult(), makeIndependent(), and mlir::OpBuilder::setInsertionPoint().

◆ canFoldIntoConsumerOp()

bool mlir::tensor::canFoldIntoConsumerOp ( CastOp  castOp)

Determines whether tensor::CastOp casts to a more dynamic version of the source tensor.

This is useful to fold a tensor.cast into a consuming op and implement canonicalization patterns for ops in different dialects that may consume the results of tensor.cast operations. Such foldable tensor.cast operations are typically inserted as extract_slice ops and are canonicalized, to preserve the type compatibility of their uses.

Returns true when all conditions are met:

  1. source and result are ranked tensors with same element type and rank.
  2. the tensor type has more static information than the result

Example:

%1 = tensor.cast %0 : tensor<8x16xf32> to tensor<?x?xf32>
%2 = consumer %1 ... : tensor<?x?xf32> ...

folds into:

%2 = consumer %0 ... : tensor<8x16xf32> ...

This is useful to fold a tensor.cast into a consuming op and implement canonicalization patterns for ops in different dialects that may consume the results of tensor.cast operations. Such foldable tensor.cast operations are typically inserted as slice ops and are canonicalized, to preserve the type compatibility of their uses.

Returns true when all conditions are met:

  1. source and result are ranked tensors with same element type and rank.
  2. the tensor type has more static information than the result

Example:

%1 = tensor.cast %0 : tensor<8x16xf32> to tensor<?x?xf32>
%2 = consumer %1 ... : tensor<?x?xf32> ...

folds into:

%2 = consumer %0 ... : tensor<8x16xf32> ...

Definition at line 315 of file TensorOps.cpp.

References preservesStaticInformation().

◆ canFoldIntoProducerOp()

bool mlir::tensor::canFoldIntoProducerOp ( CastOp  castOp)

Determines whether the tensor::CastOp casts to a more static version of the source tensor.

This is useful to fold into a producing op and implement canonicaliation patterns with the tensor.cast op as the root, but producer being from different dialects. Returns true when all conditions are met:

  1. source and result and ranked tensors with same element type and rank.
  2. the result type has more static information than the source.

Example:

%1 = producer ... : tensor<?x?xf32>
%2 = tensor.cast %1 : tensor<?x?xf32> to tensor<8x16xf32>

can be canonicalized to :

%2 = producer ... : tensor<8x16xf32>

Not all ops might be canonicalizable this way, but for those that can be, this method provides a check that it is worth doing the canonicalization.

Definition at line 345 of file TensorOps.cpp.

References preservesStaticInformation().

◆ computeTransposedType()

FailureOr< RankedTensorType > mlir::tensor::computeTransposedType ( RankedTensorType  rankedTensorType,
ArrayRef< int64_t >  transposeVector 
)

Returns the transposed rankedTensorType if transposeVector is non-empty.

Fail if transposeVector is not a permutation matching the tensor rank.

Definition at line 57 of file Utils.cpp.

References mlir::applyPermutationToVector(), mlir::failure(), mlir::isPermutationVector(), and mlir::RankedTensorType::Builder::setShape().

Referenced by buildPackingLoopNestImpl(), and mlir::linalg::hoistPaddingOnTensors().

◆ createCanonicalRankReducingExtractSliceOp()

Value mlir::tensor::createCanonicalRankReducingExtractSliceOp ( OpBuilder b,
Location  loc,
Value  tensor,
RankedTensorType  targetType 
)

Create a rank-reducing ExtractSliceOp @[0 .

. 0] with strides [1 .. 1] and appropriate sizes (i.e. tensor.getSizes()) to reduce the rank of tensor to that of targetType.

Definition at line 2373 of file TensorOps.cpp.

References mlir::OpBuilder::createOrFold(), mlir::Builder::getIndexAttr(), getMixedSizes(), and mlir::Value::getType().

Referenced by mlir::linalg::DownscaleConv2DOp::returningMatchAndRewrite(), and mlir::linalg::DownscaleDepthwiseConv2DNhwcHwcOp::returningMatchAndRewrite().

◆ createCanonicalRankReducingInsertSliceOp()

Value mlir::tensor::createCanonicalRankReducingInsertSliceOp ( OpBuilder b,
Location  loc,
Value  tensor,
Value  dest 
)

Create a rank-reducing InsertSliceOp @[0 .

. 0] with strides [1 .. 1] and appropriate sizes (i.e. dest.getSizes()). The result is a new tensor with rank increased to that of dest, obtained by inserting tensor into dest at the canonical [0 .. 0] position.

Definition at line 2727 of file TensorOps.cpp.

References mlir::OpBuilder::createOrFold(), mlir::Builder::getIndexAttr(), getMixedSizes(), and mlir::Value::getType().

Referenced by mlir::linalg::DownscaleConv2DOp::returningMatchAndRewrite(), and mlir::linalg::DownscaleDepthwiseConv2DNhwcHwcOp::returningMatchAndRewrite().

◆ createDynamicDimValues()

SmallVector< Value > mlir::tensor::createDynamicDimValues ( OpBuilder b,
Location  loc,
Value  rankedTensor 
)

◆ createFoldTensorSubsetOpsPass()

std::unique_ptr< Pass > mlir::tensor::createFoldTensorSubsetOpsPass ( )

Creates an instance of the tensor subset folding pass.

Definition at line 256 of file FoldTensorSubsetOps.cpp.

◆ createPadHighOp()

PadOp mlir::tensor::createPadHighOp ( RankedTensorType  type,
Value  source,
Value  pad,
bool  nofold,
Location  loc,
OpBuilder builder 
)

◆ createTensorBufferizePass()

std::unique_ptr< Pass > mlir::tensor::createTensorBufferizePass ( )

Creates an instance of the tensor dialect bufferization pass.

Definition at line 56 of file Bufferize.cpp.

◆ foldTensorCast()

LogicalResult mlir::tensor::foldTensorCast ( Operation op)

Performs folding of any operand of op if it comes from a tensor::CastOp that can be folded.

Definition at line 354 of file TensorOps.cpp.

◆ getMixedSize()

OpFoldResult mlir::tensor::getMixedSize ( OpBuilder builder,
Location  loc,
Value  value,
int64_t  dim 
)

◆ getMixedSizes()

SmallVector< OpFoldResult > mlir::tensor::getMixedSizes ( OpBuilder builder,
Location  loc,
Value  value 
)

◆ getOrCreateDestination()

FailureOr< Value > mlir::tensor::getOrCreateDestination ( OpBuilder b,
Location  loc,
OpResult  opResult 
)

This is a helper function for DestinationStyleOpInterface.

If there is a destination operand for the given OpResult, return that operand. Otherwise, return an empty tensor (tensor.empty) with the shape of the OpResult. Dynamic dimensions are queried via ReifyRankedShapedTypeOpInterface.

Definition at line 70 of file TensorOps.cpp.

References mlir::OpBuilder::create(), mlir::failed(), mlir::failure(), mlir::Value::getDefiningOp(), mlir::Builder::getIndexAttr(), mlir::OpResult::getResultNumber(), mlir::Value::getType(), mlir::reifyResultShapes(), and mlir::OpBuilder::setInsertionPoint().

Referenced by mlir::scf::yieldReplacementForFusedProducer().

◆ getOrCreateDestinations()

LogicalResult mlir::tensor::getOrCreateDestinations ( OpBuilder b,
Location  loc,
Operation op,
SmallVector< Value > &  result 
)

This is a helper function for DestinationStyleOpInterface.

Get or create destinations for every tensor OpResult of the given op.

Definition at line 105 of file TensorOps.cpp.

Referenced by tileAndFuseFirstExtractUseThroughContainingOpBlockArgument(), and mlir::scf::tileAndFuseProducerOfSlice().

◆ getPackInverseDestPerm()

SmallVector<int64_t> mlir::tensor::getPackInverseDestPerm ( tensor::PackOp  packOp)

◆ getUnPackInverseSrcPerm() [1/2]

SmallVector<int64_t> mlir::tensor::getUnPackInverseSrcPerm ( tensor::UnPackOp  unpackOp)

◆ getUnPackInverseSrcPerm() [2/2]

SmallVector<int64_t> mlir::tensor::getUnPackInverseSrcPerm ( tensor::UnPackOp  ,
PackingMetadata &  metadata 
)

◆ isCastLikeExtractSliceOp()

bool mlir::tensor::isCastLikeExtractSliceOp ( ExtractSliceOp  op)

A tensor.extract_slice is a cast-like operation if it merely rank-reduces unit dimensions of the source tensor or extracts the entire source tensor.

Definition at line 166 of file Utils.cpp.

◆ isCastLikeInsertSliceOp()

bool mlir::tensor::isCastLikeInsertSliceOp ( InsertSliceOp  op)

A tensor.insert_slice is a cast-like operation if it merely rank-extends the source tensor or inserts the source tensor into a destination tensor with the same shape.

Definition at line 142 of file Utils.cpp.

◆ isSameTypeWithoutEncoding()

bool mlir::tensor::isSameTypeWithoutEncoding ( Type  tp1,
Type  tp2 
)

Tests if types are the same when ignoring encoding on ranked tensors.

Definition at line 119 of file TensorOps.cpp.

◆ populateDecomposeTensorConcatPatterns()

void mlir::tensor::populateDecomposeTensorConcatPatterns ( RewritePatternSet patterns)

Populates patterns with patterns that decompose tensor.concat into tensor.empty of a tensor of the concatenated size, followed by a chain of tensor.insert_slice operations on the inputs.

This is intended to be used as a fallback tensor -> tensor lowering that decomposes concat such that it can be bufferized into a sequence of copies.

Definition at line 90 of file ConcatOpPatterns.cpp.

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

◆ populateDropRedundantInsertSliceRankExpansionPatterns()

void mlir::tensor::populateDropRedundantInsertSliceRankExpansionPatterns ( RewritePatternSet patterns)

Populates patterns with patterns that drop redundant tensor.insert_slice rank expansions.

Definition at line 238 of file MergeConsecutiveInsertExtractSlicePatterns.cpp.

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

◆ populateFoldConstantExtractSlicePatterns()

void mlir::tensor::populateFoldConstantExtractSlicePatterns ( RewritePatternSet patterns,
const ControlConstantExtractSliceFusionFn controlFn = [](ExtractSliceOp op) {   return false; } 
)

Patterns to fold the extract slice op with its constant operand.

Definition at line 2286 of file TensorOps.cpp.

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

◆ populateFoldIntoPackAndUnpackPatterns()

void mlir::tensor::populateFoldIntoPackAndUnpackPatterns ( RewritePatternSet patterns)

Populates patterns with patterns that fold operations like tensor.pad and tensor.extract_slice into tensor.pack and tensor.unpack operations respectively.

Definition at line 431 of file PackAndUnpackPatterns.cpp.

References mlir::RewritePatternSet::getContext(), and mlir::RewritePatternSet::insert().

◆ populateFoldTensorEmptyPatterns()

void mlir::tensor::populateFoldTensorEmptyPatterns ( RewritePatternSet patterns,
bool  foldSingleUseOnly = false 
)

Populates patterns with patterns that fold tensor.empty with tensor.

[extract_slice|expand_shape|collapse_shape].

If singleUseOnly is set to "true", only tensor.empty ops with a single use are folded.

Definition at line 98 of file EmptyOpPatterns.cpp.

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

Referenced by populateFoldUnitExtentDimsViaReshapesPatterns(), and populateFoldUnitExtentDimsViaSlicesPatterns().

◆ populateFoldTensorSubsetIntoVectorTransferPatterns()

void mlir::tensor::populateFoldTensorSubsetIntoVectorTransferPatterns ( RewritePatternSet patterns)

Appends patterns for folding tensor subset ops into vector transfer ops.

Definition at line 231 of file FoldTensorSubsetOps.cpp.

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

Referenced by populateFoldTensorSubsetOpPatterns().

◆ populateFoldTensorSubsetOpPatterns()

void mlir::tensor::populateFoldTensorSubsetOpPatterns ( RewritePatternSet patterns)

Appends patterns for folding tensor subset ops into consumer load/store ops into patterns.

(This includes patterns for folding tensor subset ops into vector transfer ops.)

Definition at line 224 of file FoldTensorSubsetOps.cpp.

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

◆ populateMergeConsecutiveInsertExtractSlicePatterns()

void mlir::tensor::populateMergeConsecutiveInsertExtractSlicePatterns ( RewritePatternSet patterns)

Collects patterns to merge consecutive tensor.insert_slice/extract_slice into one.

These patterns are in this separate entry point because the bufferization is sensitive to IR structure, particularly those tensor.extract_slice and tensor.insert_slice ops for creating the slices.

Definition at line 230 of file MergeConsecutiveInsertExtractSlicePatterns.cpp.

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

◆ populateReassociativeReshapeFoldingPatterns()

void mlir::tensor::populateReassociativeReshapeFoldingPatterns ( RewritePatternSet patterns)

Populates patterns with patterns that fold tensor.expand_shape and tensor.collapse_shape into other ops.

Definition at line 84 of file ReshapePatterns.cpp.

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

◆ populateRewriteAsConstantPatterns()

void mlir::tensor::populateRewriteAsConstantPatterns ( RewritePatternSet patterns)

Populates patterns with patterns that replace tensor ops (such as tensor.generate) with constants when possible.

Definition at line 50 of file RewriteAsConstant.cpp.

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

◆ populateSimplifyPackAndUnpackPatterns()

void mlir::tensor::populateSimplifyPackAndUnpackPatterns ( RewritePatternSet patterns)

Populates patterns with patterns that simplify tensor.pack and tensor.unpack operations.

Definition at line 440 of file PackAndUnpackPatterns.cpp.

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

◆ preservesStaticInformation()

bool mlir::tensor::preservesStaticInformation ( Type  source,
Type  target 
)

Returns true if target is a ranked tensor type that preserves static information available in the source ranked tensor type.

Definition at line 263 of file TensorOps.cpp.

Referenced by canFoldIntoConsumerOp(), and canFoldIntoProducerOp().

◆ registerBufferizableOpInterfaceExternalModels()

void mlir::tensor::registerBufferizableOpInterfaceExternalModels ( DialectRegistry registry)

◆ registerFindPayloadReplacementOpInterfaceExternalModels()

void mlir::tensor::registerFindPayloadReplacementOpInterfaceExternalModels ( DialectRegistry registry)

Definition at line 71 of file TensorTransformOps.cpp.

References mlir::DialectRegistry::addExtension().

Referenced by mlir::registerAllDialects().

◆ registerInferTypeOpInterfaceExternalModels()

void mlir::tensor::registerInferTypeOpInterfaceExternalModels ( mlir::DialectRegistry registry)

Registers external models for Infer Type interfaces for tensor ops.

Currently, it registers:

  • ReifyRankedShapedTypeOpInterface for tensor.collapse_shape.
  • ReifyRankedShapedTypeOpInterface for tensor.expand_shape.

Unfortunately, a "normal" internal registration is not possible at the moment, because of the dependency of the interface implementation for these ops on affine.apply and Affine dialect already depends on TensorOps. In order to break the cyclic dependency (TensorOps->AffineOps->TensorOps) the implementation is moved to a separate library.

Definition at line 202 of file TensorInferTypeOpInterfaceImpl.cpp.

References mlir::DialectRegistry::addExtension().

Referenced by mlir::registerAllDialects().

◆ registerSubsetOpInterfaceExternalModels()

void mlir::tensor::registerSubsetOpInterfaceExternalModels ( DialectRegistry registry)

◆ registerTilingInterfaceExternalModels()

void mlir::tensor::registerTilingInterfaceExternalModels ( mlir::DialectRegistry registry)

Registers external models for Tiling interface for tensor ops.

Currently, it registers:

  • TilingInterface for tensor.pad, tensor.pack, and tensor.unpack.

Unfortunately, a "normal" internal registration is not possible at the moment, because of the dependency of the interface implementation for these ops on affine.apply and Affine dialect already depends on TensorOps. In order to break the cyclic dependency (TensorOps->AffineOps->TensorOps) the implementation is moved to a separate library.

Definition at line 686 of file TensorTilingInterfaceImpl.cpp.

References mlir::DialectRegistry::addExtension().

Referenced by mlir::registerAllDialects().

◆ registerTilingInterfaceExternalModelsForPackUnPackOps()

void mlir::tensor::registerTilingInterfaceExternalModelsForPackUnPackOps ( DialectRegistry registry)

Similar to the above registeration, but it is only for tensor.pack and tensor.unpack ops.

Definition at line 695 of file TensorTilingInterfaceImpl.cpp.

References mlir::DialectRegistry::addExtension().

◆ registerTransformDialectExtension()

void mlir::tensor::registerTransformDialectExtension ( DialectRegistry registry)

◆ registerValueBoundsOpInterfaceExternalModels()

void mlir::tensor::registerValueBoundsOpInterfaceExternalModels ( DialectRegistry registry)

◆ replaceExtractSliceWithTiledProducer()

FailureOr< TilingResult > mlir::tensor::replaceExtractSliceWithTiledProducer ( OpBuilder builder,
tensor::ExtractSliceOp  sliceOp,
OpResult  producerOp 
)

Pattern to swap an tensor.extract_slice with its producer when the producer implements the TilingInterface.

The pattern itself does not provide a mechanism to control where the application happens. With use of transform dialect that control is done within the transform dialect. Other use cases can inherit from this pattern and add necessary controls.

Definition at line 23 of file SwapExtractSliceWithProducerPatterns.cpp.

References mlir::failed(), mlir::failure(), mlir::OpResult::getOwner(), and mlir::OpResult::getResultNumber().

Referenced by mlir::scf::tileAndFuseProducerOfSlice().

◆ simplifyCollapseShapeWithRankReducingExtractSlice()

FailureOr< Operation * > mlir::tensor::simplifyCollapseShapeWithRankReducingExtractSlice ( tensor::CollapseShapeOp  op,
RewriterBase rewriter 
)

Tries to simplify a tensor.collapse_shape operation by inserting a single rank-reducing tensor.extract_slice operation.

The extract_slice op will either take the place of the source, allowing for a new, simpler collapse_shape op to replace op, or the collapse_shape op will be completely replaced by the extract_slice result. Either way, op is replaced and the new op is returned.

Example:

%result = tensor.collapse_shape %0 [[0, 1], [2, 3]]
: tensor<?x1x30x10xf32> to tensor<?x300xf32>

can be transformed to

%tmp = tensor.extract_slice %0 [0, 0, 0, 0]
[0, %dim1, 30, 30]
[1, 1, 1 1]
: tensor<?x1x30x10xf32> to tensor<?x30x10xf32>
%result = tensor.collapse_shape %tmp [[0], [1, 2]]
: tensor<?x30x10xf32> to tensor<?x300xf32>

Example:

%result = tensor.collapse_shape %1 [[0, 1], [2]]
: tensor<?x1x30xf32> to tensor<?x30xf32>

can be transformed to

%result = tensor.extract_slice %1 [0, 0, 0]
[%dim2, 1, 30]
[1, 1, 1]
: tensor<?x1x30xf32> to tensor<?x30xf32>

Unsupported cases:

This transform doesn't yet support reducing the rank of the reassociation indices, which would require inserting a tensor.expand_shape op similar to the following example:

%result = tensor.collapse_shape %0 [[0, 1], [2, 3]]
: tensor<1x1x30x10xf32> to tensor<1x300xf32>

can be transformed to

%tmp = tensor.extract_slice %0 [0, 0, 0, 0]
[0, 1, 30, 30]
[1, 1, 1 1]
: tensor<1x1x30x10xf32> to tensor<30x10xf32>
%result0 = tensor.collapse_shape %tmp [[0, 1]]
: tensor<30x10xf32> to tensor<300xf32>
%result1 = tensor.expand_shape %tmp [[0, 1], [2]] :... tensor<1x300xf32>

Definition at line 160 of file ExtractSliceFromReshapeUtils.cpp.