Browse Source

Identify all cores and select the most performant one as TARGET

tags/v0.3.29
Martin Kroeker GitHub 1 year ago
parent
commit
3c3d1c4849
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 43 additions and 6 deletions
  1. +43
    -6
      driver/others/dynamic_arm64.c

+ 43
- 6
driver/others/dynamic_arm64.c View File

@@ -271,15 +271,52 @@ static gotoblas_t *get_coretype(void) {

if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
#ifdef __linux
int i;
int ncores=0;
int p,cpucap,cpulowperf=0,cpumidperf=0,cpuhiperf=0;
FILE *infile;
char buffer[512], *p, *cpu_part = NULL, *cpu_implementer = NULL;
p = (char *) NULL ;
infile = fopen("/sys/devices/system/cpu/cpu0/regs/identification/midr_el1","r");
if (!infile) return NULL;
(void)fgets(buffer, sizeof(buffer), infile);
midr_el1=strtoul(buffer,NULL,16);
fclose(infile);
#else
infile = fopen("/sys/devices/system/cpu/possible","r");
if (infile) {
(void)fgets(buffer, sizeof(buffer), infile);
sscanf(buffer,"0-%d",&ncores);
fclose (infile);
ncores++;
} else {
infile = fopen("/proc/cpuinfo","r");
while (fgets(buffer, sizeof(buffer), infile)) {
if (!strncmp("processor", buffer, 9))
ncores++;
}
}
for (i=0;i<ncores;i++) {
sprintf(buffer,"/sys/devices/system/cpu/cpu%d/regs/identification/midr_el1",i);
infile = fopen(buffer,"r");
if (!infile) return NULL;
(void)fgets(buffer, sizeof(buffer), infile);
midr_el1=strtoul(buffer,NULL,16);
implementer = (midr_el1 >> 24) & 0xFF;
p = (midr_el1 >> 4) & 0xFFF;
fclose(infile);
sprintf(buffer,"/sys/devices/system/cpu/cpu%d/cpu_capability",i);
infile = fopen(buffer,"r");
if (infile) {
(void)fgets(buffer, sizeof(buffer), infile);
cpucap=strtoul(buffer,NULL,16);
fclose(infile);
if (cpucap >= 1000) cpuhiperf++;
else if (cpucap >=500) cpumidperf++;
else cpulowperf++;
if (cpucap >=1000) part = p;
} else if (implementer == 0x41 ){
if (p >= 0xd4b) cpuhiperf++:
else if (p>= 0xd07) cpumidperf++;
else cpulowperf++;
} else cpulowperf++;
}
if (!part) part = p;
#else
snprintf(coremsg, 128, "Kernel lacks cpuid feature support. Auto detection of core type failed !!!\n");
openblas_warning(1, coremsg);
return NULL;


Loading…
Cancel
Save