-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Conditional Loop Partitioning - Extending to remove if conditions #1797
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
Conditional Loop Partitioning - Extending to remove if conditions #1797
Conversation
|
Ping |
|
We are testing for this patch, will give feedback soon. |
|
Thanks @xqdan, please feel free to provide more testcases if something is of your interest and doesn't work with this patch. |
|
@anijain2305 could you try this case. |
|
more cases: |
|
@xqdan Thanks for providing the test cases. Current situation is
|
|
hi, import tvm def test(): test() |
src/pass/loop_partition.cc
Outdated
| Stmt post_body = Substitute(body, {{Var{var}, var + post_doubt_begin}}); | ||
| post_stmt = MakeFor(node, max - post_doubt_begin + 1, post_body); | ||
| Stmt post_body; | ||
| // If the loop is going from 0 to 1, then replace the loop var with min value |
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.
remove then
|
@RichardFido Can you please edit the code to print it nicely? It doesn't compile as of now |
|
sorry about that. @anijain2305 |
| if (*as_const_int(max) == *as_const_int(post_doubt_begin)) { | ||
| post_body = Substitute(body, {{Var{var}, post_doubt_begin}}); | ||
| post_stmt = post_body; | ||
| } |
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.
just trying to understand, why this need to be handled separately?
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.
An example usecase is as follows. This is what statement looks in between the CLP is running
for (i = 0, 1)
for(j = 0, 8)
if(i + j < 4)
Do_something
If the loop bounds are going from 0 to 1, then its better to replace i with 0 because then it simplifies the conditions, resulting in better partitioning.
|
@RichardFido The example doesn't work because of the rigid structure of how bounds are deduced for the conditionals. I do not understand that portion of the code. There is an easy workaround for now. If the constant is not present on the right side alone, then the deduce_bound function does not work correctly. Solving for any combination of conditions will require decent changes in deduce_bounds functions or Simplify pass. I do not plan to work on that in this PR. |
|
I suggest we can merge this PR first, we can send more PR to support other cases someone may need. |
|
OK, reviewer, please take another round of look and https://docs.tvm.ai/contribute/code_review.html#approve-and-request-changes-explicitly |
|
THanks @xqdan @MarisaKirisame @anijain2305 @yzhliu this is now merged |
The following PR accomplishes 2 items in the context of loop partitioning pass
Illustrative example
Input
Output
Example with multiple if conditions
Input
Output