From 617fd2a520ad97643972dc8689aa7b57ffce712d Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Fri, 19 Nov 2021 22:01:29 +0100 Subject: [PATCH] [v1.00] Implemented all backends for --accurate-pp --- src/x86/freq/freq.h | 3 +++ src/x86/freq/freq_avx.c | 4 +--- src/x86/freq/freq_avx512.c | 39 ++++++++++++++++++++++++++++++++++++++ src/x86/freq/freq_nov.c | 39 ++++++++++++++++++++++++++++++++++++++ src/x86/freq/freq_sse.c | 39 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 3 deletions(-) diff --git a/src/x86/freq/freq.h b/src/x86/freq/freq.h index 8d86a14..80f99d2 100644 --- a/src/x86/freq/freq.h +++ b/src/x86/freq/freq.h @@ -4,6 +4,9 @@ #include #include "../../common/cpu.h" +#define MEASURE_TIME_SECONDS 5 +#define LOOP_ITERS 100000000 + int64_t measure_frequency(struct cpuInfo* cpu); #endif diff --git a/src/x86/freq/freq_avx.c b/src/x86/freq/freq_avx.c index 051d947..340b8ed 100644 --- a/src/x86/freq/freq_avx.c +++ b/src/x86/freq/freq_avx.c @@ -8,9 +8,7 @@ #include #include #include - -#define MEASURE_TIME_SECONDS 5 -#define LOOP_ITERS 100000000 +#include "freq.h" void* compute_avx() { bool end = false; diff --git a/src/x86/freq/freq_avx512.c b/src/x86/freq/freq_avx512.c index 6835a15..80cb18a 100644 --- a/src/x86/freq/freq_avx512.c +++ b/src/x86/freq/freq_avx512.c @@ -1,5 +1,44 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "freq.h" void* compute_avx512() { + bool end = false; + + struct timeval begin, now; + + __m512 a = _mm512_set1_ps(1.5); + __m512 b = _mm512_set1_ps(1.2); + __m512 c = _mm512_set1_ps(0.0); + + gettimeofday(&begin, NULL); + while(!end) { + for(uint64_t i=0; i < LOOP_ITERS; i++) { + c = _mm512_fmadd_ps(a, b, c); + } + + gettimeofday(&now, NULL); + double elapsed = (now.tv_sec - begin.tv_sec) + ((now.tv_usec - begin.tv_usec)/1000000.0); + end = elapsed >= (double) MEASURE_TIME_SECONDS; + } + + FILE* fp = fopen("/dev/null", "w"); + if(fp == NULL) { + printf("fopen: %s", strerror(errno)); + } + else { + fprintf(fp, "%f", c[0]); + fclose(fp); + } + return NULL; } + diff --git a/src/x86/freq/freq_nov.c b/src/x86/freq/freq_nov.c index 95b95dd..b351713 100644 --- a/src/x86/freq/freq_nov.c +++ b/src/x86/freq/freq_nov.c @@ -1,5 +1,44 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "freq.h" void* compute_nov() { + bool end = false; + + struct timeval begin, now; + + float a = 1.5; + float b = 1.2; + float c = 0.0; + + gettimeofday(&begin, NULL); + while(!end) { + for(uint64_t i=0; i < LOOP_ITERS; i++) { + c = a * b; + } + + gettimeofday(&now, NULL); + double elapsed = (now.tv_sec - begin.tv_sec) + ((now.tv_usec - begin.tv_usec)/1000000.0); + end = elapsed >= (double) MEASURE_TIME_SECONDS; + } + + FILE* fp = fopen("/dev/null", "w"); + if(fp == NULL) { + printf("fopen: %s", strerror(errno)); + } + else { + fprintf(fp, "%f", c); + fclose(fp); + } + return NULL; } + diff --git a/src/x86/freq/freq_sse.c b/src/x86/freq/freq_sse.c index 4e33c92..aba3506 100644 --- a/src/x86/freq/freq_sse.c +++ b/src/x86/freq/freq_sse.c @@ -1,5 +1,44 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "freq.h" void* compute_sse() { + bool end = false; + + struct timeval begin, now; + + __m128 a = _mm_set1_ps(1.5); + __m128 b = _mm_set1_ps(1.2); + __m128 c = _mm_set1_ps(0.0); + + gettimeofday(&begin, NULL); + while(!end) { + for(uint64_t i=0; i < LOOP_ITERS; i++) { + c = _mm_add_ps(a, b); + } + + gettimeofday(&now, NULL); + double elapsed = (now.tv_sec - begin.tv_sec) + ((now.tv_usec - begin.tv_usec)/1000000.0); + end = elapsed >= (double) MEASURE_TIME_SECONDS; + } + + FILE* fp = fopen("/dev/null", "w"); + if(fp == NULL) { + printf("fopen: %s", strerror(errno)); + } + else { + fprintf(fp, "%f", c[0]); + fclose(fp); + } + return NULL; } +