[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH v6 0/2] rocm.eclass: new eclass
From:       Yiyang Wu <xgreenlandforwyy () gmail ! com>
Date:       2022-08-31 16:40:32
Message-ID: cover.1661963640.git.xgreenlandforwyy () gmail ! com
[Download RAW message or body]

The v6 fixes several issues raised in Github PR: 
https://github.com/gentoo/gentoo/pull/26784

Changelog against v5:

1. Update outdated examples and comments
2. QA fixes
3. Rename rocm_src_{test,configure} to rocm-{test,configure} to avoid
confusion
4. Simplify rocm-test function
5. Change the reference of AMDGPU targets and GPU product matching.


Yiyang Wu (2):
  rocm.eclass: new eclass
  profiles/desc: add amdgpu_targets.desc for USE_EXPAND

 eclass/rocm.eclass                | 284 ++++++++++++++++++++++++++++++
 profiles/base/make.defaults       |   2 +-
 profiles/desc/amdgpu_targets.desc |  17 ++
 3 files changed, 302 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass
 create mode 100644 profiles/desc/amdgpu_targets.desc

Interdiff against v5:
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 679b1af54e0a..1866d6b7cc94 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -18,13 +18,16 @@
 #
 # Most ROCm packages use cmake as build system, so this eclass does not export
 # phase functions which overwrites the phase functions in cmake.eclass. Ebuild
-# should explicitly call rocm_src_* in src_configure and src_test.
+# should explicitly call rocm-{configure,test} in src_configure and src_test.
 #
 # @EXAMPLE:
-# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
 # @CODE
+# # Example ebuild for ROCm library in https://github.com/ROCmSoftwarePlatform
+# # whcih depends on rocBLAS
 # inherit cmake rocm
+# # ROCm libraries SRC_URI is usually in form of:
 # SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz \
-> ${P}.tar.gz" +# S=${WORKDIR}/${PN}-rocm-${PV}
 # SLOT="0/$(ver_cut 1-2)"
 # IUSE="test"
 # REQUIRED_USE="${ROCM_REQUIRED_USE}"
@@ -35,17 +38,15 @@
 #     sci-libs/rocBLAS:${SLOT}[${ROCM_USEDEP}]
 # "
 #
-# S=${WORKDIR}/${PN}-rocm-${PV}
-#
 # src_configure() {
 #     local mycmakeargs=(
 #         -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
 #     )
-#     rocm_src_configure
+#     rocm-configure
 # }
 #
 # src_test() {
-#     rocm_src_test
+#     rocm-test
 # }
 # @CODE
 #
@@ -53,7 +54,7 @@
 # # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
 # # architecture to compile. Requires ROCm version >5.
 # @CODE
-# ROCM_VERSION=5
+# ROCM_VERSION=5.1
 # inherit rocm
 # IUSE="rocm"
 # REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )"
