-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[RFC][EXPR] Formalize Integer Arithmetic Analysis #2588
Comments
Concerning using int32/int64 for indices, I think we should create a separate, conceptually unbounded integer type for index arithmetic. Ideally, in compile-time we should use some arbitrary precision integer library for it, but using int64 may do as a starting point. (And of course it should be represented with int32/64 in run-time). |
@tqchen I think this is very important direction to improve. Have you thought about using existing libraries like ISL? As far as I know it contains many useful algorithms and, more importantly, well-defined notation for describing formulas and relations of variables. |
re conceptual integer index. I think moving toward int64 as default and do optional narrowing is a good starting point as @sgrechanik-h pointed out. re ISL. My understanding of isl is that it tries to do exact integer set analysis, and uses a constraint solver based approach(although I am not an expert in isl). As a result, it has some restrictions in terms of operation, as well as speed of solving. In our case, we aim at providing simple forward solving ways for relaxed integer set analysis. Integer set abstraction and pushing most analysis to integer set primitives are important, and we should learn that perspective from isl. On the other hand, I think the first pass of scaffolding should aim to build a self-contained analyzer. Then we can see if there is value to bring isl as an optional sub-anlayzer. |
Constant bound analyzer #2668 |
Followup discussion with @sgrechanik-h on memoization. At the current moment, I tried to avoid memoization as much as possible mainly because memoization can cause problems when we update context information about variable x(and previously computed transformation about x related expression may no longer hold. I think this might be a good strategy we can take for now. The cost is that there might be some repetitive computations, however, given most expressions are not deep, this may not be a too big problem. One way to get around this problem is renaming (we rename the variable to another one every time its context information changes). This might need some thoughts and change in the IR, but it follows the same spirit as SSA. Alternatively, the strategy is to actively clean up the cache when there any context information change. One of the first analyzer memoization analyzer is common sub-expression folding and canonicalization, which maps two instances of x + y into the same address. In this case, because it is not dependent on the context information, we are fine. |
In my opinion, analyses should be pure functions, something like |
The main problem of making things pure is the cost of copy when updating the Context(because of the need for context to be immutable) and that may not be best for efficiency. |
@tqchen I guess we cannot know for sure: the performance benefits of memoization may outweigh the possible performance losses due to immutability. What is more important is that pure functions often make things more clear to think about. |
What I mean is that we can support memoization even if we don’t do the functionally style, as I outlined in the last post |
@tqchen One thing I wanted to clarify: why isn't the Analyzer class integrated into the Node hierarchy? Instead some separate closure-based mechanism is used for python integration, which feels strange and seemingly makes it harder to create functions which accept Analyzer objects and work across both languages. |
@sgrechanik-h This is a very good point. I have thought about it, but the conclusion then was it may not be as useful. But you are right that we might get to a stage where we need to pass Analyzer objects around and it makes sense to make Analyzer as a Node. |
#3368 finishes the migration of the analysis stack. Thanks to everyone's effort in helping reviews and contributing code to the new Analyzer. |
The integer analysis (arith namespace) serves as a foundational tool for the low-level code generation. At this point, the analysis code is somewhat scattered in the codebase. This RFC proposes to revamp them.
Here is the list of currently related code:
We have also seen issues on this topic.
Most of the current analysis functions can be put into two categories:
e1 \subset S
.{x * factor + base}
Relaxed integer set analysis only requires us to find a superset of the corresponding set. Such relaxation allows us to deal with cases such as division or other functions.
Here is a list of observations about these analysis functions.
Given these observations, the new API is a super analyzer that carries states about the context information, and bundles sub-analyzers.
Proposed sub-analyzers
Each sub-analyzer will use memoization to cache the intermediate result. Importantly, each sub-analyzer has a handle(weak reference) back to the super analyzer to allow them to call other sub-analyzers. A user needs to create a super analyzer, populates related context states, and run the analysis.
Followup Goals Enabled by This Proposal
There are several things that formalization can enable.
Proposed Steps
Comments are welcomed.
The text was updated successfully, but these errors were encountered: