-
Notifications
You must be signed in to change notification settings - Fork 207
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
Make sure uccsd from cudaqx compiles for quantum devices #2458
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…x-for-demo Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
…x-for-demo Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
…x-for-demo Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
I, Anna Gringauze <agringauze@nvidia.com>, hereby add my Signed-off-by to this commit: ae35d16 Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
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.
I don't like the idea of making the patterns reside in files other than the pass where they are applied. That's not been the practice. So I think we should merge them back.
The exception to this general rule is when patterns are shared in multiple passes, which these are not AFAICT. Instead of block copying the same pattern in 2 or more different passes and where they will become hopelessly out of synch with one another, we want to put the pattern in an include file (foo.inc
) and include that file in the n passes where it is needed. The patterns in LowerToCFG for IfOp is such a case, since it will be the same rewrite in LowerToCFG (indiscriminate) and in the canonicalization pattern you want to add (selected only when the condition is constant).
// Prevent quantum allocations from moving to an outer scope. | ||
if (block && hasQuantumAllocations(*block)) | ||
return failure(); |
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.
Was there an example where this happened? If so, the IR has bugs.
Any allocations must be either in a basic block owned by the func::FuncOp, cc::LambdaCreateOp, or a cc::ScopeOp. So this check isn't needed for valid IR.
if (auto cont = dyn_cast<cudaq::cc::ContinueOp>(block->back())) { | ||
for (std::size_t i = 0; auto opnd : ifOp.getResults()) | ||
rewriter.replaceAllUsesWith(opnd, cont.getOperand(i++)); | ||
rewriter.eraseOp(cont); |
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.
There is code in LowerToCFG.cpp that folds away cc::IfOp
s. I think you can use the RewriteIf
pattern directly from there (share it in an .inc
file). Basically, we would use that pattern on any IfOp
with a constant argument. Using the pattern will get the linear arguments propagated correctly. Also, since the argument is a constant, DCE will simply clean things up and fuse the blocks, etc.
CollapseStores.cpp | ||
CollapseStoresPatterns.cpp |
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 looks like these ought to be combined into 1 file. We put the patterns in the same source file with the pass.
LiftArrayAlloc.cpp | ||
LiftArrayAllocPatterns.cpp |
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.
I'm not sure why these are being split into two files in this PR?
…x-for-demo Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Description
Fix a number of issues with compiler passes discovered in
uccsd
compilation for quantum devices.Details
uccsd
: Update to not contain nested arraysast_bridge
: Fix incorrect boundaries generated forrange
calls.LiftArrayAlloc
Fix crashes and incorrectly optimizing multiple stores into the same pointerCollapseStores
: Remove useless storesif(%true)
andif(%false)
statementsLoopNormalize
: handle negative boundariesLoopUnroll
: Add other classic optimizations to run alongLoopUnroll
:LoopNormalize
LiftArrayAlloc
CollapseStores
simplifyRegions
Related: NVIDIA/cudaqx#64
Requires: #2570
Requires: #2571Requires: #2572
Requires: #2573