This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Verify indexing map required attributes
ClosedPublic

Authored by antiagainst on Feb 8 2021, 2:57 PM.

Details

Summary

Indexing maps for named ops can reference attributes so that
we can synthesize the indexing map dynamically. This supports
cases like strides for convolution ops. However, it does cause
an issue: now the indexing_maps() function call is dependent
on those attributes.

Linalg ops inherit LinalgOpInterfaceTraits, which calls
verifyStructuredOpInterface() to verify the interface.
verifyStructuredOpInterface() further calls indexing_maps().
Note that trait verification is done before the op itself,
where ODS generates the verification for those attributes.
So we can have indexing_maps() referencing non-existing or
invalid attribute, before the ODS-generated verification
kick in.

There isn't a dependency handling mechansim for traits.
This commit adds new interface methods to query whether an
op hasDynamicIndexingMaps() and then perform
verifyIndexingMapRequiredAttributes() in
verifyStructuredOpInterface() to handle the dependency issue.

Diff Detail

Event Timeline

antiagainst created this revision.Feb 8 2021, 2:57 PM
antiagainst requested review of this revision.Feb 8 2021, 2:57 PM
mehdi_amini added inline comments.Feb 8 2021, 5:46 PM
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
307

Do we need this check? Shouldn't we be able to call the verify unconditionally?

mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
1849

I think it is a good practice for format string with more than one parameter to document their list of parameters, this one has 7 now :)

2067

I think what's happening in this method could benefit from more documentation

nicolasvasilache accepted this revision.Feb 8 2021, 11:37 PM

Approving conditioned on the extra doc @mehdi_amini asked for. Thanks!

mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
307

Not all ops have dynamic indexing maps (i.e. ones that are dependent on the op instance's attributes).
A particular op knows whether its definition requires such attributes to define the indexing maps.
So this all makes sense to me and we are calling the verifier unconditionally.

mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
1849

+1, some /*stringName=*/ would help read this better.

This revision is now accepted and ready to land.Feb 8 2021, 11:37 PM
antiagainst marked 5 inline comments as done.
  • Address comments
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
307

Yeah. I feel this is more clear logically to show that not every op need this kind of check given that not all of them has dynamic indexing maps. :)

mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp
1849

Added explanation ahead .

This revision was landed with ongoing or failed builds.Feb 9 2021, 5:51 AM
This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Feb 9 2021, 6:09 PM
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
307

I mean that calling verifyIndexingMapRequiredAttributes() when hasDynamicIndexingMaps() return false will succeed.
So you should either make it fails when hasDynamicIndexingMaps() returns false, or not guard it here.