[gentoo-dev] [PATCH 2/2] rocm.eclass: Enable ROCm 6, add gfx94{0,1,2} (MI300) support

2024-04-14 Thread Yiyang Wu
Also update the references, since the original reference does not
contain MI300. The "see also" blog is also removed because it hasn't been
updated for 2 years.

Signed-off-by: Yiyang Wu 
---
 eclass/rocm.eclass| 12 +++-
 profiles/desc/amdgpu_targets.desc | 14 ++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index e03e8bdd507a..7039455dec6b 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -161,7 +161,7 @@ _rocm_set_globals() {
gfx906 gfx908 gfx90a gfx1030
)
;;
-   5.*|)
+   5.*)
unofficial_amdgpu_targets=(
gfx803 gfx900 gfx1010 gfx1011 gfx1012
gfx1031 gfx1100 gfx1101 gfx1102
@@ -170,6 +170,16 @@ _rocm_set_globals() {
gfx906 gfx908 gfx90a gfx1030
)
;;
+   6.*|)
+   unofficial_amdgpu_targets=(
+   gfx803 gfx900 gfx940 gfx941
+   gfx1010 gfx1011 gfx1012
+   gfx1031 gfx1101 gfx1102
+   )
+   official_amdgpu_targets=(
+   gfx906 gfx908 gfx90a gfx942 gfx1030 gfx1100
+   )
+   ;;
*)
die "Unknown ROCm major version! Please update 
rocm.eclass before bumping to new ebuilds"
;;
diff --git a/profiles/desc/amdgpu_targets.desc 
b/profiles/desc/amdgpu_targets.desc
index d52080781947..8f337b03f63d 100644
--- a/profiles/desc/amdgpu_targets.desc
+++ b/profiles/desc/amdgpu_targets.desc
@@ -1,15 +1,21 @@
-# Copyright 1999-2023 Gentoo Authors.
+# Copyright 1999-2024 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
+# Reference: GPU name and architecture codename documented by
+# GPUOpen-Tools 
https://github.com/GPUOpen-Tools/device_info/blob/master/DeviceInfo.cpp
+# ROCm official document (Instinct accelerator only) 
https://rocm.docs.amd.com/en/latest/reference/gpu-arch/gpu-arch-spec-overview.html
+# Kernel document (note: GC version is not amdgpu gfx target) 
https://www.kernel.org/doc/html/latest/gpu/amdgpu/driver-misc.html#discrete-gpu-info
+# Kernel source code (map of IP version vs amdgpu gfx target) 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/amdkfd/kfd_device.c
 kgd2kfd_probe function
+# Mesa drm source code 
https://gitlab.freedesktop.org/mesa/drm/blob/main/data/amdgpu.ids
 
 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
+gfx940 - CDNA3 Accelerator, codename aqua_vangaram, MI300A rev 0
+gfx941 - CDNA3 Accelerator, codename aqua_vangaram, MI300X rev 0
+gfx942 - CDNA3 Accelerator, codename aqua_vangaram, MI300A and MI300X rev >=1
 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
-- 
2.41.0




[gentoo-dev] [PATCH 1/2] rocm.eclass: remove xnack flag for broader compatibility

2024-04-14 Thread Yiyang Wu
Initially, rocm.eclass append xnack[1,2] feature flag to gfx9 GPUs,
since ROCm upstream does this in many of their math libraries, e.g.
rocBLAS [3]. The list includes gfx90a:xnack+, indicating xnack is usable
for MI200 series, thus rocm.eclass append :xnack+ to gfx90a.

But it turns out xnack- is also common for MI200 series, restricting to
xnack+ produces incompatible GPU kernel with xnack- mode.

Also, community also explores using xnack on other gfx9 GPU [4,5], which
is previously restricted to xnack- in rocm.eclass.

By not appending xnack feature flag, GPU kernels are compiled to "xnack
any" mode, which can be run in either mode, potentially scarifying some
performance [6,7], with no direct evidence. rocFFT reports no
performance penalty[8].

For the reason above, do not append xnack feature flag to AMDGPU_TARGETS,
which is compatible with GPUs operate in both xnack mode.

[1] https://wiki.gentoo.org/wiki/ROCm#XNACK_target_feature
[2] https://rocm.docs.amd.com/en/latest/conceptual/gpu-memory.html#xnack
[3] 
https://github.com/ROCm/rocBLAS/blob/release/rocm-rel-5.0/CMakeLists.txt#L201
[4] https://niconiconi.neocities.org/tech-notes/xnack-on-amd-gpus/
[5] https://arxiv.org/abs/2401.02680
[6] https://llvm.org/docs/AMDGPUUsage.html#target-features
[7] 
https://docs.olcf.ornl.gov/systems/crusher_quick_start_guide.html#compiling-hip-kernels-for-specific-xnack-modes
[8] 
https://github.com/ROCm/rocFFT/commit/cd2689360ba3b3579d044d8925838ff307b4b4cf

