This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tosa] Add InferTensorType interface to tosa reduce operations
ClosedPublic

Authored by AviadCo on Apr 2 2023, 2:15 AM.

Details

Summary

When this interface is used, a call to inferReturnTypeComponents()
is generated on creation and verification of the op.

Diff Detail

Event Timeline

AviadCo created this revision.Apr 2 2023, 2:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2023, 2:15 AM
AviadCo requested review of this revision.Apr 2 2023, 2:15 AM
AviadCo updated this revision to Diff 510396.Apr 2 2023, 9:24 PM

Addeed mlir tests for tosa reduce operations infer shape.

mamrami added inline comments.Apr 3 2023, 6:14 AM
mlir/test/Dialect/Tosa/invalid.mlir
102 ↗(On Diff #510396)

I would remove the function name check and the newlines, to align to the other tests.

mamrami added inline comments.Apr 3 2023, 6:24 AM
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
944

Can we have a static method with this implementation? Then it can be called here and in tosa::ConcatOp::isCompatibleReturnTypes to avoid code duplication.
Or maybe we can stay with this implementation only, and have another macro that will be defined for tosa::ConcatOp as well as for the reduce ops.

AviadCo updated this revision to Diff 510708.Apr 3 2023, 11:39 PM

Fixed Maya's comments.

AviadCo marked an inline comment as done.Apr 3 2023, 11:41 PM
AviadCo added inline comments.
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
944

Good point, made new macro and included tosa::ConcatOp in it.

mlir/test/Dialect/Tosa/invalid.mlir
102 ↗(On Diff #510396)

Ack.

AviadCo updated this revision to Diff 510720.Apr 4 2023, 1:07 AM
AviadCo marked an inline comment as done.

Removed space and redundent code from mlir checks.

eric-k256 accepted this revision.Apr 4 2023, 5:16 PM

Looks good to me.

This revision is now accepted and ready to land.Apr 4 2023, 5:16 PM
jpienaar accepted this revision.Apr 4 2023, 5:31 PM
jpienaar added inline comments.
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
933

So rhs size being 1 would be an error but if lhs were 1 then it's fine? (For example, if r.size() was 0 then the below would assert)

944

I think the proposal to call the static method from the macro sounds good. Just reduces work for compiler.

AviadCo added inline comments.Apr 4 2023, 9:00 PM
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
933

The tosa operations that have this macro are not changing the tensor length/element type, and all of them working on tensors with length 1.

Actually lhs and rhs must be from the same length from the first condition (otherwise we will return false). From the second condition lhs mustn't be 1. From the combination of those conditions we can deduce that we will return false also if rhs is 1 also (either lhs is 1 also nor rhs != lhs).

944

Ack. thanks.