My Project
Namespaces | Classes | Functions
mlir::quant Namespace Reference

Namespaces

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

Classes

class  AnyQuantizedType
 
struct  ExpressedToQuantizedConverter
 
class  QuantizationDialect
 Defines the 'Quantization' dialect. More...
 
class  QuantizedType
 
class  UniformQuantizedPerAxisType
 
class  UniformQuantizedPerAxisValueConverter
 
class  UniformQuantizedType
 
class  UniformQuantizedValueConverter
 

Functions

UniformQuantizedType fakeQuantAttrsToType (Location loc, unsigned numBits, double rmin, double rmax, bool narrowRange, Type expressedType, bool isSigned=false)
 
UniformQuantizedPerAxisType fakeQuantAttrsToType (Location loc, unsigned numBits, int32_t quantizedDimension, ArrayRef< double > rmins, ArrayRef< double > rmax, bool narrowRange, Type expressedType, bool isSigned=false)
 
std::unique_ptr< OpPassBase< FuncOp > > createConvertSimulatedQuantPass ()
 
std::unique_ptr< OpPassBase< FuncOp > > createConvertConstPass ()
 
Attribute quantizeAttr (Attribute realValue, QuantizedType quantizedElementType, Type &outConvertedType)
 
Attribute quantizeAttrUniform (Attribute realValue, UniformQuantizedType quantizedElementType, const UniformQuantizedValueConverter &converter, Type &outConvertedType)
 

Function Documentation

◆ createConvertConstPass()

std::unique_ptr< OpPassBase< 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.

◆ createConvertSimulatedQuantPass()

std::unique_ptr< OpPassBase< 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.

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

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

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

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.

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

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