-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Faster substitute_facts #8200
Conversation
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!
…o abadams/faster_substitute_facts
…o abadams/faster_substitute_facts
…o abadams/faster_substitute_facts
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
Failure unrelated (seems to be a performance flake). Ready for review. |
Oh oops, you already approved it. |
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!