-
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
[TIR] Bugs in HoistIfThenElse #5559
Comments
@kevinthesun it would be great if you can followup |
@roastduck Thank you for bringing these up. This pass was tested only for limited number of cuda conv2d workloads, and not production ready yet. It would be great if you can help fix or improve this pass. |
@roastduck would you be interested in taking over the pass? |
I met some difficulties improving this pass. For now, I'm not going to take over it. This pass massively utilizes low level semantics such as |
We could certainly rewrite the pass completely, instad of the PostOrderVisit |
Given that this pass is not product ready and we have not yet migrated this pass to the transform. Perhaps we can remove the pass for now, and then add it back once we have a better impl. Leaving the thread open for a week to see how would everyone think |
This pass has not been migrated to the new transform API, and contains potential bugs per apache#5559. Given that it is not being actively used, this PR remove this pass from the collection. Followup PRs are more than welcomed to land a better version that conforms with the new transform API.
#5944 removes this pass for now. |
This pass has not been migrated to the new transform API, and contains potential bugs per #5559. Given that it is not being actively used, this PR remove this pass from the collection. Followup PRs are more than welcomed to land a better version that conforms with the new transform API.
This pass has not been migrated to the new transform API, and contains potential bugs per apache#5559. Given that it is not being actively used, this PR remove this pass from the collection. Followup PRs are more than welcomed to land a better version that conforms with the new transform API.
This pass has not been migrated to the new transform API, and contains potential bugs per apache#5559. Given that it is not being actively used, this PR remove this pass from the collection. Followup PRs are more than welcomed to land a better version that conforms with the new transform API.
HoistIfThenElse
is a pass currently not enabled in TVM. I tried to enable it in #5553, but there are too many bugs in this pass. Let's fix them first.BUG 1:
HoistIfThenElse
transformsinto
Possible cause:
https://github.com/apache/incubator-tvm/blob/0e877521f454e239f5c44bb88e557801444d81a5/src/tir/pass/hoist_if_then_else.cc#L295
It only checks whether
if_stmt
has a preferred position, but that position is not guaranteed to be the current position. Change it toif (if_position_map.count(if_stmt.get()) && if_position_map.at(if_stmt.get()).as<ForNode>()->loop_var.get() == top_for_var) {
may solve the problem.
BUG 2:
src/tir/transforms/split_host_device.cc
want the IR to be an SSA form, where each variable can only be defined once. Since we are copying loops into both "then" branches and "else" branches, we have to rename the loop variables in "else" branches to be different from those in "then" branches. I have already written some code for this, see #5553.BUG 3:
IfThenElse
nodes containing thread indices should not be hoisted over the definition of the indices. This would happen whenAttr
node forthread_extent
is scheduled into the body of aFor
node, using acompute_at
command. I have already written some code for this, see #5553.BUG 4:
https://github.com/apache/incubator-tvm/blob/0e877521f454e239f5c44bb88e557801444d81a5/src/tir/pass/hoist_if_then_else.cc#L371
Look at this line.
if_stmt
can already been updated when running this line. Look at the example below.After hoisting
j >= 3
, if becomesNow, when we are hoisting
i >= 3
, we need to compare and removeBut
j >= 3
has been gone, soRemoveIf
fails. We have to track the updating toIfThenElse
just like what we did forFor
.BUG 5: It is for tests this time.
https://github.com/apache/incubator-tvm/blob/0e877521f454e239f5c44bb88e557801444d81a5/tests/python/unittest/test_tir_pass_hoist_if.py#L175
Why do we expect a
('For', 'j')
inside itself? As a potential problem, maybe we should change the variable names to prevent there are twoi
s and twoj
s.These are all the bugs I found.
Beside, I suggest changing all the
for (size_t i = 0; i < xxx.size(); i++)
intofor (size_t i = 0, n = xxx.size(); i < n; i++)
, since C++ compiler can't detect this loop invariant.@kevinthesun Maybe you can have a look.
The text was updated successfully, but these errors were encountered: