commit:     d2a5c15046bab11f3e70927d6b053ab98870acf0
Author:     Alfredo Tupone <tupone <AT> gentoo <DOT> org>
AuthorDate: Wed Apr  5 19:35:41 2023 +0000
Commit:     Alfredo Tupone <tupone <AT> gentoo <DOT> org>
CommitDate: Wed Apr  5 19:35:58 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d2a5c150

sci-libs/pytorch: add 2.0.0

Signed-off-by: Alfredo Tupone <tupone <AT> gentoo.org>

 sci-libs/pytorch/Manifest                          |  1 +
 sci-libs/pytorch/files/pytorch-2.0.0-emptyso.patch | 15 +++++
 .../files/pytorch-2.0.0-global-dlopen.patch        | 20 +++++++
 sci-libs/pytorch/pytorch-2.0.0.ebuild              | 64 ++++++++++++++++++++++
 4 files changed, 100 insertions(+)

diff --git a/sci-libs/pytorch/Manifest b/sci-libs/pytorch/Manifest
index 616b75a49763..1424256938e9 100644
--- a/sci-libs/pytorch/Manifest
+++ b/sci-libs/pytorch/Manifest
@@ -1 +1,2 @@
 DIST pytorch-1.13.1.tar.gz 108279745 BLAKE2B 
75de03b74dfdaf8d8fb5ea743fcc0c1b0e408a714ad4160c487921220a7b1755e5fa6e587e6bbc8c9f34dd75e096d2e6dd69c80d24821835fff6c833314434d3
 SHA512 
f16f89d027efade11d057245cad5b69a390e88b458398310ae30de2dbff7c8fd7f1165be7b8da7ea989c81ac3f5a66c5cb9050610e441a97c83fb8aa28c0bd62
+DIST pytorch-2.0.0.tar.gz 111327292 BLAKE2B 
6d593a975c0ade714f0b189f7e3c4ff704b9a9a2377b5e441a9cefc202fa22779966d08948e63671912c6ea5a0eee124042155f4f57a654db34e19e42f013cc9
 SHA512 
4dd76160711c0d87f3026c8b7fa3ed149dd86b8ac0ee9ecea0eaf80d2e6ce8c29368392e77b9466d90b60634087b462b782495997a5d33367cc8ca9fe14c8a14

diff --git a/sci-libs/pytorch/files/pytorch-2.0.0-emptyso.patch 
b/sci-libs/pytorch/files/pytorch-2.0.0-emptyso.patch
new file mode 100644
index 000000000000..e4703894308a
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-2.0.0-emptyso.patch
@@ -0,0 +1,15 @@
+--- a/setup.py 2023-04-05 11:23:00.713405789 +0200
++++ b/setup.py 2023-04-05 11:23:36.900876249 +0200
+@@ -960,12 +960,6 @@
+                     name=str('caffe2.python.caffe2_pybind11_state_hip'),
+                     sources=[]),
+             )
+-    if cmake_cache_vars['BUILD_FUNCTORCH']:
+-        extensions.append(
+-            Extension(
+-                name=str('functorch._C'),
+-                sources=[]),
+-        )
+     if cmake_cache_vars['BUILD_NVFUSER']:
+         extensions.append(
+             Extension(

diff --git a/sci-libs/pytorch/files/pytorch-2.0.0-global-dlopen.patch 
b/sci-libs/pytorch/files/pytorch-2.0.0-global-dlopen.patch
new file mode 100644
index 000000000000..0f1b400e234d
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-2.0.0-global-dlopen.patch
@@ -0,0 +1,20 @@
+--- a/torch/__init__.py        2023-04-05 11:12:25.682681130 +0200
++++ b/torch/__init__.py        2023-04-05 11:13:00.640170307 +0200
+@@ -165,7 +165,7 @@
+     lib_path = os.path.join(os.path.dirname(here), 'lib', lib_name)
+ 
+     try:
+-        ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
++        ctypes.CDLL(lib_name, mode=ctypes.RTLD_GLOBAL)
+     except OSError as err:
+         # Can only happen for wheel with cuda libs as PYPI deps
+         # As PyTorch is not purelib, but nvidia-*-cu11 is
+@@ -187,7 +187,7 @@
+             raise err
+         for lib_folder, lib_name in cuda_libs.items():
+             _preload_cuda_deps(lib_folder, lib_name)
+-        ctypes.CDLL(lib_path, mode=ctypes.RTLD_GLOBAL)
++        ctypes.CDLL(lib_name, mode=ctypes.RTLD_GLOBAL)
+ 
+ 
+ if (USE_RTLD_GLOBAL_WITH_LIBTORCH or os.getenv('TORCH_USE_RTLD_GLOBAL')) and \

diff --git a/sci-libs/pytorch/pytorch-2.0.0.ebuild 
b/sci-libs/pytorch/pytorch-2.0.0.ebuild
new file mode 100644
index 000000000000..506f1889b280
--- /dev/null
+++ b/sci-libs/pytorch/pytorch-2.0.0.ebuild
@@ -0,0 +1,64 @@
+# Copyright 2022-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_{9..11} )
+DISTUTILS_SINGLE_IMPL=1
+inherit distutils-r1
+
+DESCRIPTION="Tensors and Dynamic neural networks in Python"
+HOMEPAGE="https://pytorch.org/";
+SRC_URI="https://github.com/pytorch/${PN}/archive/refs/tags/v${PV}.tar.gz
+       -> ${P}.tar.gz"
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~amd64"
+RESTRICT="test"
+
+REQUIRED_USE=${PYTHON_REQUIRED_USE}
+RDEPEND="
+       ${PYTHON_DEPS}
+       ~sci-libs/caffe2-${PV}[${PYTHON_SINGLE_USEDEP}]
+       $(python_gen_cond_dep '
+               dev-python/typing-extensions[${PYTHON_USEDEP}]
+               dev-python/sympy[${PYTHON_USEDEP}]
+       ')
+"
+DEPEND="${RDEPEND}
+       $(python_gen_cond_dep '
+               dev-python/pyyaml[${PYTHON_USEDEP}]
+       ')
+"
+
+src_prepare() {
+       eapply \
+               
"${FILESDIR}"/0002-Don-t-build-libtorch-again-for-PyTorch-1.7.1.patch \
+               
"${FILESDIR}"/pytorch-1.9.0-Change-library-directory-according-to-CMake-build.patch
 \
+               "${FILESDIR}"/${P}-global-dlopen.patch \
+               "${FILESDIR}"/pytorch-1.7.1-torch_shm_manager.patch \
+               "${FILESDIR}"/${PN}-1.13.0-setup.patch \
+               "${FILESDIR}"/${P}-emptyso.patch \
+
+       # Set build dir for pytorch's setup
+       sed -i \
+               -e "/BUILD_DIR/s|build|/var/lib/caffe2/|" \
+               tools/setup_helpers/env.py \
+               || die
+       distutils-r1_src_prepare
+}
+
+src_compile() {
+       PYTORCH_BUILD_VERSION=${PV} \
+       PYTORCH_BUILD_NUMBER=0 \
+       USE_SYSTEM_LIBS=ON \
+       CMAKE_BUILD_DIR="${BUILD_DIR}" \
+       BUILD_DIR= \
+       distutils-r1_src_compile
+}
+
+src_install() {
+       USE_SYSTEM_LIBS=ON distutils-r1_src_install
+}

Reply via email to