MLIR  15.0.0git
Namespaces | Classes | Functions
mlir::quant Namespace Reference

Namespaces

 detail
 
 QuantizationFlags
 Enumeration of bit-mapped flags related to quantized types.
 

Classes

class  AnyQuantizedType
 A quantized type that maps storage to/from expressed types in an unspecified way. More...
 
class  CalibratedQuantizedType
 A quantized type that infers its range from given min/max values. More...
 
struct  ExpressedToQuantizedConverter
 Performs type conversion from an arbitrary input type to a type that is expressed by a QuantizedType. More...
 
class  QuantizedType
 Base class for all quantized types known to this dialect. More...
 
class  UniformQuantizedPerAxisType
 Represents per-axis (also known as per-channel quantization). More...
 
class  UniformQuantizedPerAxisValueConverter
 An utility class to quantize an attribute by the per-axis quantization parameters. More...
 
class  UniformQuantizedType
 Represents a family of uniform, quantized types. More...
 
class  UniformQuantizedValueConverter
 Reference implementation of converting between real numbers and values represented by a UniformQuantizedType. More...
 

Functions

UniformQuantizedType fakeQuantAttrsToType (Location loc, unsigned numBits, double rmin, double rmax, bool narrowRange, Type expressedType, bool isSigned=false)
 Converts per-layer FakeQuant attributes to the corresponding type. More...
 
UniformQuantizedPerAxisType fakeQuantAttrsToType (Location loc, unsigned numBits, int32_t quantizedDimension, ArrayRef< double > rmins, ArrayRef< double > rmax, bool narrowRange, Type expressedType, bool isSigned=false)
 Converts per-channel FakeQuant attributes to the corresponding type. More...
 
