[Mlir-commits] [mlir] [mlir][tosa] Replace UniformQuantizedType by the more generic Quantiz… (PR #126275)
Tai Ly
llvmlistbot at llvm.org
Fri Feb 7 14:42:28 PST 2025
https://github.com/Tai78641 updated https://github.com/llvm/llvm-project/pull/126275
>From c62371b9f787f3029bc2efd2d9b9eeefafc5a368 Mon Sep 17 00:00:00 2001
From: Thibaut Goetghebuer-Planchon <thibaut.goetghebuer-planchon at arm.com>
Date: Wed, 8 May 2024 18:09:42 +0100
Subject: [PATCH] [mlir][tosa] Replace UniformQuantizedType by the more generic
QuantizedType in Conv verifiers
Change-Id: Ie1961af931864f801914a62976bc988881ee075e
Signed-off-by: Tai Ly <tai.ly at arm.com>
---
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp | 30 +++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 955021abdd67b12..8b4bf052ee9b34c 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -240,16 +240,13 @@ static LogicalResult verifyConvOp(T op) {
bool biasIsFloat = llvm::isa<FloatType>(biasEType);
bool resultIsFloat = llvm::isa<FloatType>(resultEType);
- if (auto quantType =
- llvm::dyn_cast<mlir::quant::UniformQuantizedType>(inputEType))
+ if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(inputEType))
inputEType = quantType.getStorageType();
- if (auto quantType =
- llvm::dyn_cast<mlir::quant::UniformQuantizedType>(biasEType))
+ if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(biasEType))
biasEType = quantType.getStorageType();
- if (auto quantType =
- llvm::dyn_cast<mlir::quant::UniformQuantizedType>(resultEType))
+ if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(resultEType))
resultEType = quantType.getStorageType();
if (biasIsFloat && resultIsFloat && (biasEType != resultEType)) {
@@ -346,8 +343,7 @@ static LogicalResult verifyConvOpModes(T op) {
auto inputEType =
llvm::cast<ShapedType>(op.getInput().getType()).getElementType();
- if (auto quantType =
- llvm::dyn_cast<mlir::quant::UniformQuantizedType>(inputEType))
+ if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(inputEType))
inputEType = quantType.getStorageType();
auto accType = op.getAccType();
@@ -369,7 +365,23 @@ static LogicalResult verifyConvOpModes(T op) {
if (inputEType.isF32() && !accType.isF32())
return op.emitOpError("accumulator type for f32 tensor is not f32");
- return success();
+ auto resultEType =
+ llvm::cast<ShapedType>(op.getResult().getType()).getElementType();
+
+ if (auto quantType = llvm::dyn_cast<mlir::quant::QuantizedType>(resultEType))
+ resultEType = quantType.getStorageType();
+
+ // check allowed input/result element types combinations
+ if ((inputEType.isInteger(8) && resultEType.isInteger(32)) ||
+ (inputEType.isInteger(16) && resultEType.isInteger(48)) ||
+ (isa<Float8E5M2Type>(inputEType) && resultEType.isF16()) ||
+ (isa<Float8E4M3FNType>(inputEType) && resultEType.isF16()) ||
+ (inputEType.isF16() && resultEType.isF16()) ||
+ (inputEType.isBF16() && resultEType.isBF16()) ||
+ (inputEType.isF32() && resultEType.isF32()))
+ return success();
+
+ return op.emitOpError("input/output element types are incompatible.");
}
// verify that inType and outType have same element types
More information about the Mlir-commits
mailing list