17 return isa<FloatType>(inputType);
22 if (isa<TensorType, VectorType>(
inputType)) {
23 Type elementType = cast<ShapedType>(
inputType).getElementType();
36 assert(
expressedType &&
"convert() on unsupported conversion");
37 if (
auto tensorType = dyn_cast<RankedTensorType>(
inputType))
39 if (dyn_cast<UnrankedTensorType>(
inputType))
41 if (
auto vectorType = dyn_cast<VectorType>(
inputType))
53 if (
auto attr = dyn_cast<DenseFPElementsAttr>(realValue)) {
64 ShapedType type = attr.getType();
65 size_t dimSize = type.getDimSize(quantizationDim);
66 if (dimSize != scales.size()) {
70 converters.reserve(dimSize);
71 for (
int i = 0, e = dimSize; i != e; ++i) {
72 converters.push_back(getPerChunkConverter(i));
77 int64_t flattenIndex = 0;
78 auto shape = type.getShape();
80 std::accumulate(std::next(shape.begin(), quantizationDim + 1),
81 shape.end(), 1, std::multiplies<int64_t>());
83 return attr.
mapValues(newElementType, [&](
const APFloat &old) {
84 int chunkIndex = (flattenIndex++) / chunkSize;
85 return converters[chunkIndex % dimSize].quantizeFloatToInt(old);
Attributes are known-constant values of operations.
An attribute that represents a reference to a dense vector or tensor object.
An attribute that represents a reference to a dense float vector or tensor object.
DenseElementsAttr mapValues(Type newElementType, function_ref< APInt(const APFloat &)> mapping) const
Generates a new DenseElementsAttr by mapping each value attribute, and constructing the DenseElements...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Base class for all quantized types known to this dialect.
Type getExpressedType() const
Gets the original expressed type that this quantized type approximates.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
Performs type conversion from an arbitrary input type to a type that is expressed by a QuantizedType.
static ExpressedToQuantizedConverter forInputType(Type inputType)
Creates a converter for the given input type.
const Type inputType
The input type that is being converted from.
Type convert(QuantizedType elementalType) const
Converts the inputType to be based on the given elemental type, returning the new type (or nullptr an...
const Type expressedType
Supported, elemental expressed type (i.e.