public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] repo/gentoo:master commit in: sci-ml/caffe2/files/, sci-ml/caffe2/
@ 2025-04-05 12:55 Alfredo Tupone
  0 siblings, 0 replies; only message in thread
From: Alfredo Tupone @ 2025-04-05 12:55 UTC (permalink / raw
  To: gentoo-commits

commit:     0b45f8a6d7fae82791efe2caf4934b25d6138f4f
Author:     Sv. Lockal <lockalsash <AT> gmail <DOT> com>
AuthorDate: Thu Apr  3 18:54:54 2025 +0000
Commit:     Alfredo Tupone <tupone <AT> gentoo <DOT> org>
CommitDate: Sat Apr  5 12:52:52 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0b45f8a6

sci-ml/caffe2: fix build for ROCm

* Revised the fix for `-fclang-abi-compat=17`.
* Added fixes for libc++

Closes: https://bugs.gentoo.org/953101
Signed-off-by: Sv. Lockal <lockalsash <AT> gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/41448
Signed-off-by: Alfredo Tupone <tupone <AT> gentoo.org>

 sci-ml/caffe2/Manifest                             |  1 +
 ...ffe2-2.6.0-r2.ebuild => caffe2-2.6.0-r3.ebuild} | 64 +++++++++++++---------
 .../files/caffe2-2.6.0-rocm-fix-std-cpp17.patch    | 50 +++++++++++++++++
 3 files changed, 89 insertions(+), 26 deletions(-)

diff --git a/sci-ml/caffe2/Manifest b/sci-ml/caffe2/Manifest
index afeccbf65514..9edc8e9aadc7 100644
--- a/sci-ml/caffe2/Manifest
+++ b/sci-ml/caffe2/Manifest
@@ -1,4 +1,5 @@
 DIST caffe2-patches-20240809.tar.gz 15242 BLAKE2B 77503c61487e7d85cca5afcab9a6e638f9833a70861845638cf1b62bc492d7b6650e6db81d53ebb2f39c6313509250d339f725f04d03ec6dd23dd0cf70843d8c SHA512 74b3b0b6671b655ecac93f7436c4ed7cb0157a83aafbf6afcc0811e11cef341cd8f638db1a111bcbb01e1a6dd4daf3a36b96d7a8ce90f04c2fa091bd6e3a142b
+DIST composable_kernel-50ee4267.tar.gz 4194795 BLAKE2B b3c97d98a0c9e4620fdae3d30006edf55cc60ffa7f8518f6acb8d808647bc4de362c2e2b7e974686503fa2c7f359b6981cfbda74e40cc1bad4d351c5d2ff92e1 SHA512 9fc6f5f15556f020414b4567520329ef762209a82411a246c2bc1240a9fed2669f7fcb982cf773e3e9561bf9a2c557dba82b8b469d2e5844e679e2f5ab7c3e17
 DIST pytorch-2.4.1.tar.gz 115029469 BLAKE2B c2909ff27d527bc57cba56b780d3b8cd07a043ab045caa6c6b27857a16f9ad10aaab2116b26226b1e46ee08ffb44007965d914464418e4ae14ca48c3f3f383bb SHA512 7e9b4485e242eaf0d648765c6621d73d95e7107b766646a098175436d1ab2e2b864badd0757a3bab6b7c318233f2120bad9ac07b39bb9e357897919580c87631
 DIST pytorch-2.5.1.tar.gz 116091366 BLAKE2B 7838b17562b94ffc7d798031348689db607dd5eae2a3c35be365972e2b52a2c1b12067068d5aca5ab00cf0977d9c2c3c9ae5337d69534c864c732e6256cbeef6 SHA512 a913a466324a65fa3d79c5e9ad4d605fc7976f0134fda2f81aaa3cea29d56926604999b8a238759646d211e63b47bbb446cdffa86ca8defd8159f11e30301289
 DIST pytorch-2.6.0.tar.gz 119594438 BLAKE2B 3152eb341cf42295e147e59625beb9c06608aa4b78f9618c1c0024b10c1c767715d07fe8c4be52d029ac47f808cd0d5e65c9530ec90d951a64b993083b4067ad SHA512 a70da80ff09d226085e18228132cf6bb236ad8cc47eed52375d0d2a615f09dd33849da947270b5670c184eab60cb8e2adf11d801babfbda7aa621400501d07b0

diff --git a/sci-ml/caffe2/caffe2-2.6.0-r2.ebuild b/sci-ml/caffe2/caffe2-2.6.0-r3.ebuild
similarity index 81%
rename from sci-ml/caffe2/caffe2-2.6.0-r2.ebuild
rename to sci-ml/caffe2/caffe2-2.6.0-r3.ebuild
index b9747ad9eed4..37c752237aa1 100644
--- a/sci-ml/caffe2/caffe2-2.6.0-r2.ebuild
+++ b/sci-ml/caffe2/caffe2-2.6.0-r3.ebuild
@@ -10,10 +10,17 @@ inherit python-single-r1 cmake cuda flag-o-matic prefix rocm toolchain-funcs
 MYPN=pytorch
 MYP=${MYPN}-${PV}
 
