aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Chernov <4ernov@gmail.com>2020-02-10 21:51:53 +0300
committerBenda Xu <heroxbd@gentoo.org>2020-02-19 22:35:57 +0800
commitbb46b0f6b4260c8aca367dc153b10a385d9728eb (patch)
treecf0ef048b15f167cb0ba893524f2e8d724aba469
parentdev-tex/pythontex: bump to 0.17 and drop old. (diff)
downloadsci-bb46b0f6b4260c8aca367dc153b10a385d9728eb.tar.gz
sci-bb46b0f6b4260c8aca367dc153b10a385d9728eb.tar.bz2
sci-bb46b0f6b4260c8aca367dc153b10a385d9728eb.zip
sci-libs/pytorch: initial commit.
This is CPU version only. ROCm and CUDA options will be added later. Reference: https://github.com/aclex/pytorch-ebuild Bug: https://github.com/gentoo/sci/pull/941 Package-Manager: Portage-2.3.88, Repoman-2.3.18 Signed-off-by: Benda Xu <heroxbd@gentoo.org>
-rw-r--r--sci-libs/pytorch/Manifest22
-rw-r--r--sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.4.0.patch30
-rw-r--r--sci-libs/pytorch/files/0003-Change-path-to-caffe2-build-dir-made-by-libtorch.patch46
-rw-r--r--sci-libs/pytorch/files/0004-Don-t-fill-rpath-of-Caffe2-library-for-system-wide-i.patch104
-rw-r--r--sci-libs/pytorch/files/0005-Change-library-directory-according-to-CMake-build.patch31
-rw-r--r--sci-libs/pytorch/files/0010-Remove-conversion-ambiguity-in-ternary-operators.patch38
-rw-r--r--sci-libs/pytorch/files/pytorch-1.2.0-setup.patch24
-rw-r--r--sci-libs/pytorch/files/pytorch-1.4.0-eigen.patch13
-rw-r--r--sci-libs/pytorch/files/pytorch-1.4.0-nccl-nvccflags.patch28
-rw-r--r--sci-libs/pytorch/files/pytorch-1.4.0-skip-tests.patch28
-rw-r--r--sci-libs/pytorch/files/pytorch-1.4.0-sleef.patch15
-rw-r--r--sci-libs/pytorch/metadata.xml35
-rw-r--r--sci-libs/pytorch/pytorch-1.4.0_p0.ebuild272
13 files changed, 686 insertions, 0 deletions
diff --git a/sci-libs/pytorch/Manifest b/sci-libs/pytorch/Manifest
new file mode 100644
index 000000000..8639857d5
--- /dev/null
+++ b/sci-libs/pytorch/Manifest
@@ -0,0 +1,22 @@
+DIST FP16-febbb1c1.tar.gz 71108 BLAKE2B 995566af221d89b6ff831dd431143b0aa9b23b0a1696ca9fdb70af1817643759e7d3322240a1307edbc8d15a7f7c36545e53f5a8328840068a157281774a4ebd SHA512 9360d9543c05581124e7bb1b40dca07246512a03faf0c06d1d5b7c73c52db3c97819ebc2f6b1c8be3668ace4dfb1fb1f0904bced6998710f3b2118b7416c041a
+DIST FXdiv-b742d114.tar.gz 8567 BLAKE2B 983faa7727f296b1943ec3f5bc3ed3da5e38c390e99fdd4c7b87f9f272a5af54d6ce273e0540c68fdc428aee35c2ccd2933ff0b20fd0c627d91b0f969efbaa2d SHA512 cd363408055c16f8fe39a1c49abd5aba8eedf193e9d4d7964e39ef260a53ba6bd5708a5ba6bbc77130f324c14df57fcc9adf88df7b8a21574bbb4f968895753f
+DIST NNPACK-c039579a.tar.gz 219136 BLAKE2B fed0b28740b7d39fc77fa7587395123d6fa156ca9c4df796d44daaecedbb9604ce642da0c71034b27f8e7ab2bb07f7cf5494711a0ee9a1aea8eb9d507e3980e5 SHA512 cc5ad260433182b341615f267c2ae07753ffc6e243b6a9f182099daf9111b2863aa01c40f4866ea4d614d3d7b0330a407240a7d7057279c6abbbf3dfbc3cc090
+DIST PeachPy-07d8fde8.tar.gz 401648 BLAKE2B c563cd77a9e2eda34bbec6a34f94111a6db9500b7cda9a18e791984b789c29dde7199ed21696f10cdfb088b05e18163b02a8ca8c9e48a91b9e4a757020f096b0 SHA512 8d6cc91c8c4d56b86ef93f0acd6768a1830ecd078524b21d1a3b9ecb015f06607070148de3e634d9c5ce63ed523a8e34aa388d490e7eee061200098f39126afa
+DIST QNNPACK-7d2a4e99.tar.gz 205600 BLAKE2B f174051cba9e3307633f0b12326a37d8fde23562d47e09d3c078350146439094ca6cb2f032cf3aa4af40e5968ee16b8847241f787f7c84ea501124e0528fb82d SHA512 437a835acfedae851a9a8572fa6eea9854dcb8bcca499bc4a2582314e44f5f199778e857932da4aecf943bea7cb2eb5b1c41d4b4ca6075bddbe0f18b2c7b9127
+DIST asmjit-17556b2d.tar.gz 527758 BLAKE2B 95e51f4323fe921a3c01ef472286a73ab5e487341dc81c4519b3ffb48f3e6fc7e634070fff8cdbe03beef850c867406ca9b528733962685e456a182ba55d6d84 SHA512 4513e766d55e22998c2fbee3c22eb0501e37faeb5136d76ea59727f651d0ccd8870e57f224bab1223543a4e11d2ddb31221dfb6cfe99c8e8ed7049f2cd39633b
+DIST benchmark-505be96a.tar.gz 129647 BLAKE2B d9f435f464fa1db18b86258947b8c5077b8b20b9c26ca00aeeca79da604f299f776673c374b7d0db10a5d40cbc84774642b29e756a83f02cda5d085280387346 SHA512 2ec79b66c31d4741b214c04f7865cf0139b4c0b14a8fb2a70bf332cf90e73821282b510719689bc2fe59542ee51c87e9f9b49a47b6a67cad897f7f906f0b05e9
+DIST cpuinfo-89fe1695.tar.gz 3488961 BLAKE2B 15c9d97a39cb563d202e019a2b435cba499417aa32b90a21f72c68f55bf711007e9c496ec7740cabcc2dc0f88e66208a3f1ae1215d0ef6b33a244b0ea9e700de SHA512 ffb3eb1555e95771964afca8e003f022308dec45ae7533aa92c9c3c183764611d9bfe53b9f1d81964c244a23ebdb6a41214e09cf1c1839c847a31a31f9fc877c
+DIST cub-285aeeba.tar.gz 384479 BLAKE2B 182218d1a1cc46d87bb1a15885eeea4a580cfe2f2e4b24b80e3fb18de0784be1f70457439781bf9fe0f5f82a793dfe0fb420c73bb5cecc5c15d41affd66485e3 SHA512 0f05a4acc64b929a4cc8d71d7fed5e8780a77d19621caac322fb034343bbe5c84b6532acd2af3b8e273db6d565f69cb2348576ffeeb118f64cef08323902cb18
+DIST fbgemm-82d259da.tar.gz 159707 BLAKE2B 4fdbc4efbd6deb87f32f256d3d041cf901b3c350514577ba45d3a18bf31e68a312b0e29cdc6e81aff42fff00465f7e2d43691127b4d96db87e90f976cce7c0f2 SHA512 7c90269aca2f421707808533af82b9702eabfa92b13dfd5c757bd8ba207d76f97f9e8f72495f0f002ea6b88bc4cb32bb11e3f726f361fef41e206d18d36dac80
+DIST foxi-8f74bc4d.tar.gz 27632 BLAKE2B 590605dcc716c51339e4ea3003522875c676df9ccb1e8324d969be95bedd16b7e6abf9a6a42440c427d7606556ced8c8763ec4780da0395ce3b470f30dea376a SHA512 ae8a6aa5ac8730043ae52cf378d87563cf93a9fe132baca573e38a315703f7823f311beacc2cd2145ed84109e06f31bed97e655693cc3dcab4f19f06c28b5cf8
+DIST gemmlowp-3fb5c176.tar.gz 826382 BLAKE2B c5e68cb78429fe8ce96c752270e747382287937d0a0c1af26b444eda495a78438193c54900cd7906b34b369e170d582c5599f541d23d1280e38f972d6daea1ea SHA512 1c97bba41931c7fddf0e7c01312892cfa3d87abe2a4cdaf4cd20d846a102c5ad3d85329ccdb386f7047f2f037e92639cbcf91b317c2bf38bee11c12e71584afc
+DIST gloo-ca528e32.tar.gz 220673 BLAKE2B 67f80c171caa54526c4063dc3f691be9850891da77feb76bd3d3ebe838c7794eb6613527189a9aa368dd3c4ab44fc9c86b7e2c1b3daf744a58f95c12f8ef9289 SHA512 a915d9ad8fd4427a977d9dc5995dadc69dded22b420eec5164dd10f56a21d7e51d6fc5451573c63b571b305301fb477f6c6bbfda87b9e17888b4bf361b34ec59
+DIST googletest-2fe3bd99.tar.gz 993527 BLAKE2B fa631eadc310607dbe19cec6d66d8fb1c5e99e2dfc5031fff26f8c12c951d7798ad2062edf21589020cafc821bfe4b5e89310ee4e85f45d7d7fcd435ddd5eef9 SHA512 130182d2c1067bcd263fb27999c164d240f5d06d837475e71e7cadbf65c7211de00154dc1e15deae0b6ec2963799e55c0c21ee971e1c588064c5063e69a2bf1e
+DIST ideep-78eafa5d.tar.gz 36475 BLAKE2B 0df79cd5ac71d550391292cd1fc4caf3ed467ba6487a1581cdb4eb21c4be86881d2b1bdb76cce8f560a9fc211ac64c7cd75048c7768eb14961375c1014d0a926 SHA512 0de47a89112cb0ff2f9dc380ef91cda6a3c1c7a9fcd10dc7e9621afe6b38132501931b2ac29fc4c5f2c064e7e1bf4802bda1ea6856e9fd046ff1e4d48ef727f1
+DIST nccl-7c72dee6.tar.gz 109658 BLAKE2B bd42488a8211918460f20ae41559f4fa5a8e3e63d5f56a7256077fc512f99d7ba82d9542ef651113e70182c1d856a88a670207b22d837687ece84d108556aadb SHA512 69f8d197dc0d6ce17d7796410f3c65ea50f23c62a4ea128b3ce117c6a43be92c783c9cc7af9632f362d58c3dc43aa402b722b2280338f4094afa498261da67d6
+DIST onnx-2891e145.tar.gz 2590111 BLAKE2B 5143b7a365338bc29496f0dbc0aa21581220c1e5331913b50efd8eed9b226ec6bb970ffc281a921cb0d4098dc4441d06a3afff99c2647791ec5850a8eb3f4297 SHA512 7dee19018b9b2a71620cf961f4afcdc2c69a11b43cba4d62c69dbe398c2a6ee1059efc016dc6c5b58645524e196d6308ba1b2c8149acae905a197f84c10f00a4
+DIST onnx-tensorrt-cb3d8066.tar.gz 70233 BLAKE2B 94721e3ea16d6251c8c9060b2ff256a460ff7d1f2c78ef622bed3bc7bcf011805f6b2ada1b67340bd98b7bac43187d5ce2ad98312e57a2f273b22c551f160fc9 SHA512 4746a5988ec31994aae81324f345564ae2d733bbcbc9b4453a24cf52dda62117325269bcbf6e3e94ee1f09395313d45a7cfe6da34806df901a99740ea9b88f85
+DIST psimd-90a938f3.tar.gz 6182 BLAKE2B 8178d1fd2406a7c23f9cfd02636d2edbf2cea6af5798373b6639cb2d96d3b13d9c1d14c8006983ad5cdcde6072e9d371ced09ff2a76dd2f932a969185a233573 SHA512 f1bbbde0d4e2cb15c9f10722d6d8701d7e4d58396e9981a6887f71977bbd367e181518e44002a3be624fe05473faf094002be94d89e017b43efd4e41892f8c18
+DIST pthreadpool-13da0b4c.tar.gz 12775 BLAKE2B cb2ae4e8ab6d9501ecf835e38c57818883ec3225ef768eb2c46927600d7ba33d324f528d1009480039a5df8ebf1e807dd4ad2cb2219c45217616eff352d1d348 SHA512 1a1bdb96c993d785a2b65a190d86d44076aad8420e7e56c4553ad2786d196d41763a6edc9864bd1c456be8e56fc003f20b8e8e640760dd448310e61ef2d05e67
+DIST pytorch-1.4.0_p0.tar.gz 8715711 BLAKE2B 291f0617edd33ac74426889f4cddab4f7a0ee9c023bd20d74f37f1dad3764f332c7c5d344711b82e12c3583941ee511333fbdaf6dc467eb5cf39f1d66beed2c9 SHA512 1ad2b7570de95c2bccacc7993cef9b15af1c5f2c2acb8c5c98baea7d8f498377351ce6f495ed4ba160e5412611d1e89747260c19e3db1e45a91faf2ec1e520b3
+DIST sleef-7f523de6.tar.gz 1174007 BLAKE2B 58ebdddea912c841a4d917111d81051860631e93abbed43fb9899eff9370181f9227419e87872799a650e6a50cf174d0bf3b90c699a0e0763e903976baf95c9c SHA512 d83b24c34e83b36314344d5b31f1c3b673e38b44bc2d2bbbfdaf2019c3f0e73a83f2d13c6d745ca99d1532c1a3e0fcb4a71bd212e423bec03d610af5dd49e3f3
diff --git a/sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.4.0.patch b/sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.4.0.patch
new file mode 100644
index 000000000..de9fe9a0d
--- /dev/null
+++ b/sci-libs/pytorch/files/0002-Don-t-build-libtorch-again-for-PyTorch-1.4.0.patch
@@ -0,0 +1,30 @@
+From e5003b88ad3a504eb04c0ba66c2f439149de2ee3 Mon Sep 17 00:00:00 2001
+From: Alexey Chernov <4ernov@gmail.com>
+Date: Tue, 5 Nov 2019 00:58:17 +0300
+Subject: [PATCH 2/7] Don't build `libtorch` again for PyTorch
+
+If starting with building of `libtorch` using CMake,
+don't build it again for the sake of running `setup.py`
+to build Python version (PyTorch).
+---
+ setup.py | 7 -------
+ 1 file changed, 7 deletions(-)
+
+Index: pytorch-1.4.0_p0/setup.py
+===================================================================
+--- pytorch-1.4.0_p0.orig/setup.py
++++ pytorch-1.4.0_p0/setup.py
+@@ -303,13 +303,6 @@ def build_deps():
+ check_pydep('yaml', 'pyyaml')
+ check_pydep('typing', 'typing')
+
+- build_caffe2(version=version,
+- cmake_python_library=cmake_python_library,
+- build_python=True,
+- rerun_cmake=RERUN_CMAKE,
+- cmake_only=CMAKE_ONLY,
+- cmake=cmake)
+-
+ version_path = os.path.join(cwd, 'torch', 'version.py')
+ with open(version_path, 'w') as f:
+ f.write("__version__ = '{}'\n".format(version))
diff --git a/sci-libs/pytorch/files/0003-Change-path-to-caffe2-build-dir-made-by-libtorch.patch b/sci-libs/pytorch/files/0003-Change-path-to-caffe2-build-dir-made-by-libtorch.patch
new file mode 100644
index 000000000..f71ba17bc
--- /dev/null
+++ b/sci-libs/pytorch/files/0003-Change-path-to-caffe2-build-dir-made-by-libtorch.patch
@@ -0,0 +1,46 @@
+From dbb0bac77986016217cdfe779499a2ccd0e10570 Mon Sep 17 00:00:00 2001
+From: Alexey Chernov <4ernov@gmail.com>
+Date: Wed, 6 Nov 2019 00:16:24 +0300
+Subject: [PATCH 3/4] Change path to `caffe2` build dir made by `libtorch`
+
+Setup and use properly `caffe2` build dir made while
+`libtorch` building with CMake, so that it was used
+by the Python installation.
+---
+ setup.py | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/setup.py b/setup.py
+index f4bfdc99cd..60502b6add 100644
+--- a/setup.py
++++ b/setup.py
+@@ -236,7 +236,7 @@ else:
+ cwd = os.path.dirname(os.path.abspath(__file__))
+ lib_path = os.path.join(cwd, "torch", "lib")
+ third_party_path = os.path.join(cwd, "third_party")
+-caffe2_build_dir = os.path.join(cwd, "build")
++caffe2_build_dir = os.environ.get("CMAKE_BUILD_DIR", os.path.join(cwd, "build"))
+ # lib/pythonx.x/site-packages
+ rel_site_packages = distutils.sysconfig.get_python_lib(prefix='')
+ # full absolute path to the dir above
+@@ -279,7 +279,7 @@ elif sha != 'Unknown':
+ version += '+' + sha[:7]
+ report("Building wheel {}-{}".format(package_name, version))
+
+-cmake = CMake()
++cmake = CMake(caffe2_build_dir)
+
+ # all the work we need to do _before_ setup runs
+ def build_deps():
+@@ -445,7 +445,7 @@ class build_ext(setuptools.command.build_ext.build_ext):
+ filename = self.get_ext_filename(fullname)
+ report("\nCopying extension {}".format(ext.name))
+
+- src = os.path.join("torch", rel_site_packages, filename)
++ src = os.path.join(caffe2_build_dir, filename)
+ if not os.path.exists(src):
+ report("{} does not exist".format(src))
+ del self.extensions[i]
+--
+2.23.0
+
diff --git a/sci-libs/pytorch/files/0004-Don-t-fill-rpath-of-Caffe2-library-for-system-wide-i.patch b/sci-libs/pytorch/files/0004-Don-t-fill-rpath-of-Caffe2-library-for-system-wide-i.patch
new file mode 100644
index 000000000..c8f57d9e6
--- /dev/null
+++ b/sci-libs/pytorch/files/0004-Don-t-fill-rpath-of-Caffe2-library-for-system-wide-i.patch
@@ -0,0 +1,104 @@
+From a0ace7295b6895954d2a0f8d6fe311a34a7c4e85 Mon Sep 17 00:00:00 2001
+From: Alexey Chernov <4ernov@gmail.com>
+Date: Tue, 12 Nov 2019 02:01:36 +0300
+Subject: [PATCH 4/4] Don't fill rpath of Caffe2 library for system-wide
+ install
+
+Don't fill in runtime path of Caffe2 library for the case of
+building for system-wide installation.
+---
+ CMakeLists.txt | 3 +++
+ caffe2/CMakeLists.txt | 18 +++++++++++++++---
+ cmake/Dependencies.cmake | 19 +++++++++++--------
+ 3 files changed, 29 insertions(+), 11 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 20923c0544..45a882ae0e 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -193,6 +193,9 @@ option(USE_TBB "Use TBB" OFF)
+ # Used when building Caffe2 through setup.py
+ option(BUILDING_WITH_TORCH_LIBS "Tell cmake if Caffe2 is being built alongside torch libs" ON)
+
++# Used when building Caffe2 for further system-wide installation
++option(BUILDING_SYSTEM_WIDE "Tell cmake if Caffe2 is being built for system-wide installation" OFF)
++
+ # /Z7 override option
+ # When generating debug symbols, CMake default to use the flag /Zi.
+ # However, it is not compatible with sccache. So we rewrite it off.
+diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
+index 1f7d037243..30d5615cdb 100644
+--- a/caffe2/CMakeLists.txt
++++ b/caffe2/CMakeLists.txt
+@@ -1235,7 +1235,11 @@ if (BUILD_PYTHON)
+ if (MSVC AND BUILD_SHARED_LIBS)
+ install(FILES $<TARGET_PDB_FILE:caffe2_pybind11_state> DESTINATION "${PYTHON_LIB_REL_PATH}/caffe2/python" OPTIONAL)
+ endif()
+- set_target_properties(caffe2_pybind11_state PROPERTIES INSTALL_RPATH "${caffe2_pybind11_rpath}")
++ if (NOT BUILDING_SYSTEM_WIDE)
++ set_target_properties(caffe2_pybind11_state PROPERTIES INSTALL_RPATH "${caffe2_pybind11_rpath}")
++else()
++ set_target_properties(caffe2_pybind11_state PROPERTIES SKIP_BUILD_RPATH ON)
++ endif()
+
+ if(USE_CUDA)
+ add_library(caffe2_pybind11_state_gpu MODULE ${Caffe2_GPU_PYTHON_SRCS})
+@@ -1261,7 +1265,11 @@ if (BUILD_PYTHON)
+ if (MSVC AND BUILD_SHARED_LIBS)
+ install(FILES $<TARGET_PDB_FILE:caffe2_pybind11_state_gpu> DESTINATION "${PYTHON_LIB_REL_PATH}/caffe2/python" OPTIONAL)
+ endif()
+- set_target_properties(caffe2_pybind11_state_gpu PROPERTIES INSTALL_RPATH "${caffe2_pybind11_rpath}")
++ if (NOT BUILDING_SYSTEM_WIDE)
++ set_target_properties(caffe2_pybind11_state_gpu PROPERTIES INSTALL_RPATH "${caffe2_pybind11_rpath}")
++ else()
++ set_target_properties(caffe2_pybind11_state_gpu PROPERTIES SKIP_BUILD_RPATH ON)
++ endif()
+ endif()
+
+ if(USE_ROCM)
+@@ -1284,7 +1292,11 @@ if (BUILD_PYTHON)
+ caffe2_pybind11_state_hip PROPERTIES LIBRARY_OUTPUT_DIRECTORY
+ ${CMAKE_BINARY_DIR}/caffe2/python)
+ install(TARGETS caffe2_pybind11_state_hip DESTINATION "${PYTHON_LIB_REL_PATH}/caffe2/python")
+- set_target_properties(caffe2_pybind11_state_hip PROPERTIES INSTALL_RPATH "${caffe2_pybind11_rpath}")
++ if (NOT BUILDING_SYSTEM_WIDE)
++ set_target_properties(caffe2_pybind11_state_hip PROPERTIES INSTALL_RPATH "${caffe2_pybind11_rpath}")
++ else()
++ set_target_properties(caffe2_pybind11_state_hip PROPERTIES SKIP_BUILD_RPATH ON)
++ endif()
+ endif()
+
+ if (MSVC AND CMAKE_GENERATOR MATCHES "Visual Studio")
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index a8e9769536..6ef9d7b0e2 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -6,14 +6,17 @@ if (APPLE)
+ else()
+ set(_rpath_portable_origin $ORIGIN)
+ endif(APPLE)
+-# Use separate rpaths during build and install phases
+-set(CMAKE_SKIP_BUILD_RPATH FALSE)
+-# Don't use the install-rpath during the build phase
+-set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+-set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}")
+-# Automatically add all linked folders that are NOT in the build directory to
+-# the rpath (per library?)
+-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
++
++if (NOT BUILDING_SYSTEM_WIDE)
++ # Use separate rpaths during build and install phases
++ set(CMAKE_SKIP_BUILD_RPATH FALSE)
++ # Don't use the install-rpath during the build phase
++ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
++ set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}")
++ # Automatically add all linked folders that are NOT in the build directory to
++ # the rpath (per library?)
++ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
++endif()
+
+ # UBSAN triggers when compiling protobuf, so we need to disable it.
+ set(UBSAN_FLAG "-fsanitize=undefined")
+--
+2.23.0
+
diff --git a/sci-libs/pytorch/files/0005-Change-library-directory-according-to-CMake-build.patch b/sci-libs/pytorch/files/0005-Change-library-directory-according-to-CMake-build.patch
new file mode 100644
index 000000000..324b8f682
--- /dev/null
+++ b/sci-libs/pytorch/files/0005-Change-library-directory-according-to-CMake-build.patch
@@ -0,0 +1,31 @@
+From 52019a3f395e5fa97b26d424152d91f73b400f8e Mon Sep 17 00:00:00 2001
+From: Alexey Chernov <4ernov@gmail.com>
+Date: Wed, 13 Nov 2019 23:44:12 +0300
+Subject: [PATCH 5/5] Change library directory according to CMake build
+
+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
+@@ -234,9 +234,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.environ.get("CMAKE_BUILD_DIR", os.path.join(cwd, "build"))
++caffe2_build_dir = cmake_build_dir
+ # lib/pythonx.x/site-packages
+ rel_site_packages = distutils.sysconfig.get_python_lib(prefix='')
+ # full absolute path to the dir above
+--
+2.23.0
+
diff --git a/sci-libs/pytorch/files/0010-Remove-conversion-ambiguity-in-ternary-operators.patch b/sci-libs/pytorch/files/0010-Remove-conversion-ambiguity-in-ternary-operators.patch
new file mode 100644
index 000000000..49835d201
--- /dev/null
+++ b/sci-libs/pytorch/files/0010-Remove-conversion-ambiguity-in-ternary-operators.patch
@@ -0,0 +1,38 @@
+From 0f3a0d9a948fdd8481a5f7751a255ecd9ed4d37a Mon Sep 17 00:00:00 2001
+From: Alexey Chernov <4ernov@gmail.com>
+Date: Mon, 20 Jan 2020 01:21:22 +0300
+Subject: [PATCH 3/3] Remove conversion ambiguity in ternary operators
+
+It fails to compile with recent versions of Clang
+(namely, version 10 used behind HCC compiler when
+being built with ROCm support) with the
+`conditional expression is ambiguous` error.
+---
+ caffe2/operators/relu_op.cu | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/caffe2/operators/relu_op.cu b/caffe2/operators/relu_op.cu
+index f6edf7105e..ab49540fc9 100644
+--- a/caffe2/operators/relu_op.cu
++++ b/caffe2/operators/relu_op.cu
+@@ -51,7 +51,7 @@ __global__ void ReluCUDAKernel<half2>(const int N, const half2* X, half2* Y) {
+ #else
+ const float2 xx = __half22float2(X[i]);
+ Y[i] =
+- __floats2half2_rn(xx.x > 0.0f ? xx.x : 0.0f, xx.y > 0.0f ? xx.y : 0.0f);
++ __floats2half2_rn(xx.x > 0.0f ? float(xx.x) : 0.0f, xx.y > 0.0f ? float(xx.y) : 0.0f);
+ #endif
+ }
+ }
+@@ -101,7 +101,7 @@ __global__ void ReluGradientCUDAKernel<half2>(
+ const float2 dy = __half22float2(dY[i]);
+ const float2 yy = __half22float2(Y[i]);
+ dX[i] =
+- __floats2half2_rn(yy.x > 0.0f ? dy.x : 0.0f, yy.y > 0.0f ? dy.y : 0.0f);
++ __floats2half2_rn(yy.x > 0.0f ? float(dy.x) : 0.0f, yy.y > 0.0f ? float(dy.y) : 0.0f);
+ #endif
+ }
+ }
+--
+2.24.1
+
diff --git a/sci-libs/pytorch/files/pytorch-1.2.0-setup.patch b/sci-libs/pytorch/files/pytorch-1.2.0-setup.patch
new file mode 100644
index 000000000..85e796a60
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.2.0-setup.patch
@@ -0,0 +1,24 @@
+Index: pytorch-1.4.0_p0/setup.py
+===================================================================
+--- pytorch-1.4.0_p0.orig/setup.py
++++ pytorch-1.4.0_p0/setup.py
+@@ -288,9 +288,7 @@ def build_deps():
+ sys.exit(1)
+
+ check_file(os.path.join(third_party_path, "gloo", "CMakeLists.txt"))
+- check_file(os.path.join(third_party_path, "pybind11", "CMakeLists.txt"))
+ check_file(os.path.join(third_party_path, 'cpuinfo', 'CMakeLists.txt'))
+- check_file(os.path.join(third_party_path, 'tbb', 'Makefile'))
+ check_file(os.path.join(third_party_path, 'onnx', 'CMakeLists.txt'))
+ check_file(os.path.join(third_party_path, 'foxi', 'CMakeLists.txt'))
+ check_file(os.path.join(third_party_path, 'QNNPACK', 'CMakeLists.txt'))
+@@ -341,9 +339,6 @@ def build_deps():
+ if not same:
+ shutil.copyfile(orig_file, sym_file)
+
+- dir_util.copy_tree('third_party/pybind11/include/pybind11/',
+- 'torch/include/pybind11')
+-
+ ################################################################################
+ # Building dependent libraries
+ ################################################################################
diff --git a/sci-libs/pytorch/files/pytorch-1.4.0-eigen.patch b/sci-libs/pytorch/files/pytorch-1.4.0-eigen.patch
new file mode 100644
index 000000000..54ea3a5e0
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.4.0-eigen.patch
@@ -0,0 +1,13 @@
+Index: pytorch-1.4.0/CMakeLists.txt
+===================================================================
+--- pytorch-1.4.0.orig/CMakeLists.txt
++++ pytorch-1.4.0/CMakeLists.txt
+@@ -173,7 +173,7 @@ option(USE_REDIS "Use Redis" OFF)
+ option(USE_ROCKSDB "Use RocksDB" OFF)
+ option(USE_SNPE "Use Qualcomm's SNPE library" OFF)
+ option(USE_SYSTEM_EIGEN_INSTALL
+- "Use system Eigen instead of the one under third_party" OFF)
++ "Use system Eigen instead of the one under third_party" ON)
+ option(USE_TENSORRT "Using Nvidia TensorRT library" OFF)
+ option(USE_ZMQ "Use ZMQ" OFF)
+ option(USE_ZSTD "Use ZSTD" OFF)
diff --git a/sci-libs/pytorch/files/pytorch-1.4.0-nccl-nvccflags.patch b/sci-libs/pytorch/files/pytorch-1.4.0-nccl-nvccflags.patch
new file mode 100644
index 000000000..165e79dd4
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.4.0-nccl-nvccflags.patch
@@ -0,0 +1,28 @@
+Index: nccl-7c72dee660e4d055b81721dd6b03e4e1c0a983cf/makefiles/common.mk
+===================================================================
+--- nccl-7c72dee660e4d055b81721dd6b03e4e1c0a983cf.orig/makefiles/common.mk
++++ nccl-7c72dee660e4d055b81721dd6b03e4e1c0a983cf/makefiles/common.mk
+@@ -46,7 +46,7 @@ endif
+ CXXFLAGS := -DCUDA_MAJOR=$(CUDA_MAJOR) -DCUDA_MINOR=$(CUDA_MINOR) -fPIC -fvisibility=hidden
+ CXXFLAGS += -Wall -Wno-unused-function -Wno-sign-compare -std=c++11 -Wvla
+ CXXFLAGS += -I $(CUDA_INC)
+-NVCUFLAGS := -ccbin $(CXX) $(NVCC_GENCODE) -lineinfo -std=c++11 -Xptxas -maxrregcount=96 -Xfatbin -compress-all
++NVCUFLAGS := $(NVCCFLAGS) $(NVCC_GENCODE) -lineinfo -std=c++11 -Xptxas -maxrregcount=96 -Xfatbin -compress-all
+ # Use addprefix so that we can specify more than one path
+ NVLDFLAGS := -L${CUDA_LIB} -lcudart -lrt
+
+@@ -60,14 +60,6 @@ NVLDFLAGS += ${GCOV_FLAGS:%=-Xcompiler
+ # $(warning GCOV_FLAGS=${GCOV_FLAGS})
+ ########## GCOV ##########
+
+-ifeq ($(DEBUG), 0)
+-NVCUFLAGS += -O3
+-CXXFLAGS += -O3 -g
+-else
+-NVCUFLAGS += -O0 -G -g
+-CXXFLAGS += -O0 -g -ggdb3
+-endif
+-
+ ifneq ($(VERBOSE), 0)
+ NVCUFLAGS += -Xptxas -v -Xcompiler -Wall,-Wextra,-Wno-unused-parameter
+ CXXFLAGS += -Wall -Wextra
diff --git a/sci-libs/pytorch/files/pytorch-1.4.0-skip-tests.patch b/sci-libs/pytorch/files/pytorch-1.4.0-skip-tests.patch
new file mode 100644
index 000000000..3682469d7
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.4.0-skip-tests.patch
@@ -0,0 +1,28 @@
+Disable expected test failures.
+
+TCPStoreTest is too slow to run.
+
+Reference: https://github.com/pytorch/pytorch/issues/13746
+Reference: https://github.com/pytorch/pytorch/issues/21873
+
+Index: pytorch-1.4.0_p0/torch/lib/c10d/test/CMakeLists.txt
+===================================================================
+--- pytorch-1.4.0_p0.orig/torch/lib/c10d/test/CMakeLists.txt
++++ pytorch-1.4.0_p0/torch/lib/c10d/test/CMakeLists.txt
+@@ -14,7 +14,6 @@ function(c10d_add_test test_src)
+ endfunction()
+
+ c10d_add_test(FileStoreTest.cpp c10d)
+-c10d_add_test(TCPStoreTest.cpp c10d)
+
+ if(USE_CUDA)
+ if(USE_C10D_GLOO)
+Index: pytorch-1.4.0_p0/caffe2/share/contrib/depthwise/CMakeLists.txt
+===================================================================
+--- pytorch-1.4.0_p0.orig/caffe2/share/contrib/depthwise/CMakeLists.txt
++++ pytorch-1.4.0_p0/caffe2/share/contrib/depthwise/CMakeLists.txt
+@@ -6,4 +6,3 @@ set(Caffe2_CONTRIB_DEPTHWISE3x3_TEST_CPU
+ )
+
+ set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS} ${Caffe2_CONTRIB_DEPTHWISE3x3_CPU_SRC} PARENT_SCOPE)
+-set(Caffe2_CPU_TEST_SRCS ${Caffe2_CPU_TEST_SRCS} ${Caffe2_CONTRIB_DEPTHWISE3x3_TEST_CPU_SRC} PARENT_SCOPE)
diff --git a/sci-libs/pytorch/files/pytorch-1.4.0-sleef.patch b/sci-libs/pytorch/files/pytorch-1.4.0-sleef.patch
new file mode 100644
index 000000000..222a0f73e
--- /dev/null
+++ b/sci-libs/pytorch/files/pytorch-1.4.0-sleef.patch
@@ -0,0 +1,15 @@
+Give the location of sleef.h.
+
+Reference: https://github.com/pytorch/pytorch/issues/26555
+Index: pytorch-1.4.0/caffe2/CMakeLists.txt
+===================================================================
+--- pytorch-1.4.0.orig/caffe2/CMakeLists.txt
++++ pytorch-1.4.0/caffe2/CMakeLists.txt
+@@ -1062,6 +1062,7 @@ if (BUILD_TEST)
+ add_executable(${test_name} "${test_src}")
+ target_link_libraries(${test_name} ${Caffe2_MAIN_LIBS} gtest_main)
+ target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
++ target_include_directories(${test_name} PRIVATE $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
+ target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE})
+ add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
+ if (INSTALL_TEST)
diff --git a/sci-libs/pytorch/metadata.xml b/sci-libs/pytorch/metadata.xml
new file mode 100644
index 000000000..78e46cc35
--- /dev/null
+++ b/sci-libs/pytorch/metadata.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="person">
+ <email>4ernov@gmail.com</email>
+ <name>Alexey Chernov</name>
+ </maintainer>
+ <use>
+ <flag name="asan">Build with address sanitizer (ASAN)</flag>
+ <flag name="atlas">Use ATLAS as BLAS implementation</flag>
+ <flag name="cuda">Enable support for nVidia CUDA</flag>
+ <flag name="eigen">Use Eigen as BLAS implementation</flag>
+ <flag name="fbgemm">Enable FBGEMM (Facebook GEneral Matrix Multiplication) support</flag>
+ <flag name="gflags">Build with gflags</flag>
+ <flag name="glog">Build with glog support</flag>
+ <flag name="gloo">Build gloo distributed communication backend support</flag>
+ <flag name="leveldb">Enable support for LevelDB</flag>
+ <flag name="lmdb">Enable support for LMDB</flag>
+ <flag name="mkl">Use Intel MKL as BLAS implementation</flag>
+ <flag name="mkldnn">Build with Intel MKL-DNN support</flag>
+ <flag name="namedtensor">Enable support for named tensors</flag>
+ <flag name="nnpack">Enable NNPACK support</flag>
+ <flag name="numa">Enable support for NUMA</flag>
+ <flag name="numpy">Enable NumPy support</flag>
+ <flag name="observers">Build observers</flag>
+ <flag name="openblas">Use OpenBLAS as BLAS implementation</flag>
+ <flag name="opencv">Enable support for OpenCV</flag>
+ <flag name="opencl">Enable support for OpenCL</flag>
+ <flag name="qnnpack">Enable QNNPACK support</flag>
+ <flag name="redis">Enable support for Redis</flag>
+ <flag name="tbb">Build with Intel TBB enabled</flag>
+ <flag name="tools">Build binary tools</flag>
+ <flag name="zeromq">Enable support for ZeroMQ</flag>
+ </use>
+</pkgmetadata>
diff --git a/sci-libs/pytorch/pytorch-1.4.0_p0.ebuild b/sci-libs/pytorch/pytorch-1.4.0_p0.ebuild
new file mode 100644
index 000000000..06ee528f2
--- /dev/null
+++ b/sci-libs/pytorch/pytorch-1.4.0_p0.ebuild
@@ -0,0 +1,272 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+PYTHON_COMPAT=( python3_6 )
+
+inherit distutils-r1 cmake-utils cuda
+
+MPV=${PV/_p/a}
+
+DESCRIPTION="Tensors and Dynamic neural networks in Python with strong GPU acceleration"
+HOMEPAGE="https://pytorch.org/"
+SRC_URI="https://github.com/pytorch/${PN}/archive/v${MPV}.tar.gz -> ${P}.tar.gz
+https://github.com/facebookincubator/gloo/archive/ca528e32.tar.gz -> gloo-ca528e32.tar.gz
+https://github.com/google/benchmark/archive/505be96a.tar.gz -> benchmark-505be96a.tar.gz
+https://github.com/google/gemmlowp/archive/3fb5c176.tar.gz -> gemmlowp-3fb5c176.tar.gz
+https://github.com/google/googletest/archive/2fe3bd99.tar.gz -> googletest-2fe3bd99.tar.gz
+https://github.com/houseroad/foxi/archive/8f74bc4d.tar.gz -> foxi-8f74bc4d.tar.gz
+https://github.com/intel/ideep/archive/78eafa5d.tar.gz -> ideep-78eafa5d.tar.gz
+https://github.com/Maratyszcza/FP16/archive/febbb1c1.tar.gz -> FP16-febbb1c1.tar.gz
+https://github.com/Maratyszcza/FXdiv/archive/b742d114.tar.gz -> FXdiv-b742d114.tar.gz
+https://github.com/Maratyszcza/NNPACK/archive/c039579a.tar.gz -> NNPACK-c039579a.tar.gz
+https://github.com/Maratyszcza/PeachPy/archive/07d8fde8.tar.gz -> PeachPy-07d8fde8.tar.gz
+https://github.com/Maratyszcza/psimd/archive/90a938f3.tar.gz -> psimd-90a938f3.tar.gz
+https://github.com/Maratyszcza/pthreadpool/archive/13da0b4c.tar.gz -> pthreadpool-13da0b4c.tar.gz
+cuda? ( https://github.com/NVIDIA/nccl/archive/7c72dee6.tar.gz -> nccl-7c72dee6.tar.gz )
+https://github.com/NVlabs/cub/archive/285aeeba.tar.gz -> cub-285aeeba.tar.gz
+https://github.com/onnx/onnx/archive/2891e145.tar.gz -> onnx-2891e145.tar.gz
+https://github.com/onnx/onnx-tensorrt/archive/cb3d8066.tar.gz -> onnx-tensorrt-cb3d8066.tar.gz
+https://github.com/pytorch/cpuinfo/archive/89fe1695.tar.gz -> cpuinfo-89fe1695.tar.gz
+https://github.com/pytorch/fbgemm/archive/82d259da.tar.gz -> fbgemm-82d259da.tar.gz
+https://github.com/pytorch/QNNPACK/archive/7d2a4e99.tar.gz -> QNNPACK-7d2a4e99.tar.gz
+https://github.com/shibatch/sleef/archive/7f523de6.tar.gz -> sleef-7f523de6.tar.gz
+https://github.com/asmjit/asmjit/archive/17556b2d.tar.gz -> asmjit-17556b2d.tar.gz
+ "
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~amd64"
+
+IUSE="asan atlas cuda doc eigen +fbgemm ffmpeg gflags glog +gloo leveldb lmdb mkl mkldnn mpi namedtensor +nnpack numa +numpy +observers +openblas opencl opencv +openmp +python +qnnpack redis static tbb test tools zeromq"
+
+REQUIRED_USE="
+ python? ( ${PYTHON_REQUIRED_USE} )
+ numpy? ( python )
+ ^^ ( atlas eigen mkl openblas )
+"
+
+DEPEND="
+ dev-libs/protobuf
+ dev-python/pyyaml[${PYTHON_USEDEP}]
+ virtual/python-typing[${PYTHON_USEDEP}]
+ atlas? ( sci-libs/atlas )
+ cuda? ( dev-util/nvidia-cuda-toolkit:0= )
+ doc? ( dev-python/pytorch-sphinx-theme[${PYTHON_USEDEP}] )
+ ffmpeg? ( virtual/ffmpeg )
+ gflags? ( dev-cpp/gflags )
+ glog? ( dev-cpp/glog )
+ leveldb? ( dev-libs/leveldb )
+ lmdb? ( dev-db/lmdb )
+ mkl? ( sci-libs/mkl )
+ mpi? ( virtual/mpi )
+ numpy? ( dev-python/numpy[${PYTHON_USEDEP}] )
+ openblas? ( sci-libs/openblas )
+ opencl? ( dev-libs/clhpp virtual/opencl )
+ opencv? ( media-libs/opencv )
+ python? ( ${PYTHON_DEPS}
+ dev-python/pybind11[${PYTHON_USEDEP}]
+ )
+ redis? ( dev-db/redis )
+ zeromq? ( net-libs/zeromq )
+ eigen? ( dev-cpp/eigen
+ cuda? ( dev-cpp/eigen[cuda] ) )
+"
+RDEPEND="${DEPEND}"
+BDEPEND="
+ doc? ( app-doc/doxygen )
+"
+
+DEPEND="
+ test? ( dev-python/pytest[${PYTHON_USEDEP}] )
+ dev-python/setuptools[${PYTHON_USEDEP}]
+ dev-cpp/tbb
+ app-arch/zstd
+ dev-python/protobuf-python[${PYTHON_USEDEP}]
+ dev-python/pybind11[${PYTHON_USEDEP}]
+ sys-fabric/libibverbs
+ sys-process/numactl
+"
+
+PATCHES=(
+ "${FILESDIR}"/${PN}-1.2.0-setup.patch
+ "${FILESDIR}"/${PN}-1.4.0-eigen.patch
+ "${FILESDIR}"/${PN}-1.4.0-sleef.patch
+ "${FILESDIR}"/${PN}-1.4.0-skip-tests.patch
+ "${FILESDIR}"/0002-Don-t-build-libtorch-again-for-PyTorch-1.4.0.patch
+ "${FILESDIR}"/0003-Change-path-to-caffe2-build-dir-made-by-libtorch.patch
+ "${FILESDIR}"/0005-Change-library-directory-according-to-CMake-build.patch
+)
+
+src_unpack() {
+ default
+
+ mv -v ${PN}-${MPV} ${P} || die
+}
+
+src_prepare() {
+ cmake-utils_src_prepare
+
+ mv -v third_party/miniz-* ../ || die
+ rm -r third_party || die
+ ln -s .. third_party || die
+ cd .. || die
+ for d in *; do
+ case ${d} in
+ ${PN}* | miniz-*) continue ;;
+ PeachPy-*) mv -v ${d} python-peachpy || die ;;
+ *) mv -v ${d} ${d%-*} || die ;;
+ esac
+ done
+
+ mv -v FBGEMM fbgemm || die
+ cd fbgemm || die
+ rm -r third_party || die
+ ln -s .. third_party || die
+
+ cd ../onnx || die
+ rm -r third_party || die
+ ln -s .. third_party || die
+
+ if use cuda; then
+ cd ../nccl || die
+ eapply "${FILESDIR}"/${PN}-1.4.0-nccl-nvccflags.patch
+ ln -s . nccl || die
+
+ cuda_src_prepare
+ export CUDAHOSTCXX=$(cuda_gccdir)/g++
+ fi
+}
+
+src_configure() {
+ local blas="Eigen"
+
+ if use atlas; then
+ blas="ATLAS"
+ elif use mkl; then
+ blas="MKL"
+ elif use openblas; then
+ blas="OpenBLAS"
+ fi
+
+ local mycmakeargs=(
+ -DTORCH_BUILD_VERSION=${PV}
+ -DTORCH_INSTALL_LIB_DIR=$(get_libdir)
+ -DBUILD_BINARY=$(usex tools ON OFF)
+ -DBUILD_CUSTOM_PROTOBUF=OFF
+ -DBUILD_DOCS=$(usex doc ON OFF)
+ -DBUILD_PYTHON=$(usex python ON OFF)
+ -DBUILD_SHARED_LIBS=$(usex static OFF ON)
+ -DBUILD_TEST=$(usex test ON OFF)
+ -DUSE_ASAN=$(usex asan ON OFF)
+ -DUSE_CUDA=$(usex cuda ON OFF)
+ -DUSE_NCCL=$(usex cuda ON OFF)
+ -DUSE_ROCM=OFF
+ -DUSE_FBGEMM=$(usex fbgemm ON OFF)
+ -DUSE_FFMPEG=$(usex ffmpeg ON OFF)
+ -DUSE_GFLAGS=$(usex gflags ON OFF)
+ -DUSE_GLOG=$(usex glog ON OFF)
+ -DUSE_LEVELDB=$(usex leveldb ON OFF)
+ -DUSE_LITE_PROTO=OFF
+ -DUSE_LMDB=$(usex lmdb ON OFF)
+ -DCAFFE2_USE_MKL=$(usex mkl ON OFF)
+ -DUSE_MKLDNN=$(usex mkldnn ON OFF)
+ -DUSE_MKLDNN_CBLAS=OFF
+ -DUSE_NCCL=OFF
+ -DUSE_NNPACK=$(usex nnpack ON OFF)
+ -DUSE_NUMPY=$(usex numpy ON OFF)
+ -DUSE_NUMA=$(usex numa ON OFF)
+ -DUSE_OBSERVERS=$(usex observers ON OFF)
+ -DUSE_OPENCL=$(usex opencl ON OFF)
+ -DUSE_OPENCV=$(usex opencv ON OFF)
+ -DUSE_OPENMP=$(usex openmp ON OFF)
+ -DUSE_TBB=OFF
+ -DUSE_PROF=OFF
+ -DUSE_QNNPACK=$(usex qnnpack ON OFF)
+ -DUSE_REDIS=$(usex redis ON OFF)
+ -DUSE_ROCKSDB=OFF
+ -DUSE_ZMQ=$(usex zeromq ON OFF)
+ -DUSE_MPI=$(usex mpi ON OFF)
+ -DUSE_GLOO=$(usex gloo ON OFF)
+ -DBUILD_NAMEDTENSOR=$(usex namedtensor ON OFF)
+ -DBLAS=${blas}
+ -DBUILDING_SYSTEM_WIDE=ON # to remove insecure DT_RUNPATH header
+ )
+
+ cmake-utils_src_configure
+
+ if use python; then
+ CMAKE_BUILD_DIR=${BUILD_DIR} distutils-r1_src_configure
+ fi
+}
+
+src_compile() {
+ cmake-utils_src_compile
+
+ if use python; then
+ CMAKE_BUILD_DIR=${BUILD_DIR} distutils-r1_src_compile
+ fi
+}
+
+src_install() {
+ cmake-utils_src_install
+
+ local multilib_failing_files=(
+ libc10.so
+ libtbb.so
+ libcaffe2_observers.so
+ libshm.so
+ libcaffe2_detectron_ops.so
+ )
+
+ local LIB=$(get_libdir)
+ if [[ ${LIB} != lib ]]; then
+ for file in ${multilib_failing_files[@]}; do
+ mv -fv "${ED}/usr/lib/$file" "${ED}/usr/${LIB}"
+ done
+ fi
+
+ rm -rfv "${ED}/torch"
+ rm -rfv "${ED}/var"
+ rm -rfv "${ED}/usr/lib"
+
+ rm -fv "${ED}/usr/include/*.{h,hpp}"
+ rm -rfv "${ED}/usr/include/asmjit"
+ rm -rfv "${ED}/usr/include/c10d"
+ rm -rfv "${ED}/usr/include/fbgemm"
+ rm -rfv "${ED}/usr/include/fp16"
+ rm -rfv "${ED}/usr/include/gloo"
+ rm -rfv "${ED}/usr/include/include"
+ rm -rfv "${ED}/usr/include/var"
+
+ cp -rv "${WORKDIR}/${P}/third_party/pybind11/include/pybind11" "${ED}/usr/include/"
+
+ rm -fv "${ED}/usr/lib64/libtbb.so"
+ rm -rfv "${ED}/usr/lib64/cmake"
+
+ rm -rfv "${ED}/usr/share/doc/mkldnn"
+
+ if use python; then
+ install_shm_manager() {
+ TORCH_BIN_DIR="${ED}/usr/lib64/${EPYTHON}/site-packages/torch/bin"
+
+ mkdir -pv ${TORCH_BIN_DIR}
+ cp -v "${ED}/usr/bin/torch_shm_manager" "${TORCH_BIN_DIR}"
+ }
+
+ python_foreach_impl install_shm_manager
+
+ scanelf -r --fix "${BUILD_DIR}/caffe2/python"
+ CMAKE_BUILD_DIR=${BUILD_DIR} distutils-r1_src_install
+
+ python_foreach_impl python_optimize
+ fi
+
+ find "${ED}/usr/lib64" -name "*.a" -exec rm -fv {} \;
+
+ use test && rm -rfv "${ED}/usr/test" "${ED}"/usr/bin/test_{api,jit}
+
+ # Remove the empty directories by CMake Python:
+ find "${ED}" -type d -empty -delete || die
+}