* [gentoo-dev] [PATCH v7 0/2] rocm.eclass: new eclass
@ 2022-09-05 13:31 Yiyang Wu
2022-09-05 13:31 ` [gentoo-dev] [PATCH v7 1/2] " Yiyang Wu
2022-09-05 13:31 ` [gentoo-dev] [PATCH v7 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND Yiyang Wu
0 siblings, 2 replies; 3+ messages in thread
From: Yiyang Wu @ 2022-09-05 13:31 UTC (permalink / raw
To: gentoo-dev; +Cc: Benda Xu
Comparing to v6, rocn.eclass refactorized a lot in v7, thanks to
Michał's critical comments on
https://github.com/gentoo/gentoo/pull/26784.
Now the eclass code base is much cleaner, mostly because specific codes
in phase functions are removed.
Changelog against v6:
1. Remove phase functions rocm_src_configure and rocm_src_test. The code
duplication among ROCm ebuilds are not so large that a common phase
function is necessary. Writing a all-in-one phase function would cause
the eclass hard to maintain.
2. check_rw_permission -> check_amdgpu. Limit the function to check
amdgpu device, and move `addwrite /dev/kfd` from rocm_src_test into it.
So ebuilds can simply call check_amdgpu in src_test and do the reset of
testing.
3. Standardize and simplify codes including bash array handling.
4. ROCM_VERSION is required for all packages, not assumed to be ${PV}.
5. Reshaped the examples according to the changes.
6. Update reference of AMDGPU device map, pointing to codes in an
official repo rather than a summarize hosted on a third-party web page.
I would also like to ask a question. In check_amdgpu, if GPU access
denied, the eclass suggest the user to check whether the portage user is
in render group or not. I would like to print the username, so I tried
use ${USER} but it is not set during src_test. Previously, I used
${PORTAGE_USERNAME} but its a potage internal variable. Is there an
approach to print the portage username? Would $(whoami) suitable for
this job?
Yiyang Wu (2):
rocm.eclass: new eclass
profiles/desc: add amdgpu_targets.desc for USE_EXPAND
eclass/rocm.eclass | 223 ++++++++++++++++++++++++++++++
profiles/base/make.defaults | 2 +-
profiles/desc/amdgpu_targets.desc | 17 +++
3 files changed, 241 insertions(+), 1 deletion(-)
create mode 100644 eclass/rocm.eclass
create mode 100644 profiles/desc/amdgpu_targets.desc
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gentoo-dev] [PATCH v7 1/2] rocm.eclass: new eclass
2022-09-05 13:31 [gentoo-dev] [PATCH v7 0/2] rocm.eclass: new eclass Yiyang Wu
@ 2022-09-05 13:31 ` Yiyang Wu
2022-09-05 13:31 ` [gentoo-dev] [PATCH v7 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND Yiyang Wu
1 sibling, 0 replies; 3+ messages in thread
From: Yiyang Wu @ 2022-09-05 13:31 UTC (permalink / raw
To: gentoo-dev; +Cc: Benda Xu
This eclass provides utilities for ROCm libraries in
https://github.com/ROCmSoftwarePlatform, e.g. rocBLAS, rocFFT.
It contains a USE_EXPAND, amdgpu_targets_*, which handles the GPU
architecture to compile, and keep targets coherent among dependencies.
Packages that depend on ROCm libraries, like cupy, can also make use of
this eclass, mainly specify GPU architecture and it's corresponding
dependencies via USE_EXPAND.
Closes: https://bugs.gentoo.org/810619
Bugs: https://bugs.gentoo.org/817440
Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
---
eclass/rocm.eclass | 223 ++++++++++++++++++++++++++++++++++++
profiles/base/make.defaults | 2 +-
2 files changed, 224 insertions(+), 1 deletion(-)
create mode 100644 eclass/rocm.eclass
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index 000000000000..4c8fd39f2491
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,223 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project <sci@gentoo.org>
+# @AUTHOR:
+# Yiyang Wu <xgreenlandforwyy@gmail.com>
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/<roc|hip>*, and packages built on top of ROCm
+# libraries, can utilize variables and functions provided by this eclass.
+# It handles the AMDGPU_TARGETS variable via USE_EXPAND, so user can
+# edit USE flag to control which GPU architecture to compile. Using
+# ${ROCM_USEDEP} can ensure coherence among dependencies. Ebuilds can call the
+# function get_amdgpu_flag to translate activated target to GPU compile flags,
+# passing it to configuration. Function check_amdgpu can help ebuild ensure
+# read and write permissions to GPU device in src_test phase, throwing friendly
+# error message if unavailable.
+#
+# @EXAMPLE:
+# Example ebuild for ROCm library in https://github.com/ROCmSoftwarePlatform
+# which uses cmake to build and test, and depends on rocBLAS:
+# @CODE
+# ROCM_VERSION=${PV}
+# 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}"
+# RESTRICT="!test? ( test )"
+#
+# RDEPEND="
+# dev-util/hip
+# sci-libs/rocBLAS:${SLOT}[${ROCM_USEDEP}]
+# "
+#
+# src_configure() {
+# # avoid sandbox violation
+# addpredict /dev/kfd
+# addpredict /dev/dri/
+# local mycmakeargs=(
+# -DAMDGPU_TARGETS="$(get_amdgpu_flags)"
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# CXX=hipcc cmake_src_configure
+# }
+#
+# src_test() {
+# check_amdgpu
+# # export LD_LIBRARY_PATH=<path to built lib dir> if necessary
+# cmake_src_test # for packages using the cmake test
+# # For packages using a standalone test binary rather than cmake test,
+# # just execute it (or using edob)
+# }
+# @CODE
+#
+# Examples for packages depend on ROCm libraries -- a package which depends on
+# rocBLAS, uses comma separated ${HCC_AMDGPU_TARGET} to determine GPU
+# architectures, and requires ROCm version >=5.1
+# @CODE
+# ROCM_VERSION=5.1
+# inherit rocm
+# IUSE="rocm"
+# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )"
+# DEPEND="rocm? ( >=dev-util/hip-${ROCM_VERSION}
+# >=sci-libs/rocBLAS-${ROCM_VERSION}[${ROCM_USEDEP}] )"
+#
+# src_configure() {
+# if use rocm; then
+# local amdgpu_flags=$(get_amdgpu_flags)
+# export HCC_AMDGPU_TARGET=${amdgpu_flags//;/,}
+# fi
+# default
+# }
+# src_test() {
+# use rocm && check_amdgpu
+# default
+# }
+# @CODE
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case ${EAPI} in
+ 7|8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @REQUIRED
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. For ROCm libraries, it should be ${PV};
+# for other packages that depend on ROCm libraries, this can be set to match
+# the version required for ROCm libraries.
+
+# @ECLASS_VARIABLE: ROCM_REQUIRED_USE
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Requires at least one AMDGPU target to be compiled.
+# Example use for ROCm libraries:
+# @CODE
+# REQUIRED_USE="${ROCM_REQUIRED_USE}"
+# @CODE
+# Example use for packages that depend on ROCm libraries:
+# @CODE
+# IUSE="rocm"
+# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )"
+# @CODE
+
+# @ECLASS_VARIABLE: ROCM_USEDEP
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# This is an eclass-generated USE-dependency string which can be used to
+# depend on another ROCm package being built for the same AMDGPU architecture.
+#
+# The generated USE-flag list is compatible with packages using rocm.eclass.
+#
+# Example use:
+# @CODE
+# DEPEND="sci-libs/rocBLAS[${ROCM_USEDEP}]"
+# @CODE
+
+# @FUNCTION: _rocm_set_globals
+# @DESCRIPTION:
+# Set global variables useful to ebuilds: IUSE, ROCM_REQUIRED_USE, and
+# ROCM_USEDEP
+_rocm_set_globals() {
+ # Two lists of AMDGPU_TARGETS of certain ROCm version. Official support
+ # matrix:
+ # https://docs.amd.com/bundle/ROCm-Installation-Guide-v${ROCM_VERSION}/page/Prerequisite_Actions.html.
+ # There is no well-known unofficial support matrix.
+ # https://github.com/Bengt/ROCm/blob/patch-2/README.md#library-target-matrix
+ # may help. Gentoo have patches to enable gfx1031 as well.
+ local unofficial_amdgpu_targets official_amdgpu_targets
+ case ${ROCM_VERSION} in
+ 4.*)
+ unofficial_amdgpu_targets=(
+ gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1030
+ )
+ official_amdgpu_targets=(
+ gfx906 gfx908
+ )
+ ;;
+ 5.*)
+ unofficial_amdgpu_targets=(
+ gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1031
+ )
+ official_amdgpu_targets=(
+ gfx906 gfx908 gfx90a gfx1030
+ )
+ ;;
+ *)
+ die "Unknown ROCm major version! Please update rocm.eclass before bumping to new ebuilds"
+ ;;
+ esac
+
+ local iuse_flags=(
+ "${official_amdgpu_targets[@]/#/+amdgpu_targets_}"
+ "${unofficial_amdgpu_targets[@]/#/amdgpu_targets_}"
+ )
+ IUSE="${iuse_flags[*]}"
+
+ local all_amdgpu_targets=(
+ "${official_amdgpu_targets[@]}"
+ "${unofficial_amdgpu_targets[@]}"
+ )
+ local allflags=( "${all_amdgpu_targets[@]/#/amdgpu_targets_}" )
+ ROCM_REQUIRED_USE=" || ( ${allflags[*]} )"
+
+ local optflags=${allflags[@]/%/(-)?}
+ ROCM_USEDEP=${optflags// /,}
+}
+_rocm_set_globals
+unset -f _rocm_set_globals
+
+
+# @FUNCTION: get_amdgpu_flags
+# @USAGE: get_amdgpu_flags
+# @DESCRIPTION:
+# Convert specified use flag of amdgpu_targets to compilation flags.
+# Append default target feature to GPU arch. See
+# https://llvm.org/docs/AMDGPUUsage.html#target-features
+get_amdgpu_flags() {
+ local amdgpu_target_flags
+ for gpu_target in ${AMDGPU_TARGETS}; do
+ local target_feature=
+ case ${gpu_target} in
+ gfx906|gfx908)
+ target_feature=:xnack-
+ ;;
+ gfx90a)
+ target_feature=:xnack+
+ ;;
+ *)
+ ;;
+ esac
+ amdgpu_target_flags+="${gpu_target}${target_feature};"
+ done
+ echo "${amdgpu_target_flags}"
+}
+
+# @FUNCTION: check_amdgpu
+# @USAGE: check_amdgpu
+# @DESCRIPTION:
+# grant and check read-write permissions on AMDGPU devices, die if not available.
+check_amdgpu() {
+ for device in /dev/kfd /dev/dri/render*; do
+ addwrite ${device}
+ if [[ ! -r ${device} || ! -w ${device} ]]; then
+ eerror "Cannot read or write ${device}!"
+ eerror "Make sure it is present and check the permission."
+ ewarn "By default render group have access to it. Check if portage user is in render group."
+ die "${device} inaccessible"
+ fi
+ done
+}
+
+_ROCM_ECLASS=1
+fi
diff --git a/profiles/base/make.defaults b/profiles/base/make.defaults
index 326cb28de537..2c288d12d103 100644
--- a/profiles/base/make.defaults
+++ b/profiles/base/make.defaults
@@ -13,7 +13,7 @@ USE_EXPAND_VALUES_USERLAND="BSD GNU"
# Env vars to expand into USE vars. Modifying this requires prior
# discussion on gentoo-dev@lists.gentoo.org.
-USE_EXPAND="ABI_MIPS ABI_S390 ABI_X86 ADA_TARGET ALSA_CARDS APACHE2_MODULES APACHE2_MPMS CALLIGRA_FEATURES CAMERAS COLLECTD_PLUGINS CPU_FLAGS_ARM CPU_FLAGS_PPC CPU_FLAGS_X86 CURL_SSL ELIBC FFTOOLS GPSD_PROTOCOLS GRUB_PLATFORMS INPUT_DEVICES KERNEL L10N LCD_DEVICES LIBREOFFICE_EXTENSIONS LLVM_TARGETS LUA_SINGLE_TARGET LUA_TARGETS MONKEYD_PLUGINS NGINX_MODULES_HTTP NGINX_MODULES_MAIL NGINX_MODULES_STREAM OFFICE_IMPLEMENTATION OPENMPI_FABRICS OPENMPI_OFED_FEATURES OPENMPI_RM PHP_TARGETS POSTGRES_TARGETS PYTHON_SINGLE_TARGET PYTHON_TARGETS QEMU_SOFTMMU_TARGETS QEMU_USER_TARGETS ROS_MESSAGES RUBY_TARGETS SANE_BACKENDS USERLAND UWSGI_PLUGINS VIDEO_CARDS VOICEMAIL_STORAGE XTABLES_ADDONS"
+USE_EXPAND="ABI_MIPS ABI_S390 ABI_X86 ADA_TARGET ALSA_CARDS AMDGPU_TARGETS APACHE2_MODULES APACHE2_MPMS CALLIGRA_FEATURES CAMERAS COLLECTD_PLUGINS CPU_FLAGS_ARM CPU_FLAGS_PPC CPU_FLAGS_X86 CURL_SSL ELIBC FFTOOLS GPSD_PROTOCOLS GRUB_PLATFORMS INPUT_DEVICES KERNEL L10N LCD_DEVICES LIBREOFFICE_EXTENSIONS LLVM_TARGETS LUA_SINGLE_TARGET LUA_TARGETS MONKEYD_PLUGINS NGINX_MODULES_HTTP NGINX_MODULES_MAIL NGINX_MODULES_STREAM OFFICE_IMPLEMENTATION OPENMPI_FABRICS OPENMPI_OFED_FEATURES OPENMPI_RM PHP_TARGETS POSTGRES_TARGETS PYTHON_SINGLE_TARGET PYTHON_TARGETS QEMU_SOFTMMU_TARGETS QEMU_USER_TARGETS ROS_MESSAGES RUBY_TARGETS SANE_BACKENDS USERLAND UWSGI_PLUGINS VIDEO_CARDS VOICEMAIL_STORAGE XTABLES_ADDONS"
# USE_EXPAND variables whose contents are not shown in package manager
# output. Changes need discussion on gentoo-dev.
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-dev] [PATCH v7 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND
2022-09-05 13:31 [gentoo-dev] [PATCH v7 0/2] rocm.eclass: new eclass Yiyang Wu
2022-09-05 13:31 ` [gentoo-dev] [PATCH v7 1/2] " Yiyang Wu
@ 2022-09-05 13:31 ` Yiyang Wu
1 sibling, 0 replies; 3+ messages in thread
From: Yiyang Wu @ 2022-09-05 13:31 UTC (permalink / raw
To: gentoo-dev; +Cc: Benda Xu
Signed-off-by: Yiyang Wu <xgreenlandforwyy@gmail.com>
---
profiles/desc/amdgpu_targets.desc | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
create mode 100644 profiles/desc/amdgpu_targets.desc
diff --git a/profiles/desc/amdgpu_targets.desc b/profiles/desc/amdgpu_targets.desc
new file mode 100644
index 000000000000..66a9a7a85935
--- /dev/null
+++ b/profiles/desc/amdgpu_targets.desc
@@ -0,0 +1,17 @@
+# Copyright 1999-2022 Gentoo Authors.
+# Distributed under the terms of the GNU General Public License v2
+
+# Reference:
+# 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
+gfx906 - Vega GPU, codename vega20, including Radeon (Pro) VII, Radeon Instinct MI50/MI60
+gfx908 - CDNA Accelerator, codename arcturus, including AMD Instinct MI100 Accelerator
+gfx90a - CDNA2 Accelerator, codename aldebaran, including AMD Instinct MI200 series Accelerators
+gfx1010 - RDNA GPU, codename navi10, including Radeon RX 5700XT/5700/5700M/5700B/5700XTB/5600XT/5600/5600M, Radeon Pro 5700XT/5700, Radeon Pro W5700X/W5700
+gfx1011 - RDNA GPU, codename navi12, including Radeon Pro 5600M/V520
+gfx1012 - RDNA GPU, codename navi14, including Radeon RX 5500XT/5500/5500M/5500XTB/5300/5300M, Radeon Pro 5500XT/5500M/5300/5300M, Radeon Pro W5500X/W5500/W5500M/W5300M
+gfx1030 - RDNA2 GPU, codename navi21/sienna cichlid, including Radeon RX 6950XT/6900XT/6800XT/6800, Radeon Pro W6800
+gfx1031 - RDNA2 GPU, codename navi22/navy flounder, including Radeon RX 6750XT/6700XT/6800M/6700M
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-05 13:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05 13:31 [gentoo-dev] [PATCH v7 0/2] rocm.eclass: new eclass Yiyang Wu
2022-09-05 13:31 ` [gentoo-dev] [PATCH v7 1/2] " Yiyang Wu
2022-09-05 13:31 ` [gentoo-dev] [PATCH v7 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND Yiyang Wu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox