Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Arith] Implement statistics counters for RewriteSimplifier #14532

Merged
merged 8 commits into from
May 5, 2023

Conversation

Lunderberg
Copy link
Contributor

Previously, so long as RewriteSimplifier produces the same output, unit tests of its behavior would pass. This could have severe performance regressions, such as the one resolved in #14528, which caused the runtime of two test to increase from ~1.5 seconds to ~10 minutes each.

This commit implements statistics counts in RewriteSimplifier, which are exposed through both the C++ and Python APIs, and uses these to guard against the known performance regression from #14528.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Apr 7, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@Lunderberg
Copy link
Contributor Author

I expect the modified tests of RemoveNoOp to cause those unit tests to fail, until #14528 lands, and will re-run CI after it does.

Previously, so long as `RewriteSimplifier` produces the same output,
unit tests of its behavior would pass.  This could have severe
performance regressions, such as the one resolved in
apache#14528, which caused the runtime of
two test to increase from ~1.5 seconds to ~10 minutes each.

This commit implements statistics counts in RewriteSimplifier, which
are exposed through both the C++ and Python APIs, and uses these to
guard against the known performance regression from
apache#14528.
@Lunderberg Lunderberg force-pushed the rewrite_simplifier_stats_counters branch from 083eedf to b3b75ee Compare April 7, 2023 19:09
struct RewriteSimplifierStatsNode : Object {
int nodes_visited{0};
int constraints_entered{0};
int rewrites_attempted{0};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use int64_t

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, updated here and in the SetMaximumRewriteSteps method.

@tqchen
Copy link
Member

tqchen commented Apr 9, 2023

One thing that worth thinking about is the relation of simplification and persistence of analyzer. Since we encourage persistence of analyzer in general within a pass, so we should document in max step to encourage users to keep that in mind

@Lunderberg
Copy link
Contributor Author

Good point on the re-use of the same Analyzer instance. I've added that in the description of SetMaximumRewriteSteps, that re-use of the same object is necessary in order to have accurate usage counters.

src/tir/analysis/control_flow_graph.h Outdated Show resolved Hide resolved
src/arith/rewrite_simplify.h Outdated Show resolved Hide resolved
src/arith/rewrite_simplify.h Outdated Show resolved Hide resolved

auto* n = f.CopyOnWrite();
n->body = NoOpRemover::Apply(std::move(n->body), &analyzer, std::move(touch_pattern), nullptr);
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason for adding curly braces here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't necessary for correctness here, but were added present to limit the scope of write_ptr. It doesn't have much impact in a function of this size, especially with the return statement just afterward, but for longer functions it can help to limit the scope of variables that are only needed for a few following lines.

That said, the implementation no longer requires updating the signature of NoOpRemover::Apply, so this change has become unrelated to the overall PR.

@tqchen tqchen merged commit 1294926 into apache:main May 5, 2023
@Lunderberg Lunderberg deleted the rewrite_simplifier_stats_counters branch May 5, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants