MLIR 23.0.0git
DialectQuant.cpp
Go to the documentation of this file.
1//===- DialectQuant.cpp - 'quant' dialect submodule -----------------------===//
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#include <vector>
10
12#include "mlir-c/IR.h"
16
18
19namespace nb = nanobind;
21
22namespace mlir {
23namespace python {
25namespace quant {
26//===-------------------------------------------------------------------===//
27// QuantizedType
28//===-------------------------------------------------------------------===//
29
30struct QuantizedType : PyConcreteType<QuantizedType> {
32 static constexpr const char *pyClassName = "QuantizedType";
33 using Base::Base;
34
35 static void bindDerived(ClassTy &c) {
36 c.def_static(
37 "default_minimum_for_integer",
38 [](bool isSigned, unsigned integralWidth) {
40 integralWidth);
41 },
42 "Default minimum value for the integer with the specified signedness "
43 "and "
44 "bit width.",
45 nb::arg("is_signed"), nb::arg("integral_width"));
46 c.def_static(
47 "default_maximum_for_integer",
48 [](bool isSigned, unsigned integralWidth) {
50 integralWidth);
51 },
52 "Default maximum value for the integer with the specified signedness "
53 "and "
54 "bit width.",
55 nb::arg("is_signed"), nb::arg("integral_width"));
56 c.def_prop_ro(
57 "expressed_type",
58 [](QuantizedType &type) {
59 return PyType(type.getContext(),
61 .maybeDownCast();
62 },
63 "Type expressed by this quantized type.");
64 c.def_prop_ro(
65 "flags",
66 [](const QuantizedType &type) {
67 return mlirQuantizedTypeGetFlags(type);
68 },
69 "Flags of this quantized type (named accessors should be preferred to "
70 "this)");
71 c.def_prop_ro(
72 "is_signed",
73 [](const QuantizedType &type) {
74 return mlirQuantizedTypeIsSigned(type);
75 },
76 "Signedness of this quantized type.");
77 c.def_prop_ro(
78 "storage_type",
79 [](QuantizedType &type) {
80 return PyType(type.getContext(),
82 .maybeDownCast();
83 },
84 "Storage type backing this quantized type.");
85 c.def_prop_ro(
86 "storage_type_min",
87 [](const QuantizedType &type) {
89 },
90 "The minimum value held by the storage type of this quantized type.");
91 c.def_prop_ro(
92 "storage_type_max",
93 [](const QuantizedType &type) {
95 },
96 "The maximum value held by the storage type of this quantized type.");
97 c.def_prop_ro(
98 "storage_type_integral_width",
99 [](const QuantizedType &type) {
101 },
102 "The bitwidth of the storage type of this quantized type.");
103 c.def(
104 "is_compatible_expressed_type",
105 [](const QuantizedType &type, const PyType &candidate) {
106 return mlirQuantizedTypeIsCompatibleExpressedType(type, candidate);
107 },
108 "Checks whether the candidate type can be expressed by this quantized "
109 "type.",
110 nb::arg("candidate"));
111 c.def_prop_ro(
112 "quantized_element_type",
113 [](QuantizedType &type) {
114 return PyType(type.getContext(),
116 .maybeDownCast();
117 },
118 "Element type of this quantized type expressed as quantized type.");
119 c.def(
120 "cast_from_storage_type",
121 [](QuantizedType &type, const PyType &candidate) {
122 MlirType castResult =
124 if (!mlirTypeIsNull(castResult))
125 return QuantizedType(type.getContext(), castResult);
126 throw nb::type_error("Invalid cast.");
127 },
128 "Casts from a type based on the storage type of this quantized type to "
129 "a "
130 "corresponding type based on the quantized type. Raises TypeError if "
131 "the "
132 "cast is not valid.",
133 nb::arg("candidate"));
134 c.def_static(
135 "cast_to_storage_type",
136 [](PyType &type) {
137 MlirType castResult = mlirQuantizedTypeCastToStorageType(type);
138 if (!mlirTypeIsNull(castResult))
139 return PyType(type.getContext(), castResult).maybeDownCast();
140 throw nb::type_error("Invalid cast.");
141 },
142 "Casts from a type based on a quantized type to a corresponding type "
143 "based on the storage type of this quantized type. Raises TypeError if "
144 "the cast is not valid.",
145 nb::arg("type"));
146 c.def(
147 "cast_from_expressed_type",
148 [](QuantizedType &type, const PyType &candidate) {
149 MlirType castResult =
151 if (!mlirTypeIsNull(castResult))
152 return PyType(type.getContext(), castResult).maybeDownCast();
153 throw nb::type_error("Invalid cast.");
154 },
155 "Casts from a type based on the expressed type of this quantized type "
156 "to "
157 "a corresponding type based on the quantized type. Raises TypeError if "
158 "the cast is not valid.",
159 nb::arg("candidate"));
160 c.def_static(
161 "cast_to_expressed_type",
162 [](PyType &type) {
163 MlirType castResult = mlirQuantizedTypeCastToExpressedType(type);
164 if (!mlirTypeIsNull(castResult))
165 return PyType(type.getContext(), castResult).maybeDownCast();
166 throw nb::type_error("Invalid cast.");
167 },
168 "Casts from a type based on a quantized type to a corresponding type "
169 "based on the expressed type of this quantized type. Raises TypeError "
170 "if "
171 "the cast is not valid.",
172 nb::arg("type"));
173 c.def(
174 "cast_expressed_to_storage_type",
175 [](QuantizedType &type, const PyType &candidate) {
176 MlirType castResult =
178 if (!mlirTypeIsNull(castResult))
179 return PyType(type.getContext(), castResult).maybeDownCast();
180 throw nb::type_error("Invalid cast.");
181 },
182 "Casts from a type based on the expressed type of this quantized type "
183 "to "
184 "a corresponding type based on the storage type. Raises TypeError if "
185 "the "
186 "cast is not valid.",
187 nb::arg("candidate"));
188 }
189};
190
191//===-------------------------------------------------------------------===//
192// AnyQuantizedType
193//===-------------------------------------------------------------------===//
194
195struct AnyQuantizedType : PyConcreteType<AnyQuantizedType, QuantizedType> {
199 static constexpr const char *pyClassName = "AnyQuantizedType";
201 using Base::Base;
202
203 static void bindDerived(ClassTy &c) {
204 c.def_static(
205 "get",
206 [](unsigned flags, const PyType &storageType,
207 const PyType &expressedType, int64_t storageTypeMin,
208 int64_t storageTypeMax, DefaultingPyMlirContext context) {
209 return AnyQuantizedType(
210 context->getRef(),
211 mlirAnyQuantizedTypeGet(flags, storageType, expressedType,
212 storageTypeMin, storageTypeMax));
213 },
214 "Gets an instance of AnyQuantizedType in the same context as the "
215 "provided storage type.",
216 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
217 nb::arg("storage_type_min"), nb::arg("storage_type_max"),
218 nb::arg("context") = nb::none());
219 }
220};
221
222//===-------------------------------------------------------------------===//
223// UniformQuantizedType
224//===-------------------------------------------------------------------===//
225
227 : PyConcreteType<UniformQuantizedType, QuantizedType> {
231 static constexpr const char *pyClassName = "UniformQuantizedType";
233 using Base::Base;
234
235 static void bindDerived(ClassTy &c) {
236 c.def_static(
237 "get",
238 [](unsigned flags, const PyType &storageType,
239 const PyType &expressedType, double scale, int64_t zeroPoint,
240 int64_t storageTypeMin, int64_t storageTypeMax,
241 DefaultingPyMlirContext context) {
243 context->getRef(),
244 mlirUniformQuantizedTypeGet(flags, storageType, expressedType,
245 scale, zeroPoint, storageTypeMin,
246 storageTypeMax));
247 },
248 "Gets an instance of UniformQuantizedType in the same context as the "
249 "provided storage type.",
250 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
251 nb::arg("scale"), nb::arg("zero_point"), nb::arg("storage_type_min"),
252 nb::arg("storage_type_max"), nb::arg("context") = nb::none());
253 c.def_prop_ro(
254 "scale",
255 [](const UniformQuantizedType &type) {
257 },
258 "The scale designates the difference between the real values "
259 "corresponding to consecutive quantized values differing by 1.");
260 c.def_prop_ro(
261 "zero_point",
262 [](const UniformQuantizedType &type) {
264 },
265 "The storage value corresponding to the real value 0 in the affine "
266 "equation.");
267 c.def_prop_ro(
268 "is_fixed_point",
269 [](const UniformQuantizedType &type) {
271 },
272 "Fixed point values are real numbers divided by a scale.");
273 }
274};
275
276//===-------------------------------------------------------------------===//
277// UniformQuantizedPerAxisType
278//===-------------------------------------------------------------------===//
279
281 : PyConcreteType<UniformQuantizedPerAxisType, QuantizedType> {
282 static constexpr IsAFunctionTy isaFunction =
286 static constexpr const char *pyClassName = "UniformQuantizedPerAxisType";
287 static inline const MlirStringRef name =
289 using Base::Base;
290
291 static void bindDerived(ClassTy &c) {
292 c.def_static(
293 "get",
294 [](unsigned flags, const PyType &storageType,
295 const PyType &expressedType, std::vector<double> scales,
296 std::vector<int64_t> zeroPoints, int32_t quantizedDimension,
297 int64_t storageTypeMin, int64_t storageTypeMax,
298 DefaultingPyMlirContext context) {
299 if (scales.size() != zeroPoints.size())
300 throw nb::value_error(
301 "Mismatching number of scales and zero points.");
302 auto nDims = static_cast<intptr_t>(scales.size());
304 context->getRef(),
306 flags, storageType, expressedType, nDims, scales.data(),
307 zeroPoints.data(), quantizedDimension, storageTypeMin,
308 storageTypeMax));
309 },
310 "Gets an instance of UniformQuantizedPerAxisType in the same context "
311 "as "
312 "the provided storage type.",
313 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
314 nb::arg("scales"), nb::arg("zero_points"),
315 nb::arg("quantized_dimension"), nb::arg("storage_type_min"),
316 nb::arg("storage_type_max"), nb::arg("context") = nb::none());
317 c.def_prop_ro(
318 "scales",
319 [](const UniformQuantizedPerAxisType &type) {
321 std::vector<double> scales;
322 scales.reserve(nDim);
323 for (intptr_t i = 0; i < nDim; ++i) {
324 double scale = mlirUniformQuantizedPerAxisTypeGetScale(type, i);
325 scales.push_back(scale);
326 }
327 return scales;
328 },
329 "The scales designate the difference between the real values "
330 "corresponding to consecutive quantized values differing by 1. The ith "
331 "scale corresponds to the ith slice in the quantized_dimension.");
332 c.def_prop_ro(
333 "zero_points",
334 [](const UniformQuantizedPerAxisType &type) {
336 std::vector<int64_t> zeroPoints;
337 zeroPoints.reserve(nDim);
338 for (intptr_t i = 0; i < nDim; ++i) {
339 int64_t zeroPoint =
341 zeroPoints.push_back(zeroPoint);
342 }
343 return zeroPoints;
344 },
345 "the storage values corresponding to the real value 0 in the affine "
346 "equation. The ith zero point corresponds to the ith slice in the "
347 "quantized_dimension.");
348 c.def_prop_ro(
349 "quantized_dimension",
350 [](const UniformQuantizedPerAxisType &type) {
352 },
353 "Specifies the dimension of the shape that the scales and zero points "
354 "correspond to.");
355 c.def_prop_ro(
356 "is_fixed_point",
357 [](const UniformQuantizedPerAxisType &type) {
359 },
360 "Fixed point values are real numbers divided by a scale.");
361 }
362};
363
364//===-------------------------------------------------------------------===//
365// UniformQuantizedSubChannelType
366//===-------------------------------------------------------------------===//
367
369 : PyConcreteType<UniformQuantizedSubChannelType, QuantizedType> {
370 static constexpr IsAFunctionTy isaFunction =
374 static constexpr const char *pyClassName = "UniformQuantizedSubChannelType";
375 static inline const MlirStringRef name =
377 using Base::Base;
378
379 static void bindDerived(ClassTy &c) {
380 c.def_static(
381 "get",
382 [](unsigned flags, const PyType &storageType,
383 const PyType &expressedType, PyAttribute scales,
384 PyAttribute zeroPoints, std::vector<int32_t> quantizedDimensions,
385 std::vector<int64_t> blockSizes, int64_t storageTypeMin,
386 int64_t storageTypeMax, DefaultingPyMlirContext context) {
388 context->getRef(),
390 flags, storageType, expressedType, scales, zeroPoints,
391 static_cast<intptr_t>(blockSizes.size()),
392 quantizedDimensions.data(), blockSizes.data(), storageTypeMin,
393 storageTypeMax));
394 },
395 "Gets an instance of UniformQuantizedSubChannel in the same context as "
396 "the provided storage type.",
397 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
398 nb::arg("scales"), nb::arg("zero_points"),
399 nb::arg("quantized_dimensions"), nb::arg("block_sizes"),
400 nb::arg("storage_type_min"), nb::arg("storage_type_max"),
401 nb::arg("context") = nb::none());
402 c.def_prop_ro(
403 "quantized_dimensions",
404 [](const UniformQuantizedSubChannelType &type) {
405 intptr_t nDim =
407 std::vector<int32_t> quantizedDimensions;
408 quantizedDimensions.reserve(nDim);
409 for (intptr_t i = 0; i < nDim; ++i) {
410 quantizedDimensions.push_back(
412 i));
413 }
414 return quantizedDimensions;
415 },
416 "Gets the quantized dimensions. Each element in the returned list "
417 "represents an axis of the quantized data tensor that has a specified "
418 "block size. The order of elements corresponds to the order of block "
419 "sizes returned by 'block_sizes' method. It means that the data tensor "
420 "is quantized along the i-th dimension in the returned list using the "
421 "i-th block size from block_sizes method.");
422 c.def_prop_ro(
423 "block_sizes",
424 [](const UniformQuantizedSubChannelType &type) {
425 intptr_t nDim =
427 std::vector<int64_t> blockSizes;
428 blockSizes.reserve(nDim);
429 for (intptr_t i = 0; i < nDim; ++i) {
430 blockSizes.push_back(
432 }
433 return blockSizes;
434 },
435 "Gets the block sizes for the quantized dimensions. The i-th element "
436 "in "
437 "the returned list corresponds to the block size for the i-th "
438 "dimension "
439 "in the list returned by quantized_dimensions method.");
440 c.def_prop_ro(
441 "scales",
444 type.getContext(),
446 },
447 "The scales of the quantized type.");
448 c.def_prop_ro(
449 "zero_points",
452 type.getContext(),
454 },
455 "The zero points of the quantized type.");
456 }
457};
458
459//===-------------------------------------------------------------------===//
460// CalibratedQuantizedType
461//===-------------------------------------------------------------------===//
462
464 : PyConcreteType<CalibratedQuantizedType, QuantizedType> {
465 static constexpr IsAFunctionTy isaFunction =
469 static constexpr const char *pyClassName = "CalibratedQuantizedType";
471 using Base::Base;
472
473 static void bindDerived(ClassTy &c) {
474 c.def_static(
475 "get",
476 [](const PyType &expressedType, double min, double max,
477 DefaultingPyMlirContext context) {
479 context->getRef(),
480 mlirCalibratedQuantizedTypeGet(expressedType, min, max));
481 },
482 "Gets an instance of CalibratedQuantizedType in the same context as "
483 "the "
484 "provided expressed type.",
485 nb::arg("expressed_type"), nb::arg("min"), nb::arg("max"),
486 nb::arg("context") = nb::none());
487 c.def_prop_ro("min", [](const PyType &type) {
489 });
490 c.def_prop_ro("max", [](const PyType &type) {
492 });
493 }
494};
495
496static void populateDialectQuantSubmodule(nb::module_ &m) {
498
499 // Set the FLAG_SIGNED class attribute after binding QuantizedType
500 auto quantizedTypeClass = m.attr("QuantizedType");
501 quantizedTypeClass.attr("FLAG_SIGNED") = mlirQuantizedTypeGetSignedFlag();
502
508}
509} // namespace quant
510} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
511} // namespace python
512} // namespace mlir
513
514NB_MODULE(_mlirDialectsQuant, m) {
515 m.doc() = "MLIR Quantization dialect";
516
519}
NB_MODULE(_mlirDialectsQuant, m)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:278
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1001
Wrapper around the generic MlirType.
Definition IRCore.h:874
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:876
MLIR_CAPI_EXPORTED intptr_t mlirUniformQuantizedPerAxisTypeGetNumDims(MlirType type)
Returns the number of axes in the given quantized per-axis type.
Definition Quant.cpp:196
MLIR_CAPI_EXPORTED bool mlirTypeIsACalibratedQuantizedType(MlirType type)
Returns true if the given type is a CalibratedQuantizedType.
Definition Quant.cpp:289
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMaximumForInteger(bool isSigned, unsigned integralWidth)
Returns the maximum possible value stored by a quantized type.
Definition Quant.cpp:37
MLIR_CAPI_EXPORTED MlirTypeID mlirCalibratedQuantizedTypeGetTypeID(void)
Definition Quant.cpp:293
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized type is fixed-point.
Definition Quant.cpp:165
MLIR_CAPI_EXPORTED MlirAttribute mlirUniformQuantizedSubChannelTypeGetZeroPoints(MlirType type)
Returns the zero-points of the quantized type.
Definition Quant.cpp:280
MLIR_CAPI_EXPORTED MlirStringRef mlirUniformQuantizedPerAxisTypeGetName(void)
Definition Quant.cpp:192
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:59
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedType(MlirType type)
Returns true if the given type is a UniformQuantizedType.
Definition Quant.cpp:136
MLIR_CAPI_EXPORTED bool mlirTypeIsAQuantizedType(MlirType type)
Returns true if the given type is a quantization dialect type.
Definition Quant.cpp:23
MLIR_CAPI_EXPORTED double mlirUniformQuantizedPerAxisTypeGetScale(MlirType type, intptr_t pos)
Returns pos-th scale of the given quantized per-axis type.
Definition Quant.cpp:202
MLIR_CAPI_EXPORTED MlirAttribute mlirUniformQuantizedSubChannelTypeGetScales(MlirType type)
Returns the scales of the quantized type.
Definition Quant.cpp:275
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedTypeGetZeroPoint(MlirType type)
Returns the zero point of the given uniform quantized type.
Definition Quant.cpp:161
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized per-axis type is fixed-point.
Definition Quant.cpp:218
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedSubChannelTypeGetBlockSize(MlirType type, intptr_t pos)
Returns the block size at the given position.
Definition Quant.cpp:269
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:63
MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMax(MlirType type)
Returns the max value of the given calibrated quantized type.
Definition Quant.cpp:311
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:297
MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsSigned(MlirType type)
Returns true if the given type is signed, false otherwise.
Definition Quant.cpp:51
MLIR_CAPI_EXPORTED intptr_t mlirUniformQuantizedSubChannelTypeGetNumBlockSizes(MlirType type)
Returns the number of block sizes provided in type.
Definition Quant.cpp:257
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:207
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:213
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:98
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetExpressedType(MlirType type)
Gets the original type approximated by the given quantized type.
Definition Quant.cpp:43
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:67
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:120
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:87
MLIR_CAPI_EXPORTED MlirTypeID mlirAnyQuantizedTypeGetTypeID(void)
Definition Quant.cpp:116
MLIR_CAPI_EXPORTED MlirTypeID mlirUniformQuantizedTypeGetTypeID(void)
Definition Quant.cpp:140
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetStorageType(MlirType type)
Returns the underlying type used to store the values.
Definition Quant.cpp:55
MLIR_CAPI_EXPORTED MlirTypeID mlirUniformQuantizedPerAxisTypeGetTypeID(void)
Definition Quant.cpp:177
MLIR_CAPI_EXPORTED int32_t mlirUniformQuantizedSubChannelTypeGetQuantizedDimension(MlirType type, intptr_t pos)
Returns the quantized dimension at the given position.
Definition Quant.cpp:263
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:92
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedPerAxisType(MlirType type)
Returns true if the given type is a UniformQuantizedPerAxisType.
Definition Quant.cpp:173
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetQuantizedElementType(MlirType type)
Returns the element type of the given quantized type as another quantized type.
Definition Quant.cpp:77
MLIR_CAPI_EXPORTED bool mlirTypeIsAAnyQuantizedType(MlirType type)
Returns true if the given type is an AnyQuantizedType.
Definition Quant.cpp:112
MLIR_CAPI_EXPORTED MlirStringRef mlirAnyQuantizedTypeGetName(void)
Definition Quant.cpp:128
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:102
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:81
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetSignedFlag(void)
Returns the bit flag used to indicate signedness of a quantized type.
Definition Quant.cpp:27
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMinimumForInteger(bool isSigned, unsigned integralWidth)
Returns the minimum possible value stored by a quantized type.
Definition Quant.cpp:31
MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMin(MlirType type)
Returns the min value of the given calibrated quantized type.
Definition Quant.cpp:307
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetFlags(MlirType type)
Gets the flags associated with the given quantized type.
Definition Quant.cpp:47
MLIR_CAPI_EXPORTED MlirTypeID mlirUniformQuantizedSubChannelTypeGetTypeID(void)
Definition Quant.cpp:230
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:181
MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedSubChannelTypeGet(unsigned flags, MlirType storageType, MlirType expressedType, MlirAttribute scalesAttr, MlirAttribute zeroPointsAttr, intptr_t blockSizeInfoLength, int32_t *quantizedDimensions, int64_t *blockSizes, int64_t storageTypeMin, int64_t storageTypeMax)
Creates a UniformQuantizedSubChannelType with the given parameters.
Definition Quant.cpp:234
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:71
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedSubChannelType(MlirType type)
Returns true if the given type is a UniformQuantizedSubChannel.
Definition Quant.cpp:226
MLIR_CAPI_EXPORTED MlirStringRef mlirUniformQuantizedSubChannelTypeGetName(void)
Definition Quant.cpp:253
MLIR_CAPI_EXPORTED MlirStringRef mlirCalibratedQuantizedTypeGetName(void)
Definition Quant.cpp:303
MLIR_CAPI_EXPORTED double mlirUniformQuantizedTypeGetScale(MlirType type)
Returns the scale of the given uniform quantized type.
Definition Quant.cpp:157
MLIR_CAPI_EXPORTED MlirStringRef mlirUniformQuantizedTypeGetName(void)
Definition Quant.cpp:153
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:144
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
Definition IR.h:1160
static void populateDialectQuantSubmodule(nb::module_ &m)
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78