From 4f0a3e55c9727eca5a1bcdc3f4367ac5b5999531 Mon Sep 17 00:00:00 2001 From: miha-q <> Date: Mon, 4 Mar 2024 17:36:30 -0500 Subject: [PATCH] Mon Mar 4 05:36:30 PM EST 2024 --- src/QAnsel.c | 61 +++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/QAnsel.c b/src/QAnsel.c index 067d7a2..f48de21 100644 --- a/src/QAnsel.c +++ b/src/QAnsel.c @@ -7,6 +7,7 @@ #include "display.c" #include "chacha20.c" #define QUBITS_MAX 14 +//#define SPEED_TEST unsigned char HIDDEN_VARIABLE = 0; FILE* RANDOM_FILE; #define GPU_ENABLED @@ -211,7 +212,7 @@ void qansel_instruction(cpx_mtx_t* stateVector, unsigned char qubitCount, QInstr tmp.cols = filter.cols * gate.cols; tmp.ptr = malloc(tmp.rows * (tmp.cols * 2) * sizeof(float)); - + #ifdef SPEED_TEST printf("%ix%i (knk)\n", tmp.rows, tmp.cols); unsigned long int us1, us2; us1 = get_time(); @@ -226,19 +227,20 @@ void qansel_instruction(cpx_mtx_t* stateVector, unsigned char qubitCount, QInstr cpx_mtx_knk(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); us2 = get_time(); printf("\tBare: %lu\n", us2 - us1); - -// if (USE_GPU && 0) -// { -// cpx_mtx_knk_metal(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); -// } -// else if (USE_THREADS) -// { -// cpx_mtx_knk_threads(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); -// } -// else -// { -// cpx_mtx_knk(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); -// } + #else + if (USE_GPU && 0) + { + cpx_mtx_knk_metal(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); + } + else if (USE_THREADS) + { + cpx_mtx_knk_threads(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); + } + else + { + cpx_mtx_knk(tmp.ptr, filter.ptr, gate.ptr, filter.rows, filter.cols, gate.rows, gate.cols); + } + #endif free(filter.ptr); @@ -249,6 +251,7 @@ void qansel_instruction(cpx_mtx_t* stateVector, unsigned char qubitCount, QInstr cpx_mtx_init(&tmp, stateVector->rows, stateVector->cols); + #ifdef SPEED_TEST printf("%ix%i (dot)\n", tmp.rows, tmp.cols); unsigned long int us1, us2; us1 = get_time(); @@ -263,21 +266,21 @@ void qansel_instruction(cpx_mtx_t* stateVector, unsigned char qubitCount, QInstr cpx_mtx_dot(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); us2 = get_time(); printf("\tBare: %lu\n", us2 - us1); - - - //if (USE_GPU) - //{ - // - // cpx_mtx_dot_metal(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); - //} - //else if (USE_THREADS) - //{ - // cpx_mtx_dot_threads(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); - //} - //else - //{ - // cpx_mtx_dot(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); - //} + #else + if (USE_GPU) + { + + cpx_mtx_dot_metal(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); + } + else if (USE_THREADS) + { + cpx_mtx_dot_threads(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); + } + else + { + cpx_mtx_dot(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); + } + #endif free(stateVector->ptr); stateVector->ptr = tmp.ptr; free(filter.ptr); -- 2.39.5