-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·194 lines (166 loc) · 5.72 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
#!/usr/bin/env bash
# Author: Kent Knox
# #################################################
# 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
# lsb-release file describes the system
if [[ ! -e "/etc/lsb-release" ]]; then
echo "This script depends on the /etc/lsb-release file"
exit 2
fi
source /etc/lsb-release
if [[ ${DISTRIB_ID} != Ubuntu ]]; then
echo "This script only validated with Ubuntu"
exit 2
fi
# #################################################
# helper functions
# #################################################
function display_help()
{
echo "hipblas build & installation helper script"
echo "./install [-h|--help] "
echo " [-h|--help] prints this help message"
echo " [-i|--install] install after build"
echo " [-d|--dependencies] install build dependencies"
echo " [-c|--clients] build library clients too (combines with -i & -d)"
echo " [--cuda] build library for cuda backend"
}
# 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 $@
else
$@
fi
}
# #################################################
# global variables
# #################################################
install_package=false
install_dependencies=false
build_clients=false
build_cuda=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,clients,dependencies,cuda --options hicd -- "$@")
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 ;;
-c|--clients)
build_clients=true
shift ;;
--cuda)
build_cuda=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
rm -rf ${build_dir}
# #################################################
# install build dependencies on request
# #################################################
if [[ "${install_dependencies}" == true ]]; then
# dependencies needed for hipblas and clients to build
library_dependencies_ubuntu=( "make" "cmake-curses-gui" "pkg-config" "hip_hcc" )
if [[ "${build_cuda}" == false ]]; then
library_dependencies_ubuntu+=( "hcc" "rocblas" )
else
# Ideally, this could be cuda-cublas-dev, but the package name has a version number in it
library_dependencies_ubuntu+=( "cuda" )
fi
client_dependencies_ubuntu=( "gfortran" "libboost-program-options-dev" )
elevate_if_not_root apt update
# Dependencies required by main library
for package in "${library_dependencies_ubuntu[@]}"; 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
# Dependencies required by library client apps
if [[ "${build_clients}" == true ]]; then
for package in "${client_dependencies_ubuntu[@]}"; 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
# The following builds googletest & lapack from source, installs into cmake default /usr/local
pushd .
printf "\033[32mBuilding \033[33mgoogletest & lapack\033[32m from source; installing into \033[33m/usr/local\033[0m\n"
mkdir -p ${build_dir}/deps && cd ${build_dir}/deps
cmake -DBUILD_BOOST=OFF ../../deps
make -j$(nproc)
elevate_if_not_root make install
popd
fi
fi
pushd .
# #################################################
# configure
# #################################################
mkdir -p ${build_dir}/release && cd ${build_dir}/release
if [[ "${build_cuda}" == false ]]; then
export CXX=/opt/rocm/bin/hcc
fi
if [[ "${build_clients}" == true ]]; then
cmake -DBUILD_CLIENTS_SAMPLES=ON -DBUILD_CLIENTS_TESTS=ON ../..
else
cmake ../..
fi
# #################################################
# build
# #################################################
make -j$(nproc)
# #################################################
# install
# #################################################
# installing through package manager, which makes uninstalling easy
if [[ "${install_package}" == true ]]; then
make package
elevate_if_not_root dpkg -i hipblas-*.deb
fi
popd