Skip to content

Sync Sub-channel quantized type from llvm-project (pre-merge) to npu-plugin #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions mlir/include/mlir-c/Dialect/Quant.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,47 @@ mlirUniformQuantizedPerAxisTypeGetQuantizedDimension(MlirType type);
MLIR_CAPI_EXPORTED bool
mlirUniformQuantizedPerAxisTypeIsFixedPoint(MlirType type);

//===---------------------------------------------------------------------===//
// UniformQuantizedSubChannelType
//===---------------------------------------------------------------------===//

/// Returns `true` if the given type is a UniformQuantizedSubChannel.
MLIR_CAPI_EXPORTED bool
mlirTypeIsAUniformQuantizedSubChannelType(MlirType type);

/// Creates a UniformQuantizedSubChannelType with the given parameters.
///
/// The type is owned by the context. `scalesAttr` and `zeroPointsAttr` must be
/// DenseElementsAttrs. `quantizedDimensions` and `blockSizes`
/// point to `blockSizeInfoLength` number of elements, describing respectively
/// the quantization axis and corresponding block size.
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);

/// Returns the number of block sizes provided in type.
MLIR_CAPI_EXPORTED intptr_t
mlirUniformQuantizedSubChannelTypeGetNumBlockSizes(MlirType type);

/// Returns the quantized dimension at the given position.
MLIR_CAPI_EXPORTED int32_t
mlirUniformQuantizedSubChannelTypeGetQuantizedDimension(MlirType type,
intptr_t pos);

/// Returns the block size at the given position.
MLIR_CAPI_EXPORTED int64_t
mlirUniformQuantizedSubChannelTypeGetBlockSize(MlirType type, intptr_t pos);

/// Returns the scales of the quantized type.
MLIR_CAPI_EXPORTED MlirAttribute
mlirUniformQuantizedSubChannelTypeGetScales(MlirType type);

/// Returns the zero-points of the quantized type.
MLIR_CAPI_EXPORTED MlirAttribute
mlirUniformQuantizedSubChannelTypeGetZeroPoints(MlirType type);

//===---------------------------------------------------------------------===//
// CalibratedQuantizedType
//===---------------------------------------------------------------------===//
Expand Down
36 changes: 26 additions & 10 deletions mlir/include/mlir/Dialect/Quant/QuantDialectBytecode.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef QUANT_BYTECODE
#define QUANT_BYTECODE

include "mlir/IR/BuiltinDialectBytecode.td"
include "mlir/IR/BytecodeBase.td"

def DoubleAPFloat:
Expand Down Expand Up @@ -81,6 +82,21 @@ def UniformQuantizedPerAxisType: DialectType<(type
}];
}

def UniformQuantizedSubChannelType
: DialectType<(type VarInt:$flags, Type:$storageType, Type:$expressedType,
SignedVarInt:$storageTypeMin, SignedVarInt:$storageTypeMax,
Array<SignedVarIntList>:$quantizedDimensions,
Array<SignedVarIntList>:$blockSizes, DenseElementsAttr:$scales,
DenseElementsAttr:$zeroPoints)> {
// Note: builder order differs from bytecode.
let cBuilder = [{
get<$_resultType>(context, flags, storageType, expressedType, scales,
zeroPoints, llvm::to_vector(llvm::map_range(quantizedDimensions,
[](int64_t dim) { return static_cast<int32_t>(dim);})), blockSizes,
storageTypeMin, storageTypeMax)
}];
}

def QuantileQuantizedType: DialectType<(type
VarInt:$flags,
Type:$storageType,
Expand Down Expand Up @@ -118,16 +134,16 @@ def QuantileQuantizedPerAxisType: DialectType<(type
/// compatibility with older bytecode.

def QuantDialectTypes : DialectTypes<"Quant"> {
let elems = [
ReservedOrDead,
AnyQuantizedType,
AnyQuantizedTypeWithExpressedType,
CalibratedQuantizedType,
UniformQuantizedType,
UniformQuantizedPerAxisType,
QuantileQuantizedType,
QuantileQuantizedPerAxisType
let elems = [ReservedOrDead,
AnyQuantizedType,
AnyQuantizedTypeWithExpressedType,
CalibratedQuantizedType,
UniformQuantizedType,
UniformQuantizedPerAxisType,
UniformQuantizedSubChannelType,
QuantileQuantizedType,
QuantileQuantizedPerAxisType
];
}

#endif // QUANT_BYTECODE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eof

#endif // QUANT_BYTECODE
Loading