Skip to content

Commit f7b8223

Browse files
committed
doc: add cuda guide for fedora
Since NVIDIA does not release CUDA for in-maintenance versions of Fedora, the process of setting up the CUDA toolkit on Fedora has become quite involved. This guide should help mere mortals install CUDA for development in a Fedora 39 toolbox environment, without affecting the host system.
1 parent 53ff6b9 commit f7b8223

File tree

1 file changed

+309
-0
lines changed

1 file changed

+309
-0
lines changed

docs/cuda-feoda.md

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
# Setting Up CUDA on Fedora
2+
3+
## Table of Contents
4+
5+
- [Prerequisites](#prerequisites)
6+
- [Monitoring NVIDIA CUDA Repositories](#monitoring-nvidia-cuda-repositories)
7+
- [Using the Fedora 39 CUDA Repository](#using-the-fedora-39-cuda-repository)
8+
- [Creating a Fedora Toolbox Environment](#creating-a-fedora-toolbox-environment)
9+
- [Installing Essential Development Tools](#installing-essential-development-tools)
10+
- [Adding the CUDA Repository](#adding-the-cuda-repository)
11+
- [Installing `nvidia-driver-libs`](#installing-nvidia-driver-libs)
12+
- [Manually Resolving Package Conflicts](#manually-resolving-package-conflicts)
13+
- [Finalizing the Installation of `nvidia-driver-libs`](#finalizing-the-installation-of-nvidia-driver-libs)
14+
- [Installing the CUDA Meta-Package](#installing-the-cuda-meta-package)
15+
- [Configuring the Environment](#configuring-the-environment)
16+
- [Verifying the Installation](#verifying-the-installation)
17+
- [Conclusion](#conclusion)
18+
- [Troubleshooting](#troubleshooting)
19+
- [Additional Notes](#additional-notes)
20+
- [References](#references)
21+
22+
## Prerequisites
23+
24+
- **Fedora Toolbox or Podman** set up on your system (this guide uses Fedora 39 in a toolbox environment).
25+
- **Internet connectivity** to download packages.
26+
27+
## Monitoring NVIDIA CUDA Repositories
28+
29+
Before proceeding, it is advisable to check if NVIDIA has updated their CUDA repositories for your Fedora version. NVIDIA's repositories can be found at:
30+
31+
- [Fedora 40 CUDA Repository](https://developer.download.nvidia.com/compute/cuda/repos/fedora40/x86_64/)
32+
- [Fedora 41 CUDA Repository](https://developer.download.nvidia.com/compute/cuda/repos/fedora41/x86_64/)
33+
34+
As of the latest update, these repositories do not contain the `cuda` meta-package or are missing essential components.
35+
36+
## Using the Fedora 39 CUDA Repository
37+
38+
Since the newer repositories are incomplete, we'll use the Fedora 39 repository:
39+
40+
- [Fedora 39 CUDA Repository](https://developer.download.nvidia.com/compute/cuda/repos/fedora39/x86_64/)
41+
42+
**Note:** Fedora 39 is no longer maintained, so we recommend using a toolbox environment to prevent system conflicts.
43+
44+
## Creating a Fedora Toolbox Environment
45+
46+
This guide focuses on Fedora hosts, but with small adjustments, it can work for other hosts. Using a Fedora 39 toolbox allows us to install the necessary packages without affecting the host system.
47+
48+
**Note:** Toolbox is available for other systems, and even without Toolbox, it is possible to use Podman or Docker.
49+
50+
We do not recommend installing on the host system, as Fedora 39 is out-of-maintenance, and instead you should upgrade to a maintained version of Fedora for your host.
51+
52+
1. **Create a Fedora 39 Toolbox:**
53+
54+
```bash
55+
toolbox create --image registry.fedoraproject.org/fedora-toolbox:39 --container fedora-toolbox-39-cuda
56+
```
57+
58+
2. **Enter the Toolbox:**
59+
60+
```bash
61+
toolbox enter --container fedora-toolbox-39-cuda
62+
```
63+
64+
Inside the toolbox, you have root privileges and can install packages without affecting the host system.
65+
66+
## Installing Essential Development Tools
67+
68+
1. **Synchronize the DNF Package Manager:**
69+
70+
```bash
71+
sudo dnf distro-sync
72+
```
73+
74+
2. **Install the Default Text Editor (Optional):**
75+
76+
```bash
77+
sudo dnf install vim-default-editor --allowerasing
78+
```
79+
80+
The `--allowerasing` flag resolves any package conflicts.
81+
82+
3. **Install Development Tools and Libraries:**
83+
84+
```bash
85+
sudo dnf install @c-development @development-tools cmake
86+
```
87+
88+
This installs essential packages for compiling software, including `gcc`, `make`, and other development headers.
89+
90+
## Adding the CUDA Repository
91+
92+
Add the NVIDIA CUDA repository to your DNF configuration:
93+
94+
```bash
95+
sudo dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/fedora39/x86_64/cuda-fedora39.repo
96+
```
97+
98+
After adding the repository, synchronize the package manager again:
99+
100+
```bash
101+
sudo dnf distro-sync
102+
```
103+
104+
## Installing `nvidia-driver-libs`
105+
106+
Attempt to install `nvidia-driver-libs`:
107+
108+
```bash
109+
sudo dnf install nvidia-driver-libs
110+
```
111+
112+
**Explanation:**
113+
114+
- `nvidia-driver-libs` contains necessary NVIDIA driver libraries required by CUDA.
115+
- This step might fail due to conflicts with existing NVIDIA drivers on the host system.
116+
117+
## Manually Resolving Package Conflicts
118+
119+
If the installation fails due to conflicts, we'll manually download and install the required packages, excluding conflicting files.
120+
121+
### 1. Download the `nvidia-driver-libs` RPM
122+
123+
```bash
124+
sudo dnf download --arch x86_64 nvidia-driver-libs
125+
```
126+
127+
You should see a file similar to:
128+
129+
```
130+
nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
131+
```
132+
133+
### 2. Attempt to Install the RPM
134+
135+
```bash
136+
sudo dnf install nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
137+
```
138+
139+
**Expected Error:**
140+
141+
Installation may fail with errors pointing to conflicts with `egl-gbm` and `egl-wayland`.
142+
143+
**Note: It is important to carefully read the error messages to identify the exact paths that need to be excluded.**
144+
145+
### 3. Download Dependencies
146+
147+
```bash
148+
sudo dnf download --arch x86_64 egl-gbm egl-wayland
149+
```
150+
151+
### 4. Install `egl-gbm` with Excluded Paths
152+
153+
Exclude conflicting files during installation:
154+
155+
```bash
156+
sudo rpm --install --verbose --hash \
157+
--excludepath=/usr/lib64/libnvidia-egl-gbm.so.1.1.2 \
158+
--excludepath=/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json \
159+
egl-gbm-1.1.2^20240919gitb24587d-3.fc39.x86_64.rpm
160+
```
161+
162+
**Explanation:**
163+
164+
- The `--excludepath` option skips installing files that conflict with existing files.
165+
- Adjust the paths based on the error messages you receive.
166+
167+
### 5. Install `egl-wayland` with Excluded Paths
168+
169+
```bash
170+
sudo rpm --install --verbose --hash \
171+
--excludepath=/usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json \
172+
egl-wayland-1.1.17^20241118giteeb29e1-5.fc39.x86_64.rpm
173+
```
174+
175+
### 6. Install `nvidia-driver-libs` with Excluded Paths
176+
177+
```bash
178+
sudo rpm --install --verbose --hash \
179+
--excludepath=/usr/share/glvnd/egl_vendor.d/10_nvidia.json \
180+
--excludepath=/usr/share/nvidia/nvoptix.bin \
181+
nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
182+
```
183+
184+
**Note:**
185+
186+
- Replace the paths with the ones causing conflicts in your installation if they differ.
187+
- The `--verbose` and `--hash` options provide detailed output during installation.
188+
189+
## Finalizing the Installation of `nvidia-driver-libs`
190+
191+
After manually installing the dependencies, run:
192+
193+
```bash
194+
sudo dnf install nvidia-driver-libs
195+
```
196+
197+
You should receive a message indicating the package is already installed:
198+
199+
```
200+
Package nvidia-driver-libs-3:560.35.05-1.fc39.x86_64 is already installed.
201+
Dependencies resolved.
202+
Nothing to do.
203+
Complete!
204+
```
205+
206+
## Installing the CUDA Meta-Package
207+
208+
Now that the driver libraries are installed, proceed to install CUDA:
209+
210+
```bash
211+
sudo dnf install cuda
212+
```
213+
214+
This installs the CUDA toolkit and associated packages.
215+
216+
## Configuring the Environment
217+
218+
To use CUDA, add its binary directory to your system's `PATH`.
219+
220+
1. **Create a Profile Script:**
221+
222+
```bash
223+
sudo sh -c 'echo "export PATH=\$PATH:/usr/local/cuda/bin" >> /etc/profile.d/cuda.sh'
224+
```
225+
226+
**Explanation:**
227+
228+
- We add to `/etc/profile.d/` as the `/etc/` folder is unique to this particular container, and is not shared with other containers or the host system.
229+
- The backslash `\` before `$PATH` ensures the variable is correctly written into the script.
230+
231+
2. **Make the Script Executable:**
232+
233+
```bash
234+
sudo chmod +x /etc/profile.d/cuda.sh
235+
```
236+
237+
3. **Source the Script to Update Your Environment:**
238+
239+
```bash
240+
source /etc/profile.d/cuda.sh
241+
```
242+
243+
**Note:** This command updates your current shell session with the new `PATH`. The `/etc/profile.d/cuda.sh` script ensures that the CUDA binaries are available in your `PATH` for all future sessions.
244+
245+
## Verifying the Installation
246+
247+
To confirm that CUDA is correctly installed and configured, check the version of the NVIDIA CUDA Compiler (`nvcc`):
248+
249+
```bash
250+
nvcc --version
251+
```
252+
253+
You should see output similar to:
254+
255+
```
256+
nvcc: NVIDIA (R) Cuda compiler driver
257+
Copyright (c) 2005-2024 NVIDIA Corporation
258+
Built on Tue_Oct_29_23:50:19_PDT_2024
259+
Cuda compilation tools, release 12.6, V12.6.85
260+
Build cuda_12.6.r12.6/compiler.35059454_0
261+
```
262+
263+
This output confirms that the CUDA compiler is accessible and indicates the installed version.
264+
265+
## Conclusion
266+
267+
You have successfully set up CUDA on Fedora within a toolbox environment using the Fedora 39 CUDA repository. By manually resolving package conflicts and configuring the environment, you can develop CUDA applications without affecting your host system.
268+
269+
## Troubleshooting
270+
271+
- **Installation Failures:**
272+
- If you encounter errors during installation, carefully read the error messages. They often indicate conflicting files or missing dependencies.
273+
- Use the `--excludepath` option with `rpm` to exclude conflicting files during manual installations.
274+
275+
- **Driver Conflicts:**
276+
- Since the host system may already have NVIDIA drivers installed, conflicts can arise. Using the toolbox environment helps isolate these issues.
277+
278+
- **Environment Variables Not Set:**
279+
- If `nvcc` is not found after installation, ensure that `/usr/local/cuda/bin` is in your `PATH`.
280+
- Run `echo $PATH` to check if the path is included.
281+
- Re-source the profile script or open a new terminal session.
282+
283+
## Additional Notes
284+
285+
- **Updating CUDA in the Future:**
286+
- Keep an eye on the official NVIDIA repositories for updates to your Fedora version.
287+
- When an updated repository becomes available, adjust your `dnf` configuration accordingly.
288+
289+
- **Building `llama.cpp`:**
290+
- With CUDA installed, you can follow these [build instructions for `llama.cpp`](https://github.com/ggerganov/llama.cpp/blob/master/docs/build.md) to compile it with CUDA support.
291+
- Ensure that any CUDA-specific build flags or paths are correctly set in your build configuration.
292+
293+
- **Using the Toolbox Environment:**
294+
- The toolbox environment is isolated from your host system, which helps prevent conflicts.
295+
- Remember that system files and configurations inside the toolbox are separate from the host. By default the home directory of the user is shared between the host and the toolbox.
296+
297+
---
298+
299+
**Disclaimer:** Manually installing and modifying system packages can lead to instability of the container. The above steps are provided as a guideline and may need adjustments based on your specific system configuration. Always back up important data before making significant system changes, especially as your home folder is writable and shared with he toolbox.
300+
301+
**Acknowledgments:** Special thanks to the Fedora community and NVIDIA documentation for providing resources that assisted in creating this guide.
302+
303+
## References
304+
305+
- [Fedora Toolbox Documentation](https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/)
306+
- [NVIDIA CUDA Installation Guide](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html)
307+
- [Podman Documentation](https://podman.io/get-started)
308+
309+
---

0 commit comments

Comments
 (0)