C++ segfault when passing callable kernel to another kernel from library
Open
Nobody has claimed this yet.
bug
critical
stale-notified
- Dominant language
- C++
- Stars
- 1.1k
- Forks
- 456
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 165
Description
Take the following files
// lib.h
#include "cudaq.h"
void kernel(cudaq::qvector<>& q);
// lib.cpp
#include "lib.h"
__qpu__ void kernel(cudaq::qvector<>& q) {
x(q[0]);
}
and
// user.cpp
#include "lib.h"
__qpu__ void userKernel(const std::function<void(cudaq::qvector<> &)> &init) {
cudaq::qvector q(2);
init(q);
}
int main() { userKernel(kernel); }
Compile and link with the following
nvq++ --enable-mlir -fPIC -c lib.cpp -o lib.o
nvq++ --enable-mlir -fPIC lib.o user.cpp
# The run
CUDAQ_LOG_LEVEL=info ./a.out
This results in a segmentation fault.
Can anyone else reproduce this? I would be very thankful for anyone's help on this one. This kind of pattern will be a primary feature of future downstream libraries.
Another variation would be this
// lib.h
#include "cudaq.h"
std::function<void(cudaq::qvector<>&)> get_kernel();//cudaq::qvector<>& q);
// lib.cpp
#include "lib.h"
__qpu__ void kernel(cudaq::qvector<> &q) { x(q[0]); }
std::function<void(cudaq::qvector<> &)> get_kernel() { return kernel; }
#include "lib.h"
__qpu__ void userKernel(const std::function<void(cudaq::qvector<> &)> &init) {
cudaq::qvector q(2);
init(q);
}
int main() { userKernel(get_kernel()); }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.