21 auto linalgOp = cast<LinalgOp>(op);
22 auto *dialect =
static_cast<LinalgDialect *
>(linalgOp->getDialect());
23 LinalgDialect::RegionBuilderFunType fun =
26 assert(fun &&
"Expected a builtin named Linalg op.");
27 assert(op->
getNumRegions() == 1 &&
"Expected Linalg op with 1 region");
29 "Expected Linalg op with 0 blocks");
33 for (
OpOperand &opOperand : linalgOp->getOpOperands()) {
35 argLocs.push_back(opOperand.get().getLoc());
40 Block *body =
b.createBlock(®ion, {}, argTypes, argLocs);
41 b.setInsertionPointToStart(body);
44 op, [&](StringRef name,
Attribute &attr) { attrs.
append(name, attr); });
45 fun(
b, *body, attrs, {});
49 auto linalgOp = llvm::dyn_cast<mlir::linalg::LinalgOp>(
unwrap(op));
60 return {toAttr(dims.
batch), toAttr(dims.
m), toAttr(dims.
n), toAttr(dims.
k)};
65 auto linalgOp = dyn_cast<linalg::LinalgOp>(
unwrap(op));
69 FailureOr<linalg::ContractionDimensions> maybeDims =
71 if (failed(maybeDims))
82 if (!indexingMaps || numMaps != 3)
86 for (
size_t i = 0; i < numMaps; ++i) {
87 maps.push_back(
unwrap(indexingMaps[i]));
90 FailureOr<linalg::ContractionDimensions> maybeDims =
92 if (failed(maybeDims))
101 auto linalgOp = llvm::dyn_cast<mlir::linalg::LinalgOp>(
unwrap(op));
125 auto linalgOp = llvm::dyn_cast<mlir::linalg::LinalgOp>(
unwrap(op));
129 FailureOr<linalg::ConvolutionDimensions> maybeDims =
131 if (failed(maybeDims))
142 if (!indexingMaps || numMaps != 3)
146 for (
size_t i = 0; i < numMaps; ++i)
147 maps.push_back(
unwrap(indexingMaps[i]));
149 FailureOr<linalg::ConvolutionDimensions> maybeDims =
151 if (failed(maybeDims))
159 auto linalgOp = llvm::dyn_cast<mlir::linalg::LinalgOp>(
unwrap(op));
161 return MlirAttribute{
nullptr};
163 ArrayAttr attr = linalgOp.getIndexingMaps();
static MlirLinalgConvolutionDimensions toConvolutionDimensions(MLIRContext *ctx, const linalg::ConvolutionDimensions &dims)
MLIR_CAPI_EXPORTED MlirLinalgConvolutionDimensions mlirLinalgInferConvolutionDimensions(MlirOperation op)
void mlirLinalgFillBuiltinNamedOpRegion(MlirOperation mlirOp)
Apply the special region builder for the builtin named Linalg op.
MLIR_CAPI_EXPORTED MlirLinalgContractionDimensions mlirLinalgInferContractionDimensionsFromMaps(const MlirAffineMap *indexingMaps, size_t numMaps)
static MlirLinalgContractionDimensions toContractionDimensions(MLIRContext *ctx, const linalg::ContractionDimensions &dims)
MLIR_CAPI_EXPORTED bool mlirLinalgIsAContractionOp(MlirOperation op)
MLIR_CAPI_EXPORTED MlirAttribute mlirLinalgGetIndexingMapsAttribute(MlirOperation op)
MLIR_CAPI_EXPORTED MlirLinalgConvolutionDimensions mlirLinalgInferConvolutionDimensionsFromMaps(const MlirAffineMap *indexingMaps, size_t numMaps)
MLIR_CAPI_EXPORTED bool mlirLinalgIsAConvolutionOp(MlirOperation op)
MLIR_CAPI_EXPORTED MlirLinalgContractionDimensions mlirLinalgInferContractionDimensions(MlirOperation op)
#define MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Name, Namespace, ClassName)
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
ImplicitLocOpBuilder maintains a 'current location', allowing use of the create<> method without spec...
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
This class represents an operand of an operation.
StringRef getStringRef() const
Return the name of this operation. This always succeeds.
void walkInherentAttrs(Operation *op, InherentAttrVisitor visitor) const
Visit the inherent attributes stored in the properties of op.
Operation is the basic unit of execution within MLIR.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
unsigned getNumRegions()
Returns the number of regions held by this operation.
Location getLoc()
The source location the operation was defined or derived from.
OperationName getName()
The name of an operation is the key identifier for it.
MLIRContext * getContext()
Return the context this operation is associated with.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
BlockListType & getBlocks()
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int32_t > content)
MlirDiagnostic wrap(mlir::Diagnostic &diagnostic)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
#define MLIR_CAPI_EXPORTED
FailureOr< ConvolutionDimensions > inferConvolutionDims(LinalgOp linalgOp)
Find at least 1 parallel (output_image) and reduction (filter_loop) dimension candidates that form a ...
bool isaConvolutionOpInterface(LinalgOp linalgOp, bool allowEmptyConvolvedDims=false)
Checks whether linalgOp conforms to ConvolutionOpInterface.
FailureOr< ContractionDimensions > inferContractionDims(LinalgOp linalgOp)
Find at least 2 parallel (m and n) and 1 reduction (k) dimension candidates that form a matmul subcom...
bool isaContractionOpInterface(LinalgOp linalgOp)
Checks whether linalgOp conforms to ContractionOpInterface.
Include the generated interface declarations.
Type getElementTypeOrSelf(Type type)
Return the element type or return the type itself.
Positions of a Linalg op loops that correspond to different kinds of a contraction dimension.
SmallVector< unsigned, 2 > batch
SmallVector< unsigned, 2 > m
SmallVector< unsigned, 2 > n
SmallVector< unsigned, 2 > k
Positions of a Linalg op loops that correspond to different kinds of a convolution dimension.
SmallVector< unsigned, 2 > depth
SmallVector< unsigned, 2 > outputImage
SmallVector< unsigned, 2 > outputChannel
SmallVector< int64_t, 2 > dilations
SmallVector< int64_t, 2 > strides
SmallVector< unsigned, 2 > inputChannel
SmallVector< unsigned, 2 > batch
SmallVector< unsigned, 2 > filterLoop