MLIR  15.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
mlir::quant::QuantizedType Class Reference

Base class for all quantized types known to this dialect. More...

#include "mlir/Dialect/Quant/QuantTypes.h"

+ Inheritance diagram for mlir::quant::QuantizedType:
+ Collaboration diagram for mlir::quant::QuantizedType:

Public Types

using ImplType = detail::QuantizedTypeStorage
 
- Public Types inherited from mlir::Type
template<typename ConcreteType , typename BaseType , typename StorageType , template< typename T > class... Traits>
using TypeBase = detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
 Utility class for implementing types. More...
 
using ImplType = TypeStorage
 
using AbstractTy = AbstractType
 

Public Member Functions

Type getExpressedType () const
 Gets the original expressed type that this quantized type approximates. More...
 
unsigned getFlags () const
 Gets the flags associated with this type. More...
 
bool isSigned () const
 Whether the storage type should be interpreted as a signed quantity (true) or an unsigned value (false). More...
 
Type getStorageType () const
 Gets the underlying type used for to store values. More...
 
int64_t getStorageTypeMin () const
 The minimum value that storageType can take. More...
 
int64_t getStorageTypeMax () const
 The maximum value that storageType can take. More...
 
unsigned getStorageTypeIntegralWidth () const
 Gets the integral bit width that the underlying storage type can exactly represent. More...
 
bool isCompatibleExpressedType (Type candidateExpressedType)
 Returns whether the candidateExpressedType is a match for this QuantizedType. More...
 
Type castFromStorageType (Type candidateType)
 Casts from a type based on the storageType to a corresponding type based on this type (returns nullptr if the cast is not valid). More...
 
Type castFromExpressedType (Type candidateType)
 Casts from a type based on the expressedType to a corresponding type based on this type (returns nullptr if the cast is not valid). More...
 
Type castExpressedToStorageType (Type candidateType)
 Casts from a type based on the expressedType to the equivalent type based on storageType by way of this QuantizedType. More...
 
- Public Member Functions inherited from mlir::Type
constexpr Type ()
 
 Type (const ImplType *impl)
 
 Type (const Type &other)=default
 
Typeoperator= (const Type &other)=default
 
bool operator== (Type other) const
 
bool operator!= (Type other) const
 
 operator bool () const
 
bool operator! () const
 
template<typename U >
bool isa () const
 
template<typename First , typename Second , typename... Rest>
bool isa () const
 
template<typename U >
dyn_cast () const
 
template<typename U >
dyn_cast_or_null () const
 
template<typename U >
cast () const
 
TypeID getTypeID ()
 Return a unique identifier for the concrete type. More...
 
MLIRContextgetContext () const
 Return the MLIRContext in which this type was uniqued. More...
 
DialectgetDialect () const
 Get the dialect this type is registered to. More...
 
bool isIndex () const
 
bool isBF16 () const
 
bool isF16 () const
 
bool isF32 () const
 
bool isF64 () const
 
bool isF80 () const
 
bool isF128 () const
 
bool isInteger (unsigned width) const
 Return true if this is an integer type with the specified width. More...
 
bool isSignlessInteger () const
 Return true if this is a signless integer type (with the specified width). More...
 
bool isSignlessInteger (unsigned width) const
 
bool isSignedInteger () const
 Return true if this is a signed integer type (with the specified width). More...
 
bool isSignedInteger (unsigned width) const
 
bool isUnsignedInteger () const
 Return true if this is an unsigned integer type (with the specified width). More...
 
bool isUnsignedInteger (unsigned width) const
 
unsigned getIntOrFloatBitWidth () const
 Return the bit width of an integer or a float type, assert failure on other types. More...
 
bool isSignlessIntOrIndex () const
 Return true if this is a signless integer or index type. More...
 
bool isSignlessIntOrIndexOrFloat () const
 Return true if this is a signless integer, index, or float type. More...
 
bool isSignlessIntOrFloat () const
 Return true of this is a signless integer or a float type. More...
 
bool isIntOrIndex () const
 Return true if this is an integer (of any signedness) or an index type. More...
 
bool isIntOrFloat () const
 Return true if this is an integer (of any signedness) or a float type. More...
 
bool isIntOrIndexOrFloat () const
 Return true if this is an integer (of any signedness), index, or float type. More...
 
void print (raw_ostream &os) const
 Print the current type. More...
 
void dump () const
 
const voidgetAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits. More...
 
template<template< typename T > class Trait>
bool hasTrait ()
 Returns true if the type was registered with a particular trait. More...
 
const AbstractTygetAbstractType ()
 Return the abstract type descriptor for this type. More...
 

Static Public Member Functions

static LogicalResult verify (function_ref< InFlightDiagnostic()> emitError, unsigned flags, Type storageType, Type expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
 
static bool classof (Type type)
 Support method to enable LLVM-style type casting. More...
 
static int64_t getDefaultMinimumForInteger (bool isSigned, unsigned integralWidth)
 Gets the minimum possible stored by a storageType. More...
 
static int64_t getDefaultMaximumForInteger (bool isSigned, unsigned integralWidth)
 Gets the maximum possible stored by a storageType. More...
 
static QuantizedType getQuantizedElementType (Type primitiveOrContainerType)
 Returns the element type as a QuantizedType or nullptr if it is not a quantized type. More...
 
static Type castToStorageType (Type quantizedType)
 Casts from a type based on a QuantizedType to a corresponding type based on the storageType (returns nullptr if the cast is not valid). More...
 
static Type castToExpressedType (Type quantizedType)
 Casts from a type based on QuantizedType to a corresponding type based on the expressedType (returns nullptr if the cast is not valid). More...
 
- Static Public Member Functions inherited from mlir::Type
static bool classof (Type)
 
static Type getFromOpaquePointer (const void *pointer)
 

Static Public Attributes

static constexpr unsigned MaxStorageBits = 32
 The maximum number of bits supported for storage types. More...
 

Additional Inherited Members

- Protected Attributes inherited from mlir::Type
ImplTypeimpl {nullptr}
 

Detailed Description

Base class for all quantized types known to this dialect.

All quantized types have:

The base class provides generic support for manipulating the types based on these fields.

Definition at line 52 of file QuantTypes.h.

Member Typedef Documentation

◆ ImplType

Definition at line 54 of file QuantTypes.h.

Member Function Documentation

◆ castExpressedToStorageType()

Type QuantizedType::castExpressedToStorageType ( Type  candidateType)

Casts from a type based on the expressedType to the equivalent type based on storageType by way of this QuantizedType.

Equivalent to: QuantizedType::castToStorageType(castFromExpressedType(candidateType)) (but with validity checks). Example (for this = !quant.uniform<i8:f32, 1.0>): tensor<4xf32> -> tensor<4xi8>

Definition at line 208 of file QuantTypes.cpp.

References castToStorageType().

Referenced by convertDenseFPElementsAttr(), and convertSparseElementsAttr().

◆ castFromExpressedType()

Type QuantizedType::castFromExpressedType ( Type  candidateType)

Casts from a type based on the expressedType to a corresponding type based on this type (returns nullptr if the cast is not valid).

Examples: f32 -> !quant.uniform<i8:f32, 1.0> tensor<4xf32> -> tensor<4x!quant.uniform<i8:f32, 1.0>> vector<4xf32> -> vector<4x!quant.uniform<i8:f32, 1.0>>

Definition at line 153 of file QuantTypes.cpp.

References mlir::Type::cast(), and mlir::Type::isa().

◆ castFromStorageType()

Type QuantizedType::castFromStorageType ( Type  candidateType)

Casts from a type based on the storageType to a corresponding type based on this type (returns nullptr if the cast is not valid).

Examples: i8 -> !quant.uniform<i8:f32, 1.0> tensor<4xi8> -> tensor<4x!quant.uniform<i8:f32, 1.0}>> vector<4xi8> -> vector<4x!quant.uniform<i8:f32, 1.0>>

Definition at line 103 of file QuantTypes.cpp.

References mlir::Type::cast(), and mlir::Type::isa().

◆ castToExpressedType()

Type QuantizedType::castToExpressedType ( Type  quantizedType)
static

Casts from a type based on QuantizedType to a corresponding type based on the expressedType (returns nullptr if the cast is not valid).

This is the inverse of castFromExpressedType.

Definition at line 181 of file QuantTypes.cpp.

References mlir::Type::cast(), and mlir::Type::isa().

Referenced by mlirQuantizedTypeCastToExpressedType().

◆ castToStorageType()

Type QuantizedType::castToStorageType ( Type  quantizedType)
static

Casts from a type based on a QuantizedType to a corresponding type based on the storageType (returns nullptr if the cast is not valid).

This is the inverse of castFromStorageType().

Definition at line 126 of file QuantTypes.cpp.

References mlir::Type::cast(), and mlir::Type::isa().

Referenced by castExpressedToStorageType(), and mlirQuantizedTypeCastToStorageType().

◆ classof()

bool QuantizedType::classof ( Type  type)
static

Support method to enable LLVM-style type casting.

Definition at line 27 of file QuantTypes.cpp.

References mlir::Type::getDialect().

◆ getDefaultMaximumForInteger()

static int64_t mlir::quant::QuantizedType::getDefaultMaximumForInteger ( bool  isSigned,
unsigned  integralWidth 
)
inlinestatic

Gets the maximum possible stored by a storageType.

storageTypeMax must be less than or equal to this value.

Definition at line 80 of file QuantTypes.h.

