1 |
The v6 fixes several issues raised in Github PR: |
2 |
https://github.com/gentoo/gentoo/pull/26784 |
3 |
|
4 |
Changelog against v5: |
5 |
|
6 |
1. Update outdated examples and comments |
7 |
2. QA fixes |
8 |
3. Rename rocm_src_{test,configure} to rocm-{test,configure} to avoid |
9 |
confusion |
10 |
4. Simplify rocm-test function |
11 |
5. Change the reference of AMDGPU targets and GPU product matching. |
12 |
|
13 |
|
14 |
Yiyang Wu (2): |
15 |
rocm.eclass: new eclass |
16 |
profiles/desc: add amdgpu_targets.desc for USE_EXPAND |
17 |
|
18 |
eclass/rocm.eclass | 284 ++++++++++++++++++++++++++++++ |
19 |
profiles/base/make.defaults | 2 +- |
20 |
profiles/desc/amdgpu_targets.desc | 17 ++ |
21 |
3 files changed, 302 insertions(+), 1 deletion(-) |
22 |
create mode 100644 eclass/rocm.eclass |
23 |
create mode 100644 profiles/desc/amdgpu_targets.desc |
24 |
|
25 |
Interdiff against v5: |
26 |
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass |
27 |
index 679b1af54e0a..1866d6b7cc94 100644 |
28 |
--- a/eclass/rocm.eclass |
29 |
+++ b/eclass/rocm.eclass |
30 |
@@ -18,13 +18,16 @@ |
31 |
# |
32 |
# Most ROCm packages use cmake as build system, so this eclass does not export |
33 |
# phase functions which overwrites the phase functions in cmake.eclass. Ebuild |
34 |
-# should explicitly call rocm_src_* in src_configure and src_test. |
35 |
+# should explicitly call rocm-{configure,test} in src_configure and src_test. |
36 |
# |
37 |
# @EXAMPLE: |
38 |
-# # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform |
39 |
# @CODE |
40 |
+# # Example ebuild for ROCm library in https://github.com/ROCmSoftwarePlatform |
41 |
+# # whcih depends on rocBLAS |
42 |
# inherit cmake rocm |
43 |
+# # ROCm libraries SRC_URI is usually in form of: |
44 |
# SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz -> ${P}.tar.gz" |
45 |
+# S=${WORKDIR}/${PN}-rocm-${PV} |
46 |
# SLOT="0/$(ver_cut 1-2)" |
47 |
# IUSE="test" |
48 |
# REQUIRED_USE="${ROCM_REQUIRED_USE}" |
49 |
@@ -35,17 +38,15 @@ |
50 |
# sci-libs/rocBLAS:${SLOT}[${ROCM_USEDEP}] |
51 |
# " |
52 |
# |
53 |
-# S=${WORKDIR}/${PN}-rocm-${PV} |
54 |
-# |
55 |
# src_configure() { |
56 |
# local mycmakeargs=( |
57 |
# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF) |
58 |
# ) |
59 |
-# rocm_src_configure |
60 |
+# rocm-configure |
61 |
# } |
62 |
# |
63 |
# src_test() { |
64 |
-# rocm_src_test |
65 |
+# rocm-test |
66 |
# } |
67 |
# @CODE |
68 |
# |
69 |
@@ -53,7 +54,7 @@ |
70 |
# # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU |
71 |
# # architecture to compile. Requires ROCm version >5. |
72 |
# @CODE |
73 |
-# ROCM_VERSION=5 |
74 |
+# ROCM_VERSION=5.1 |
75 |
# inherit rocm |
76 |
# IUSE="rocm" |
77 |
# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )" |
78 |
@@ -206,25 +207,31 @@ get_amdgpu_flags() { |
79 |
# @FUNCTION: check_rw_permission |
80 |
# @USAGE: check_rw_permission <file> |
81 |
# @DESCRIPTION: |
82 |
-# check read and write permissions on specific files. |
83 |
-# allow using wildcard, for example check_rw_permission /dev/dri/render* |
84 |
+# check read and write permissions on a specific file, die if no permission. |
85 |
+# @EXAMPLE: |
86 |
+# @CODE |
87 |
+# check_rw_permission /dev/kfd |
88 |
+# CODE |
89 |
check_rw_permission() { |
90 |
- [[ -r $1 ]] && [[ -w $1 ]] || die \ |
91 |
- "Portage do not have read or write permissions on $1! \n Make sure both are in render group and check the permissions." |
92 |
+ if [[ ! -r $1 ]] || [[ ! -w $1 ]]; then |
93 |
+ eerror "Portage do not have read or write permissions on $1!" |
94 |
+ eerror "Make sure both are in render group and check the permissions." |
95 |
+ die "No permissions on $1" |
96 |
+ fi |
97 |
} |
98 |
|
99 |
# == phase functions == |
100 |
|
101 |
-# @FUNCTION: rocm_src_configure |
102 |
+# @FUNCTION: rocm-configure |
103 |
# @DESCRIPTION: |
104 |
-# configure rocm packages, and setting common cmake arguments |
105 |
-rocm_src_configure() { |
106 |
- # allow acces to hardware |
107 |
+# configure rocm packages, and setting common cmake arguments. Only for ROCm |
108 |
+# libraries in https://github.com/ROCmSoftwarePlatform using cmake. |
109 |
+rocm-configure() { |
110 |
+ # avoid sandbox violation |
111 |
addpredict /dev/kfd |
112 |
addpredict /dev/dri/ |
113 |
|
114 |
mycmakeargs+=( |
115 |
- -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr" |
116 |
-DAMDGPU_TARGETS="$(get_amdgpu_flags)" |
117 |
-DCMAKE_SKIP_RPATH=TRUE |
118 |
) |
119 |
@@ -232,46 +239,45 @@ rocm_src_configure() { |
120 |
CXX="hipcc" cmake_src_configure |
121 |
} |
122 |
|
123 |
-# @FUNCTION: rocm_src_test |
124 |
+# @FUNCTION: rocm-test |
125 |
# @DESCRIPTION: |
126 |
-# Test whether valid GPU device is present. If so, find how to, and execute test. |
127 |
-# ROCm packages can have to test mechanism: |
128 |
+# Test whether valid GPU device is present. If so, execute test. |
129 |
+# @EXAMPLE: |
130 |
+# ROCm packages can have two test scenarioes: |
131 |
# 1. cmake_src_test. MAKEOPTS="-j1" ensures only one test on GPU at a time; |
132 |
-# 2. one single gtest binary called "${PN,,}"-test; |
133 |
-# 3. Some package like rocFFT have alternative test like rocfft-selftest; |
134 |
-# 4. Custome testing binaries like dev-libs/rccl. Use ${ROCM_TESTS} to specify. |
135 |
-rocm_src_test() { |
136 |
+# @CODE |
137 |
+# LD_LIBRARY_PATH=<path-to-lib> rocm-test --cmake |
138 |
+# @CODE |
139 |
+# 2. one gtest binary called "${PN,,}"-test in ${BUILD_DIR}/clients/staging; |
140 |
+# @CODE |
141 |
+# cd "${BUILD_DIR}"/clients/staging || die |
142 |
+# LD_LIBRARY_PATH=<path-to-lib> rocm-test "${PN,,}"-test |
143 |
+# @CODE |
144 |
+# Some packages like rocFFT have two test binaries like rocfft-selftest; |
145 |
+# packages like dev-libs/rccl have test binary with custom names. |
146 |
+# @CODE |
147 |
+# cd "${BUILD_DIR}"/clients/staging || die |
148 |
+# export LD_LIBRARY_PATH=<path-to-lib> |
149 |
+# cd <test-bin-location> || die |
150 |
+# rocm-test <test-bin-1> |
151 |
+# rocm-test <test-bin-2> |
152 |
+# @CODE |
153 |
+rocm-test() { |
154 |
# grant and check permissions on /dev/kfd and /dev/dri/render* |
155 |
for device in /dev/kfd /dev/dri/render*; do |
156 |
- addwrite ${device} |
157 |
- check_rw_permission ${device} |
158 |
+ addwrite "${device}" |
159 |
+ check_rw_permission "${device}" |
160 |
done |
161 |
|
162 |
- : ${LD_LIBRARY_PATH:="${BUILD_DIR}/clients:${BUILD_DIR}/src:${BUILD_DIR}/library:${BUILD_DIR}/library/src:${BUILD_DIR}/library/src/device"} |
163 |
- export LD_LIBRARY_PATH |
164 |
- if grep -q 'build test:' "${BUILD_DIR}"/build.ninja; then |
165 |
- MAKEOPTS="-j1" cmake_src_test |
166 |
- elif [[ -d ${BUILD_DIR}/clients/staging ]]; then |
167 |
- cd "${BUILD_DIR}/clients/staging" || die "Test directory not found!" |
168 |
- for test_program in "${PN,,}-"*test; do |
169 |
- if [[ -x ${test_program} ]]; then |
170 |
- edob ./${test_program} |
171 |
- else |
172 |
- die "The test program ${test_program} does not exist or cannot be excuted!" |
173 |
- fi |
174 |
- done |
175 |
- elif [[ -n ${ROCM_TESTS} ]]; then |
176 |
- for test_program in ${ROCM_TESTS}; do |
177 |
- cd "${BUILD_DIR}" || die |
178 |
- if [[ -x ${test_program} ]]; then |
179 |
- edob ./${test_program} |
180 |
- else |
181 |
- die "The test program ${test_program} does not exist or cannot be excuted!" |
182 |
- fi |
183 |
- done |
184 |
- else |
185 |
- die "There is no cmake tests, no \${ROCM_TESTS} executable provided, nor ${BUILD_DIR}/clients/staging where test program might be located." |
186 |
- fi |
187 |
+ case ${1} in |
188 |
+ --cmake) |
189 |
+ # Avoid multi jobs running that may cause GPU error or CPU overload |
190 |
+ MAKEOPTS="-j1" cmake_src_test |
191 |
+ ;; |
192 |
+ *) |
193 |
+ edob ./${1} |
194 |
+ ;; |
195 |
+ esac |
196 |
} |
197 |
|
198 |
_ROCM_ECLASS=1 |
199 |
diff --git a/profiles/desc/amdgpu_targets.desc b/profiles/desc/amdgpu_targets.desc |
200 |
index 8a3db2b56dab..df013d4f2c08 100644 |
201 |
--- a/profiles/desc/amdgpu_targets.desc |
202 |
+++ b/profiles/desc/amdgpu_targets.desc |
203 |
@@ -1,7 +1,9 @@ |
204 |
# Copyright 1999-2022 Gentoo Authors. |
205 |
# Distributed under the terms of the GNU General Public License v2 |
206 |
|
207 |
-# Copied from https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2/#fn:67 |
208 |
+# Referene: |
209 |
+# GPU name and Architecture codename: https://github.com/GPUOpen-Tools/device_info/blob/master/DeviceInfo.cpp |
210 |
+# See also: https://www.coelacanth-dream.com/posts/2019/12/30/did-rid-product-matome-p2/#fn:67 |
211 |
|
212 |
gfx803 - Fiji GPU, codename fiji, including Radeon R9 Nano/Fury/FuryX, Radeon Pro Duo, FirePro S9300x2, Radeon Instinct MI8 |
213 |
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 |
214 |
-- |
215 |
2.34.1 |