[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / mlir / include / mlir-c / Dialect / Quant.h
bloba7d98dc3c1a7757e025cd6ac90469d8c696280a1
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 //===----------------------------------------------------------------------===//
10 #ifndef MLIR_C_DIALECT_QUANT_H
11 #define MLIR_C_DIALECT_QUANT_H
13 #include "mlir-c/IR.h"
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
19 MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(quant, quant);
21 //===---------------------------------------------------------------------===//
22 // QuantizedType
23 //===---------------------------------------------------------------------===//
25 /// Returns `true` if the given type is a quantization dialect type.
26 MLIR_CAPI_EXPORTED bool mlirTypeIsAQuantizedType(MlirType type);
28 /// Returns the bit flag used to indicate signedness of a quantized type.
29 MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetSignedFlag(void);
31 /// Returns the minimum possible value stored by a quantized type.
32 MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMinimumForInteger(
33 bool isSigned, unsigned integralWidth);
35 /// Returns the maximum possible value stored by a quantized type.
36 MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMaximumForInteger(
37 bool isSigned, unsigned integralWidth);
39 /// Gets the original type approximated by the given quantized type.
40 MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetExpressedType(MlirType type);
42 /// Gets the flags associated with the given quantized type.
43 MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetFlags(MlirType type);
45 /// Returns `true` if the given type is signed, `false` otherwise.
46 MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsSigned(MlirType type);
48 /// Returns the underlying type used to store the values.
49 MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetStorageType(MlirType type);
51 /// Returns the minimum value that the storage type of the given quantized type
52 /// can take.
53 MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMin(MlirType type);
55 /// Returns the maximum value that the storage type of the given quantized type
56 /// can take.
57 MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMax(MlirType type);
59 /// Returns the integral bitwidth that the storage type of the given quantized
60 /// type can represent exactly.
61 MLIR_CAPI_EXPORTED unsigned
62 mlirQuantizedTypeGetStorageTypeIntegralWidth(MlirType type);
64 /// Returns `true` if the `candidate` type is compatible with the given
65 /// quantized `type`.
66 MLIR_CAPI_EXPORTED bool
67 mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate);
69 /// Returns the element type of the given quantized type as another quantized
70 /// type.
71 MLIR_CAPI_EXPORTED MlirType
72 mlirQuantizedTypeGetQuantizedElementType(MlirType type);
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.
77 MLIR_CAPI_EXPORTED MlirType
78 mlirQuantizedTypeCastFromStorageType(MlirType type, MlirType candidate);
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.
82 MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastToStorageType(MlirType type);
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.
87 MLIR_CAPI_EXPORTED MlirType
88 mlirQuantizedTypeCastFromExpressedType(MlirType type, MlirType candidate);
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.
92 MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastToExpressedType(MlirType type);
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.
96 MLIR_CAPI_EXPORTED MlirType
97 mlirQuantizedTypeCastExpressedToStorageType(MlirType type, MlirType candidate);
99 //===---------------------------------------------------------------------===//
100 // AnyQuantizedType
101 //===---------------------------------------------------------------------===//
103 /// Returns `true` if the given type is an AnyQuantizedType.
104 MLIR_CAPI_EXPORTED bool mlirTypeIsAAnyQuantizedType(MlirType type);
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.
109 MLIR_CAPI_EXPORTED MlirType mlirAnyQuantizedTypeGet(unsigned flags,
110 MlirType storageType,
111 MlirType expressedType,
112 int64_t storageTypeMin,
113 int64_t storageTypeMax);
115 //===---------------------------------------------------------------------===//
116 // UniformQuantizedType
117 //===---------------------------------------------------------------------===//
119 /// Returns `true` if the given type is a UniformQuantizedType.
120 MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedType(MlirType type);
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.
125 MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedTypeGet(
126 unsigned flags, MlirType storageType, MlirType expressedType, double scale,
127 int64_t zeroPoint, int64_t storageTypeMin, int64_t storageTypeMax);
129 /// Returns the scale of the given uniform quantized type.
130 MLIR_CAPI_EXPORTED double mlirUniformQuantizedTypeGetScale(MlirType type);
132 /// Returns the zero point of the given uniform quantized type.
133 MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedTypeGetZeroPoint(MlirType type);
135 /// Returns `true` if the given uniform quantized type is fixed-point.
136 MLIR_CAPI_EXPORTED bool mlirUniformQuantizedTypeIsFixedPoint(MlirType type);
138 //===---------------------------------------------------------------------===//
139 // UniformQuantizedPerAxisType
140 //===---------------------------------------------------------------------===//
142 /// Returns `true` if the given type is a UniformQuantizedPerAxisType.
143 MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedPerAxisType(MlirType type);
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.
149 MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedPerAxisTypeGet(
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);
154 /// Returns the number of axes in the given quantized per-axis type.
155 MLIR_CAPI_EXPORTED intptr_t
156 mlirUniformQuantizedPerAxisTypeGetNumDims(MlirType type);
158 /// Returns `pos`-th scale of the given quantized per-axis type.
159 MLIR_CAPI_EXPORTED double mlirUniformQuantizedPerAxisTypeGetScale(MlirType type,
160 intptr_t pos);
162 /// Returns `pos`-th zero point of the given quantized per-axis type.
163 MLIR_CAPI_EXPORTED int64_t
164 mlirUniformQuantizedPerAxisTypeGetZeroPoint(MlirType type, intptr_t pos);
166 /// Returns the index of the quantized dimension in the given quantized per-axis
167 /// type.
168 MLIR_CAPI_EXPORTED int32_t
169 mlirUniformQuantizedPerAxisTypeGetQuantizedDimension(MlirType type);
171 /// Returns `true` if the given uniform quantized per-axis type is fixed-point.
172 MLIR_CAPI_EXPORTED bool
173 mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type);
175 //===---------------------------------------------------------------------===//
176 // CalibratedQuantizedType
177 //===---------------------------------------------------------------------===//
179 /// Returns `true` if the given type is a CalibratedQuantizedType.
180 MLIR_CAPI_EXPORTED bool mlirTypeIsACalibratedQuantizedType(MlirType type);
182 /// Creates an instance of CalibratedQuantizedType with the given parameters
183 /// in the same context as `expressedType` and returns it. The instance is owned
184 /// by the context.
185 MLIR_CAPI_EXPORTED MlirType
186 mlirCalibratedQuantizedTypeGet(MlirType expressedType, double min, double max);
188 /// Returns the min value of the given calibrated quantized type.
189 MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMin(MlirType type);
191 /// Returns the max value of the given calibrated quantized type.
192 MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMax(MlirType type);
194 #ifdef __cplusplus
196 #endif
198 #endif // MLIR_C_DIALECT_QUANT_H