MLIR  19.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:

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...
 
constexpr Type ()=default
 
 Type (const ImplType *impl)
 
 Type (const Type &other)=default
 
- Public Member Functions inherited from mlir::Type
constexpr Type ()=default
 
 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... Tys>
bool isa () const
 
template<typename... Tys>
bool isa_and_nonnull () 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 isFloat8E5M2 () const
 
bool isFloat8E4M3FN () const
 
bool isFloat8E5M2FNUZ () const
 
bool isFloat8E4M3FNUZ () const
 
bool isFloat8E4M3B11FNUZ () const
 
bool isBF16 () const
 
bool isF16 () const
 
bool isTF32 () const
 
bool isF32 () const
 
bool isF64 () const
 
bool isF80 () const
 
bool isF128 () const
 
bool isInteger () const
 Return true if this is an integer type (with the specified width). More...
 
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 print (raw_ostream &os, AsmState &state) const
 
void dump () const
 
const void * getAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits. More...
 
template<typename InterfaceT >
bool hasPromiseOrImplementsInterface ()
 Returns true if InterfaceT has been promised by the dialect or implemented. More...
 
template<template< typename T > class Trait>
bool hasTrait ()
 Returns true if the type was registered with a particular trait. More...
 
const AbstractTygetAbstractType () const
 Return the abstract type descriptor for this type. More...
 
ImplTypegetImpl () const
 Return the Type implementation. More...
 
void walkImmediateSubElements (function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
 Walk all of the immediately nested sub-attributes and sub-types. More...
 
auto replaceImmediateSubElements (ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
 Replace the immediately nested sub-attributes and sub-types with those provided. More...
 
template<WalkOrder Order = WalkOrder::PostOrder, typename... WalkFns>
auto walk (WalkFns &&...walkFns)
 Walk this type and all attibutes/types nested within using the provided walk functions. More...
 
template<typename... ReplacementFns>
auto replace (ReplacementFns &&...replacementFns)
 Recursively replace all of the nested sub-attributes and sub-types using the provided map functions. 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 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 49 of file QuantTypes.h.

Member Typedef Documentation

◆ ImplType

Definition at line 51 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 209 of file QuantTypes.cpp.

References castToStorageType().

◆ 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 154 of file QuantTypes.cpp.

References mlir::get().

◆ 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::get(), and getShape().

◆ 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 182 of file QuantTypes.cpp.

References mlir::get().

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 127 of file QuantTypes.cpp.

References mlir::get().

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 77 of file QuantTypes.h.

References isSigned().

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 67 of file QuantTypes.h.

References isSigned().

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.

Referenced by isSigned().

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

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.

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

◆ 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 102 of file QuantTypes.h.

References getFlags(), and mlir::quant::QuantizationFlags::Signed.

Referenced by getDefaultMaximumForInteger(), getDefaultMinimumForInteger(), and printStorageType().

◆ Type() [1/3]

constexpr mlir::Type::Type
constexprdefault

◆ Type() [2/3]

mlir::Type::Type
inline

Definition at line 87 of file Types.h.

◆ Type() [3/3]

mlir::Type::Type
default

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

The maximum number of bits supported for storage types.

Definition at line 55 of file QuantTypes.h.

Referenced by parseStorageType().


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