diff --git a/01h.c b/01h.c index 65cea84..fa57100 100644 --- a/01h.c +++ b/01h.c @@ -137,6 +137,44 @@ void debugCpuInfo(struct cpuInfo* cpu) { /*** STRING FUNCTIONS ***/ +char* getPeakPerformance(struct cpuInfo* cpu, long freq) { + /*** + PP = PeakPerformance + SP = SinglePrecision + + PP(SP) = + N_CORES * + FREQUENCY * + 2(Two vector units) * + 2(If cpu has fma) * + 16(If AVX512), 8(If AVX), 4(If SSE) * + + ***/ + + //7 for GFLOP/s and 6 for digits,eg 412.14 + int size = 7+6+1+1; + char* string = malloc(sizeof(char)*size); + float flops = cpu->nCores*freq*2; + + if(cpu->FMA3 || cpu->FMA4) + flops = flops*2; + + if(cpu->AVX512) + flops = flops*16; + else if(cpu->AVX || cpu->AVX2) + flops = flops*8; + else if(cpu->SSE) + flops = flops*4; + + if(flops >= (double)1000000000000.0) + snprintf(string,size,"%.2f TFLOP/s",flops/1000000000000); + else if(flops >= 1000000000.0) + snprintf(string,size,"%.2f GFLOP/s",flops/1000000000); + else + snprintf(string,size,"%.2f MFLOP/s",flops/1000000); + return string; +} + char* getString_NumberCores(struct cpuInfo* cpu) { char* string = malloc(sizeof(char)*2+1); snprintf(string,2+1,"%d",cpu->nCores); diff --git a/01h.h b/01h.h index d1da2b4..019c31a 100644 --- a/01h.h +++ b/01h.h @@ -9,6 +9,7 @@ struct cpuInfo* getCPUInfo(); void debugCpuInfo(struct cpuInfo* cpu); char* getString_NumberCores(struct cpuInfo* cpu); +char* getPeakPerformance(struct cpuInfo* cpu, long freq); char* getString_AVX(struct cpuInfo* cpu); char* getString_SSE(struct cpuInfo* cpu); char* getString_FMA(struct cpuInfo* cpu); diff --git a/main.c b/main.c index bba0bf8..c4d3b65 100644 --- a/main.c +++ b/main.c @@ -53,7 +53,7 @@ int main() { printf(TITLE_L1"%s\n",l1); printf(TITLE_L2"%s\n",l2); printf(TITLE_L3"%s\n",l3); - printf(TITLE_PEAK"%s\n","??? GFLOP/s"); + printf(TITLE_PEAK"%s\n",getPeakPerformance(cpu,getFrequency(freq))); free(cpuName); free(maxFrequency); diff --git a/udev.c b/udev.c index 7051be8..cfb66f2 100644 --- a/udev.c +++ b/udev.c @@ -13,8 +13,8 @@ struct cache { }; struct frequency { - int max; - int min; + long max; + long min; }; /*** @@ -83,7 +83,7 @@ Returns CPU frequency in Hz ***/ -int getFrequency(char* path) { +long getFrequencyFromFile(char* path) { FILE *file = fopen(path, "r"); if(file == NULL) { @@ -106,10 +106,14 @@ int getFrequency(char* path) { int ret = atoi(buf); free(buf); if(ret == 0) { - printf("error in getFrequency\n"); + printf("error in getFrequencyFromFile\n"); return NO_CACHE; } - return ret; + return (long)ret*1000; +} + +long getFrequency(struct frequency* freq) { + return freq->max; } /*** GET_STRING ***/ @@ -157,10 +161,10 @@ char* getString_MaxFrequency(struct frequency* freq) { //Max 3 digits and 3 for '(M/G)Hz' plus 1 for '\0' int size = (4+3+1); char* string = malloc(sizeof(char)*size); - if(freq->max >= 1000000) - snprintf(string,size,"%.2f"STRING_GIGAHERZ,(float)(freq->max)/1000000); + if(freq->max >= 1000000000) + snprintf(string,size,"%.2f"STRING_GIGAHERZ,(float)(freq->max)/1000000000); else - snprintf(string,size,"%.2f"STRING_MEGAHERZ,(float)(freq->max)/100000); + snprintf(string,size,"%.2f"STRING_MEGAHERZ,(float)(freq->max)/1000000); return string; } @@ -177,8 +181,8 @@ struct cache* new_cache(struct cache* cach) { struct frequency* new_frequency(struct frequency* freq) { freq = malloc(sizeof(struct frequency)); - freq->max = getFrequency(_PATH_FREQUENCY_MAX); - freq->min = getFrequency(_PATH_FREQUENCY_MIN); + freq->max = getFrequencyFromFile(_PATH_FREQUENCY_MAX); + freq->min = getFrequencyFromFile(_PATH_FREQUENCY_MIN); return freq; } diff --git a/udev.h b/udev.h index 2a28d0b..5692959 100644 --- a/udev.h +++ b/udev.h @@ -47,5 +47,6 @@ struct frequency* new_frequency(struct frequency* freq); void debugFrequency(struct frequency* freq); void freeFrequency(struct frequency* freq); char* getString_MaxFrequency(struct frequency* freq); +long getFrequency(struct frequency* freq); #endif