# Backends and Execution **Backends** are the execution targets: simulators (CPU, GPU) or real quantum hardware. CUDA-Q abstracts backends—same kernel code runs on any target. ```cpp #include "cudaq.h" #include struct SimpleKernel { void operator()() __qpu__ { cudaq::qvector q(2); h(q[0]); cx(q[0], q[1]); mz(q); } }; int main() { // List available backends auto backends = cudaq::available_backends(); for (const auto& backend : backends) { printf("Available: %s\n", backend.c_str()); } // Set backend at runtime cudaq::set_target("nvidia"); // GPU simulator (cuQuantum) auto gpu_result = cudaq::sample(1000); printf("GPU result:\n"); for (auto& [bits, count] : gpu_result) { printf(" %s: %lu\n", bits.c_str(), count); } // Switch to CPU simulator cudaq::set_target("qpp"); auto cpu_result = cudaq::sample(1000); printf("CPU result:\n"); for (auto& [bits, count] : cpu_result) { printf(" %s: %lu\n", bits.c_str(), count); } // Connect to real hardware (if available) cudaq::set_target("iqm"); // IQM backend // auto hw_result = cudaq::sample(1000); return 0; } ``` ## Backend Types **GPU Simulators** (nvidia, cuQuantum): fast for 20–30 qubits, perfect fidelity **CPU Simulators** (qpp, stim): universal but slower **Hardware Providers** (IQM, IonQ, etc.): real quantum processors