[arch-commits] Commit in python-pytorch/trunk (3 files)

Konstantin Gizdov kgizdov at archlinux.org
Mon Jan 27 17:16:31 UTC 2020


    Date: Monday, January 27, 2020 @ 17:16:31
  Author: kgizdov
Revision: 556235

upgpkg: python-pytorch 1.4.0-4: fix nccl version and TORCH_CUDA_API export

Added:
  python-pytorch/trunk/nccl_version.patch
  python-pytorch/trunk/torch_cuda_api.patch
Modified:
  python-pytorch/trunk/PKGBUILD

----------------------+
 PKGBUILD             |   19 +++++++++++++++++--
 nccl_version.patch   |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 torch_cuda_api.patch |   13 +++++++++++++
 3 files changed, 76 insertions(+), 2 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2020-01-27 17:15:20 UTC (rev 556234)
+++ PKGBUILD	2020-01-27 17:16:31 UTC (rev 556235)
@@ -5,19 +5,23 @@
 pkgname=("python-pytorch" "python-pytorch-opt" "python-pytorch-cuda" "python-pytorch-opt-cuda")
 _pkgname="pytorch"
 pkgver=1.4.0
-pkgrel=3
+pkgrel=4
 pkgdesc="Tensors and Dynamic neural networks in Python with strong GPU acceleration"
 arch=('x86_64')
 url="https://pytorch.org"
 license=('BSD')
 depends=('google-glog' 'gflags' 'opencv' 'openmp' 'nccl' 'pybind11' 'python' 'python-yaml' 'python-numpy' 'protobuf' 'ffmpeg' 'python-future' 'qt5-base')
-makedepends=('python' 'python-setuptools' 'python-yaml' 'python-numpy' 'cmake' 'cuda' 'cudnn' 'git' 'magma' 'ninja')
+makedepends=('python' 'python-setuptools' 'python-yaml' 'python-numpy' 'cmake' 'cuda' 'cudnn' 'git' 'magma' 'ninja' 'pkgconfig')
 source=("${_pkgname}-${pkgver}::git+https://github.com/pytorch/pytorch.git#tag=v$pkgver"
         fix_include_system.patch
+        nccl_version.patch
+        torch_cuda_api.patch
         https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/30332.patch
         https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/30333.patch)
 sha256sums=('SKIP'
             '147bdaeac8ec46ea46382e6146878bd8f8d51e05d5bd6f930dfd8e2b520859b9'
+            '1a276bd827a0c76dab908cbc6605fa4c9fc2cc2b9431b6578a41133ae27dba2b'
+            '8965f003f5812c5ab1bd27ab66d916560ea4a644364727b9755dc0dea752ad77'
             '3170551116798dc496636a87f00b86c6463895bb6d174df616c5224adfb74ff3'
             'c8c305c892be85c47872ae1f1ecd5b3b8af12876fbfe3641045c8c839e5126da')
 
@@ -41,10 +45,19 @@
   # https://bugs.archlinux.org/task/64981
   patch -N torch/utils/cpp_extension.py "${srcdir}"/fix_include_system.patch
 
+  # FindNCCL patch to export correct nccl version
+  patch -Np1 -i "${srcdir}"/nccl_version.patch
+
+  # correctly export torch cuda api for nccl runtime error
+  patch -Np1 -i "${srcdir}"/torch_cuda_api.patch
+
   # https://github.com/pytorch/pytorch/issues/32277
   patch -Np1 -i "$srcdir"/30332.patch
   patch -Np1 -i "$srcdir"/30333.patch
 
+  # remove local nccl
+  rm -rf third_party/nccl/nccl
+
   cd ..
 
   cp -a "${_pkgname}-${pkgver}" "${_pkgname}-${pkgver}-opt"
@@ -65,6 +78,8 @@
   export BUILD_BINARY=ON
   export USE_OPENCV=ON
   export USE_SYSTEM_NCCL=ON
+  export NCCL_VERSION=$(pkg-config nccl --modversion)
+  export NCCL_VER_CODE=$(sed -n 's/^#define NCCL_VERSION_CODE\s*\(.*\).*/\1/p' /usr/include/nccl.h)
   export CUDAHOSTCXX=g++-8
   export CUDA_HOME=/opt/cuda
   export CUDNN_LIB_DIR=/usr/lib

Added: nccl_version.patch
===================================================================
--- nccl_version.patch	                        (rev 0)
+++ nccl_version.patch	2020-01-27 17:16:31 UTC (rev 556235)
@@ -0,0 +1,46 @@
+diff --git a/cmake/Modules/FindNCCL.cmake b/cmake/Modules/FindNCCL.cmake
+index 5bd3ccd606..f92eda98f5 100644
+--- a/cmake/Modules/FindNCCL.cmake
++++ b/cmake/Modules/FindNCCL.cmake
+@@ -48,37 +48,39 @@ find_library(NCCL_LIBRARIES
+ 
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(NCCL DEFAULT_MSG NCCL_INCLUDE_DIRS NCCL_LIBRARIES)
+ 
+ if(NCCL_FOUND)  # obtaining NCCL version and some sanity checks
+   set (NCCL_HEADER_FILE "${NCCL_INCLUDE_DIRS}/nccl.h")
+   message (STATUS "Determining NCCL version from ${NCCL_HEADER_FILE}...")
+   set (OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
+   list (APPEND CMAKE_REQUIRED_INCLUDES ${NCCL_INCLUDE_DIRS})
+   include(CheckCXXSymbolExists)
+-  check_cxx_symbol_exists(NCCL_VERSION_CODE nccl.h NCCL_VERSION_DEFINED)
++  set(NCCL_VERSION_CODE $ENV{NCCL_VER_CODE})
++  set(NCCL_VERSION_DEFINED $ENV{NCCL_VER_CODE})
+ 
+-  if (NCCL_VERSION_DEFINED)
++  if (DEFINED NCCL_VERSION_DEFINED)
+     set(file "${PROJECT_BINARY_DIR}/detect_nccl_version.cc")
+     file(WRITE ${file} "
+       #include <iostream>
+       #include <nccl.h>
+       int main()
+       {
+         std::cout << NCCL_MAJOR << '.' << NCCL_MINOR << '.' << NCCL_PATCH << std::endl;
+ 
+         int x;
+         ncclGetVersion(&x);
+         return x == NCCL_VERSION_CODE;
+       }
+ ")
+     try_run(NCCL_VERSION_MATCHED compile_result ${PROJECT_BINARY_DIR} ${file}
++          CMAKE_FLAGS -DINCLUDE_DIRECTORIES=/opt/cuda/include
+           RUN_OUTPUT_VARIABLE NCCL_VERSION_FROM_HEADER
+           LINK_LIBRARIES ${NCCL_LIBRARIES})
+     if (NOT NCCL_VERSION_MATCHED)
+       message(FATAL_ERROR "Found NCCL header version and library version do not match! \
+ (include: ${NCCL_INCLUDE_DIRS}, library: ${NCCL_LIBRARIES}) Please set NCCL_INCLUDE_DIR and NCCL_LIB_DIR manually.")
+     endif()
+     message(STATUS "NCCL version: ${NCCL_VERSION_FROM_HEADER}")
+   else()
+     message(STATUS "NCCL version < 2.3.5-5")
+   endif ()

Added: torch_cuda_api.patch
===================================================================
--- torch_cuda_api.patch	                        (rev 0)
+++ torch_cuda_api.patch	2020-01-27 17:16:31 UTC (rev 556235)
@@ -0,0 +1,13 @@
+diff --git a/torch/csrc/cuda/nccl.h b/torch/csrc/cuda/nccl.h
+index 9f276f76fa..8a9062e857 100644
+--- a/torch/csrc/cuda/nccl.h
++++ b/torch/csrc/cuda/nccl.h
+@@ -19,7 +21,7 @@ namespace nccl {
+ // Don't use them outside of these files.
+ namespace detail {
+ 
+-void throw_nccl_error(ncclResult_t status);
++TORCH_CUDA_API void throw_nccl_error(ncclResult_t status);
+ 
+ static inline void NCCL_CHECK(ncclResult_t status) {
+   if (status != ncclSuccess) {



More information about the arch-commits mailing list