-
Notifications
You must be signed in to change notification settings - Fork 19
/
install.sh
executable file
·438 lines (385 loc) · 13.4 KB
/
install.sh
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
#!/usr/bin/env bash
# Author: Nico Trost
#set -x #echo on
# #################################################
# helper functions
# #################################################
function display_help()
{
echo "rocHPCG build helper script"
echo "./install [-h|--help] "
echo " [-h|--help] prints this help message"
echo " [-i|--install] install after build"
echo " [-d|--dependencies] install dependencies"
echo " [-r|--reference] reference mode"
echo " [-g|--debug] -DCMAKE_BUILD_TYPE=Debug (default: Release)"
echo " [-t|--test] build single GPU test"
echo " [--with-rocm=<dir>] Path to ROCm install (default: /opt/rocm)"
echo " [--with-mpi=<dir>] Path to external MPI install (Default: clone+build OpenMPI v4.1.0 in deps/)"
echo " [--gpu-aware-mpi] MPI library supports GPU-aware communication (Default: false)"
echo " [--with-openmp] compile with OpenMP support (default: enabled)"
echo " [--with-memmgmt] compile with smart memory management (default: enabled)"
echo " [--with-memdefrag] compile with memory defragmentation (defaut: enabled)"
echo " [--with-roctx] enable rocTX markers (default: false)"
}
# This function is helpful for dockerfiles that do not have sudo installed, but the default user is root
# true is a system command that completes successfully, function returns success
# prereq: ${ID} must be defined before calling
supported_distro( )
{
if [ -z ${ID+foo} ]; then
printf "supported_distro(): \$ID must be set\n"
exit 2
fi
case "${ID}" in
ubuntu|centos|rhel|fedora|sles|opensuse-leap)
true
;;
*) printf "This script is currently supported on Ubuntu, CentOS, RHEL, Fedora and SLES\n"
exit 2
;;
esac
}
# This function is helpful for dockerfiles that do not have sudo installed, but the default user is root
check_exit_code( )
{
if (( $? != 0 )); then
exit $?
fi
}
# This function is helpful for dockerfiles that do not have sudo installed, but the default user is root
elevate_if_not_root( )
{
local uid=$(id -u)
if (( ${uid} )); then
sudo $@
check_exit_code
else
$@
check_exit_code
fi
}
# Take an array of packages as input, and install those packages with 'apt' if they are not already installed
install_apt_packages( )
{
package_dependencies=("$@")
for package in "${package_dependencies[@]}"; do
if [[ $(dpkg-query --show --showformat='${db:Status-Abbrev}\n' ${package} 2> /dev/null | grep -q "ii"; echo $?) -ne 0 ]]; then
printf "\033[32mInstalling \033[33m${package}\033[32m from distro package manager\033[0m\n"
elevate_if_not_root apt install -y --no-install-recommends ${package}
fi
done
}
# Take an array of packages as input, and install those packages with 'yum' if they are not already installed
install_yum_packages( )
{
package_dependencies=("$@")
for package in "${package_dependencies[@]}"; do
if [[ $(yum list installed ${package} &> /dev/null; echo $? ) -ne 0 ]]; then
printf "\033[32mInstalling \033[33m${package}\033[32m from distro package manager\033[0m\n"
elevate_if_not_root yum -y --nogpgcheck install ${package}
fi
done
}
# Take an array of packages as input, and install those packages with 'dnf' if they are not already installed
install_dnf_packages( )
{
package_dependencies=("$@")
for package in "${package_dependencies[@]}"; do
if [[ $(dnf list installed ${package} &> /dev/null; echo $? ) -ne 0 ]]; then
printf "\033[32mInstalling \033[33m${package}\033[32m from distro package manager\033[0m\n"
elevate_if_not_root dnf install -y ${package}
fi
done
}
# Take an array of packages as input, and install those packages with 'zypper' if they are not already installed
install_zypper_packages( )
{
package_dependencies=("$@")
for package in "${package_dependencies[@]}"; do
if [[ $(rpm -q ${package} &> /dev/null; echo $? ) -ne 0 ]]; then
printf "\033[32mInstalling \033[33m${package}\033[32m from distro package manager\033[0m\n"
elevate_if_not_root zypper -n --no-gpg-checks install ${package}
fi
done
}
# Take an array of packages as input, and delegate the work to the appropriate distro installer
# prereq: ${ID} must be defined before calling
install_packages( )
{
if [ -z ${ID+foo} ]; then
printf "install_packages(): \$ID must be set\n"
exit 2
fi
# dependencies needed for executable to build
local library_dependencies_ubuntu=( "make" "pkg-config" "libnuma1" "cmake" "libnuma-dev" "autoconf" "libtool" "automake" "m4" "flex" )
local library_dependencies_centos=( "epel-release" "make" "cmake3" "gcc-c++" "rpm-build" "numactl-libs" "autoconf" "libtool" "automake" "m4" "flex" )
local library_dependencies_fedora=( "make" "cmake" "gcc-c++" "libcxx-devel" "rpm-build" "numactl-libs" "autoconf" "libtool" "automake" "m4" "flex" )
local library_dependencies_sles=( "make" "cmake" "gcc-c++" "rpm-build" "libnuma-devel" "autoconf" "libtool" "automake" "m4" "flex" )
if [[ ( "${ID}" == "sles" ) ]]; then
if [[ -f /etc/os-release ]]; then
. /etc/os-release
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if [[ $(version $VERSION_ID) -ge $(version 15.4) ]]; then
library_dependencies_sles+=( "libcxxtools10" )
else
library_dependencies_sles+=( "libcxxtools9" )
fi
fi
fi
if [[ "${with_rocm}" == /opt/rocm ]]; then
library_dependencies_ubuntu+=("rocm-dev" "rocprim-dev")
library_dependencies_centos+=("rocm-dev" "rocprim-devel")
library_dependencies_fedora+=("rocm-dev" "rocprim-devel")
library_dependencies_sles+=("rocm-dev" "rocprim-devel")
fi
case "${ID}" in
ubuntu)
elevate_if_not_root apt update
install_apt_packages "${library_dependencies_ubuntu[@]}"
;;
centos|rhel)
# yum -y update brings *all* installed packages up to date
# without seeking user approval
# elevate_if_not_root yum -y update
install_yum_packages "${library_dependencies_centos[@]}"
;;
fedora)
# elevate_if_not_root dnf -y update
install_dnf_packages "${library_dependencies_fedora[@]}"
;;
sles|opensuse-leap)
# elevate_if_not_root zypper -y update
install_zypper_packages "${library_dependencies_sles[@]}"
;;
*)
echo "This script is currently supported on Ubuntu, CentOS, RHEL, Fedora and SLES"
exit 2
;;
esac
}
# Clone and build OpenMPI+UCX in rochpcg/openmpi
install_openmpi( )
{
if [ ! -d "./deps/ucx" ]; then
mkdir -p deps && cd deps
git clone --branch v1.13.1 https://github.com/openucx/ucx.git ucx
cd ucx; ./autogen.sh; ./autogen.sh #why do we have to run this twice?
mkdir build; cd build
../contrib/configure-opt --prefix=${PWD}/../ --with-rocm=${with_rocm} --without-knem --without-cuda --without-java
make -j$(nproc); make install; cd ../../..
fi
if [ ! -d "./deps/openmpi" ]; then
mkdir -p deps && cd deps
git clone --branch v4.1.4 https://github.com/open-mpi/ompi.git openmpi
cd openmpi; ./autogen.pl; mkdir build; cd build
../configure --prefix=${PWD}/../ --with-ucx=${PWD}/../../ucx --without-verbs
make -j$(nproc); make install; cd ../../..
fi
}
# #################################################
# Pre-requisites check
# #################################################
# Exit code 0: alls well
# Exit code 1: problems with getopt
# Exit code 2: problems with supported platforms
# check if getopt command is installed
type getopt > /dev/null
if [[ $? -ne 0 ]]; then
echo "This script uses getopt to parse arguments; try installing the util-linux package";
exit 1
fi
# os-release file describes the system
if [[ -e "/etc/os-release" ]]; then
source /etc/os-release
else
echo "This script depends on the /etc/os-release file"
exit 2
fi
# The following function exits script if an unsupported distro is detected
supported_distro
# #################################################
# global variables
# #################################################
install_package=false
install_dependencies=false
install_prefix=rochpcg-install
build_release=true
build_reference=false
build_test=false
with_rocm=/opt/rocm
with_mpi=deps/openmpi
gpu_aware_mpi=OFF
with_omp=ON
with_memmgmt=ON
with_memdefrag=ON
with_roctx=false
# #################################################
# Parameter parsing
# #################################################
# check if we have a modern version of getopt that can handle whitespace and long parameters
getopt -T
if [[ $? -eq 4 ]]; then
GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,dependencies,reference,debug,test,with-rocm:,with-mpi:,gpu-aware-mpi:,with-openmp:,with-memmgmt:,with-memdefrag:,with-roctx --options hidrgt -- "$@")
else
echo "Need a new version of getopt"
exit 1
fi
if [[ $? -ne 0 ]]; then
echo "getopt invocation failed; could not parse the command line";
exit 1
fi
eval set -- "${GETOPT_PARSE}"
while true; do
case "${1}" in
-h|--help)
display_help
exit 0
;;
-i|--install)
install_package=true
shift ;;
-d|--dependencies)
install_dependencies=true
shift ;;
-r|--reference)
build_reference=true
shift ;;
-g|--debug)
build_release=false
shift ;;
-t|--test)
build_test=true
shift ;;
--with-rocm)
with_rocm=${2}
shift 2 ;;
--with-mpi)
with_mpi=${2}
shift 2 ;;
--gpu-aware-mpi)
gpu_aware_mpi=${2}
shift 2 ;;
--with-openmp)
with_omp=${2}
shift 2 ;;
--with-memmgmt)
with_memmgmt=${2}
shift 2 ;;
--with-memdefrag)
with_memdefrag=${2}
shift 2 ;;
--with-roctx)
with_roctx=true
shift ;;
--) shift ; break ;;
*) echo "Unexpected command line parameter received; aborting";
exit 1
;;
esac
done
build_dir=./build
printf "\033[32mCreating project build directory in: \033[33m${build_dir}\033[0m\n"
# #################################################
# prep
# #################################################
# ensure a clean build environment
if [[ "${build_release}" == true ]]; then
rm -rf ${build_dir}/release
else
rm -rf ${build_dir}/debug
fi
# Default cmake executable is called cmake
cmake_executable=cmake
case "${ID}" in
centos|rhel)
cmake_executable=cmake3
;;
esac
# #################################################
# dependencies
# #################################################
if [[ "${install_dependencies}" == true ]]; then
install_packages
fi
# We append customary rocm path; if user provides custom rocm path in ${path}, our
# hard-coded path has lesser priority
export ROCM_PATH=${with_rocm}
export PATH=${PATH}:${ROCM_PATH}/bin
pushd .
# #################################################
# MPI
# #################################################
if [[ "${with_mpi}" == deps/openmpi ]]; then
install_openmpi
fi
# #################################################
# configure & build
# #################################################
cmake_common_options="-DHPCG_OPENMP=${with_omp} -DOPT_MEMMGMT=${with_memmgmt} -DOPT_DEFRAG=${with_memdefrag} -DOPT_ROCTX=${with_roctx}"
shopt -s nocasematch
# gpu aware mpi
if [[ "${gpu_aware_mpi}" == on || "${gpu_aware_mpi}" == true || "${gpu_aware_mpi}" == 1 || "${gpu_aware_mpi}" == enabled ]]; then
cmake_common_options="${cmake_common_options} -DGPU_AWARE_MPI=ON"
fi
# mpi
if [[ "${with_mpi}" == off || "${with_mpi}" == false || "${with_mpi}" == 0 || "${with_mpi}" == disabled ]]; then
cmake_common_options="${cmake_common_options} -DHPCG_MPI=OFF"
else
cmake_common_options="${cmake_common_options} -DHPCG_MPI_DIR=${with_mpi}"
fi
shopt -u nocasematch
# build type
if [[ "${build_release}" == true ]]; then
mkdir -p ${build_dir}/release && cd ${build_dir}/release
cmake_common_options="${cmake_common_options} -DCMAKE_BUILD_TYPE=Release"
else
mkdir -p ${build_dir}/debug && cd ${build_dir}/debug
cmake_common_options="${cmake_common_options} -DCMAKE_BUILD_TYPE=Debug"
fi
# reference mode
if [[ "${build_reference}" == true ]]; then
cmake_common_options="${cmake_common_options} -DHPCG_REFERENCE=ON"
fi
# build test
if [[ "${build_test}" == true ]]; then
cmake_common_options="${cmake_common_options} -DBUILD_TEST=ON"
fi
# Build library with AMD toolchain because of existense of device kernels
${cmake_executable} ${cmake_common_options} \
-DCPACK_SET_DESTDIR=OFF \
-DCMAKE_INSTALL_PREFIX=${install_prefix} \
-DCPACK_PACKAGING_INSTALL_PREFIX=${with_rocm} \
-DROCM_PATH="${with_rocm}" ../..
check_exit_code
if [[ "${build_test}" == false ]]; then
make -j$(nproc) install
else
make -j$(nproc)
fi
check_exit_code
# #################################################
# install
# #################################################
# installing through package manager, which makes uninstalling easy
if [[ "${install_package}" == true ]]; then
if [[ "${build_test}" == false ]]; then
make package
check_exit_code
case "${ID}" in
ubuntu)
elevate_if_not_root dpkg -i rochpcg[-\_]*.deb
;;
centos|rhel)
elevate_if_not_root yum -y localinstall rochpcg-*.rpm
;;
fedora)
elevate_if_not_root dnf install rochpcg-*.rpm
;;
sles)
elevate_if_not_root zypper -n --no-gpg-checks install rochpcg-*.rpm
;;
esac
fi
fi
popd