This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Transforms] GreedyPatternRewriteDriver: Worklist randomizer
ClosedPublic

Authored by springerm on Jan 24 2023, 3:10 AM.

Details

Summary

Instead of always taking the last op from the worklist, take a random one. For testing/debugging purposes only. This feature can be used to ensure that lowering pipelines work correctly regardless of the order in which ops are processed by the GreedyPatternRewriteDriver.

The randomizer can be enabled by setting a numeric MLIR_GREEDY_REWRITE_RANDOMIZER_SEED option.

Note: When enabled, 27 tests are currently failing. Partly because FileCheck tests are looking for exact IR.

Discussion: https://discourse.llvm.org/t/discussion-fuzzing-pattern-application/67911

Diff Detail

Event Timeline

springerm created this revision.Jan 24 2023, 3:10 AM
springerm requested review of this revision.Jan 24 2023, 3:10 AM
kuhar added a subscriber: kuhar.Jan 26 2023, 6:16 AM
kuhar added inline comments.
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
360–361

I'm don't have experience with random number in LLVM, but I wonder if we should use some centralized instance like https://llvm.org/doxygen/classllvm_1_1RandomNumberGenerator.html?

519

nit: I think llvm::contains would work here

springerm retitled this revision from [mlir][WIP] GreedyPatternRewriteDriver: Worklist fuzzer to [mlir][Transforms] GreedyPatternRewriteDriver: Worklist fuzzer.May 26 2023, 8:37 AM
springerm edited the summary of this revision. (Show Details)
springerm marked 2 inline comments as done.
springerm edited the summary of this revision. (Show Details)
springerm added reviewers: mehdi_amini, jpienaar.
springerm added a reviewer: rriddle.
kuhar added a comment.EditedMay 26 2023, 10:26 AM

As a general comment, IMO we should call it 'randomizer'/'randomized' throughout the patch. IMHO fuzzing has a more specific meaning.

mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
239

Doesn't this modify the global rand state? Could we use something stateful from <random> instead?

249

nit: either for (int i = pos, e = ....size(); i < e; ++i) or we could use llvm::enumerate(list)

LGTM on the principle, but @kuhar made good comments to address.

Also can you document this flag (and the one you already introduced) in the debugging guide?

springerm updated this revision to Diff 526249.May 27 2023, 2:22 AM
springerm edited the summary of this revision. (Show Details)

address comments

springerm marked 2 inline comments as done.May 27 2023, 2:22 AM
springerm retitled this revision from [mlir][Transforms] GreedyPatternRewriteDriver: Worklist fuzzer to [mlir][Transforms] GreedyPatternRewriteDriver: Worklist randomizer.
springerm edited the summary of this revision. (Show Details)
kuhar accepted this revision.May 27 2023, 10:49 AM

LGTM. I'd love to see this as a runtime option in the future -- not sure how difficult that is to plumb through though.

This revision is now accepted and ready to land.May 27 2023, 10:49 AM
mehdi_amini accepted this revision.May 27 2023, 12:17 PM

LG!

This is the doc I was referring to earlier: https://mlir.llvm.org/getting_started/Debugging/