Skip to content

Commit a3271b0

Browse files
authored
Merge branch 'main' into Siesta_HOOK
2 parents 38ac22d + f13f1d3 commit a3271b0

2 files changed

Lines changed: 56 additions & 12 deletions

File tree

bot/build.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,6 @@ declare -a BUILD_STEP_ARGS=()
261261
BUILD_STEP_ARGS+=("--save" "${TARBALL_TMP_BUILD_STEP_DIR}")
262262
BUILD_STEP_ARGS+=("--storage" "${STORAGE}")
263263

264-
# add options required to handle NVIDIA support
265-
if nvidia_gpu_available; then
266-
BUILD_STEP_ARGS+=("--nvidia" "all")
267-
else
268-
BUILD_STEP_ARGS+=("--nvidia" "install")
269-
fi
270-
271264
# Retain location for host injections so we don't reinstall CUDA
272265
# (Always need to run the driver installation as available driver may change)
273266
if [[ ! -z ${SHARED_FS_PATH} ]]; then
@@ -294,19 +287,39 @@ else
294287
# prepend accel/ to all array elements
295288
EESSI_ACCELERATOR_TARGET_OVERRIDES=("${ACCEL_OVERRIDES_ARRAY[@]/#/accel/}")
296289
fi
290+
RESUME_DIR=""
291+
297292
for ACCEL_OVERRIDE in "${EESSI_ACCELERATOR_TARGET_OVERRIDES[@]}"; do
293+
# copy the common build step arguments to a a
294+
BUILD_STEP_ARGS_ACCEL=("${BUILD_STEP_ARGS[@]}")
295+
if [[ "${ACCEL_OVERRIDE}" == "accel/nvidia/"* ]]; then
296+
nvidia_cc=${ACCEL_OVERRIDE##*/cc}
297+
# add options required to handle NVIDIA support
298+
# only make the GPU available in the container if the host has a GPU and it has the correct compute capability
299+
if nvidia_gpu_available && nvidia_gpu_has_compute_capability "${nvidia_cc}" ; then
300+
echo "bot/build.sh: GPU with the requested compute capability is available, using '--nvidia all'"
301+
BUILD_STEP_ARGS_ACCEL+=("--nvidia" "all")
302+
else
303+
echo "bot/build.sh: no GPU with the requested compute capability is available, using '--nvidia install'"
304+
BUILD_STEP_ARGS_ACCEL+=("--nvidia" "install")
305+
fi
306+
fi
307+
# resume from the previous accelerator's build directory
308+
# as we want to combine all accelerator builds into a single tarball in the end
309+
if [[ ! -z "${RESUME_DIR}" ]]; then
310+
BUILD_STEP_ARGS_ACCEL+=("--resume" "${RESUME_DIR}")
311+
fi
312+
298313
export EESSI_ACCELERATOR_TARGET_OVERRIDE="${ACCEL_OVERRIDE}"
299314
echo "bot/build.sh: EESSI_ACCELERATOR_TARGET_OVERRIDE='${ACCEL_OVERRIDE}'"
300315
echo "Executing command to build software:"
301-
echo "$software_layer_dir/eessi_container.sh ${COMMON_ARGS[@]} ${BUILD_STEP_ARGS[@]}"
316+
echo "$software_layer_dir/eessi_container.sh ${COMMON_ARGS[@]} ${BUILD_STEP_ARGS_ACCEL[@]}"
302317
echo " -- $software_layer_dir/install_software_layer.sh \"${INSTALL_SCRIPT_ARGS[@]}\" \"$@\" 2>&1 | tee -a ${build_outerr}"
303-
$software_layer_dir/eessi_container.sh "${COMMON_ARGS[@]}" "${BUILD_STEP_ARGS[@]}" \
318+
$software_layer_dir/eessi_container.sh "${COMMON_ARGS[@]}" "${BUILD_STEP_ARGS_ACCEL[@]}" \
304319
-- $software_layer_dir/install_software_layer.sh "${INSTALL_SCRIPT_ARGS[@]}" "$@" 2>&1 | tee -a ${build_outerr}
305320

306321
# determine temporary directory to resume from for the next accelerator,
307-
# as we want to combine all accelerator builds into a single tarball in the end
308-
BUILD_TMPDIR=$(grep ' as tmp directory ' ${build_outerr} | cut -d ' ' -f 2)
309-
BUILD_STEP_ARGS+=("--resume" "${BUILD_TMPDIR}")
322+
RESUME_DIR=$(grep ' as tmp directory ' ${build_outerr} | cut -d ' ' -f 2)
310323
done
311324

312325
# prepare directory to store tarball of tmp for tarball step

scripts/utils.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,34 @@ function nvidia_gpu_available {
166166
return 2
167167
fi
168168
}
169+
170+
function nvidia_gpu_has_compute_capability {
171+
# Ensure we are given a single compute capability argument
172+
if [ $# -ne 1 ]; then
173+
echo_red "Function requires a single compute capability argument" >&2
174+
return $ANY_ERROR_EXITCODE
175+
fi
176+
# Remove period (if present) from the given compute capability, i.e. 8.0 -> 80
177+
requested_cc=${1//./}
178+
# We are careful here in case we are running in a container and LD_LIBARY_PATH has been wiped.
179+
mapfile -t gpu_ccs < <(LD_LIBRARY_PATH="/.singularity.d/libs:${LD_LIBRARY_PATH}" nvidia-smi --query-gpu=compute_cap --format=noheader)
180+
# Remove the periods from all compute capabilities
181+
gpu_ccs=("${gpu_ccs[@]//./}")
182+
# On a multi-GPU system we may get the compute capabilities of all GPUs, one per line.
183+
# In that case we print a warning and check the first GPU.
184+
if [ ${#gpu_ccs[@]} -eq 0 ]; then
185+
echo_red "ERROR: querying for the GPU's compute capability did not return anything."
186+
return 1
187+
else
188+
if [ ${#gpu_ccs[@]} -gt 1 ]; then
189+
echo_yellow "Warning: multiple GPUs detected, checking the compute capability of the first GPU".
190+
fi
191+
if [ "$requested_cc" == "${gpu_ccs[0]}" ]; then
192+
echo_green "Requested compute capability matches the one from the GPU."
193+
return 0
194+
else
195+
echo_yellow "Warning: the compute capability of the GPU (${gpu_ccs[0]}) does not match the requested compute capability ($requested_cc)."
196+
return 2
197+
fi
198+
fi
199+
}

0 commit comments

Comments
 (0)