This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Enable specifying querying function in ValueShapeRange
ClosedPublic

Authored by jpienaar on Aug 9 2021, 8:53 AM.

Details

Summary

This enables querying shapes/values as shapes without mutating the IR directly
(e.g., towards enabling doing inference in analysis & application steps,
inferring function shape with constant from callsite, ...). Add a new
ShapeAdaptor that abstracts over whether shape is from Type or
ShapedTypeComponents or DenseIntElementsAttribute. This adds new accessors to
ValueShapeRange to get Shape and value as shape, but doesn't restrict or remove
the previous way of accessing Type via the Value for now, that does mean a less
refined shape could be accidentally queried and will be restricted in follow
up.

Currently restricted Value query to what can be represented as Shape. So only
supports cases where constant subgraph evaluation's output is a shape. I had
considered making it more general, but without TBD extern attribute concept or
some such a user cannot today uniformly avoid overhead (it does happen less
frequently shape inference side, but we've run into OOMs here and so rather
starting more restrictive here).

Update TOSA ops and also (but potentially more as an example and for discussion)
the shape inference pass.

Diff Detail

Event Timeline

jpienaar created this revision.Aug 9 2021, 8:53 AM
jpienaar requested review of this revision.Aug 9 2021, 8:53 AM
rsuderman accepted this revision.Aug 10 2021, 11:08 AM

Just some minor fixes.

mlir/lib/Interfaces/InferTypeOpInterface.cpp
164

Some leaked debug code

mlir/unittests/Interfaces/InferTypeOpInterfaceTest.cpp
58

Is there any reason this is an ASSERT instead of an EXPECT? Seems kinda strange to have the random intersperse.

This revision is now accepted and ready to land.Aug 10 2021, 11:08 AM
rriddle added inline comments.Aug 10 2021, 11:10 AM
mlir/lib/Interfaces/InferTypeOpInterface.cpp
135–136

This looks sketchy, why is this necessary?

jpienaar updated this revision to Diff 365562.Aug 10 2021, 11:25 AM
jpienaar marked 2 inline comments as done.

Remove leftover debugging

mlir/lib/Interfaces/InferTypeOpInterface.cpp
135–136

Left over debugging, good catch. I was debugging a module and just use this to avoid output from different threads getting munged.

mlir/unittests/Interfaces/InferTypeOpInterfaceTest.cpp
58

Yes, so if this fails then the call below (hasRank()) would assert in debug mode and crash the test, so need to ensure we don't try and "dereference" if null.

This revision was landed with ongoing or failed builds.Aug 10 2021, 11:44 AM
This revision was automatically updated to reflect the committed changes.