This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Add check if the operand of the operations is constant.
ClosedPublic

Authored by tatwaichong on Mar 6 2023, 11:41 AM.

Details

Summary

Some uses of TOSA rely on the constant operands of particular operations,
e.g. paddings and pad_const in pad op. Add a verification pattern in the
validation pass, and this is optionally enabled.

Change-Id: I1628c0840a27ab06ef91150eee56ad4f5ac9543d

Diff Detail

Event Timeline

tatwaichong created this revision.Mar 6 2023, 11:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2023, 11:41 AM
tatwaichong requested review of this revision.Mar 6 2023, 11:41 AM

Define these constant operand checking functions as function template. That might make
code cleaner as it is likely more operations will be added.

rsuderman requested changes to this revision.Mar 9 2023, 10:50 AM
rsuderman added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
111

Generally we avoid contractions in debug statements

isn't -> is not

114

ditto

120

Not necessary in this CR but longterm we should probably have a table lookup instead of a series of if/else operations. It is excessive right now as we have only two but useful to keep in mind.

122

We should probably just invoke signalPassFailure() within the checkConstantsOperand helper. This way we do not need to repeat the check statements.

125

ditto

This revision now requires changes to proceed.Mar 9 2023, 10:50 AM

Instead of checking a series of if/else operations, adopt operation type look-up method
by implementing polymorphism. I think that may easier to extend to involve more operations
or other checking patterns. And address other review comments.

tatwaichong marked 4 inline comments as done.Mar 15 2023, 5:46 PM
tatwaichong added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
120

Great suggestion. I intend to get rid of if-else-checking manner in this PR as there is a new - fully_connected op check added, and likely more operand checks or other patterns will be added in the future. hopefully, this change can make the code easier to extend.

rsuderman requested changes to this revision.Mar 17 2023, 11:09 AM
rsuderman added inline comments.
mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
40

Typically you don't want to define a default implementation for a virtual function in this case as it is expected to be overrideen.

112

Using the class ConstantOperandCheck for the vector is unnecessary as you are just using it as a wrapper around a function reference. Instead you can using SmallVector<std::function<LogicalResult(Operation*)>>, then emplace the statically defined checkers above. This avoids having an extra virtual function lookup and removes all of the class boilerplate for each check.

This revision now requires changes to proceed.Mar 17 2023, 11:09 AM

Populate and call checkers (function) directly to avoid virtual function lookup and class
overhead.

rsuderman added inline comments.Mar 20 2023, 1:01 PM
mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
40

You don't need a class at all. Just move the population and validation to the Pass itself, and make the individual checks standalone functions.

Rebase onto top-of-tree to include the fix that isn't relevant to this patch.

tatwaichong marked 2 inline comments as done.Mar 20 2023, 2:09 PM
tatwaichong marked 2 inline comments as done.Mar 20 2023, 3:17 PM

As suggested, minimize the change by adding the necessary checkers only.

As suggested, minimize the change by adding the necessary checkers only.

rsuderman accepted this revision.Mar 21 2023, 1:49 PM

Awesome. This is so much cleaner.

This revision is now accepted and ready to land.Mar 21 2023, 1:49 PM