|
1 | 1 | set -e |
2 | | -source /etc/os-release |
3 | | -MAJOR_VERSION_ID=${VERSION_ID%%.*} |
4 | 2 |
|
5 | | -verify_driver() { |
6 | | - # Verify NVIDIA driver: |
7 | | - # Installation could finish successfully but the driver is still unusable |
8 | | - # A common error when running this check: |
9 | | - # "NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA |
10 | | - # driver. Make sure that the latest NVIDIA driver is installed and running." |
11 | | - nvidia-smi |
12 | | -} |
| 3 | +# DCGM and CUDA toolkit share the same NVIDIA repo, which has already been configured in the image |
| 4 | +# Install DCGM |
| 5 | +sudo yum install -y datacenter-gpu-manager |
| 6 | +sudo systemctl --now enable nvidia-dcgm |
13 | 7 |
|
14 | | -install_cuda_from_runfile() { |
15 | | - # Ref: https://docs.nvidia.com/datacenter/tesla/tesla-installation-notes/index.html#runfile |
16 | | - # This method requires the matching kernel-devel package to be installed, and |
17 | | - # the package may be absent from the repo and cause this method to fail |
18 | | - # Remove existing installation before using the runfile |
19 | | - remove_cuda_package |
20 | | - remove_driver_package |
21 | | - # For Rocky Linux 9: when a new OS version becomes available, the default |
22 | | - # repo setting (/etc/yum.repos.d/rocky.repo) will automatically point to the |
23 | | - # new version's repo. This is problematic since the new OS is not available |
24 | | - # right away on GCE. Set up the matched repo to install the correct |
25 | | - # kernel-devel-$(uname -r) |
26 | | - # Not needed for RL8 since 8.10 is already the last RL8 release. |
27 | | - REPO_URL="https://dl.rockylinux.org/vault/rocky/$VERSION_ID/AppStream/x86_64/os/" |
28 | | - REPO_METADATA="$REPO_URL/repodata/repomd.xml" |
29 | | - STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$REPO_METADATA") |
30 | | - if [[ $ID == rocky && "$MAJOR_VERSION_ID" == 9 && "$STATUS_CODE" == "200" ]]; then |
31 | | - cat <<EOF | sudo tee /etc/yum.repos.d/rocky-matched.repo |
32 | | -[appstream-matched] |
33 | | -name=Rocky Linux \$releasever - AppStream - Matched |
34 | | -baseurl=$REPO_URL |
35 | | -gpgcheck=1 |
36 | | -enabled=1 |
37 | | -countme=1 |
38 | | -metadata_expire=6h |
39 | | -gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 |
40 | | -EOF |
41 | | - fi |
42 | | - sudo yum install -y pciutils gcc make wget yum-utils |
43 | | - local KERNEL_PACKAGE="kernel-devel-$(uname -r)" |
44 | | - if [[ $ID == rocky && "$MAJOR_VERSION_ID" == 9 && "$STATUS_CODE" == "403" ]]; then |
45 | | - wget https://dl.rockylinux.org/vault/rocky/$VERSION_ID/AppStream/x86_64/os/Packages/k/${KERNEL_PACKAGE}.rpm |
46 | | - KERNEL_PACKAGE=${KERNEL_PACKAGE}.rpm |
47 | | - fi |
48 | | - |
49 | | - sudo yum install -y $KERNEL_PACKAGE |
50 | | - # Installing latest version of NVIDIA CUDA and driver |
51 | | - local CUDA_VERSION=12.9.0 |
52 | | - local CUDA_BUNDLED_DRIVER_VERSION=575.51.03 |
53 | | - echo "Installing CUDA Toolkit $CUDA_VERSION from CUDA installer with bundled driver $CUDA_BUNDLED_DRIVER_VERSION" |
54 | | - curl -fSsl -O https://developer.download.nvidia.com/compute/cuda/$CUDA_VERSION/local_installers/cuda_${CUDA_VERSION}_${CUDA_BUNDLED_DRIVER_VERSION}_linux.run |
55 | | - sudo sh cuda_${CUDA_VERSION}_${CUDA_BUNDLED_DRIVER_VERSION}_linux.run --silent |
56 | | - verify_driver |
57 | | -} |
58 | | - |
59 | | -setup_repo() { |
60 | | - # Enable EPEL (Extra Packages for Enterprise Linux) for packages such as DKMS |
61 | | - # Ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#prepare-rhel-9-rocky-9 |
62 | | - sudo yum install -y yum-utils epel-release |
63 | | - sudo yum-config-manager \ |
64 | | - --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel$MAJOR_VERSION_ID/x86_64/cuda-rhel$MAJOR_VERSION_ID.repo |
65 | | - sudo yum clean all |
66 | | -} |
67 | | - |
68 | | -install_cuda_from_package_manager() { |
69 | | - setup_repo |
70 | | - install_driver_package |
71 | | - # TODO(b/377558109): remove the temporary fix once the repo is updated |
72 | | - sudo yum -y install cuda-toolkit-12-9 cuda-demo* |
73 | | - verify_driver |
74 | | -} |
75 | | - |
76 | | -remove_cuda_package() { |
77 | | - # Ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#removing-cuda-toolkit-and-driver |
78 | | - sudo yum -y remove "cuda*" "*cublas*" "*cufft*" "*cufile*" "*curand*" \ |
79 | | - "*cusolver*" "*cusparse*" "*gds-tools*" "*npp*" "*nvjpeg*" "nsight*" \ |
80 | | - "*nvvm*" |
81 | | -} |
82 | | - |
83 | | -install_dcgm() { |
84 | | - # Ref: https://docs.nvidia.com/datacenter/dcgm/latest/user-guide/getting-started.html#rhel-centos-rocky-linux |
85 | | - setup_repo |
86 | | - sudo yum install -y datacenter-gpu-manager |
87 | | - sudo systemctl --now enable nvidia-dcgm |
88 | | - |
89 | | - # check DCGM service running and load profiling module |
90 | | - dcgmi discovery --list |
91 | | -} |
92 | | - |
93 | | -try_install() { |
94 | | - # Export all functions for the bash subprocess |
95 | | - eval "$(declare -F | sed 's/ -f / -fx /')" |
96 | | - export ID MAJOR_VERSION_ID VERSION_ID |
97 | | - for install_method in "$@"; do |
98 | | - echo "Installing NVIDIA driver and CUDA with $install_method..." |
99 | | - # Can't use a subshell because of https://lists.gnu.org/archive/html/bug-bash/2012-12/msg00094.html |
100 | | - bash -$- -c $install_method && { |
101 | | - echo "NVIDIA driver and CUDA has been installed successfully with $install_method." |
102 | | - return 0 |
103 | | - } |
104 | | - done |
105 | | - echo "NVIDIA driver and CUDA cannot be installed; all installation methods failed." |
106 | | - return 1 |
107 | | -} |
108 | | - |
109 | | -handle_rhel9() { |
110 | | - install_driver_package() { |
111 | | - # Ref: https://developer.nvidia.com/cuda-12-9-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=RHEL&target_version=8&target_type=rpm_network |
112 | | - sudo yum -y module install nvidia-driver:575-dkms |
113 | | - } |
114 | | -} |
115 | | - |
116 | | -handle_common() { |
117 | | - install_driver_package() { |
118 | | - # Ref: https://developer.nvidia.com/cuda-12-2-2-download-archive?target_os=Linux&target_arch=x86_64&Distribution=RHEL&target_version=8&target_type=rpm_network |
119 | | - sudo yum -y module install nvidia-driver |
120 | | - } |
121 | | -} |
122 | | - |
123 | | -remove_driver_package() { |
124 | | - # Ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#removing-cuda-toolkit-and-driver |
125 | | - sudo yum -y module remove --all nvidia-driver |
126 | | -} |
127 | | - |
128 | | -case "$MAJOR_VERSION_ID" in |
129 | | - 9) handle_rhel9;; |
130 | | - *) handle_common;; |
131 | | -esac |
132 | | -try_install install_cuda_from_package_manager install_cuda_from_runfile |
133 | | -install_dcgm |
| 8 | +# check DCGM service running and load profiling module |
| 9 | +dcgmi discovery --list |
0 commit comments