1 |
This eclass provides utilities for ROCm libraries in |
2 |
https://github.com/ROCmSoftwarePlatform, e.g. rocBLAS, rocFFT. |
3 |
It contains a USE_EXPAND, amdgpu_targets_*, which handles the GPU |
4 |
architecture to compile, and keep targets coherent among dependencies. |
5 |
Packages that depend on ROCm libraries, like cupy, can also make use of |
6 |
this eclass, mainly specify GPU architecture and it's corresponding |
7 |
dependencies via USE_EXPAND. |
8 |
|
9 |
Closes: https://bugs.gentoo.org/810619 |
10 |
Bugs: https://bugs.gentoo.org/817440 |
11 |
Signed-off-by: Yiyang Wu <xgreenlandforwyy@×××××.com> |
12 |
--- |
13 |
eclass/rocm.eclass | 223 ++++++++++++++++++++++++++++++++++++ |
14 |
profiles/base/make.defaults | 2 +- |
15 |
2 files changed, 224 insertions(+), 1 deletion(-) |
16 |
create mode 100644 eclass/rocm.eclass |
17 |
|
18 |
diff --git a/eclass/rocm.eclass b/eclass/rocm.eclass |
19 |
new file mode 100644 |
20 |
index 000000000000..4c8fd39f2491 |
21 |
--- /dev/null |
22 |
+++ b/eclass/rocm.eclass |
23 |
@@ -0,0 +1,223 @@ |
24 |
+# Copyright 2022 Gentoo Authors |
25 |
+# Distributed under the terms of the GNU General Public License v2 |
26 |
+ |
27 |
+# @ECLASS: rocm.eclass |
28 |
+# @MAINTAINER: |
29 |
+# Gentoo Science Project <sci@g.o> |
30 |
+# @AUTHOR: |
31 |
+# Yiyang Wu <xgreenlandforwyy@×××××.com> |
32 |
+# @SUPPORTED_EAPIS: 7 8 |
33 |
+# @BLURB: Common functions and variables for ROCm packages written in HIP |
34 |
+# @DESCRIPTION: |
35 |
+# ROCm packages such as sci-libs/<roc|hip>*, and packages built on top of ROCm |
36 |
+# libraries, can utilize variables and functions provided by this eclass. |
37 |
+# It handles the AMDGPU_TARGETS variable via USE_EXPAND, so user can |
38 |
+# edit USE flag to control which GPU architecture to compile. Using |
39 |
+# ${ROCM_USEDEP} can ensure coherence among dependencies. Ebuilds can call the |
40 |
+# function get_amdgpu_flag to translate activated target to GPU compile flags, |
41 |
+# passing it to configuration. Function check_amdgpu can help ebuild ensure |
42 |
+# read and write permissions to GPU device in src_test phase, throwing friendly |
43 |
+# error message if unavailable. |
44 |
+# |
45 |
+# @EXAMPLE: |
46 |
+# Example ebuild for ROCm library in https://github.com/ROCmSoftwarePlatform |
47 |
+# which uses cmake to build and test, and depends on rocBLAS: |
48 |
+# @CODE |
49 |
+# ROCM_VERSION=${PV} |
50 |
+# inherit cmake rocm |
51 |
+# # ROCm libraries SRC_URI is usually in form of: |
52 |
+# SRC_URI="https://github.com/ROCmSoftwarePlatform/${PN}/archive/rocm-${PV}.tar.gz -> ${P}.tar.gz" |
53 |
+# S=${WORKDIR}/${PN}-rocm-${PV} |
54 |
+# SLOT="0/$(ver_cut 1-2)" |
55 |
+# IUSE="test" |
56 |
+# REQUIRED_USE="${ROCM_REQUIRED_USE}" |
57 |
+# RESTRICT="!test? ( test )" |
58 |
+# |
59 |
+# RDEPEND=" |
60 |
+# dev-util/hip |
61 |
+# sci-libs/rocBLAS:${SLOT}[${ROCM_USEDEP}] |
62 |
+# " |
63 |
+# |
64 |
+# src_configure() { |
65 |
+# # avoid sandbox violation |
66 |
+# addpredict /dev/kfd |
67 |
+# addpredict /dev/dri/ |
68 |
+# local mycmakeargs=( |
69 |
+# -DAMDGPU_TARGETS="$(get_amdgpu_flags)" |
70 |
+# -DBUILD_CLIENTS_TESTS=$(usex test ON OFF) |
71 |
+# ) |
72 |
+# CXX=hipcc cmake_src_configure |
73 |
+# } |
74 |
+# |
75 |
+# src_test() { |
76 |
+# check_amdgpu |
77 |
+# # export LD_LIBRARY_PATH=<path to built lib dir> if necessary |
78 |
+# cmake_src_test # for packages using the cmake test |
79 |
+# # For packages using a standalone test binary rather than cmake test, |
80 |
+# # just execute it (or using edob) |
81 |
+# } |
82 |
+# @CODE |
83 |
+# |
84 |
+# Examples for packages depend on ROCm libraries -- a package which depends on |
85 |
+# rocBLAS, uses comma separated ${HCC_AMDGPU_TARGET} to determine GPU |
86 |
+# architectures, and requires ROCm version >=5.1 |
87 |
+# @CODE |
88 |
+# ROCM_VERSION=5.1 |
89 |
+# inherit rocm |
90 |
+# IUSE="rocm" |
91 |
+# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )" |
92 |
+# DEPEND="rocm? ( >=dev-util/hip-${ROCM_VERSION} |
93 |
+# >=sci-libs/rocBLAS-${ROCM_VERSION}[${ROCM_USEDEP}] )" |
94 |
+# |
95 |
+# src_configure() { |
96 |
+# if use rocm; then |
97 |
+# local amdgpu_flags=$(get_amdgpu_flags) |
98 |
+# export HCC_AMDGPU_TARGET=${amdgpu_flags//;/,} |
99 |
+# fi |
100 |
+# default |
101 |
+# } |
102 |
+# src_test() { |
103 |
+# use rocm && check_amdgpu |
104 |
+# default |
105 |
+# } |
106 |
+# @CODE |
107 |
+ |
108 |
+if [[ ! ${_ROCM_ECLASS} ]]; then |
109 |
+ |
110 |
+case ${EAPI} in |
111 |
+ 7|8) ;; |
112 |
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; |
113 |
+esac |
114 |
+ |
115 |
+# @ECLASS_VARIABLE: ROCM_VERSION |
116 |
+# @REQUIRED |
117 |
+# @PRE_INHERIT |
118 |
+# @DESCRIPTION: |
119 |
+# The ROCm version of current package. For ROCm libraries, it should be ${PV}; |
120 |
+# for other packages that depend on ROCm libraries, this can be set to match |
121 |
+# the version required for ROCm libraries. |
122 |
+ |
123 |
+# @ECLASS_VARIABLE: ROCM_REQUIRED_USE |
124 |
+# @OUTPUT_VARIABLE |
125 |
+# @DESCRIPTION: |
126 |
+# Requires at least one AMDGPU target to be compiled. |
127 |
+# Example use for ROCm libraries: |
128 |
+# @CODE |
129 |
+# REQUIRED_USE="${ROCM_REQUIRED_USE}" |
130 |
+# @CODE |
131 |
+# Example use for packages that depend on ROCm libraries: |
132 |
+# @CODE |
133 |
+# IUSE="rocm" |
134 |
+# REQUIRED_USE="rocm? ( ${ROCM_REQUIRED_USE} )" |
135 |
+# @CODE |
136 |
+ |
137 |
+# @ECLASS_VARIABLE: ROCM_USEDEP |
138 |
+# @OUTPUT_VARIABLE |
139 |
+# @DESCRIPTION: |
140 |
+# This is an eclass-generated USE-dependency string which can be used to |
141 |
+# depend on another ROCm package being built for the same AMDGPU architecture. |
142 |
+# |
143 |
+# The generated USE-flag list is compatible with packages using rocm.eclass. |
144 |
+# |
145 |
+# Example use: |
146 |
+# @CODE |
147 |
+# DEPEND="sci-libs/rocBLAS[${ROCM_USEDEP}]" |
148 |
+# @CODE |
149 |
+ |
150 |
+# @FUNCTION: _rocm_set_globals |
151 |
+# @DESCRIPTION: |
152 |
+# Set global variables useful to ebuilds: IUSE, ROCM_REQUIRED_USE, and |
153 |
+# ROCM_USEDEP |
154 |
+_rocm_set_globals() { |
155 |
+ # Two lists of AMDGPU_TARGETS of certain ROCm version. Official support |
156 |
+ # matrix: |
157 |
+ # https://docs.amd.com/bundle/ROCm-Installation-Guide-v${ROCM_VERSION}/page/Prerequisite_Actions.html. |
158 |
+ # There is no well-known unofficial support matrix. |
159 |
+ # https://github.com/Bengt/ROCm/blob/patch-2/README.md#library-target-matrix |
160 |
+ # may help. Gentoo have patches to enable gfx1031 as well. |
161 |
+ local unofficial_amdgpu_targets official_amdgpu_targets |
162 |
+ case ${ROCM_VERSION} in |
163 |
+ 4.*) |
164 |
+ unofficial_amdgpu_targets=( |
165 |
+ gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1030 |
166 |
+ ) |
167 |
+ official_amdgpu_targets=( |
168 |
+ gfx906 gfx908 |
169 |
+ ) |
170 |
+ ;; |
171 |
+ 5.*) |
172 |
+ unofficial_amdgpu_targets=( |
173 |
+ gfx803 gfx900 gfx1010 gfx1011 gfx1012 gfx1031 |
174 |
+ ) |
175 |
+ official_amdgpu_targets=( |
176 |
+ gfx906 gfx908 gfx90a gfx1030 |
177 |
+ ) |
178 |
+ ;; |
179 |
+ *) |
180 |
+ die "Unknown ROCm major version! Please update rocm.eclass before bumping to new ebuilds" |
181 |
+ ;; |
182 |
+ esac |
183 |
+ |
184 |
+ local iuse_flags=( |
185 |
+ "${official_amdgpu_targets[@]/#/+amdgpu_targets_}" |
186 |
+ "${unofficial_amdgpu_targets[@]/#/amdgpu_targets_}" |
187 |
+ ) |
188 |
+ IUSE="${iuse_flags[*]}" |
189 |
+ |
190 |
+ local all_amdgpu_targets=( |
191 |
+ "${official_amdgpu_targets[@]}" |
192 |
+ "${unofficial_amdgpu_targets[@]}" |
193 |
+ ) |
194 |
+ local allflags=( "${all_amdgpu_targets[@]/#/amdgpu_targets_}" ) |
195 |
+ ROCM_REQUIRED_USE=" || ( ${allflags[*]} )" |
196 |
+ |
197 |
+ local optflags=${allflags[@]/%/(-)?} |
198 |
+ ROCM_USEDEP=${optflags// /,} |
199 |
+} |
200 |
+_rocm_set_globals |
201 |
+unset -f _rocm_set_globals |
202 |
+ |
203 |
+ |
204 |
+# @FUNCTION: get_amdgpu_flags |
205 |
+# @USAGE: get_amdgpu_flags |
206 |
+# @DESCRIPTION: |
207 |
+# Convert specified use flag of amdgpu_targets to compilation flags. |
208 |
+# Append default target feature to GPU arch. See |
209 |
+# https://llvm.org/docs/AMDGPUUsage.html#target-features |
210 |
+get_amdgpu_flags() { |
211 |
+ local amdgpu_target_flags |
212 |
+ for gpu_target in ${AMDGPU_TARGETS}; do |
213 |
+ local target_feature= |
214 |
+ case ${gpu_target} in |
215 |
+ gfx906|gfx908) |
216 |
+ target_feature=:xnack- |
217 |
+ ;; |
218 |
+ gfx90a) |
219 |
+ target_feature=:xnack+ |
220 |
+ ;; |
221 |
+ *) |
222 |
+ ;; |
223 |
+ esac |
224 |
+ amdgpu_target_flags+="${gpu_target}${target_feature};" |
225 |
+ done |
226 |
+ echo "${amdgpu_target_flags}" |
227 |
+} |
228 |
+ |
229 |
+# @FUNCTION: check_amdgpu |
230 |
+# @USAGE: check_amdgpu |
231 |
+# @DESCRIPTION: |
232 |
+# grant and check read-write permissions on AMDGPU devices, die if not available. |
233 |
+check_amdgpu() { |
234 |
+ for device in /dev/kfd /dev/dri/render*; do |
235 |
+ addwrite ${device} |
236 |
+ if [[ ! -r ${device} || ! -w ${device} ]]; then |
237 |
+ eerror "Cannot read or write ${device}!" |
238 |
+ eerror "Make sure it is present and check the permission." |
239 |
+ ewarn "By default render group have access to it. Check if portage user is in render group." |
240 |
+ die "${device} inaccessible" |
241 |
+ fi |
242 |
+ done |
243 |
+} |
244 |
+ |
245 |
+_ROCM_ECLASS=1 |
246 |
+fi |
247 |
diff --git a/profiles/base/make.defaults b/profiles/base/make.defaults |
248 |
index 326cb28de537..2c288d12d103 100644 |
249 |
--- a/profiles/base/make.defaults |
250 |
+++ b/profiles/base/make.defaults |
251 |
@@ -13,7 +13,7 @@ USE_EXPAND_VALUES_USERLAND="BSD GNU" |
252 |
|
253 |
# Env vars to expand into USE vars. Modifying this requires prior |
254 |
# discussion on gentoo-dev@l.g.o. |
255 |
-USE_EXPAND="ABI_MIPS ABI_S390 ABI_X86 ADA_TARGET ALSA_CARDS APACHE2_MODULES APACHE2_MPMS CALLIGRA_FEATURES CAMERAS COLLECTD_PLUGINS CPU_FLAGS_ARM CPU_FLAGS_PPC CPU_FLAGS_X86 CURL_SSL ELIBC FFTOOLS GPSD_PROTOCOLS GRUB_PLATFORMS INPUT_DEVICES KERNEL L10N LCD_DEVICES LIBREOFFICE_EXTENSIONS LLVM_TARGETS LUA_SINGLE_TARGET LUA_TARGETS MONKEYD_PLUGINS NGINX_MODULES_HTTP NGINX_MODULES_MAIL NGINX_MODULES_STREAM OFFICE_IMPLEMENTATION OPENMPI_FABRICS OPENMPI_OFED_FEATURES OPENMPI_RM PHP_TARGETS POSTGRES_TARGETS PYTHON_SINGLE_TARGET PYTHON_TARGETS QEMU_SOFTMMU_TARGETS QEMU_USER_TARGETS ROS_MESSAGES RUBY_TARGETS SANE_BACKENDS USERLAND UWSGI_PLUGINS VIDEO_CARDS VOICEMAIL_STORAGE XTABLES_ADDONS" |
256 |
+USE_EXPAND="ABI_MIPS ABI_S390 ABI_X86 ADA_TARGET ALSA_CARDS AMDGPU_TARGETS APACHE2_MODULES APACHE2_MPMS CALLIGRA_FEATURES CAMERAS COLLECTD_PLUGINS CPU_FLAGS_ARM CPU_FLAGS_PPC CPU_FLAGS_X86 CURL_SSL ELIBC FFTOOLS GPSD_PROTOCOLS GRUB_PLATFORMS INPUT_DEVICES KERNEL L10N LCD_DEVICES LIBREOFFICE_EXTENSIONS LLVM_TARGETS LUA_SINGLE_TARGET LUA_TARGETS MONKEYD_PLUGINS NGINX_MODULES_HTTP NGINX_MODULES_MAIL NGINX_MODULES_STREAM OFFICE_IMPLEMENTATION OPENMPI_FABRICS OPENMPI_OFED_FEATURES OPENMPI_RM PHP_TARGETS POSTGRES_TARGETS PYTHON_SINGLE_TARGET PYTHON_TARGETS QEMU_SOFTMMU_TARGETS QEMU_USER_TARGETS ROS_MESSAGES RUBY_TARGETS SANE_BACKENDS USERLAND UWSGI_PLUGINS VIDEO_CARDS VOICEMAIL_STORAGE XTABLES_ADDONS" |
257 |
|
258 |
# USE_EXPAND variables whose contents are not shown in package manager |
259 |
# output. Changes need discussion on gentoo-dev. |
260 |
-- |
261 |
2.34.1 |