29 #include <tbb/queuing_mutex.h> 33 tbb::queuing_mutex libmutex;
35 void unload_groq_sv_lib_unlocked();
36 int init_groq_sv_lib_unlocked(
const int reserved_device_num,
int initialize_id_in);
48 int (*
calcsvKernelGroq_dll)(
int num_gates,
float* gates,
int* target_qubits,
int* control_qubits,
float* result_real,
float* result_imag,
int device_num) = NULL;
80 tbb::queuing_mutex::scoped_lock lock(libmutex);
81 unload_groq_sv_lib_unlocked();
87 void unload_groq_sv_lib_unlocked()
106 tbb::queuing_mutex::scoped_lock lock(libmutex);
107 return init_groq_sv_lib_unlocked(reserved_device_num, initialize_id_in);
113 int init_groq_sv_lib_unlocked(
const int reserved_device_num,
int initialize_id_in ) {
115 initialize_id = initialize_id_in;
117 unload_groq_sv_lib_unlocked();
123 handle_sv = dlopen(lib_name.c_str(), RTLD_NOW);
125 std::string err(
"init_groq_lib: failed to load library " + lib_name +
" - " + std::string(dlerror()));
157 void apply_to_groq_sv(
int reserved_device_num,
int chosen_device_num,
int qbit_num, std::vector<Matrix>& u3_qbit, std::vector<int>& target_qbits, std::vector<int>& control_qbits,
Matrix& quantum_state,
int id_in) {
166 tbb::queuing_mutex::scoped_lock lock(libmutex);
167 if (
handle_sv == NULL && !init_groq_sv_lib_unlocked(reserved_device_num, id_in)) {
168 throw std::string(
"Could not load and initialize Groq library");
178 tbb::queuing_mutex::scoped_lock lock(libmutex);
180 if ( quantum_state.
size() == 0 ) {
181 if (
load_sv_dll( NULL, qbit_num, chosen_device_num) ) {
182 throw std::string(
"Error occured while reseting the state vector to Groq LPU");
185 quantum_state =
Matrix( matrix_size, 1);
191 throw std::string(
"apply_to_groq_sv: the size of the input vector should be in match with the number of qubits");
194 if ( quantum_state.
cols != 1 ) {
195 throw std::string(
"apply_to_groq_sv: the input state should have a single column");
199 std::vector<float> inout;
200 inout.reserve(quantum_state.
size()*2);
201 for (
size_t idx = 0; idx < quantum_state.
rows; idx++) {
202 inout.push_back(quantum_state.
data[idx].
real);
203 inout.push_back(quantum_state.
data[idx].
imag);
212 throw std::string(
"Error occured while uploading state vector to Groq LPU");
222 std::vector<float> gateMatrices;
223 gateMatrices.reserve( 4*u3_qbit.size()*2 );
224 for (
const Matrix& m : u3_qbit) {
225 for (
size_t i = 0; i < m.rows; i++) {
226 for (
size_t j = 0; j < m.cols; j++) {
228 gateMatrices.push_back( m.data[i*m.stride+j].real );
229 gateMatrices.push_back( m.data[i*m.stride+j].imag );
240 if (
calcsvKernelGroq_dll(u3_qbit.size(), gateMatrices.data(), target_qbits.data(), control_qbits.data(), transformed_sv_real.
get_data(), transformed_sv_imag.
get_data(), chosen_device_num)) {
241 throw std::string(
"Error running gate kernels on groq");
251 quantum_state.
data[idx].
real = transformed_sv_real[idx];
252 quantum_state.
data[idx].
imag = transformed_sv_imag[idx];
void apply_to_groq_sv(int reserved_device_num, int chosen_device_num, int qbit_num, std::vector< Matrix > &u3_qbit, std::vector< int > &target_qbits, std::vector< int > &control_qbits, Matrix &quantum_state, int id_in)
Call to pefrom the state vector simulation on the Groq hardware.
void unload_groq_sv_lib()
Call to unload the programs from the reserved Groq cards.
size_t(* get_accelerator_avail_num_sv_dll)()
int init_groq_sv_lib(const int reserved_device_num, int initialize_id_in)
Call to allocated Groq cards for calculations.
int(* load_sv_dll)(float *data, size_t num_qubits, size_t device_num)
int get_initialize_id()
Call to get the identification number of the inititalization of the library.
int(* initialize_groq_sv_dll)(int accelerator_num)
scalar * data
pointer to the stored data
data
load the unitary from file
Header file for Groq LPU support in state vector simulation.
scalar * get_data() const
Call to get the pointer to the stored data.
int rows
The number of rows.
int cols
The number of columns.
void(* releive_groq_sv_dll)()
int(* calcsvKernelGroq_dll)(int num_gates, float *gates, int *target_qubits, int *control_qubits, float *result_real, float *result_imag, int device_num)
Double-precision complex matrix (float64).
int size() const
Call to get the number of the allocated elements.
size_t(* get_accelerator_free_num_sv_dll)()
double real
the real part of a complex number
double imag
the imaginary part of a complex number