MLIR 22.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
106/// Creates an instance of AnyQuantizedType with the given parameters in the
107/// same context as `storageType` and returns it. The instance is owned by the
108/// context.
109MLIR_CAPI_EXPORTED MlirType mlirAnyQuantizedTypeGet(unsigned flags,
110 MlirType storageType,
111 MlirType expressedType,
112 int64_t storageTypeMin,
113 int64_t storageTypeMax);
114
115//===---------------------------------------------------------------------===//
116// UniformQuantizedType
117//===---------------------------------------------------------------------===//
118
119/// Returns `true` if the given type is a UniformQuantizedType.
121
122/// Creates an instance of UniformQuantizedType with the given parameters in the
123/// same context as `storageType` and returns it. The instance is owned by the
124/// context.
126 unsigned flags, MlirType storageType, MlirType expressedType, double scale,
127 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
128
129/// Returns the scale of the given uniform quantized type.
131
132/// Returns the zero point of the given uniform quantized type.
134
135/// Returns `true` if the given uniform quantized type is fixed-point.
137
138//===---------------------------------------------------------------------===//
139// UniformQuantizedPerAxisType
140//===---------------------------------------------------------------------===//
141
142/// Returns `true` if the given type is a UniformQuantizedPerAxisType.
144
145/// Creates an instance of UniformQuantizedPerAxisType with the given parameters
146/// in the same context as `storageType` and returns it. `scales` and
147/// `zeroPoints` point to `nDims` number of elements. The instance is owned
148/// by the context.
150 unsigned flags, MlirType storageType, MlirType expressedType,
151 intptr_t nDims, double *scales, int64_t *zeroPoints,
152 int32_t quantizedDimension, int64_t storageTypeMin, int64_t storageTypeMax);
153
154/// Returns the number of axes in the given quantized per-axis type.
155MLIR_CAPI_EXPORTED intptr_t
157
158/// Returns `pos`-th scale of the given quantized per-axis type.
160 intptr_t pos);
161
162/// Returns `pos`-th zero point of the given quantized per-axis type.
164mlirUniformQuantizedPerAxisTypeGetZeroPoint(MlirType type, intptr_t pos);
165
166/// Returns the index of the quantized dimension in the given quantized per-axis
167/// type.
168MLIR_CAPI_EXPORTED int32_t
170
171/// Returns `true` if the given uniform quantized per-axis type is fixed-point.
174
175//===---------------------------------------------------------------------===//
176// UniformQuantizedSubChannelType
177//===---------------------------------------------------------------------===//
178
179/// Returns `true` if the given type is a UniformQuantizedSubChannel.
182
183/// Creates a UniformQuantizedSubChannelType with the given parameters.
184///
185/// The type is owned by the context. `scalesAttr` and `zeroPointsAttr` must be
186/// DenseElementsAttrs. `quantizedDimensions` and `blockSizes`
187/// point to `blockSizeInfoLength` number of elements, describing respectively
188/// the quantization axis and corresponding block size.
190 unsigned flags, MlirType storageType, MlirType expressedType,
191 MlirAttribute scalesAttr, MlirAttribute zeroPointsAttr,
192 intptr_t blockSizeInfoLength, int32_t *quantizedDimensions,
193 int64_t *blockSizes, int64_t storageTypeMin, int64_t storageTypeMax);
194
195/// Returns the number of block sizes provided in type.
196MLIR_CAPI_EXPORTED intptr_t
198
199/// Returns the quantized dimension at the given position.
200MLIR_CAPI_EXPORTED int32_t
202 intptr_t pos);
203
204/// Returns the block size at the given position.
206mlirUniformQuantizedSubChannelTypeGetBlockSize(MlirType type, intptr_t pos);
207
208/// Returns the scales of the quantized type.
209MLIR_CAPI_EXPORTED MlirAttribute
211
212/// Returns the zero-points of the quantized type.
213MLIR_CAPI_EXPORTED MlirAttribute
215
216//===---------------------------------------------------------------------===//
217// CalibratedQuantizedType
218//===---------------------------------------------------------------------===//
219
220/// Returns `true` if the given type is a CalibratedQuantizedType.
222
223/// Creates an instance of CalibratedQuantizedType with the given parameters
224/// in the same context as `expressedType` and returns it. The instance is owned
225/// by the context.
226MLIR_CAPI_EXPORTED MlirType
227mlirCalibratedQuantizedTypeGet(MlirType expressedType, double min, double max);
228
229/// Returns the min value of the given calibrated quantized type.
231
232/// Returns the max value of the given calibrated quantized type.
234
235#ifdef __cplusplus
236}
237#endif
238
239#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:172
MLIR_CAPI_EXPORTED bool mlirTypeIsACalibratedQuantizedType(MlirType type)
Returns true if the given type is a CalibratedQuantizedType.
Definition Quant.cpp:257
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 bool mlirUniformQuantizedTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized type is fixed-point.
Definition Quant.cpp:149
MLIR_CAPI_EXPORTED MlirAttribute mlirUniformQuantizedSubChannelTypeGetZeroPoints(MlirType type)
Returns the zero-points of the quantized type.
Definition Quant.cpp:248
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:128
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:178
MLIR_CAPI_EXPORTED MlirAttribute mlirUniformQuantizedSubChannelTypeGetScales(MlirType type)
Returns the scales of the quantized type.
Definition Quant.cpp:243
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedTypeGetZeroPoint(MlirType type)
Returns the zero point of the given uniform quantized type.
Definition Quant.cpp:145
MLIR_CAPI_EXPORTED bool mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type)
Returns true if the given uniform quantized per-axis type is fixed-point.
Definition Quant.cpp:194
MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedSubChannelTypeGetBlockSize(MlirType type, intptr_t pos)
Returns the block size at the given position.
Definition Quant.cpp:237
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:271
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:261
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:225
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:183
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:189
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:116
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 MlirType mlirQuantizedTypeGetStorageType(MlirType type)
Returns the underlying type used to store the values.
Definition Quant.cpp:55
MLIR_CAPI_EXPORTED int32_t mlirUniformQuantizedSubChannelTypeGetQuantizedDimension(MlirType type, intptr_t pos)
Returns the quantized dimension at the given position.
Definition Quant.cpp:231
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:157
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 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:267
MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetFlags(MlirType type)
Gets the flags associated with the given quantized type.
Definition Quant.cpp:47
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:161
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:206
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:202
MLIR_CAPI_EXPORTED double mlirUniformQuantizedTypeGetScale(MlirType type)
Returns the scale of the given uniform quantized type.
Definition Quant.cpp:141
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:132
#define MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Name, Namespace)
Definition IR.h:215
#define MLIR_CAPI_EXPORTED
Definition Support.h:46