Skip to content

Commit e3b318b

Browse files
cuda installation tweaks
1 parent c75b6de commit e3b318b

File tree

6 files changed

+115
-13
lines changed

6 files changed

+115
-13
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ For upcoming features and changes and full history see [Patch Notes](CHANGELOG.m
146146
To compile from source, you need an installation of CUDA. If `nvcc` is not installed, you can install the CUDA Toolkit with nvcc through the following commands.
147147

148148
```bash
149-
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/cuda_install.sh
149+
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/install_cuda.sh
150150
# Syntax cuda_install CUDA_VERSION INSTALL_PREFIX EXPORT_TO_BASH
151-
# CUDA_VERSION in {110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121}
151+
# CUDA_VERSION in {110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122}
152152
# EXPORT_TO_BASH in {0, 1} with 0=False and 1=True
153153

154-
# For example, the following installs CUDA 11.8 to ~/local/cuda-11.8 and exports the path to your .bashrc
155-
bash cuda install 118 ~/local 1
154+
# For example, the following installs CUDA 11.7 to ~/local/cuda-11.7 and exports the path to your .bashrc
155+
bash install_cuda.sh 117 ~/local 1
156156
```
157157

158158
To use a specific CUDA version just for a single compile run, you can set the variable `CUDA_HOME`, for example the following command compiles `libbitsandbytes_cuda117.so` using compiler flags for cuda11x with the cuda version at `~/local/cuda-11.7`:

bitsandbytes/cuda_setup/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def generate_instructions(self):
6464
self.add_log_entry('CUDA SETUP: Solution 1b): Once the library is found add it to the LD_LIBRARY_PATH: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:FOUND_PATH_FROM_1a')
6565
self.add_log_entry('CUDA SETUP: Solution 1c): For a permanent solution add the export from 1b into your .bashrc file, located at ~/.bashrc')
6666
self.add_log_entry('CUDA SETUP: Solution 2: If no library was found in step 1a) you need to install CUDA.')
67-
self.add_log_entry('CUDA SETUP: Solution 2a): Download CUDA install script: wget https://github.com/TimDettmers/bitsandbytes/blob/main/cuda_install.sh')
68-
self.add_log_entry('CUDA SETUP: Solution 2b): Install desired CUDA version to desired location. The syntax is bash cuda_install.sh CUDA_VERSION PATH_TO_INSTALL_INTO.')
69-
self.add_log_entry('CUDA SETUP: Solution 2b): For example, "bash cuda_install.sh 113 ~/local/" will download CUDA 11.3 and install into the folder ~/local')
67+
self.add_log_entry('CUDA SETUP: Solution 2a): Download CUDA install script: wget https://github.com/TimDettmers/bitsandbytes/blob/main/install_cuda.sh')
68+
self.add_log_entry('CUDA SETUP: Solution 2b): Install desired CUDA version to desired location. The syntax is bash install_cuda.sh CUDA_VERSION PATH_TO_INSTALL_INTO.')
69+
self.add_log_entry('CUDA SETUP: Solution 2b): For example, "bash install_cuda.sh 113 ~/local/" will download CUDA 11.3 and install into the folder ~/local')
7070
return
7171

7272
make_cmd = f'CUDA_VERSION={self.cuda_version_string}'

compile_from_source.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ To run these steps you will need to have the nvcc compiler installed that comes
99
You can install CUDA locally without sudo by following the following steps:
1010

1111
```bash
12-
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/cuda_install.sh
12+
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/install_cuda.sh
1313
# Syntax cuda_install CUDA_VERSION INSTALL_PREFIX EXPORT_TO_BASH
1414
# CUDA_VERSION in {110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121}
1515
# EXPORT_TO_BASH in {0, 1} with 0=False and 1=True
1616

1717
# For example, the following installs CUDA 11.7 to ~/local/cuda-11.7 and exports the path to your .bashrc
18-
bash cuda install 117 ~/local 1
18+
bash install_cuda.sh 117 ~/local 1
1919
```
2020

2121
By default, the Makefile will look at your `CUDA_HOME` environmental variable to find your CUDA version for compiling the library. If this path is not set it is inferred from the path of your `nvcc` compiler.

how_to_use_nonpytorch_cuda.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ where XX.X is the CUDA version number.
1515
You can also install CUDA version that you need locally with a script provided by bitsandbytes as follows:
1616

1717
```bash
18-
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/cuda_install.sh
18+
wget https://raw.githubusercontent.com/TimDettmers/bitsandbytes/main/install_cuda.sh
1919
# Syntax cuda_install CUDA_VERSION INSTALL_PREFIX EXPORT_TO_BASH
2020
# CUDA_VERSION in {110, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122}
2121
# EXPORT_TO_BASH in {0, 1} with 0=False and 1=True
2222

2323
# For example, the following installs CUDA 11.7 to ~/local/cuda-11.7 and exports the path to your .bashrc
24-
bash cuda install 117 ~/local 1
24+
bash install_cuda.sh 117 ~/local 1
2525
```
2626

2727
## Setting the environmental variables BNB_CUDA_VERSION, and LD_LIBRARY_PATH

install_cuda.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import os
2+
import sys
3+
import subprocess
4+
from urllib.request import urlretrieve
5+
6+
cuda_versions = {
7+
"92": "https://developer.nvidia.com/compute/cuda/9.2/Prod2/local_installers/cuda_9.2.148_396.37_linux",
8+
"100": "https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux",
9+
"101": "https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.105_418.39_linux.run",
10+
"102": "https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run",
11+
"110": "https://developer.download.nvidia.com/compute/cuda/11.0.3/local_installers/cuda_11.0.3_450.51.06_linux.run",
12+
"111": "https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run",
13+
"112": "https://developer.download.nvidia.com/compute/cuda/11.2.2/local_installers/cuda_11.2.2_460.32.03_linux.run",
14+
"113": "https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.19.01_linux.run",
15+
"114": "https://developer.download.nvidia.com/compute/cuda/11.4.4/local_installers/cuda_11.4.4_470.82.01_linux.run",
16+
"115": "https://developer.download.nvidia.com/compute/cuda/11.5.2/local_installers/cuda_11.5.2_495.29.05_linux.run",
17+
"116": "https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run",
18+
"117": "https://developer.download.nvidia.com/compute/cuda/11.7.0/local_installers/cuda_11.7.0_515.43.04_linux.run",
19+
"118": "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run",
20+
"120": "https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda_12.0.0_525.60.13_linux.run",
21+
"121": "https://developer.download.nvidia.com/compute/cuda/12.1.0/local_installers/cuda_12.1.0_530.30.02_linux.run",
22+
"122": "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run",
23+
"123": "https://developer.download.nvidia.com/compute/cuda/12.3.1/local_installers/cuda_12.3.1_545.23.08_linux.run",
24+
}
25+
26+
27+
def install_cuda(version, base_path, download_path):
28+
formatted_version = f"{version[:-1]}.{version[-1]}"
29+
folder = f"cuda-{formatted_version}"
30+
install_path = os.path.join(base_path, folder)
31+
32+
if os.path.exists(install_path):
33+
print(f"Removing existing CUDA version {version} at {install_path}...")
34+
subprocess.run(["rm", "-rf", install_path], check=True)
35+
36+
url = cuda_versions[version]
37+
filename = url.split('/')[-1]
38+
filepath = os.path.join(download_path, filename)
39+
40+
if not os.path.exists(filepath):
41+
print(f"Downloading CUDA version {version} from {url}...")
42+
urlretrieve(url, filepath)
43+
else:
44+
print(f"Installer for CUDA version {version} already downloaded.")
45+
46+
# Make the installer executable
47+
subprocess.run(["chmod", "+x", filepath], check=True)
48+
49+
# Install CUDA
50+
print(f"Installing CUDA version {version}...")
51+
install_command = [
52+
"bash", filepath,
53+
"--no-drm", "--no-man-page", "--override",
54+
"--toolkitpath=" + install_path, "--toolkit", "--silent"
55+
]
56+
57+
print(f"Running command: {' '.join(install_command)}")
58+
59+
try:
60+
subprocess.run(install_command, check=True)
61+
except subprocess.CalledProcessError as e:
62+
print(f"Installation failed for CUDA version {version}: {e}")
63+
return
64+
finally:
65+
# Delete the installer file
66+
os.remove(filepath)
67+
68+
print(f"CUDA version {version} installed at {install_path}")
69+
70+
def main():
71+
user_base_path = os.path.expanduser("~/cuda")
72+
system_base_path = "/usr/local/cuda"
73+
base_path = user_base_path # default to user-specific installation
74+
download_path = "/tmp" # default download path
75+
76+
if len(sys.argv) < 2:
77+
print("Usage: python install_cuda.py <version/all> [user/system] [download_path]")
78+
sys.exit(1)
79+
80+
version = sys.argv[1]
81+
if len(sys.argv) > 2:
82+
base_path = system_base_path if sys.argv[2] == "system" else user_base_path
83+
if len(sys.argv) > 3:
84+
download_path = sys.argv[3]
85+
86+
if not os.path.exists(base_path):
87+
os.makedirs(base_path)
88+
if not os.path.exists(download_path):
89+
os.makedirs(download_path)
90+
91+
# Install CUDA version(s)
92+
if version == "all":
93+
for ver in cuda_versions.keys():
94+
install_cuda(ver, base_path, download_path)
95+
elif version in cuda_versions:
96+
install_cuda(version, base_path, download_path)
97+
else:
98+
print(f"Invalid CUDA version: {version}. Available versions are: {', '.join(cuda_versions.keys())}")
99+
sys.exit(1)
100+
101+
if __name__ == "__main__":
102+
main()

cuda_install.sh renamed to install_cuda.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ if [[ -n "$CUDA_VERSION" ]]; then
7474
URL=$URL123
7575
FOLDER=cuda-12.3
7676
else
77-
echo "argument error: No cuda version passed as input. Choose among versions 92 to 121"
77+
echo "argument error: No cuda version passed as input. Choose among versions 92 to 123"
7878
fi
7979
else
80-
echo "argument error: No cuda version passed as input. Choose among versions 92 to 112"
80+
echo "argument error: No cuda version passed as input. Choose among versions 92 to 123"
8181
fi
8282

8383
FILE=$(basename $URL)

0 commit comments

Comments
 (0)