-
Notifications
You must be signed in to change notification settings - Fork 248
[py] Fix loop invariant attribute. #2767
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
base: main
Are you sure you want to change the base?
Conversation
56a2a4a
to
1c0d1cb
Compare
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
bodyBuilder, | ||
startVal=startVal, | ||
stepVal=stepVal, | ||
isDecrementing=isDecrementing) |
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.
Something like this must be normalized. Is the cc-loop-normalize pass being run?
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.
Hard to know. The pass does get run in various places but I'm not sure if it cover all paths used to execute Python kernels. Is this pass a requirement in all cases or only when doing other loop transformations ?
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.
Normalization transforms the iteration space of a loop to a counted or invariant form.
More precisely, if we have a loop like
for (i = start_expr; comparison(i, stop_expr); i = step_expr(i)) ....
this loop in normalized form is more like
for (i' = 0; i' < new_uppser_bound_expr; i' = i' + 1) {
i = some_expr(i');
....
}
Once in this form, the loop is much more amenable to loop transformations such as unrolling.
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.
So it is not a requirement for loops that are already normalized, but if Python is creating a loop that descends or uses a step other than 1, the loop must be normalized.
Normalization ought to be part of the new "classical optimizations" pipeline by default.
1c0d1cb
to
1de30f8
Compare
Python's for-loops are not guaranteed to be invariant. The AST bridge would need to do further analysis to guarantee the property. This PR does not add such an analysis, but fixes the places where the bridge might wrongly label a for-loop invariant when, in reality, it might not be. Signed-off-by: boschmitt <[email protected]>
1de30f8
to
5cd7492
Compare
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Description
Python's for-loops are not guaranteed to be invariant. The AST bridge would need to do further analysis to guarantee the property. This PR does not add such an analysis, but fixes the places where the bridge might wrongly label a for-loop invariant when, in reality, it might not be.