Skip to content

Conversation

@abadams
Copy link
Member

@abadams abadams commented Feb 18, 2024

We were making a very large number stmt_uses_vars queries that covered the same sub-stmts. I solved it by adding a cache.

Speeds up local laplacian lowering by 10% by basically removing this pass from the profile.

Also a drive-by typo fix in Lower.cpp

We were making a very large number stmt_uses_vars queries that covered
the same sub-stmts. I solved it by adding a cache.

Speeds up local laplacian lowering by 10% by basically removing this
pass from the profile.

Also a drive-by typo fix in Lower.cpp
class CachingStmtUsesVars : public IRMutator {
const Scope<> &query;
bool found_use = false;
std::map<Stmt, bool> cache;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not std::set<> instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, just fer grins, would unordered_map or unordered_set be any better here? (Surely the order doesn't matter)

Copy link
Member Author

Choose a reason for hiding this comment

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

There are three possible states:

  • I've seen this stmt before and it doesn't contain the vars (map contains false)
  • I've seen this stmt before and it does contain the vars (map contains true)
  • I haven't seen this stmt before and it needs to be analyzed (not in the map)

Copy link
Member Author

Choose a reason for hiding this comment

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

I generally avoid unordered_set and unordered_map because every time I've benchmarked them within Halide they haven't been enough faster to outweigh a really annoying property that I've been burned by: If you have a bug where you accidentally depend on the order of the keys, it can fail on some machines but not others depending on the standard library used, which makes debugging it really annoying.

@abadams
Copy link
Member Author

abadams commented Feb 22, 2024

All green, just needs a review.

@abadams abadams merged commit aae84f6 into main Feb 26, 2024
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.

3 participants