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

Faster substitute_facts #8200

Merged
merged 11 commits into from
Apr 19, 2024
Merged

Faster substitute_facts #8200

merged 11 commits into from
Apr 19, 2024

Conversation

abadams
Copy link
Member

@abadams abadams commented Apr 17, 2024

It was O(n) for n facts. This makes it O(log(n))

This was particularly bad for pipelines with lots of inputs or outputs,
because those pipelines have lots of asserts, which make for lots of
facts to substitute in.

Speeds up lowering of local laplacian with 20 pyramid levels (which has
only one input and one output) by 1.09x

Speeds up lowering of the adams 2019 cost model training pipeline (lots
of weight inputs and lots outputs due to derivatives) by 1.5x

Speeds up resnet50 (tons of weight inputs) lowering by 7.3x!

Deletes a bunch of code and speeds up lowering time of local laplacian
with 20 pyramid levels by ~2.5%
It was O(n) for n facts. This makes it O(log(n))

This was particularly bad for pipelines with lots of inputs or outputs,
because those pipelines have lots of asserts, which make for lots of
facts to substitute in.

Speeds up lowering of local laplacian with 20 pyramid levels (which has
only one input and one output) by 1.09x

Speeds up lowering of the adams 2019 cost model training pipeline (lots
of weight inputs and lots outputs due to derivatives) by 1.5x

Speeds up resnet50 (tons of weight inputs) lowering by 7.3x!
@abadams
Copy link
Member Author

abadams commented Apr 18, 2024

Ready for review

@@ -258,7 +258,7 @@ class Simplify : public VariadicVisitor<Simplify, Expr, Stmt> {

std::vector<const Variable *> pop_list;
std::vector<const Variable *> bounds_pop_list;
std::vector<Expr> truths, falsehoods;
std::set<Expr, IRDeepCompare> truths, falsehoods;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered unordered_set?

Copy link
Member Author

Choose a reason for hiding this comment

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

comparing Exprs for < is actually a lot cheaper than hashing them, because you can early out as soon as you find an IRNodeType that differs instead of having to descend to the bottom.

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth putting that in a comment then :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, that was a bit of a guess. Nowhere in the compiler do we use unordered sets or maps with Expr keys, because we don't have a hash function. I'm just doing what we do everywhere else.

@abadams
Copy link
Member Author

abadams commented Apr 19, 2024

Failure unrelated (seems to be a performance flake). Ready for review.

@abadams
Copy link
Member Author

abadams commented Apr 19, 2024

Oh oops, you already approved it.

@abadams abadams merged commit 31c52ab into main Apr 19, 2024
18 of 19 checks passed
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.

2 participants