Gentoo Archives: gentoo-commits

From: Andrew Ammerlaan <andrewammerlaan@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sci:master commit in: sci-libs/pytorch/, sci-libs/pytorch/files/
Date: Wed, 22 Dec 2021 14:33:40
Message-Id: 1640176943.65e0afb1b927e1da6d8e23565b7d0aa1eacfc013.andrewammerlaan@gentoo
1 commit: 65e0afb1b927e1da6d8e23565b7d0aa1eacfc013
2 Author: YiyangWu <xgreenlandforwyy <AT> gmail <DOT> com>
3 AuthorDate: Wed Dec 22 09:59:27 2021 +0000
4 Commit: Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org>
5 CommitDate: Wed Dec 22 12:42:23 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/sci.git/commit/?id=65e0afb1
7
8 sci-libs/pytorch: fix python and update rocm support
9
10 Other changes:
11
12 1. Pytorch seems to be work fine with different version of protobuf, so
13 no need to specify 0/30; however when protobuf version changed torch
14 should be rebuilt.
15
16 2. BUILD_NAMEDTENSOR is not an option now
17
18 3. Verbose mode for rm in src_install
19
20 Package-Manager: Portage-3.0.22, Repoman-3.0.3
21 Signed-off-by: Yiyang Wu <xgreenlandforwyy <AT> gmail.com>
22 Closes: https://github.com/gentoo/sci/pull/1123
23 Signed-off-by: Andrew Ammerlaan <andrewammerlaan <AT> gentoo.org>
24
25 ...ibrary-directory-according-to-CMake-build.patch | 32 +++++++++++++++
26 .../files/pytorch-1.9.1-fix-wrong-hipify.patch | 13 ++++++
27 sci-libs/pytorch/pytorch-1.10.1.ebuild | 47 +++++++++++++---------
28 3 files changed, 74 insertions(+), 18 deletions(-)
29
30 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
31 new file mode 100644
32 index 000000000..214267487
33 --- /dev/null
34 +++ b/sci-libs/pytorch/files/pytorch-1.9.0-Change-library-directory-according-to-CMake-build.patch
35 @@ -0,0 +1,32 @@
36 +From 52019a3f395e5fa97b26d424152d91f73b400f8e Mon Sep 17 00:00:00 2001
37 +From: Alexey Chernov <4ernov@×××××.com>
38 +Date: Wed, 13 Nov 2019 23:44:12 +0300
39 +Subject: [PATCH 5/5] Change library directory according to CMake build
40 +Modified: Tue, 03 Aug 2021, fit for pytorch-1.9.0
41 +
42 +Change `lib_path` in favour of out-of-tree CMake build
43 +directory, so that all the C++ libraries be found.
44 +---
45 + setup.py | 5 +++--
46 + 1 file changed, 3 insertions(+), 2 deletions(-)
47 +
48 +diff --git a/setup.py b/setup.py
49 +index 60502b6add..cbced52192 100644
50 +--- a/setup.py
51 ++++ b/setup.py
52 +@@ -268,9 +268,10 @@ else:
53 +
54 + # Constant known variables used throughout this file
55 + cwd = os.path.dirname(os.path.abspath(__file__))
56 +-lib_path = os.path.join(cwd, "torch", "lib")
57 ++cmake_build_dir = os.environ.get("CMAKE_BUILD_DIR", os.path.join(cwd, "build"))
58 ++lib_path = os.path.join(cmake_build_dir, "lib")
59 + third_party_path = os.path.join(cwd, "third_party")
60 +-caffe2_build_dir = os.path.join(cwd, "build")
61 ++caffe2_build_dir = cmake_build_dir
62 +
63 + # CMAKE: full path to python library
64 + if IS_WINDOWS:
65 +--
66 +2.23.0
67 +
68
69 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
70 new file mode 100644
71 index 000000000..4e37acd3f
72 --- /dev/null
73 +++ b/sci-libs/pytorch/files/pytorch-1.9.1-fix-wrong-hipify.patch
74 @@ -0,0 +1,13 @@
75 +The hipify misadd a ) and causes compilation error
76 +
77 +--- orig/aten/src/ATen/native/sparse/hip/SparseHIPTensor.hip
78 ++++ pytorch-1.9.1/aten/src/ATen/native/sparse/hip/SparseHIPTensor.hip
79 +@@ -282,7 +282,7 @@ Tensor sparse_mask_helper_cuda(
80 + mask_indices_ti,
81 + t_indices_pos_ti,
82 + t_values_ti,
83 +- r_values_ti);
84 ++ r_values_ti;
85 + C10_HIP_KERNEL_LAUNCH_CHECK();
86 + });
87 + }
88
89 diff --git a/sci-libs/pytorch/pytorch-1.10.1.ebuild b/sci-libs/pytorch/pytorch-1.10.1.ebuild
90 index 5a745c28f..1750f40c9 100644
91 --- a/sci-libs/pytorch/pytorch-1.10.1.ebuild
92 +++ b/sci-libs/pytorch/pytorch-1.10.1.ebuild
93 @@ -58,7 +58,8 @@ LICENSE="BSD"
94 SLOT="0"
95 KEYWORDS="~amd64"
96
97 -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"
98 +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"
99 +RESTRICT="!test? ( test )"
100 REQUIRED_USE="
101 ?? ( cuda rocm )
102 "
103 @@ -68,17 +69,17 @@ RDEPEND="
104 blas? ( virtual/blas )
105 cuda? ( dev-libs/cudnn
106 dev-cpp/eigen[cuda] )
107 - rocm? ( >=dev-util/hip-4.0.0-r1
108 - >=dev-libs/rccl-4
109 - >=sci-libs/rocThrust-4
110 - >=sci-libs/hipCUB-4
111 - >=sci-libs/rocPRIM-4
112 - >=sci-libs/miopen-4
113 - >=sci-libs/rocBLAS-4
114 - >=sci-libs/rocRAND-4
115 - >=sci-libs/hipSPARSE-4
116 - >=sci-libs/rocFFT-4
117 - >=dev-util/roctracer-4 )
118 + rocm? ( >=dev-util/hip-4.3
119 + >=dev-libs/rccl-4.3
120 + >=sci-libs/rocThrust-4.3
121 + >=sci-libs/hipCUB-4.3
122 + >=sci-libs/rocPRIM-4.3
123 + >=sci-libs/miopen-4.3
124 + >=sci-libs/rocBLAS-4.3
125 + >=sci-libs/rocRAND-4.3
126 + >=sci-libs/hipSPARSE-4.3
127 + >=sci-libs/rocFFT-4.3
128 + >=dev-util/roctracer-4.3 )
129 ffmpeg? ( media-video/ffmpeg )
130 gflags? ( dev-cpp/gflags )
131 glog? ( dev-cpp/glog[gflags] )
132 @@ -90,12 +91,12 @@ RDEPEND="
133 python? ( ${PYTHON_DEPS}
134 dev-python/pybind11[${PYTHON_USEDEP}]
135 dev-python/numpy[${PYTHON_USEDEP}]
136 - dev-python/protobuf-python:0/30
137 + dev-python/protobuf-python:=
138 )
139 redis? ( dev-db/redis )
140 zeromq? ( net-libs/zeromq )
141 dev-cpp/eigen
142 - dev-libs/protobuf:0/30
143 + dev-libs/protobuf:=
144 dev-libs/libuv
145 "
146
147 @@ -103,6 +104,7 @@ RDEPEND="
148 BDEPEND="dev-python/pyyaml"
149
150 DEPEND="${RDEPEND}
151 + test? ( dev-python/pytest[${PYTHON_USEDEP}] )
152 dev-cpp/tbb
153 app-arch/zstd
154 dev-python/pybind11[${PYTHON_USEDEP}]
155 @@ -112,7 +114,7 @@ DEPEND="${RDEPEND}
156 "
157
158 PATCHES=(
159 - "${FILESDIR}"/${PN}-1.6.0-skip-tests.patch
160 + "${FILESDIR}"/${PN}-1.9.0-Change-library-directory-according-to-CMake-build.patch
161 "${FILESDIR}"/${PN}-1.6.0-global-dlopen.patch
162 "${FILESDIR}"/0002-Don-t-build-libtorch-again-for-PyTorch-1.7.1.patch
163 "${FILESDIR}"/${PN}-1.7.1-no-rpath.patch
164 @@ -213,12 +215,21 @@ src_prepare() {
165
166 ebegin "HIPifying cuda sources"
167 ${EPYTHON} tools/amd_build/build_amd.py || die
168 + eapply "${FILESDIR}"/${PN}-1.9.1-fix-wrong-hipify.patch
169 eend $?
170
171 - export PYTORCH_ROCM_ARCH=$(rocminfo | egrep -o "gfx[0-9]+" | uniq | awk -vORS=';' "{print $1}" | sed 's/;$/\n/') || die
172 + local ROCM_VERSION="$(hipconfig -v)-"
173 + export PYTORCH_ROCM_ARCH="${AMDGPU_TARGETS}"
174 sed -e "/set(roctracer_INCLUDE_DIRS/s,\${ROCTRACER_PATH}/include,${EPREFIX}/usr/include/roctracer," \
175 + -e "/PYTORCH_HIP_HCC_LIBRARIES/s,\${HIP_PATH}/lib,${EPREFIX}/usr/lib/hip/lib," \
176 + -e "s,\${ROCTRACER_PATH}/lib,${EPREFIX}/usr/lib64/roctracer," \
177 + -e "/READ.*\.info\/version-dev/c\ set(ROCM_VERSION_DEV_RAW ${ROCM_VERSION})" \
178 -i cmake/public/LoadHIP.cmake || die
179 + sed -r -e '/^if\(USE_ROCM/{:a;N;/\nendif/!ba; s,\{([^\{]*)_PATH\}(/include)?,\{\L\1_\UINCLUDE_DIRS\},g}' -i cmake/Dependencies.cmake || die
180 fi
181 +
182 + # Set build dir for pytorch's setup
183 + sed -e "/BUILD_DIR/s,build,${BUILD_DIR}," -i tools/setup_helpers/env.py || die
184 }
185
186 src_configure() {
187 @@ -262,13 +273,12 @@ src_configure() {
188 -DUSE_GLOO=$(usex gloo ON OFF)
189 -DUSE_SYSTEM_EIGEN_INSTALL=ON
190 -DUSE_SYSTEM_PYBIND11=ON
191 - -DBUILD_NAMEDTENSOR=$(usex namedtensor ON OFF)
192 -DBLAS=$(usex blas Generic Eigen)
193 -DTP_BUILD_LIBUV=OFF
194 -Wno-dev
195 )
196
197 - cmake_src_configure
198 + HIP_PATH="${EPREFIX}/usr/lib/hip" cmake_src_configure
199
200 if use python; then
201 CMAKE_BUILD_DIR="${BUILD_DIR}" distutils-r1_src_configure
202 @@ -308,6 +318,7 @@ src_install() {
203 rm -rfv "${ED}/usr/include/var"
204
205 rm -r "${ED}/usr/${LIB}/cmake" || die
206 + rm -rv "${ED}/usr/${LIB}/cmake" || die
207
208 if use python; then
209 scanelf -r --fix "${BUILD_DIR}/caffe2/python" || die