[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 13:56:36 PST 2025


================
@@ -850,6 +850,71 @@ LogicalResult tosa::ConcatOp::inferReturnTypeComponents(
   return success();
 }
 
+LogicalResult tosa::ConcatOp::verify() {
+  // check that each input has same element type as output
+  auto outType = getOutput().getType();
+  const Operation::operand_range inputList = getInput1();
+
+  if (!llvm::all_of(inputList, [&](auto input) {
+        return succeeded(verifySameElementTypes(
+            *this, /* inType = */ input.getType(), outType));
+      })) {
+    return failure();
+  }
+
+  // Check there is at least one input
+  if (inputList.empty())
+    return emitOpError("expect at least one input");
+
+  const Type firstInputType = inputList.front().getType();
+  const ShapeAdaptor firstInputShape(firstInputType);
+  const int32_t axis = getAxis();
+
+  if (firstInputShape.hasRank()) {
----------------
Jerry-Ge wrote:

> Looks like I made the incorrect assumption here that all inputs would have the same rank (or no rank)

I think you were correct. From the spec, it's saying `All inputs must have the same rank and data type` (https://www.mlplatform.org/tosa/tosa_spec.html#_concat)

Even for dynamic inputs, the rank still doesn't change right? e.g., `<2x?x3x4>`, `getRank()` still returns `4`

https://github.com/llvm/llvm-project/pull/127923


More information about the Mlir-commits mailing list