MLIR
22.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/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/TypeSwitch.h"
#include <numeric>
#include "mlir/Dialect/Tosa/IR/TosaOpsDialect.cpp.inc"
#include "mlir/Dialect/Tosa/Utils/ConversionUtils.h"
#include "mlir/Dialect/Tosa/IR/TosaAvailability.cpp.inc"
#include "mlir/Dialect/Tosa/IR/TosaEnums.cpp.inc"
#include "mlir/Dialect/Tosa/IR/TosaInterfaces.cpp.inc"
#include "mlir/Dialect/Tosa/IR/TosaOpAvailabilityImpl.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.
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) |
std::optional< int64_t > | idivCheck (const int64_t lhs, const int64_t rhs) |
Type | getStorageElementTypeOrSelf (Type type) |
Type | getStorageElementTypeOrSelf (Value value) |
static LogicalResult | verifyRescaleValueAndZpTypes (Operation *op, Value val, Value valZp, StringRef name) |
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) |
static FailureOr< tosa::VariableOp > | findVariableDecl (Operation *op, StringRef symName) |
template<typename T > | |
static LogicalResult | verifyVariableOpErrorIf (T op, Type type, StringRef name) |
template<typename T > | |
static LogicalResult | verifySameElementTypes (T op, Type inType, Type outType) |
template<typename T > | |
static LogicalResult | verifyPoolingOp (T op) |
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. More... | |
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. More... | |
static void | buildMatMulOpWithQuantInfo (OpBuilder &builder, OperationState &result, Type outputType, Value a, Value b) |
The tosa.matmul op is also intended to be generated where a fully_connected op must be constructed where the weight is not a constant. More... | |
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. More... | |
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. More... | |
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. More... | |
static void | buildVariableOp (OpBuilder &builder, OperationState &result, StringRef name, Type variableType, Attribute initialValue) |
static LogicalResult | resolveBroadcastShape (const ValueShapeRange &operands, SmallVector< int64_t > &outShape) |
static LogicalResult | verifyDimIsPowerOfTwo (Operation *op, const int64_t dimSize, const llvm::StringRef dimName) |
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) |
static void | printInitializationList (OpAsmPrinter &parser, Block::BlockArgListType blocksArgs, ValueRange initializers, StringRef prefix="") |
#define COMPATIBLE_RETURN_TYPES | ( | OP | ) |
Definition at line 3011 of file TosaOps.cpp.
#define GET_ATTRDEF_CLASSES |
Definition at line 4345 of file TosaOps.cpp.
#define GET_ATTRDEF_LIST |
#define GET_OP_CLASSES |
Definition at line 4358 of file TosaOps.cpp.
#define GET_OP_LIST |
#define GET_TYPEDEF_CLASSES |
Definition at line 4351 of file TosaOps.cpp.
#define GET_TYPEDEF_LIST |
#define NARY_SHAPE_INFER | ( | OP | ) |
Definition at line 3113 of file TosaOps.cpp.
#define REDUCE_SHAPE_INFER | ( | OP | ) |
Definition at line 3020 of file TosaOps.cpp.
#define ZERO_POINT_HELPER | ( | OP, | |
OPERAND_NAME, | |||
SIGN_EXTEND | |||
) |
Definition at line 2492 of file TosaOps.cpp.
|
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 1301 of file TosaOps.cpp.
References mlir::OperationState::addAttribute(), mlir::OperationState::addOperands(), mlir::tosa::buildUnaryOpQuantizationAttr(), mlir::tosa::createZeroPointTensor(), mlir::emitError(), mlir::Value::getType(), mlir::OperationState::location, and mlir::OperationState::types.
|
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 1226 of file TosaOps.cpp.
References mlir::OperationState::addAttribute(), mlir::OperationState::addOperands(), mlir::OperationState::addTypes(), mlir::tosa::buildConvOpQuantizationAttr(), mlir::tosa::buildConvOpResultTypeInfo(), and mlir::tosa::createZPsAsConst().
|
static |
The tosa.matmul op is also intended to be generated where a fully_connected op must be constructed where the weight is not a constant.
In this case, the fully_connected op must be expressed using matmul. TODO: Add link to the leglization document explaining this.
Definition at line 1272 of file TosaOps.cpp.
References mlir::OperationState::addOperands(), mlir::OperationState::addTypes(), mlir::tosa::buildMatMulOpQuantizationAttr(), mlir::tosa::createZPsAsConst(), mlir::Builder::getI32Type(), mlir::Builder::getIntegerType(), getStorageElementTypeOrSelf(), and mlir::Value::getType().
|
static |
This builder is called on single-parameter negate operator to construct input and output zero points based on their types.
Definition at line 1346 of file TosaOps.cpp.
References mlir::OperationState::addOperands(), mlir::tosa::buildUnaryOpQuantizationAttr(), mlir::tosa::createZeroPointTensor(), mlir::emitError(), mlir::Value::getType(), mlir::OperationState::location, and mlir::OperationState::types.
|
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 1386 of file TosaOps.cpp.
References mlir::OperationState::addOperands(), mlir::tosa::buildPadOpQuantizationAttr(), mlir::tosa::createPadConstTensor(), mlir::OperationState::location, and mlir::OperationState::types.
|
static |
Handles tosa.transpose_conv2d which has outpad and output shape attributes.
Definition at line 1250 of file TosaOps.cpp.
References mlir::OperationState::addAttribute(), mlir::OperationState::addOperands(), mlir::OperationState::addTypes(), mlir::tosa::buildConvOpQuantizationAttr(), mlir::tosa::buildConvOpResultTypeInfo(), and mlir::tosa::createZPsAsConst().
|
static |
Definition at line 1400 of file TosaOps.cpp.
References mlir::OperationState::addAttribute(), mlir::tosa::convertFromMlirShape(), mlir::emitError(), mlir::get(), mlir::Builder::getIndexTensorAttr(), mlir::Builder::getStringAttr(), and mlir::OperationState::location.
|
static |
Definition at line 136 of file TosaOps.cpp.
Referenced by mlir::tosa::printVariableOpTypeOrInitialValue().
Definition at line 900 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getNumElements(), mlir::ShapeAdaptor::hasRank(), and mlir::ShapeAdaptor::hasStaticShape().
|
static |
Definition at line 858 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), mlir::remark::failed(), and mlir::verifyCompatibleShape().
Referenced by errorIfTypeOrShapeMismatch(), and verifyVariableOpErrorIf().
|
static |
Definition at line 882 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), errorIfTypeOrShapeMismatch(), mlir::remark::failed(), and mlir::ValueRange::getTypes().
|
static |
Definition at line 910 of file TosaOps.cpp.
References mlir::WalkResult::advance(), mlir::Operation::getParentOfType(), and mlir::WalkResult::interrupt().
Referenced by verifyVariableOpErrorIf().
Definition at line 521 of file TosaOps.cpp.
References mlir::getElementTypeOrSelf().
Referenced by buildMatMulOpWithQuantInfo(), mlir::tosa::createPadConstTensor(), mlir::tosa::createZeroPointTensor(), getStorageElementTypeOrSelf(), verifyConvOp(), and verifyRescaleValueAndZpTypes().
Definition at line 528 of file TosaOps.cpp.
References getStorageElementTypeOrSelf(), and mlir::Value::getType().
|
static |
Definition at line 2422 of file TosaOps.cpp.
References mlir::m_Constant(), and mlir::matchPattern().
std::optional<int64_t> idivCheck | ( | const int64_t | lhs, |
const int64_t | rhs | ||
) |
Definition at line 515 of file TosaOps.cpp.
Referenced by verifyConvOpErrorIf(), and verifyPoolingOp().
|
static |
Definition at line 3101 of file TosaOps.cpp.
References mlir::remark::failed(), and resolveBroadcastShape().
|
static |
Definition at line 3210 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getDimSize().
|
static |
Definition at line 3890 of file TosaOps.cpp.
|
static |
Definition at line 2995 of file TosaOps.cpp.
References mlir::ShapeAdaptor::getDims(), mlir::ShapeAdaptor::getRank(), and mlir::ShapeAdaptor::hasRank().
|
static |
Definition at line 1431 of file TosaOps.cpp.
References mlir::ValueShapeRange::getShape().
Referenced by NAryInferReturnTypes().
|
static |
Definition at line 572 of file TosaOps.cpp.
References getStorageElementTypeOrSelf().
|
static |
Definition at line 718 of file TosaOps.cpp.
References mlir::remark::failed(), and idivCheck().
|
static |
Definition at line 677 of file TosaOps.cpp.
|
static |
Definition at line 1520 of file TosaOps.cpp.
References mlir::Operation::emitOpError().
|
static |
Definition at line 1026 of file TosaOps.cpp.
References mlir::remark::failed(), and idivCheck().
|
static |
Definition at line 3045 of file TosaOps.cpp.
References mlir::TensorType::getShape(), and mlir::TensorType::hasRank().
|
static |
Definition at line 532 of file TosaOps.cpp.
References mlir::Operation::emitOpError(), mlir::Type::getIntOrFloatBitWidth(), getStorageElementTypeOrSelf(), and mlir::Value::getType().
|
static |
Definition at line 963 of file TosaOps.cpp.
|
static |
Definition at line 944 of file TosaOps.cpp.
References errorIfTypeOrShapeMismatch(), mlir::remark::failed(), findVariableDecl(), and mlir::tosa::getVariableType().
|
static |
Definition at line 2450 of file TosaOps.cpp.
References mlir::getElementTypeOrSelf(), and mlir::Type::isInteger().
|
static |
Definition at line 2465 of file TosaOps.cpp.
References mlir::getElementTypeOrSelf(), and mlir::Type::isInteger().