From 81d2a99b9391156b9093f747a0f36a9803967432 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Tue, 17 Feb 2026 11:36:41 -0800 Subject: [PATCH 1/3] call clearLmod before loading the NVHPC modules in case the envvars were populated by a different user --- features/src/nvhpc/.bashrc | 2 ++ features/src/nvhpc/devcontainer-feature.json | 2 +- features/src/nvhpc/install.sh | 10 +++--- .../{etc/profile.d/nvhpc.sh => load-nvhpc.sh} | 32 +++++++++++++++---- 4 files changed, 35 insertions(+), 11 deletions(-) rename features/src/nvhpc/{etc/profile.d/nvhpc.sh => load-nvhpc.sh} (53%) diff --git a/features/src/nvhpc/.bashrc b/features/src/nvhpc/.bashrc index 75e78075..584bd333 100644 --- a/features/src/nvhpc/.bashrc +++ b/features/src/nvhpc/.bashrc @@ -13,3 +13,5 @@ if [ -z "${LIBRARY_PATH:-}" ] \ || [ -n "${LIBRARY_PATH##*"${NVHPC_CUDA_HOME}/lib64/stubs"*}" ]; then export LIBRARY_PATH="${NVHPC_CUDA_HOME}/lib64/stubs${LIBRARY_PATH:+:$LIBRARY_PATH}" fi + +. /etc/profile.d/load-nvhpc._sh diff --git a/features/src/nvhpc/devcontainer-feature.json b/features/src/nvhpc/devcontainer-feature.json index 9fc79b56..97ed553d 100644 --- a/features/src/nvhpc/devcontainer-feature.json +++ b/features/src/nvhpc/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "NVHPC SDK", "id": "nvhpc", - "version": "26.4.2", + "version": "26.4.3", "description": "A feature to install the NVHPC SDK", "options": { "version": { diff --git a/features/src/nvhpc/install.sh b/features/src/nvhpc/install.sh index 2349d0dc..c2466218 100644 --- a/features/src/nvhpc/install.sh +++ b/features/src/nvhpc/install.sh @@ -68,7 +68,7 @@ if ! test -L /usr/local/cuda; then ln -s "${NVHPC_CUDA_HOME}" /usr/local/cuda; fi -cuda_ver=$(grep "#define CUDA_VERSION" "${NVHPC_CUDA_HOME}/include/cuda.h" | cut -d' ' -f3); +cuda_ver="$(grep "#define CUDA_VERSION" "${NVHPC_CUDA_HOME}/include/cuda.h" | cut -d' ' -f3)"; export NVHPC_CUDA_VERSION_MAJOR="$((cuda_ver / 1000))"; export NVHPC_CUDA_VERSION_MINOR="$((cuda_ver / 10 % 100))"; export NVHPC_CUDA_VERSION_PATCH="$((cuda_ver % 10))"; @@ -94,11 +94,13 @@ vars_+=('$NVHPC_CUDA_HOME'); vars_+=('$NVHPC_MODULEFILE_DIRS'); printf -v vars_ '%s,' "${vars_[@]}"; +cp load-nvhpc.sh /etc/profile.d/load-nvhpc._sh + # export envvars in bashrc files -append_to_etc_bashrc "$(cat <(cat .bashrc | envsubst "${vars_%,}") etc/profile.d/nvhpc.sh)"; -append_to_all_bashrcs "$(cat <(cat .bashrc | envsubst "${vars_%,}") etc/profile.d/nvhpc.sh)"; +append_to_etc_bashrc "$(cat <(cat .bashrc | envsubst "${vars_%,}"))"; +append_to_all_bashrcs "$(cat <(cat .bashrc | envsubst "${vars_%,}"))"; # export envvars in /etc/profile.d -add_etc_profile_d_script nvhpc "$(cat <(cat .bashrc | envsubst "${vars_%,}") etc/profile.d/nvhpc.sh)"; +add_etc_profile_d_script nvhpc "$(cat <(cat .bashrc | envsubst "${vars_%,}"))"; # Clean up # rm -rf /tmp/*; diff --git a/features/src/nvhpc/etc/profile.d/nvhpc.sh b/features/src/nvhpc/load-nvhpc.sh similarity index 53% rename from features/src/nvhpc/etc/profile.d/nvhpc.sh rename to features/src/nvhpc/load-nvhpc.sh index 7d7da673..a195ba57 100755 --- a/features/src/nvhpc/etc/profile.d/nvhpc.sh +++ b/features/src/nvhpc/load-nvhpc.sh @@ -1,14 +1,29 @@ -if ! command -V module 2>&1 | grep -q function; then - . /etc/profile.d/lmod._sh; -fi +DEVCONTAINERS_NVHPC_LOADED_BY="${DEVCONTAINERS_NVHPC_LOADED_BY:-}" + +if ! test "${DEVCONTAINERS_NVHPC_LOADED_BY:-}" = "$(whoami)"; then + + # "unload" lmod so all the modules are loaded from scratch + for __module_unload_func_name in clearMT clearLmod; do + if ! command -V $__module_unload_func_name 2>&1 | grep -q function; then + . /etc/profile.d/lmod._sh + fi + $__module_unload_func_name >/dev/null 2>&1 + done + unset __module_unload_func_name -if [ -n "${PATH##*"${NVHPC_ROOT}/compilers/bin"*}" ]; then + if ! command -V module 2>&1 | grep -q function; then + . /etc/profile.d/lmod._sh; + fi + + # Restore MODULEPATH since it is cleared by `clearLmod` for NVHPC_MODULEFILES_DIR in "${NVHPC_MODULEFILE_DIRS[@]}"; do if [ -n "${MODULEPATH##*"${NVHPC_MODULEFILES_DIR}"*}" ]; then module use -a "${NVHPC_MODULEFILES_DIR}"; fi done unset NVHPC_MODULEFILES_DIR; + + # Load the NHVPC modules again for NVHPC_MODULE_NAME in "nvhpc-hpcx-cuda${NVHPC_CUDA_VERSION_MAJOR}/${NVHPC_VERSION}" \ "nvhpc-hpcx/${NVHPC_VERSION}"; do if ! module list "${NVHPC_MODULE_NAME}" 2>&1 | grep -q 'None found.'; then @@ -20,8 +35,9 @@ if [ -n "${PATH##*"${NVHPC_ROOT}/compilers/bin"*}" ]; then unset NVHPC_MODULE_NAME; # Have to source and manually call hpcx_load for nvhpc>=25.7 - if [ "${NVHPC_VERSION_MAJOR}" -ge 25 ] \ - && [ "${NVHPC_VERSION_MINOR}" -ge 5 ]; then + if test "${NVHPC_VERSION_MAJOR}" -lt 25 || test "${NVHPC_VERSION_MINOR}" -lt 7; then + : + else HPCX_INIT="$(find -L "$NVHPC_ROOT"/comm_libs/ -path '*/latest/hpcx-init.sh' -print -quit)"; if [ -n "${HPCX_INIT:+x}" ] && [ -s "${HPCX_INIT}" ]; then . "$HPCX_INIT"; @@ -29,4 +45,8 @@ if [ -n "${PATH##*"${NVHPC_ROOT}/compilers/bin"*}" ]; then fi unset HPCX_INIT; fi + + DEVCONTAINERS_NVHPC_LOADED_BY="$(whoami)" fi + +export DEVCONTAINERS_NVHPC_LOADED_BY From 82b4540c09da4bc5f8fe8a912c1f8f32c83ffab2 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Tue, 17 Feb 2026 11:58:20 -0800 Subject: [PATCH 2/3] always call hpcx_load if it exists --- features/src/nvhpc/load-nvhpc.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/features/src/nvhpc/load-nvhpc.sh b/features/src/nvhpc/load-nvhpc.sh index a195ba57..bd2bccd2 100755 --- a/features/src/nvhpc/load-nvhpc.sh +++ b/features/src/nvhpc/load-nvhpc.sh @@ -35,16 +35,12 @@ if ! test "${DEVCONTAINERS_NVHPC_LOADED_BY:-}" = "$(whoami)"; then unset NVHPC_MODULE_NAME; # Have to source and manually call hpcx_load for nvhpc>=25.7 - if test "${NVHPC_VERSION_MAJOR}" -lt 25 || test "${NVHPC_VERSION_MINOR}" -lt 7; then - : - else - HPCX_INIT="$(find -L "$NVHPC_ROOT"/comm_libs/ -path '*/latest/hpcx-init.sh' -print -quit)"; - if [ -n "${HPCX_INIT:+x}" ] && [ -s "${HPCX_INIT}" ]; then - . "$HPCX_INIT"; - hpcx_load; - fi - unset HPCX_INIT; + HPCX_INIT="$(find -L "$NVHPC_ROOT"/comm_libs/ -path '*/latest/hpcx-init.sh' -print -quit)"; + if [ -n "${HPCX_INIT:+x}" ] && [ -s "${HPCX_INIT}" ]; then + . "$HPCX_INIT"; + hpcx_load; fi + unset HPCX_INIT; DEVCONTAINERS_NVHPC_LOADED_BY="$(whoami)" fi From 14dd6f71381ff8d59e37b38423c4a7d1cb073da0 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Tue, 17 Feb 2026 12:02:41 -0800 Subject: [PATCH 3/3] run feature tests in ubunut:24.04 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e0beeda..99af3309 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -123,7 +123,7 @@ jobs: feature: ${{ fromJSON(needs.features-matrix.outputs.features) }} with: name: "{0}" - args: "-f ${{ matrix.feature }} -i ubuntu:22.04 --skip-scenarios" + args: "-f ${{ matrix.feature }} -i ubuntu:24.04 --skip-scenarios" image-matrix: name: Determine image matrix