This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Revisit std.subview handling of static information.
ClosedPublic

Authored by nicolasvasilache on May 8 2020, 9:29 PM.

Details

Summary

The main objective of this revision is to change the way static information is represented, propagated and canonicalized in the SubViewOp.

In the current implementation the issue is that canonicalization may strictly lose information because static offsets are combined in irrecoverable ways into the result type, in order to fit the strided memref representation.

The core semantics of the op do not change but the parser and printer do: the op always requires rank offsets, sizes and strides. These quantities can now be either SSA values or static integer attributes.

The result type is automatically deduced from the static information and more powerful canonicalizations (as powerful as the representation with sentinel ? values allows). Previously static information was inferred on a best-effort basis from looking at the source and destination type.

Relevant tests are rewritten to use the idiomatic offset: x, strides : [...]-form. Bugs are corrected along the way that were not trivially visible in flattened strided memref form.

It is an open question, and a longer discussion, whether a better result type representation would be a nicer alternative. For now, the subview op carries the required semantic.

Diff Detail

Event Timeline

bondhugula added inline comments.
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
2680

/// doc comment here.

mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2185–2293

/ doc style comment here. We are using / comments for local methods as well everywhere or at least that's the style AFAIU.

2204

Likewise.

2461–2465

Nit: / ->

2476–2482

Likewise.

mlir/test/IR/core-ops.mlir
12–13

Typo: C_HECK

mravishankar requested changes to this revision.May 9 2020, 10:23 PM

Mostly looks OK to me and much better to canonicalize. Thanks for doing this. Some minor comments.

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

Nit: please align as above.

2641

AFAIK the verifier code below, the staticOffsets, staticSizes and staticStrides need to be specified always. So having a default value here is misleading. Can we move these operands before the offsets, sizes and strides (I know that makes it a breaking change)

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

I find this a bit misleading. If left empty in the build, then this implicitly means that all the values are -1. I would rather be explicit that the subview needs an ArrayAttr for staticOffsets, staticSizes, staticStrides that is of size rank of the source. Based on what are -1, will dictate the sizes of offsets, sizes and strides that are specified. This would make the dynamic values optional and needed only if one of the static* has a -1 entry. Note this is more a suggestion.

2428

isnt this just

llvm::to_vector<4>(llvm::map_range(attr, [](Attribute a) -> int64_t { return a.cast<IntegerAttr>().getInt();}))

2602–2603

These two lines can be moved into the canonicalizeSubViewPart method since they are repeated below.

This revision now requires changes to proceed.May 9 2020, 10:23 PM
nicolasvasilache marked 15 inline comments as done.

Address review

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

I can split this in 2 builders, one that needs to take everything and another one that takes none and documents that it uses the default which is "all dynamic".
Clients shouldn't have to worry about passing always dynamic entries for everything (which is the way one would almost always construct this and later call canonicalization).

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

very good point, addressed with 2 builders.

2428

yes, thanks, much cleaner!

2602–2603

I need to pass a preallocated vector that can be modified in place.
I could also return 2 values but it wouldn't change anything I'd claim except I'd have to return a pair and std::tie.
And like people will complain that they want a struct instead of a pair so at this point, you know :)

Harbormaster completed remote builds in B56347: Diff 263237.
This revision was not accepted when it landed; it landed in state Needs Review.May 11 2020, 3:08 PM
This revision was automatically updated to reflect the committed changes.

Awesome! This is a nice clean up, thanks Nicolas!

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

Won't a plain StringRef[4] work here? That will help with initialization and lifetime?

herhut reopened this revision.May 12 2020, 6:26 AM
herhut added a subscriber: herhut.
herhut added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2560

This canonicalization leads to subview operations with mixed constants/operands that cannot be lowered to LLVM. While they could never be lowered, it is now impossible to compile them at all, as using ConstantOp operands also no longer works.

Before landing this canonicalizer, we need to extend the LLVM lowering.

nicolasvasilache marked an inline comment as done.

Update LLVM lowering and add a mixed test case.

nicolasvasilache marked an inline comment as done.May 12 2020, 2:25 PM
nicolasvasilache added inline comments.
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
2560

Sorry about that @herhut thanks for reverting.
I updated the lowering to LLVM and added a mixed static-dynamic test case.
XLA is green for me, IREE too.

ftynse accepted this revision.May 12 2020, 3:14 PM
andydavis1 accepted this revision.May 12 2020, 4:16 PM
This revision was not accepted when it landed; it landed in state Needs Review.May 12 2020, 5:15 PM
This revision was automatically updated to reflect the committed changes.
nicolasvasilache marked an inline comment as done.

Thanks for fixing this!