MLIR  20.0.0git
Quant.h
Go to the documentation of this file.
1 //===-- mlir-c/Dialect/Quant.h - C API for LLVM -------------------*- C -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
4 // Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef MLIR_C_DIALECT_QUANT_H
11 #define MLIR_C_DIALECT_QUANT_H
12 
13 #include "mlir-c/IR.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
20 
21 //===---------------------------------------------------------------------===//
22 // QuantizedType
23 //===---------------------------------------------------------------------===//
24 
25 /// Returns `true` if the given type is a quantization dialect type.
27 
28 /// Returns the bit flag used to indicate signedness of a quantized type.
30 
31 /// Returns the minimum possible value stored by a quantized type.
33  bool isSigned, unsigned integralWidth);
34 
35 /// Returns the maximum possible value stored by a quantized type.
37  bool isSigned, unsigned integralWidth);
38 
39 /// Gets the original type approximated by the given quantized type.
41 
42 /// Gets the flags associated with the given quantized type.
43 MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetFlags(MlirType type);
44 
45 /// Returns `true` if the given type is signed, `false` otherwise.
47 
48 /// Returns the underlying type used to store the values.
50 
51 /// Returns the minimum value that the storage type of the given quantized type
52 /// can take.
54 
55 /// Returns the maximum value that the storage type of the given quantized type
56 /// can take.
58 
59 /// Returns the integral bitwidth that the storage type of the given quantized
60 /// type can represent exactly.
61 MLIR_CAPI_EXPORTED unsigned
63 
64 /// Returns `true` if the `candidate` type is compatible with the given
65 /// quantized `type`.
67 mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate);
68 
69 /// Returns the element type of the given quantized type as another quantized
70 /// type.
71 MLIR_CAPI_EXPORTED MlirType
73 
74 /// Casts from a type based on the storage type of the given type to a
75 /// corresponding type based on the given type. Returns a null type if the cast
76 /// is not valid.
77 MLIR_CAPI_EXPORTED MlirType
78 mlirQuantizedTypeCastFromStorageType(MlirType type, MlirType candidate);
79 
80 /// Casts from a type based on a quantized type to a corresponding typed based
81 /// on the storage type. Returns a null type if the cast is not valid.
83 
84 /// Casts from a type based on the expressed type of the given type to a
85 /// corresponding type based on the given type. Returns a null type if the cast
86 /// is not valid.
87 MLIR_CAPI_EXPORTED MlirType
88 mlirQuantizedTypeCastFromExpressedType(MlirType type, MlirType candidate);
89 
90 /// Casts from a type based on a quantized type to a corresponding typed based
91 /// on the expressed type. Returns a null type if the cast is not valid.
93 
94 /// Casts from a type based on the expressed type of the given quantized type to
95 /// equivalent type based on storage type of the same quantized type.
96 MLIR_CAPI_EXPORTED MlirType
97 mlirQuantizedTypeCastExpressedToStorageType(MlirType type, MlirType candidate);
98 
99 //===---------------------------------------------------------------------===//
100 // AnyQuantizedType
101 //===---------------------------------------------------------------------===//
102 
103 /// Returns `true` if the given type is an AnyQuantizedType.
105 
106 /// Creates an instance of AnyQuantizedType with the given parameters in the
107 /// same context as `storageType` and returns it. The instance is owned by the
108 /// context.
109 MLIR_CAPI_EXPORTED MlirType mlirAnyQuantizedTypeGet(unsigned flags,
110  MlirType storageType,
111  MlirType expressedType,
112  int64_t storageTypeMin,
113  int64_t storageTypeMax);
114 
115 //===---------------------------------------------------------------------===//
116 // UniformQuantizedType
117 //===---------------------------------------------------------------------===//
118 
119 /// Returns `true` if the given type is a UniformQuantizedType.
121 
122 /// Creates an instance of UniformQuantizedType with the given parameters in the
123 /// same context as `storageType` and returns it. The instance is owned by the
124 /// context.
126  unsigned flags, MlirType storageType, MlirType expressedType, double scale,
127  int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
128 
129 /// Returns the scale of the given uniform quantized type.
131 
132 /// Returns the zero point of the given uniform quantized type.
134 
135 /// Returns `true` if the given uniform quantized type is fixed-point.
137 
138 //===---------------------------------------------------------------------===//
139 // UniformQuantizedPerAxisType
140 //===---------------------------------------------------------------------===//
141 
142 /// Returns `true` if the given type is a UniformQuantizedPerAxisType.
144 
145 /// Creates an instance of UniformQuantizedPerAxisType with the given parameters
146 /// in the same context as `storageType` and returns it. `scales` and
147 /// `zeroPoints` point to `nDims` number of elements. The instance is owned
148 /// by the context.
150  unsigned flags, MlirType storageType, MlirType expressedType,
151  intptr_t nDims, double *scales, int64_t *zeroPoints,
152  int32_t quantizedDimension, int64_t storageTypeMin, int64_t storageTypeMax);
153 
154 /// Returns the number of axes in the given quantized per-axis type.
155 MLIR_CAPI_EXPORTED intptr_t
157 
158 /// Returns `pos`-th scale of the given quantized per-axis type.
160  intptr_t pos);
161 
162 /// Returns `pos`-th zero point of the given quantized per-axis type.
163 MLIR_CAPI_EXPORTED int64_t
164 mlirUniformQuantizedPerAxisTypeGetZeroPoint(MlirType type, intptr_t pos);
165 
166 /// Returns the index of the quantized dimension in the given quantized per-axis
167 /// type.
168 MLIR_CAPI_EXPORTED int32_t
170 
171 /// Returns `true` if the given uniform quantized per-axis type is fixed-point.
174 
175 //===---------------------------------------------------------------------===//
176 // CalibratedQuantizedType
177 //===---------------------------------------------------------------------===//
178 
179 /// Returns `true` if the given type is a CalibratedQuantizedType.
181 
182 /// Creates an instance of CalibratedQuantizedType with the given parameters
183 /// in the same context as `expressedType` and returns it. The instance is owned
184 /// by the context.
185 MLIR_CAPI_EXPORTED MlirType
186 mlirCalibratedQuantizedTypeGet(MlirType expressedType, double min, double max);
187 
188 /// Returns the min value of the given calibrated quantized type.
190 
191 /// Returns the max value of the given calibrated quantized type.
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 #endif // MLIR_C_DIALECT_QUANT_H
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
MLIR_CAPI_EXPORTED intptr_t mlirUniformQuantizedPerAxisTypeGetNumDims(MlirType type)
Returns the number of axes in the given quantized per-axis type.
Definition: Quant.cpp:171
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(quant, quant)
MLIR_CAPI_EXPORTED bool mlirTypeIsACalibratedQuantizedType(MlirType type)
Returns true if the given type is a CalibratedQuantizedType.
Definition: Quant.cpp:201
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMaximumForInteger(bool isSigned, unsigned integralWidth)
Returns the maximum possible value stored by a quantized type.
Definition: Quant.cpp:36
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized type is fixed-point.
Definition: Quant.cpp:148
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMin(MlirType type)
Returns the minimum value that the storage type of the given quantized type can take.
Definition: Quant.cpp:58
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedType(MlirType type)
Returns true if the given type is a UniformQuantizedType.
Definition: Quant.cpp:127
MLIR_CAPI_EXPORTED bool mlirTypeIsAQuantizedType(MlirType type)
Returns true if the given type is a quantization dialect type.
Definition: Quant.cpp:22
MLIR_CAPI_EXPORTED double mlirUniformQuantizedPerAxisTypeGetScale(MlirType type, intptr_t pos)
Returns pos-th scale of the given quantized per-axis type.
Definition: Quant.cpp:177
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedTypeGetZeroPoint(MlirType type)
Returns the zero point of the given uniform quantized type.
Definition: Quant.cpp:144
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized per-axis type is fixed-point.
Definition: Quant.cpp:193
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMax(MlirType type)
Returns the maximum value that the storage type of the given quantized type can take.
Definition: Quant.cpp:62
MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMax(MlirType type)
Returns the max value of the given calibrated quantized type.
Definition: Quant.cpp:215
MLIR_CAPI_EXPORTED MlirType mlirCalibratedQuantizedTypeGet(MlirType expressedType, double min, double max)
Creates an instance of CalibratedQuantizedType with the given parameters in the same context as expre...
Definition: Quant.cpp:205
MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsSigned(MlirType type)
Returns true if the given type is signed, false otherwise.
Definition: Quant.cpp:50
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedPerAxisTypeGetZeroPoint(MlirType type, intptr_t pos)
Returns pos-th zero point of the given quantized per-axis type.
Definition: Quant.cpp:182
MLIR_CAPI_EXPORTED int32_t mlirUniformQuantizedPerAxisTypeGetQuantizedDimension(MlirType type)
Returns the index of the quantized dimension in the given quantized per-axis type.
Definition: Quant.cpp:188
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastToExpressedType(MlirType type)
Casts from a type based on a quantized type to a corresponding typed based on the expressed type.
Definition: Quant.cpp:97
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetExpressedType(MlirType type)
Gets the original type approximated by the given quantized type.
Definition: Quant.cpp:42
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetStorageTypeIntegralWidth(MlirType type)
Returns the integral bitwidth that the storage type of the given quantized type can represent exactly...
Definition: Quant.cpp:66
MLIR_CAPI_EXPORTED MlirType mlirAnyQuantizedTypeGet(unsigned flags, MlirType storageType, MlirType expressedType, int64_t storageTypeMin, int64_t storageTypeMax)
Creates an instance of AnyQuantizedType with the given parameters in the same context as storageType ...
Definition: Quant.cpp:115
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastToStorageType(MlirType type)
Casts from a type based on a quantized type to a corresponding typed based on the storage type.
Definition: Quant.cpp:86
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetStorageType(MlirType type)
Returns the underlying type used to store the values.
Definition: Quant.cpp:54
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastFromExpressedType(MlirType type, MlirType candidate)
Casts from a type based on the expressed type of the given type to a corresponding type based on the ...
Definition: Quant.cpp:91
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedPerAxisType(MlirType type)
Returns true if the given type is a UniformQuantizedPerAxisType.
Definition: Quant.cpp:156
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetQuantizedElementType(MlirType type)
Returns the element type of the given quantized type as another quantized type.
Definition: Quant.cpp:76
MLIR_CAPI_EXPORTED bool mlirTypeIsAAnyQuantizedType(MlirType type)
Returns true if the given type is an AnyQuantizedType.
Definition: Quant.cpp:111
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastExpressedToStorageType(MlirType type, MlirType candidate)
Casts from a type based on the expressed type of the given quantized type to equivalent type based on...
Definition: Quant.cpp:101
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastFromStorageType(MlirType type, MlirType candidate)
Casts from a type based on the storage type of the given type to a corresponding type based on the gi...
Definition: Quant.cpp:80
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetSignedFlag(void)
Returns the bit flag used to indicate signedness of a quantized type.
Definition: Quant.cpp:26
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMinimumForInteger(bool isSigned, unsigned integralWidth)
Returns the minimum possible value stored by a quantized type.
Definition: Quant.cpp:30
MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMin(MlirType type)
Returns the min value of the given calibrated quantized type.
Definition: Quant.cpp:211
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetFlags(MlirType type)
Gets the flags associated with the given quantized type.
Definition: Quant.cpp:46
MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedPerAxisTypeGet(unsigned flags, MlirType storageType, MlirType expressedType, intptr_t nDims, double *scales, int64_t *zeroPoints, int32_t quantizedDimension, int64_t storageTypeMin, int64_t storageTypeMax)
Creates an instance of UniformQuantizedPerAxisType with the given parameters in the same context as s...
Definition: Quant.cpp:160
MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate)
Returns true if the candidate type is compatible with the given quantized type.
Definition: Quant.cpp:70
MLIR_CAPI_EXPORTED double mlirUniformQuantizedTypeGetScale(MlirType type)
Returns the scale of the given uniform quantized type.
Definition: Quant.cpp:140
MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedTypeGet(unsigned flags, MlirType storageType, MlirType expressedType, double scale, int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax)
Creates an instance of UniformQuantizedType with the given parameters in the same context as storageT...
Definition: Quant.cpp:131
#define MLIR_CAPI_EXPORTED
Definition: Support.h:46