9#ifndef MLIR_DIALECT_QUANT_IR_QUANTTYPES_H
10#define MLIR_DIALECT_QUANT_IR_QUANTTYPES_H
18#include "llvm/Support/MathExtras.h"
70 unsigned integralWidth) {
72 return llvm::minIntN(integralWidth);
80 unsigned integralWidth) {
82 return llvm::maxIntN(integralWidth);
84 return llvm::maxUIntN(integralWidth);
204 detail::AnyQuantizedTypeStorage> {
209 static constexpr StringLiteral
name =
"quant.any";
265 detail::UniformQuantizedTypeStorage> {
270 static constexpr StringLiteral
name =
"quant.uniform";
275 Type expressedType,
double scale,
283 Type storageType,
Type expressedType,
double scale,
289 Type storageType,
Type expressedType,
double scale,
324 :
public Type::TypeBase<UniformQuantizedPerAxisType, QuantizedType,
325 detail::UniformQuantizedPerAxisTypeStorage> {
330 static constexpr StringLiteral
name =
"quant.uniform_per_axis";
335 get(
unsigned flags,
Type storageType,
Type expressedType,
337 int32_t quantizedDimension,
int64_t storageTypeMin,
351 Type storageType,
Type expressedType,
353 int32_t quantizedDimension,
int64_t storageTypeMin,
409 :
public Type::TypeBase<UniformQuantizedSubChannelType, QuantizedType,
410 detail::UniformQuantizedSubChannelTypeStorage> {
415 static constexpr StringLiteral
name =
"quant.uniform_sub_channel";
420 get(
unsigned flags,
Type storageType,
Type expressedType,
438 Type storageType,
Type expressedType,
525 detail::CalibratedQuantizedTypeStorage> {
530 static constexpr StringLiteral
name =
"quant.calibrated";
591 detail::QuantileTypeStorage,
592 mlir::QuantStorageTypeInterface::Trait> {
617 std::optional<int64_t> storageMin = std::nullopt,
618 std::optional<int64_t> storageMax = std::nullopt);
624 std::optional<int64_t> storageMin = std::nullopt,
625 std::optional<int64_t> storageMax = std::nullopt);
630 std::optional<int64_t> storageMin, std::optional<int64_t> storageMax);
638 static constexpr llvm::StringLiteral
getMnemonic() {
return {
"quantile"}; }
640 static constexpr llvm::StringLiteral
name =
"quantile";
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
This base class exposes generic asm printer hooks, usable across the various derived printers.
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.
MLIRContext is the top-level object for a collection of MLIR operations.
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).
detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... > TypeBase
Utility class for implementing types.
StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... > Base
static ConcreteType getChecked(const Location &loc, Args &&...args)
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.
unsigned getLogicalBitWidth() const
static QuantileType getChecked(function_ref< InFlightDiagnostic()> emitError, mlir::MLIRContext *ctx, Type storageType, Type quantileType, ArrayRef< double > quantiles, std::optional< int64_t > storageMin=std::nullopt, std::optional< int64_t > storageMax=std::nullopt)
static bool classof(mlir::Type type)
Methods for support type inquiry through isa, cast, and dyn_cast.
unsigned getStorageWidth() const
std::optional< int64_t > getStorageMin() const
Return the explicit storage minimum, if set.
int64_t getDefaultMinimum(bool isSigned) const
unsigned getElementsPerByte() const
static constexpr llvm::StringLiteral name
std::string getStorageTypeName(bool isSigned) const
detail::QuantileTypeStorage ImplType
bool shouldDefaultToSigned() const
Type getQuantileType() const
int64_t getDefaultMaximum(bool isSigned) const
static QuantileType get(mlir::MLIRContext *ctx, Type storageType, Type quantileType, ArrayRef< double > quantiles={}, std::optional< int64_t > storageMin=std::nullopt, std::optional< int64_t > storageMax=std::nullopt)
ArrayRef< double > getQuantiles() const
Return the quantile table of this float type.
std::optional< unsigned > getPreferredAlignmentBytes() const
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, Type storageType, Type quantileType, ArrayRef< double > quantiles, std::optional< int64_t > storageMin, std::optional< int64_t > storageMax)
std::optional< int64_t > getStorageMax() const
Return the explicit storage maximum, if set.
Type getStorageType() const
static constexpr llvm::StringLiteral getMnemonic()
void print(mlir::AsmPrinter &printer) const
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...
detail::QuantizedTypeStorage ImplType
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)
Enumeration of bit-mapped flags related to quantized types.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::function_ref< Fn > function_ref