commit:     8337afbc16f16f0799c2e08094f5dc36fdbcc3ea
Author:     Alfredo Tupone <tupone <AT> gentoo <DOT> org>
AuthorDate: Sun Jun 26 07:58:44 2022 +0000
Commit:     Alfredo Tupone <tupone <AT> gentoo <DOT> org>
CommitDate: Sun Jun 26 07:58:44 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8337afbc

sci-libs/pytorch: add to tree

Package-Manager: Portage-3.0.30, Repoman-3.0.3
Signed-off-by: Alfredo Tupone <tupone <AT> gentoo.org>

 sci-libs/pytorch/Manifest                          |  1 +
 ...-t-build-libtorch-again-for-PyTorch-1.7.1.patch | 18 +++++++
 .../files/pytorch-1.6.0-global-dlopen.patch        | 15 ++++++
 .../files/pytorch-1.7.1-torch_shm_manager.patch    | 13 +++++
 ...ibrary-directory-according-to-CMake-build.patch | 32 +++++++++++++
 sci-libs/pytorch/metadata.xml                      | 11 +++++
 sci-libs/pytorch/pytorch-1.11.0.ebuild             | 56 ++++++++++++++++++++++
 7 files changed, 146 insertions(+)

diff --git a/sci-libs/pytorch/Manifest b/sci-libs/pytorch/Manifest
new file mode 100644
index 000000000000..ae4d5567b7fc
--- /dev/null
+++ b/sci-libs/pytorch/Manifest
@@ -0,0 +1 @@
+DIST pytorch-1.11.0.tar.gz 20719323 BLAKE2B 
24e7aaa2c26821d36f8092542de9d8d5ac85a619fb9fffb5131987958842afb1cad395780662d15f3411a7cc6ff83a445871960eca1e469fcbf0b9895d83d6e0
 SHA512 
2342eb7a1a241f5855a7cf12e11f62bc4baaa78d1d0864e53bfc946e783eb4addd05ca154a814d2376cd602098b5547e61c158d6eddb7cad5a9f3b0c1357adca

diff --git 
a/sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.7.1.patch
 
b/sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.7.1.patch
new file mode 100644
index 000000000000..640d061fcc59
--- /dev/null
+++ 
b/sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.7.1.patch
@@ -0,0 +1,18 @@
+diff --git a/setup.py b/setup.py
+index 2db381644c..2241a33015 100644
+--- a/setup.py
++++ b/setup.py
+@@ -363,13 +363,6 @@ def build_deps():
+     check_submodules()
+     check_pydep('yaml', 'pyyaml')
+ 
+-    build_caffe2(version=version,
+-                 cmake_python_library=cmake_python_library,
+-                 build_python=True,
+-                 rerun_cmake=RERUN_CMAKE,
+-                 cmake_only=CMAKE_ONLY,
+-                 cmake=cmake)
+-
+     if CMAKE_ONLY:
+         report('Finished running cmake. Run "ccmake build" or '
+                '"cmake-gui build" to adjust build options and '

diff --git a/sci-libs/pytorch/files/pytorch-1.6.0-global-dlopen.patch 
b/sci-libs/pytorch/files/pytorch-1.6.0-global-dlopen.patch
new file mode 100644
index 000000000000..1e9388ff17a6
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.6.0-global-dlopen.patch
@@ -0,0 +1,15 @@
+Don't hardcode the library path. Leave it to the dynamic loader.
+
+Index: pytorch-1.6.0/torch/__init__.py
+===================================================================
+--- pytorch-1.6.0.orig/torch/__init__.py
++++ pytorch-1.6.0/torch/__init__.py
+@@ -138,7 +138,7 @@ def _load_global_deps():
+     here = os.path.abspath(__file__)
+     lib_path = os.path.join(os.path.dirname(here), 'lib', 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/files/pytorch-1.7.1-torch_shm_manager.patch 
b/sci-libs/pytorch/files/pytorch-1.7.1-torch_shm_manager.patch
new file mode 100644
index 000000000000..69c2ddc5947e
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.7.1-torch_shm_manager.patch
@@ -0,0 +1,13 @@
+diff --git a/torch/__init__.py b/torch/__init__.py
+index 03f6eca622..297fb169a4 100644
+--- a/torch/__init__.py
++++ b/torch/__init__.py
+@@ -412,7 +412,7 @@ def manager_path():
+ 
+ 
+ # Shared memory manager needs to know the exact location of manager executable
+-_C._initExtension(manager_path())
++_C._initExtension(b"/usr/bin/torch_shm_manager")
+ del manager_path
+ 
+ # Appease the type checker: it can't deal with direct setting of globals().

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 000000000000..214267487c95
--- /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/metadata.xml b/sci-libs/pytorch/metadata.xml
new file mode 100644
index 000000000000..d12749aa5c21
--- /dev/null
+++ b/sci-libs/pytorch/metadata.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd";>
+<pkgmetadata>
+       <maintainer type="person">
+               <email>tup...@gentoo.org</email>
+               <name>Tupone Alfredo</name>
+       </maintainer>
+       <upstream>
+               <remote-id type="github">pytorch/pytorch</remote-id>
+       </upstream>
+</pkgmetadata>

diff --git a/sci-libs/pytorch/pytorch-1.11.0.ebuild 
b/sci-libs/pytorch/pytorch-1.11.0.ebuild
new file mode 100644
index 000000000000..a57ff0163fd0
--- /dev/null
+++ b/sci-libs/pytorch/pytorch-1.11.0.ebuild
@@ -0,0 +1,56 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_{8,9,10} )
+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[${PYTHON_USEDEP}]
+       dev-python/typing-extensions[${PYTHON_USEDEP}]
+"
+DEPEND="${RDEPEND}
+       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}"/${PN}-1.6.0-global-dlopen.patch \
+               "${FILESDIR}"/pytorch-1.7.1-torch_shm_manager.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