-
Notifications
You must be signed in to change notification settings - Fork 7
New lowering pass: loop rotation #2500
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
Conversation
This reverts commit 5eb594f.
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.
Still working on, but some initial comments
I get this build error (clang 13):
|
I think this is a bug of clang, but I changed the code to |
Yeah, looks like so. I don't see any error with the change. |
inlineMost(); | ||
fusion.rotateLoop(tv4, -1, {tv1, tv2}); |
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.
This looks inconsistent to me. Both are a fusion-wide operation, and one implicitly uses the fusion from a FusionGuard
, but another is a method of Fusion
. I'd say just rotateLoop(tv4, -1, {tv1, tv2});
would align well with the existing APIs.
Just curious, can loop rotation be nested? Not that I think it's important. |
I don't think so. To support nested loop rotation, we need to carefully handle the |
OK. Maybe add a comment about it? |
Actually, it is pretty easy to support it with very little extra work: I can just rotate one loop each pass. I updated this PR to support this in 67f7df3 |
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.
Approving now. Thanks for the updates. This is still not something I like, #2500 (comment), but it's a question on code style, and it shouldn't block the PR.
This PR adds a new lowering pass: loop rotation.
Loop rotation is a loop transformation that transforms the code like below
into something like:
Right now, because existing predicates should already cover all illegal access, I am not materializing the
0 < n
andi + 1 < n
predicates, so I am actually generating:Loop rotation is conceptually very simple regarding index and predicate lowering, and their changes are mostly mechanical. For the trivial loop
for i = 0
, our index and predicate lowering should already handle it correctly. For the exprs inside theif i + 1 < n
block, the only change needed is to replace all theloop->index()
withloop->index() + 1
, which requires me to detect theif i + 1 < n
block and mark its body as "rotated" during index and predicate lowering.In order to use loop rotation, users can do
fusion.rotateLoop(tv, dim, {tv1, tv2})
, then during lowering, the looptv->axis(dim)
will be rotated, and the expressions allocating and computingtv1
andtv2
will be the rotated exprs.