From d2858ed4f97b7b7beea4ad7b39384246fb4882da Mon Sep 17 00:00:00 2001 From: miha-q <> Date: Mon, 4 Mar 2024 17:26:41 -0500 Subject: [PATCH] Mon Mar 4 05:26:41 PM EST 2024 --- src/QAnsel.c | 43 ++++++++++++++++++++++++++++++------------- src/cores.c | 11 ++++++++++- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/QAnsel.c b/src/QAnsel.c index 3c868eb..7907c2e 100644 --- a/src/QAnsel.c +++ b/src/QAnsel.c @@ -232,19 +232,36 @@ void qansel_instruction(cpx_mtx_t* stateVector, unsigned char qubitCount, QInstr } cpx_mtx_init(&tmp, stateVector->rows, stateVector->cols); - if (USE_GPU) - { - printf("A\n"); - 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); - } + printf("%ix%i\n", tmp.rows, tmp.cols); + unsigned long int us1, us2; + + us1 = get_time(); + cpx_mtx_dot_metal(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); + us2 = get_time(); + printf("\tMetal: %lu\n", us2 - us1); + us1 = get_time(); + cpx_mtx_dot_threads(tmp.ptr, stateVector->ptr, filter.ptr, stateVector->rows, stateVector->cols, filter.rows, filter.cols); + us2 = get_time(); + printf("\tThreads: %lu\n", us2 - us1); + us1 = get_time(); + 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); + //} free(stateVector->ptr); stateVector->ptr = tmp.ptr; free(filter.ptr); diff --git a/src/cores.c b/src/cores.c index 4320e71..09e7151 100644 --- a/src/cores.c +++ b/src/cores.c @@ -1,9 +1,10 @@ #include - +#include #if defined(_WIN32) || defined(_WIN64) #include #elif defined(__linux__) #include +#include #elif defined(__APPLE__) #include #endif @@ -50,4 +51,12 @@ int get_core_count() } } return coreCount; +} + +unsigned long int get_time() +{ + struct timeval tv; + gettimeofday(&tv,NULL); + unsigned long int timestamp = 1000000 * tv.tv_sec + tv.tv_usec; + return timestamp; } \ No newline at end of file -- 2.39.5