This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Add tosa shape inference with InferReturnTypeComponent
ClosedPublic

Authored by rsuderman on Jul 1 2021, 12:53 PM.

Details

Summary

Added InferReturnTypeComponents for NAry operations, reshape, and reverse.
With the additional tosa-infer-shapes pass, we can infer/propagate shapes
across a set of TOSA operations. Current version does not modify the
FuncOp type by inserting an unrealized conversion cast prior to any new
non-matchin returns.

Diff Detail

Event Timeline

rsuderman created this revision.Jul 1 2021, 12:53 PM
rsuderman requested review of this revision.Jul 1 2021, 12:53 PM
rsuderman updated this revision to Diff 355989.Jul 1 2021, 12:56 PM

Added missing checks for test.

silvas requested changes to this revision.Jul 1 2021, 1:02 PM
silvas added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
37

I don't think lhs or rhs can ever be null here for this pass.

197

This is not correct, as it can change the result types. You need to check that all users allow their types to be updated to the new type in place.

206

Why can't you use a tensor.cast op?

This revision now requires changes to proceed.Jul 1 2021, 1:02 PM
rsuderman updated this revision to Diff 356032.Jul 1 2021, 3:37 PM

Addressed comments about tensor.cast, added dependent dialects, and removed uneeded type checks.

silvas requested changes to this revision.Jul 1 2021, 3:46 PM
silvas added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
197

you shouldn't need to update each use like this (setting the type on the value updates all uses automatically since they just point at the value). I meant that you should check that all users are tosa ops and not some random op that doesn't allow its operand types to be changed.

202

nit: update comments

This revision now requires changes to proceed.Jul 1 2021, 3:46 PM
rsuderman updated this revision to Diff 356033.Jul 1 2021, 3:54 PM
rsuderman marked 2 inline comments as done.

Change shape propagation to only occur to ops from supported dialects.

rsuderman marked an inline comment as done.Jul 1 2021, 3:54 PM
rsuderman added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
197

I restricted to ReturnOp and TosaDialect operations. In the future it should probably be expanded to include Call and some other standard ops.

206

When I chatted with Stella she suggested unrealized cast so that a later pass can correct return types on the function. I changed to a tensor.cast operation but either should be fine for this usecase.

silvas requested changes to this revision.Jul 1 2021, 3:56 PM
silvas added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
210

You shouldn't need any of this stuff updating originalUses.

This revision now requires changes to proceed.Jul 1 2021, 3:56 PM
rsuderman updated this revision to Diff 356034.Jul 1 2021, 3:58 PM
rsuderman marked an inline comment as done.

Correct unecessary use case setting.

rsuderman updated this revision to Diff 356036.Jul 1 2021, 3:58 PM
rsuderman marked 2 inline comments as done.

Typo

rsuderman marked an inline comment as done.Jul 1 2021, 3:58 PM
rsuderman added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
197

See version committed just as you added this comment.

silvas accepted this revision.Jul 1 2021, 4:00 PM
silvas added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
197

Oh, sorry. I guess phabricator was racy.

This revision is now accepted and ready to land.Jul 1 2021, 4:00 PM
This revision was landed with ongoing or failed builds.Jul 1 2021, 4:07 PM
This revision was automatically updated to reflect the committed changes.