NVIDIA / NVIDIA/cuda-quantum

Support calling kernel_builder<qreg,...> from CUDA Quantum Kernel

Open
#659 1 comment 0 reactions 3 assignees View on GitHub

@1tnguyen is already working on this.

Since Sep 14, 2023.

enhancement stale-notified
Dominant language
C++
Stars
1.1k
Forks
456
Avg merge
1d 22h
Merged PRs (30d)
165

Description

#include "cudaq.h"
#include "cudaq/builder/kernels.h"
#include <iostream>

struct kernel {
  void operator()(auto &&callable) __qpu__ {
    cudaq::qreg q(2);
    callable(q);
  }
};

int main() {

  std::vector<std::complex<double>> state{.70710678, 0., 0., 0.70710678};
  auto [bell, qubits] = cudaq::make_kernel<cudaq::qreg<> &>();
  cudaq::from_state(bell, qubits, state, 2);
  std::cout << bell << "\n";

  kernel test;
  cudaq::sample(test, bell).dump();
}

The issue with this is that a pure-device kernel (bell) created by the kernel_builder does not generate a .thunk function since GenKernelExecution will not add the kernel to the worklist at line 720. So when the callable(q) call happens, kernel_builder::operator()(Args...) is invoked, but fails in the JIT compilation (no thunk, kernelReg, kernelInit, etc), and in invokeCode we'll have no way to call it since there is not thunk.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.