+# caffe2-2.6.0 depends on future version of composable kernel
+# TODO: replace it with RDEPEND in the future
+CK_COMMIT=50ee4267e27b875d149e642f4cebd47be1dc3b57
+CK_P=composable_kernel-${CK_COMMIT:0:8}
+
 DESCRIPTION="A deep learning framework"
 HOMEPAGE="https://pytorch.org/"
-SRC_URI="https://github.com/pytorch/${MYPN}/archive/refs/tags/v${PV}.tar.gz
-	-> ${MYP}.tar.gz"
+SRC_URI="
+	https://github.com/pytorch/${MYPN}/archive/refs/tags/v${PV}.tar.gz -> ${MYP}.tar.gz
+	rocm? ( https://github.com/ROCm/composable_kernel/archive/${CK_COMMIT}.tar.gz -> ${CK_P}.tar.gz )
+"
 
 S="${WORKDIR}"/${MYP}
 
@@ -68,24 +75,19 @@ RDEPEND="
 		sci-ml/gemmlowp
 	)
 	rocm? (
-		=dev-util/hip-6.1*
-		=dev-libs/rccl-6.1*[${ROCM_USEDEP}]
-		=sci-libs/rocThrust-6.1*[${ROCM_USEDEP}]
-		=sci-libs/rocPRIM-6.1*[${ROCM_USEDEP}]
-		=sci-libs/hipBLAS-6.1*[${ROCM_USEDEP}]
-		=sci-libs/hipFFT-6.1*[${ROCM_USEDEP}]
-		=sci-libs/hipSPARSE-6.1*[${ROCM_USEDEP}]
-		=sci-libs/hipRAND-6.1*[${ROCM_USEDEP}]
-		=sci-libs/hipCUB-6.1*[${ROCM_USEDEP}]
-		=sci-libs/hipSOLVER-6.1*[${ROCM_USEDEP}]
-		=sci-libs/miopen-6.1*[${ROCM_USEDEP}]
-		=dev-util/roctracer-6.1*[${ROCM_USEDEP}]
-
-		=sci-libs/hipBLASLt-6.1*
-		amdgpu_targets_gfx90a? ( =sci-libs/hipBLASLt-6.1*[amdgpu_targets_gfx90a] )
-		amdgpu_targets_gfx940? ( =sci-libs/hipBLASLt-6.1*[amdgpu_targets_gfx940] )
-		amdgpu_targets_gfx941? ( =sci-libs/hipBLASLt-6.1*[amdgpu_targets_gfx941] )
-		amdgpu_targets_gfx942? ( =sci-libs/hipBLASLt-6.1*[amdgpu_targets_gfx942] )
+		>=dev-libs/rccl-6.1      <dev-libs/rccl-6.4
+		>=dev-util/hip-6.1       <dev-util/hip-6.4
+		>=dev-util/roctracer-6.1 <dev-util/roctracer-6.4
+		>=sci-libs/hipBLAS-6.1   <sci-libs/hipBLAS-6.4
+		>=sci-libs/hipBLASLt-6.1 <sci-libs/hipBLASLt-6.4
+		>=sci-libs/hipCUB-6.1    <sci-libs/hipCUB-6.4
+		>=sci-libs/hipFFT-6.1    <sci-libs/hipFFT-6.4
+		>=sci-libs/hipRAND-6.1   <sci-libs/hipRAND-6.4
+		>=sci-libs/hipSOLVER-6.1 <sci-libs/hipSOLVER-6.4
+		>=sci-libs/hipSPARSE-6.1 <sci-libs/hipSPARSE-6.4
+		>=sci-libs/miopen-6.1    <sci-libs/miopen-6.4
+		>=sci-libs/rocPRIM-6.1   <sci-libs/rocPRIM-6.4
+		>=sci-libs/rocThrust-6.1 <sci-libs/rocThrust-6.4
 	)
 	distributed? (
 		sci-ml/tensorpipe[cuda?]
@@ -122,6 +124,7 @@ PATCHES=(
 	"${FILESDIR}"/${PN}-2.4.0-cpp-httplib.patch
 	"${FILESDIR}"/${PN}-2.5.1-glog-0.6.0.patch
 	"${FILESDIR}"/${PN}-2.5.1-newfix-functorch-install.patch
+	"${FILESDIR}"/${PN}-2.6.0-rocm-fix-std-cpp17.patch
 )
 
 src_prepare() {
@@ -178,9 +181,22 @@ src_prepare() {
 	if use rocm; then
 		sed -e "s:/opt/rocm:/usr:" \
 			-e "s:lib/cmake:$(get_libdir)/cmake:g" \
-			-e "s/HIP 1.0/HIP 1.0 REQUIRED/" \
 			-i cmake/public/LoadHIP.cmake || die
 
+		# TODO: delete, when caffe2 depends on systemwide composable_kernel
+		sed -e "s:third_party/composable_kernel:../composable_kernel-${CK_COMMIT}:g" \
+			-i aten/src/ATen/CMakeLists.txt || die
+
+		if tc-is-clang; then
+			# Systemwide gcc (for absl and at::TensorBase) + hipcc (llvm>=18) need abi-compat=17.
+			# But systemwide clang>=18 + hipcc (>=llvm-18) need opposite!
+			# See also: https://github.com/llvm/llvm-project/issues/102443#issuecomment-2329726287
+			sed '/-fclang-abi-compat=17/d' -i cmake/Dependencies.cmake || die
+		fi
+
+		# Workaround for libc++ issue https://github.com/llvm/llvm-project/issues/100802
+		sed 's/std::memcpy/memcpy/g' -i c10/util/Half.h || die
+
 		ebegin "HIPifying cuda sources"
 		${EPYTHON} tools/amd_build/build_amd.py || die
 		eend $?
@@ -275,15 +291,11 @@ src_configure() {
 		mycmakeargs+=(
 			-DUSE_NCCL=ON
 			-DUSE_SYSTEM_NCCL=ON
+			-DCMAKE_REQUIRE_FIND_PACKAGE_HIP=ON
 		)
 
 		# ROCm libraries produce too much warnings
 		append-cxxflags -Wno-deprecated-declarations -Wno-unused-result
-
-		if tc-is-clang; then
-			# fix mangling in LLVM: https://github.com/llvm/llvm-project/issues/85656
-			append-cxxflags -fclang-abi-compat=17
-		fi
 	fi
 
 	if use onednn; then

diff --git a/sci-ml/caffe2/files/caffe2-2.6.0-rocm-fix-std-cpp17.patch b/sci-ml/caffe2/files/caffe2-2.6.0-rocm-fix-std-cpp17.patch
new file mode 100644
index 000000000000..1b8084ac187f
--- /dev/null
+++ b/sci-ml/caffe2/files/caffe2-2.6.0-rocm-fix-std-cpp17.patch
@@ -0,0 +1,50 @@
+Fix for CXX=clang USE=rocm error: invalid argument '-std=c++17' not allowed with 'C'
+https://github.com/pytorch/pytorch/issues/103222
+--- a/c10/hip/CMakeLists.txt
++++ b/c10/hip/CMakeLists.txt
+@@ -36,6 +36,7 @@ if(NOT BUILD_LIBTORCHLESS)
+ 
+   # Propagate HIP_CXX_FLAGS that were set from Dependencies.cmake
+   target_compile_options(c10_hip PRIVATE ${HIP_CXX_FLAGS})
++  set_target_properties(c10_hip PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
+ 
+   # caffe2_hip adds a bunch of dependencies like rocsparse, but c10/hip is supposed to be
+   # minimal.  I'm not sure if we need hip_hcc or not; for now leave it out
+--- a/caffe2/CMakeLists.txt
++++ b/caffe2/CMakeLists.txt
+@@ -1684,6 +1684,7 @@ if(USE_ROCM)
+ 
+   # Since PyTorch files contain HIP headers, these flags are required for the necessary definitions to be added.
+   target_compile_options(torch_hip PUBLIC ${HIP_CXX_FLAGS})  # experiment
++  set_target_properties(torch_hip PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
+ 
+   target_link_libraries(torch_hip PUBLIC c10_hip)
+ 
+@@ -1886,6 +1887,7 @@ if(BUILD_TEST)
+       target_include_directories(${test_name} PRIVATE $<INSTALL_INTERFACE:include>)
+       target_include_directories(${test_name} PRIVATE ${Caffe2_CPU_INCLUDE} ${Caffe2_HIP_INCLUDE})
+       target_compile_options(${test_name} PRIVATE ${HIP_CXX_FLAGS})
++      set_target_properties(${test_name} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
+       add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
+       if(INSTALL_TEST)
+         set_target_properties(${test_name} PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${_rpath_portable_origin}/../lib")
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -1043,7 +1043,6 @@ if(USE_ROCM)
+     list(APPEND HIP_CXX_FLAGS -Wno-duplicate-decl-specifier)
+     list(APPEND HIP_CXX_FLAGS -DCAFFE2_USE_MIOPEN)
+     list(APPEND HIP_CXX_FLAGS -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP)
+-    list(APPEND HIP_CXX_FLAGS -std=c++17)
+     list(APPEND HIP_CXX_FLAGS -DHIPBLAS_V2)
+     if(HIP_NEW_TYPE_ENUMS)
+       list(APPEND HIP_CXX_FLAGS -DHIP_NEW_TYPE_ENUMS)
+--- a/cmake/public/utils.cmake
++++ b/cmake/public/utils.cmake
+@@ -267,6 +267,7 @@ function(caffe2_hip_binary_target target_name_or_src)
+   caffe2_binary_target(${target_name_or_src})
+ 
+   target_compile_options(${__target} PRIVATE ${HIP_CXX_FLAGS})
++  set_target_properties(${__target} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
+   target_include_directories(${__target} PRIVATE ${Caffe2_HIP_INCLUDE})
+ endfunction()
+ 


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-04-05 12:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-05 12:55 [gentoo-commits] repo/gentoo:master commit in: sci-ml/caffe2/files/, sci-ml/caffe2/ Alfredo Tupone

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox