NVIDIA / cuda-quantum

C++ and Python support for the CUDA Quantum programming model for heterogeneous quantum-classical workflows
https://nvidia.github.io/cuda-quantum/
Other
552 stars 188 forks source link

Errors should be thrown for a kernel lambda that lacks a __qpu__ attribute #2267

Open amccaskey opened 1 month ago

amccaskey commented 1 month ago

It could be easy (I did it) for someone to write a kernel but forget the qpu attribute. In the following case, an error is not thrown.

#include "cudaq.h"
int main() {
  auto kernel = []() { cudaq::qvector q(2); };
}

The compiler should throw an error for this. It does throw an error for quantum allocations in free functions. I think I just caught it for lambdas.

schweitzpgi commented 5 days ago

I think this was intentionally allowed to support passing lambdas to top-level cudaq functions where the "kernel" aspect of the lambda is implied. Maybe we can narrow the loophole or get rid of it entirely.