This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Shape] Lower `shape_of` for unranked tensors
ClosedPublic

Authored by frgossen on Jun 19 2020, 8:06 AM.

Details

Summary

Lower shape_of for unranked tensors.
Materializes shape in stack-allocated memory.

Diff Detail

Event Timeline

frgossen created this revision.Jun 19 2020, 8:06 AM
Herald added a project: Restricted Project. · View Herald Transcript
herhut requested changes to this revision.Jun 19 2020, 8:43 AM
herhut added a subscriber: ftynse.
herhut added inline comments.
mlir/lib/Conversion/ShapeToSCF/ShapeToSCF.cpp
73

nit: maybe to for loop so it reads better?

mlir/lib/IR/StandardTypes.cpp
401 ↗(On Diff #272081)

This is intentional. Memrefs may not have index type, as index has no size. @ftynse Has this changed?

So I guess the only way out is to allocate this as int64 and put casts around it.

This revision now requires changes to proceed.Jun 19 2020, 8:43 AM
frgossen updated this revision to Diff 272345.Jun 22 2020, 1:23 AM
frgossen marked an inline comment as done.

Materialize as memref<i64>

frgossen marked an inline comment as done.Jun 22 2020, 1:23 AM
herhut accepted this revision.Jun 22 2020, 1:34 AM
herhut edited reviewers, added: ftynse; removed: rriddle.

With the missing cast, this looks fine to me. Maybe @ftynse has an opinion though.

mlir/lib/Conversion/ShapeToSCF/ShapeToSCF.cpp
116

You now need to cast the result back to index, as it is a ?xi64 now. All a bit suboptimal but yeah...

This revision is now accepted and ready to land.Jun 22 2020, 1:34 AM
frgossen marked an inline comment as done.Jun 22 2020, 2:05 AM
frgossen added inline comments.
mlir/lib/Conversion/ShapeToSCF/ShapeToSCF.cpp
116

I could not see any operation in std that supports this.
tensor_cast requires the element type to be equal, index_cast does not have a lowering to LLVM.
In fact, I could not find any lowering or legalization pass for tensors.
Is that generally missing or is there a trick?

frgossen updated this revision to Diff 272351.Jun 22 2020, 2:05 AM

Add missing cast

This revision was automatically updated to reflect the committed changes.