Gentoo Archives: gentoo-dev

From: Yiyang Wu <xgreenlandforwyy@×××××.com>
To: gentoo-dev@l.g.o
Cc: Benda Xu <heroxbd@g.o>, Ulrich Mueller <ulm@g.o>, YiyangWu <xgreenlandforwyy@×××××.com>
Subject: [gentoo-dev] [PATCH v3 0/2] rocm.eclass: new eclass for ROCm packages
Date: Sun, 21 Aug 2022 07:22:56
Message-Id: cover.1661065019.git.xgreenlandforwyy@gmail.com
1 From: YiyangWu <xgreenlandforwyy@×××××.com>
2
3 This v3 fixes various problems pointed out by Ulrich. The most important
4 change, is that check_rw_permission cannot accept wildcards (it is
5 previously designed to enable wildcard, but I implemented it with bugs,
6 so I turned to disabling wildcard and loop around devices).
7
8 Updated patch is also accessible in
9 https://github.com/gentoo/gentoo/pull/26784, with QA check by qa-bot.
10
11 Changelog compare to v2:
12 1. Re-wrap description, <80 characters;
13 2. correct version detection;
14 3. decorate code block using @CODE;
15 4. standardize EAPI check copied from multilib-minimal.eclass;
16 5. correct quotation mark usage (which fixes ROCM_TESTS iteration);
17 6. use has function to test variable inside array;
18 7. fix typo;
19 8. avoid using internal portage variables;
20 9. disable wildcard in check_rw_permission; iterate devices to check;
21 10. referece bug #817440 in commit message.
22
23 Yiyang Wu (2):
24 rocm.eclass: new eclass
25 profiles/desc: add amdgpu_targets.desc for USE_EXPAND
26
27 eclass/rocm.eclass | 278 ++++++++++++++++++++++++++++++
28 profiles/base/make.defaults | 2 +-
29 profiles/desc/amdgpu_targets.desc | 15 ++
30 3 files changed, 294 insertions(+), 1 deletion(-)
31 create mode 100644 eclass/rocm.eclass
32 create mode 100644 profiles/desc/amdgpu_targets.desc
33
34 Interdiff against v2:
35 diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass
36 index 8ca2c051ddce..4b220db0aa81 100644
37 --- a/eclass/rocm.eclass
38 +++ b/eclass/rocm.eclass
39 @@ -9,12 +9,12 @@
40 # @SUPPORTED_EAPIS: 7 8
41 # @BLURB: Common functions and variables for ROCm packages written in HIP
42 # @DESCRIPTION:
43 -# ROCm packages such as sci-libs/<roc|hip>* can utilize functions in this eclass.
44 -# Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so user can
45 -# use USE flag to control which GPU architecture to compile, and ensure coherence
46 -# among dependencies. It also specify CXX=hipcc, to let hipcc compile. Another
47 -# important function is src_test, which checks whether a valid KFD device exists
48 -# for testing, and then execute the test program.
49 +# ROCm packages such as sci-libs/<roc|hip>* can utilize functions in this
50 +# eclass. Currently, it handles the AMDGPU_TARGETS variable via USE_EXPAND, so
51 +# user can use USE flag to control which GPU architecture to compile, and
52 +# ensure coherence among dependencies. It also specify CXX=hipcc, to let hipcc
53 +# compile. Another important function is src_test, which checks whether a valid
54 +# KFD device exists for testing, and then execute the test program.
55 #
56 # Most ROCm packages use cmake as build system, so this eclass does not export
57 # phase functions which overwrites the phase functions in cmake.eclass. Ebuild
58 @@ -22,6 +22,7 @@
59 #
60 # @EXAMPLE:
61 # # Example for ROCm packages in https://github.com/ROCmSoftwarePlatform
62 +# @CODE
63 # inherit cmake rocm
64 # SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz -> ${P}.tar.gz"
65 # SLOT="0/$(ver_cut 1-2)"
66 @@ -46,10 +47,12 @@
67 # src_test() {
68 # rocm_src_test
69 # }
70 +# @CODE
71 #
72 # # Example for packages depend on ROCm libraries -- a package depend on
73 # # rocBLAS, and use comma seperated ${HCC_AMDGPU_TARGET} to determine GPU
74 # # architecture to compile. Requires ROCm version >5.
75 +# @CODE
76 # ROCM_VERSION=5
77 # inherit rocm
78 # IUSE="rocm"
79 @@ -64,20 +67,17 @@
80 # fi
81 # default
82 # }
83 +# @CODE
84
85 if [[ ! ${_ROCM_ECLASS} ]]; then
86
87 -case "${EAPI:-0}" in
88 - 7|8)
89 - ;;
90 - *)
91 - die "Unsupported EAPI=${EAPI} for ${ECLASS}"
92 - ;;
93 +case ${EAPI} in
94 + 7|8) ;;
95 + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
96 esac
97
98 inherit edo
99
100 -
101 # @ECLASS_VARIABLE: ROCM_VERSION
102 # @DEFAULT_UNSET
103 # @PRE_INHERIT
104 @@ -96,7 +96,7 @@ inherit edo
105 # @ECLASS_VARIABLE: OFFICIAL_AMDGPU_TARGETS
106 # @INTERNAL
107 # @DESCRIPTION:
108 -# The list of USE flags corresponding to all officlially supported AMDGPU
109 +# The list of USE flags corresponding to all officially supported AMDGPU
110 # targets in this ROCm version, documented at
111 # https://docs.amd.com/bundle/ROCm-Installation-Guide-v${PV}/page/Prerequisite_Actions.html.
112 # USE flag of these architectures will be default on. Depends on ${PV}.
113 @@ -106,10 +106,14 @@ inherit edo
114 # @DESCRIPTION:
115 # Requires at least one AMDGPU target to be compiled.
116 # Example use for ROCm libraries:
117 +# @CODE
118 # REQUIRED_USE="${ROCM_REQUIRED_USE}"
119 +# @CODE
120 # Example use for packages that depend on ROCm libraries
121 +# @CODE
122 # IUSE="rocm"
123 # REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )"
124 +# @CODE
125
126 # @ECLASS_VARIABLE: ROCM_USEDEP
127 # @OUTPUT_VARIABLE
128 @@ -130,7 +134,7 @@ inherit edo
129 # OFFICIAL_AMDGPU_TARGETS, ROCM_REQUIRED_USE, and ROCM_USEDEP
130 _rocm_set_globals() {
131 case ${ROCM_VERSION:-${PV}} in
132 - 4*)
133 + 4.*)
134 ALL_AMDGPU_TARGETS=(
135 gfx803 gfx900 gfx906 gfx908
136 gfx1010 gfx1011 gfx1012 gfx1030
137 @@ -139,7 +143,7 @@ _rocm_set_globals() {
138 gfx906 gfx908
139 )
140 ;;
141 - 5*)
142 + 5.*)
143 ALL_AMDGPU_TARGETS=(
144 gfx803 gfx900 gfx906 gfx908 gfx90a
145 gfx1010 gfx1011 gfx1012 gfx1030 gfx1031
146 @@ -154,8 +158,8 @@ _rocm_set_globals() {
147 esac
148
149 ROCM_REQUIRED_USE+=" || ("
150 - for gpu_target in ${ALL_AMDGPU_TARGETS[@]}; do
151 - if [[ " ${OFFICIAL_AMDGPU_TARGETS[*]} " =~ " ${gpu_target} " ]]; then
152 + for gpu_target in "${ALL_AMDGPU_TARGETS[@]}"; do
153 + if has ${gpu_target} "${OFFICIAL_AMDGPU_TARGETS[*]}"; then
154 IUSE+=" ${gpu_target/#/+amdgpu_targets_}"
155 else
156 IUSE+=" ${gpu_target/#/amdgpu_targets_}"
157 @@ -180,7 +184,7 @@ unset -f _rocm_set_globals
158 # https://llvm.org/docs/AMDGPUUsage.html#target-features
159 get_amdgpu_flags() {
160 local AMDGPU_TARGET_FLAGS
161 - for gpu_target in ${ALL_AMDGPU_TARGETS[@]}; do
162 + for gpu_target in "${ALL_AMDGPU_TARGETS[@]}"; do
163 local target_feature=
164 if use amdgpu_targets_${gpu_target}; then
165 case ${gpu_target} in
166 @@ -205,8 +209,8 @@ get_amdgpu_flags() {
167 # check read and write permissions on specific files.
168 # allow using wildcard, for example check_rw_permission /dev/dri/render*
169 check_rw_permission() {
170 - [[ -r "$1" ]] && [[ -w "$1" ]] || die \
171 - "${PORTAGE_USERNAME} do not have read or write permissions on $1! \n Make sure ${PORTAGE_USERNAME} is in render group and check the permissions."
172 + [[ -r $1 ]] && [[ -w $1 ]] || die \
173 + "Portage do not have read or write permissions on $1! \n Make sure both are in render group and check the permissions."
174 }
175
176 # == phase functions ==
177 @@ -232,23 +236,22 @@ rocm_src_configure() {
178 # @DESCRIPTION:
179 # Test whether valid GPU device is present. If so, find how to, and execute test.
180 # ROCm packages can have to test mechanism:
181 -# 1. cmake_src_test. Set MAKEOPTS="-j1" to make sure only one test on GPU at a time;
182 +# 1. cmake_src_test. MAKEOPTS="-j1" ensures only one test on GPU at a time;
183 # 2. one single gtest binary called "${PN,,}"-test;
184 # 3. Some package like rocFFT have alternative test like rocfft-selftest;
185 # 4. Custome testing binaries like dev-libs/rccl. Use ${ROCM_TESTS} to specify.
186 rocm_src_test() {
187 - addwrite /dev/kfd
188 - addwrite /dev/dri/
189 -
190 - # check permissions on /dev/kfd and /dev/dri/render*
191 - check_rw_permission /dev/kfd
192 - check_rw_permission /dev/dri/render*
193 + # grant and check permissions on /dev/kfd and /dev/dri/render*
194 + for device in /dev/kfd /dev/dri/render*; do
195 + addwrite ${device}
196 + check_rw_permission ${device}
197 + done
198
199 : ${LD_LIBRARY_PATH:="${BUILD_DIR}/clients:${BUILD_DIR}/src:${BUILD_DIR}/library:${BUILD_DIR}/library/src:${BUILD_DIR}/library/src/device"}
200 export LD_LIBRARY_PATH
201 if grep -q 'build test:' "${BUILD_DIR}"/build.ninja; then
202 MAKEOPTS="-j1" cmake_src_test
203 - elif [[ -d "${BUILD_DIR}"/clients/staging ]]; then
204 + elif [[ -d ${BUILD_DIR}/clients/staging ]]; then
205 cd "${BUILD_DIR}/clients/staging" || die "Test directory not found!"
206 for test_program in "${PN,,}-"*test; do
207 if [[ -x ${test_program} ]]; then
208 @@ -257,8 +260,8 @@ rocm_src_test() {
209 die "The test program ${test_program} does not exist or cannot be excuted!"
210 fi
211 done
212 - elif [[ ! -z "${ROCM_TESTS}" ]]; then
213 - for test_program in "${ROCM_TESTS}"; do
214 + elif [[ -n ${ROCM_TESTS} ]]; then
215 + for test_program in ${ROCM_TESTS}; do
216 cd "${BUILD_DIR}" || die
217 if [[ -x ${test_program} ]]; then
218 edob ./${test_program}
219 --
220 2.34.1

Replies

Subject Author
[gentoo-dev] [PATCH v3 1/2] rocm.eclass: new eclass Yiyang Wu <xgreenlandforwyy@×××××.com>
[gentoo-dev] [PATCH v3 2/2] profiles/desc: add amdgpu_targets.desc for USE_EXPAND Yiyang Wu <xgreenlandforwyy@×××××.com>