Skip to content
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

Implement a loop peeling pass. #824

Merged
merged 1 commit into from
Oct 30, 2023
Merged

Conversation

schweitzpgi
Copy link
Collaborator

This pass only implements a very resricted form of loop peeling. Specifically, a do-while loop is peeled and converted into a copy of the body of the do and a succeeding while loop.

The purpose of this transformation is to allow do-while loops to be converted to while loops. Once unrolling of general while loops is enabled, the compiler will be able to fully unroll a wider range of styles of loop statements.

@schweitzpgi schweitzpgi added the enhancement New feature or request label Oct 25, 2023
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 25, 2023
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 26, 2023
@copy-pr-bot
Copy link

copy-pr-bot bot commented Oct 26, 2023

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@schweitzpgi
Copy link
Collaborator Author

schweitzpgi commented Oct 26, 2023

/ok to test

Command Bot: Processing...

@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 26, 2023
@schweitzpgi schweitzpgi enabled auto-merge (squash) October 26, 2023 00:45
@schweitzpgi schweitzpgi force-pushed the ch-loop.peeling branch 2 times, most recently from b27bbdc to 6ef8df1 Compare October 26, 2023 17:49
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 26, 2023
Copy link
Collaborator

@bmhowe23 bmhowe23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work if there are alloca's in the loop body? It looks like the current tests don't have any cc.alloc's or quake.alloca's in the loop body. I could be wrong, but it seems like special handling would be needed to handle that.
(Maybe it doesn't matter because there would also be corresponding dealloc's.)

@schweitzpgi
Copy link
Collaborator Author

Will this work if there are alloca's in the loop body? It looks like the current tests don't have any cc.alloc's or quake.alloca's in the loop body. I could be wrong, but it seems like special handling would be needed to handle that. (Maybe it doesn't matter because there would also be corresponding dealloc's.)

No special handling is needed.

A quake.alloca must be scoped or have a mirroring quake.dealloc. Specifically, it must appear within the body of a function or a cc.scope. Passes like add-dealloc and unwind-lowering can relax this requirement by introducing explicit quake.dealloc ops.

For the case in hand, any qubits allocated within the body of a do-while will be scoped or mirrored. So just like unrolling, each qubit's allocation and deallocation will happen exactly once per iteration.

This pass only implements a very resricted form of loop peeling.
Specifically, a do-while loop is peeled and converted into a copy of the
body of the do and a succeeding while loop.

The purpose of this transformation is to allow do-while loops to be
converted to while loops. Once unrolling of general while loops is
enabled, the compiler will be able to fully unroll a wider range of
styles of loop statements.

Fix some bugs and extend test to include loop with region arguments.
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 27, 2023
@schweitzpgi schweitzpgi merged commit da71c3d into NVIDIA:main Oct 30, 2023
105 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2023
@schweitzpgi schweitzpgi deleted the ch-loop.peeling branch October 30, 2023 14:42
@bettinaheim bettinaheim added release notes Changes need to be captured in the release notes and removed enhancement New feature or request labels Nov 15, 2023
@bettinaheim bettinaheim added this to the release 0.5.0 milestone Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release notes Changes need to be captured in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ranged for loops, std::reverse iterator modifier, and cudaq::range
3 participants