[Mlir-commits] [mlir] [mlir][tosa] Add more verifiers for the following operators (PR #127923)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Feb 27 11:54:32 PST 2025
================
@@ -899,6 +964,57 @@ LogicalResult tosa::MatMulOp::inferReturnTypeComponents(
return success();
}
+LogicalResult MatMulOp::verify() {
+ auto aType = llvm::dyn_cast<ShapedType>(getA().getType());
+ auto bType = llvm::dyn_cast<ShapedType>(getB().getType());
+
+ // Must be shaped tensor types
+ if (!aType) {
+ emitOpError("expect a shaped tensor for input a, got ") << getA().getType();
+ return failure();
+ }
+ if (!bType) {
+ emitOpError("expect a shaped tensor for input b, got ") << getB().getType();
+ return failure();
+ }
+
+ auto aElementType = aType.getElementType();
+ auto bElementType = bType.getElementType();
+
+ auto aQuantizedEType =
+ llvm::dyn_cast<quant::UniformQuantizedType>(aElementType);
+ auto bQuantizedEType =
+ llvm::dyn_cast<quant::UniformQuantizedType>(bElementType);
+
+ if (aQuantizedEType || bQuantizedEType) {
----------------
Jerry-Ge wrote:
>Probably worth breaking the if nesting?
I don't think so. I think the use of nested ifs is more elegant.
>Check if not both quantized
There're 3 cases where NOT BOTH QUANTIZED is true.
1. A is non-quanitzed, B is non-quantized
2. A is non-quantized, B is quantized
3. A is quantized, B is non-quantized
For case 1, it's valid. For case 2 and 3, they're not valid.
If we don't use the nested ifs, the checking conditions for case 2 and 3 will be very similar and long which is not very elegant.
What do you think? Not sure if you have a better way to organize this.
https://github.com/llvm/llvm-project/pull/127923
More information about the Mlir-commits
mailing list