-
Notifications
You must be signed in to change notification settings - Fork 4
/
build-docker.sh
executable file
·364 lines (337 loc) · 12.6 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
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
#!/usr/bin/env bash
: ${DOCKER_USER:=$(whoami)}
: ${ROCM_VERSIONS:="5.0"}
: ${PYTHON_VERSIONS:="10"}
: ${BUILD_CI:=""}
: ${PUSH:=0}
: ${PULL:=--pull}
: ${OUTPUT_VERBOSITY:=""}
: ${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_JAX:="0"}
: ${BUILD_KOKKOS:="0"}
: ${BUILD_TAU:="0"}
: ${BUILD_SCOREP:="0"}
: ${BUILD_MPI4PY:="0"}
: ${BUILD_HPCTOOLKIT:="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:=""}
: ${INSTALL_GRAFANA:=0}
tolower()
{
echo "$@" | awk -F '\\|~\\|' '{print tolower($1)}';
}
toupper()
{
echo "$@" | awk -F '\\|~\\|' '{print toupper($1)}';
}
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=`cat /etc/os-release | grep '^NAME' | sed -e 's/NAME="//' -e 's/"$//' | tr '[:upper:]' '[:lower:]' `
DISTRO_VERSION=`cat /etc/os-release | grep '^VERSION_ID' | sed -e 's/VERSION_ID="//' -e 's/"$//' | tr '[:upper:]' '[:lower:]' `
AMDGPU_GFXMODEL=`rocminfo | grep gfx | sed -e 's/Name://' | head -1 |sed 's/ //g'`
usage()
{
print_option() { printf " --%-20s %-24s %s\n" "${1}" "${2}" "${3}"; }
echo "Options:"
print_option "help -h" "" "prints this message to terminal"
echo ""
print_default_option() { printf " --%-20s %-24s %s (default: %s)\n" "${1}" "${2}" "${3}" "$(tolower ${4})"; }
print_default_option "pull" -- "instructs to not pull down the most recent base container" "--pull"
print_default_option "admin-username" "[ADMIN_USERNAME]" "container admin username" "${ADMIN_USERNAME}"
print_default_option admin-password "[ADMIN_PASSWORD]" "container admin password" "not set, needs to be provided as input"
print_default_option build-openmpi -- "flag to build OpenMPI" "not included"
print_default_option build-aomp-latest -- "flag to build the latest version of AOMP for offloading" "not included"
print_default_option build-llvm-latest -- "flag to build the latest version of LLVM for offloading" "not included"
print_default_option build-gcc-latest -- "flag to build the latest version of gcc with offloading" "not included"
print_default_option build-og-latest -- "flag to build the latest version of gcc develop with offloading" "not included"
print_default_option build-clacc-latest -- "flag to build the latest version of clacc with offloading" "not included"
print_default_option build-pytorch -- "flag to build the latest version of pytorch" "not included"
print_default_option build-cupy -- "flag to build the latest version of cupy" "not included"
print_default_option build-kokkos -- "flag to build the latest version of kokkos" "not included"
print_default_option build-hpctoolkit -- "flag to build the latest version of hpctoolkit" "not included"
print_default_option install-grafana -- "flag to install grafana" "not included"
print_default_option build-all-latest -- "flag to build all the additional libraries that need a flag to be built" "not included"
print_default_option use_cached-apps -- "flag to use pre-built gcc and aomp located in CacheFiles/${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} directory" "not included"
print_default_option omnitrace-build-from-source -- "flag to build omnitrace from source instead of using pre-built versions" "not included"
print_default_option output-verbosity -- "flag to show more docker build output" "not included"
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 amdgpu-gfxmodel [AMDGPU_GFXMODEL] "Specify the AMD GPU target architecture" "${AMDGPU_GFXMODEL}"
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" "[NUMBER OF ATTEMPTS]" "Number of attempts to build (to account for network errors)" "${RETRY}"
print_default_option push -- "Push the image to Dockerhub" "do not push"
}
n=0
while [[ $# -gt 0 ]]
do
case "${1}" in
"--help")
usage
exit 0
;;
"--distro")
shift
DISTRO=${1}
last() { DISTRO="${DISTRO} ${1}"; }
;;
"--distro-versions")
shift
DISTRO_VERSION=${1}
last() { DISTRO_VERSION="${DISTRO_VERSION} ${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-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-jax")
BUILD_JAX="1"
reset-last
;;
"--build-kokkos")
BUILD_KOKKOS="1"
reset-last
;;
"--build-tau")
BUILD_TAU="1"
reset-last
;;
"--build-scorep")
BUILD_SCOREP="1"
reset-last
;;
"--build-mpi4py")
BUILD_MPI4PY="1"
reset-last
;;
"--build-hpctoolkit")
BUILD_HPCTOOLKIT="1"
reset-last
;;
"--install-grafana")
INSTALL_GRAFANA="1"
reset-last
;;
"--build-all-latest")
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"
BUILD_JAX="1"
BUILD_KOKKOS="1"
BUILD_TAU="1"
BUILD_SCOREP="1"
BUILD_MPI4PY="1"
BUILD_HPCTOOLKIT="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}"
COMM_DOCKER_OPTS="-f comm/Dockerfile ${NO_CACHE} --build-arg DOCKER_USER=${DOCKER_USER} --build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL}"
TOOLS_DOCKER_OPTS="-f tools/Dockerfile ${NO_CACHE} --build-arg DOCKER_USER=${DOCKER_USER} --build-arg OMNITRACE_BUILD_FROM_SOURCE=\"${OMNITRACE_BUILD_FROM_SOURCE}\" --build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL} --build-arg BUILD_HPCTOOLKIT=${BUILD_HPCTOOLKIT} --build-arg BUILD_TAU=${BUILD_TAU} --build-arg BUILD_SCOREP=${BUILD_SCOREP} "
EXTRAS_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 PYTHON_VERSIONS=\"${PYTHON_VERSIONS}\" --build-arg ADMIN_USERNAME=${ADMIN_USERNAME} --build-arg ADMIN_PASSWORD=${ADMIN_PASSWORD}"
EXTRAS_DOCKER_OPTS="${EXTRAS_DOCKER_OPTS} -f extras/Dockerfile"
ADD_OPTIONS=""
PODMAN_DETECT=`docker |& grep "Emulate Docker CLI using podman" | wc -l`
if [[ "${PODMAN_DETECT}" -ge "1" ]]; then
ADD_OPTIONS="${ADD_OPTIONS} --format docker"
fi
for ROCM_VERSION in ${ROCM_VERSIONS}
do
mkdir -p CacheFiles/${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION}-${AMDGPU_GFXMODEL}
if [ -d CacheFiles/${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION}-${AMDGPU_GFXMODEL}/ ]; then
USE_CACHED_APPS=1
fi
GENERAL_DOCKER_OPTS="${ADD_OPTIONS} --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} \
--build-arg USE_CACHED_APPS=${USE_CACHED_APPS} \
--tag ${DOCKER_USER}/rocm:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
.
# Building comm docker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${COMM_DOCKER_OPTS} \
--build-arg AMDGPU_GFXMODEL=${AMDGPU_GFXMODEL} \
--build-arg USE_CACHED_APPS=${USE_CACHED_APPS} \
-t ${DOCKER_USER}/comm:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
.
# Building tools docker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${TOOLS_DOCKER_OPTS} \
--build-arg INSTALL_GRAFANA="${INSTALL_GRAFANA}" \
-t ${DOCKER_USER}/tools:release-base-${DISTRO}-${DISTRO_VERSION}-rocm-${ROCM_VERSION} \
.
# Building extrasdocker
verbose-build docker build ${OUTPUT_VERBOSITY} ${GENERAL_DOCKER_OPTS} ${EXTRAS_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 BUILD_JAX=${BUILD_JAX} \
--build-arg BUILD_KOKKOS=${BUILD_KOKKOS} \
--build-arg BUILD_TAU=${BUILD_TAU} \
--build-arg BUILD_SCOREP=${BUILD_SCOREP} \
--build-arg BUILD_MPI4PY=${BUILD_MPI4PY} \
--build-arg BUILD_HPCTOOLKIT=${BUILD_HPCTOOLKIT} \
--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