aboutsummaryrefslogtreecommitdiff
path: root/src/core/runtime.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-13 08:07:10 +0200
committerhachem <im@hachem.wtf>2026-09-13 08:07:10 +0200
commitae07aab1442a45bbddb79e066f15eaf252a4254a (patch)
tree111ae3073f25059ec29145548aa81305e4b024fb /src/core/runtime.c
parentc0405cc8a81e6197df976d3135db413b6c74ba90 (diff)
wire simd into runtime execution
Diffstat (limited to 'src/core/runtime.c')
-rw-r--r--src/core/runtime.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/core/runtime.c b/src/core/runtime.c
index 0e5cf9d..950ec7c 100644
--- a/src/core/runtime.c
+++ b/src/core/runtime.c
@@ -4,6 +4,7 @@
#include "core/gates.h"
#include "core/kernel.h"
#include "maths/complex.h"
+#include "maths/simd.h"
struct PsiRuntimeConfig psi_new_runtime_config(void)
{
@@ -121,6 +122,31 @@ static struct PsiVector new_zero_state(size_t num_qubits)
return state;
}
+static void execute_kernels(struct PsiVector *state, const struct PsiKernel *kernels, size_t count, size_t num_qubits, struct PsiRuntimeConfig config)
+{
+ bool use_parallel = config.parallel && num_qubits >= config.parallel_threshold;
+
+ for (size_t i = 0; i < count; i++)
+ {
+ struct PsiKernel kernel = kernels[i];
+
+ if (config.simd && kernel.target_count == 1)
+ {
+ struct PsiComplex gate[2][2] = {
+ { kernel.matrix.data[0], kernel.matrix.data[1] },
+ { kernel.matrix.data[2], kernel.matrix.data[3] },
+ };
+
+ if (use_parallel)
+ psi_apply_single_qubit_gate_simd_parallel(state->data, gate, kernel.targets[0], num_qubits);
+ else
+ psi_apply_single_qubit_gate_simd(state->data, gate, kernel.targets[0], num_qubits);
+ }
+ else
+ psi_apply_kernel(state, kernel, num_qubits);
+ }
+}
+
struct PsiVector psi_compute_runtime_config(struct PsiRuntimeConfig config, size_t num_qubits, const struct PsiGateOp *operations, size_t op_count)
{
struct PsiVector state = new_zero_state(num_qubits);
@@ -136,7 +162,7 @@ struct PsiVector psi_compute_runtime_config(struct PsiRuntimeConfig config, size
}
psi_optimize_structure_aware_batch(&batch);
- psi_execute_structure_aware_batch(batch, &state);
+ execute_kernels(&state, batch.kernels, batch.count, num_qubits, config);
psi_free_structure_aware_batch(&batch);
return state;
@@ -153,7 +179,7 @@ struct PsiVector psi_compute_runtime_config(struct PsiRuntimeConfig config, size
if (config.batched)
psi_optimize_kernel_batch(&batch);
- psi_execute_kernel_batch(batch, &state);
+ execute_kernels(&state, batch.kernels, batch.count, num_qubits, config);
psi_free_kernel_batch(&batch);
return state;