From 6ffc0fd601de20a961367357f74295902d7c7869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Wed, 5 Aug 2020 20:51:05 +0200 Subject: [PATCH] python3Packages.pytorch: fix Darwin build by disabling GCD PyTorch 1.6.0 has updated the vendored pthreadpool library, which has recently added support for Grand Central Dispatch. Unfortunately, it uses functionality (DISPATCH_APPLY_AUTO) that is only available since macOS 10.13, whereas we are still using 10.12 libraries. We can't directly pass through option to vendored libraries, since the setup.py scripts creates/filters the options that are passed to CMake. So, instead, this adds a small patch that disables the GCD functionality in pthreadpool. --- .../python-modules/pytorch/default.nix | 7 +++ .../pytorch/pthreadpool-disable-gcd.diff | 45 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 pkgs/development/python-modules/pytorch/pthreadpool-disable-gcd.diff diff --git a/pkgs/development/python-modules/pytorch/default.nix b/pkgs/development/python-modules/pytorch/default.nix index 4eabaf26f772..da7da4ca38fc 100644 --- a/pkgs/development/python-modules/pytorch/default.nix +++ b/pkgs/development/python-modules/pytorch/default.nix @@ -135,6 +135,13 @@ in buildPythonPackage rec { url = "https://github.com/pytorch/pytorch/commit/7676682584d0caf9243bce74ea0a88711ec4a807.diff"; sha256 = "13spncaqlpsp8qk2850yly7xqwmhhfwznhmzkk8jgpslkbx75vgq"; }) + ] ++ lib.optionals stdenv.isDarwin [ + # pthreadpool added support for Grand Central Dispatch in April + # 2020. However, this relies on functionality (DISPATCH_APPLY_AUTO) + # that is available starting with macOS 10.13. However, our current + # base is 10.12. Until we upgrade, we can fall back on the older + # pthread support. + ./pthreadpool-disable-gcd.diff ]; preConfigure = lib.optionalString cudaSupport '' diff --git a/pkgs/development/python-modules/pytorch/pthreadpool-disable-gcd.diff b/pkgs/development/python-modules/pytorch/pthreadpool-disable-gcd.diff new file mode 100644 index 000000000000..eddd45723f8b --- /dev/null +++ b/pkgs/development/python-modules/pytorch/pthreadpool-disable-gcd.diff @@ -0,0 +1,45 @@ +diff --git a/third_party/pthreadpool/CMakeLists.txt b/third_party/pthreadpool/CMakeLists.txt +index 0db3264..1ba91c4 100644 +--- a/third_party/pthreadpool/CMakeLists.txt ++++ b/third_party/pthreadpool/CMakeLists.txt +@@ -74,9 +74,7 @@ IF(EMSCRIPTEN) + LIST(APPEND PTHREADPOOL_SRCS src/shim.c) + ELSE() + LIST(APPEND PTHREADPOOL_SRCS src/portable-api.c src/memory.c) +- IF(APPLE AND (PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "default" OR PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "gcd")) +- LIST(APPEND PTHREADPOOL_SRCS src/gcd.c) +- ELSEIF(CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS)$" AND (PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "default" OR PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "event")) ++ IF(CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS)$" AND (PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "default" OR PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "event")) + LIST(APPEND PTHREADPOOL_SRCS src/windows.c) + ELSE() + LIST(APPEND PTHREADPOOL_SRCS src/pthreads.c) +@@ -111,10 +109,6 @@ ELSEIF(PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "futex") + TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_FUTEX=1) + TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_GCD=0) + TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_EVENT=0) +-ELSEIF(PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "gcd") +- TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_FUTEX=0) +- TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_GCD=1) +- TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_EVENT=0) + ELSEIF(PTHREADPOOL_SYNC_PRIMITIVE STREQUAL "event") + TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_FUTEX=0) + TARGET_COMPILE_DEFINITIONS(pthreadpool PRIVATE PTHREADPOOL_USE_GCD=0) +diff --git a/third_party/pthreadpool/src/threadpool-common.h b/third_party/pthreadpool/src/threadpool-common.h +index ca84744..244d0ca 100644 +--- a/third_party/pthreadpool/src/threadpool-common.h ++++ b/third_party/pthreadpool/src/threadpool-common.h +@@ -14,14 +14,6 @@ + #endif + #endif + +-#ifndef PTHREADPOOL_USE_GCD +- #if defined(__APPLE__) +- #define PTHREADPOOL_USE_GCD 1 +- #else +- #define PTHREADPOOL_USE_GCD 0 +- #endif +-#endif +- + #ifndef PTHREADPOOL_USE_EVENT + #if defined(_WIN32) || defined(__CYGWIN__) + #define PTHREADPOOL_USE_EVENT 1