Repository navigation
Cache symbol replacement results by replacement and range versions - #203251
Closed
laithsakka wants to merge 4 commits into
Closed
laithsakka wants to merge 4 commits into
laithsakka wants to merge 4 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Human : I am fixing some caching bugs, that makes cache misses more often, but for replace , find those shall not be effected.
since those are very important we can use a less strict requirement than _version_counter , by only tracking _replacements_version_counter and _var_to_range_version_counter.
this is for perf. we already track both counters.
ranges are needed too: _find (and so replace) can return a partially resolved replacement when the fully resolved one isn't known to fit the symbol's range, and that changes once ranges narrow.
Invalidate
ShapeEnv.replace,ShapeEnv._findandSymNode.exprwith_replacements_version_counterand_var_to_range_version_counterinstead of the global_version_counter. Runtime asserts, axioms and divisibility changes now keep these results warm; replacement and range changes still clear them. Extend_lru_cachewith areplacements_and_rangesoption; all other caches continue using_version_counter.Ranges are part of the key because
_find's result depends on them. Witha -> b + 1andb -> c + d,_find(a)tries to storec + d + 1asa's replacement._set_replacementrejects it unlessc + d + 1is known to lie withina's range (e.g.ain [0, 100] withc,dunbounded), so_find(a)andreplace(a)returnb + 1until the ranges ofcanddnarrow.SymNode.exprpreviously keyed only on_replacements_version_counter, so after a range change it kept the less resolved result. It now checks both counters.The symbolic op memo is fixed separately in the next diff.
Authored with an AI assistant.
@exported-using-ghexport
Differential Revision: D128486311
Differential Revision: D128486311