9 #ifndef MLIR_DIALECT_QUANT_IR_QUANTTYPES_H
10 #define MLIR_DIALECT_QUANT_IR_QUANTTYPES_H
18 #include "llvm/Support/MathExtras.h"
34 namespace QuantizationFlags {
60 Type storageType,
Type expressedType, int64_t storageTypeMin,
61 int64_t storageTypeMax);
69 unsigned integralWidth) {
71 return llvm::minIntN(integralWidth);
79 unsigned integralWidth) {
81 return llvm::maxIntN(integralWidth);
83 return llvm::maxUIntN(integralWidth);
201 detail::AnyQuantizedTypeStorage> {
204 using Base::getChecked;
206 static constexpr StringLiteral
name =
"quant.any";
211 Type expressedType, int64_t storageTypeMin,
212 int64_t storageTypeMax);
218 Type storageType,
Type expressedType, int64_t storageTypeMin,
219 int64_t storageTypeMax);
224 Type storageType,
Type expressedType, int64_t storageTypeMin,
225 int64_t storageTypeMax);
262 detail::UniformQuantizedTypeStorage> {
265 using Base::getChecked;
267 static constexpr StringLiteral
name =
"quant.uniform";
272 Type expressedType,
double scale,
273 int64_t zeroPoint, int64_t storageTypeMin,
274 int64_t storageTypeMax);
280 Type storageType,
Type expressedType,
double scale,
281 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
286 Type storageType,
Type expressedType,
double scale,
287 int64_t zeroPoint, int64_t storageTypeMin,
288 int64_t storageTypeMax);
321 :
public Type::TypeBase<UniformQuantizedPerAxisType, QuantizedType,
322 detail::UniformQuantizedPerAxisTypeStorage> {
325 using Base::getChecked;
327 static constexpr StringLiteral
name =
"quant.uniform_per_axis";
332 get(
unsigned flags,
Type storageType,
Type expressedType,
334 int32_t quantizedDimension, int64_t storageTypeMin,
335 int64_t storageTypeMax);
343 int64_t storageTypeMin, int64_t storageTypeMax);
348 Type storageType,
Type expressedType,
350 int32_t quantizedDimension, int64_t storageTypeMin,
351 int64_t storageTypeMax);
406 :
public Type::TypeBase<UniformQuantizedSubChannelType, QuantizedType,
407 detail::UniformQuantizedSubChannelTypeStorage> {
410 using Base::getChecked;
412 static constexpr StringLiteral
name =
"quant.uniform_sub_channel";
417 get(
unsigned flags,
Type storageType,
Type expressedType,
420 int64_t storageTypeMin, int64_t storageTypeMax);
430 int64_t storageTypeMax);
435 Type storageType,
Type expressedType,
439 int64_t storageTypeMax);
522 detail::CalibratedQuantizedTypeStorage> {
525 using Base::getChecked;
527 static constexpr StringLiteral
name =
"quant.calibrated";
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
An attribute that represents a reference to a dense vector or tensor object.
This class represents a diagnostic that is inflight and set to be reported.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isInteger() const
Return true if this is an integer type (with the specified width).
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
A quantized type that maps storage to/from expressed types in an unspecified way.
static AnyQuantizedType get(unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Gets an instance of the type with all parameters specified but not checked.
static constexpr StringLiteral name
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Verifies construction invariants and issues errors/warnings.
static AnyQuantizedType getChecked(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Gets an instance of the type with all specified parameters checked.
A quantized type that infers its range from given min/max values.
static constexpr StringLiteral name
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type expressedType, double min, double max)
Verifies construction invariants and issues errors/warnings.
static CalibratedQuantizedType get(Type expressedType, double min, double max)
Gets an instance of the type with all parameters specified but not checked.
static CalibratedQuantizedType getChecked(function_ref< InFlightDiagnostic()> emitError, Type expressedType, double min, double max)
Gets an instance of the type with all specified parameters checked.
Base class for all quantized types known to this dialect.
Type getExpressedType() const
Gets the original expressed type that this quantized type approximates.
static constexpr unsigned MaxStorageBits
The maximum number of bits supported for storage types.
bool hasStorageTypeBounds() const
Return whether the storage type has explicit min or max boundaries different from the minimum and max...
static Type castToStorageType(Type quantizedType)
Casts from a type based on a QuantizedType to a corresponding type based on the storageType (returns ...
Type castExpressedToStorageType(Type candidateType)
Casts from a type based on the expressedType to the equivalent type based on storageType by way of th...
static Type castToExpressedType(Type quantizedType)
Casts from a type based on QuantizedType to a corresponding type based on the expressedType (returns ...
bool isSigned() const
Whether the storage type should be interpreted as a signed quantity (true) or an unsigned value (fals...
static QuantizedType getQuantizedElementType(Type primitiveOrContainerType)
Returns the element type as a QuantizedType or nullptr if it is not a quantized type.
unsigned getFlags() const
Gets the flags associated with this type.
int64_t getStorageTypeMax() const
The maximum value that storageType can take.
static int64_t getDefaultMaximumForInteger(bool isSigned, unsigned integralWidth)
Gets the maximum possible stored by a storageType.
unsigned getStorageTypeIntegralWidth() const
Gets the integral bit width that the underlying storage type can exactly represent.
static bool classof(Type type)
Support method to enable LLVM-style type casting.
Type castFromStorageType(Type candidateType)
Casts from a type based on the storageType to a corresponding type based on this type (returns nullpt...
int64_t getStorageTypeMin() const
The minimum value that storageType can take.
static int64_t getDefaultMinimumForInteger(bool isSigned, unsigned integralWidth)
Gets the minimum possible stored by a storageType.
Type getStorageType() const
Gets the underlying type used for to store values.
Type castFromExpressedType(Type candidateType)
Casts from a type based on the expressedType to a corresponding type based on this type (returns null...
bool isCompatibleExpressedType(Type candidateExpressedType)
Returns whether the candidateExpressedType is a match for this QuantizedType.
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.