mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-24 23:40:39 +01:00
[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:
6
Makefile
6
Makefile
@@ -70,13 +70,13 @@ static: $(OUTPUT)
|
||||
strict: CFLAGS += -O2 -Werror -fsanitize=undefined -D_FORTIFY_SOURCE=2
|
||||
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 $@
|
||||
|
||||
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 $@
|
||||
|
||||
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 $@
|
||||
|
||||
$(OUTPUT): Makefile $(SOURCE) $(HEADERS)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "../../common/cpu.h"
|
||||
|
||||
#define MEASURE_TIME_SECONDS 5
|
||||
#define LOOP_ITERS 1000000000
|
||||
#define LOOP_ITERS 100000000
|
||||
|
||||
int64_t measure_frequency(struct cpuInfo* cpu);
|
||||
|
||||
|
||||
@@ -15,13 +15,25 @@ void* compute_avx() {
|
||||
|
||||
struct timeval begin, now;
|
||||
|
||||
__m256 a = _mm256_set1_ps(1.5);
|
||||
__m256 b = _mm256_set1_ps(1.2);
|
||||
__m256 a[8];
|
||||
__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);
|
||||
while(!end) {
|
||||
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);
|
||||
@@ -34,7 +46,8 @@ void* compute_avx() {
|
||||
printf("fopen: %s", strerror(errno));
|
||||
}
|
||||
else {
|
||||
fprintf(fp, "%f", a[0]);
|
||||
for(int i=0; i < 8; i++)
|
||||
fprintf(fp, "%f", a[i][0]);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
#include <stdint.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() {
|
||||
bool end = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user