From 111958c02a8fb2f24458a3fb1f997dd8512cb5f9 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Mon, 6 Feb 2023 14:20:50 +0800 Subject: [PATCH 1/2] python3Packages.torch: fix build with gcc 12 --- pkgs/development/python-modules/torch/default.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/torch/default.nix b/pkgs/development/python-modules/torch/default.nix index c64f36c8df321..e6c939788b1da 100644 --- a/pkgs/development/python-modules/torch/default.nix +++ b/pkgs/development/python-modules/torch/default.nix @@ -111,6 +111,15 @@ in buildPythonPackage rec { # base is 10.12. Until we upgrade, we can fall back on the older # pthread support. ./pthreadpool-disable-gcd.diff + ] ++ [ + # PyTorch fails to build on gcc 12 due to gloo + # https://github.com/pytorch/pytorch/issues/77614 + (fetchpatch { + url = "https://github.com/facebookincubator/gloo/commit/4a5e339b764261d20fc409071dc7a8b8989aa195.patch"; + stripLen = 1; + extraPrefix = "third_party/gloo/"; + hash = "sha256-UxR1r7F6g76BWj3GBIrSy5t+YZDCWy6mMddwx+hon5w="; + }) ]; postPatch = lib.optionalString rocmSupport '' @@ -204,7 +213,11 @@ in buildPythonPackage rec { # # Also of interest: pytorch ignores CXXFLAGS uses CFLAGS for both C and C++: # https://github.com/pytorch/pytorch/blob/v1.11.0/setup.py#L17 - NIX_CFLAGS_COMPILE = lib.optionals (blas.implementation == "mkl") [ "-Wno-error=array-bounds" ]; + NIX_CFLAGS_COMPILE = lib.optionals (blas.implementation == "mkl") [ "-Wno-error=array-bounds" ] + # Suppress gcc regression: avx512 math function raises uninitialized variable warning + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105593 + # See also: Fails to compile with GCC 12.1.0 https://github.com/pytorch/pytorch/issues/77939 + ++ [ "-Wno-error=maybe-uninitialized" "-Wno-error=uninitialized" ]; nativeBuildInputs = [ cmake From c09e42d337ebd3052840bc630b029ec2a1063074 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Mon, 6 Feb 2023 17:42:52 +0800 Subject: [PATCH 2/2] python3Packages.torch: conditionalize -Wno-error={maybe-,}uninitialized on GNU stdenv --- pkgs/development/python-modules/torch/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/torch/default.nix b/pkgs/development/python-modules/torch/default.nix index e6c939788b1da..f1a8e72a591db 100644 --- a/pkgs/development/python-modules/torch/default.nix +++ b/pkgs/development/python-modules/torch/default.nix @@ -217,7 +217,7 @@ in buildPythonPackage rec { # Suppress gcc regression: avx512 math function raises uninitialized variable warning # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105593 # See also: Fails to compile with GCC 12.1.0 https://github.com/pytorch/pytorch/issues/77939 - ++ [ "-Wno-error=maybe-uninitialized" "-Wno-error=uninitialized" ]; + ++ lib.optionals stdenv.cc.isGNU [ "-Wno-error=maybe-uninitialized" "-Wno-error=uninitialized" ]; nativeBuildInputs = [ cmake