commit:     65e0afb1b927e1da6d8e23565b7d0aa1eacfc013
Author:     YiyangWu <xgreenlandforwyy <AT> gmail <DOT> com>
AuthorDate: Wed Dec 22 09:59:27 2021 +0000
Commit:     Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org>
CommitDate: Wed Dec 22 12:42:23 2021 +0000
URL:        https://gitweb.gentoo.org/proj/sci.git/commit/?id=65e0afb1

sci-libs/pytorch: fix python and update rocm support

Other changes:

1. Pytorch seems to be work fine with different version of protobuf, so
   no need to specify 0/30; however when protobuf version changed torch
   should be rebuilt.

2. BUILD_NAMEDTENSOR is not an option now

3. Verbose mode for rm in src_install

Package-Manager: Portage-3.0.22, Repoman-3.0.3
Signed-off-by: Yiyang Wu <xgreenlandforwyy <AT> gmail.com>
Closes: https://github.com/gentoo/sci/pull/1123
Signed-off-by: Andrew Ammerlaan <andrewammerlaan <AT> gentoo.org>

 ...ibrary-directory-according-to-CMake-build.patch | 32 +++++++++++++++
 .../files/pytorch-1.9.1-fix-wrong-hipify.patch     | 13 ++++++
 sci-libs/pytorch/pytorch-1.10.1.ebuild             | 47 +++++++++++++---------
 3 files changed, 74 insertions(+), 18 deletions(-)

diff --git 
a/sci-libs/pytorch/files/pytorch-1.9.0-Change-library-directory-according-to-CMake-build.patch
 
b/sci-libs/pytorch/files/pytorch-1.9.0-Change-library-directory-according-to-CMake-build.patch
new file mode 100644
index 000000000..214267487
--- /dev/null
+++ 
b/sci-libs/pytorch/files/pytorch-1.9.0-Change-library-directory-according-to-CMake-build.patch
@@ -0,0 +1,32 @@
+From 52019a3f395e5fa97b26d424152d91f73b400f8e Mon Sep 17 00:00:00 2001
+From: Alexey Chernov <4er...@gmail.com>
+Date: Wed, 13 Nov 2019 23:44:12 +0300
+Subject: [PATCH 5/5] Change library directory according to CMake build
+Modified: Tue, 03 Aug 2021, fit for pytorch-1.9.0
+
+Change `lib_path` in favour of out-of-tree CMake build
+directory, so that all the C++ libraries be found.
+---
+ setup.py | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/setup.py b/setup.py
+index 60502b6add..cbced52192 100644
+--- a/setup.py
++++ b/setup.py
+@@ -268,9 +268,10 @@ else:
+ 
+ # Constant known variables used throughout this file
+ cwd = os.path.dirname(os.path.abspath(__file__))
+-lib_path = os.path.join(cwd, "torch", "lib")
++cmake_build_dir = os.environ.get("CMAKE_BUILD_DIR", os.path.join(cwd, 
"build"))
++lib_path = os.path.join(cmake_build_dir, "lib")
+ third_party_path = os.path.join(cwd, "third_party")
+-caffe2_build_dir = os.path.join(cwd, "build")
++caffe2_build_dir = cmake_build_dir
+ 
+ # CMAKE: full path to python library
+ if IS_WINDOWS:
+-- 
+2.23.0
+

diff --git a/sci-libs/pytorch/files/pytorch-1.9.1-fix-wrong-hipify.patch 
b/sci-libs/pytorch/files/pytorch-1.9.1-fix-wrong-hipify.patch
new file mode 100644
index 000000000..4e37acd3f
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.9.1-fix-wrong-hipify.patch
@@ -0,0 +1,13 @@
+The hipify misadd a ) and causes compilation error
+
+--- orig/aten/src/ATen/native/sparse/hip/SparseHIPTensor.hip
++++ pytorch-1.9.1/aten/src/ATen/native/sparse/hip/SparseHIPTensor.hip
+@@ -282,7 +282,7 @@ Tensor sparse_mask_helper_cuda(
+               mask_indices_ti,
+               t_indices_pos_ti,
+               t_values_ti,
+-              r_values_ti);
++              r_values_ti;
+           C10_HIP_KERNEL_LAUNCH_CHECK();
+         });
+   }

diff --git a/sci-libs/pytorch/pytorch-1.10.1.ebuild 
b/sci-libs/pytorch/pytorch-1.10.1.ebuild
index 5a745c28f..1750f40c9 100644
--- a/sci-libs/pytorch/pytorch-1.10.1.ebuild
+++ b/sci-libs/pytorch/pytorch-1.10.1.ebuild
@@ -58,7 +58,8 @@ LICENSE="BSD"
 SLOT="0"
 KEYWORDS="~amd64"
 
-IUSE="asan blas cuda +fbgemm ffmpeg gflags glog +gloo leveldb lmdb mkldnn mpi 
namedtensor +nnpack numa +observers opencl opencv +openmp +python +qnnpack 
redis rocm static tools zeromq"
+IUSE="asan blas cuda +fbgemm ffmpeg gflags glog +gloo leveldb lmdb mkldnn mpi 
namedtensor +nnpack numa +observers opencl opencv +openmp +python +qnnpack 
redis rocm static test tools zeromq"
+RESTRICT="!test? ( test )"
 REQUIRED_USE="
        ?? ( cuda rocm )
 "
@@ -68,17 +69,17 @@ RDEPEND="
        blas? ( virtual/blas )
        cuda? ( dev-libs/cudnn
                dev-cpp/eigen[cuda] )
