MLIR 23.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
16extern "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.
43MLIR_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.
61MLIR_CAPI_EXPORTED unsigned
63
64/// Returns `true` if the `candidate` type is compatible with the given
65/// quantized `type`.
67mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate);
68
69/// Returns the element type of the given quantized type as another quantized
70/// type.
71MLIR_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.
77MLIR_CAPI_EXPORTED MlirType
78mlirQuantizedTypeCastFromStorageType(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.
87MLIR_CAPI_EXPORTED MlirType
88mlirQuantizedTypeCastFromExpressedType(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.
96MLIR_CAPI_EXPORTED MlirType
97mlirQuantizedTypeCastExpressedToStorageType(MlirType type, MlirType candidate);
98
99//===---------------------------------------------------------------------===//
100// AnyQuantizedType
101//===---------------------------------------------------------------------===//
102
103/// Returns `true` if the given type is an AnyQuantizedType.
105
107
108/// Creates an instance of AnyQuantizedType with the given parameters in the
109/// same context as `storageType` and returns it. The instance is owned by the
110/// context.
111MLIR_CAPI_EXPORTED MlirType mlirAnyQuantizedTypeGet(unsigned flags,
112 MlirType storageType,
113 MlirType expressedType,
114 int64_t storageTypeMin,
115 int64_t storageTypeMax);
116
118
119//===---------------------------------------------------------------------===//
120// UniformQuantizedType
121//===---------------------------------------------------------------------===//
122
123/// Returns `true` if the given type is a UniformQuantizedType.
125
127
128/// Creates an instance of UniformQuantizedType with the given parameters in the
129/// same context as `storageType` and returns it. The instance is owned by the
130/// context.
132 unsigned flags, MlirType storageType, MlirType expressedType, double scale,
133 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
134
136
137/// Returns the scale of the given uniform quantized type.
139
140/// Returns the zero point of the given uniform quantized type.
142
143/// Returns `true` if the given uniform quantized type is fixed-point.
145
146//===---------------------------------------------------------------------===//
147// UniformQuantizedPerAxisType
148//===---------------------------------------------------------------------===//
149
150/// Returns `true` if the given type is a UniformQuantizedPerAxisType.
152
154
155/// Creates an instance of UniformQuantizedPerAxisType with the given parameters
156/// in the same context as `storageType` and returns it. `scales` and
157/// `zeroPoints` point to `nDims` number of elements. The instance is owned
158/// by the context.
160 unsigned flags, MlirType storageType, MlirType expressedType,
161 intptr_t nDims, double *scales, int64_t *zeroPoints,
162 int32_t quantizedDimension, int64_t storageTypeMin, int64_t storageTypeMax);
163
165
166/// Returns the number of axes in the given quantized per-axis type.
169
170/// Returns `pos`-th scale of the given quantized per-axis type.
172 intptr_t pos);
173
174/// Returns `pos`-th zero point of the given quantized per-axis type.
177
178/// Returns the index of the quantized dimension in the given quantized per-axis
179/// type.
180MLIR_CAPI_EXPORTED int32_t
182
183/// Returns `true` if the given uniform quantized per-axis type is fixed-point.
186
187//===---------------------------------------------------------------------===//
188// UniformQuantizedSubChannelType
189//===---------------------------------------------------------------------===//
190
191/// Returns `true` if the given type is a UniformQuantizedSubChannel.
194
196
197/// Creates a UniformQuantizedSubChannelType with the given parameters.
198///
199/// The type is owned by the context. `scalesAttr` and `zeroPointsAttr` must be
200/// DenseElementsAttrs. `quantizedDimensions` and `blockSizes`
201/// point to `blockSizeInfoLength` number of elements, describing respectively
202/// the quantization axis and corresponding block size.
204 unsigned flags, MlirType storageType, MlirType expressedType,
205 MlirAttribute scalesAttr, MlirAttribute zeroPointsAttr,
206 intptr_t blockSizeInfoLength, int32_t *quantizedDimensions,
207 int64_t *blockSizes, int64_t storageTypeMin, int64_t storageTypeMax);
208
211
212/// Returns the number of block sizes provided in type.
215
216/// Returns the quantized dimension at the given position.
217MLIR_CAPI_EXPORTED int32_t
219 intptr_t pos);
220
221/// Returns the block size at the given position.
224
225/// Returns the scales of the quantized type.
226MLIR_CAPI_EXPORTED MlirAttribute
228
229/// Returns the zero-points of the quantized type.
230MLIR_CAPI_EXPORTED MlirAttribute
232
233//===---------------------------------------------------------------------===//
234// CalibratedQuantizedType
235//===---------------------------------------------------------------------===//
236
237/// Returns `true` if the given type is a CalibratedQuantizedType.
239
241
242/// Creates an instance of CalibratedQuantizedType with the given parameters
243/// in the same context as `expressedType` and returns it. The instance is owned
244/// by the context.
245MLIR_CAPI_EXPORTED MlirType
246mlirCalibratedQuantizedTypeGet(MlirType expressedType, double min, double max);
247
249
250/// Returns the min value of the given calibrated quantized type.
252
253/// Returns the max value of the given calibrated quantized type.
255
256#ifdef __cplusplus
257}
258#endif
259
260#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: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
#define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace)
Definition IR.h:215
#define MLIR_CAPI_EXPORTED
Definition Support.h:46
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:75