]> foleosoft.com Git - QAnsel.git/commitdiff
Mon Mar 4 05:36:30 PM EST 2024
authormiha-q <>
Mon, 4 Mar 2024 22:36:30 +0000 (17:36 -0500)
committermiha-q <>
Mon, 4 Mar 2024 22:36:30 +0000 (17:36 -0500)
src/QAnsel.c

index 067d7a2b81d848f3deb20d188cf684c3e81b61db..f48de21df6c9de51826b36f9f027a1a976d906e3 100644 (file)
@@ -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);