[v1.01] Run multiple independent instructions in the pipeline for AVX freq too. Fixes incorrect frequency measures under certain CPUs

This commit is contained in:
Dr-Noob
2021-12-27 12:42:03 +01:00
parent a4e1a837a3
commit 874a856e34
4 changed files with 21 additions and 14 deletions

View File

@@ -70,13 +70,13 @@ static: $(OUTPUT)
strict: CFLAGS += -O2 -Werror -fsanitize=undefined -D_FORTIFY_SOURCE=2 strict: CFLAGS += -O2 -Werror -fsanitize=undefined -D_FORTIFY_SOURCE=2
strict: $(OUTPUT) strict: $(OUTPUT)
freq_nov.o: Makefile $(SRC_DIR)freq/freq_nov.c $(SRC_DIR)freq/freq_nov.h freq_nov.o: Makefile $(SRC_DIR)freq/freq_nov.c $(SRC_DIR)freq/freq_nov.h $(SRC_FREQ)/freq.h $(SRC_DIR)freq/freq.h
$(CC) $(CFLAGS) $(SANITY_FLAGS) -c -pthread $(SRC_DIR)freq/freq_nov.c -o $@ $(CC) $(CFLAGS) $(SANITY_FLAGS) -c -pthread $(SRC_DIR)freq/freq_nov.c -o $@
freq_avx.o: Makefile $(SRC_DIR)freq/freq_avx.c $(SRC_DIR)freq/freq_avx.h freq_avx.o: Makefile $(SRC_DIR)freq/freq_avx.c $(SRC_DIR)freq/freq_avx.h $(SRC_DIR)freq/freq.h
$(CC) $(CFLAGS) $(SANITY_FLAGS) -c -mavx -pthread $(SRC_DIR)freq/freq_avx.c -o $@ $(CC) $(CFLAGS) $(SANITY_FLAGS) -c -mavx -pthread $(SRC_DIR)freq/freq_avx.c -o $@
freq_avx512.o: Makefile $(SRC_DIR)freq/freq_avx512.c $(SRC_DIR)freq/freq_avx512.h freq_avx512.o: Makefile $(SRC_DIR)freq/freq_avx512.c $(SRC_DIR)freq/freq_avx512.h $(SRC_DIR)freq/freq.h
$(CC) $(CFLAGS) $(SANITY_FLAGS) -c -mavx512f -pthread $(SRC_DIR)freq/freq_avx512.c -o $@ $(CC) $(CFLAGS) $(SANITY_FLAGS) -c -mavx512f -pthread $(SRC_DIR)freq/freq_avx512.c -o $@
$(OUTPUT): Makefile $(SOURCE) $(HEADERS) $(OUTPUT): Makefile $(SOURCE) $(HEADERS)

View File

@@ -5,7 +5,7 @@
#include "../../common/cpu.h" #include "../../common/cpu.h"
#define MEASURE_TIME_SECONDS 5 #define MEASURE_TIME_SECONDS 5
#define LOOP_ITERS 1000000000 #define LOOP_ITERS 100000000
int64_t measure_frequency(struct cpuInfo* cpu); int64_t measure_frequency(struct cpuInfo* cpu);

View File

@@ -15,13 +15,25 @@ void* compute_avx() {
struct timeval begin, now; struct timeval begin, now;
__m256 a = _mm256_set1_ps(1.5); __m256 a[8];
__m256 b = _mm256_set1_ps(1.2); __m256 b[8];
for(int i=0; i < 8; i++) {
a[i] = _mm256_set1_ps(1.5);
b[i] = _mm256_set1_ps(1.2);
}
gettimeofday(&begin, NULL); gettimeofday(&begin, NULL);
while(!end) { while(!end) {
for(uint64_t i=0; i < LOOP_ITERS; i++) { for(uint64_t i=0; i < LOOP_ITERS; i++) {
a = _mm256_add_ps(a, b); a[0] = _mm256_add_ps(a[0], b[0]);
a[1] = _mm256_add_ps(a[1], b[1]);
a[2] = _mm256_add_ps(a[2], b[2]);
a[3] = _mm256_add_ps(a[3], b[3]);
a[4] = _mm256_add_ps(a[4], b[4]);
a[5] = _mm256_add_ps(a[5], b[5]);
a[6] = _mm256_add_ps(a[6], b[6]);
a[7] = _mm256_add_ps(a[7], b[7]);
} }
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
@@ -34,7 +46,8 @@ void* compute_avx() {
printf("fopen: %s", strerror(errno)); printf("fopen: %s", strerror(errno));
} }
else { else {
fprintf(fp, "%f", a[0]); for(int i=0; i < 8; i++)
fprintf(fp, "%f", a[i][0]);
fclose(fp); fclose(fp);
} }

View File

@@ -10,12 +10,6 @@
#include <stdint.h> #include <stdint.h>
#include "freq.h" #include "freq.h"
/*
* For AVX512, it seems that multiple independent
* instructions are needed to force the CPU to
* use AVX512 frequency, since with only one instruction
* (as the AVX implementaion) it still uses AVX frequency
*/
void* compute_avx512() { void* compute_avx512() {
bool end = false; bool end = false;