Required prerequisites
Describe the bug
Running the compiler with -fno-array-conversion causes segfault in QIR translation phase
Steps to reproduce the bug
Run the code below
#include <cudaq.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <complex>
using namespace std::complex_literals;
CUDAQ_REGISTER_OPERATION(
unitary_1,
2, // Number of qubits
0, // Number of params
(std::vector<std::complex<double>>{
{0.48963027692339345, -0.25497750785839352},{-0.22290322074166435, 0.30788011301354312},{ 0.50693167801629657, -0.036611223283494282},{ 0.30200841137366813, 0.44860167656042738},
{-0.51738122275537601, -0.091208540881094272},{-0.83122487092786412, 0.079376387676733509},{ 0.088739148266466686, 0.010140598124231683},{ 0.082370385022818904, -0.10954417805917306},
{0.088186930618414469, 0.62478914049322731},{-0.097310507557154757, -0.3128004789016916},{ -0.035253085563191573, -0.27404382928458881},{ 0.64664643631039709, 0.0073284857955460466},
{-0.1010243030649756, 0.10441273962889276},{0.19981159839759674, -0.10512109154564615},{ 0.72831094545570485, 0.35626224934256495},{ 0.088607619728219733, -0.51254855126160204}
})
);
struct main_circuit {
uint64_t operator()() __qpu__ {
cudaq::qubit q0;
cudaq::qubit q1;
unitary_1(q0, q1);
return 0;
}};
int main(int argc, char* argv[]) {
auto kernel = main_circuit{};
return 0;
}
Compile:
external/cuda-quantum/build/bin/nvq++ -fno-array-conversion test.cpp -o test
Error:
external/cuda-quantum/build/bin/nvq++: line 27: 259349 Segmentation fault (core dumped) "$@"
failed: "/home/ilan/programming/QFpp/external/cuda-quantum/build/bin/cudaq-translate --convert-to=qir:0.1 test.qke.iCJ0fu -o test.ll.EHZxYU"
Replacing the custom unitary with some other primitive 2 qubit gate works. Compiling array conversion enabled works. This is presumably because the custom unitary vectors are treated as though they need dynamic heap allocation instead of creating the unitary matrix and embedding it in the quake call operation.
Expected behavior
Compiler should not segfault. If array conversion is expected, this should be communicated gracefully to the user.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
- CUDA-Q version:
b04dee51
- Python version: 3.12.3
- C++ compiler: clang++ 18.1.3
- Operating system: Ubuntu 24.04
Suggestions
No response
Required prerequisites
Describe the bug
Running the compiler with
-fno-array-conversioncauses segfault in QIR translation phaseSteps to reproduce the bug
Run the code below
Compile:
external/cuda-quantum/build/bin/nvq++ -fno-array-conversion test.cpp -o testError:
Replacing the custom unitary with some other primitive 2 qubit gate works. Compiling array conversion enabled works. This is presumably because the custom unitary vectors are treated as though they need dynamic heap allocation instead of creating the unitary matrix and embedding it in the quake call operation.
Expected behavior
Compiler should not segfault. If array conversion is expected, this should be communicated gracefully to the user.
Is this a regression? If it is, put the last known working version (or commit) here.
Not a regression
Environment
b04dee51Suggestions
No response