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;
20using namespace llvm;
22
23namespace mlir {
24namespace python {
26namespace quant {
27//===-------------------------------------------------------------------===//
28// QuantizedType
29//===-------------------------------------------------------------------===//
30
31struct QuantizedType : PyConcreteType<QuantizedType> {
33 static constexpr const char *pyClassName = "QuantizedType";
34 using Base::Base;
35
36 static void bindDerived(ClassTy &c) {
37 c.def_static(
38 "default_minimum_for_integer",
39 [](bool isSigned, unsigned integralWidth) {
41 integralWidth);
42 },
43 "Default minimum value for the integer with the specified signedness "
44 "and "
45 "bit width.",
46 nb::arg("is_signed"), nb::arg("integral_width"));
47 c.def_static(
48 "default_maximum_for_integer",
49 [](bool isSigned, unsigned integralWidth) {
51 integralWidth);
52 },
53 "Default maximum value for the integer with the specified signedness "
54 "and "
55 "bit width.",
56 nb::arg("is_signed"), nb::arg("integral_width"));
57 c.def_prop_ro(
58 "expressed_type",
59 [](QuantizedType &type) {
60 return PyType(type.getContext(),
62 .maybeDownCast();
63 },
64 "Type expressed by this quantized type.");
65 c.def_prop_ro(
66 "flags",
67 [](const QuantizedType &type) {
68 return mlirQuantizedTypeGetFlags(type);
69 },
70 "Flags of this quantized type (named accessors should be preferred to "
71 "this)");
72 c.def_prop_ro(
73 "is_signed",
74 [](const QuantizedType &type) {
75 return mlirQuantizedTypeIsSigned(type);
76 },
77 "Signedness of this quantized type.");
78 c.def_prop_ro(
79 "storage_type",
80 [](QuantizedType &type) {
81 return PyType(type.getContext(),
83 .maybeDownCast();
84 },
85 "Storage type backing this quantized type.");
86 c.def_prop_ro(
87 "storage_type_min",
88 [](const QuantizedType &type) {
90 },
91 "The minimum value held by the storage type of this quantized type.");
92 c.def_prop_ro(
93 "storage_type_max",
94 [](const QuantizedType &type) {
96 },
97 "The maximum value held by the storage type of this quantized type.");
98 c.def_prop_ro(
99 "storage_type_integral_width",
100 [](const QuantizedType &type) {
102 },
103 "The bitwidth of the storage type of this quantized type.");
104 c.def(
105 "is_compatible_expressed_type",
106 [](const QuantizedType &type, const PyType &candidate) {
107 return mlirQuantizedTypeIsCompatibleExpressedType(type, candidate);
108 },
109 "Checks whether the candidate type can be expressed by this quantized "
110 "type.",
111 nb::arg("candidate"));
112 c.def_prop_ro(
113 "quantized_element_type",
114 [](QuantizedType &type) {
115 return PyType(type.getContext(),
117 .maybeDownCast();
118 },
119 "Element type of this quantized type expressed as quantized type.");
120 c.def(
121 "cast_from_storage_type",
122 [](QuantizedType &type, const PyType &candidate) {
123 MlirType castResult =
125 if (!mlirTypeIsNull(castResult))
126 return QuantizedType(type.getContext(), castResult);
127 throw nb::type_error("Invalid cast.");
128 },
129 "Casts from a type based on the storage type of this quantized type to "
130 "a "
131 "corresponding type based on the quantized type. Raises TypeError if "
132 "the "
133 "cast is not valid.",
134 nb::arg("candidate"));
135 c.def_static(
136 "cast_to_storage_type",
137 [](PyType &type) {
138 MlirType castResult = mlirQuantizedTypeCastToStorageType(type);
139 if (!mlirTypeIsNull(castResult))
140 return PyType(type.getContext(), castResult).maybeDownCast();
141 throw nb::type_error("Invalid cast.");
142 },
143 "Casts from a type based on a quantized type to a corresponding type "
144 "based on the storage type of this quantized type. Raises TypeError if "
145 "the cast is not valid.",
146 nb::arg("type"));
147 c.def(
148 "cast_from_expressed_type",
149 [](QuantizedType &type, const PyType &candidate) {
150 MlirType castResult =
152 if (!mlirTypeIsNull(castResult))
153 return PyType(type.getContext(), castResult).maybeDownCast();
154 throw nb::type_error("Invalid cast.");
155 },
156 "Casts from a type based on the expressed type of this quantized type "
157 "to "
158 "a corresponding type based on the quantized type. Raises TypeError if "
159 "the cast is not valid.",
160 nb::arg("candidate"));
161 c.def_static(
162 "cast_to_expressed_type",
163 [](PyType &type) {
164 MlirType castResult = mlirQuantizedTypeCastToExpressedType(type);
165 if (!mlirTypeIsNull(castResult))
166 return PyType(type.getContext(), castResult).maybeDownCast();
167 throw nb::type_error("Invalid cast.");
168 },
169 "Casts from a type based on a quantized type to a corresponding type "
170 "based on the expressed type of this quantized type. Raises TypeError "
171 "if "
172 "the cast is not valid.",
173 nb::arg("type"));
174 c.def(
175 "cast_expressed_to_storage_type",
176 [](QuantizedType &type, const PyType &candidate) {
177 MlirType castResult =
179 if (!mlirTypeIsNull(castResult))
180 return PyType(type.getContext(), castResult).maybeDownCast();
181 throw nb::type_error("Invalid cast.");
182 },
183 "Casts from a type based on the expressed type of this quantized type "
184 "to "
185 "a corresponding type based on the storage type. Raises TypeError if "
186 "the "
187 "cast is not valid.",
188 nb::arg("candidate"));
189 }
190};
191
192//===-------------------------------------------------------------------===//
193// AnyQuantizedType
194//===-------------------------------------------------------------------===//
195
196struct AnyQuantizedType : PyConcreteType<AnyQuantizedType, QuantizedType> {
200 static constexpr const char *pyClassName = "AnyQuantizedType";
202 using Base::Base;
203
204 static void bindDerived(ClassTy &c) {
205 c.def_static(
206 "get",
207 [](unsigned flags, const PyType &storageType,
208 const PyType &expressedType, int64_t storageTypeMin,
209 int64_t storageTypeMax, DefaultingPyMlirContext context) {
210 return AnyQuantizedType(
211 context->getRef(),
212 mlirAnyQuantizedTypeGet(flags, storageType, expressedType,
213 storageTypeMin, storageTypeMax));
214 },
215 "Gets an instance of AnyQuantizedType in the same context as the "
216 "provided storage type.",
217 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
218 nb::arg("storage_type_min"), nb::arg("storage_type_max"),
219 nb::arg("context") = nb::none());
220 }
221};
222
223//===-------------------------------------------------------------------===//
224// UniformQuantizedType
225//===-------------------------------------------------------------------===//
226
228 : PyConcreteType<UniformQuantizedType, QuantizedType> {
232 static constexpr const char *pyClassName = "UniformQuantizedType";
234 using Base::Base;
235
236 static void bindDerived(ClassTy &c) {
237 c.def_static(
238 "get",
239 [](unsigned flags, const PyType &storageType,
240 const PyType &expressedType, double scale, int64_t zeroPoint,
241 int64_t storageTypeMin, int64_t storageTypeMax,
242 DefaultingPyMlirContext context) {
244 context->getRef(),
245 mlirUniformQuantizedTypeGet(flags, storageType, expressedType,
246 scale, zeroPoint, storageTypeMin,
247 storageTypeMax));
248 },
249 "Gets an instance of UniformQuantizedType in the same context as the "
250 "provided storage type.",
251 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
252 nb::arg("scale"), nb::arg("zero_point"), nb::arg("storage_type_min"),
253 nb::arg("storage_type_max"), nb::arg("context") = nb::none());
254 c.def_prop_ro(
255 "scale",
256 [](const UniformQuantizedType &type) {
258 },
259 "The scale designates the difference between the real values "
260 "corresponding to consecutive quantized values differing by 1.");
261 c.def_prop_ro(
262 "zero_point",
263 [](const UniformQuantizedType &type) {
265 },
266 "The storage value corresponding to the real value 0 in the affine "
267 "equation.");
268 c.def_prop_ro(
269 "is_fixed_point",
270 [](const UniformQuantizedType &type) {
272 },
273 "Fixed point values are real numbers divided by a scale.");
274 }
275};
276
277//===-------------------------------------------------------------------===//
278// UniformQuantizedPerAxisType
279//===-------------------------------------------------------------------===//
280
282 : PyConcreteType<UniformQuantizedPerAxisType, QuantizedType> {
283 static constexpr IsAFunctionTy isaFunction =
287 static constexpr const char *pyClassName = "UniformQuantizedPerAxisType";
288 static inline const MlirStringRef name =
290 using Base::Base;
291
292 static void bindDerived(ClassTy &c) {
293 c.def_static(
294 "get",
295 [](unsigned flags, const PyType &storageType,
296 const PyType &expressedType, std::vector<double> scales,
297 std::vector<int64_t> zeroPoints, int32_t quantizedDimension,
298 int64_t storageTypeMin, int64_t storageTypeMax,
299 DefaultingPyMlirContext context) {
300 if (scales.size() != zeroPoints.size())
301 throw nb::value_error(
302 "Mismatching number of scales and zero points.");
303 auto nDims = static_cast<intptr_t>(scales.size());
305 context->getRef(),
307 flags, storageType, expressedType, nDims, scales.data(),
308 zeroPoints.data(), quantizedDimension, storageTypeMin,
309 storageTypeMax));
310 },
311 "Gets an instance of UniformQuantizedPerAxisType in the same context "
312 "as "
313 "the provided storage type.",
314 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
315 nb::arg("scales"), nb::arg("zero_points"),
316 nb::arg("quantized_dimension"), nb::arg("storage_type_min"),
317 nb::arg("storage_type_max"), nb::arg("context") = nb::none());
318 c.def_prop_ro(
319 "scales",
320 [](const UniformQuantizedPerAxisType &type) {
322 std::vector<double> scales;
323 scales.reserve(nDim);
324 for (intptr_t i = 0; i < nDim; ++i) {
325 double scale = mlirUniformQuantizedPerAxisTypeGetScale(type, i);
326 scales.push_back(scale);
327 }
328 return scales;
329 },
330 "The scales designate the difference between the real values "
331 "corresponding to consecutive quantized values differing by 1. The ith "
332 "scale corresponds to the ith slice in the quantized_dimension.");
333 c.def_prop_ro(
334 "zero_points",
335 [](const UniformQuantizedPerAxisType &type) {
337 std::vector<int64_t> zeroPoints;
338 zeroPoints.reserve(nDim);
339 for (intptr_t i = 0; i < nDim; ++i) {
340 int64_t zeroPoint =
342 zeroPoints.push_back(zeroPoint);
343 }
344 return zeroPoints;
345 },
346 "the storage values corresponding to the real value 0 in the affine "
347 "equation. The ith zero point corresponds to the ith slice in the "
348 "quantized_dimension.");
349 c.def_prop_ro(
350 "quantized_dimension",
351 [](const UniformQuantizedPerAxisType &type) {
353 },
354 "Specifies the dimension of the shape that the scales and zero points "
355 "correspond to.");
356 c.def_prop_ro(
357 "is_fixed_point",
358 [](const UniformQuantizedPerAxisType &type) {
360 },
361 "Fixed point values are real numbers divided by a scale.");
362 }
363};
364
365//===-------------------------------------------------------------------===//
366// UniformQuantizedSubChannelType
367//===-------------------------------------------------------------------===//
368
370 : PyConcreteType<UniformQuantizedSubChannelType, QuantizedType> {
371 static constexpr IsAFunctionTy isaFunction =
375 static constexpr const char *pyClassName = "UniformQuantizedSubChannelType";
376 static inline const MlirStringRef name =
378 using Base::Base;
379
380 static void bindDerived(ClassTy &c) {
381 c.def_static(
382 "get",
383 [](unsigned flags, const PyType &storageType,
384 const PyType &expressedType, PyAttribute scales,
385 PyAttribute zeroPoints, std::vector<int32_t> quantizedDimensions,
386 std::vector<int64_t> blockSizes, int64_t storageTypeMin,
387 int64_t storageTypeMax, DefaultingPyMlirContext context) {
389 context->getRef(),
391 flags, storageType, expressedType, scales, zeroPoints,
392 static_cast<intptr_t>(blockSizes.size()),
393 quantizedDimensions.data(), blockSizes.data(), storageTypeMin,
394 storageTypeMax));
395 },
396 "Gets an instance of UniformQuantizedSubChannel in the same context as "
397 "the provided storage type.",
398 nb::arg("flags"), nb::arg("storage_type"), nb::arg("expressed_type"),
399 nb::arg("scales"), nb::arg("zero_points"),
400 nb::arg("quantized_dimensions"), nb::arg("block_sizes"),
401 nb::arg("storage_type_min"), nb::arg("storage_type_max"),
402 nb::arg("context") = nb::none());
403 c.def_prop_ro(
404 "quantized_dimensions",
405 [](const UniformQuantizedSubChannelType &type) {
406 intptr_t nDim =
408 std::vector<int32_t> quantizedDimensions;
409 quantizedDimensions.reserve(nDim);
410 for (intptr_t i = 0; i < nDim; ++i) {
411 quantizedDimensions.push_back(
413 i));
414 }
415 return quantizedDimensions;
416 },
417 "Gets the quantized dimensions. Each element in the returned list "
418 "represents an axis of the quantized data tensor that has a specified "
419 "block size. The order of elements corresponds to the order of block "
420 "sizes returned by 'block_sizes' method. It means that the data tensor "
421 "is quantized along the i-th dimension in the returned list using the "
422 "i-th block size from block_sizes method.");
423 c.def_prop_ro(
424 "block_sizes",
425 [](const UniformQuantizedSubChannelType &type) {
426 intptr_t nDim =
428 std::vector<int64_t> blockSizes;
429 blockSizes.reserve(nDim);
430 for (intptr_t i = 0; i < nDim; ++i) {
431 blockSizes.push_back(
433 }
434 return blockSizes;
435 },
436 "Gets the block sizes for the quantized dimensions. The i-th element "
437 "in "
438 "the returned list corresponds to the block size for the i-th "
439 "dimension "
440 "in the list returned by quantized_dimensions method.");
441 c.def_prop_ro(
442 "scales",
445 type.getContext(),
447 },
448 "The scales of the quantized type.");
449 c.def_prop_ro(
450 "zero_points",
453 type.getContext(),
455 },
456 "The zero points of the quantized type.");
457 }
458};
459
460//===-------------------------------------------------------------------===//
461// CalibratedQuantizedType
462//===-------------------------------------------------------------------===//
463
465 : PyConcreteType<CalibratedQuantizedType, QuantizedType> {
466 static constexpr IsAFunctionTy isaFunction =
470 static constexpr const char *pyClassName = "CalibratedQuantizedType";
472 using Base::Base;
473
474 static void bindDerived(ClassTy &c) {
475 c.def_static(
476 "get",
477 [](const PyType &expressedType, double min, double max,
478 DefaultingPyMlirContext context) {
480 context->getRef(),
481 mlirCalibratedQuantizedTypeGet(expressedType, min, max));
482 },
483 "Gets an instance of CalibratedQuantizedType in the same context as "
484 "the "
485 "provided expressed type.",
486 nb::arg("expressed_type"), nb::arg("min"), nb::arg("max"),
487 nb::arg("context") = nb::none());
488 c.def_prop_ro("min", [](const PyType &type) {
490 });
491 c.def_prop_ro("max", [](const PyType &type) {
493 });
494 }
495};
496
497static void populateDialectQuantSubmodule(nb::module_ &m) {
499
500 // Set the FLAG_SIGNED class attribute after binding QuantizedType
501 auto quantizedTypeClass = m.attr("QuantizedType");
502 quantizedTypeClass.attr("FLAG_SIGNED") = mlirQuantizedTypeGetSignedFlag();
503
509}
510} // namespace quant
511} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
512} // namespace python
513} // namespace mlir
514
515NB_MODULE(_mlirDialectsQuant, m) {
516 m.doc() = "MLIR Quantization dialect";
517
520}
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:280
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1009
Wrapper around the generic MlirType.
Definition IRCore.h:876
PyType(PyMlirContextRef contextRef, MlirType type)
Definition IRCore.h:878
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:1156
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
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:75