|
MLIR
22.0.0git
|
#include "mlir/Dialect/Quant/IR/Quant.h"#include "mlir/Dialect/Quant/IR/QuantTypes.h"#include "mlir/IR/BuiltinTypes.h"#include "mlir/IR/DialectImplementation.h"#include "mlir/IR/Types.h"#include "llvm/ADT/APFloat.h"Go to the source code of this file.
Functions | |
| static IntegerType | parseStorageType (DialectAsmParser &parser, bool &isSigned) |
| static ParseResult | parseStorageRange (DialectAsmParser &parser, IntegerType storageType, bool isSigned, int64_t &storageTypeMin, int64_t &storageTypeMax) |
| static FloatType | parseExpressedTypeAndRange (DialectAsmParser &parser, double &min, double &max) |
| static Type | parseAnyType (DialectAsmParser &parser) |
| Parses an AnyQuantizedType. More... | |
| static LogicalResult | isScaleInExpressedTypeRange (function_ref< InFlightDiagnostic()> emitError, Type expressedType, double scale) |
| Checks if the given scale value is within the valid range of the expressed type. More... | |
| static ParseResult | parseQuantParams (DialectAsmParser &parser, Type expressedType, double &scale, int64_t &zeroPoint) |
| Parses a quantization parameter, which is either a scale value (float) or a scale-zero point pair (float:integer). More... | |
| static ParseResult | parseBlockSizeInfoUntilRBrace (DialectAsmParser &parser, SmallVectorImpl< int32_t > &quantizedDimensions, SmallVectorImpl< int64_t > &blockSizes) |
| Parses block size information for sub-channel quantization, assuming the leading '{' has already been parsed. More... | |
| static ParseResult | parseQuantParamListUntilRBrace (DialectAsmParser &parser, Type expressedType, SmallVectorImpl< double > &scales, SmallVectorImpl< int64_t > &zeroPoints, SmallVectorImpl< int64_t > &dims) |
Parses a bracketed list of quantization parameters, returning the dimensions of the parsed sub-tensors in dims. More... | |
| static Type | parseUniformType (DialectAsmParser &parser) |
| Parses a UniformQuantizedType. More... | |
| static Type | parseCalibratedType (DialectAsmParser &parser) |
| Parses an CalibratedQuantizedType. More... | |
| static void | printStorageType (QuantizedType type, DialectAsmPrinter &out) |
| static void | printQuantParams (double scale, int64_t zeroPoint, DialectAsmPrinter &out) |
| static void | printBlockSizeInfo (ArrayRef< std::pair< int32_t, int64_t >> blockSizeInfo, DialectAsmPrinter &out) |
| static void | printAnyQuantizedType (AnyQuantizedType type, DialectAsmPrinter &out) |
| Helper that prints a AnyQuantizedType. More... | |
| static void | printUniformQuantizedType (UniformQuantizedType type, DialectAsmPrinter &out) |
| Helper that prints a UniformQuantizedType. More... | |
| static void | printUniformQuantizedPerAxisType (UniformQuantizedPerAxisType type, DialectAsmPrinter &out) |
| Helper that prints a UniformQuantizedPerAxisType. More... | |
| static void | printDenseQuantizationParameters (ArrayRef< APFloat > scales, ArrayRef< APInt > zeroPoints, ArrayRef< int64_t > shape, DialectAsmPrinter &out) |
Prints quantization parameters as a nested list of scale[:zero_point] elements. More... | |
| static void | printUniformQuantizedSubChannelType (UniformQuantizedSubChannelType type, DialectAsmPrinter &out) |
| Helper that prints a UniformQuantizedSubChannelType. More... | |
| static void | printCalibratedQuantizedType (CalibratedQuantizedType type, DialectAsmPrinter &out) |
| Helper that prints a CalibratedQuantizedType. More... | |
|
static |
Checks if the given scale value is within the valid range of the expressed type.
The expressedType argument is the floating-point type used for expressing the quantized values, and scale is the double value to check.
Definition at line 161 of file TypeParser.cpp.
References mlir::emitError().
Referenced by parseQuantParams().
|
static |
Parses an AnyQuantizedType.
any ::= any< storage-spec (expressed-type-spec)?> storage-spec ::= storage-type (< storage-range >)? storage-range ::= integer-literal : integer-literal storage-type ::= (i | u) integer-literal expressed-type-spec ::= : f integer-literal
Definition at line 115 of file TypeParser.cpp.
References mlir::AsmParser::getChecked(), mlir::AsmParser::parseGreater(), mlir::AsmParser::parseLess(), mlir::AsmParser::parseOptionalColon(), parseStorageRange(), parseStorageType(), mlir::AsmParser::parseType(), and mlir::quant::QuantizationFlags::Signed.
|
static |
Parses block size information for sub-channel quantization, assuming the leading '{' has already been parsed.
The block size information is provided as a comma-separated list of "Axis:BlockSize" pairs, terminated by a '}'.
The parsed axis indices are stored in quantizedDimensions, and the corresponding block sizes are stored in blockSizes.
Definition at line 207 of file TypeParser.cpp.
References mlir::AsmParser::parseColon(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseOptionalRBrace(), and mlir::AsmParser::parseRBrace().
Referenced by parseUniformType().
|
static |
Parses an CalibratedQuantizedType.
calibrated ::= calibrated< expressed-spec > expressed-spec ::= expressed-type < calibrated-range > expressed-type ::= f integer-literal calibrated-range ::= float-literal : float-literal
Definition at line 447 of file TypeParser.cpp.
References mlir::AsmParser::getChecked(), max(), min(), parseExpressedTypeAndRange(), mlir::AsmParser::parseGreater(), and mlir::AsmParser::parseLess().
|
static |
Definition at line 89 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::remark::failed(), mlir::AsmParser::getCurrentLocation(), max(), min(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseFloat(), mlir::AsmParser::parseGreater(), mlir::AsmParser::parseLess(), and mlir::AsmParser::parseType().
Referenced by parseCalibratedType().
|
static |
Parses a bracketed list of quantization parameters, returning the dimensions of the parsed sub-tensors in dims.
The dimension of the list is prepended to the dimensions of the sub-tensors. This function assumes that the initial left brace has already been parsed. For example:
parseQuantParamListUntilRBrace(1.0:1, 2.0:4, 3.0:4}) -> Success, dims = [3], scales = [1.0, 2.0, 3.0], zeroPoints = [1, 4, 4]
parseQuantParamListUntilRBrace({1.0, 2.0}, {3.0:1, 4.0:9}}) -> Success, dims = [2, 2], scales = [1.0, 2.0, 3.0, 4.0], zeroPoints = [0, 0, 1, 9]
This function expects all sub-tensors to have the same rank.
Definition at line 246 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseOptionalLBrace(), parseQuantParams(), and mlir::AsmParser::parseRBrace().
Referenced by parseUniformType().
|
static |
Parses a quantization parameter, which is either a scale value (float) or a scale-zero point pair (float:integer).
expressedType, expressing the type of scale values, is used to validate the scale. The parsed scale and zero point (if any) are stored in scale and zeroPoint.
Definition at line 178 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::remark::failed(), mlir::AsmParser::getCurrentLocation(), isScaleInExpressedTypeRange(), mlir::AsmParser::parseFloat(), mlir::AsmParser::parseInteger(), and mlir::AsmParser::parseOptionalColon().
Referenced by parseQuantParamListUntilRBrace(), and parseUniformType().
|
static |
Definition at line 58 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::remark::failed(), mlir::AsmParser::getCurrentLocation(), mlir::quant::QuantizedType::getDefaultMaximumForInteger(), mlir::quant::QuantizedType::getDefaultMinimumForInteger(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseGreater(), mlir::AsmParser::parseInteger(), and mlir::AsmParser::parseOptionalLess().
Referenced by parseAnyType(), and parseUniformType().
|
static |
Definition at line 19 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getCurrentLocation(), mlir::Builder::getIntegerType(), mlir::OptionalParseResult::has_value(), mlir::quant::QuantizedType::MaxStorageBits, mlir::AsmParser::parseKeyword(), and mlir::AsmParser::parseOptionalType().
Referenced by parseAnyType(), and parseUniformType().
|
static |
Parses a UniformQuantizedType.
uniform_type ::= uniform_per_layer | uniform_per_axis | uniform_sub_channel uniform_per_layer ::= uniform< storage-spec expressed-type-spec , scale-zero > uniform_per_axis ::= uniform< storage-spec expressed-type-spec axis-spec , { scale-zero-list } > uniform_sub_channel ::= uniform< storage-spec expressed-type-spec block-size-info , scale-zero-tensor > storage-spec ::= storage-type (< storage-range >)? storage-range ::= integer-literal : integer-literal storage-type ::= (i | u) integer-literal expressed-type-spec ::= : f integer-literal axis-spec ::= : integer-literal scale-zero ::= scale (: zero-point)? scale ::= float-literal zero-point ::= integer-literal scale-zero-list ::= scale-zero (, scale-zero)* block-size-info ::= { } | { axis-block : (, axis-block)* } axis-block ::= axis-spec : block-size-spec block-size-spec ::= integer-literal scale-zero-tensor ::= scale-zero-dense-exp | scale-zero-list scale-zero-dense-exp ::= { scale-zero-tensor (, scale-zero-tensor)* }
Definition at line 324 of file TypeParser.cpp.
References mlir::get(), mlir::DenseElementsAttr::get(), mlir::AsmParser::getChecked(), parseBlockSizeInfoUntilRBrace(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseComma(), mlir::AsmParser::parseGreater(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseLBrace(), mlir::AsmParser::parseLess(), mlir::AsmParser::parseOptionalColon(), mlir::AsmParser::parseOptionalLBrace(), parseQuantParamListUntilRBrace(), parseQuantParams(), parseStorageRange(), parseStorageType(), mlir::AsmParser::parseType(), and mlir::quant::QuantizationFlags::Signed.
|
static |
Helper that prints a AnyQuantizedType.
Definition at line 525 of file TypeParser.cpp.
References printStorageType().
|
static |
Definition at line 514 of file TypeParser.cpp.
Referenced by printUniformQuantizedSubChannelType().
|
static |
Helper that prints a CalibratedQuantizedType.
Definition at line 638 of file TypeParser.cpp.
References mlir::quant::CalibratedQuantizedType::getMax(), and mlir::quant::CalibratedQuantizedType::getMin().
|
static |
Prints quantization parameters as a nested list of scale[:zero_point] elements.
The nesting corresponds to the shape dimensions.
Elements are delimited by commas, and the inner dimensions are enclosed in braces. zero_point is only printed if it is non-zero. For example:
printDenseQuantizationParameters(scales=[1.0, 2.0, 3.0, 4.0], zeroPoints=[0, 0, 1, 9], shape=[2, 2])
would print:
{{1.0, 2.0}, {3.0:1, 4.0:9}}
Definition at line 582 of file TypeParser.cpp.
Referenced by printUniformQuantizedSubChannelType().
|
static |
Definition at line 505 of file TypeParser.cpp.
Referenced by printUniformQuantizedType().
|
static |
Definition at line 488 of file TypeParser.cpp.
References mlir::quant::QuantizedType::getStorageTypeIntegralWidth(), mlir::quant::QuantizedType::getStorageTypeMax(), mlir::quant::QuantizedType::getStorageTypeMin(), mlir::quant::QuantizedType::hasStorageTypeBounds(), and mlir::quant::QuantizedType::isSigned().
Referenced by printAnyQuantizedType(), printUniformQuantizedPerAxisType(), printUniformQuantizedSubChannelType(), and printUniformQuantizedType().
|
static |
Helper that prints a UniformQuantizedPerAxisType.
Definition at line 548 of file TypeParser.cpp.
References mlir::quant::UniformQuantizedPerAxisType::getQuantizedDimension(), mlir::quant::UniformQuantizedPerAxisType::getScales(), mlir::quant::UniformQuantizedPerAxisType::getZeroPoints(), and printStorageType().
|
static |
Helper that prints a UniformQuantizedSubChannelType.
Definition at line 620 of file TypeParser.cpp.
References mlir::quant::UniformQuantizedSubChannelType::getBlockSizeInfo(), mlir::quant::UniformQuantizedSubChannelType::getScales(), mlir::DenseElementsAttr::getType(), mlir::DenseElementsAttr::getValues(), mlir::quant::UniformQuantizedSubChannelType::getZeroPoints(), printBlockSizeInfo(), printDenseQuantizationParameters(), and printStorageType().
|
static |
Helper that prints a UniformQuantizedType.
Definition at line 536 of file TypeParser.cpp.
References mlir::quant::UniformQuantizedType::getScale(), mlir::quant::UniformQuantizedType::getZeroPoint(), printQuantParams(), and printStorageType().