Support for PP in SP. Moved frequency get to KHz to Hz

This commit is contained in:
Dr-Noob
2018-03-30 00:34:43 +02:00
parent 5e65f5bb78
commit 4c991164c8
5 changed files with 55 additions and 11 deletions

38
01h.c
View File

@@ -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);

1
01h.h
View File

@@ -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);

2
main.c
View File

@@ -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);

24
udev.c
View File

@@ -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;
}

1
udev.h
View File

@@ -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