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

Make sure uccsd from cudaqx compiles for quantum devices #2458

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

annagrin
Copy link
Collaborator

@annagrin annagrin commented Dec 9, 2024

Description

Fix a number of issues with compiler passes discovered in uccsd compilation for quantum devices.

Details

  • uccsd: Update to not contain nested arrays
  • ast_bridge: Fix incorrect boundaries generated for range calls.
  • LiftArrayAlloc Fix crashes and incorrectly optimizing multiple stores into the same pointer
  • CollapseStores: Remove useless stores
  • Canonicalization: Add const prop for if(%true) and if(%false) statements
  • LoopNormalize: handle negative boundaries
  • LoopUnroll: Add other classic optimizations to run along LoopUnroll:
    • LoopNormalize
    • LiftArrayAlloc
    • CollapseStores
    • simplifyRegions
  • Add tests

Related: NVIDIA/cudaqx#64
Requires: #2570
Requires: #2571
Requires: #2572
Requires: #2573

Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
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>
Copy link

github-actions bot commented Dec 9, 2024

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

github-actions bot pushed a commit that referenced this pull request Dec 9, 2024
…x-for-demo

Signed-off-by: Anna Gringauze <agringauze@nvidia.com>
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>
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 Jan 30, 2025
Copy link
Collaborator

@schweitzpgi schweitzpgi left a 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).

Comment on lines +2072 to +2074
// Prevent quantum allocations from moving to an outer scope.
if (block && hasQuantumAllocations(*block))
return failure();
Copy link
Collaborator

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.

Comment on lines +2077 to +2080
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);
Copy link
Collaborator

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::IfOps. 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.

Comment on lines 20 to 21
CollapseStores.cpp
CollapseStoresPatterns.cpp
Copy link
Collaborator

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.

Comment on lines 38 to 39
LiftArrayAlloc.cpp
LiftArrayAllocPatterns.cpp
Copy link
Collaborator

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?

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 Jan 31, 2025
@annagrin annagrin marked this pull request as draft January 31, 2025 19:58
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 Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants