Skip to content

Commit ea030fa

Browse files
Add new NVIDIA CUDA feature (#80)
* Add new Nvidia feature * Remove random empty files * Update comments * Rename feature to nvidia-cuda * Add feature to tests * Add version * Move test to match new name * Add final output message * Fix capitalization of NVIDIA * Remove option for base CUDA * Use camelCase * Check for required packages * Use os-release instead of lsb_release * Clean up keyring variables * Collapse keyring lines * Always install CUDA libraries * Add option to install NVTX * Always use ubuntu2004 repo * Use test instead of brackets * Add default values to feature * Add version options for CUDA and cuDNN * Rename CUDA version option * Add scenario to test specific CUDA/cuDNN version * Rename cuDNN scenario * Fix typo in test scenario * Update variable casing * Add more helpful error messages * Remove default values from script * Use enum for version option * Polish new scenarios * Remove apt_get_update_if_needed and check_packages * Add more versions * Improve error messages * Comments and feature description Co-authored-by: Josh Spicer <joshspicer@github.com>
1 parent ad088a1 commit ea030fa

8 files changed

Lines changed: 180 additions & 0 deletions

File tree

.github/workflows/test-all.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
"java",
2929
"kubectl-helm-minikube",
3030
"node",
31+
"nvidia-cuda",
3132
"oryx",
3233
"php",
3334
"powershell",

.github/workflows/test-pr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
java: ./**/java/**
2929
kubectl-helm-minikube: ./**/kubectl-helm-minikube/**
3030
node: ./**/node/**
31+
nvidia-cuda: ./**/nvidia-cuda/**
3132
oryx: ./**/oryx/**
3233
php: ./**/php/**
3334
powershell: ./**/powershell/**
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"id": "nvidia-cuda",
3+
"name": "NVIDIA CUDA",
4+
"description": "Installs shared libraries for NVIDIA CUDA.",
5+
"version": "1.0.0",
6+
"options": {
7+
"installCudnn": {
8+
"type": "boolean",
9+
"default": false,
10+
"description": "Additionally install CUDA Deep Neural Network (cuDNN) shared library"
11+
},
12+
"installNvtx": {
13+
"type": "boolean",
14+
"default": false,
15+
"description": "Additionally install NVIDIA Tools Extension (NVTX)"
16+
},
17+
"cudaVersion": {
18+
"type": "string",
19+
"enum": [
20+
"11.7",
21+
"11.6",
22+
"11.5",
23+
"11.4",
24+
"11.3",
25+
"11.2"
26+
],
27+
"default": "11.7",
28+
"description": "Version of CUDA to install"
29+
},
30+
"cudnnVersion": {
31+
"type": "string",
32+
"enum": [
33+
"8.5.0.96",
34+
"8.4.1.50",
35+
"8.4.0.27",
36+
"8.3.3.40",
37+
"8.3.2.44",
38+
"8.3.1.22",
39+
"8.3.0.98",
40+
"8.2.4.15",
41+
"8.2.2.26",
42+
"8.2.1.32",
43+
"8.2.0.53",
44+
"8.1.1.33",
45+
"8.1.0.77"
46+
],
47+
"default": "8.5.0.96",
48+
"description": "Version of cuDNN to install"
49+
}
50+
}
51+
}

src/nvidia-cuda/install.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
INSTALL_CUDNN=${INSTALLCUDNN}
6+
INSTALL_NVTX=${INSTALLNVTX}
7+
CUDA_VERSION=${CUDAVERSION}
8+
CUDNN_VERSION=${CUDNNVERSION}
9+
10+
if [ "$(id -u)" -ne 0 ]; then
11+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
12+
exit 1
13+
fi
14+
15+
# Install dependencies
16+
apt-get update -yq
17+
apt-get install -yq wget ca-certificates
18+
19+
# Add NVIDIA's package repository to apt so that we can download packages
20+
# Always use the ubuntu2004 repo because the other repos (e.g., debian11) are missing packages
21+
NVIDIA_REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64"
22+
KEYRING_PACKAGE="cuda-keyring_1.0-1_all.deb"
23+
KEYRING_PACKAGE_URL="$NVIDIA_REPO_URL/$KEYRING_PACKAGE"
24+
KEYRING_PACKAGE_PATH="$(mktemp -d)"
25+
KEYRING_PACKAGE_FILE="$KEYRING_PACKAGE_PATH/$KEYRING_PACKAGE"
26+
wget -O "$KEYRING_PACKAGE_FILE" "$KEYRING_PACKAGE_URL"
27+
apt-get install -yq "$KEYRING_PACKAGE_FILE"
28+
apt-get update -yq
29+
30+
# Ensure that the requested version of CUDA is available
31+
cuda_pkg="cuda-libraries-${CUDA_VERSION/./-}"
32+
nvtx_pkg="cuda-nvtx-${CUDA_VERSION/./-}"
33+
if ! apt-cache show "$cuda_pkg"; then
34+
echo "The requested version of CUDA is not available: CUDA $CUDA_VERSION"
35+
exit 1
36+
fi
37+
38+
# Ensure that the requested version of cuDNN is available AND compatible
39+
cudnn_pkg_version="libcudnn8=${CUDNN_VERSION}-1+cuda${CUDA_VERSION}"
40+
if ! apt-cache show "$cudnn_pkg_version"; then
41+
echo "The requested version of cuDNN is not available: cuDNN $CUDNN_VERSION for CUDA $CUDA_VERSION"
42+
exit 1
43+
fi
44+
45+
echo "Installing CUDA libraries..."
46+
apt-get install -yq "$cuda_pkg"
47+
48+
if [ "$INSTALL_CUDNN" = "true" ]; then
49+
echo "Installing cuDNN libraries..."
50+
apt-get install -yq "$cudnn_pkg_version"
51+
fi
52+
53+
if [ "$INSTALL_NVTX" = "true" ]; then
54+
echo "Installing NVTX..."
55+
apt-get install -yq "$nvtx_pkg"
56+
fi
57+
58+
echo "Done!"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Check installation of libcudnn8
9+
check "libcudnn.so.8" test 1 -eq "$(find /usr -name 'libcudnn.so.8' | wc -l)"
10+
11+
# Check installation of cuda-nvtx-11-<version>
12+
check "cuda-11+nvtx" test -e '/usr/local/cuda-11/targets/x86_64-linux/include/nvtx3'
13+
14+
# Report result
15+
reportResults
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Check installation of libcudnn8 (8.3.2)
9+
check "libcudnn.so.8.3.2" test 1 -eq "$(find /usr -name 'libcudnn.so.8.3.2' | wc -l)"
10+
11+
# Check installation of cuda-nvtx-11-5 (11.5)
12+
check "cuda-11-5+nvtx" test -e '/usr/local/cuda-11.5/targets/x86_64-linux/include/nvtx3'
13+
14+
# Report result
15+
reportResults
16+

test-scenarios/scenarios.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,25 @@
9191
"version": "3"
9292
}
9393
}
94+
},
95+
"install_cudnn_nvxt": {
96+
"image": "debian",
97+
"features": {
98+
"nvidia-cuda": {
99+
"installCudnn": true,
100+
"installNvtx": true
101+
}
102+
}
103+
},
104+
"install_cudnn_nvxt_version": {
105+
"image": "debian",
106+
"features": {
107+
"nvidia-cuda": {
108+
"installCudnn": true,
109+
"installNvtx": true,
110+
"cudaVersion": "11.5",
111+
"cudnnVersion": "8.3.2.44"
112+
}
113+
}
94114
}
95115
}

test/nvidia-cuda/test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Check installation of cuda-libraries-11-<version>
9+
check "libcudart.so.11.0" test 1 -eq "$(find /usr -name 'libcudart.so.11.0' | wc -l)"
10+
check "libcublas.so.11" test 1 -eq "$(find /usr -name 'libcublas.so.11' | wc -l)"
11+
check "libcublasLt.so.11" test 1 -eq "$(find /usr -name 'libcublasLt.so.11' | wc -l)"
12+
check "libcufft.so.10" test 1 -eq "$(find /usr -name 'libcufft.so.10' | wc -l)"
13+
check "libcurand.so.10" test 1 -eq "$(find /usr -name 'libcurand.so.10' | wc -l)"
14+
check "libcusolver.so.11" test 1 -eq "$(find /usr -name 'libcusolver.so.11' | wc -l)"
15+
check "libcusparse.so.11" test 1 -eq "$(find /usr -name 'libcusparse.so.11' | wc -l)"
16+
17+
# Report result
18+
reportResults

0 commit comments

Comments
 (0)