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);
203 detail::AnyQuantizedTypeStorage> {
206 using Base::getChecked;
208 static constexpr StringLiteral
name =
"quant.any";
213 Type expressedType, int64_t storageTypeMin,
214 int64_t storageTypeMax);
220 Type storageType,
Type expressedType, int64_t storageTypeMin,
221 int64_t storageTypeMax);
226 Type storageType,
Type expressedType, int64_t storageTypeMin,
227 int64_t storageTypeMax);
264 detail::UniformQuantizedTypeStorage> {
267 using Base::getChecked;
269 static constexpr StringLiteral
name =
"quant.uniform";
274 Type expressedType,
double scale,
275 int64_t zeroPoint, int64_t storageTypeMin,
276 int64_t storageTypeMax);
282 Type storageType,
Type expressedType,
double scale,
283 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
288 Type storageType,
Type expressedType,
double scale,
289 int64_t zeroPoint, int64_t storageTypeMin,
290 int64_t storageTypeMax);
323 :
public Type::TypeBase<UniformQuantizedPerAxisType, QuantizedType,
324 detail::UniformQuantizedPerAxisTypeStorage> {
327 using Base::getChecked;
329 static constexpr StringLiteral
name =
"quant.uniform_per_axis";
334 get(
unsigned flags,
Type storageType,
Type expressedType,
336 int32_t quantizedDimension, int64_t storageTypeMin,
337 int64_t storageTypeMax);
345 int64_t storageTypeMin, int64_t storageTypeMax);
350 Type storageType,
Type expressedType,
352 int32_t quantizedDimension, int64_t storageTypeMin,
353 int64_t storageTypeMax);
408 :
public Type::TypeBase<UniformQuantizedSubChannelType, QuantizedType,
409 detail::UniformQuantizedSubChannelTypeStorage> {
412 using Base::getChecked;
414 static constexpr StringLiteral
name =
"quant.uniform_sub_channel";
419 get(
unsigned flags,
Type storageType,
Type expressedType,
422 int64_t storageTypeMin, int64_t storageTypeMax);
432 int64_t storageTypeMax);
437 Type storageType,
Type expressedType,
441 int64_t storageTypeMax);
524 detail::CalibratedQuantizedTypeStorage> {
527 using Base::getChecked;
529 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.