Signed-off-by: Yiyang Wu 
---
 eclass/rocm.eclass | 19 ++-
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 9804ecde97d0..e03e8bdd507a 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -1,4 +1,4 @@
-# Copyright 2022-2023 Gentoo Authors
+# Copyright 2022-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: rocm.eclass
@@ -201,22 +201,7 @@ unset -f _rocm_set_globals
 # 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}"
+   echo $(printf "%s;" ${AMDGPU_TARGETS[@]})
 }
 
 # @FUNCTION: check_amdgpu
-- 
2.41.0




[gentoo-dev] [PATCH 0/2] rocm.eclass: drop xnack feature flag and support ROCm 6

2024-04-14 Thread Yiyang Wu
The first patch simplifies rocm.eclass, dropping xnack feature in
get_amdgpu_flags. This makes the compiled GPU binary more compatible.
The details are explained the commit message.

The second commit adds support for ROCm 6 and MI300.

Github pull request: https://github.com/gentoo/gentoo/pull/36254

Yiyang Wu (2):
  rocm.eclass: remove xnack flag for broader compatibility
  Enable ROCm 6, add gfx94{0,1,2} (MI300) support

 eclass/rocm.eclass| 31 +--
 profiles/desc/amdgpu_targets.desc | 14 ++
 2 files changed, 23 insertions(+), 22 deletions(-)

-- 
2.41.0




[gentoo-dev] [PATCH 2/2] profiles/desc/amdgpu_targets.desc: Fill in more GPU models

2023-11-16 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 profiles/desc/amdgpu_targets.desc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/profiles/desc/amdgpu_targets.desc 
b/profiles/desc/amdgpu_targets.desc
index 77ffa43399f1..46513023c3a9 100644
--- a/profiles/desc/amdgpu_targets.desc
+++ b/profiles/desc/amdgpu_targets.desc
@@ -18,6 +18,6 @@ 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
-gfx1100 - RDNA3 GPU, codename navi31/plum bonito, including Radeon RX 
7900XTX/7900XT
-gfx1101 - RDNA3 GPU, codename navi32
-gfx1102 - RDNA3 GPU, codename navi33
+gfx1100 - RDNA3 GPU, codename navi31/plum bonito, including Radeon RX 
7900XTX/7900XT, AMD Radeon Pro W7900/W7800
+gfx1101 - RDNA3 GPU, codename navi32, including Radeon RX 7700XT/7800XT
+gfx1102 - RDNA3 GPU, codename navi33, including Radeon RX 7600/7600M/7600M 
XT/7700S/7600S, AMD Radeon PRO W7600/W7500
-- 
2.41.0




[gentoo-dev] [PATCH 1/2] rocm.eclass: Fix the xnack feature for gfx90a

2023-11-16 Thread Yiyang Wu
MI210 is xnack disabled by default. Compile with :xnack+ will produce
GPU kernels that cannot be run on MI210.

Two targets, gfx90a_xnack and gfx90a_noxnack are introduced to replace
gfx90a, for the following reason:

Upstream usually ships 2 version: gfx90a:xnack-, gfx90a:xnack+. Although
a single gfx90a should have maximum compatibility, According to [1,2],
compile with xnack+/xnack- may have better performance on xnack
enabled/disabled GPUs. Therefore we ship both the target, align with
upstream. gfx900 is also appended with :xnack- to align with upstream
default.

However, some ROCm libraries does not need xnack feature flag, such as
sci-libs/miopen and sci-libs/rocFFT, so "--no-xnack-flag" option is
introduced to stop appending xnack feature. Demonstrate this option in
the second example ebuild.

Update description file profiles/desc/amdgpu_targets.desc accordingly.

Github PR: https://github.com/gentoo/gentoo/pull/33861

[1] https://llvm.org/docs/AMDGPUUsage.html#target-features
[2] 
https://docs.olcf.ornl.gov/systems/crusher_quick_start_guide.html#compiling-hip-kernels-for-specific-xnack-modes

Signed-off-by: Yiyang Wu 
---
 eclass/rocm.eclass| 31 ++-
 profiles/desc/amdgpu_targets.desc |  5 -
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index b78dfea1cc31..3209c003e323 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -60,7 +60,8 @@
 #
 # 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
+# architectures which does not accept :xnack feature flag, and requires ROCm
+# version >=5.1
 # @CODE
 # ROCM_VERSION=5.1
 # inherit rocm
@@ -71,7 +72,7 @@
 #
 # src_configure() {
 # if use rocm; then
-# local amdgpu_flags=$(get_amdgpu_flags)
+# local amdgpu_flags=$(get_amdgpu_flags --no-xnack-flag)
 # export HCC_AMDGPU_TARGET=${amdgpu_flags//;/,}
 # fi
 # default
