30 quantizedType.def_staticmethod(
31 "default_minimum_for_integer",
32 [](
bool isSigned,
unsigned integralWidth) {
36 "Default minimum value for the integer with the specified signedness and "
38 nb::arg(
"is_signed"), nb::arg(
"integral_width"));
39 quantizedType.def_staticmethod(
40 "default_maximum_for_integer",
41 [](
bool isSigned,
unsigned integralWidth) {
45 "Default maximum value for the integer with the specified signedness and "
47 nb::arg(
"is_signed"), nb::arg(
"integral_width"));
48 quantizedType.def_property_readonly(
51 "Type expressed by this quantized type.");
52 quantizedType.def_property_readonly(
54 "Flags of this quantized type (named accessors should be preferred to "
56 quantizedType.def_property_readonly(
59 "Signedness of this quantized type.");
60 quantizedType.def_property_readonly(
63 "Storage type backing this quantized type.");
64 quantizedType.def_property_readonly(
67 "The minimum value held by the storage type of this quantized type.");
68 quantizedType.def_property_readonly(
71 "The maximum value held by the storage type of this quantized type.");
72 quantizedType.def_property_readonly(
73 "storage_type_integral_width",
77 "The bitwidth of the storage type of this quantized type.");
79 "is_compatible_expressed_type",
80 [](MlirType type, MlirType candidate) {
83 "Checks whether the candidate type can be expressed by this quantized "
85 nb::arg(
"candidate"));
86 quantizedType.def_property_readonly(
87 "quantized_element_type",
91 "Element type of this quantized type expressed as quantized type.");
93 "cast_from_storage_type",
94 [](MlirType type, MlirType candidate) {
99 throw nb::type_error(
"Invalid cast.");
101 "Casts from a type based on the storage type of this quantized type to a "
102 "corresponding type based on the quantized type. Raises TypeError if the "
103 "cast is not valid.",
104 nb::arg(
"candidate"));
105 quantizedType.def_staticmethod(
106 "cast_to_storage_type",
111 throw nb::type_error(
"Invalid cast.");
113 "Casts from a type based on a quantized type to a corresponding type "
114 "based on the storage type of this quantized type. Raises TypeError if "
115 "the cast is not valid.",
118 "cast_from_expressed_type",
119 [](MlirType type, MlirType candidate) {
120 MlirType castResult =
124 throw nb::type_error(
"Invalid cast.");
126 "Casts from a type based on the expressed type of this quantized type to "
127 "a corresponding type based on the quantized type. Raises TypeError if "
128 "the cast is not valid.",
129 nb::arg(
"candidate"));
130 quantizedType.def_staticmethod(
131 "cast_to_expressed_type",
136 throw nb::type_error(
"Invalid cast.");
138 "Casts from a type based on a quantized type to a corresponding type "
139 "based on the expressed type of this quantized type. Raises TypeError if "
140 "the cast is not valid.",
143 "cast_expressed_to_storage_type",
144 [](MlirType type, MlirType candidate) {
145 MlirType castResult =
149 throw nb::type_error(
"Invalid cast.");
151 "Casts from a type based on the expressed type of this quantized type to "
152 "a corresponding type based on the storage type. Raises TypeError if the "
153 "cast is not valid.",
154 nb::arg(
"candidate"));
156 quantizedType.get_class().attr(
"FLAG_SIGNED") =
163 auto anyQuantizedType =
165 quantizedType.get_class());
166 anyQuantizedType.def_classmethod(
168 [](nb::object cls,
unsigned flags, MlirType storageType,
169 MlirType expressedType, int64_t storageTypeMin,
170 int64_t storageTypeMax) {
172 storageTypeMin, storageTypeMax));
174 "Gets an instance of AnyQuantizedType in the same context as the "
175 "provided storage type.",
176 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
177 nb::arg(
"expressed_type"), nb::arg(
"storage_type_min"),
178 nb::arg(
"storage_type_max"));
186 quantizedType.get_class());
187 uniformQuantizedType.def_classmethod(
189 [](nb::object cls,
unsigned flags, MlirType storageType,
190 MlirType expressedType,
double scale, int64_t zeroPoint,
191 int64_t storageTypeMin, int64_t storageTypeMax) {
193 expressedType, scale, zeroPoint,
194 storageTypeMin, storageTypeMax));
196 "Gets an instance of UniformQuantizedType in the same context as the "
197 "provided storage type.",
198 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
199 nb::arg(
"expressed_type"), nb::arg(
"scale"), nb::arg(
"zero_point"),
200 nb::arg(
"storage_type_min"), nb::arg(
"storage_type_max"));
201 uniformQuantizedType.def_property_readonly(
204 "The scale designates the difference between the real values "
205 "corresponding to consecutive quantized values differing by 1.");
206 uniformQuantizedType.def_property_readonly(
209 "The storage value corresponding to the real value 0 in the affine "
211 uniformQuantizedType.def_property_readonly(
214 "Fixed point values are real numbers divided by a scale.");
221 quantizedType.get_class());
222 uniformQuantizedPerAxisType.def_classmethod(
224 [](nb::object cls,
unsigned flags, MlirType storageType,
225 MlirType expressedType, std::vector<double> scales,
226 std::vector<int64_t> zeroPoints, int32_t quantizedDimension,
227 int64_t storageTypeMin, int64_t storageTypeMax) {
228 if (scales.size() != zeroPoints.size())
229 throw nb::value_error(
230 "Mismatching number of scales and zero points.");
231 auto nDims =
static_cast<intptr_t
>(scales.size());
233 flags, storageType, expressedType, nDims, scales.data(),
234 zeroPoints.data(), quantizedDimension, storageTypeMin,
237 "Gets an instance of UniformQuantizedPerAxisType in the same context as "
238 "the provided storage type.",
239 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
240 nb::arg(
"expressed_type"), nb::arg(
"scales"), nb::arg(
"zero_points"),
241 nb::arg(
"quantized_dimension"), nb::arg(
"storage_type_min"),
242 nb::arg(
"storage_type_max"));
243 uniformQuantizedPerAxisType.def_property_readonly(
247 std::vector<double> scales;
248 scales.reserve(nDim);
249 for (intptr_t i = 0; i < nDim; ++i) {
251 scales.push_back(scale);
255 "The scales designate the difference between the real values "
256 "corresponding to consecutive quantized values differing by 1. The ith "
257 "scale corresponds to the ith slice in the quantized_dimension.");
258 uniformQuantizedPerAxisType.def_property_readonly(
262 std::vector<int64_t> zeroPoints;
263 zeroPoints.reserve(nDim);
264 for (intptr_t i = 0; i < nDim; ++i) {
267 zeroPoints.push_back(zeroPoint);
271 "the storage values corresponding to the real value 0 in the affine "
272 "equation. The ith zero point corresponds to the ith slice in the "
273 "quantized_dimension.");
274 uniformQuantizedPerAxisType.def_property_readonly(
275 "quantized_dimension",
279 "Specifies the dimension of the shape that the scales and zero points "
281 uniformQuantizedPerAxisType.def_property_readonly(
286 "Fixed point values are real numbers divided by a scale.");
292 m,
"UniformQuantizedSubChannelType",
294 uniformQuantizedSubChannelType.def_classmethod(
296 [](nb::object cls,
unsigned flags, MlirType storageType,
297 MlirType expressedType, MlirAttribute scales, MlirAttribute zeroPoints,
298 std::vector<int32_t> quantizedDimensions,
299 std::vector<int64_t> blockSizes, int64_t storageTypeMin,
300 int64_t storageTypeMax) {
302 flags, storageType, expressedType, scales, zeroPoints,
303 static_cast<intptr_t
>(blockSizes.size()),
304 quantizedDimensions.data(), blockSizes.data(), storageTypeMin,
307 "Gets an instance of UniformQuantizedSubChannel in the same context as "
308 "the provided storage type.",
309 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
310 nb::arg(
"expressed_type"), nb::arg(
"scales"), nb::arg(
"zero_points"),
311 nb::arg(
"quantized_dimensions"), nb::arg(
"block_sizes"),
312 nb::arg(
"storage_type_min"), nb::arg(
"storage_type_max"));
313 uniformQuantizedSubChannelType.def_property_readonly(
314 "quantized_dimensions",
318 std::vector<int32_t> quantizedDimensions;
319 quantizedDimensions.reserve(nDim);
320 for (intptr_t i = 0; i < nDim; ++i) {
321 quantizedDimensions.push_back(
324 return quantizedDimensions;
326 "Gets the quantized dimensions. Each element in the returned list "
327 "represents an axis of the quantized data tensor that has a specified "
328 "block size. The order of elements corresponds to the order of block "
329 "sizes returned by 'block_sizes' method. It means that the data tensor "
330 "is quantized along the i-th dimension in the returned list using the "
331 "i-th block size from block_sizes method.");
332 uniformQuantizedSubChannelType.def_property_readonly(
337 std::vector<int64_t> blockSizes;
338 blockSizes.reserve(nDim);
339 for (intptr_t i = 0; i < nDim; ++i) {
340 blockSizes.push_back(
345 "Gets the block sizes for the quantized dimensions. The i-th element in "
346 "the returned list corresponds to the block size for the i-th dimension "
347 "in the list returned by quantized_dimensions method.");
348 uniformQuantizedSubChannelType.def_property_readonly(
350 [](MlirType type) -> MlirAttribute {
353 "The scales of the quantized type.");
354 uniformQuantizedSubChannelType.def_property_readonly(
356 [](MlirType type) -> MlirAttribute {
359 "The zero points of the quantized type.");
367 quantizedType.get_class());
368 calibratedQuantizedType.def_classmethod(
370 [](nb::object cls, MlirType expressedType,
double min,
double max) {
373 "Gets an instance of CalibratedQuantizedType in the same context as the "
374 "provided expressed type.",
375 nb::arg(
"cls"), nb::arg(
"expressed_type"), nb::arg(
"min"),
377 calibratedQuantizedType.def_property_readonly(
"min", [](MlirType type) {
380 calibratedQuantizedType.def_property_readonly(
"max", [](MlirType type) {
386 m.doc() =
"MLIR Quantization dialect";
static void populateDialectQuantSubmodule(const nb::module_ &m)
NB_MODULE(_mlirDialectsQuant, m)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
Creates a custom subclass of mlir.ir.Type, implementing a casting constructor and type checking metho...
MLIR_CAPI_EXPORTED intptr_t mlirUniformQuantizedPerAxisTypeGetNumDims(MlirType type)
Returns the number of axes in the given quantized per-axis type.
MLIR_CAPI_EXPORTED bool mlirTypeIsACalibratedQuantizedType(MlirType type)
Returns true if the given type is a CalibratedQuantizedType.
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMaximumForInteger(bool isSigned, unsigned integralWidth)
Returns the maximum possible value stored by a quantized type.
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized type is fixed-point.
MLIR_CAPI_EXPORTED MlirAttribute mlirUniformQuantizedSubChannelTypeGetZeroPoints(MlirType type)
Returns the zero-points of the quantized type.
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMin(MlirType type)
Returns the minimum value that the storage type of the given quantized type can take.
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedType(MlirType type)
Returns true if the given type is a UniformQuantizedType.
MLIR_CAPI_EXPORTED bool mlirTypeIsAQuantizedType(MlirType type)
Returns true if the given type is a quantization dialect type.
MLIR_CAPI_EXPORTED double mlirUniformQuantizedPerAxisTypeGetScale(MlirType type, intptr_t pos)
Returns pos-th scale of the given quantized per-axis type.
MLIR_CAPI_EXPORTED MlirAttribute mlirUniformQuantizedSubChannelTypeGetScales(MlirType type)
Returns the scales of the quantized type.
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedTypeGetZeroPoint(MlirType type)
Returns the zero point of the given uniform quantized type.
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized per-axis type is fixed-point.
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedSubChannelTypeGetBlockSize(MlirType type, intptr_t pos)
Returns the block size at the given position.
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMax(MlirType type)
Returns the maximum value that the storage type of the given quantized type can take.
MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMax(MlirType type)
Returns the max value of the given calibrated quantized type.
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...
MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsSigned(MlirType type)
Returns true if the given type is signed, false otherwise.
MLIR_CAPI_EXPORTED intptr_t mlirUniformQuantizedSubChannelTypeGetNumBlockSizes(MlirType type)
Returns the number of block sizes provided in type.
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedPerAxisTypeGetZeroPoint(MlirType type, intptr_t pos)
Returns pos-th zero point of the given quantized per-axis type.
MLIR_CAPI_EXPORTED int32_t mlirUniformQuantizedPerAxisTypeGetQuantizedDimension(MlirType type)
Returns the index of the quantized dimension in the given quantized per-axis type.
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.
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetExpressedType(MlirType type)
Gets the original type approximated by the given quantized type.
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetStorageTypeIntegralWidth(MlirType type)
Returns the integral bitwidth that the storage type of the given quantized type can represent exactly...
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 ...
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.
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetStorageType(MlirType type)
Returns the underlying type used to store the values.
MLIR_CAPI_EXPORTED int32_t mlirUniformQuantizedSubChannelTypeGetQuantizedDimension(MlirType type, intptr_t pos)
Returns the quantized dimension at the given position.
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 ...
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedPerAxisType(MlirType type)
Returns true if the given type is a UniformQuantizedPerAxisType.
MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetQuantizedElementType(MlirType type)
Returns the element type of the given quantized type as another quantized type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAAnyQuantizedType(MlirType type)
Returns true if the given type is an AnyQuantizedType.
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...
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...
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetSignedFlag(void)
Returns the bit flag used to indicate signedness of a quantized type.
MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMinimumForInteger(bool isSigned, unsigned integralWidth)
Returns the minimum possible value stored by a quantized type.
MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMin(MlirType type)
Returns the min value of the given calibrated quantized type.
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetFlags(MlirType type)
Gets the flags associated with the given quantized type.
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...
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.
MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate)
Returns true if the candidate type is compatible with the given quantized type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedSubChannelType(MlirType type)
Returns true if the given type is a UniformQuantizedSubChannel.
MLIR_CAPI_EXPORTED double mlirUniformQuantizedTypeGetScale(MlirType type)
Returns the scale of the given uniform quantized type.
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...
static bool mlirTypeIsNull(MlirType type)
Checks whether a type is null.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.