-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathinstall.sh
More file actions
109 lines (87 loc) · 3.61 KB
/
install.sh
File metadata and controls
109 lines (87 loc) · 3.61 KB
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
#! /usr/bin/env bash
set -e
# Ensure we're in this feature's directory during build
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# install global/common scripts
. ./common/install.sh;
check_packages \
gpg \
lmod \
wget \
dpkg-dev \
apt-utils \
lsb-release \
gettext-base \
bash-completion \
ca-certificates \
apt-transport-https \
software-properties-common \
;
# Ensure lmod preceeds nvhpc's profile init
if [ -f /etc/profile.d/lmod.sh ]; then
mv /etc/profile.d/lmod.{,_}sh;
fi
echo "Downloading NVHPC gpg key...";
wget --no-hsts -q -O- https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK \
| gpg --dearmor -o /etc/apt/trusted.gpg.d/nvidia-hpcsdk-archive-keyring.gpg;
chmod 0644 /etc/apt/trusted.gpg.d/*.gpg || true;
echo "Adding NVHPC SDK apt repository...";
# Install NVHPC-SDK apt repository
apt-add-repository -y "deb https://developer.download.nvidia.com/hpc-sdk/ubuntu/$(dpkg-architecture -q DEB_BUILD_ARCH) /";
echo "Installing NVHPC SDK...";
NVHPC_VERSION="${VERSION:-${NVHPCVERSION:-}}";
NVHPC_VERSION_MAJOR="$(echo "${NVHPC_VERSION}" | cut -d'.' -f1)";
NVHPC_VERSION_MINOR="$(echo "${NVHPC_VERSION}" | cut -d'.' -f2)";
pkgs=();
pkgs+=("nvhpc-${NVHPC_VERSION/./-}");
# only <= nvhpc-23-3 has a dependency on the nvhpc-2023 package
if [ "${NVHPC_VERSION_MAJOR}" -le 23 ] \
&& [ "${NVHPC_VERSION_MINOR}" -le 3 ]; then
pkgs+=("nvhpc-20${NVHPC_VERSION_MAJOR}=${NVHPC_VERSION}");
fi
check_packages "${pkgs[@]}";
export NVHPC="/opt/nvidia/hpc_sdk";
export NVHPC_VERSION="${NVHPC_VERSION}";
export NVHPC_VERSION_MAJOR="${NVHPC_VERSION_MAJOR}";
export NVHPC_VERSION_MINOR="${NVHPC_VERSION_MINOR}";
export NVHPC_ROOT="${NVHPC}/Linux_$(uname -p)/${NVHPC_VERSION}";
export NVHPC_CUDA_HOME="$(dirname "$(find "$NVHPC_ROOT/cuda" -type f -name 'version.json' | head -n1)")";
export NVHPC_MODULEFILE_DIRS="($(find "${NVHPC}/" -type d -name modulefiles -exec echo -n \"{}\"\ \;))";
if ! test -L /usr/local/cuda; then
# Create /usr/local/cuda symlink (for clangd)
ln -s "${NVHPC_CUDA_HOME}" /usr/local/cuda;
fi
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))";
export NVHPC_CUDA_VERSION="$NVHPC_CUDA_VERSION_MAJOR.$NVHPC_CUDA_VERSION_MINOR.$NVHPC_CUDA_VERSION_PATCH";
bash "${NVHPC_ROOT}/compilers/bin/makelocalrc" \
-x "${NVHPC_ROOT}/compilers/bin" \
-gcc "$(which gcc)" \
-gpp "$(which g++)" \
-g77 "$(which gfortran)";
vars_=();
vars_+=('$NVHPC');
vars_+=('$NVHPC_CUDA_VERSION');
vars_+=('$NVHPC_CUDA_VERSION_MAJOR');
vars_+=('$NVHPC_CUDA_VERSION_MINOR');
vars_+=('$NVHPC_CUDA_VERSION_PATCH');
vars_+=('$NVHPC_VERSION');
vars_+=('$NVHPC_VERSION_MAJOR');
vars_+=('$NVHPC_VERSION_MINOR');
vars_+=('$NVHPC_ROOT');
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_%,}"))";
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_%,}"))";
# Clean up
# rm -rf /tmp/*;
rm -rf /var/tmp/*;
rm -rf /var/cache/apt/*;
rm -rf /var/lib/apt/lists/*;