-
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] Add additional termination condition to For node to enable While loop like feature #7385
Conversation
commit ee2363b Author: Masahiro Masuda <masahi129@gmail.com> Date: Fri Jan 29 11:44:02 2021 +0900 enable extern lib offload for nvptx
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.
LGTM! This is awesome stuff.
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.
LGTM. Longer term we probably want to add this to hybrid script and/or tvm script
@@ -802,6 +802,9 @@ class ForNode : public StmtNode { | |||
ForKind kind; | |||
/*! \brief The body of the for loop. */ | |||
Stmt body; | |||
/*! \brief The additional termination condition of the for loop. */ | |||
Optional<PrimExpr> test; |
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.
It would be helpful to have a RFC discussion, since different strategies changes to the IR can have different implications
Thanks @masahi . I think it is great to enable support for some form of While loop. It would be great to have an RFC thread discussing the alternatives in the IR node design. Since the IR node design can impact the general ability to do analysis and will impact how would we engineer future transformation passes. For example, I can see two possible variants:
V0 means the for loop is somewhat overloaded for both while and For. On one hand it brings the benefit of richer semantics and the minimum set of changes to enable such feature. This does mean that the visitors to For would need to handle the semantics of break. Given that the for loop is used for regular interval analysis, it could be beneficial to distinguish between "regular structured loop" vs "un-structured loop", unless the condition testing also offers some analysis benefits. I think this PoC is a great start and would be great to have a design discussion over the RFC |
@tqchen Yes, what you said totally makes sense to me. As you said, this is a minimal-change solution, but I think ideally we want a separate I'll send a RFC, sure. |
TIR While node added in #7425 |
This is my proposed solution to add While loop like feature to TIR, in the simplest, the least invasive way. It generalizes the For node termination condition from
to
Using this, we can write binary search as follows (see the complete test case, which implements numpy
searchsorted
function, here).My motivation was to improve GPU NMS performance using while loop, and it indeed did:
NMS workload from PyTorch MaskRCNN:
And a crazy 120000 box + 100
max_out_size
NMS workload from TF MaskRCNN. The difference is huge because the # of iterations changed from 120000 to 100 (roughly)please review @tqchen @mbrookhart @kevinthesun @zhiics @Laurawly @anijain2305 @trevor-m