-       rocm? ( >=dev-util/hip-4.0.0-r1
-                       >=dev-libs/rccl-4
-                       >=sci-libs/rocThrust-4
-                       >=sci-libs/hipCUB-4
-                       >=sci-libs/rocPRIM-4
-                       >=sci-libs/miopen-4
-                       >=sci-libs/rocBLAS-4
-                       >=sci-libs/rocRAND-4
-                       >=sci-libs/hipSPARSE-4
-                       >=sci-libs/rocFFT-4
-                       >=dev-util/roctracer-4 )
+       rocm? ( >=dev-util/hip-4.3
+                       >=dev-libs/rccl-4.3
+                       >=sci-libs/rocThrust-4.3
+                       >=sci-libs/hipCUB-4.3
+                       >=sci-libs/rocPRIM-4.3
+                       >=sci-libs/miopen-4.3
+                       >=sci-libs/rocBLAS-4.3
+                       >=sci-libs/rocRAND-4.3
+                       >=sci-libs/hipSPARSE-4.3
+                       >=sci-libs/rocFFT-4.3
+                       >=dev-util/roctracer-4.3 )
        ffmpeg? ( media-video/ffmpeg )
        gflags? ( dev-cpp/gflags )
        glog? ( dev-cpp/glog[gflags] )
@@ -90,12 +91,12 @@ RDEPEND="
        python? ( ${PYTHON_DEPS}
                dev-python/pybind11[${PYTHON_USEDEP}]
                dev-python/numpy[${PYTHON_USEDEP}]
-               dev-python/protobuf-python:0/30
+               dev-python/protobuf-python:=
        )
        redis? ( dev-db/redis )
        zeromq? ( net-libs/zeromq )
        dev-cpp/eigen
-       dev-libs/protobuf:0/30
+       dev-libs/protobuf:=
        dev-libs/libuv
 "
 
@@ -103,6 +104,7 @@ RDEPEND="
 BDEPEND="dev-python/pyyaml"
 
 DEPEND="${RDEPEND}
+       test? ( dev-python/pytest[${PYTHON_USEDEP}] )
        dev-cpp/tbb
        app-arch/zstd
        dev-python/pybind11[${PYTHON_USEDEP}]
@@ -112,7 +114,7 @@ DEPEND="${RDEPEND}
 "
 
 PATCHES=(
-       "${FILESDIR}"/${PN}-1.6.0-skip-tests.patch
+       
"${FILESDIR}"/${PN}-1.9.0-Change-library-directory-according-to-CMake-build.patch
        "${FILESDIR}"/${PN}-1.6.0-global-dlopen.patch
        "${FILESDIR}"/0002-Don-t-build-libtorch-again-for-PyTorch-1.7.1.patch
        "${FILESDIR}"/${PN}-1.7.1-no-rpath.patch
@@ -213,12 +215,21 @@ src_prepare() {
 
                ebegin "HIPifying cuda sources"
                ${EPYTHON} tools/amd_build/build_amd.py || die
+               eapply "${FILESDIR}"/${PN}-1.9.1-fix-wrong-hipify.patch
                eend $?
 
-               export PYTORCH_ROCM_ARCH=$(rocminfo | egrep -o "gfx[0-9]+" | 
uniq | awk -vORS=';' "{print $1}" | sed 's/;$/\n/') || die
+               local ROCM_VERSION="$(hipconfig -v)-"
+               export PYTORCH_ROCM_ARCH="${AMDGPU_TARGETS}"
                sed -e 
"/set(roctracer_INCLUDE_DIRS/s,\${ROCTRACER_PATH}/include,${EPREFIX}/usr/include/roctracer,"
 \
+                       -e 
"/PYTORCH_HIP_HCC_LIBRARIES/s,\${HIP_PATH}/lib,${EPREFIX}/usr/lib/hip/lib," \
+                       -e 
"s,\${ROCTRACER_PATH}/lib,${EPREFIX}/usr/lib64/roctracer," \
+                       -e "/READ.*\.info\/version-dev/c\  
set(ROCM_VERSION_DEV_RAW ${ROCM_VERSION})" \
                        -i cmake/public/LoadHIP.cmake || die
+               sed -r -e '/^if\(USE_ROCM/{:a;N;/\nendif/!ba; 
s,\{([^\{]*)_PATH\}(/include)?,\{\L\1_\UINCLUDE_DIRS\},g}' -i 
cmake/Dependencies.cmake || die
        fi
+
+       # Set build dir for pytorch's setup
+       sed -e "/BUILD_DIR/s,build,${BUILD_DIR}," -i tools/setup_helpers/env.py 
|| die
 }
 
 src_configure() {
@@ -262,13 +273,12 @@ src_configure() {
                -DUSE_GLOO=$(usex gloo ON OFF)
                -DUSE_SYSTEM_EIGEN_INSTALL=ON
                -DUSE_SYSTEM_PYBIND11=ON
-               -DBUILD_NAMEDTENSOR=$(usex namedtensor ON OFF)
                -DBLAS=$(usex blas Generic Eigen)
                -DTP_BUILD_LIBUV=OFF
                -Wno-dev
        )
 
-       cmake_src_configure
+       HIP_PATH="${EPREFIX}/usr/lib/hip" cmake_src_configure
 
        if use python; then
                CMAKE_BUILD_DIR="${BUILD_DIR}" distutils-r1_src_configure
@@ -308,6 +318,7 @@ src_install() {
        rm -rfv "${ED}/usr/include/var"
 
        rm -r "${ED}/usr/${LIB}/cmake" || die
+       rm -rv "${ED}/usr/${LIB}/cmake" || die
 
        if use python; then
                scanelf -r --fix "${BUILD_DIR}/caffe2/python" || die

Reply via email to