@@ -271,15 +271,52 @@ static gotoblas_t *get_coretype(void) {
271
271
272
272
if (!(getauxval (AT_HWCAP ) & HWCAP_CPUID )) {
273
273
#ifdef __linux
274
+ int i ;
275
+ int ncores = 0 ;
276
+ int p ,cpucap ,cpulowperf = 0 ,cpumidperf = 0 ,cpuhiperf = 0 ;
274
277
FILE * infile ;
275
278
char buffer [512 ], * p , * cpu_part = NULL , * cpu_implementer = NULL ;
276
279
p = (char * ) NULL ;
277
- infile = fopen ("/sys/devices/system/cpu/cpu0/regs/identification/midr_el1" ,"r" );
278
- if (!infile ) return NULL ;
279
- (void )fgets (buffer , sizeof (buffer ), infile );
280
- midr_el1 = strtoul (buffer ,NULL ,16 );
281
- fclose (infile );
282
- #else
280
+ infile = fopen ("/sys/devices/system/cpu/possible" ,"r" );
281
+ if (infile ) {
282
+ (void )fgets (buffer , sizeof (buffer ), infile );
283
+ sscanf (buffer ,"0-%d" ,& ncores );
284
+ fclose (infile );
285
+ ncores ++ ;
286
+ } else {
287
+ infile = fopen ("/proc/cpuinfo" ,"r" );
288
+ while (fgets (buffer , sizeof (buffer ), infile )) {
289
+ if (!strncmp ("processor" , buffer , 9 ))
290
+ ncores ++ ;
291
+ }
292
+ }
293
+ for (i = 0 ;i < ncores ;i ++ ) {
294
+ sprintf (buffer ,"/sys/devices/system/cpu/cpu%d/regs/identification/midr_el1" ,i );
295
+ infile = fopen (buffer ,"r" );
296
+ if (!infile ) return NULL ;
297
+ (void )fgets (buffer , sizeof (buffer ), infile );
298
+ midr_el1 = strtoul (buffer ,NULL ,16 );
299
+ implementer = (midr_el1 >> 24 ) & 0xFF ;
300
+ p = (midr_el1 >> 4 ) & 0xFFF ;
301
+ fclose (infile );
302
+ sprintf (buffer ,"/sys/devices/system/cpu/cpu%d/cpu_capability" ,i );
303
+ infile = fopen (buffer ,"r" );
304
+ if (infile ) {
305
+ (void )fgets (buffer , sizeof (buffer ), infile );
306
+ cpucap = strtoul (buffer ,NULL ,16 );
307
+ fclose (infile );
308
+ if (cpucap >= 1000 ) cpuhiperf ++ ;
309
+ else if (cpucap >=500 ) cpumidperf ++ ;
310
+ else cpulowperf ++ ;
311
+ if (cpucap >=1000 ) part = p ;
312
+ } else if (implementer == 0x41 ){
313
+ if (p >= 0xd4b ) cpuhiperf ++ :
314
+ else if (p >= 0xd07 ) cpumidperf ++ ;
315
+ else cpulowperf ++ ;
316
+ } else cpulowperf ++ ;
317
+ }
318
+ if (!part ) part = p ;
319
+ #else
283
320
snprintf (coremsg , 128 , "Kernel lacks cpuid feature support. Auto detection of core type failed !!!\n" );
284
321
openblas_warning (1 , coremsg );
285
322
return NULL ;
0 commit comments