This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Standard] Add `dynamic_tensor_from_elements` operation
ClosedPublic

Authored by frgossen on Aug 20 2020, 3:34 AM.

Details

Summary

With dynamic_tensor_from_elements tensor values of dynamic size can be
created. The body of the operation essentially maps the index space to tensor
elements.

Declare SCF operations in the scf namespace to avoid name clash with the new
std.yield operation. Resolve ambiguities between linalg/shape/std/scf.yield
operations.

Diff Detail

Event Timeline

frgossen created this revision.Aug 20 2020, 3:34 AM
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: silvas. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
frgossen requested review of this revision.Aug 20 2020, 3:34 AM
silvas added inline comments.Aug 20 2020, 11:11 AM
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
1481

We need to verify that all ops in the body are NoSideEffect

1482

I think this needs some more traits related to regions (look at scf dialect ops)

1504

we should use the term "extent" instead of "dimension" in this case, as "dimension" is ambiguous (for example, the meaning of "dimension" in a transpose op)

3262

Needs HasParent, NoSideEffect (see scf dialect)

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1666

attr-dict handling is needed?

1677

personally, I have found this "only take the dynamic dimensions" to be a huge pain in other ops (requires lots of special handling code). I would prefer to take all dimensions.

As an example, if we have tensor_cast %result_of_dynamic_tensor_from_elements : tensor<?xf32> to tensor<4xf32>, we cannot elide the tensor_cast without major repair of the dynamic_tensor_from_elements op.

We can have a canonicalization that looks at the output type, and replaces any input extents with constants if the output type is more precise.

1684

reword to something like "all body operands must be index" + "must have one body argument per input dimension"

mlir/test/Dialect/Standard/invalid.mlir
62

this case can be verified with traits

Also, can you update the commit description to include a description of the namespace changes?

frgossen edited the summary of this revision. (Show Details)Aug 26 2020, 1:42 AM
frgossen updated this revision to Diff 287878.Aug 26 2020, 2:10 AM
frgossen marked 7 inline comments as done.
frgossen edited the summary of this revision. (Show Details)

Address comments

frgossen added inline comments.Aug 26 2020, 2:11 AM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1666

Not at this point.

Correct me if I'm wrong but I thought attr-dict should always be supported. At least assemblyFormat enforces this.

1677

Why would this be a major repair?
With the current version, you'd have to erase one operand and otherwise you'd have to replace it with a constant. The body arguments span the entire index space anyways.
I don't yet see the advantage and think it'd be nice if this was consistent with, e.g. alloc.

frgossen added inline comments.Sep 1 2020, 6:34 AM
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1677

Just a follow up comment:
When implementing the lowering for this op in TensorFlow, I found it very useful that that alloca expect the same operands.

herhut accepted this revision.Sep 1 2020, 8:38 AM

Thanks. Please fix comments before landing.

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
3272

Would let verifier = ? work to avoid specifying the empty hook?

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1677

I also think we should strive for consistency here. If we want to change this kind of behavior, we need to do it globally and not just for this op.

1684

I would also prefer distinct error messages for the two failure cases (too few arguments and wrong type).

3315

See my other comment. This should not be needed.

This revision is now accepted and ready to land.Sep 1 2020, 8:38 AM
frgossen updated this revision to Diff 290242.Sep 7 2020, 4:42 AM
frgossen marked 5 inline comments as done.

Address comments

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
1684

Sorry, misunderstood that comment.

This revision was landed with ongoing or failed builds.Sep 7 2020, 4:45 AM
This revision was automatically updated to reflect the committed changes.