This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Limit number of pattern rewrites in CanonicalizerPass
ClosedPublic

Authored by springerm on Dec 21 2022, 10:47 PM.

Details

Summary

The greedy pattern rewriter consists of two nested loops. config.maxIterations (which configurable on the CanonicalizerPass) controls the maximum number of iterations of the outer loops.

/// This specifies the maximum number of times the rewriter will iterate
/// between applying patterns and simplifying regions. Use `kNoLimit` to
/// disable this iteration limit.
int64_t maxIterations = 10;

This change adds config.maxNumRewrites which controls the maximum number of pattern rewrites within an iteration. (It effectively control the maximum number of iterations of the inner loop.)

This flag is meant for debugging and useful in cases where one or multiple faulty patterns can be applied indefinitely, resulting in an infinite loop. Such bugs are difficult to debug even with mlir-opt -debug because no output will printed to the terminal until the process terminates.

Diff Detail

Event Timeline

springerm created this revision.Dec 21 2022, 10:47 PM
springerm requested review of this revision.Dec 21 2022, 10:47 PM
mehdi_amini accepted this revision.Dec 22 2022, 12:53 PM

LGTM, but I don't quite get this part of the description:

Such bugs are difficult to debug even with mlir-opt -debug because no output will printed to the terminal until the process terminates.

I expect all the debug to show up as it goes, I see a bunch of logger.getOStream() << "\n"; that should trigger printing.
Should we add a call to logger.flush(); between each iteration?

This revision is now accepted and ready to land.Dec 22 2022, 12:53 PM

LGTM, but I don't quite get this part of the description:

Such bugs are difficult to debug even with mlir-opt -debug because no output will printed to the terminal until the process terminates.

I expect all the debug to show up as it goes, I see a bunch of logger.getOStream() << "\n"; that should trigger printing.
Should we add a call to logger.flush(); between each iteration?

Hmm it could be that this is just an issue when running a test case in Google3. Will drop that part from the commit message.

This revision was landed with ongoing or failed builds.Dec 23 2022, 4:09 AM
This revision was automatically updated to reflect the committed changes.