29 quantizedType.def_staticmethod(
30 "default_minimum_for_integer",
31 [](
bool isSigned,
unsigned integralWidth) {
35 "Default minimum value for the integer with the specified signedness and "
37 nb::arg(
"is_signed"), nb::arg(
"integral_width"));
38 quantizedType.def_staticmethod(
39 "default_maximum_for_integer",
40 [](
bool isSigned,
unsigned integralWidth) {
44 "Default maximum value for the integer with the specified signedness and "
46 nb::arg(
"is_signed"), nb::arg(
"integral_width"));
47 quantizedType.def_property_readonly(
50 "Type expressed by this quantized type.");
51 quantizedType.def_property_readonly(
53 "Flags of this quantized type (named accessors should be preferred to "
55 quantizedType.def_property_readonly(
58 "Signedness of this quantized type.");
59 quantizedType.def_property_readonly(
62 "Storage type backing this quantized type.");
63 quantizedType.def_property_readonly(
66 "The minimum value held by the storage type of this quantized type.");
67 quantizedType.def_property_readonly(
70 "The maximum value held by the storage type of this quantized type.");
71 quantizedType.def_property_readonly(
72 "storage_type_integral_width",
76 "The bitwidth of the storage type of this quantized type.");
78 "is_compatible_expressed_type",
79 [](MlirType type, MlirType candidate) {
82 "Checks whether the candidate type can be expressed by this quantized "
84 nb::arg(
"candidate"));
85 quantizedType.def_property_readonly(
86 "quantized_element_type",
90 "Element type of this quantized type expressed as quantized type.");
92 "cast_from_storage_type",
93 [](MlirType type, MlirType candidate) {
98 throw nb::type_error(
"Invalid cast.");
100 "Casts from a type based on the storage type of this quantized type to a "
101 "corresponding type based on the quantized type. Raises TypeError if the "
102 "cast is not valid.",
103 nb::arg(
"candidate"));
104 quantizedType.def_staticmethod(
105 "cast_to_storage_type",
110 throw nb::type_error(
"Invalid cast.");
112 "Casts from a type based on a quantized type to a corresponding type "
113 "based on the storage type of this quantized type. Raises TypeError if "
114 "the cast is not valid.",
117 "cast_from_expressed_type",
118 [](MlirType type, MlirType candidate) {
119 MlirType castResult =
123 throw nb::type_error(
"Invalid cast.");
125 "Casts from a type based on the expressed type of this quantized type to "
126 "a corresponding type based on the quantized type. Raises TypeError if "
127 "the cast is not valid.",
128 nb::arg(
"candidate"));
129 quantizedType.def_staticmethod(
130 "cast_to_expressed_type",
135 throw nb::type_error(
"Invalid cast.");
137 "Casts from a type based on a quantized type to a corresponding type "
138 "based on the expressed type of this quantized type. Raises TypeError if "
139 "the cast is not valid.",
142 "cast_expressed_to_storage_type",
143 [](MlirType type, MlirType candidate) {
144 MlirType castResult =
148 throw nb::type_error(
"Invalid cast.");
150 "Casts from a type based on the expressed type of this quantized type to "
151 "a corresponding type based on the storage type. Raises TypeError if the "
152 "cast is not valid.",
153 nb::arg(
"candidate"));
155 quantizedType.get_class().attr(
"FLAG_SIGNED") =
162 auto anyQuantizedType =
164 quantizedType.get_class());
165 anyQuantizedType.def_classmethod(
167 [](nb::object cls,
unsigned flags, MlirType storageType,
168 MlirType expressedType, int64_t storageTypeMin,
169 int64_t storageTypeMax) {
171 storageTypeMin, storageTypeMax));
173 "Gets an instance of AnyQuantizedType in the same context as the "
174 "provided storage type.",
175 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
176 nb::arg(
"expressed_type"), nb::arg(
"storage_type_min"),
177 nb::arg(
"storage_type_max"));
185 quantizedType.get_class());
186 uniformQuantizedType.def_classmethod(
188 [](nb::object cls,
unsigned flags, MlirType storageType,
189 MlirType expressedType,
double scale, int64_t zeroPoint,
190 int64_t storageTypeMin, int64_t storageTypeMax) {
192 expressedType, scale, zeroPoint,
193 storageTypeMin, storageTypeMax));
195 "Gets an instance of UniformQuantizedType in the same context as the "
196 "provided storage type.",
197 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
198 nb::arg(
"expressed_type"), nb::arg(
"scale"), nb::arg(
"zero_point"),
199 nb::arg(
"storage_type_min"), nb::arg(
"storage_type_max"));
200 uniformQuantizedType.def_property_readonly(
203 "The scale designates the difference between the real values "
204 "corresponding to consecutive quantized values differing by 1.");
205 uniformQuantizedType.def_property_readonly(
208 "The storage value corresponding to the real value 0 in the affine "
210 uniformQuantizedType.def_property_readonly(
213 "Fixed point values are real numbers divided by a scale.");
220 quantizedType.get_class());
221 uniformQuantizedPerAxisType.def_classmethod(
223 [](nb::object cls,
unsigned flags, MlirType storageType,
224 MlirType expressedType, std::vector<double> scales,
225 std::vector<int64_t> zeroPoints, int32_t quantizedDimension,
226 int64_t storageTypeMin, int64_t storageTypeMax) {
227 if (scales.size() != zeroPoints.size())
228 throw nb::value_error(
229 "Mismatching number of scales and zero points.");
230 auto nDims =
static_cast<intptr_t
>(scales.size());
232 flags, storageType, expressedType, nDims, scales.data(),
233 zeroPoints.data(), quantizedDimension, storageTypeMin,
236 "Gets an instance of UniformQuantizedPerAxisType in the same context as "
237 "the provided storage type.",
238 nb::arg(
"cls"), nb::arg(
"flags"), nb::arg(
"storage_type"),
239 nb::arg(
"expressed_type"), nb::arg(
"scales"), nb::arg(
"zero_points"),
240 nb::arg(
"quantized_dimension"), nb::arg(
"storage_type_min"),
241 nb::arg(
"storage_type_max"));
242 uniformQuantizedPerAxisType.def_property_readonly(
246 std::vector<double> scales;
247 scales.reserve(nDim);
248 for (intptr_t i = 0; i < nDim; ++i) {
250 scales.push_back(scale);
254 "The scales designate the difference between the real values "
255 "corresponding to consecutive quantized values differing by 1. The ith "
256 "scale corresponds to the ith slice in the quantized_dimension.");
257 uniformQuantizedPerAxisType.def_property_readonly(
261 std::vector<int64_t> zeroPoints;
262 zeroPoints.reserve(nDim);
263 for (intptr_t i = 0; i < nDim; ++i) {
266 zeroPoints.push_back(zeroPoint);
270 "the storage values corresponding to the real value 0 in the affine "
271 "equation. The ith zero point corresponds to the ith slice in the "
272 "quantized_dimension.");
273 uniformQuantizedPerAxisType.def_property_readonly(
274 "quantized_dimension",
278 "Specifies the dimension of the shape that the scales and zero points "
280 uniformQuantizedPerAxisType.def_property_readonly(
285 "Fixed point values are real numbers divided by a scale.");
293 quantizedType.get_class());
294 calibratedQuantizedType.def_classmethod(
296 [](nb::object cls, MlirType expressedType,
double min,
double max) {
299 "Gets an instance of CalibratedQuantizedType in the same context as the "
300 "provided expressed type.",
301 nb::arg(
"cls"), nb::arg(
"expressed_type"), nb::arg(
"min"),
303 calibratedQuantizedType.def_property_readonly(
"min", [](MlirType type) {
306 calibratedQuantizedType.def_property_readonly(
"max", [](MlirType type) {
312 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 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 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 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 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 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 bool mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate)
Returns true if the candidate type is compatible with the given quantized type.
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.