@@ -143,7 +144,7 @@ _rocm_set_globals() {
gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1031
)
official_amdgpu_targets=(
-   gfx906 gfx908 gfx90a gfx1030
+   gfx906 gfx908 gfx90a_xnack gfx90a_noxnack 
gfx1030
)
;;
5.*|)
@@ -152,7 +153,7 @@ _rocm_set_globals() {
gfx1031 gfx1100 gfx1101 gfx1102
)
official_amdgpu_targets=(
-   gfx906 gfx908 gfx90a gfx1030
+   gfx906 gfx908 gfx90a_xnack gfx90a_noxnack 
gfx1030
)
;;
*)
@@ -181,26 +182,38 @@ unset -f _rocm_set_globals
 
 
 # @FUNCTION: get_amdgpu_flags
-# @USAGE: get_amdgpu_flags
+# @USAGE: get_amdgpu_flags [--no-xnack-flag]
 # @DESCRIPTION:
 # Convert specified use flag of amdgpu_targets to compilation flags.
-# Append default target feature to GPU arch. See
+# Append default target feature xnack to GPU arch. See
 # https://llvm.org/docs/AMDGPUUsage.html#target-features
+# If specified with --no-xnack-flag, do not append xnack feature flag.
 get_amdgpu_flags() {
local amdgpu_target_flags
for gpu_target in ${AMDGPU_TARGETS}; do
local target_feature=
case ${gpu_target} in
-   gfx906|gfx908)
+   gfx900|gfx906|gfx908)
+   # These GPUs ususally does not enable xnack, so
+   # disabling xnack generates faster GPU kernels.
target_feature=:xnack-
;;
-   gfx90a)
+   gfx90a_noxnack)
+   gpu_target=gfx90a
+   target_feature=:xnack-
+   ;;
+   gfx90a_xnack)
+   gpu_target=gfx90a
target_feature=:xnack+
;;
*)
;;
esac
-   amdgpu_target_flags+="${gpu_target}${target_feature};"
+   if [[ "$1" == "--no-xnack-flag" ]]; then
+   amdgpu_target_flags+="${gpu_target};"
+   else
+   amdgpu_target_flags+="${gpu_target}${target_feature};"
+   fi
done
echo "${amdgpu_target_flags}"
 }
diff --git a/profiles/desc/amdgpu_targets.desc 
b/profiles/desc/amdgpu_targets.desc
index 9c5739e9d9a4..77ffa43399f1 100644
--- a/profiles/desc/amdgpu_targets.desc
+++ b/profiles/desc/amdg

[gentoo-dev] [PATCH] rocm.eclass: support RDNA3 GPU for >=5.4, remove <5

2023-01-28 Thread Yiyang Wu
ROCm libraries with version <5 are cleaned up, remove version 4 support
for rocm.eclass.

RDNA3 has initial support in ROCm libraries starting from 5.4 releases.
Enable gfx110* amdgpu_targets in rocm.eclass and add corresponding
description.

Tried =sci-libs/rocBLAS-5.4.2, can compile successfully with
amdgpu_targets_gfx1100 (but not tested on real GPU).
rocBLAS-5.4.2.ebuild is in https://github.com/gentoo/gentoo/pull/29319

The github PR for this patch is at
https://github.com/gentoo/gentoo/pull/29320

