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

Nested C++ QPU kernel does not accept std::vector parameters anymore #2535

Open
3 of 4 tasks
bebora opened this issue Jan 24, 2025 · 0 comments
Open
3 of 4 tasks

Nested C++ QPU kernel does not accept std::vector parameters anymore #2535

bebora opened this issue Jan 24, 2025 · 0 comments

Comments

@bebora
Copy link
Contributor

bebora commented Jan 24, 2025

Required prerequisites

  • Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
  • Make sure you've read the documentation. Your issue may be addressed there.
  • Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
  • If possible, make a PR with a failing test to give us a starting point to work on!

Describe the bug

nvq++ correctly compiles a quantum kernel with a std::vector parameter. However, if this std::vector is then passed to another kernel inside the original one, compilation fails.

Steps to reproduce the bug

Create vect.cpp:

#include <cudaq.h>
#include <vector>

__qpu__ void ApplyMaskedX(cudaq::qview<> qc, std::vector<int> mask)
{
    int s = qc.size();
    for (int i = 0; i < s; i++)
    {
        if (mask[i] == 1)
        {
            x(qc[i]);
        }
    }
}

struct RunKernel
{
    __qpu__ auto operator()(std::vector<int> mask)
    {
        cudaq::qvector qc(mask.size());
        ApplyMaskedX(qc, mask);
        mz(qc);
    }
};

int main()
{
    std::vector<int> mask = {1, 0, 1, 0, 0};
    auto res = cudaq::sample(1000, RunKernel{}, mask);
    res.dump();
}

Compile it:

$ nvq++ vect.cpp 
loc("vect.cpp":21:26):error: /cuda-quantum/lib/Frontend/nvqpp/ConvertExpr.cpp:2950: not yet implemented: C++ constructor (non-default)
vect.cpp:21:26: error: C++ constructor (non-default) is not yet supported
        ApplyMaskedX(qc, mask);
                         ^

The code compiles and runs if the innermost kernel is inlined inside the outer one as follows:

// includes...
struct RunKernel
{
    __qpu__ auto operator()(std::vector<int> mask)
    {
        cudaq::qvector qc(mask.size());
        int s = qc.size();
        for (int i = 0; i < s; i++)
        {
            if (mask[i] == 1)
            {
                x(qc[i]);
            }
        }
        mz(qc);
    }
};
// main...

Expected behavior

I expect to be able to pass outer std::vector parameters to sub-kernels to write composable functions.

Is this a regression? If it is, put the last known working version (or commit) here.

0.9.0

Environment

  • CUDA-Q version: 0.9.1 (pre-built binaries and cu12-0.9.1 Docker image)
  • Operating system: Ubuntu 22.04.5 LTS

Suggestions

No response

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

No branches or pull requests

1 participant