Skip to content

Commit

Permalink
temporarily disable errexit shell option when calling out to archdete…
Browse files Browse the repository at this point in the history
…ct to detect accelerator
  • Loading branch information
boegel committed Oct 6, 2024
1 parent 24f0620 commit 3bf3b12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/tests_archdetect_nvidia_gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ jobs:
echo "Test for '${{matrix.fake_nvidia_smi_script}}' PASSED: '$out'"
# by default the 'errexit' option is enabled (set -e),
# which causes trouble when 'eessi_archdetect.sh accelpath'
# fails to detect an accelerator and produces a non-zero exit code,
# so we have to unset it using 'set +e'
echo "set flags: $-"
set +e
echo "set flags after unsetting errexit option: $-"
# run full EESSI init script, which pick up on the accelerator (if available)
echo
. init/bash 2>&1 | tee init.out
Expand Down Expand Up @@ -95,7 +87,7 @@ jobs:
else
echo ">>> checking for 'accel/nvidia/cc80' in init output..."
grep "archdetect found supported accelerator for CPU target x86_64/amd/zen2: accel/nvidia/cc80" init.out || (echo "FAILED 2" && exit 1)
grep "Prepending /cvmfs/software.eessi.io/versions/2023.06/software/linux x86_64/amd/zen2/accel/nvidia/cc80/modules/all to \$MODULEPATH" init.out || (echo "FAILED 3" && exit 1)
grep "Prepending /cvmfs/software.eessi.io/versions/2023.06/software/linux/x86_64/amd/zen2/accel/nvidia/cc80/modules/all to \$MODULEPATH" init.out || (echo "FAILED 3" && exit 1)
fi
echo ">>> checking last line of init output..."
Expand Down
19 changes: 17 additions & 2 deletions init/eessi_environment_variables
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ if [ -d $EESSI_PREFIX ]; then
break
fi
done

# we need to make sure that errexit shell option (set -e) is not enabled,
# since archdetect will produce non-zero exit code if no accelerator was found
if [[ "$-" =~ e ]]; then
errexit_shell_option_set='yes'
set +e
else
errexit_shell_option_set='no'
fi

# to be able to grab exit code of archdetect trying to detect accelerators,
# we can not run it via $(...), so we have to redirect the output to a temporary file
tmpout=$(mktemp)
${EESSI_INIT_DIR_PATH}/eessi_archdetect.sh accelpath 2>&1 > $tmpout
ec=$?
if [[ $ec -eq 0 ]]; then
accelpath_exit_code=$?

if [[ "$errexit_shell_option_set" == "yes" ]]; then
set -e
fi

if [[ $accelpath_exit_code -eq 0 ]]; then
export EESSI_ACCEL_SUBDIR=$(tail -1 $tmpout && rm -f $tmpout)
if [ -z ${EESSI_ACCEL_SUBDIR} ]; then
error "accelerator detection with archdetect worked, but no result was returned?!"
Expand Down

0 comments on commit 3bf3b12

Please sign in to comment.