9 #ifndef MLIR_DIALECT_QUANTOPS_QUANT_TYPES_H_ 10 #define MLIR_DIALECT_QUANTOPS_QUANT_TYPES_H_ 18 #include "llvm/Support/MathExtras.h" 23 class QuantizedIntegerType;
27 struct QuantizedTypeStorage;
28 struct AnyQuantizedTypeStorage;
29 struct UniformQuantizedTypeStorage;
30 struct UniformQuantizedPerAxisTypeStorage;
34 namespace QuantizationTypes {
36 Any = Type::FIRST_QUANTIZATION_TYPE,
44 namespace QuantizationFlags {
66 static constexpr
unsigned MaxStorageBits = 32;
70 unsigned flags,
Type storageType,
71 Type expressedType, int64_t storageTypeMin,
72 int64_t storageTypeMax);
76 return type.
getKind() >= Type::FIRST_QUANTIZATION_TYPE &&
83 unsigned integralWidth) {
85 return llvm::minIntN(integralWidth);
93 unsigned integralWidth) {
95 return llvm::maxIntN(integralWidth);
97 return llvm::maxUIntN(integralWidth);
108 Type getExpressedType()
const;
112 unsigned getFlags()
const;
124 Type getStorageType()
const;
127 int64_t getStorageTypeMin()
const;
130 int64_t getStorageTypeMax()
const;
134 unsigned getStorageTypeIntegralWidth()
const;
143 bool isCompatibleExpressedType(
Type candidateExpressedType);
159 Type castFromStorageType(
Type candidateType);
164 static Type castToStorageType(
Type quantizedType);
172 Type castFromExpressedType(
Type candidateType);
177 static Type castToExpressedType(
Type quantizedType);
185 Type castExpressedToStorageType(
Type candidateType);
211 detail::AnyQuantizedTypeStorage> {
221 Type expressedType, int64_t storageTypeMin,
222 int64_t storageTypeMax);
227 Type expressedType, int64_t storageTypeMin,
228 int64_t storageTypeMax,
Location location);
233 unsigned flags,
Type storageType,
234 Type expressedType, int64_t storageTypeMin,
235 int64_t storageTypeMax);
272 detail::UniformQuantizedTypeStorage> {
279 Type expressedType,
double scale,
280 int64_t zeroPoint, int64_t storageTypeMin,
281 int64_t storageTypeMax);
286 getChecked(
unsigned flags,
Type storageType,
Type expressedType,
double scale,
287 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax,
293 Type storageType,
Type expressedType,
double scale, int64_t zeroPoint,
294 int64_t storageTypeMin, int64_t storageTypeMax);
303 double getScale()
const;
307 int64_t getZeroPoint()
const;
314 bool isFixedPoint()
const {
return isSigned() && getZeroPoint() == 0; }
332 :
public Type::TypeBase<UniformQuantizedPerAxisType, QuantizedType,
333 detail::UniformQuantizedPerAxisTypeStorage> {
340 get(
unsigned flags,
Type storageType,
Type expressedType,
342 int32_t quantizedDimension, int64_t storageTypeMin,
343 int64_t storageTypeMax);
348 getChecked(
unsigned flags,
Type storageType,
Type expressedType,
350 int32_t quantizedDimension, int64_t storageTypeMin,
351 int64_t storageTypeMax,
Location location);
358 int64_t storageTypeMin, int64_t storageTypeMax);
384 int32_t getQuantizedDimension()
const;
394 return llvm::all_of(getZeroPoints(),
395 [](int64_t zeroPoint) {
return zeroPoint != 0; });
402 #endif // MLIR_DIALECT_QUANTOPS_QUANT_TYPES_H_ Definition: InferTypeOpInterface.cpp:20
FlagValue
Definition: QuantTypes.h:45
Definition: TypeDetail.h:23
static int64_t getDefaultMinimumForInteger(bool isSigned, unsigned integralWidth)
Definition: QuantTypes.h:82
Definition: QuantTypes.h:36
Definition: Location.h:52
bool isIndex()
Definition: StandardTypes.cpp:30
Definition: QuantTypes.h:39
Definition: LogicalResult.h:18
unsigned getKind() const
Return the classification for this type.
Definition: Types.cpp:22
Definition: QuantTypes.h:48
bool isF32()
Definition: StandardTypes.cpp:27
Definition: QuantTypes.h:209
bool isBF16()
Definition: StandardTypes.cpp:25
Type()
Definition: Types.h:111
Definition: QuantTypes.h:38
Definition: QuantTypes.h:37
bool isSigned() const
Definition: QuantTypes.h:117
Kind
Definition: QuantTypes.h:35
static bool classof(Type type)
Support method to enable LLVM-style type casting.
Definition: QuantTypes.h:75
Definition: QuantTypes.h:60
Definition: StorageUniquerSupport.h:30
Definition: MLIRContext.h:34
bool isInteger(unsigned width)
Return true if this is an integer type with the specified width.
Definition: StandardTypes.cpp:33
bool isF16()
Definition: StandardTypes.cpp:26
bool isF64()
Definition: StandardTypes.cpp:28
static bool kindof(unsigned kind)
Support method to enable LLVM-style type casting.
Definition: QuantTypes.h:216
static int64_t getDefaultMaximumForInteger(bool isSigned, unsigned integralWidth)
Definition: QuantTypes.h:92