-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-docker.sh
executable file
·309 lines (283 loc) · 9.98 KB
/
build-docker.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
#!/usr/bin/env bash
: ${DOCKER_USER:=$(whoami)}
: ${ROCM_VERSIONS:="5.0"}
: ${PYTHON_VERSIONS:="8 9 10 11"}
: ${BUILD_CI:=""}
: ${PUSH:=0}
: ${PULL:=--pull}
: ${OUTPUT_VERBOSITY:=""}
: ${BUILD_OPENMPI:="0"}
: ${BUILD_AOMP_LATEST:="0"}
: ${BUILD_LLVM_LATEST:="0"}
: ${BUILD_GCC_LATEST:="0"}
: ${BUILD_OG_LATEST:="0"}
: ${BUILD_CLACC_LATEST:="0"}
: ${BUILD_PYTORCH:="0"}
: ${BUILD_CUPY:="0"}
: ${BUILD_ALL_LATEST:="0"}
: ${RETRY:=3}
: ${NO_CACHE:=""}
: ${OMNITRACE_BUILD_FROM_SOURCE:=0}
: ${ADMIN_USERNAME:="admin"}
: ${ADMIN_PASSWORD:=""}
: ${USE_CACHED_APPS:=0}
: ${AMDGPU_GFXMODEL:=""}
tolower()
{
echo "$@" | awk -F '\\|~\\|' '{print tolower($1)}';
}
toupper()
{
echo "$@" | awk -F '\\|~\\|' '{print toupper($1)}';
}
usage()
{
print_option() { printf " --%-20s %-24s %s\n" "${1}" "${2}" "${3}"; }
echo "Options:"
print_option "help -h" "" "This message"
print_option "no-pull" "" "Do not pull down most recent base container"
echo ""
print_default_option() { printf " --%-20s %-24s %s (default: %s)\n" "${1}" "${2}" "${3}" "$(tolower ${4})"; }
print_default_option admin-username "[ADMIN_USERNAME]"
print_default_option admin-password "[ADMIN_PASSWORD]"
print_default_option build-aomp-latest -- flag to build the latest version of AOMP for offloading
print_default_option build-llvm-latest -- flag to build the latest version of LLVM for offloading
print_default_option build-gcc-latest -- flag to build the latest version of gcc with offloading
print_default_option build-og-latest -- flag to build the latest version of gcc develop with offloading
print_default_option build-clacc-latest -- flag to build the latest version of clacc with offloading
print_default_option build-pytorch -- flag to build the latest version of pytorch
print_default_option build-cupy -- flag to build the latest version of cupy
print_default_option use_cached-apps -- flag to use pre-built gcc and aomp located in CacheFiles/${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} directory
print_default_option omnitrace-build-from-source -- flag to build omnitrace from source instead of using pre-built versions
print_default_option output-verbosity -- flag to show more docker build output
print_default_option distro "[ubuntu|opensuse|rhel]" "OS distribution" "${DISTRO}"
print_default_option distro-versions "[VERSION] [VERSION...]" "Ubuntu, OpenSUSE, or RHEL release" "${DISTRO_VERSIONS}"
print_default_option rocm-versions "[VERSION] [VERSION...]" "ROCm versions" "${ROCM_VERSIONS}"
print_default_option python-versions "[VERSION] [VERSION...]" "Python 3 minor releases" "${PYTHON_VERSIONS}"
print_default_option "docker_user" "[DOCKER_USERNAME]" "DockerHub username" "${DOCKER_USER}"
print_default_option "retry" "[N]" "Number of attempts to build (to account for network errors)" "${RETRY}"
print_default_option push "" "Push the image to Dockerhub" ""
#print_default_option lto "[on|off]" "Enable LTO" "${LTO}"
}
send-error()
{
usage
echo -e "\nError: ${@}"
exit 1
}
verbose-run()
{
echo -e "\n### Executing \"${@}\"... ###\n"
eval "${@}"
}
verbose-build()
{
echo -e "\n### Executing \"${@}\" a maximum of ${RETRY} times... ###\n"
for i in $(seq 1 1 ${RETRY})
do
set +e
eval "${@}"
local RETC=$?
set -e
if [ "${RETC}" -eq 0 ]; then
break
else
echo -en "\n### Command failed with error code ${RETC}... "
if [ "${i}" -ne "${RETRY}" ]; then
echo -e "Retrying... ###\n"
sleep 3
else
echo -e "Exiting... ###\n"
exit ${RETC}
fi
fi
done
}
reset-last()
{
last() { send-error "Unsupported argument :: ${1}"; }
}
set -e
DISTRO=`lsb_release -i | cut -f2 | tr '[:upper:]' '[:lower:]'`
DISTRO_VERSIONS=`lsb_release -r | cut -f2`
AMDGPU_GFXMODEL=`rocminfo | grep gfx | sed -e 's/Name://' | head -1 |sed 's/ //g'`
n=0
while [[ $# -gt 0 ]]
do
case "${1}" in
"-h|--help")
usage
exit 0
;;
"--distro")
shift
DISTRO=${1}
last() { DISTRO="${DISTRO} ${1}"; }
;;
"--distro-versions")
shift
DISTRO_VERSIONS=${1}
last() { DISTRO_VERSIONS="${DISTRO_VERSIONS} ${1}"; }
;;
"--rocm-versions")
shift
ROCM_VERSIONS=${1}
last() { ROCM_VERSIONS="${ROCM_VERSIONS} ${1}"; }
;;
"--python-versions")
shift
PYTHON_VERSIONS=${1}
last() { PYTHON_VERSIONS="${PYTHON_VERSIONS} ${1}"; }
;;
"--docker_user")
shift
DOCKER_USER=${1}
reset-last
;;
"--admin-username")
shift
ADMIN_USERNAME=${1}
reset-last
;;
"--admin-password")
shift
ADMIN_PASSWORD=${1}
reset-last
;;
"--amdgpu-gfxmodel")
shift
AMDGPU_GFXMODEL=${1}
reset-last
;;
"--omnitrace-build-from-source")
OMNITRACE_BUILD_FROM_SOURCE=1
reset-last
;;
"--push")
PUSH=1
reset-last
;;
"--output-verbosity")
OUTPUT_VERBOSITY="--progress=plain"
reset-last
;;
"--no-cache")
NO_CACHE=--no-cache
reset-last
;;
"--no-pull")
PULL=""
reset-last
;;
"--retry")
shift
RETRY=${1}
reset-last
;;
"--build-openmpi")
BUILD_OPENMPI="1"
reset-last
;;
"--build-aomp-latest")
BUILD_AOMP_LATEST="1"
reset-last
;;
"--build-llvm-latest")
BUILD_LLVM_LATEST="1"
reset-last
;;
"--build-gcc-latest")
BUILD_GCC_LATEST="1"
reset-last
;;
"--build-og-latest")
BUILD_OG_LATEST="1"
reset-last
;;
"--build-clacc-latest")
BUILD_CLACC_LATEST="1"
reset-last
;;
"--build-pytorch")
BUILD_PYTORCH="1"
reset-last
;;
"--build-cupy")
BUILD_CUPY="1"
reset-last
;;
"--build-all-latest")
#BUILD_OPENMPI="1"
BUILD_ALL_LATEST="1"
BUILD_AOMP_LATEST="1"
#BUILD_LLVM_LATEST="1"
BUILD_GCC_LATEST="1"
#BUILD_OG_LATEST="1"
#BUILD_CLACC_LATEST="1"
BUILD_PYTORCH="1"
BUILD_CUPY="1"
reset-last
;;
"--use-cached-apps")
USE_CACHED_APPS="1"
reset-last
;;
"--*")
send-error "Unsupported argument at position $((${n} + 1)) :: ${1}"
;;
*)
last ${1}
;;
esac
n=$((${n} + 1))
shift
done
if [ "x${ADMIN_PASSWORD}" == "x" ] ; then
echo "A password for the admin user is required"
echo " --admin-password <xxxx>"
echo " --admin-username <admin>"
exit;
fi
ROCM_DOCKER_OPTS="${PULL} -f rocm/Dockerfile ${NO_CACHE}"
OMNITRACE_DOCKER_OPTS="-f omnitrace/Dockerfile ${NO_CACHE} --build-arg DOCKER_USER=${DOCKER_USER} --build-arg OMNITRACE_BUILD_FROM_SOURCE=\"${OMNITRACE_BUILD_FROM_SOURCE}\" --build-arg PYTHON_VERSIONS=\"${PYTHON_VERSIONS}\" --build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL}"
OMNIPERF_DOCKER_OPTS="-f omniperf/Dockerfile ${NO_CACHE} --build-arg DOCKER_USER=${DOCKER_USER}"
TRAINING_DOCKER_OPTS="${NO_CACHE} --build-arg DOCKER_USER=${DOCKER_USER} --build-arg BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%SZ') --build-arg OG_BUILD_DATE=$(date -u +'%y-%m-%d') --build-arg BUILD_VERSION=1.1 --build-arg DISTRO=${DISTRO} --build-arg ADMIN_USERNAME=${ADMIN_USERNAME} --build-arg ADMIN_PASSWORD=${ADMIN_PASSWORD}"
TRAINING_DOCKER_OPTS="${TRAINING_DOCKER_OPTS} -f training/Dockerfile"
for ROCM_VERSION in ${ROCM_VERSIONS}
do
if [ -d CacheFiles/${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION}-${AMDGPU_GFXMODEL}/ ]; then
USE_CACHED_APPS=1
fi
GENERAL_DOCKER_OPTS="--build-arg DISTRO=${DISTRO} --build-arg DISTRO_VERSION=${DISTRO_VERSION} --build-arg ROCM_VERSION=${ROCM_VERSION}"
# Building rocm docker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${ROCM_DOCKER_OPTS} \
--build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL} \
--tag ${DOCKER_USER}/rocm:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
.
# Building omnitrace docker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${OMNITRACE_DOCKER_OPTS} \
--build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL} \
-t ${DOCKER_USER}/omnitrace:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
.
# Building omniperf docker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${OMNIPERF_DOCKER_OPTS} \
-t ${DOCKER_USER}/omniperf:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
.
# Building training docker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${TRAINING_DOCKER_OPTS} \
--build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL} \
--build-arg BUILD_GCC_LATEST=${BUILD_GCC_LATEST} \
--build-arg BUILD_AOMP_LATEST=${BUILD_AOMP_LATEST} \
--build-arg BUILD_LLVM_LATEST=${BUILD_LLVM_LATEST} \
--build-arg BUILD_OG_LATEST=${BUILD_OG_LATEST} \
--build-arg BUILD_CLACC_LATEST=${BUILD_CLACC_LATEST} \
--build-arg BUILD_PYTORCH=${BUILD_PYTORCH} \
--build-arg BUILD_CUPY=${BUILD_CUPY} \
--build-arg USE_CACHED_APPS=${USE_CACHED_APPS} \
-t ${DOCKER_USER}/training:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
-t training \
.
if [ "${PUSH}" -ne 0 ]; then
docker push ${CONTAINER}
fi
done