MLIR  19.0.0git
QuantUtils.h
Go to the documentation of this file.
1 //===-- QuantUtils.h - TOSA numerical support declarations ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Function declarations for TOSA numerical support functions and quantization
10 // attribute builders
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_DIALECT_TOSA_UTILS_QUANTUTILS_H
15 #define MLIR_DIALECT_TOSA_UTILS_QUANTUTILS_H
16 
18 
21 
22 namespace mlir {
23 namespace tosa {
24 
25 //===----------------------------------------------------------------------===//
26 // Utility functions to support quantization handling in Tosa.
27 //===----------------------------------------------------------------------===//
28 
29 /// From a scale value, computes multiplier and shift values
30 /// for 16 or 32-bit scale widths.
31 void computeMultiplierAndShift(double scale, int32_t &multiplier,
32  int32_t &shift, int32_t scaleWidth);
33 
34 //// Builds ConvOpQuantizationAttr from input and weight.
35 ConvOpQuantizationAttr buildConvOpQuantizationAttr(OpBuilder &builder,
36  Value input, Value weight);
37 
38 //// Builds MatMulOpQuantizationAttr for MatMul operations from A and B.
39 MatMulOpQuantizationAttr buildMatMulOpQuantizationAttr(OpBuilder &builder,
40  Value a, Value b);
41 
42 //// Builds UnaryOpQuantizationAttr for unary operations from input values.
43 UnaryOpQuantizationAttr buildUnaryOpQuantizationAttr(OpBuilder &builder,
44  Value input,
45  Type outputRawType);
46 
47 //// Builds PadOpQuantizationAttr for pad operations from input values.
48 PadOpQuantizationAttr buildPadOpQuantizationAttr(OpBuilder &builder,
49  Value input);
50 
51 //// construct ConvOp output type with correct bitwidth based on input/weight
52 /// width.
53 Type buildConvOpResultTypeInfo(OpBuilder &builder, Type outputType, Value input,
54  Value weight);
55 
56 /// Builds Tosa quantization attributes from min/max values.
57 Type buildQTypeFromMinMax(OpBuilder builder, Type inputDType, Attribute minAttr,
58  Attribute maxAttr, IntegerAttr quantBits,
59  int filterQuantDim, bool isSigned,
60  BoolAttr narrowRange);
61 
62 /// Builds Tosa quantization attributes from min/max values.
63 TypeAttr buildQTypeAttrFromMinMax(OpBuilder builder, Type inputDType,
64  Attribute minAttr, Attribute maxAttr,
65  IntegerAttr quantBits, int filterQuantDim,
66  bool isSigned, BoolAttr narrowRange);
67 
68 } // namespace tosa
69 } // namespace mlir
70 
71 #endif // MLIR_DIALECT_TOSA_UTILS_QUANTUTILS_H
@ Type
An inlay hint that for a type annotation.
ConvOpQuantizationAttr buildConvOpQuantizationAttr(OpBuilder &builder, Value input, Value weight)
Method to build ConvOpQuantizationAttr, called from ConvOpQuantInfoBuilder/TransConvOpQuantInfoBuilde...
Definition: QuantUtils.cpp:120
TypeAttr buildQTypeAttrFromMinMax(OpBuilder builder, Type inputDType, Attribute minAttr, Attribute maxAttr, IntegerAttr quantBits, int filterQuantDim, bool isSigned, BoolAttr narrowRange)
Builds Tosa quantization attributes from min/max values.
Definition: QuantUtils.cpp:339
Type buildConvOpResultTypeInfo(OpBuilder &builder, Type outputType, Value input, Value weight)
construct ConvOp output type with correct bitwidth based on input/weight width.
Definition: QuantUtils.cpp:239
Type buildQTypeFromMinMax(OpBuilder builder, Type inputDType, Attribute minAttr, Attribute maxAttr, IntegerAttr quantBits, int filterQuantDim, bool isSigned, BoolAttr narrowRange)
Builds Tosa quantization attributes from min/max values.
Definition: QuantUtils.cpp:271
PadOpQuantizationAttr buildPadOpQuantizationAttr(OpBuilder &builder, Value input)
Builds PadOpQuantizationAttr, called from PadOpQuantInfoBuilder: inputZp: input zeropoint.
Definition: QuantUtils.cpp:219
MatMulOpQuantizationAttr buildMatMulOpQuantizationAttr(OpBuilder &builder, Value a, Value b)
Builds MatMulOpQuantizationAttr, called from MatMulOpQuantInfoBuilder: aZp: input a zeropoint bZp: in...
Definition: QuantUtils.cpp:164
void computeMultiplierAndShift(double scale, int32_t &multiplier, int32_t &shift, int32_t scaleWidth)
From a scale value, computes multiplier and shift values for 16 or 32-bit scale widths.
Definition: QuantUtils.cpp:95
UnaryOpQuantizationAttr buildUnaryOpQuantizationAttr(OpBuilder &builder, Value input, Type outputRawType)
Builds UnaryOpQuantizationAttr UnaryOpQuantInfoBuilder: inputZp: input zeropoint outputZp: output zer...
Definition: QuantUtils.cpp:193
Include the generated interface declarations.