From a978341d34fbfa5e2fa68d54ec8d24fe371e5ec8 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Thu, 7 Jul 2022 14:05:42 +0200 Subject: [PATCH] Add autodetection for POWER7, POWER9 & POWER10 Read from `/proc/cpuinfo` as done for ARM. Fixes #501 --- frame/base/bli_cpuid.c | 27 +++++++++++++++++++++++---- frame/base/bli_cpuid.h | 6 +++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/frame/base/bli_cpuid.c b/frame/base/bli_cpuid.c index 4b3837544f..98e66c767b 100644 --- a/frame/base/bli_cpuid.c +++ b/frame/base/bli_cpuid.c @@ -459,7 +459,7 @@ bool bli_cpuid_is_bulldozer return TRUE; } -#elif defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) +#elif defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) || defined(_ARCH_PPC) arch_t bli_cpuid_query_id( void ) { @@ -514,9 +514,14 @@ arch_t bli_cpuid_query_id( void ) return BLIS_ARCH_GENERIC; } } - else if ( vendor == VENDOR_UNKNOWN ) + else if ( vendor == VENDOR_IBM ) { - return BLIS_ARCH_GENERIC; + if ( model == MODEL_POWER7) + return BLIS_ARCH_POWER7; + else if ( model == MODEL_POWER9) + return BLIS_ARCH_POWER9; + else if ( model == MODEL_POWER10) + return BLIS_ARCH_POWER10; } return BLIS_ARCH_GENERIC; @@ -1015,7 +1020,7 @@ int vpu_count( void ) } } -#elif defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) +#elif defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) || defined(_ARCH_PPC) #define TEMP_BUFFER_SIZE 200 @@ -1037,6 +1042,20 @@ uint32_t bli_cpuid_query char feat_str[ TEMP_BUFFER_SIZE ]; char* r_val; +#ifdef _ARCH_PPC + r_val = find_string_in( "cpu", proc_str, TEMP_BUFFER_SIZE, pci_str ); + if ( r_val == NULL ) return VENDOR_IBM; + + if ( strstr( proc_str, "POWER7" ) != NULL ) + *model = MODEL_POWER7; + else if ( strstr( proc_str, "POWER9" ) != NULL ) + *model = MODEL_POWER9; + else if ( strstr( proc_str, "POWER10" ) != NULL ) + *model = MODEL_POWER10; + + return VENDOR_IBM; +#endif + //printf( "bli_cpuid_query(): beginning search\n" ); // Search /proc/cpuinfo for the 'Processor' entry. diff --git a/frame/base/bli_cpuid.h b/frame/base/bli_cpuid.h index 62c05ad5ca..395a9ae5d9 100644 --- a/frame/base/bli_cpuid.h +++ b/frame/base/bli_cpuid.h @@ -159,19 +159,23 @@ enum FEATURE_AVX512VL = 0x4000 }; -#elif defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) +#elif defined(__aarch64__) || defined(__arm__) || defined(_M_ARM) || defined(_ARCH_PPC) char* find_string_in( char* target, char* buffer, size_t buf_len, char* filepath ); enum { VENDOR_ARM = 0, + VENDOR_IBM, VENDOR_UNKNOWN }; enum { MODEL_ARMV7 = 0, MODEL_ARMV8, + MODEL_POWER7, + MODEL_POWER9, + MODEL_POWER10, MODEL_UNKNOWN }; enum