This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Verify zero-dim tensors in the input
ClosedPublic

Authored by Lewuathe on Jul 5 2023, 11:36 PM.

Details

Summary

As TOSA does not support the tensor with zero dimensions, we can check the zero value for the static shape input.

Ideally, we should be able to check the tensor shape more broadly, such as using CPred in the TOSA type definition. But based on the discussion here It makes input type verification complicated and hard to maintain and still only applies to the case the input is statically shaped. Therefore, in this change, we have put the zero dimension check in the verification of each op, which would be flexible and maintainable.

See: https://github.com/llvm/llvm-project/issues/63212

Diff Detail

Event Timeline

Lewuathe created this revision.Jul 5 2023, 11:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 5 2023, 11:36 PM
Lewuathe requested review of this revision.Jul 5 2023, 11:36 PM
Lewuathe edited the summary of this revision. (Show Details)Jul 5 2023, 11:41 PM

Great, thanks for addressing my bug report!

TinaAMD added inline comments.Jul 6 2023, 2:23 AM
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
103

Maybe we can name it "hasZeroDimension" (without the "s")? When I first saw the name, I was a bit confused if this checks for rank == 0 (which is permitted).

jpienaar added inline comments.
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
104

Is static on purpose or do you want to see if ranked? E.g.,. ?x0x10 would pass verification as not static, but you already know it's invalid

Lewuathe added inline comments.Jul 6 2023, 6:12 PM
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
104

Good point. I'm going to omit the check for the static type and check the zero as long as the input is ranked.

Lewuathe updated this revision to Diff 537948.Jul 6 2023, 6:33 PM

Support all ranked tensors.

Lewuathe marked 2 inline comments as done.Jul 6 2023, 6:33 PM

I agree with the concept here, just a comment on having a clearer error message and then I think it will be ready.

mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
132

Here and below, I think this error is confusing in the same way the function name was confusing. I suggest

"tensor has a dimension with size zero. Each dimension of a tensor must have size >= 1"

as an example.

Lewuathe updated this revision to Diff 538315.Jul 7 2023, 9:28 PM

Improve error message.

Lewuathe marked an inline comment as done.Jul 7 2023, 9:29 PM

@eric-k256 I have improved the error message accordingly. Can I ask you to review it again?

eric-k256 accepted this revision.Jul 10 2023, 9:16 AM

Looks good, thanks!

This revision is now accepted and ready to land.Jul 10 2023, 9:16 AM
This revision was automatically updated to reflect the committed changes.
Peiming added inline comments.
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
104

Could the ShapedType be unranked? We observed an (*this).hasRank() && "cannot query rank of unranked shaped type" error from upstream.

Peiming added inline comments.Jul 10 2023, 6:04 PM
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
104