From 680cd30daf763a87d9f8490b7a799daaea1d17a2 Mon Sep 17 00:00:00 2001 From: Bran Date: Wed, 27 Feb 2019 23:30:09 +0000 Subject: AVX detection fails on MacOS if $PATH doesn't contain /usr/sbin #7801 -- fix --- numpy/_build_utils/src/apple_sgemv_fix.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c index 4c9c82ece..934aba49d 100644 --- a/numpy/_build_utils/src/apple_sgemv_fix.c +++ b/numpy/_build_utils/src/apple_sgemv_fix.c @@ -29,6 +29,9 @@ #include #include #include +#include +#include +#include /* ----------------------------------------------------------------- */ /* Original cblas_sgemv */ @@ -66,12 +69,21 @@ static int AVX_and_10_9 = 0; /* Dynamic check for AVX support * __builtin_cpu_supports("avx") is available in gcc 4.8, * but clang and icc do not currently support it. */ -#define cpu_supports_avx()\ -(system("sysctl -n machdep.cpu.features | grep -q AVX") == 0) - +#define cpu_supports_avx() ({\ + int enabled, r;\ + size_t length = sizeof(enabled);\ + r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0);\ + r == 0 && enabled != 0;\ +}) + /* Check if we are using MacOS X version 10.9 */ -#define using_mavericks()\ -(system("sw_vers -productVersion | grep -q 10\\.9\\.") == 0) +#define using_mavericks() ({\ + int r;\ + char str[32] = {0};\ + size_t size = sizeof(str);\ + r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0);\ + r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0;\ +}) __attribute__((destructor)) static void unloadlib(void) -- cgit v1.2.1 From 3d319ffa5fabdd3a8e2732e98df4626289e9af9f Mon Sep 17 00:00:00 2001 From: Bran Date: Mon, 4 Mar 2019 21:11:21 +0000 Subject: =?UTF-8?q?AVX=20detection=20fails=20on=20MacOS=20if=20/home/bran/?= =?UTF-8?q?.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s?= =?UTF-8?q?bin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/System32:/m?= =?UTF-8?q?nt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System?= =?UTF-8?q?32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:/mnt/?= =?UTF-8?q?c/Program=20Files/dotnet:/mnt/c/Program=20Files/Microsoft=20SQL?= =?UTF-8?q?=20Server/130/Tools/Binn:/mnt/c/Program=20Files/PuTTY:/mnt/c/Us?= =?UTF-8?q?ers/Bran/AppData/Local/Programs/Python/Python37/Scripts:/mnt/c/?= =?UTF-8?q?Users/Bran/AppData/Local/Programs/Python/Python37:/mnt/c/Users/?= =?UTF-8?q?Bran/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/Bran/AppD?= =?UTF-8?q?ata/Local/Programs/Microsoft=20VS=20Code/bin:/snap/bin=20doesn'?= =?UTF-8?q?t=20contain=20/usr/sbin=20#7801=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- numpy/_build_utils/src/apple_sgemv_fix.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c index 934aba49d..5f84de232 100644 --- a/numpy/_build_utils/src/apple_sgemv_fix.c +++ b/numpy/_build_utils/src/apple_sgemv_fix.c @@ -69,21 +69,27 @@ static int AVX_and_10_9 = 0; /* Dynamic check for AVX support * __builtin_cpu_supports("avx") is available in gcc 4.8, * but clang and icc do not currently support it. */ -#define cpu_supports_avx() ({\ - int enabled, r;\ - size_t length = sizeof(enabled);\ - r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0);\ - r == 0 && enabled != 0;\ -}) +static inline int cpu_supports_avx() { + int enabled, r; + size_t length = sizeof(enabled); + r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0); + if ( r == 0 && enabled != 0) + return 1; + else + return 0; +} /* Check if we are using MacOS X version 10.9 */ -#define using_mavericks() ({\ - int r;\ - char str[32] = {0};\ - size_t size = sizeof(str);\ - r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0);\ - r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0;\ -}) +static inline int cpu_supports_avx() { + int r; + char str[32] = {0}; + size_t size = sizeof(str); + r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0); + if ( r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0) + return 1; + else + return 0; +} __attribute__((destructor)) static void unloadlib(void) -- cgit v1.2.1 From 5acc591473a4239a994b19eb6e7b256ba557ce21 Mon Sep 17 00:00:00 2001 From: Bran Date: Mon, 4 Mar 2019 21:14:32 +0000 Subject: AVX detection fails on MacOS if $PATH doesn't contain /usr/sbin #7801 --- numpy/_build_utils/src/apple_sgemv_fix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c index 5f84de232..5b27c73f4 100644 --- a/numpy/_build_utils/src/apple_sgemv_fix.c +++ b/numpy/_build_utils/src/apple_sgemv_fix.c @@ -80,7 +80,7 @@ static inline int cpu_supports_avx() { } /* Check if we are using MacOS X version 10.9 */ -static inline int cpu_supports_avx() { +static inline int using_mavericks() { int r; char str[32] = {0}; size_t size = sizeof(str); -- cgit v1.2.1 From 95342f6df4952bc88c5a02e1f3f8909ced05ae7f Mon Sep 17 00:00:00 2001 From: Bran Date: Thu, 14 Mar 2019 17:28:56 +0000 Subject: AVX detection fails on MacOS if $PATH doesn't contain /usr/sbin #7801 --- numpy/_build_utils/src/apple_sgemv_fix.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c index 5b27c73f4..aef7ff534 100644 --- a/numpy/_build_utils/src/apple_sgemv_fix.c +++ b/numpy/_build_utils/src/apple_sgemv_fix.c @@ -70,25 +70,25 @@ static int AVX_and_10_9 = 0; * __builtin_cpu_supports("avx") is available in gcc 4.8, * but clang and icc do not currently support it. */ static inline int cpu_supports_avx() { - int enabled, r; - size_t length = sizeof(enabled); - r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0); - if ( r == 0 && enabled != 0) - return 1; - else - return 0; + int enabled, r; + size_t length = sizeof(enabled); + r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0); + if ( r == 0 && enabled != 0) + return 1; + else + return 0; } /* Check if we are using MacOS X version 10.9 */ static inline int using_mavericks() { - int r; - char str[32] = {0}; - size_t size = sizeof(str); - r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0); - if ( r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0) - return 1; - else - return 0; + int r; + char str[32] = {0}; + size_t size = sizeof(str); + r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0); + if ( r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0) + return 1; + else + return 0; } __attribute__((destructor)) -- cgit v1.2.1 From d90f854af4b2ba1f0ac6eb9c36bcfe53ffa7cf1d Mon Sep 17 00:00:00 2001 From: Bran Date: Fri, 5 Apr 2019 06:59:33 +0100 Subject: BUG: Use C call to sysctlbyname for AVX detection on MacOS --- numpy/_build_utils/src/apple_sgemv_fix.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c index aef7ff534..c33c68992 100644 --- a/numpy/_build_utils/src/apple_sgemv_fix.c +++ b/numpy/_build_utils/src/apple_sgemv_fix.c @@ -69,26 +69,34 @@ static int AVX_and_10_9 = 0; /* Dynamic check for AVX support * __builtin_cpu_supports("avx") is available in gcc 4.8, * but clang and icc do not currently support it. */ -static inline int cpu_supports_avx() { +static inline int +cpu_supports_avx() +{ int enabled, r; size_t length = sizeof(enabled); r = sysctlbyname("hw.optional.avx1_0", &enabled, &length, NULL, 0); - if ( r == 0 && enabled != 0) + if ( r == 0 && enabled != 0) { return 1; - else + } + else { return 0; + } } /* Check if we are using MacOS X version 10.9 */ -static inline int using_mavericks() { +static inline int +using_mavericks() +{ int r; char str[32] = {0}; size_t size = sizeof(str); r = sysctlbyname("kern.osproductversion", str, &size, NULL, 0); - if ( r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0) + if ( r == 0 && strncmp(str, "10.9", strlen("10.9")) == 0) { return 1; - else + } + else { return 0; + } } __attribute__((destructor)) -- cgit v1.2.1