commit: 5eaadaa18765311254b697c1a5eafc9972e42b44 Author: Sv. Lockal <lockalsash <AT> gmail <DOT> com> AuthorDate: Sun Nov 9 12:13:24 2025 +0000 Commit: Alfredo Tupone <tupone <AT> gentoo <DOT> org> CommitDate: Mon Nov 10 07:37:20 2025 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5eaadaa1
sci-ml/gloo: add support of AMD GPUs (USE=rocm) and fix cuda There is a chicken-egg build dependency between gloo and pytorch. To build with GLOO_USE_TORCH_DTYPES, few pytorch headers are required. So instead of this: 1) USE=-gloo emerge caffe2 2) emerge gloo 3) USE=gloo emerge caffe2 gloo ebuild now includes some (2.9.0) version of caffe2 just for headers Closes: https://bugs.gentoo.org/965091 Signed-off-by: Sv. Lockal <lockalsash <AT> gmail.com> Part-of: https://github.com/gentoo/gentoo/pull/44550 Signed-off-by: Alfredo Tupone <tupone <AT> gentoo.org> sci-ml/gloo/Manifest | 1 + sci-ml/gloo/files/gloo-2025.06.04-gentoo.patch | 102 +++++++++++++-------- ...5.06.04-r1.ebuild => gloo-2025.06.04-r2.ebuild} | 41 +++++++-- sci-ml/gloo/metadata.xml | 1 + 4 files changed, 99 insertions(+), 46 deletions(-) diff --git a/sci-ml/gloo/Manifest b/sci-ml/gloo/Manifest index 5fef42a9228a..1993d7768c61 100644 --- a/sci-ml/gloo/Manifest +++ b/sci-ml/gloo/Manifest @@ -1,2 +1,3 @@ DIST gloo-2023.12.03.tar.gz 259857 BLAKE2B b56cbbb0986b70ed327a8d019f140099c5d1d725576120089cd5e640dc42daa6c6bb67de877d540fd2160f5b8d89cf54af7c11a1b81039e62e4de97daa4f63d6 SHA512 597679dd96394e7d0009be34ef9bd6f8446d22e2faa006c0853e055caf0d6d821c7532ff867b4d924197e92ab53c4c7ee9b74f897d6c5a469ee797c11ce0d28d DIST gloo-2025.06.04.tar.gz 272417 BLAKE2B f3cf3326276bb839166f3094d49fcd537e5a446bda65fb34adad5540df4c505bf7f7f56071d78d14cbc49db6d02f190198e45dd25ae307cfbc5d27db4c2c3703 SHA512 87264b940f2a9f50f3054d3853ad3c0aff33c29253e27c4d0e5fc18a674ebb362719a811b01847daaadf0b9a151a51eabd9dae694ac7d1ad300e24842bea1241 +DIST pytorch-2.9.0.tar.gz 55750268 BLAKE2B 943459ec60a4e1f5e36766defc7018fbf9722fb1564b723c2a7ebcb2a5d8b1735f0b1542dc67a77f788af3e2454ea6261dbdee5beb2bcfa4af2e58ca566edc93 SHA512 2ecdc0eac39ecee68b0f4c98e498424cde00c45bbeeff576c8778046f97119cd02885498b072352dd3cdd9aecd02baf61cdc5554bce8d757b30c673053a0cc80 diff --git a/sci-ml/gloo/files/gloo-2025.06.04-gentoo.patch b/sci-ml/gloo/files/gloo-2025.06.04-gentoo.patch index 120eb467bb0f..c74ed8a3c8b6 100644 --- a/sci-ml/gloo/files/gloo-2025.06.04-gentoo.patch +++ b/sci-ml/gloo/files/gloo-2025.06.04-gentoo.patch @@ -1,6 +1,6 @@ ---- a/CMakeLists.txt 2022-06-09 08:29:13.172119535 +0200 -+++ b/CMakeLists.txt 2022-06-09 08:29:27.474929097 +0200 -@@ -2,6 +2,9 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.18 FATAL_ERROR) project(gloo CXX C) @@ -10,27 +10,9 @@ set(GLOO_VERSION_MAJOR 0) set(GLOO_VERSION_MINOR 5) set(GLOO_VERSION_PATCH 0) ---- a/gloo/CMakeLists.txt 2022-06-09 08:41:09.883773600 +0200 -+++ b/gloo/CMakeLists.txt 2022-06-09 08:42:39.045637103 +0200 -@@ -191,7 +191,7 @@ - # want to statically link with Gloo and not install any artifacts. - if(GLOO_INSTALL) - install(TARGETS gloo EXPORT GlooTargets -- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) -+ DESTINATION ${CMAKE_INSTALL_LIBDIR}) - if(USE_CUDA) - install(TARGETS gloo_cuda EXPORT GlooTargets - DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) ---- a/gloo/test/CMakeLists.txt 2022-06-10 22:17:03.682856314 +0200 -+++ b/gloo/test/CMakeLists.txt 2022-06-10 22:17:49.671242697 +0200 -@@ -80,3 +80,4 @@ - gloo_hip_add_executable(gloo_test_hip ${GLOO_TEST_HIP_SRCS}) - target_link_libraries(gloo_test_hip gloo_hip gtest OpenSSL::SSL OpenSSL::Crypto) - endif() -+add_test(NAME gloo_test COMMAND gloo_test) ---- a/cmake/Dependencies.cmake 2022-06-11 23:38:57.367089917 +0200 -+++ b/cmake/Dependencies.cmake 2022-06-11 23:48:57.690866797 +0200 -@@ -81,7 +81,7 @@ +--- a/cmake/Dependencies.cmake ++++ b/cmake/Dependencies.cmake +@@ -81,7 +81,7 @@ if(USE_LIBUV) pkg_search_module(libuv REQUIRED libuv>=1.26) find_file( libuv_LIBRARY @@ -39,7 +21,7 @@ PATHS ${libuv_LIBDIR} NO_DEFAULT_PATH) if(NOT EXISTS ${libuv_LIBRARY}) -@@ -90,10 +90,7 @@ +@@ -90,10 +90,7 @@ if(USE_LIBUV) endif() add_library(uv_a INTERFACE IMPORTED) @@ -51,19 +33,42 @@ endif() endif() ---- a/gloo/transport/tcp/tls/pair.cc 2022-10-04 21:14:04.099150060 +0200 -+++ b/gloo/transport/tcp/tls/pair.cc 2022-10-04 21:14:22.330886610 +0200 -@@ -17,6 +17,7 @@ - - #include <poll.h> - #include <cstring> -+#include <array> +--- a/gloo/CMakeLists.txt ++++ b/gloo/CMakeLists.txt +@@ -191,14 +191,14 @@ endif() + # want to statically link with Gloo and not install any artifacts. + if(GLOO_INSTALL) + install(TARGETS gloo EXPORT GlooTargets +- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}) + if(USE_CUDA) + install(TARGETS gloo_cuda EXPORT GlooTargets +- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + if(USE_ROCM) + install(TARGETS gloo_hip EXPORT GlooTargets +- DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}) + endif() + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/gloo) +@@ -215,11 +215,7 @@ if(GLOO_INSTALL) + endforeach() + endif() + if(USE_ROCM) +- foreach(HEADER ${GLOO_HIP_HDRS}) +- string(REGEX MATCH "(.*)[/\\]" DIR ${HEADER}) +- string(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "gloo" DIR ${DIR}) +- install(FILES ${HEADER} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${DIR}) +- endforeach() ++ install(FILES ${GLOO_HIP_HDRS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/gloo) + endif() + endif() - namespace gloo { - namespace transport { ---- a/gloo/common/linux.cc 2022-10-04 21:20:21.401691929 +0200 -+++ b/gloo/common/linux.cc 2022-10-04 21:23:13.924192100 +0200 -@@ -198,7 +198,7 @@ +--- a/gloo/common/linux.cc ++++ b/gloo/common/linux.cc +@@ -198,7 +198,7 @@ static int getInterfaceSpeedGLinkSettings(int sock, struct ifreq* ifr) { } ecmd; int rv; @@ -72,7 +77,7 @@ memset(&ecmd, 0, sizeof(ecmd)); ecmd.req.cmd = ETHTOOL_GLINKSETTINGS; -@@ -226,7 +226,7 @@ +@@ -226,7 +226,7 @@ static int getInterfaceSpeedGSet(int sock, struct ifreq* ifr) { struct ethtool_cmd edata; int rv; @@ -81,3 +86,24 @@ memset(&edata, 0, sizeof(edata)); edata.cmd = ETHTOOL_GSET; +--- a/gloo/transport/tcp/tls/pair.cc ++++ b/gloo/transport/tcp/tls/pair.cc +@@ -17,6 +17,7 @@ + + #include <poll.h> + #include <cstring> ++#include <array> + + namespace gloo { + namespace transport { +--- a/cmake/Hip.cmake ++++ b/cmake/Hip.cmake +@@ -13,7 +13,7 @@ ELSE() + ENDIF() + + # Add HIP to the CMAKE Module Path +-set(CMAKE_MODULE_PATH ${ROCM_PATH}/lib/cmake/hip ${CMAKE_MODULE_PATH}) ++set(CMAKE_MODULE_PATH ${ROCM_PATH}/${CMAKE_INSTALL_LIBDIR}/cmake/hip ${CMAKE_MODULE_PATH}) + + # Disable Asserts In Code (Can't use asserts on HIP stack.) + ADD_DEFINITIONS(-DNDEBUG) diff --git a/sci-ml/gloo/gloo-2025.06.04-r1.ebuild b/sci-ml/gloo/gloo-2025.06.04-r2.ebuild similarity index 53% rename from sci-ml/gloo/gloo-2025.06.04-r1.ebuild rename to sci-ml/gloo/gloo-2025.06.04-r2.ebuild index 9d06465fb7d1..1b2fed01a890 100644 --- a/sci-ml/gloo/gloo-2025.06.04-r1.ebuild +++ b/sci-ml/gloo/gloo-2025.06.04-r2.ebuild @@ -2,21 +2,31 @@ # Distributed under the terms of the GNU General Public License v2 EAPI=8 -inherit cmake cuda +ROCM_VERSION=6.3 +inherit cmake cuda flag-o-matic rocm CommitId=c7b7b022c124d9643957d9bd55f57ac59fce8fa2 +# Need half/bf16 headers from any pytorch +PYTORCH_PV=2.9.0 +PYTORCH_P=pytorch-${PYTORCH_PV} + DESCRIPTION="library of floating-point neural network inference operators" HOMEPAGE="https://github.com/facebookincubator/gloo/" -SRC_URI="https://github.com/facebookincubator/${PN}/archive/${CommitId}.tar.gz - -> ${P}.tar.gz" +SRC_URI=" + https://github.com/facebookincubator/${PN}/archive/${CommitId}.tar.gz -> ${P}.tar.gz + + cuda? ( https://github.com/pytorch/pytorch/archive/refs/tags/v${PYTORCH_PV}.tar.gz -> ${PYTORCH_P}.tar.gz ) + rocm? ( https://github.com/pytorch/pytorch/archive/refs/tags/v${PYTORCH_PV}.tar.gz -> ${PYTORCH_P}.tar.gz ) +" S="${WORKDIR}"/${PN}-${CommitId} +PYTORCH_S="${WORKDIR}"/${PYTORCH_P} LICENSE="MIT" SLOT="0" KEYWORDS="~amd64" -IUSE="cuda libuv mpi redis ssl test" +IUSE="cuda libuv mpi redis rocm ssl test" RDEPEND=" cuda? ( dev-util/nvidia-cuda-toolkit:= ) @@ -26,6 +36,7 @@ RDEPEND=" dev-db/redis dev-libs/hiredis ) + rocm? ( dev-util/hip:= ) ssl? ( dev-libs/openssl:= ) " DEPEND="${RDEPEND} @@ -37,22 +48,21 @@ RESTRICT="test" # For some test the network is needed PATCHES=( "${FILESDIR}"/${P}-gentoo.patch - "${FILESDIR}"/${PN}-2023.01.17-cuda.patch "${FILESDIR}"/${P}-ssl3.patch "${FILESDIR}"/${PN}-2023.12.03-gcc15.patch ) src_prepare() { - eapply_user + if use cuda || use rocm; then + touch "${PYTORCH_S}"/torch/headeronly/macros/cmake_macros.h || die + fi cmake_src_prepare use cuda && cuda_add_sandbox } src_configure() { local mycmakeargs=( - -DGLOO_USE_TORCH_DTYPES=$(usex cuda ON OFF) -DBUILD_TEST=$(usex test ON OFF) - -DUSE_CUDA=$(usex cuda ON OFF) -DGLOO_USE_CUDA_TOOLKIT=$(usex cuda ON OFF) -DUSE_LIBUV=$(usex libuv ON OFF) -DUSE_MPI=$(usex mpi ON OFF) @@ -64,6 +74,21 @@ src_configure() { mycmakeargs+=( -DCMAKE_CUDA_FLAGS="$(cuda_gccdir -f | tr -d \")" + -DGLOO_TORCH_DIR="${PYTORCH_S}" + -DGLOO_USE_TORCH_DTYPES=ON + -DUSE_CUDA=ON + ) + fi + if use rocm; then + export ROCM_PATH="${EPREFIX}/usr" + export GLOO_ROCM_ARCH="$(get_amdgpu_flags)" + mycmakeargs+=( + -DCMAKE_HIP_ARCHITECTURES="${GLOO_ROCM_ARCH}" + -DCMAKE_REQUIRE_FIND_PACKAGE_HIP=$(usex rocm ON OFF) + -DGLOO_TORCH_DIR="${PYTORCH_S}" + -DHIP_CXX_FLAGS="$(test-flags-HIPCXX ${CXXFLAGS})" + -DGLOO_USE_TORCH_DTYPES=ON + -DUSE_ROCM=ON ) fi cmake_src_configure diff --git a/sci-ml/gloo/metadata.xml b/sci-ml/gloo/metadata.xml index 453b2878b484..3211dff8a6c8 100644 --- a/sci-ml/gloo/metadata.xml +++ b/sci-ml/gloo/metadata.xml @@ -11,5 +11,6 @@ <use> <flag name="libuv">Enable libuv support</flag> <flag name="redis">Enable Redis backend for storage via <pkg>dev-libs/hiredis</pkg></flag> + <flag name="rocm">Enable ROCm gpu computing support</flag> </use> </pkgmetadata>
