|
MLIR 24.0.0git
|
#include "mlir/Dialect/Tosa/IR/TosaOps.h"#include "mlir/Dialect/Quant/IR/Quant.h"#include "mlir/Dialect/Shard/Interfaces/ShardingInterface.h"#include "mlir/Dialect/Tensor/IR/Tensor.h"#include "mlir/Dialect/Tosa/Utils/QuantUtils.h"#include "mlir/Dialect/Tosa/Utils/ShapeUtils.h"#include "mlir/Dialect/Utils/IndexingUtils.h"#include "mlir/Dialect/Utils/VerificationUtils.h"#include "mlir/IR/BuiltinTypeInterfaces.h"#include "mlir/IR/BuiltinTypes.h"#include "mlir/IR/DialectImplementation.h"#include "mlir/IR/Matchers.h"#include "mlir/IR/TypeUtilities.h"#include "mlir/Interfaces/InferTypeOpInterface.h"#include "mlir/Transforms/InliningUtils.h"#include "llvm/ADT/APFloat.h"#include "llvm/ADT/SmallVectorExtras.h"#include "llvm/ADT/TypeSwitch.h"#include <numeric>#include <type_traits>#include "mlir/Dialect/Tosa/IR/TosaOpsDialect.cpp.inc"#include "mlir/Dialect/Tosa/Utils/ConversionUtils.h"#include "mlir/Dialect/Tosa/IR/TosaEnums.cpp.inc"#include "mlir/Dialect/Tosa/IR/TosaInterfaces.cpp.inc"#include "mlir/Dialect/Tosa/IR/TosaDialectBytecode.cpp.inc"#include "mlir/Dialect/Tosa/IR/TosaOpsTypesBase.cpp.inc"#include "mlir/Dialect/Tosa/IR/TosaOps.cpp.inc"#include "mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"Go to the source code of this file.
Classes | |
| class | ConvInferShapeAdaptorBase |
| class | ConvInferShapeAdaptor< Conv2DOp::Adaptor > |
| class | ConvInferShapeAdaptor< Conv2DBlockScaledOp::Adaptor > |
| class | ConvInferShapeAdaptor< Conv3DOp::Adaptor > |
Macros | |
| #define | GET_TYPEDEF_LIST |
| #define | GET_OP_LIST |
| #define | GET_ATTRDEF_LIST |
| #define | ZERO_POINT_HELPER(OP, OPERAND_NAME, SIGN_EXTEND) |
| #define | COMPATIBLE_RETURN_TYPES(OP) |
| #define | REDUCE_SHAPE_INFER(OP) |
| #define | NARY_SHAPE_INFER(OP) |
| #define | GET_ATTRDEF_CLASSES |
| #define | GET_TYPEDEF_CLASSES |
| #define | GET_OP_CLASSES |
Functions | |
| static SmallVector< int64_t > | convertToMlirShape (ArrayRef< int64_t > shape) |
| static std::optional< int64_t > | idivCheck (const int64_t lhs, const int64_t rhs) |
| static LogicalResult | verifyRescaleValueAndZpTypes (Operation *op, Value val, Value valZp, StringRef name) |
| LogicalResult | tryUpdateDimOrFailure (Operation *op, int64_t &currDim, const int64_t newDim, const StringRef operandName, const StringRef dimName) |
| static void | printShapeToDiagnostic (InFlightDiagnostic &diag, ArrayRef< int64_t > shape) |
| static LogicalResult | verifyOutputShapeCompatibleWithExpected (Operation *op, ShapedType outputType, ArrayRef< int64_t > expectedShape, StringRef outputName="output") |
| LogicalResult | verifyConvOutputSize (Operation *op, const int64_t inputSize, const int64_t kernelSize, const int64_t outputSize, const int64_t padBefore, const int64_t padAfter, const int64_t stride, const int64_t dilation, const llvm::StringRef dimName, const llvm::StringRef dimAxis, const llvm::StringRef padBeforeName, const llvm::StringRef padAfterName) |
| static ParseResult | parseScaleValues (AsmParser &parser, SmallVector< Attribute > &scaleValues, Type scaleType) |
| static void | printScaleValues (AsmPrinter &printer, ArrayRef< Attribute > scaleValues, Type) |
| template<typename T> | |
| static LogicalResult | verifyConvOp (T op) |
| template<typename T> | |
| static LogicalResult | verifyConvOpModes (T op) |
| template<typename T> | |
| static LogicalResult | verifyConvOpErrorIf (T op) |
| static LogicalResult | errorIfTypeOrShapeMismatch (Operation *op, Type type1, StringRef name1, Type type2, StringRef name2) |
| static LogicalResult | errorIfTypeOrShapeMismatch (Operation *op, ValueRange list1, StringRef name1, ValueRange list2, StringRef name2) |
| static LogicalResult | errorIfShapeNotSizeOne (Operation *op, Type type) |
| template<typename T> | |
| static LogicalResult | verifyVariableOpErrorIf (T op, Type type, StringRef name) |
| static LogicalResult | verifySameElementTypes (Operation *op, Type aType, Type bType, StringRef aName="input", StringRef bName="output") |
| static LogicalResult | verifyPoolingOpImpl (Operation *op, ArrayRef< int64_t > kernel, ArrayRef< int64_t > strides, ArrayRef< int64_t > padding, Value input, Value output) |
| template<typename T> | |
| static LogicalResult | verifyPoolingOp (T op) |
| template<typename T> | |
| static LogicalResult | verifyAvgPoolCommonTypeAndZpChecks (T op) |
| template<typename T, typename std::enable_if< IsSupportedAdaptivePoolConstShapeVerifyOp< T >, int >::type = 0> | |
| static void | extractAdaptivePoolingConstShapeOperands (T op, AdaptivePoolingConstShapeValues &values) |
| static void | buildConvOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value input, Value weight, Value bias, DenseI64ArrayAttr pad, DenseI64ArrayAttr stride, DenseI64ArrayAttr dilation, TypeAttr accType) |
| This builder is called on all convolution operators except TransposeConv, which has specialized output shape semantics. | |
| static void | buildTransConvOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value input, Value weight, Value bias, DenseI64ArrayAttr outpad, DenseI64ArrayAttr stride, TypeAttr accType) |
| Handles tosa.transpose_conv2d which has outpad and output shape attributes. | |
| static void | buildMatMulLikeOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value a, Value b) |
| static void | buildMatMulOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value a, Value b) |
| static void | buildMatMulTOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value a, Value b) |
| static void | buildAvgPool2dOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value input, DenseArrayAttr kernel, DenseArrayAttr stride, DenseArrayAttr pad, TypeAttr accType) |
| Both the tosa.avg_pool2d and unary ops use the same UnaryOpQuantizationAttr but avg_pool operator has its own builder as it has additional parameters not part of the unary ops. | |
| static void | buildAvgPool2dAdaptiveOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value input, DenseI64ArrayAttr kernel, DenseI64ArrayAttr stride, DenseI64ArrayAttr pad, TypeAttr accType) |
| This builder mirrors avg_pool2d quant-info handling and materializes kernel/stride/pad as const_shape operands for avg_pool2d_adaptive. | |
| static void | buildNegateOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value input) |
| This builder is called on single-parameter negate operator to construct input and output zero points based on their types. | |
| static void | buildPadOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value input, Value paddings) |
| This builder is called on TOSA pad operator that needs to create its own OptionalAttr quantization_attr parameter to scale the padding values correctly. | |
| static void | buildVariableOp (OpBuilder &builder, OperationState &result, StringRef name, Type variableType, Attribute initialValue) |
| static FailureOr< int64_t > | resolveBroadcastDim (const int64_t dim1, const int64_t dim2) |
| static LogicalResult | resolveBroadcastShape (const ValueShapeRange &operands, SmallVector< int64_t > &outShape) |
| static LogicalResult | verifyDimIsPowerOfTwo (Operation *op, const int64_t dimSize, const llvm::StringRef dimName) |
| template<typename T> | |
| static LogicalResult | verifyMatMulQuantizedOperandsType (T op, Type aElementType, Type bElementType) |
| template<typename T> | |
| static LogicalResult | verifyMatMulZeroPointType (T op, Value input, Value zp, StringRef inputName, StringRef zpName) |
| static FailureOr< int64_t > | getZeroPoint (Value val, bool signExtend) |
| template<typename T> | |
| static LogicalResult | verifyZeroPoint (T op, Value val, const int64_t &zp, const std::string &operand) |
| static LogicalResult | verifyZeroPoint (tosa::RescaleOp op, Value zpVal, const int64_t &zp, const std::string &operand) |
| static LogicalResult | ReduceInferReturnTypes (ShapeAdaptor operandShape, Type inputType, IntegerAttr axis, SmallVectorImpl< ShapedTypeComponents > &inferredReturnShapes) |
| template<typename T> | |
| static LogicalResult | verifyReduceOp (T op) |
| static LogicalResult | NAryInferReturnTypes (const ValueShapeRange &operands, SmallVectorImpl< ShapedTypeComponents > &inferredReturnShapes) |
| static LogicalResult | poolingInferReturnTypes (ShapeAdaptor inputShape, ArrayRef< int64_t > kernel, ArrayRef< int64_t > stride, ArrayRef< int64_t > pad, SmallVectorImpl< ShapedTypeComponents > &inferredReturnShapes) |
| template<typename AdaptorT> | |
| LogicalResult | inferConvReturnTypeComponents (AdaptorT adaptor, SmallVectorImpl< ShapedTypeComponents > &inferredReturnShapes) |
| static void | printInitializationList (OpAsmPrinter &parser, Block::BlockArgListType blocksArgs, ValueRange initializers, StringRef prefix="") |
Variables | |
| template<typename T> | |
| static constexpr bool | IsSupportedAdaptivePoolConstShapeVerifyOp |
| #define COMPATIBLE_RETURN_TYPES | ( | OP | ) |
Definition at line 4201 of file TosaOps.cpp.
| #define GET_ATTRDEF_CLASSES |
Definition at line 6114 of file TosaOps.cpp.
| #define GET_ATTRDEF_LIST |
| #define GET_OP_CLASSES |
Definition at line 6127 of file TosaOps.cpp.
| #define GET_OP_LIST |
| #define GET_TYPEDEF_CLASSES |
Definition at line 6120 of file TosaOps.cpp.
| #define GET_TYPEDEF_LIST |
| #define NARY_SHAPE_INFER | ( | OP | ) |
Definition at line 4303 of file TosaOps.cpp.
| #define REDUCE_SHAPE_INFER | ( | OP | ) |
Definition at line 4210 of file TosaOps.cpp.
| #define ZERO_POINT_HELPER | ( | OP, | |
| OPERAND_NAME, | |||
| SIGN_EXTEND ) |
Definition at line 3415 of file TosaOps.cpp.
|
static |
This builder mirrors avg_pool2d quant-info handling and materializes kernel/stride/pad as const_shape operands for avg_pool2d_adaptive.
Definition at line 1658 of file TosaOps.cpp.
References mlir::detail::DenseArrayAttrImpl< T >::asArrayRef(), b, mlir::tosa::buildUnaryOpQuantizationAttr(), mlir::tosa::createZeroPointTensor(), mlir::emitError(), mlir::tosa::getTosaConstShape(), mlir::Value::getType(), and result.
|
static |
Both the tosa.avg_pool2d and unary ops use the same UnaryOpQuantizationAttr but avg_pool operator has its own builder as it has additional parameters not part of the unary ops.
Definition at line 1614 of file TosaOps.cpp.
References mlir::tosa::buildUnaryOpQuantizationAttr(), mlir::tosa::createZeroPointTensor(), mlir::emitError(), mlir::Value::getType(), and result.
|
static |
This builder is called on all convolution operators except TransposeConv, which has specialized output shape semantics.
The builder also defines the bitwidth of the output given the bit width of the input & weight content.
Definition at line 1531 of file TosaOps.cpp.
References mlir::tosa::buildConvOpQuantizationAttr(), mlir::tosa::buildConvOpResultTypeInfo(), mlir::tosa::createZPsAsConst(), and result.
|
static |
Definition at line 1573 of file TosaOps.cpp.
References b, mlir::tosa::buildMatMulOpQuantizationAttr(), mlir::tosa::createZPsAsConst(), mlir::Builder::getI32Type(), mlir::Builder::getIntegerType(), mlir::tosa::getStorageElementTypeOrSelf(), mlir::Value::getType(), and result.
Referenced by buildMatMulOpWithQuantInfo(), and buildMatMulTOpWithQuantInfo().
|
static |
Definition at line 1598 of file TosaOps.cpp.
References b, buildMatMulLikeOpWithQuantInfo(), and result.
|
static |
Definition at line 1604 of file TosaOps.cpp.
References b, buildMatMulLikeOpWithQuantInfo(), and result.
|
static |
This builder is called on single-parameter negate operator to construct input and output zero points based on their types.
Definition at line 1705 of file TosaOps.cpp.
References mlir::tosa::buildUnaryOpQuantizationAttr(), mlir::tosa::createZeroPointTensor(), mlir::emitError(), mlir::Value::getType(), and result.
|
static |
This builder is called on TOSA pad operator that needs to create its own OptionalAttr quantization_attr parameter to scale the padding values correctly.
No pad_const is interpreted as zero-padding.
Definition at line 1745 of file TosaOps.cpp.
References mlir::tosa::buildPadOpQuantizationAttr(), mlir::tosa::createPadConstTensor(), and result.
|
static |
Handles tosa.transpose_conv2d which has outpad and output shape attributes.
Definition at line 1555 of file TosaOps.cpp.
References mlir::tosa::buildConvOpQuantizationAttr(), mlir::tosa::buildConvOpResultTypeInfo(), mlir::tosa::createZPsAsConst(), and result.
|
static |
Definition at line 1759 of file TosaOps.cpp.
References mlir::tosa::convertFromMlirShape(), mlir::emitError(), mlir::Builder::getIndexTensorAttr(), mlir::Builder::getStringAttr(), and result.
|
static |
Definition at line 138 of file TosaOps.cpp.
Referenced by mlir::tosa::printVariableOpTypeOrInitialValue().
Definition at line 1164 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getNumElements(), mlir::ShapeAdaptor::hasRank(), mlir::ShapeAdaptor::hasStaticShape(), and success().
|
static |
Definition at line 1122 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), success(), and mlir::verifyCompatibleShape().
Referenced by errorIfTypeOrShapeMismatch(), and verifyVariableOpErrorIf().
|
static |
Definition at line 1146 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), errorIfTypeOrShapeMismatch(), mlir::ValueRange::getTypes(), and success().
|
static |
Definition at line 1424 of file TosaOps.cpp.
References mlir::tosa::getConstShapeValues().
Definition at line 3346 of file TosaOps.cpp.
References mlir::m_Constant(), and mlir::matchPattern().
Referenced by mlir::quant::UniformQuantizedValueConverter::UniformQuantizedValueConverter().
Definition at line 577 of file TosaOps.cpp.
Referenced by mlir::tosa::impl::TosaValidationBase< DerivedT >::createTosaValidation, mlir::tosa::impl::TosaValidationBase< DerivedT >::TosaValidationBase(), verifyConvOutputSize(), and verifyPoolingOpImpl().
| LogicalResult inferConvReturnTypeComponents | ( | AdaptorT | adaptor, |
| SmallVectorImpl< ShapedTypeComponents > & | inferredReturnShapes ) |
Definition at line 4637 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getDimSize(), mlir::ShapeAdaptor::hasRank(), and success().
|
static |
Definition at line 4291 of file TosaOps.cpp.
References resolveBroadcastShape(), and success().
|
static |
Definition at line 779 of file TosaOps.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseFloat(), mlir::AsmParser::parseOptionalColon(), mlir::AsmParser::parseType(), and success().
|
static |
Definition at line 4400 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getDimSize(), mlir::ShapeAdaptor::hasRank(), and success().
|
static |
Definition at line 5593 of file TosaOps.cpp.
|
static |
Definition at line 808 of file TosaOps.cpp.
References mlir::AsmPrinter::printAttributeWithoutType().
|
static |
Definition at line 654 of file TosaOps.cpp.
References diag().
Referenced by verifyOutputShapeCompatibleWithExpected().
|
static |
Definition at line 4185 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getDims(), mlir::ShapeAdaptor::getRank(), mlir::ShapeAdaptor::hasRank(), and success().
Definition at line 1789 of file TosaOps.cpp.
Referenced by resolveBroadcastShape().
|
static |
Definition at line 1803 of file TosaOps.cpp.
References mlir::ValueShapeRange::getShape(), resolveBroadcastDim(), and success().
Referenced by NAryInferReturnTypes().
| LogicalResult tryUpdateDimOrFailure | ( | Operation * | op, |
| int64_t & | currDim, | ||
| const int64_t | newDim, | ||
| const StringRef | operandName, | ||
| const StringRef | dimName ) |
Definition at line 639 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), and success().
|
static |
Definition at line 1366 of file TosaOps.cpp.
References mlir::tosa::getStorageElementTypeOrSelf(), mlir::Type::isBF16(), mlir::Type::isF16(), mlir::Type::isF32(), and success().
|
static |
Definition at line 855 of file TosaOps.cpp.
References mlir::tosa::getStorageElementTypeFromQuantized(), mlir::tosa::getStorageElementTypeOrSelf(), and success().
|
static |
Definition at line 1019 of file TosaOps.cpp.
References success(), and verifyConvOutputSize().
|
static |
Definition at line 997 of file TosaOps.cpp.
References mlir::tosa::getStorageElementTypeFromQuantized(), and success().
| LogicalResult verifyConvOutputSize | ( | Operation * | op, |
| const int64_t | inputSize, | ||
| const int64_t | kernelSize, | ||
| const int64_t | outputSize, | ||
| const int64_t | padBefore, | ||
| const int64_t | padAfter, | ||
| const int64_t | stride, | ||
| const int64_t | dilation, | ||
| const llvm::StringRef | dimName, | ||
| const llvm::StringRef | dimAxis, | ||
| const llvm::StringRef | padBeforeName, | ||
| const llvm::StringRef | padAfterName ) |
Definition at line 683 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), idivCheck(), and success().
Referenced by verifyConvOpErrorIf().
|
static |
Definition at line 1889 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), and success().
|
static |
Definition at line 2187 of file TosaOps.cpp.
References success().
|
static |
Definition at line 2214 of file TosaOps.cpp.
References diag(), mlir::getElementTypeOrSelf(), mlir::tosa::getStorageElementTypeOrSelf(), mlir::Value::getType(), and success().
|
static |
Definition at line 667 of file TosaOps.cpp.
References diag(), mlir::Operation::emitOpError(), printShapeToDiagnostic(), success(), and mlir::verifyCompatibleShape().
|
static |
Definition at line 1360 of file TosaOps.cpp.
References verifyPoolingOpImpl().
|
static |
Definition at line 1265 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), mlir::Value::getType(), idivCheck(), success(), and verifySameElementTypes().
Referenced by verifyPoolingOp().
|
static |
Definition at line 4235 of file TosaOps.cpp.
References mlir::TensorType::getShape(), mlir::TensorType::hasRank(), and success().
|
static |
Definition at line 594 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), mlir::Type::getIntOrFloatBitWidth(), mlir::tosa::getStorageElementTypeOrSelf(), mlir::Value::getType(), and success().
|
static |
Definition at line 1199 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), and success().
Referenced by verifyPoolingOpImpl().
|
static |
Definition at line 1173 of file TosaOps.cpp.
References errorIfTypeOrShapeMismatch(), mlir::tosa::getVariableType(), mlir::SymbolTable::lookup(), and success().
|
static |
Definition at line 3373 of file TosaOps.cpp.
References mlir::getElementTypeOrSelf(), mlir::Type::isInteger(), and success().
|
static |
Definition at line 3388 of file TosaOps.cpp.
References mlir::getElementTypeOrSelf(), mlir::Type::isInteger(), and success().
|
staticconstexpr |
Definition at line 1417 of file TosaOps.cpp.