Skip to content

Commit 1e38444

Browse files
authored
Merge pull request #486 from johnnynunez/master
Simplify Installation Cuda and latest Cuda
2 parents 0b85840 + d643f24 commit 1e38444

File tree

5 files changed

+124
-156
lines changed

5 files changed

+124
-156
lines changed

.github/workflows/main.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ jobs:
1515
strategy:
1616
matrix:
1717
include:
18+
- os: ubuntu-24.04
19+
cuda: "12.6"
20+
arch: 89
21+
- os: ubuntu-24.04
22+
cuda: "12.5"
23+
arch: 86
24+
- os: ubuntu-22.04
25+
cuda: "11.8"
26+
arch: 89
1827
- os: ubuntu-22.04
1928
cuda: "11.7"
2029
arch: 89
@@ -43,7 +52,7 @@ jobs:
4352
steps:
4453
- name: Install dependencies
4554
run: sudo apt-get update && sudo apt-get install cmake gcc g++
46-
- uses: actions/checkout@v3
55+
- uses: actions/checkout@v4
4756
with:
4857
submodules: recursive
4958
- name: Install CUDA
@@ -63,6 +72,14 @@ jobs:
6372
strategy:
6473
matrix:
6574
include:
75+
- os: windows-2025
76+
visual_studio: "Visual Studio 17 2022"
77+
cuda: "12.6.3"
78+
arch: 89
79+
- os: windows-2025
80+
visual_studio: "Visual Studio 17 2022"
81+
cuda: "12.5.0"
82+
arch: 86
6683
- os: windows-2019
6784
visual_studio: "Visual Studio 16 2019"
6885
cuda: "11.5.1"

LICENSE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved.
1+
Copyright (c) 2020-2025, NVIDIA CORPORATION. All rights reserved.
22