Closes: https://bugs.gentoo.org/891499
Signed-off-by: Yiyang Wu 
---
 eclass/rocm.eclass| 13 +++--
 profiles/desc/amdgpu_targets.desc |  5 -
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index cf7a18b70ad2..b78dfea1cc31 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -1,4 +1,4 @@
-# Copyright 2022 Gentoo Authors
+# Copyright 2022-2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: rocm.eclass
@@ -138,17 +138,18 @@ _rocm_set_globals() {
# may help. Gentoo have patches to enable gfx1031 as well.
local unofficial_amdgpu_targets official_amdgpu_targets
case ${ROCM_VERSION} in
-   4.*)
+   5.[0-3].*)
unofficial_amdgpu_targets=(
-   gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1030
+   gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1031
)
official_amdgpu_targets=(
-   gfx906 gfx908
+   gfx906 gfx908 gfx90a gfx1030
)
;;
-   5.*)
+   5.*|)
unofficial_amdgpu_targets=(
-   gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1031
+   gfx803 gfx900 gfx1010 gfx1011 gfx1012
+   gfx1031 gfx1100 gfx1101 gfx1102
)
official_amdgpu_targets=(
gfx906 gfx908 gfx90a gfx1030
diff --git a/profiles/desc/amdgpu_targets.desc 
b/profiles/desc/amdgpu_targets.desc
index 66a9a7a85935..9c5739e9d9a4 100644
--- a/profiles/desc/amdgpu_targets.desc
+++ b/profiles/desc/amdgpu_targets.desc
@@ -1,4 +1,4 @@
-# Copyright 1999-2022 Gentoo Authors.
+# Copyright 1999-2023 Gentoo Authors.
 # Distributed under the terms of the GNU General Public License v2
 
 # Reference:
@@ -15,3 +15,6 @@ 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
+gfx1100 - RDNA3 GPU, codename navi31/plum bonito, including Radeon RX 
7900XTX/7900XT
+gfx1101 - RDNA3 GPU, codename navi32
+gfx1102 - RDNA3 GPU, codename navi33
-- 
2.39.0




[gentoo-dev] [PATCH v7 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-09-05 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 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 ..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




[gentoo-dev] [PATCH v7 1/2] rocm.eclass: new eclass

2022-09-05 Thread Yiyang Wu
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 
---
 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 ..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 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/*, 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= 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=&

[gentoo-dev] [PATCH v7 0/2] rocm.eclass: new eclass

2022-09-05 Thread Yiyang Wu
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




[gentoo-dev] [PATCH v6 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-08-31 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 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 ..df013d4f2c08
--- /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
+
+# 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
+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




[gentoo-dev] [PATCH v6 1/2] rocm.eclass: new eclass

2022-08-31 Thread Yiyang Wu
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 
---
 eclass/rocm.eclass  | 284 
 profiles/base/make.defaults |   2 +-
 2 files changed, 285 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index ..1866d6b7cc94
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,284 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/* can utilize functions in this
+# eclass.  Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so
+# user can use USE flag to control which GPU architecture to compile, and
+# ensure coherence among dependencies. It also specify CXX=hipcc, to let hipcc
+# compile. Another important function is src_test, which checks whether a valid
+# KFD device exists for testing, and then execute the test program.
+#
+# 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-{configure,test} in src_configure and src_test.
+#
+# @EXAMPLE:
+# @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}"
+# RESTRICT="!test? ( test )"
+#
+# RDEPEND="
+# dev-util/hip
+# sci-libs/rocBLAS:${SLOT}[${ROCM_USEDEP}]
+# "
+#
+# src_configure() {
+# local mycmakeargs=(
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# rocm-configure
+# }
+#
+# src_test() {
+# rocm-test
+# }
+# @CODE
+#
+# # Example for packages depend on ROCm libraries -- a package depend on
+# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
+# # architecture to compile. Requires ROCm version >5.
+# @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
+# }
+# @CODE
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case ${EAPI} in
+   7|8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. Default is ${PV}, but for other packages
+# that depend on ROCm libraries, this can be set to match the version of
+# required ROCm libraries.
+
+# @ECLASS_VARIABLE: ALL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all AMDGPU targets in this ROCm
+# version. The value depends on ${PV}. Architectures and devices map:
+# https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2
+
+# @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all officially supported AMDGPU
+# targets in this ROCm version, documented at
+# 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
+# USE flag of these architectures will be default on. Depends on ${PV}.
+
+# @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 

[gentoo-dev] [PATCH v6 0/2] rocm.eclass: new eclass

2022-08-31 Thread Yiyang Wu
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 
 # @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= rocm-test --cmake
+# @CODE
+# 2. one gtest binary called "${PN,,}"-test in ${BUILD_DIR}/clients/staging;
+# @CODE
+# cd "${BUILD_DIR}"/cl

[gentoo-dev] [PATCH v5 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-08-28 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 profiles/desc/amdgpu_targets.desc | 15 +++
 1 file changed, 15 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 ..8a3db2b56dab
--- /dev/null
+++ b/profiles/desc/amdgpu_targets.desc
@@ -0,0 +1,15 @@
+# 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
+
+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




[gentoo-dev] [PATCH v5 1/2] rocm.eclass: new eclass

2022-08-28 Thread Yiyang Wu
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 
---
 eclass/rocm.eclass  | 278 
 profiles/base/make.defaults |   2 +-
 2 files changed, 279 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index ..679b1af54e0a
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,278 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/* can utilize functions in this
+# eclass.  Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so
+# user can use USE flag to control which GPU architecture to compile, and
+# ensure coherence among dependencies. It also specify CXX=hipcc, to let hipcc
+# compile. Another important function is src_test, which checks whether a valid
+# KFD device exists for testing, and then execute the test program.
+#
+# 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.
+#
+# @EXAMPLE:
+# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
+# @CODE
+# inherit cmake rocm
+# 
SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz
 -> ${P}.tar.gz"
+# 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}]
+# "
+#
+# S=${WORKDIR}/${PN}-rocm-${PV}
+#
+# src_configure() {
+# local mycmakeargs=(
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# rocm_src_configure
+# }
+#
+# src_test() {
+# rocm_src_test
+# }
+# @CODE
+#
+# # Example for packages depend on ROCm libraries -- a package depend on
+# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
+# # architecture to compile. Requires ROCm version >5.
+# @CODE
+# ROCM_VERSION=5
+# 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
+# }
+# @CODE
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case ${EAPI} in
+   7|8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. Default is ${PV}, but for other packages
+# that depend on ROCm libraries, this can be set to match the version of
+# required ROCm libraries.
+
+# @ECLASS_VARIABLE: ALL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all AMDGPU targets in this ROCm
+# version. The value depends on ${PV}. Architectures and devices map:
+# https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2
+
+# @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all officially supported AMDGPU
+# targets in this ROCm version, documented at
+# 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
+# USE flag of these architectures will be default on. Depends on ${PV}.
+
+# @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 arc

[gentoo-dev] [PATCH v5 0/2] *** rocm.eclass: new class ***

2022-08-28 Thread Yiyang Wu
The v5 patches corrects the usage of bash array expansion on
OFFICIAL_AMDGPU_TARGETS.

The updated Github PR is located at
https://github.com/gentoo/gentoo/pull/26784

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

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

Interdiff against v4:
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 225329df4876..679b1af54e0a 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -159,7 +159,7 @@ _rocm_set_globals() {
 
ROCM_REQUIRED_USE+=" || ("
for gpu_target in "${ALL_AMDGPU_TARGETS[@]}"; do
-   if has "${gpu_target}" ${OFFICIAL_AMDGPU_TARGETS[*]}; then
+   if has "${gpu_target}" "${OFFICIAL_AMDGPU_TARGETS[@]}"; then
IUSE+=" ${gpu_target/#/+amdgpu_targets_}"
else
IUSE+=" ${gpu_target/#/amdgpu_targets_}"
-- 
2.34.1




[gentoo-dev] [PATCH v4 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-08-27 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 profiles/desc/amdgpu_targets.desc | 15 +++
 1 file changed, 15 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 ..8a3db2b56dab
--- /dev/null
+++ b/profiles/desc/amdgpu_targets.desc
@@ -0,0 +1,15 @@
+# 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
+
+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




[gentoo-dev] [PATCH v4 1/2] rocm.eclass: new eclass

2022-08-27 Thread Yiyang Wu
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 
---
 eclass/rocm.eclass  | 278 
 profiles/base/make.defaults |   2 +-
 2 files changed, 279 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index ..225329df4876
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,278 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/* can utilize functions in this
+# eclass.  Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so
+# user can use USE flag to control which GPU architecture to compile, and
+# ensure coherence among dependencies. It also specify CXX=hipcc, to let hipcc
+# compile. Another important function is src_test, which checks whether a valid
+# KFD device exists for testing, and then execute the test program.
+#
+# 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.
+#
+# @EXAMPLE:
+# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
+# @CODE
+# inherit cmake rocm
+# 
SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz
 -> ${P}.tar.gz"
+# 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}]
+# "
+#
+# S=${WORKDIR}/${PN}-rocm-${PV}
+#
+# src_configure() {
+# local mycmakeargs=(
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# rocm_src_configure
+# }
+#
+# src_test() {
+# rocm_src_test
+# }
+# @CODE
+#
+# # Example for packages depend on ROCm libraries -- a package depend on
+# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
+# # architecture to compile. Requires ROCm version >5.
+# @CODE
+# ROCM_VERSION=5
+# 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
+# }
+# @CODE
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case ${EAPI} in
+   7|8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. Default is ${PV}, but for other packages
+# that depend on ROCm libraries, this can be set to match the version of
+# required ROCm libraries.
+
+# @ECLASS_VARIABLE: ALL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all AMDGPU targets in this ROCm
+# version. The value depends on ${PV}. Architectures and devices map:
+# https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2
+
+# @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all officially supported AMDGPU
+# targets in this ROCm version, documented at
+# 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
+# USE flag of these architectures will be default on. Depends on ${PV}.
+
+# @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 arc

[gentoo-dev] [PATCH v4 0/2] *** rocm.eclass: new eclass ***

2022-08-27 Thread Yiyang Wu
The v4 patches fixes a bug about determining whether ${gpu_target} is in
${OFFICIAL_AMDGPU_TARGETS[*]}. Nothing else has changed, and the eclass
works as expected in my experiment ebuilds on sci-libs/roc*.

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

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

Interdiff against v3:
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 4b220db0aa81..225329df4876 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -159,7 +159,7 @@ _rocm_set_globals() {
 
ROCM_REQUIRED_USE+=" || ("
for gpu_target in "${ALL_AMDGPU_TARGETS[@]}"; do
-   if has ${gpu_target} "${OFFICIAL_AMDGPU_TARGETS[*]}"; then
+   if has "${gpu_target}" ${OFFICIAL_AMDGPU_TARGETS[*]}; then
IUSE+=" ${gpu_target/#/+amdgpu_targets_}"
else
IUSE+=" ${gpu_target/#/amdgpu_targets_}"
-- 
2.34.1




[gentoo-dev] [PATCH v3 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-08-21 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 profiles/desc/amdgpu_targets.desc | 15 +++
 1 file changed, 15 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 ..8a3db2b56dab
--- /dev/null
+++ b/profiles/desc/amdgpu_targets.desc
@@ -0,0 +1,15 @@
+# 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
+
+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




[gentoo-dev] [PATCH v3 1/2] rocm.eclass: new eclass

2022-08-21 Thread Yiyang Wu
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 
---
 eclass/rocm.eclass  | 278 
 profiles/base/make.defaults |   2 +-
 2 files changed, 279 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index ..4b220db0aa81
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,278 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/* can utilize functions in this
+# eclass.  Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so
+# user can use USE flag to control which GPU architecture to compile, and
+# ensure coherence among dependencies. It also specify CXX=hipcc, to let hipcc
+# compile. Another important function is src_test, which checks whether a valid
+# KFD device exists for testing, and then execute the test program.
+#
+# 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.
+#
+# @EXAMPLE:
+# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
+# @CODE
+# inherit cmake rocm
+# 
SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz
 -> ${P}.tar.gz"
+# 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}]
+# "
+#
+# S=${WORKDIR}/${PN}-rocm-${PV}
+#
+# src_configure() {
+# local mycmakeargs=(
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# rocm_src_configure
+# }
+#
+# src_test() {
+# rocm_src_test
+# }
+# @CODE
+#
+# # Example for packages depend on ROCm libraries -- a package depend on
+# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
+# # architecture to compile. Requires ROCm version >5.
+# @CODE
+# ROCM_VERSION=5
+# 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
+# }
+# @CODE
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case ${EAPI} in
+   7|8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. Default is ${PV}, but for other packages
+# that depend on ROCm libraries, this can be set to match the version of
+# required ROCm libraries.
+
+# @ECLASS_VARIABLE: ALL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all AMDGPU targets in this ROCm
+# version. The value depends on ${PV}. Architectures and devices map:
+# https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2
+
+# @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all officially supported AMDGPU
+# targets in this ROCm version, documented at
+# 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
+# USE flag of these architectures will be default on. Depends on ${PV}.
+
+# @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 arc

[gentoo-dev] [PATCH v3 0/2] rocm.eclass: new eclass for ROCm packages

2022-08-21 Thread Yiyang Wu
From: YiyangWu 

This v3 fixes various problems pointed out by Ulrich. The most important
change, is that check_rw_permission cannot accept wildcards (it is
previously designed to enable wildcard, but I implemented it with bugs,
so I turned to disabling wildcard and loop around devices).

Updated patch is also accessible in
https://github.com/gentoo/gentoo/pull/26784, with QA check by qa-bot.

Changelog compare to v2:
1. Re-wrap description, <80 characters;
2. correct version detection;
3. decorate code block using @CODE;
4. standardize EAPI check copied from multilib-minimal.eclass;
5. correct quotation mark usage (which fixes ROCM_TESTS iteration);
6. use has function to test variable inside array;
7. fix typo;
8. avoid using internal portage variables;
9. disable wildcard in check_rw_permission; iterate devices to check;
10. referece bug #817440 in commit message.

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

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

Interdiff against v2:
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index 8ca2c051ddce..4b220db0aa81 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -9,12 +9,12 @@
 # @SUPPORTED_EAPIS: 7 8
 # @BLURB: Common functions and variables for ROCm packages written in HIP
 # @DESCRIPTION:
-# ROCm packages such as sci-libs/* can utilize functions in this 
eclass.
-# Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so user can
-# use USE flag to control which GPU architecture to compile, and ensure 
coherence
-# among dependencies. It also specify CXX=hipcc, to let hipcc compile. Another
-# important function is src_test, which checks whether a valid KFD device 
exists
-# for testing, and then execute the test program.
+# ROCm packages such as sci-libs/* can utilize functions in this
+# eclass.  Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so
+# user can use USE flag to control which GPU architecture to compile, and
+# ensure coherence among dependencies. It also specify CXX=hipcc, to let hipcc
+# compile. Another important function is src_test, which checks whether a valid
+# KFD device exists for testing, and then execute the test program.
 #
 # 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
@@ -22,6 +22,7 @@
 #
 # @EXAMPLE:
 # # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
+# @CODE
 # inherit cmake rocm
 # 
SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz
 -> ${P}.tar.gz"
 # SLOT="0/$(ver_cut 1-2)"
@@ -46,10 +47,12 @@
 # src_test() {
 # rocm_src_test
 # }
+# @CODE
 #
 # # Example for packages depend on ROCm libraries -- a package depend on
 # # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
 # # architecture to compile. Requires ROCm version >5.
+# @CODE
 # ROCM_VERSION=5
 # inherit rocm
 # IUSE="rocm"
@@ -64,20 +67,17 @@
 # fi
 # default
 # }
+# @CODE
 
 if [[ ! ${_ROCM_ECLASS} ]]; then
 
-case "${EAPI:-0}" in
-   7|8)
-   ;;
-   *)
-   die "Unsupported EAPI=${EAPI} for ${ECLASS}"
-   ;;
+case ${EAPI} in
+   7|8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
 esac
 
 inherit edo
 
-
 # @ECLASS_VARIABLE: ROCM_VERSION
 # @DEFAULT_UNSET
 # @PRE_INHERIT
@@ -96,7 +96,7 @@ inherit edo
 # @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
 # @INTERNAL
 # @DESCRIPTION:
-# The list of USE flags corresponding to all officlially supported AMDGPU
+# The list of USE flags corresponding to all officially supported AMDGPU
 # targets in this ROCm version, documented at
 # 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
 # USE flag of these architectures will be default on. Depends on ${PV}.
@@ -106,10 +106,14 @@ inherit edo
 # @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
@@ -130,7 +134,7 @@ inherit edo
 # OFFICIAL_AMDGPU_TARGETS, ROCM_REQUIRED_USE, and ROCM_USEDEP
 _rocm_set_globals() {
case ${ROCM_VERSION:-${PV}} in
-   4*)
+   4.*)
ALL_AMDGPU_TARGETS=(
gfx803 gfx900 gfx906 gfx908
gfx1010 gfx10

[gentoo-dev] [PATCH v2 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-08-15 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
Signed-off-by: YiyangWu 
---
 profiles/desc/amdgpu_targets.desc | 15 +++
 1 file changed, 15 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 ..8a3db2b56dab
--- /dev/null
+++ b/profiles/desc/amdgpu_targets.desc
@@ -0,0 +1,15 @@
+# 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
+
+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




[gentoo-dev] [PATCH v2 1/2] rocm.eclass: new eclass

2022-08-15 Thread Yiyang Wu
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
Signed-off-by: YiyangWu 
---
 eclass/rocm.eclass  | 275 
 profiles/base/make.defaults |   2 +-
 2 files changed, 276 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index ..8ca2c051ddce
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,275 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/* can utilize functions in this 
eclass.
+# Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so user can
+# use USE flag to control which GPU architecture to compile, and ensure 
coherence
+# among dependencies. It also specify CXX=hipcc, to let hipcc compile. Another
+# important function is src_test, which checks whether a valid KFD device 
exists
+# for testing, and then execute the test program.
+#
+# 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.
+#
+# @EXAMPLE:
+# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
+# inherit cmake rocm
+# 
SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz
 -> ${P}.tar.gz"
+# 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}]
+# "
+#
+# S=${WORKDIR}/${PN}-rocm-${PV}
+#
+# src_configure() {
+# local mycmakeargs=(
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# rocm_src_configure
+# }
+#
+# src_test() {
+# rocm_src_test
+# }
+#
+# # Example for packages depend on ROCm libraries -- a package depend on
+# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
+# # architecture to compile. Requires ROCm version >5.
+# ROCM_VERSION=5
+# 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
+# }
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case "${EAPI:-0}" in
+   7|8)
+   ;;
+   *)
+   die "Unsupported EAPI=${EAPI} for ${ECLASS}"
+   ;;
+esac
+
+inherit edo
+
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. Default is ${PV}, but for other packages
+# that depend on ROCm libraries, this can be set to match the version of
+# required ROCm libraries.
+
+# @ECLASS_VARIABLE: ALL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all AMDGPU targets in this ROCm
+# version. The value depends on ${PV}. Architectures and devices map:
+# https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2
+
+# @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all officlially supported AMDGPU
+# targets in this ROCm version, documented at
+# 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
+# USE flag of these architectures will be default on. Depends on ${PV}.
+
+# @ECLASS_VARIABLE: ROCM_REQUIRED_USE
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Requires at least one AMDGPU target to be compiled.
+# Example use for ROCm libraries:
+# REQUIRED_USE="${ROCM_REQUIRED_USE}"
+# Example use for packages that depend on ROCm libraries
+# IUSE="rocm"
+# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )"
+
+# @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 co

[gentoo-dev] [PATCH v2 0/2] rocm.eclass: new eclass for ROCm packages

2022-08-15 Thread Yiyang Wu
From: YiyangWu 

This update fixes problems pointed out last week on rocm.eclass.

Changelog from v1:
1. Change to the mordern EAPI check style;
2. fix typo in amdgpu_targets.desc;
3. remove trailing space in comments

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

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

Interdiff against v1:
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
index e4b448f7b894..8ca2c051ddce 100644
--- a/eclass/rocm.eclass
+++ b/eclass/rocm.eclass
@@ -19,7 +19,7 @@
 # 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.
-# 
+#
 # @EXAMPLE:
 # # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
 # inherit cmake rocm
@@ -28,25 +28,25 @@
 # IUSE="test"
 # REQUIRED_USE="${ROCM_REQUIRED_USE}"
 # RESTRICT="!test? ( test )"
-#  
+#
 # RDEPEND="
 # dev-util/hip
 # 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
 # }
-# 
+#
 # src_test() {
 # rocm_src_test
 # }
-# 
+#
 # # Example for packages depend on ROCm libraries -- a package depend on
 # # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
 # # architecture to compile. Requires ROCm version >5.
@@ -67,14 +67,11 @@
 
 if [[ ! ${_ROCM_ECLASS} ]]; then
 
-case ${EAPI} in
-   0|1|2|3|4|5|6)
-   die "${ECLASS}: unsupported EAPI=${EAPI:-0} (too old)"
-   ;;
+case "${EAPI:-0}" in
7|8)
;;
*)
-   die "${ECLASS}: unsupported EAPI=${EAPI} (unknown)"
+   die "Unsupported EAPI=${EAPI} for ${ECLASS}"
;;
 esac
 
diff --git a/profiles/desc/amdgpu_targets.desc 
b/profiles/desc/amdgpu_targets.desc
index 942ab51356fb..8a3db2b56dab 100644
--- a/profiles/desc/amdgpu_targets.desc
+++ b/profiles/desc/amdgpu_targets.desc
@@ -8,7 +8,7 @@ gfx900 - Vega GPU, codename vega10, including Radeon Vega 
Frontier Edition, Rade
 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
+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
-- 
2.34.1




[gentoo-dev] [PATCH 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND

2022-08-08 Thread Yiyang Wu
Signed-off-by: Yiyang Wu 
---
 profiles/desc/amdgpu_targets.desc | 15 +++
 1 file changed, 15 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 ..942ab51356fb
--- /dev/null
+++ b/profiles/desc/amdgpu_targets.desc
@@ -0,0 +1,15 @@
+# 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
+
+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




[gentoo-dev] [PATCH 1/2] rocm.eclass: new eclass

2022-08-08 Thread Yiyang Wu
Closes: https://bugs.gentoo.org/810619
Signed-off-by: YiyangWu 
---
 eclass/rocm.eclass  | 278 
 profiles/base/make.defaults |   2 +-
 2 files changed, 279 insertions(+), 1 deletion(-)
 create mode 100644 eclass/rocm.eclass

diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
new file mode 100644
index ..e4b448f7b894
--- /dev/null
+++ b/eclass/rocm.eclass
@@ -0,0 +1,278 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: rocm.eclass
+# @MAINTAINER:
+# Gentoo Science Project 
+# @AUTHOR:
+# Yiyang Wu 
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Common functions and variables for ROCm packages written in HIP
+# @DESCRIPTION:
+# ROCm packages such as sci-libs/* can utilize functions in this 
eclass.
+# Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so user can
+# use USE flag to control which GPU architecture to compile, and ensure 
coherence
+# among dependencies. It also specify CXX=hipcc, to let hipcc compile. Another
+# important function is src_test, which checks whether a valid KFD device 
exists
+# for testing, and then execute the test program.
+#
+# 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.
+# 
+# @EXAMPLE:
+# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
+# inherit cmake rocm
+# 
SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz
 -> ${P}.tar.gz"
+# 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}]
+# "
+# 
+# S=${WORKDIR}/${PN}-rocm-${PV}
+#  
+# src_configure() {
+# local mycmakeargs=(
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF)
+# )
+# rocm_src_configure
+# }
+# 
+# src_test() {
+# rocm_src_test
+# }
+# 
+# # Example for packages depend on ROCm libraries -- a package depend on
+# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
+# # architecture to compile. Requires ROCm version >5.
+# ROCM_VERSION=5
+# 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
+# }
+
+if [[ ! ${_ROCM_ECLASS} ]]; then
+
+case ${EAPI} in
+   0|1|2|3|4|5|6)
+   die "${ECLASS}: unsupported EAPI=${EAPI:-0} (too old)"
+   ;;
+   7|8)
+   ;;
+   *)
+   die "${ECLASS}: unsupported EAPI=${EAPI} (unknown)"
+   ;;
+esac
+
+inherit edo
+
+
+# @ECLASS_VARIABLE: ROCM_VERSION
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The ROCm version of current package. Default is ${PV}, but for other packages
+# that depend on ROCm libraries, this can be set to match the version of
+# required ROCm libraries.
+
+# @ECLASS_VARIABLE: ALL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all AMDGPU targets in this ROCm
+# version. The value depends on ${PV}. Architectures and devices map:
+# https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2
+
+# @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
+# @INTERNAL
+# @DESCRIPTION:
+# The list of USE flags corresponding to all officlially supported AMDGPU
+# targets in this ROCm version, documented at
+# 
https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
+# USE flag of these architectures will be default on. Depends on ${PV}.
+
+# @ECLASS_VARIABLE: ROCM_REQUIRED_USE
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Requires at least one AMDGPU target to be compiled.
+# Example use for ROCm libraries:
+# REQUIRED_USE="${ROCM_REQUIRED_USE}"
+# Example use for packages that depend on ROCm libraries
+# IUSE="rocm"
+# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )"
+
+# @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 used by the eclass: ALL_AMDGPU_TARGETS,
+# OFFICIAL_AMDGPU_TARGET

[gentoo-dev] [PATCH 0/2] rocm.eclass for ROCm packages written in HIP

2022-08-08 Thread Yiyang Wu
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.

This is the core delivery in GSoC 2022 project "Refining ROCm Packages
in Gentoo"

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

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

-- 
2.34.1