My Project
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
mlir::quant::QuantizedType Class Reference

#include <QuantTypes.h>

Inheritance diagram for mlir::quant::QuantizedType:
Inheritance graph
[legend]
Collaboration diagram for mlir::quant::QuantizedType:
Collaboration graph
[legend]

Public Types

using ImplType = detail::QuantizedTypeStorage
 
- Public Types inherited from mlir::Type
enum  Kind {
  Function, Opaque, LAST_BUILTIN_TYPE = Opaque, DEFINE_SYM_KIND_RANGE,
  DEFINE_SYM_KIND_RANGE
}
 
template<typename ConcreteType , typename BaseType , typename StorageType = DefaultTypeStorage>
using TypeBase = detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer >
 Utility class for implementing types. More...
 
using ImplType = TypeStorage
 

Public Member Functions

Type getExpressedType () const
 
unsigned getFlags () const
 
bool isSigned () const
 
Type getStorageType () const
 
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
 
bool isCompatibleExpressedType (Type candidateExpressedType)
 
Type castFromStorageType (Type candidateType)
 
Type castFromExpressedType (Type candidateType)
 
Type castExpressedToStorageType (Type candidateType)
 
- Public Member Functions inherited from mlir::Type
 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 U >
dyn_cast () const
 
template<typename U >
dyn_cast_or_null () const
 
template<typename U >
cast () const
 
unsigned getKind () const
 Return the classification for this type. More...
 
MLIRContextgetContext () const
 Return the LLVMContext in which this type was uniqued. More...
 
DialectgetDialect () const
 Get the dialect this type is registered to. More...
 
bool isIndex ()
 
bool isBF16 ()
 
bool isF16 ()
 
bool isF32 ()
 
bool isF64 ()
 
bool isInteger (unsigned width)
 Return true if this is an integer type with the specified width. More...
 
unsigned getIntOrFloatBitWidth ()
 
bool isIntOrIndex ()
 Return true if this is an integer or index type. More...
 
bool isIntOrIndexOrFloat ()
 Return true if this is an integer, index, or float type. More...
 
bool isIntOrFloat ()
 Return true of this is an integer or a float type. More...
 
void print (raw_ostream &os)
 Print the current type. More...
 
void dump ()
 
unsigned getSubclassData () const
 
void setSubclassData (unsigned val)
 
const void * getAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits. More...
 

Static Public Member Functions

static LogicalResult verifyConstructionInvariants (Optional< Location > loc, MLIRContext *context, 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)
 
static int64_t getDefaultMaximumForInteger (bool isSigned, unsigned integralWidth)
 
static QuantizedType getQuantizedElementType (Type primitiveOrContainerType)
 
static Type castToStorageType (Type quantizedType)
 
static Type castToExpressedType (Type quantizedType)
 
- 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
 

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.

Member Typedef Documentation

◆ ImplType

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>

◆ 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>>

◆ 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>>

◆ 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.

◆ 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().

◆ classof()

static bool mlir::quant::QuantizedType::classof ( Type  type)
inlinestatic

Support method to enable LLVM-style type casting.

◆ 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.

◆ 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.

◆ 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.

◆ getFlags()

unsigned QuantizedType::getFlags ( ) const

Gets the flags associated with this type. Typically a more specific accessor is appropriate.

◆ 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>

◆ 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.

◆ 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.

◆ getStorageTypeMax()

int64_t QuantizedType::getStorageTypeMax ( ) const

The maximum value that storageType can take.

◆ getStorageTypeMin()

int64_t QuantizedType::getStorageTypeMin ( ) const

The minimum value that storageType can take.

◆ 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>

◆ 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).

◆ verifyConstructionInvariants()

LogicalResult QuantizedType::verifyConstructionInvariants ( Optional< Location loc,
MLIRContext context,
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.


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