This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
forked from saitam757/Solus-ROCm-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amdgpu-install
executable file
·592 lines (524 loc) · 16.2 KB
/
amdgpu-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
#!/bin/bash
#
# Copyright 2016-2021 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
set -e # Exit immediately if a command fails
EULA_FILE=/usr/share/amdgpu-install/AMDGPUPROEULA
DKMS_PACKAGE=amdgpu-dkms
BASE_ROCM_PACKAGE=rocm-core
BASE_PACKAGES=("$DKMS_PACKAGE" amdgpu-core "$BASE_ROCM_PACKAGE")
OPENCL_ROCR_PACKAGE=rocm-opencl-runtime
USECASE_DKMS_PACKAGES=("$DKMS_PACKAGE")
USECASE_GRAPHICS_PACKAGES=(amdgpu-lib amdgpu-lib32)
USECASE_MULTIMEDIA_PACKAGES=(amdgpu-lib amdgpu-lib32)
USECASE_WORKSTATION_PACKAGES=(amdgpu-pro amdgpu-pro-lib32)
USECASE_AMF_PACKAGES=(amf-amdgpu-pro)
USECASE_ROCM_PACKAGES=(rocm-dev)
USECASE_LRT_PACKAGES=(rocm-language-runtime)
USECASE_OPENCL_PACKAGES=($OPENCL_ROCR_PACKAGE)
USECASE_OPENCLSDK_PACKAGES=(rocm-opencl-sdk)
USECASE_HIP_PACKAGES=(rocm-hip-runtime)
USECASE_HIPLIBSDK_PACKAGES=(rocm-hip-sdk)
USECASE_MLLIB_PACKAGES=(rocm-ml-libraries)
USECASE_MLSDK_PACKAGES=(rocm-ml-sdk)
OPENCL_ROCR_PACKAGES=($OPENCL_ROCR_PACKAGE)
OPENCL_LEGACY_PACKAGES=(clinfo-amdgpu-pro opencl-legacy-amdgpu-pro-icd)
VULKAN_AMDVLK_PACKAGES=(vulkan-amdgpu)
VULKAN_PRO_PACKAGES=(vulkan-amdgpu-pro vulkan-amdgpu-pro:i386)
VULKAN_RADV_PACKAGES=(mesa-vulkan-drivers)
usage() {
cat <<END_USAGE
Usage: $PROG [options...]
Options:
-h|--help Display this help message
--rocmrelease= Install a specific ROCm release. By default only
one release of ROCm can be installed. Using this
option will allow installation of multiple releases.
Note: when used during uninstall, the specific rocm
release will be removed. Use --rocmrelease=all
to uninstall all rocm releases.
END_USAGE
if [[ "$PROG" != *"uninstall" ]]; then
cat <<END_USAGE
--dryrun Print list of commands to run and exit
--pro (DEPRECATED) Install legacy OpenGL, pro Vulkan, and
open source multimedia. This is equivalent to:
$PROG --usecase=workstation --vulkan=pro
--usecase= Install a set of libraries for a specific use case
--list-usecase Show all available usecases and descriptions
--opencl= Install a specific OpenCL implementation. This option
implies the addition of the opencl usecase.
Available implementations:
rocr (ROCr/KFD based OpenCL)
legacy (Legacy OpenCL)
--vulkan= Install a specific vulkan implementation
Available implementations:
amdvlk (AMD open source implementation)
pro (AMD closed source implementation)
--no-dkms Do not install dkms and use built-in kernel driver
--no-32 Do not install 32 bit graphics runtime support
--accept-eula Accept EULA for this run only (for non-free install)
Note: only use this option if you accept the EULA
--uninstall Uninstall the graphics driver
Options --opencl/--vulkan/--usecase can be used together, e.g.:
$PROG --usecase=graphics --vulkan=amdvlk --opencl=rocr
Multiple implementations can be selected if comma separated, e.g.:
$PROG --usecase=graphics,opencl --opencl=rocr,legacy --vulkan=amdvlk,pro
Unless the -h|--help option is given, '$PKGMAN' options may be present
END_USAGE
fi
}
usecase_usage() {
cat <<END_USECASE_USAGE
If --usecase option is not present, the default selection is
"dkms,graphics,opencl,hip"
Available use cases:
dkms (to only install the kernel mode driver)
- Kernel mode driver (included in all usecases)
graphics (for users of graphics applications)
- Open source Mesa 3D graphics and multimedia libraries
multimedia (for users of open source multimedia)
- Open source Mesa 3D graphics and multimedia libraries
workstation (for users of legacy WS applications)
- Open source multimedia libraries
- Closed source (legacy) OpenGL
rocm (for users and developers requiring full ROCm stack)
- OpenCL (ROCr/KFD based) runtime
- HIP runtimes
- Machine learning framework
- All ROCm libraries and applications
amf (for users of AMF based multimedia)
- AMF closed source multimedia library
lrt (for users of applications requiring ROCm runtime)
- ROCm Compiler and device libraries
- ROCr runtime and thunk
opencl (for users of applications requiring OpenCL on Vega or later
products)
- ROCr based OpenCL
- ROCm Language runtime
openclsdk (for application developers requiring ROCr based OpenCL)
- ROCr based OpenCL
- ROCm Language runtime
- development and SDK files for ROCr based OpenCL
hip (for users of HIP runtime on AMD products)
- HIP runtimes
hiplibsdk (for application developers requiring HIP on AMD products)
- HIP runtimes
- ROCm math libraries
- HIP development libraries
mllib (for users/developers executing machine learning workloads)
- MIOpen hip/tensile libraries
- Clang OpenCL
- MIOpen kernels
END_USECASE_USAGE
}
function stderr() {
cat - 1>&2
}
function check_for_absence_of_nomodeset() {
if grep -q nomodeset "/proc/cmdline"; then
echo "WARNING: nomodeset detected in kernel parameters, "`
`"amdgpu requires KMS" | stderr
fi
}
function check_dkms_succeeded_for_running_kernel() {
if [[ ! "${OPTIONS[*]}" =~ "no-dkms" ]] && \
! /usr/sbin/dkms status amdgpu | grep `uname -r` | \
grep -q installed; then
echo "WARNING: amdgpu dkms failed for running kernel" | stderr
fi
}
function check_install() {
check_for_absence_of_nomodeset
check_dkms_succeeded_for_running_kernel
if [[ "${OPTIONS[*]}" =~ "accept-eula" ]]; then
echo -e "INFO: Using --accept-eula confirms acceptance of the"`
`" following license\n$EULA_FILE"
fi
}
function check_options() {
if [[ "${OPTIONS[*]}" =~ "no-dkms" ]]; then
if [[ "$USECASE_OPTION" =~ "dkms" ]]; then
echo -e "ERROR: '--no-dkms' and '--usecase=dkms' does"`
`" not install a valid set of packages" \
| stderr
exit 1
elif [[ "$USECASE_OPTION" =~ "workstation" ]]; then
echo -e "ERROR: using '--no-dkms' with "`
`"'--usecase=workstation' is not supported" \
| stderr
exit 1
elif [[ "$OPENCL_OPTION" =~ "legacy" ]]; then
echo -e "ERROR: using '--no-dkms' with "`
`"'--opencl=legacy' is not supported" \
| stderr
exit 1
fi
fi
}
function check_eula() {
if [[ "${OPTIONS[*]}" =~ "accept-eula" ]]; then
${OS_CLASS}_enable_propriety
trap ${OS_CLASS}_disable_propriety 0 ERR
elif [[ "${PACKAGES[*]}" =~ "amdgpu-pro" ]]; then
local checksumdir="/var/lib/amdgpu/eula_accepted.d"
local checksum="$(eula_hash)"
if [ ! -f "$checksumdir/$checksum" ]; then
if dialog --textbox $EULA_FILE 0 0 --yesno "Do you "`
`"agree with the end user license agreement?" \
0 0; then
clear
$SUDO mkdir -p "$checksumdir"
$SUDO touch "$checksumdir/$checksum"
${OS_CLASS}_enable_propriety
else
clear
echo -e "ERROR: EULA acceptance is required "`
`"to install requested packages" \
| stderr
exit 1
fi
fi
fi
}
function eula_hash() {
if [ -f "$EULA_FILE" ]; then
md5sum $EULA_FILE | cut -d' ' -f1
else
echo -e "ERROR: required $EULA_FILE does not exist." | stderr
exit 1
fi
}
function debian_enable_propriety() {
$SUDO sed -i 's/^#deb /deb /' \
/etc/apt/sources.list.d/amdgpu-proprietary.list
$SUDO $PKGMAN update
}
function fedora_enable_propriety() {
$SUDO sed -i 's/^enabled=0/enabled=1/' \
/etc/yum.repos.d/amdgpu-proprietary.repo
}
function suse_enable_propriety() {
$SUDO sed -i 's/^enabled=0/enabled=1/' \
/etc/zypp/repos.d/amdgpu-proprietary.repo
}
function debian_disable_propriety() {
$SUDO sed -i 's/^deb /#deb /' \
/etc/apt/sources.list.d/amdgpu-proprietary.list
$SUDO $PKGMAN update ||:
}
function fedora_disable_propriety() {
$SUDO sed -i 's/^enabled=1/enabled=0/' \
/etc/yum.repos.d/amdgpu-proprietary.repo
}
function suse_disable_propriety() {
$SUDO sed -i 's/^enabled=1/enabled=0/' \
/etc/zypp/repos.d/amdgpu-proprietary.repo
}
function os_release() {
if [[ -r /etc/os-release ]]; then
. /etc/os-release
PKGUPDATE=
case "$ID" in
ubuntu|linuxmint|debian)
PKGUPDATE="apt-get update"
PKGMAN=apt-get
OS_CLASS=debian
:
;;
fedora)
PKGMAN=dnf
OS_CLASS=fedora
RMPKG=erase
;;
rhel|centos|almalinux|rocky)
PKGMAN=yum
OS_CLASS=fedora
RMPKG=erase
;;
sles|sled|opensuse*)
PKGMAN=zypper
OS_CLASS=suse
RMPKG=remove
;;
amzn)
PKGMAN=yum
OS_CLASS=fedora
RMPKG=erase
;;
solus)
PKGMAN=eopkg
OS_CLASS=solus
RMPKG=remove
;;
*)
echo "Unsupported OS: `
`/etc/os-release ID '$ID'" | stderr
exit 1
;;
esac
else
echo "Unsupported OS" | stderr
exit 1
fi
}
function add_package_list() {
local listname="$1"
local option
local array=()
local listopts
eval listopts="\$${listname^^}_OPTION"
for option in ${listopts//,/ }; do
eval array=(\${${listname^^}_${option^^}_PACKAGES[*]})
if [[ -z "$array" ]]; then
echo "ERROR: $listname implementation '$option' is"`
`" not supported or invalid" | stderr
exit 1
fi
PACKAGES+=(${array[*]})
done
}
function debian_check_multi_rocm_install() {
dpkg -l | grep -q "$BASE_ROCM_PACKAGE[0-9]"
}
function fedora_check_multi_rocm_install() {
rpm -qa | grep -q "$BASE_ROCM_PACKAGE[0-9]"
}
function suse_check_multi_rocm_install() {
fedora_check_multi_rocm_install
}
function add_rocm_release() {
local i
if [[ -n "$ROCM_RELEASE" ]]; then
if [[ ! "${PACKAGES[*]}" =~ "rocm-" ]]; then
echo "ERROR: --rocmrelease option is used but no "`
`"ROCm package is to be installed" | stderr
exit 1
fi
if [[ "$ROCM_RELEASE" == "all" ]]; then
echo "ERROR: --rocmrelease=all is not a valid option "`
`"for install" | stderr
exit 1
fi
for i in "${!PACKAGES[@]}"; do
if [[ "${PACKAGES[$i]}" = rocm-* ]]; then
PACKAGES[$i]="${PACKAGES[$i]}$ROCM_RELEASE"
fi
done
elif ${OS_CLASS}_check_multi_rocm_install && \
[[ "${PACKAGES[*]}" =~ "rocm-" ]]; then
echo -e "ERROR: A multi-release ROCm install was detected on "`
`"the system.\nPlease specify --rocmrelease to "`
`"continue installing new rocm packages." | stderr
exit 1
fi
}
function check_version_list() {
local list="$(cat /usr/share/amdgpu*/*-versionlist 2>/dev/null | "`
`"awk -F'\"' '/AMDGPU_VERSION_LIST_/ {printf $2}')"
for i in ${!PACKAGES[@]}; do
for pkg in $list; do
if [[ "${pkg%%=*}" == "${PACKAGES[$i]}" ]]; then
if [[ "$DNF" == "yum" ]]; then
pkg="${pkg/=*:/=}"
fi
PACKAGES[$i]="${pkg/=/-}"
break
fi
done
done
}
function debian_build_package_list() {
if [[ ! "${OPTIONS[*]}" =~ "no-dkms" ]]; then
if apt-cache show linux-headers-$(uname -r) &>/dev/null; then
PACKAGES=(${PACKAGES[*]} linux-headers-$(uname -r))
fi
if apt-cache show linux-modules-extra-$(uname -r) &>/dev/null
then
PACKAGES=(${PACKAGES[*]} linux-modules-extra-$(uname -r))
fi
fi
}
function fedora_build_package_list() {
OPTIONS+=(no-32)
check_version_list
if [[ ! "${OPTIONS[*]}" =~ "no-dkms" ]] && \
! rpm --quiet -q kernel-devel-$(uname -r); then
PACKAGES=(${PACKAGES[*]} kernel-devel-$(uname -r))
fi
}
function suse_build_package_list() {
OPTIONS+=(no-32)
check_version_list
}
function build_package_list() {
local list=()
add_package_list "Usecase"
if [[ ! "${OPTIONS[*]}" =~ "no-dkms" ]] && \
[[ ! "$USECASE_OPTION" =~ "dkms" ]]; then
PACKAGES=(${PACKAGES[*]} $DKMS_PACKAGE)
fi
if [[ -n "$OPENCL_OPTION" ]]; then
PACKAGES=("${PACKAGES[@]/$OPENCL_ROCR_PACKAGE/}")
add_package_list "OpenCL"
fi
add_package_list "Vulkan"
${OS_CLASS}_build_package_list
if [[ "${OPTIONS[*]}" =~ "no-32" ]]; then
PACKAGES=("${PACKAGES[@]/*lib32/}")
PACKAGES=("${PACKAGES[@]/*i386/}")
fi
add_rocm_release
return 0
}
function amdgpu_install() {
check_options
build_package_list
if [[ "${OPTIONS[*]}" =~ "dryrun" ]]; then
${PKGUPDATE:+echo $SUDO $PKGUPDATE}
echo $SUDO $PKGMAN install ${1+"$@"} ${PACKAGES[*]}
echo $SUDO ln -sf $SCRIPT_DIR/$PROG $SBIN/${PROG%-*}-uninstall
return 0
fi
check_eula
${PKGUPDATE:+$SUDO $PKGUPDATE}
$SUDO $PKGMAN install ${1+"$@"} ${PACKAGES[*]}
$SUDO ln -sf $SCRIPT_DIR/$PROG $SBIN/${PROG%-*}-uninstall
check_install
}
function amdgpu_uninstall() {
if [[ -z "$ROCM_RELEASE" ]] && \
${OS_CLASS}_check_multi_rocm_install; then
echo -e "ERROR: A multi-release ROCm install was detected on "`
`"the system.\nPlease use --rocmrelease to specify "`
`"which release to remove, or use\n--rocmrelease=all "`
`"to uninstall everything." | stderr
exit 1
fi
${OS_CLASS}_amdgpu_uninstall "$@"
}
function debian_amdgpu_uninstall() {
local list=()
local i
for i in "${BASE_PACKAGES[@]}"; do
list=(${list[*]} $(dpkg -l \
| awk /"$i"/' { printf " %s",$2 }'))
done
[ ${#list[@]} -eq 0 ] || $SUDO $PKGMAN purge ${1+"$@"} "${list[@]}"
$SUDO rm -rf $SBIN/${PROG%-*}-uninstall
$SUDO $PKGMAN update ||:
}
function fedora_amdgpu_uninstall() {
local list=()
for i in "${BASE_PACKAGES[@]}"; do
list=(${list[*]} $(rpm -qa "$i"* \
| awk -F'-[0-9]' '{ printf " %s",$1 }'))
done
[ ${#list[@]} -eq 0 ] || $SUDO $PKGMAN $RMPKG ${1+"$@"} "${list[@]}"
$SUDO rm -rf $SBIN/${PROG%-*}-uninstall
}
function suse_amdgpu_uninstall() {
fedora_amdgpu_uninstall "$@"
}
function radeon_install() {
echo -e "WARNING: '$PROG' is deprecated\n"`
`"Please use amdgpu-install instead."
amdgpu_install "$@"
}
function amdgpu_pro_install() {
echo -e "WARNING: '$PROG' is deprecated\n"`
`"Please use the following command instead:\n"`
`"amdgpu-install --usecase=workstation --vulkan=pro"
VULKAN_OPTION="pro"
USECASE_OPTION="workstation"
amdgpu_install "$@"
}
function radeon_uninstall() {
amdgpu_uninstall "$@"
}
function amdgpu_pro_uninstall() {
amdgpu_uninstall "$@"
}
# MAIN
PROG=${0##*/}
PROG_DIR=$(cd ${0%/*} && pwd -P)
SUDO=$([[ $(id -u) -ne 0 ]] && echo "sudo" ||:)
SBIN="/usr/bin"
SCRIPT_DIR=$(dirname "$0")
USECASE_OPTION="graphics,opencl,hip"
OPENCL_OPTION=
VULKAN_OPTION=
ROCM_RELEASE=
OPTIONS=()
os_release # Check for supported OS
while (($#)) # Loop until each positional param has been processed
do
case "$1" in
-h|--help) # Display basic usage
usage
exit 0
;;
--list-usecase) # List usecase options
usecase_usage
exit 0
;;
--dryrun|--no-dkms|--no-32|--accept-eula) #
OPTIONS+=(${1#--})
shift
;;
--pro)
echo -e "WARNING: '--pro' option is deprecated\nPlease "`
`"use '--usecase=workstation --vulkan=pro' instead"
USECASE_OPTION="workstation"
VULKAN_OPTION="pro"
shift
;;
--usecase=*|--opencl=*|--vulkan=*)
option=${1%=*}
option=${option#--}
eval ${option^^}_OPTION="${1#--*=}"
shift
;;
--rocmrelease=*)
if [[ "${1#--*=}" == "all" ]] ; then
ROCM_RELEASE="all"
elif [[ ${1#--*=} =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
ROCM_RELEASE="${1#--*=}"
BASE_PACKAGES=("$BASE_ROCM_PACKAGE$ROCM_RELEASE")
else
echo "ERROR: Invalid ROCm release format '${1#--*=}'" \
| stderr
usage
exit 1
fi
shift
;;
--uninstall)
PROG="amdgpu_uninstall"
shift
;;
*)
ARGS+="$1 "
shift
;;
esac
done
set -- $ARGS
${PROG//-/_} ${1+"$@"}