This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add RuntimeVerifiableOpInterface and transform
ClosedPublic

Authored by springerm on Nov 23 2022, 7:31 AM.

Details

Summary

Static op verification cannot detect cases where an op is valid at compile time but may be invalid at runtime.

An example of such an op is memref::ExpandShapeOp.

Invalid at compile time: memref.expand_shape %m [[0, 1]] : memref<11xf32> into memref<2x5xf32>

Valid at compile time (because we do not know any better): memref.expand_shape %m [[0, 1]] : memref<?xf32> into memref<?x5xf32>. This op may or may not be valid at runtime depending on the runtime shape of %m.

Invalid runtime ops such as the one above are hard to debug because they can crash the program execution at a seemingly unrelated position or (even worse) compute an invalid result without crashing.

This revision adds a new op interface RuntimeVerifiableOpInterface that can be implemented by ops that provide additional runtime verification. Such runtime verification can be computationally expensive, so it is only generated on an opt-in basis by running -generate-runtime-verification. A simple runtime verifier for memref::ExpandShapeOp is provided as an example.

Diff Detail

Event Timeline

springerm created this revision.Nov 23 2022, 7:31 AM
springerm requested review of this revision.Nov 23 2022, 7:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2022, 7:31 AM
rriddle requested changes to this revision.EditedNov 23 2022, 7:34 AM

This looks like something that needs an RFC. I'd like to see a post on discourse proposing something here.

This revision now requires changes to proceed.Nov 23 2022, 7:34 AM
springerm planned changes to this revision.Nov 23 2022, 7:35 AM
springerm added reviewers: ftynse, herhut.
springerm updated this revision to Diff 477780.Nov 24 2022, 7:10 AM

return values and strings instead of generating AssertOps in the interface impl

springerm updated this revision to Diff 480014.Dec 5 2022, 1:28 AM

address RFC comments

springerm edited the summary of this revision. (Show Details)Dec 5 2022, 2:14 AM

Fine with me, @rriddle has the RFC been discussed enough to satisfy your block?

mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp
68

you depend on cf as well here...

mlir/lib/Transforms/GenerateRuntimeVerification.cpp
34

Just a nit, but does getOperation()->walk([&](RuntimeVerifiableOpInterface verifiableOp) work?

springerm marked an inline comment as done.

address comments

mlir/lib/Transforms/GenerateRuntimeVerification.cpp
34

Yes it does

springerm marked an inline comment as done.Dec 19 2022, 11:33 PM
rriddle accepted this revision.Dec 20 2022, 10:35 PM

Looks reasonable to me!

mlir/include/mlir/Interfaces/RuntimeVerifiableOpInterface.td
30
mlir/lib/Transforms/GenerateRuntimeVerification.cpp
34

Why not just create the builder here? I don't think you save much by creating the builder outside.

This revision is now accepted and ready to land.Dec 20 2022, 10:35 PM
rriddle added inline comments.Dec 20 2022, 10:41 PM
mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp
18–20
59–61
This revision was landed with ongoing or failed builds.Dec 21 2022, 1:57 AM
This revision was automatically updated to reflect the committed changes.
springerm marked 2 inline comments as done.
guraypp added a subscriber: guraypp.Jan 6 2023, 3:06 AM
This comment was removed by guraypp.