Referenced by mlirQuantizedTypeGetDefaultMaximumForInteger(), parseStorageRange(), and printStorageType().

◆ getDefaultMinimumForInteger()

static int64_t mlir::quant::QuantizedType::getDefaultMinimumForInteger ( bool  isSigned,
unsigned  integralWidth 
)
inlinestatic

Gets the minimum possible stored by a storageType.

storageTypeMin must be greater than or equal to this value.

Definition at line 70 of file QuantTypes.h.

Referenced by mlirQuantizedTypeGetDefaultMinimumForInteger(), parseStorageRange(), and printStorageType().

◆ getExpressedType()

Type QuantizedType::getExpressedType ( ) const

Gets the original expressed type that this quantized type approximates.

Note that this presumes that the quantized type was always derived from a floating point type, which in the broadest definition, is not true (i.e. it could be some form of integral, fixed type or affine type in its own right); however, at the high level, no examples of such usage are presently known and the restriction serves some useful purposes (such as always being able to reverse a transformation or measure error). In most cases, this will be f32.

Definition at line 81 of file QuantTypes.cpp.

Referenced by mlir::quant::ExpressedToQuantizedConverter::convert().

◆ getFlags()

unsigned QuantizedType::getFlags ( ) const

Gets the flags associated with this type.

Typically a more specific accessor is appropriate.

Definition at line 23 of file QuantTypes.cpp.

◆ getQuantizedElementType()

QuantizedType QuantizedType::getQuantizedElementType ( Type  primitiveOrContainerType)
static

Returns the element type as a QuantizedType or nullptr if it is not a quantized type.

If the type is primitive, returns that. If it is a container (vector/tensor), return the element type. Examples: !quant.uniform<i8:f32, 1.0> -> !quant.uniform<i8:f32, 1.0> tensor<4x!quant.uniform<i8:f32, 1.0> -> quant.uniform<i8:f32, 1.0>

Definition at line 94 of file QuantTypes.cpp.

References mlir::Type::cast(), mlir::Type::dyn_cast(), getElementType(), and mlir::Type::isa().

Referenced by mlirQuantizedTypeGetQuantizedElementType().

◆ getStorageType()

Type QuantizedType::getStorageType ( ) const

Gets the underlying type used for to store values.

Note that this may be signed or unsigned. Use the isSigned() accessor to differentiate.

Definition at line 63 of file QuantTypes.cpp.

Referenced by convertPrimitiveValueAttr().

◆ getStorageTypeIntegralWidth()

unsigned QuantizedType::getStorageTypeIntegralWidth ( ) const

Gets the integral bit width that the underlying storage type can exactly represent.

For integral storage types, this will just be their width.

Definition at line 75 of file QuantTypes.cpp.

Referenced by printStorageType().

◆ getStorageTypeMax()

int64_t QuantizedType::getStorageTypeMax ( ) const

The maximum value that storageType can take.

Definition at line 71 of file QuantTypes.cpp.

Referenced by printStorageType().

◆ getStorageTypeMin()

int64_t QuantizedType::getStorageTypeMin ( ) const

The minimum value that storageType can take.

Definition at line 67 of file QuantTypes.cpp.

Referenced by printStorageType().

◆ isCompatibleExpressedType()

bool QuantizedType::isCompatibleExpressedType ( Type  candidateExpressedType)

Returns whether the candidateExpressedType is a match for this QuantizedType.

This will be true if the candidate type is either a primitive type or a container type whose element type equals this QuantizedType's expressed type. Examples of compatible candidateExpressedType: !quant.uniform<i8:f32, 1.0> =~ f32 !quant.uniform<i8:f32, 1.0> =~ tensor<4xf32>

Definition at line 85 of file QuantTypes.cpp.

References mlir::Type::cast(), getElementType(), and mlir::Type::isa().

◆ isSigned()

bool mlir::quant::QuantizedType::isSigned ( ) const
inline

Whether the storage type should be interpreted as a signed quantity (true) or an unsigned value (false).

Definition at line 105 of file QuantTypes.h.

References mlir::Type::isBF16(), mlir::Type::isF16(), mlir::Type::isF32(), mlir::Type::isF64(), mlir::Type::isIndex(), mlir::Type::isInteger(), and mlir::quant::QuantizationFlags::Signed.

Referenced by printStorageType().

◆ verify()

LogicalResult QuantizedType::verify ( function_ref< InFlightDiagnostic()>  emitError,
unsigned  flags,
Type  storageType,
Type  expressedType,
int64_t  storageTypeMin,
int64_t  storageTypeMax 
)
static

Member Data Documentation

◆ MaxStorageBits

constexpr unsigned mlir::quant::QuantizedType::MaxStorageBits = 32
static

The maximum number of bits supported for storage types.

Definition at line 58 of file QuantTypes.h.

Referenced by parseStorageType().


The documentation for this class was generated from the following files: