#include "mlir/Conversion/TosaToLinalg/TosaToLinalg.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/Dialect/Linalg/IR/Linalg.h"
#include "mlir/Dialect/Math/IR/Math.h"
#include "mlir/Dialect/SCF/IR/SCF.h"
#include "mlir/Dialect/Tensor/IR/Tensor.h"
#include "mlir/Dialect/Tensor/Utils/Utils.h"
#include "mlir/Dialect/Tosa/IR/TosaOps.h"
#include "mlir/Dialect/Tosa/Utils/ConversionUtils.h"
#include "mlir/Dialect/Utils/IndexingUtils.h"
#include "mlir/Dialect/Utils/ReshapeOpsUtils.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/DialectConversion.h"
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include <numeric>
#include <type_traits>
usingnamespacemlir;
usingnamespacemlir::tosa;
static mlir::Value applyPad(Location loc, Value input, ArrayRef<int64_t> pad,
TypedAttr padAttr, OpBuilder &rewriter) { … }
static mlir::Value
linalgIntBroadcastExtSIAdd(PatternRewriter &rewriter, Location loc, Value bias,
Value conv, Value result,
ArrayRef<AffineMap> indexingMaps) { … }
static mlir::Value linalgBroadcastAndMaybeExtSI(PatternRewriter &rewriter,
Location loc, Value source,
Value result) { … }
static mlir::Value reifyConstantDim(int64_t attr,
ImplicitLocOpBuilder &builder) { … }
static mlir::Value getConvOrPoolOutputDim(Location loc, Value inputDim,
int64_t padBeforeAttr,
int64_t padAfterAttr, Value kernelDim,
int64_t strideAttr,
int64_t dilationAttr,
OpBuilder &rewriter) { … }
static SmallVector<Value> inferDynamicDimsForConv(
Location loc, Value input, Value weight, ShapedType resultTy,
ArrayRef<int64_t> padAttr, ArrayRef<int64_t> strideAttr,
ArrayRef<int64_t> dilationAttr, ArrayRef<int64_t> inputSizeDims,
ArrayRef<int64_t> kernelSizeDims, OpBuilder &rewriter) { … }
static void createDepthwiseConvCollapseMap(
int64_t outputRank, SmallVector<ReassociationExprs, 4> &reassociationMap,
OpBuilder &rewriter) { … }
namespace {
template <typename TosaConvOp, typename LinalgConvOp, typename LinalgConvQOp>
class ConvConverter : public OpConversionPattern<TosaConvOp> { … };
class DepthwiseConvConverter
: public OpConversionPattern<tosa::DepthwiseConv2DOp> { … };
class MatMulConverter : public OpConversionPattern<tosa::MatMulOp> { … };
class FullyConnectedConverter
: public OpConversionPattern<tosa::FullyConnectedOp> { … };
class MaxPool2dConverter : public OpRewritePattern<tosa::MaxPool2dOp> { … };
class AvgPool2dConverter : public OpRewritePattern<tosa::AvgPool2dOp> { … };
class TransposeConverter : public OpRewritePattern<tosa::TransposeOp> { … };
}
void mlir::tosa::populateTosaToLinalgNamedConversionPatterns(
RewritePatternSet *patterns, const TosaToLinalgNamedOptions &options) { … }