brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.4 KiB · dc0989e Raw
240 lines · c
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 LLVM4// Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef MLIR_C_DIALECT_QUANT_H11#define MLIR_C_DIALECT_QUANT_H12 13#include "mlir-c/IR.h"14 15#ifdef __cplusplus16extern "C" {17#endif18 19MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(quant, quant);20 21//===---------------------------------------------------------------------===//22// QuantizedType23//===---------------------------------------------------------------------===//24 25/// Returns `true` if the given type is a quantization dialect type.26MLIR_CAPI_EXPORTED bool mlirTypeIsAQuantizedType(MlirType type);27 28/// Returns the bit flag used to indicate signedness of a quantized type.29MLIR_CAPI_EXPORTED unsigned mlirQuantizedTypeGetSignedFlag(void);30 31/// Returns the minimum possible value stored by a quantized type.32MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMinimumForInteger(33    bool isSigned, unsigned integralWidth);34 35/// Returns the maximum possible value stored by a quantized type.36MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetDefaultMaximumForInteger(37    bool isSigned, unsigned integralWidth);38 39/// Gets the original type approximated by the given quantized type.40MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetExpressedType(MlirType 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.46MLIR_CAPI_EXPORTED bool mlirQuantizedTypeIsSigned(MlirType type);47 48/// Returns the underlying type used to store the values.49MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeGetStorageType(MlirType type);50 51/// Returns the minimum value that the storage type of the given quantized type52/// can take.53MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMin(MlirType type);54 55/// Returns the maximum value that the storage type of the given quantized type56/// can take.57MLIR_CAPI_EXPORTED int64_t mlirQuantizedTypeGetStorageTypeMax(MlirType type);58 59/// Returns the integral bitwidth that the storage type of the given quantized60/// type can represent exactly.61MLIR_CAPI_EXPORTED unsigned62mlirQuantizedTypeGetStorageTypeIntegralWidth(MlirType type);63 64/// Returns `true` if the `candidate` type is compatible with the given65/// quantized `type`.66MLIR_CAPI_EXPORTED bool67mlirQuantizedTypeIsCompatibleExpressedType(MlirType type, MlirType candidate);68 69/// Returns the element type of the given quantized type as another quantized70/// type.71MLIR_CAPI_EXPORTED MlirType72mlirQuantizedTypeGetQuantizedElementType(MlirType type);73 74/// Casts from a type based on the storage type of the given type to a75/// corresponding type based on the given type. Returns a null type if the cast76/// is not valid.77MLIR_CAPI_EXPORTED MlirType78mlirQuantizedTypeCastFromStorageType(MlirType type, MlirType candidate);79 80/// Casts from a type based on a quantized type to a corresponding typed based81/// on the storage type. Returns a null type if the cast is not valid.82MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastToStorageType(MlirType type);83 84/// Casts from a type based on the expressed type of the given type to a85/// corresponding type based on the given type. Returns a null type if the cast86/// is not valid.87MLIR_CAPI_EXPORTED MlirType88mlirQuantizedTypeCastFromExpressedType(MlirType type, MlirType candidate);89 90/// Casts from a type based on a quantized type to a corresponding typed based91/// on the expressed type. Returns a null type if the cast is not valid.92MLIR_CAPI_EXPORTED MlirType mlirQuantizedTypeCastToExpressedType(MlirType type);93 94/// Casts from a type based on the expressed type of the given quantized type to95/// equivalent type based on storage type of the same quantized type.96MLIR_CAPI_EXPORTED MlirType97mlirQuantizedTypeCastExpressedToStorageType(MlirType type, MlirType candidate);98 99//===---------------------------------------------------------------------===//100// AnyQuantizedType101//===---------------------------------------------------------------------===//102 103/// Returns `true` if the given type is an AnyQuantizedType.104MLIR_CAPI_EXPORTED bool mlirTypeIsAAnyQuantizedType(MlirType type);105 106/// Creates an instance of AnyQuantizedType with the given parameters in the107/// same context as `storageType` and returns it. The instance is owned by the108/// 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// UniformQuantizedType117//===---------------------------------------------------------------------===//118 119/// Returns `true` if the given type is a UniformQuantizedType.120MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedType(MlirType type);121 122/// Creates an instance of UniformQuantizedType with the given parameters in the123/// same context as `storageType` and returns it. The instance is owned by the124/// context.125MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedTypeGet(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.130MLIR_CAPI_EXPORTED double mlirUniformQuantizedTypeGetScale(MlirType type);131 132/// Returns the zero point of the given uniform quantized type.133MLIR_CAPI_EXPORTED int64_t mlirUniformQuantizedTypeGetZeroPoint(MlirType type);134 135/// Returns `true` if the given uniform quantized type is fixed-point.136MLIR_CAPI_EXPORTED bool mlirUniformQuantizedTypeIsFixedPoint(MlirType type);137 138//===---------------------------------------------------------------------===//139// UniformQuantizedPerAxisType140//===---------------------------------------------------------------------===//141 142/// Returns `true` if the given type is a UniformQuantizedPerAxisType.143MLIR_CAPI_EXPORTED bool mlirTypeIsAUniformQuantizedPerAxisType(MlirType type);144 145/// Creates an instance of UniformQuantizedPerAxisType with the given parameters146/// in the same context as `storageType` and returns it. `scales` and147/// `zeroPoints` point to `nDims` number of elements. The instance is owned148/// by the context.149MLIR_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);153 154/// Returns the number of axes in the given quantized per-axis type.155MLIR_CAPI_EXPORTED intptr_t156mlirUniformQuantizedPerAxisTypeGetNumDims(MlirType type);157 158/// Returns `pos`-th scale of the given quantized per-axis type.159MLIR_CAPI_EXPORTED double mlirUniformQuantizedPerAxisTypeGetScale(MlirType type,160                                                                  intptr_t pos);161 162/// Returns `pos`-th zero point of the given quantized per-axis type.163MLIR_CAPI_EXPORTED int64_t164mlirUniformQuantizedPerAxisTypeGetZeroPoint(MlirType type, intptr_t pos);165 166/// Returns the index of the quantized dimension in the given quantized per-axis167/// type.168MLIR_CAPI_EXPORTED int32_t169mlirUniformQuantizedPerAxisTypeGetQuantizedDimension(MlirType type);170 171/// Returns `true` if the given uniform quantized per-axis type is fixed-point.172MLIR_CAPI_EXPORTED bool173mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type);174 175//===---------------------------------------------------------------------===//176// UniformQuantizedSubChannelType177//===---------------------------------------------------------------------===//178 179/// Returns `true` if the given type is a UniformQuantizedSubChannel.180MLIR_CAPI_EXPORTED bool181mlirTypeIsAUniformQuantizedSubChannelType(MlirType type);182 183/// Creates a UniformQuantizedSubChannelType with the given parameters.184///185/// The type is owned by the context. `scalesAttr` and `zeroPointsAttr` must be186/// DenseElementsAttrs.  `quantizedDimensions` and `blockSizes`187/// point to `blockSizeInfoLength` number of elements, describing respectively188/// the quantization axis and corresponding block size.189MLIR_CAPI_EXPORTED MlirType mlirUniformQuantizedSubChannelTypeGet(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_t197mlirUniformQuantizedSubChannelTypeGetNumBlockSizes(MlirType type);198 199/// Returns the quantized dimension at the given position.200MLIR_CAPI_EXPORTED int32_t201mlirUniformQuantizedSubChannelTypeGetQuantizedDimension(MlirType type,202                                                        intptr_t pos);203 204/// Returns the block size at the given position.205MLIR_CAPI_EXPORTED int64_t206mlirUniformQuantizedSubChannelTypeGetBlockSize(MlirType type, intptr_t pos);207 208/// Returns the scales of the quantized type.209MLIR_CAPI_EXPORTED MlirAttribute210mlirUniformQuantizedSubChannelTypeGetScales(MlirType type);211 212/// Returns the zero-points of the quantized type.213MLIR_CAPI_EXPORTED MlirAttribute214mlirUniformQuantizedSubChannelTypeGetZeroPoints(MlirType type);215 216//===---------------------------------------------------------------------===//217// CalibratedQuantizedType218//===---------------------------------------------------------------------===//219 220/// Returns `true` if the given type is a CalibratedQuantizedType.221MLIR_CAPI_EXPORTED bool mlirTypeIsACalibratedQuantizedType(MlirType type);222 223/// Creates an instance of CalibratedQuantizedType with the given parameters224/// in the same context as `expressedType` and returns it. The instance is owned225/// by the context.226MLIR_CAPI_EXPORTED MlirType227mlirCalibratedQuantizedTypeGet(MlirType expressedType, double min, double max);228 229/// Returns the min value of the given calibrated quantized type.230MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMin(MlirType type);231 232/// Returns the max value of the given calibrated quantized type.233MLIR_CAPI_EXPORTED double mlirCalibratedQuantizedTypeGetMax(MlirType type);234 235#ifdef __cplusplus236}237#endif238 239#endif // MLIR_C_DIALECT_QUANT_H240