|
MLIR 23.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/QuantStorageTypeInterface.h"#include "mlir/IR/Types.h"#include "llvm/ADT/APFloat.h"#include "llvm/ADT/SmallVectorExtras.h"Go to the source code of this file.
Functions | |
| static Type | parseStorageType (DialectAsmParser &parser, bool &isSigned) |
| static ParseResult | parseStorageRange (DialectAsmParser &parser, Type 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. | |
| 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. | |
| 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). | |
| 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. | |
| 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. | |
| static Type | parseUniformType (DialectAsmParser &parser) |
| Parses a UniformQuantizedType. | |
| static Type | parseCalibratedType (DialectAsmParser &parser) |
| Parses an CalibratedQuantizedType. | |
| 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. | |
| static void | printUniformQuantizedType (UniformQuantizedType type, DialectAsmPrinter &out) |
| Helper that prints a UniformQuantizedType. | |
| static void | printUniformQuantizedPerAxisType (UniformQuantizedPerAxisType type, DialectAsmPrinter &out) |
| Helper that prints a UniformQuantizedPerAxisType. | |
| 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. | |
| static void | printUniformQuantizedSubChannelType (UniformQuantizedSubChannelType type, DialectAsmPrinter &out) |
| Helper that prints a UniformQuantizedSubChannelType. | |
| static void | printCalibratedQuantizedType (CalibratedQuantizedType type, DialectAsmPrinter &out) |
| Helper that prints a CalibratedQuantizedType. | |
|
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 174 of file TypeParser.cpp.
References mlir::emitError(), and success().
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 128 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 220 of file TypeParser.cpp.
References mlir::AsmParser::parseColon(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseOptionalRBrace(), mlir::AsmParser::parseRBrace(), and success().
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 460 of file TypeParser.cpp.
References mlir::AsmParser::getChecked(), max(), min(), parseExpressedTypeAndRange(), mlir::AsmParser::parseGreater(), and mlir::AsmParser::parseLess().
|
static |
Definition at line 102 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), 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 259 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseOptionalLBrace(), parseQuantParamListUntilRBrace(), parseQuantParams(), mlir::AsmParser::parseRBrace(), and success().
Referenced by parseQuantParamListUntilRBrace(), and 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 191 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), isScaleInExpressedTypeRange(), mlir::AsmParser::parseFloat(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseOptionalColon(), and success().
Referenced by parseQuantParamListUntilRBrace(), and parseUniformType().
|
static |
Definition at line 70 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseGreater(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseOptionalLess(), and success().
Referenced by parseAnyType(), and parseUniformType().
|
static |
Definition at line 21 of file TypeParser.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getCurrentLocation(), mlir::Builder::getIntegerType(), mlir::AsmParser::parseKeyword(), mlir::AsmParser::parseOptionalType(), and result.
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 337 of file TypeParser.cpp.
References mlir::DenseElementsAttr::get(), mlir::AsmParser::getChecked(), mlir::Type::getIntOrFloatBitWidth(), 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 535 of file TypeParser.cpp.
References printStorageType().
|
static |
Definition at line 524 of file TypeParser.cpp.
Referenced by printUniformQuantizedSubChannelType().
|
static |
Helper that prints a CalibratedQuantizedType.
Definition at line 648 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 592 of file TypeParser.cpp.
Referenced by printUniformQuantizedSubChannelType().
|
static |
Definition at line 515 of file TypeParser.cpp.
Referenced by printUniformQuantizedType().
|
static |
Definition at line 501 of file TypeParser.cpp.
References mlir::quant::QuantizedType::getStorageType(), 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 558 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 630 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 546 of file TypeParser.cpp.
References mlir::quant::UniformQuantizedType::getScale(), mlir::quant::UniformQuantizedType::getZeroPoint(), printQuantParams(), and printStorageType().