std::unique_ptr< OperationPass< func::FuncOp > > createConvertSimulatedQuantPass ()
 Creates a pass that converts quantization simulation operations (i.e. More...
 
std::unique_ptr< OperationPass< func::FuncOp > > createConvertConstPass ()
 Creates a pass that converts constants followed by a qbarrier to a constant whose value is quantized. More...
 
Attribute quantizeAttr (Attribute realValue, QuantizedType quantizedElementType, Type &outConvertedType)
 Converts an attribute from a type based on quantizedElementType.getExpressedType() to one based on quantizedElementType.getStorageType(), where quantizedElementType is as from QuantizedType::getQuantizedElementType(). More...
 
Attribute quantizeAttrUniform (Attribute realValue, UniformQuantizedType quantizedElementType, const UniformQuantizedValueConverter &converter, Type &outConvertedType)
 Converts an attribute from a type based on quantizedElementType.getExpressedType() to one based on quantizedElementType.getStorageType(), where quantizedElementType is as from QuantizedType::getQuantizedElementType() and casted to an UniformQuantizedType. More...
 

Function Documentation

◆ createConvertConstPass()

std::unique_ptr< OperationPass< func::FuncOp > > mlir::quant::createConvertConstPass ( )

Creates a pass that converts constants followed by a qbarrier to a constant whose value is quantized.

This is typically one of the last passes done when lowering to express actual quantized arithmetic in a low level representation. Because it modifies the constant, it is destructive and cannot be undone.

Definition at line 102 of file ConvertConst.cpp.

◆ createConvertSimulatedQuantPass()

std::unique_ptr< OperationPass< func::FuncOp > > mlir::quant::createConvertSimulatedQuantPass ( )

Creates a pass that converts quantization simulation operations (i.e.

FakeQuant and those like it) to casts into/out of supported QuantizedTypes.

Definition at line 138 of file ConvertSimQuant.cpp.

◆ fakeQuantAttrsToType() [1/2]

UniformQuantizedType mlir::quant::fakeQuantAttrsToType ( Location  loc,
unsigned  numBits,
double  rmin,
double  rmax,
bool  narrowRange,
Type  expressedType,
bool  isSigned = false 
)

Converts per-layer FakeQuant attributes to the corresponding type.

In the event that the parameters cannot be converted, returns a nullptr convertible Type and issues an appropriate error. Note that there are multiple variants of a per-layer FakeQuant op, so this function takes the attributes discretely vs taking a reference to the originating op.

Definition at line 108 of file FakeQuantSupport.cpp.

References mlir::emitError(), mlir::quant::UniformQuantizedType::getChecked(), mlir::Type::getContext(), getDefaultStorageParams(), getNudgedScaleAndZeroPoint(), and mlir::quant::QuantizationFlags::Signed.

Referenced by mlir::tosa::buildQTypeFromMinMax().

◆ fakeQuantAttrsToType() [2/2]

UniformQuantizedPerAxisType mlir::quant::fakeQuantAttrsToType ( Location  loc,
unsigned  numBits,
int32_t  quantizedDimension,
ArrayRef< double >  rmins,
ArrayRef< double >  rmax,
bool  narrowRange,
Type  expressedType,
bool  isSigned = false 
)

Converts per-channel FakeQuant attributes to the corresponding type.

In the event that the parameters cannot be converted, returns a nullptr convertible Type and issues an appropriate error.

Definition at line 139 of file FakeQuantSupport.cpp.

References mlir::emitError(), mlir::quant::UniformQuantizedPerAxisType::getChecked(), mlir::Type::getContext(), getDefaultStorageParams(), getNudgedScaleAndZeroPoint(), and mlir::quant::QuantizationFlags::Signed.

◆ quantizeAttr()

Attribute mlir::quant::quantizeAttr ( Attribute  realValue,
QuantizedType  quantizedElementType,
Type outConvertedType 
)

Converts an attribute from a type based on quantizedElementType.getExpressedType() to one based on quantizedElementType.getStorageType(), where quantizedElementType is as from QuantizedType::getQuantizedElementType().

Convert an attribute from a type based on quantizedElementType.getExpressedType() to one based on quantizedElementType.getStorageType().

Returns nullptr if the conversion is not supported. On success, stores the converted type in outConvertedType.

Examples:

  1. realValue is a primitive value attribute: (realValue: FloatAttr, quantizedElementType: UniformQuantizedType[i8:f32]) -> (IntegerAttr, outConvertedType: i8)
  2. realValue is an elements attribute: (realValue: DenseElementsAttr[tensor<2x2xf32>], quantizedElementType: UniformQuantizedType[i8:f32]) -> (DenseElementsAttr[tensor<2x2xi8>], outConvertedType: tensor<2x2xi8>)

Returns nullptr if the conversion is not supported. On success, stores the converted type in outConvertedType.

Definition at line 127 of file QuantizeUtils.cpp.

References mlir::quant::UniformQuantizedPerAxisValueConverter::convert(), mlir::Type::dyn_cast(), and quantizeAttrUniform().

◆ quantizeAttrUniform()

Attribute mlir::quant::quantizeAttrUniform ( Attribute  realValue,
UniformQuantizedType  quantizedElementType,
const UniformQuantizedValueConverter converter,
Type outConvertedType 
)

Converts an attribute from a type based on quantizedElementType.getExpressedType() to one based on quantizedElementType.getStorageType(), where quantizedElementType is as from QuantizedType::getQuantizedElementType() and casted to an UniformQuantizedType.

Converts a real expressed Attribute to a corresponding Attribute containing quantized storage values assuming the given uniform quantizedElementType and converter.

Returns nullptr if the conversion is not supported. On success, stores the converted type in outConvertedType.

Examples:

  1. realValue is a primitive value attribute: (realValue: FloatAttr, quantizedElementType: UniformQuantizedType[i8:f32]) -> (IntegerAttr, outConvertedType: i8)
  2. realValue is an elements attribute: (realValue: DenseElementsAttr[tensor<2x2xf32>], quantizedElementType: UniformQuantizedType[i8:f32]) -> (DenseElementsAttr[tensor<2x2xi8>], outConvertedType: tensor<2x2xi8>)

Definition at line 99 of file QuantizeUtils.cpp.

References mlir::Attribute::cast(), convertDenseFPElementsAttr(), convertPrimitiveValueAttr(), convertSparseElementsAttr(), and mlir::Attribute::isa().

Referenced by quantizeAttr().