diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2019-04-10 19:04:23 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-10 19:04:23 -0600 |
commit | d7a73f8c700edcf150d59a570e0173b60f84c7a7 (patch) | |
tree | b2e16f4d09c1557aff60864b86d71569419fad22 /numpy/_build_utils/src | |
parent | 3257586ec441c2e234c40c4c074ce240935c3e0b (diff) | |
parent | d90f854af4b2ba1f0ac6eb9c36bcfe53ffa7cf1d (diff) | |
download | numpy-d7a73f8c700edcf150d59a570e0173b60f84c7a7.tar.gz |
Merge pull request #13060 from bran206/master
BUG: Use C call to sysctlbyname for AVX detection on MacOS
Diffstat (limited to 'numpy/_build_utils/src')
-rw-r--r-- | numpy/_build_utils/src/apple_sgemv_fix.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/numpy/_build_utils/src/apple_sgemv_fix.c b/numpy/_build_utils/src/apple_sgemv_fix.c index 788a62e61..b1dbeb681 100644 --- a/numpy/_build_utils/src/apple_sgemv_fix.c +++ b/numpy/_build_utils/src/apple_sgemv_fix.c @@ -29,6 +29,9 @@ #include <dlfcn.h> #include <stdlib.h> #include <stdio.h> +#include <sys/types.h> +#include <sys/sysctl.h> +#include <string.h> /* ----------------------------------------------------------------- */ /* Original cblas_sgemv */ @@ -66,12 +69,35 @@ 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) - +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()\ -(system("sw_vers -productVersion | grep -q 10\\.9\\.") == 0) +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; + } +} __attribute__((destructor)) static void unloadlib(void) |