33
Redistribution and use in source and binary forms, with or without modification, are permitted
44
provided that the following conditions are met:
@@ -18,4 +18,4 @@ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAG
1818
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
1919
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2020
STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ sudo apt-get install build-essential git
9898
```
9999

100100
We also recommend installing [CUDA](https://developer.nvidia.com/cuda-toolkit) in `/usr/local/` and adding the CUDA installation to your PATH.
101-
For example, if you have CUDA 11.4, add the following to your `~/.bashrc`
101+
For example, if you have CUDA 12.6.3, add the following to your `~/.bashrc`
102102
```sh
103-
export PATH="/usr/local/cuda-11.4/bin:$PATH"
104-
export LD_LIBRARY_PATH="/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH"
103+
export PATH="/usr/local/cuda-12.6.3/bin:$PATH"
104+
export LD_LIBRARY_PATH="/usr/local/cuda-12.6.3/lib64:$LD_LIBRARY_PATH"
105105
```
106106

107107

Original file line numberDiff line numberDiff line change
@@ -1,181 +1,129 @@
1-
# @todo - better / more robust parsing of inputs from env vars.
1+
#!/bin/bash
2+
23
## -------------------
3-
## Constants
4+
## Configuration
45
## -------------------
56

6-
# @todo - apt repos/known supported versions?
7-
8-
# @todo - GCC support matrix?
9-
10-
# List of sub-packages to install.
11-
# @todo - pass this in from outside the script?
12-
# @todo - check the specified subpackages exist via apt pre-install? apt-rdepends cuda-9-0 | grep "^cuda-"?
13-
14-
# Ideally choose from the list of meta-packages to minimise variance between cuda versions (although it does change too)
15-
CUDA_PACKAGES_IN=(
16-
"command-line-tools"
17-
"libraries-dev"
7+
# CUDA sub-packages to install.
8+
declare -a CUDA_PACKAGES_IN=(
9+
"cuda-command-line-tools"
10+
"cuda-libraries-dev"
11+
"cuda-nvcc"
1812
)
1913

2014
## -------------------
21-
## Bash functions
15+
## Helper Functions
2216
## -------------------
23-
# returns 0 (true) if a >= b
24-
function version_ge() {
25-
[ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1
26-
[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" == "$2" ]
27-
}
28-
# returns 0 (true) if a > b
29-
function version_gt() {
30-
[ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1
31-
[ "$1" = "$2" ] && return 1 || version_ge $1 $2
32-
}
33-
# returns 0 (true) if a <= b
34-
function version_le() {
35-
[ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1
36-
[ "$(printf '%s\n' "$@" | sort -V | head -n 1)" == "$1" ]
37-
}
38-
# returns 0 (true) if a < b
39-
function version_lt() {
40-
[ "$#" != "2" ] && echo "${FUNCNAME[0]} requires exactly 2 arguments." && exit 1
41-
[ "$1" = "$2" ] && return 1 || version_le $1 $2
17+
18+
# Function to check if a command exists
19+
command_exists() {
20+
command -v "$1" >/dev/null 2>&1
4221
}
4322

4423
## -------------------
45-
## Select CUDA version
24+
## Input Validation and Environment Setup
4625
## -------------------
4726

48-
# Get the cuda version from the environment as $cuda.
49-
CUDA_VERSION_MAJOR_MINOR=${cuda}
27+
# Get CUDA version from environment variable 'cuda'
28+
CUDA_VERSION_MAJOR_MINOR="${cuda}"
5029

51-
# Split the version.
52-
# We (might/probably) don't know PATCH at this point - it depends which version gets installed.
53-
CUDA_MAJOR=$(echo "${CUDA_VERSION_MAJOR_MINOR}" | cut -d. -f1)
54-
CUDA_MINOR=$(echo "${CUDA_VERSION_MAJOR_MINOR}" | cut -d. -f2)
55-
CUDA_PATCH=$(echo "${CUDA_VERSION_MAJOR_MINOR}" | cut -d. -f3)
56-
# use lsb_release to find the OS.
57-
UBUNTU_VERSION=$(lsb_release -sr)
58-
UBUNTU_VERSION="${UBUNTU_VERSION//.}"
59-
60-
echo "CUDA_MAJOR: ${CUDA_MAJOR}"
61-
echo "CUDA_MINOR: ${CUDA_MINOR}"
62-
echo "CUDA_PATCH: ${CUDA_PATCH}"
63-
# echo "UBUNTU_NAME: ${UBUNTU_NAME}"
64-
echo "UBUNTU_VERSION: ${UBUNTU_VERSION}"
65-
66-
# If we don't know the CUDA_MAJOR or MINOR, error.
67-
if [ -z "${CUDA_MAJOR}" ] ; then
68-
echo "Error: Unknown CUDA Major version. Aborting."
69-
exit 1
30+
# Validate CUDA version
31+
if [ -z "$CUDA_VERSION_MAJOR_MINOR" ]; then
32+
echo "Error: CUDA version not specified. Please set the 'cuda' environment variable (e.g., cuda=12.2)."
33+
exit 1
7034
fi
71-
if [ -z "${CUDA_MINOR}" ] ; then
72-
echo "Error: Unknown CUDA Minor version. Aborting."
73-
exit 1
35+
36+
CUDA_MAJOR=$(echo "$CUDA_VERSION_MAJOR_MINOR" | cut -d. -f1)
37+
CUDA_MINOR=$(echo "$CUDA_VERSION_MAJOR_MINOR" | cut -d. -f2)
38+
39+
# Check for root/sudo
40+
if ! command_exists sudo && [ "$EUID" -ne 0 ]; then
41+
echo "Error: This script requires root privileges. Please run with sudo."
42+
exit 1
7443
fi
75-
# If we don't know the Ubuntu version, error.
76-
if [ -z ${UBUNTU_VERSION} ]; then
77-
echo "Error: Unknown Ubuntu version. Aborting."
78-
exit 1
44+
45+
SUDO_CMD=""
46+
if [ "$EUID" -ne 0 ]; then
47+
SUDO_CMD="sudo"
7948
fi
8049

50+
# Get Ubuntu version
51+
UBUNTU_VERSION=$(lsb_release -sr)
8152

82-
## ---------------------------
83-
## GCC studio support check?
84-
## ---------------------------
53+
# Validate Ubuntu version
54+
if [ -z "$UBUNTU_VERSION" ]; then
55+
echo "Error: Could not determine Ubuntu version."
56+
exit 1
57+
fi
8558

86-
# @todo
59+
# Format Ubuntu version for URLs (e.g., 20.04 -> 2004)
60+
UBUNTU_VERSION_FORMATTED=$(echo "$UBUNTU_VERSION" | tr -d '.')
8761

88-
## -------------------------------
89-
## Select CUDA packages to install
90-
## -------------------------------
91-
CUDA_PACKAGES=""
92-
for package in "${CUDA_PACKAGES_IN[@]}"
93-
do :
94-
# @todo This is not perfect. Should probably provide a separate list for diff versions
95-
# cuda-compiler-X-Y if CUDA >= 9.1 else cuda-nvcc-X-Y
96-
if [[ "${package}" == "nvcc" ]] && version_ge "$CUDA_VERSION_MAJOR_MINOR" "9.1" ; then
97-
package="compiler"
98-
elif [[ "${package}" == "compiler" ]] && version_lt "$CUDA_VERSION_MAJOR_MINOR" "9.1" ; then
99-
package="nvcc"
100-
fi
101-
# Build the full package name and append to the string.
102-
CUDA_PACKAGES+=" cuda-${package}-${CUDA_MAJOR}-${CUDA_MINOR}"
103-
done
104-
echo "CUDA_PACKAGES ${CUDA_PACKAGES}"
62+
echo "CUDA Version: $CUDA_VERSION_MAJOR_MINOR"
63+
echo "Ubuntu Version: $UBUNTU_VERSION"
64+
echo "Ubuntu Version Formatted: $UBUNTU_VERSION_FORMATTED"
10565

106-
## -----------------
107-
## Prepare to install
108-
## -----------------
66+
## -------------------
67+
## Install CUDA
68+
## -------------------
10969

110-
PIN_FILENAME="cuda-ubuntu${UBUNTU_VERSION}.pin"
111-
PIN_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/${PIN_FILENAME}"
112-
APT_KEY_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/3bf863cc.pub"
113-
REPO_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION}/x86_64/"
70+
# Download and install the CUDA keyring
71+
KEYRING_URL="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION_FORMATTED}/x86_64/cuda-keyring_1.1-1_all.deb"
72+
echo "Downloading CUDA keyring from: $KEYRING_URL"
73+
wget -nv "$KEYRING_URL" -O cuda-keyring.deb
74+
$SUDO_CMD dpkg -i cuda-keyring.deb
75+
rm cuda-keyring.deb
11476

115-
echo "PIN_FILENAME ${PIN_FILENAME}"
116-
echo "PIN_URL ${PIN_URL}"
117-
echo "APT_KEY_URL ${APT_KEY_URL}"
77+
# Update package list
78+
echo "Updating package list..."
79+
$SUDO_CMD apt-get update
11880

119-
## -----------------
120-
## Check for root/sudo
121-
## -----------------
81+
# Construct the list of CUDA packages to install
82+
CUDA_PACKAGES=""
83+
for package in "${CUDA_PACKAGES_IN[@]}"; do
84+
CUDA_PACKAGES+=" ${package}-${CUDA_MAJOR}-${CUDA_MINOR}"
85+
done
12286

123-
# Detect if the script is being run as root, storing true/false in is_root.
124-
is_root=false
125-
if (( $EUID == 0)); then
126-
is_root=true
127-
fi
128-
# Find if sudo is available
129-
has_sudo=false
130-
if command -v sudo &> /dev/null ; then
131-
has_sudo=true
132-
fi
133-
# Decide if we can proceed or not (root or sudo is required) and if so store whether sudo should be used or not.
134-
if [ "$is_root" = false ] && [ "$has_sudo" = false ]; then
135-
echo "Root or sudo is required. Aborting."
136-
exit 1
137-
elif [ "$is_root" = false ] ; then
138-
USE_SUDO=sudo
139-
else
140-
USE_SUDO=
87+
# Special handling for nvcc in older versions
88+
if (( $(echo "$CUDA_MAJOR < 9" | bc -l) )); then
89+
CUDA_PACKAGES+=" cuda-nvcc-${CUDA_MAJOR}-${CUDA_MINOR}"
14190
fi
14291

143-
## -----------------
144-
## Install
145-
## -----------------
146-
echo "Adding CUDA Repository"
147-
wget ${PIN_URL}
148-
$USE_SUDO mv ${PIN_FILENAME} /etc/apt/preferences.d/cuda-repository-pin-600
149-
$USE_SUDO apt-key adv --fetch-keys ${APT_KEY_URL}
150-
$USE_SUDO add-apt-repository "deb ${REPO_URL} /"
151-
$USE_SUDO apt-get update
152-
153-
echo "Installing CUDA packages ${CUDA_PACKAGES}"
154-
$USE_SUDO apt-get -y install ${CUDA_PACKAGES}
155-
156-
if [[ $? -ne 0 ]]; then
157-
echo "CUDA Installation Error."
158-
exit 1
92+
# Install CUDA packages
93+
echo "Installing CUDA packages: $CUDA_PACKAGES"
94+
$SUDO_CMD apt-get install -y --no-install-recommends $CUDA_PACKAGES
95+
96+
if [ $? -ne 0 ]; then
97+
echo "Error: Failed to install CUDA packages."
98+
exit 1
15999
fi
160-
## -----------------
161-
## Set environment vars / vars to be propagated
162-
## -----------------
163100

164-
CUDA_PATH=/usr/local/cuda-${CUDA_MAJOR}.${CUDA_MINOR}
165-
echo "CUDA_PATH=${CUDA_PATH}"
166-
export CUDA_PATH=${CUDA_PATH}
101+
## -------------------
102+
## Environment Variables
103+
## -------------------
167104

105+
CUDA_PATH="/usr/local/cuda-${CUDA_MAJOR}.${CUDA_MINOR}"
106+
echo "CUDA_PATH=$CUDA_PATH"
168107

169-
# Quick test. @temp
108+
# Update environment variables for the current shell
109+
export CUDA_PATH
170110
export PATH="$CUDA_PATH/bin:$PATH"
171-
export LD_LIBRARY_PATH="$CUDA_PATH/lib:$LD_LIBRARY_PATH"
172-
nvcc -V
173-
174-
# If executed on github actions, make the appropriate echo statements to update the environment
175-
if [[ $GITHUB_ACTIONS ]]; then
176-
# Set paths for subsequent steps, using ${CUDA_PATH}
177-
echo "Adding CUDA to CUDA_PATH, PATH and LD_LIBRARY_PATH"
178-
echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV
179-
echo "${CUDA_PATH}/bin" >> $GITHUB_PATH
180-
echo "LD_LIBRARY_PATH=${CUDA_PATH}/lib:${LD_LIBRARY_PATH}" >> $GITHUB_ENV
111+
export LD_LIBRARY_PATH="$CUDA_PATH/lib64:$LD_LIBRARY_PATH"
112+
113+
# Verify installation (optional)
114+
echo "Verifying installation..."
115+
if command_exists nvcc; then
116+
nvcc --version
117+
else
118+
echo "Warning: nvcc not found. Installation might be incomplete."
181119
fi
120+
121+
# Update environment variables for GitHub Actions (if applicable)
122+
if [ -n "$GITHUB_ACTIONS" ]; then
123+
echo "Setting environment variables for GitHub Actions..."
124+
echo "CUDA_PATH=$CUDA_PATH" >> "$GITHUB_ENV"
125+
echo "$CUDA_PATH/bin" >> "$GITHUB_PATH"
126+
echo "LD_LIBRARY_PATH=$CUDA_PATH/lib64:$LD_LIBRARY_PATH" >> "$GITHUB_ENV"
127+
fi
128+
129+
echo "CUDA installation complete."

dependencies/cuda-cmake-github-actions/scripts/actions/install_cuda_windows.ps1

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Dictionary of known cuda versions and thier download URLS, which do not follow a consistent pattern :(
66
$CUDA_KNOWN_URLS = @{
7-
"8.0.44" = "http://developer.nvidia.com/compute/cuda/8.0/Prod/network_installers/cuda_8.0.44_win10_network-exe";
7+
"8.0.44" = "http://developer.nvidia.com/compute/cuda/8.0/Prod/network_installers/cuda_8.0.44_win10_network-exe";
88
"8.0.61" = "http://developer.nvidia.com/compute/cuda/8.0/Prod2/network_installers/cuda_8.0.61_win10_network-exe";
99
"9.0.176" = "http://developer.nvidia.com/compute/cuda/9.0/Prod/network_installers/cuda_9.0.176_win10_network-exe";
1010
"9.1.85" = "http://developer.nvidia.com/compute/cuda/9.1/Prod/network_installers/cuda_9.1.85_win10_network";
@@ -25,7 +25,10 @@ $CUDA_KNOWN_URLS = @{
2525
"11.3.0" = "https://developer.download.nvidia.com/compute/cuda/11.3.0/network_installers/cuda_11.3.0_win10_network.exe";
2626
"11.3.1" = "https://developer.download.nvidia.com/compute/cuda/11.3.1/network_installers/cuda_11.3.1_win10_network.exe";
2727
"11.5.0" = "https://developer.download.nvidia.com/compute/cuda/11.5.0/network_installers/cuda_11.5.0_win10_network.exe";
28-
"11.5.1" = "https://developer.download.nvidia.com/compute/cuda/11.5.1/network_installers/cuda_11.5.1_windows_network.exe"
28+
"11.5.1" = "https://developer.download.nvidia.com/compute/cuda/11.5.1/network_installers/cuda_11.5.1_windows_network.exe";
29+
"11.8.0" = "https://developer.download.nvidia.com/compute/cuda/11.8.0/network_installers/cuda_11.8.0_windows_network.exe";
30+
"12.5.0" = "https://developer.download.nvidia.com/compute/cuda/12.5.0/network_installers/cuda_12.5.0_windows_network.exe";
31+
"12.6.3" = "https://developer.download.nvidia.com/compute/cuda/12.6.3/network_installers/cuda_12.6.3_windows_network.exe";
2932
}
3033

3134
# @todo - change this to be based on _MSC_VER intead, or invert it to be CUDA keyed instead?

0 commit comments

Comments
 (0)