[Mlir-commits] [mlir] [mlir][tosa] Add error_if checks for Transpose (PR #135219)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Apr 14 13:10:59 PDT 2025
================
@@ -1993,22 +1998,27 @@ LogicalResult tosa::TransposeOp::verify() {
constantPerms, [](int32_t v) -> int64_t { return v; }))))
return emitOpError() << "expected valid permutation indices";
+ // ERROR_IF(tensor_size(shape1) != tensor_size(shape))
+ if (inputShape.hasStaticShape() && outputShape.hasStaticShape() &&
+ inputShape.getNumElements() != outputShape.getNumElements())
+ return emitOpError() << "expected input1 and output to have same numbers "
+ "of elements, got "
+ << inputShape.getNumElements() << " and "
+ << outputShape.getNumElements();
+
// Verify that the types of the input and output tensors are properly
// permuted.
- if (inputType.hasRank() && outputType.hasRank()) {
- assert(constantPerms.size() == static_cast<size_t>(inputType.getRank()) &&
- inputType.getRank() == outputType.getRank());
-
- for (auto i = 0; i < outputType.getRank(); i++) {
- if (inputType.isDynamicDim(constantPerms[i]) ||
- outputType.isDynamicDim(i))
+ if (inputShape.hasRank() && outputShape.hasRank()) {
+ for (auto i = 0; i < outputShape.getRank(); i++) {
+ if (inputShape.isDynamicDim(constantPerms[i]) ||
+ outputShape.isDynamicDim(i))
continue;
- if (inputType.getDimSize(constantPerms[i]) != outputType.getDimSize(i))
+ if (inputShape.getDimSize(constantPerms[i]) != outputShape.getDimSize(i))
return emitOpError()
<< "expected output tensor dim " << i << " to match "
<< "input dim " << constantPerms[i] << " with value of "
- << inputType.getDimSize(constantPerms[i]);
+ << inputShape.getDimSize(constantPerms[i]);
}
}
----------------
Jerry-Ge wrote:
are we missing the check for those? https://www.mlplatform.org/tosa/tosa_spec.html#_transpose
```
// Ensure each perms value is a valid value
ERROR_IF(index >= rank(shape1));
ERROR_IF(index < 0);
// Ensure ranks aren't repeated
ERROR_IF(indexes_used[index] == true);
indexes_used[index] = true;
```
https://github.com/llvm/llvm-project/pull/135219
More information about the Mlir-commits
mailing list