[Mlir-commits] [mlir] QuantileType bytecode patch (PR #203495)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jun 12 04:30:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: vsimion26
<details>
<summary>Changes</summary>
Since the merge of this PR(https://github.com/llvm/llvm-project/pull/190321) there were some issues identified, such as QuantileType not being added in the ByteCode files. This PR focuses on fixing these missing pieces which should make QuantileType a complete and functional type.
---
Full diff: https://github.com/llvm/llvm-project/pull/203495.diff
5 Files Affected:
- (modified) mlir/include/mlir/Dialect/Quant/IR/Quant.h (+1)
- (modified) mlir/include/mlir/Dialect/Quant/IR/QuantBase.td (+10)
- (modified) mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td (+15-1)
- (modified) mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp (+23)
- (modified) mlir/test/Dialect/Quant/Bytecode/types.mlir (+16)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Quant/IR/Quant.h b/mlir/include/mlir/Dialect/Quant/IR/Quant.h
index 11a969a3ee519..eb207e8054c9b 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/Quant.h
+++ b/mlir/include/mlir/Dialect/Quant/IR/Quant.h
@@ -27,6 +27,7 @@ namespace quant {
class QuantizedType;
class UniformQuantizedType;
class UniformQuantizedPerAxisType;
+class QuantileType;
} // namespace quant
} // namespace mlir
diff --git a/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td b/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
index 23bf5cf15e256..b129e4b57e353 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
+++ b/mlir/include/mlir/Dialect/Quant/IR/QuantBase.td
@@ -402,6 +402,16 @@ class quant_ScalarOrTensorOf<Type etype> :
def quant_QuantizedType :
Type<CPred<"::llvm::isa<mlir::quant::QuantizedType>($_self)">, "quantized type">;
+// QuantileType
+def quant_QuantileType :
+ DialectType<Quant_Dialect,
+ CPred<"::llvm::isa<::mlir::quant::QuantileType>($_self)">,
+ "QuantileType">;
+
+// Predicate for detecting a scalar or tensor of QuantileType.
+def quant_QuantileValueType :
+ quant_ScalarOrTensorOf<quant_QuantileType>;
+
def quant_ScalarType :
Type<Or<[
AnySignlessInteger.predicate,
diff --git a/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td b/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
index 8c74dbef5d94a..8225e12754a66 100644
--- a/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
+++ b/mlir/include/mlir/Dialect/Quant/IR/QuantDialectBytecode.td
@@ -23,6 +23,12 @@ def DoubleAPFloat:
WithType <"double">>>>;
def DoubleAPFloatList : List<DoubleAPFloat>;
+def OptionalSignedVarInt:
+ WithParser <"succeeded(readOptionalSignedVarInt($_reader, $_var))",
+ WithBuilder<"$_args",
+ WithPrinter<"writeOptionalSignedVarInt($_writer, $_getter)",
+ WithType <"std::optional<int64_t>">>>>;
+
let cType = "AnyQuantizedType" in {
def AnyQuantizedType: DialectType<(type
@@ -97,6 +103,14 @@ def UniformQuantizedSubChannelType
}];
}
+def QuantileType : DialectType<(type
+ Type:$storageType,
+ Type:$quantileType,
+ Array<DoubleAPFloatList>:$quantiles,
+ OptionalSignedVarInt:$storageMin,
+ OptionalSignedVarInt:$storageMax
+)>;
+
/// This enum contains marker codes used to indicate which attribute is
/// currently being decoded, and how it should be decoded. The order of these
/// codes should generally be unchanged, as any changes will inevitably break
@@ -106,7 +120,7 @@ def QuantDialectTypes : DialectTypes<"Quant"> {
let elems = [ReservedOrDead, AnyQuantizedType,
AnyQuantizedTypeWithExpressedType, CalibratedQuantizedType,
UniformQuantizedType, UniformQuantizedPerAxisType,
- UniformQuantizedSubChannelType];
+ UniformQuantizedSubChannelType, QuantileType];
}
#endif // QUANT_BYTECODE
diff --git a/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp b/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
index 1b3cc5a43f460..870f13d4fb8c2 100644
--- a/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
+++ b/mlir/lib/Dialect/Quant/IR/QuantDialectBytecode.cpp
@@ -30,6 +30,29 @@ static LogicalResult readDoubleAPFloat(DialectBytecodeReader &reader,
return success();
}
+static LogicalResult readOptionalSignedVarInt(DialectBytecodeReader &reader,
+ std::optional<int64_t> &val) {
+ bool hasValue;
+ if (failed(reader.readBool(hasValue)))
+ return failure();
+ if (hasValue) {
+ int64_t v;
+ if (failed(reader.readSignedVarInt(v)))
+ return failure();
+ val = v;
+ } else {
+ val = std::nullopt;
+ }
+ return success();
+}
+
+static void writeOptionalSignedVarInt(DialectBytecodeWriter &writer,
+ std::optional<int64_t> val) {
+ writer.writeOwnedBool(val.has_value());
+ if (val.has_value())
+ writer.writeSignedVarInt(*val);
+}
+
#include "mlir/Dialect/Quant/IR/QuantDialectBytecode.cpp.inc"
/// This class implements the bytecode interface for the Quant dialect.
diff --git a/mlir/test/Dialect/Quant/Bytecode/types.mlir b/mlir/test/Dialect/Quant/Bytecode/types.mlir
index 4b03548a5ad11..848f15e3fb085 100644
--- a/mlir/test/Dialect/Quant/Bytecode/types.mlir
+++ b/mlir/test/Dialect/Quant/Bytecode/types.mlir
@@ -85,3 +85,19 @@ module @parseUniformSubChannel attributes {
// CHECK: !quant.uniform<i8:f32:{0:1, 1:2}, {{\{}}{2.000000e+00:10, 3.000000e+00:20}, {4.000000e+00:30, 5.000000e+00:40}}>
bytecode.test = !quant.uniform<i8:f32:{0:1, 1:2}, {{2.0:10, 3.0:20}, {4.0:30, 5.0:40}}>
} {}
+
+//===----------------------------------------------------------------------===//
+// QuantileType
+//===----------------------------------------------------------------------===//
+
+// CHECK-LABEL: parseQuantileNoStorageBounds
+module @parseQuantileNoStorageBounds attributes {
+ // CHECK: !quant.quantile<ui4:f16, {-1.000000e+00,-8.750000e-01,-7.500000e-01,-6.250000e-01,-5.000000e-01,-3.750000e-01,-2.500000e-01,-1.250000e-01,1.250000e-01,2.500000e-01,3.750000e-01,5.000000e-01,6.250000e-01,7.500000e-01,8.750000e-01,1.000000e+00}>
+ bytecode.test = !quant.quantile<ui4:f16, {-1.0,-0.875,-0.75,-0.625,-0.5,-0.375,-0.25,-0.125,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1.0}>
+} {}
+
+// CHECK-LABEL: parseQuantileWithStorageBounds
+module @parseQuantileWithStorageBounds attributes {
+ // CHECK: !quant.quantile<ui4:f16, {-1.000000e+00,-5.000000e-01,2.500000e-01,7.500000e-01,1.000000e+00}, <-2:2>>
+ bytecode.test = !quant.quantile<ui4:f16, {-1.0,-0.5,0.25,0.75,1.0}, <-2:2>>
+} {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/203495
More information about the Mlir-commits
mailing list