@@ -206,25 +207,31 @@ get_amdgpu_flags() {
 # @FUNCTION: check_rw_permission
 # @USAGE: check_rw_permission <file>
 # @DESCRIPTION:
-# check read and write permissions on specific files.
-# allow using wildcard, for example check_rw_permission /dev/dri/render*
+# check read and write permissions on a specific file, die if no permission.
+# @EXAMPLE:
+# @CODE
+# check_rw_permission /dev/kfd
+# CODE
 check_rw_permission() {
-	[[ -r $1 ]] && [[ -w $1 ]] || die \
-		"Portage do not have read or write permissions on $1! \n Make sure both are in \
render group and check the permissions." +	if [[ ! -r $1 ]] || [[ ! -w $1 ]]; then 
+		eerror "Portage do not have read or write permissions on $1!"
+		eerror "Make sure both are in render group and check the permissions."
+		die "No permissions on $1"
+	fi
 }
 
 # == phase functions ==
 
-# @FUNCTION: rocm_src_configure
+# @FUNCTION: rocm-configure
 # @DESCRIPTION:
-# configure rocm packages, and setting common cmake arguments
-rocm_src_configure() {
-	# allow acces to hardware
+# configure rocm packages, and setting common cmake arguments. Only for ROCm
+# libraries in https://github.com/ROCmSoftwarePlatform using cmake.
+rocm-configure() {
+	# avoid sandbox violation
 	addpredict /dev/kfd
 	addpredict /dev/dri/
 
 	mycmakeargs+=(
-		-DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
 		-DAMDGPU_TARGETS="$(get_amdgpu_flags)"
 		-DCMAKE_SKIP_RPATH=TRUE
 	)
@@ -232,46 +239,45 @@ rocm_src_configure() {
 	CXX="hipcc" cmake_src_configure
 }
 
-# @FUNCTION: rocm_src_test
+# @FUNCTION: rocm-test
 # @DESCRIPTION:
-# Test whether valid GPU device is present. If so, find how to, and execute test.
-# ROCm packages can have to test mechanism:
+# Test whether valid GPU device is present. If so, execute test.
+# @EXAMPLE:
+# ROCm packages can have two test scenarioes:
 # 1. cmake_src_test. MAKEOPTS="-j1" ensures only one test on GPU at a time;
-# 2. one single gtest binary called "${PN,,}"-test;
-# 3. Some package like rocFFT have alternative test like rocfft-selftest;
-# 4. Custome testing binaries like dev-libs/rccl. Use ${ROCM_TESTS} to specify.
-rocm_src_test() {
+# @CODE
+# LD_LIBRARY_PATH=<path-to-lib> rocm-test --cmake
+# @CODE
+# 2. one gtest binary called "${PN,,}"-test in ${BUILD_DIR}/clients/staging;
+# @CODE
+# cd "${BUILD_DIR}"/clients/staging || die
+# LD_LIBRARY_PATH=<path-to-lib> rocm-test "${PN,,}"-test
+# @CODE
+# Some packages like rocFFT have two test binaries like rocfft-selftest;
+# packages like dev-libs/rccl have test binary with custom names.
+# @CODE
+# cd "${BUILD_DIR}"/clients/staging || die
+# export LD_LIBRARY_PATH=<path-to-lib>
+# cd <test-bin-location> || die
+# rocm-test <test-bin-1>
+# rocm-test <test-bin-2> 
+# @CODE
+rocm-test() {
 	# grant and check permissions on /dev/kfd and /dev/dri/render*
 	for device in /dev/kfd /dev/dri/render*; do
-		addwrite ${device}
-		check_rw_permission ${device}
+		addwrite "${device}"
+		check_rw_permission "${device}"
 	done
 
-	: ${LD_LIBRARY_PATH:="${BUILD_DIR}/clients:${BUILD_DIR}/src:${BUILD_DIR}/library:${BUILD_DIR}/library/src:${BUILD_DIR}/library/src/device"}
                
-	export LD_LIBRARY_PATH
-	if grep -q 'build test:' "${BUILD_DIR}"/build.ninja; then
-		MAKEOPTS="-j1" cmake_src_test
-	elif [[ -d ${BUILD_DIR}/clients/staging ]]; then
-		cd "${BUILD_DIR}/clients/staging" || die "Test directory not found!"
-		for test_program in "${PN,,}-"*test; do
-			if [[ -x ${test_program} ]]; then
-					edob ./${test_program}
-			else
-				die "The test program ${test_program} does not exist or cannot be excuted!"
-			fi
-		done
-	elif [[ -n ${ROCM_TESTS} ]]; then
-		for test_program in ${ROCM_TESTS}; do
-			cd "${BUILD_DIR}" || die
-			if [[ -x ${test_program} ]]; then
-			edob ./${test_program}
-			else
-				die "The test program ${test_program} does not exist or cannot be excuted!"
-			fi
-		done
-	else
-		die "There is no cmake tests, no \${ROCM_TESTS} executable provided, nor \
                ${BUILD_DIR}/clients/staging where test program might be located."
-	fi
+	case ${1} in
+		--cmake)
+			# Avoid multi jobs running that may cause GPU error or CPU overload
+			MAKEOPTS="-j1" cmake_src_test
+			;;
+		*)
+			edob ./${1}
+			;;
+	esac
 }
 
 _ROCM_ECLASS=1
diff --git a/profiles/desc/amdgpu_targets.desc b/profiles/desc/amdgpu_targets.desc
index 8a3db2b56dab..df013d4f2c08 100644
--- a/profiles/desc/amdgpu_targets.desc
+++ b/profiles/desc/amdgpu_targets.desc
@@ -1,7 +1,9 @@
 # Copyright 1999-2022 Gentoo Authors.
 # Distributed under the terms of the GNU General Public License v2
 
-# Copied from https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2/#fn:67
 +# Refereneļ¼š
+# GPU name and Architecture codename: \
https://github.com/GPUOpen-Tools/device_info/blob/master/DeviceInfo.cpp +# See also: \
https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2/#fn:67  
 gfx803 - Fiji GPU, codename fiji, including Radeon R9 Nano/Fury/FuryX, Radeon Pro \
Duo, FirePro S9300x2, Radeon Instinct MI8   gfx900 - Vega GPU, codename vega10, \
including Radeon Vega Frontier Edition, Radeon RX Vega 56/64, Radeon RX Vega 64 \
Liquid, Radeon Pro Vega 48/56/64/64X, Radeon Pro WX 8200/9100, Radeon Pro \
                V320/V340/SSG, Radeon Instinct MI25
-- 
2.34.1


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic