Skip to content

Commit 9ab42dc

Browse files
authored
docs: update fedora cuda guide for 12.8 release (ggml-org#11393)
* docs: update fedora cuda guide for 12.8 release * docs: build cuda update
1 parent 194b2e6 commit 9ab42dc

File tree

2 files changed

+105
-107
lines changed

2 files changed

+105
-107
lines changed

docs/build.md

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,66 @@ For detailed info, please refer to [llama.cpp for SYCL](./backend/SYCL.md).
125125
126126
## CUDA
127127
128-
This provides GPU acceleration using an NVIDIA GPU. Make sure to have the CUDA toolkit installed. You can download it from your Linux distro's package manager (e.g. `apt install nvidia-cuda-toolkit`) or from the [NVIDIA developer site](https://developer.nvidia.com/cuda-downloads).
128+
This provides GPU acceleration using an NVIDIA GPU. Make sure to have the [CUDA toolkit](https://developer.nvidia.com/cuda-toolkit) installed.
129129
130-
If you are using Fedora (using Fedora Workstation, or an 'Atomic' variant such as Silverblue), or would like to set up CUDA in a toolbox, please consider our [Fedora CUDA guide](./cuda-fedora.md). Unfortunately, the process is not as simple as one might expect.
130+
#### Download directly from NVIDIA
131+
You may find the official downloads here: [NVIDIA developer site](https://developer.nvidia.com/cuda-downloads).
131132
132-
- Using `CMake`:
133133
134-
```bash
135-
cmake -B build -DGGML_CUDA=ON
136-
cmake --build build --config Release
137-
```
134+
#### Compile and run inside a Fedora Toolbox Container
135+
We also have a [guide](./cuda-fedora.md) for setting up CUDA toolkit in a Fedora [toolbox container](https://containertoolbx.org/).
136+
137+
**Recommended for:**
138+
139+
- ***Particularly*** *convenient* for users of [Atomic Desktops for Fedora](https://fedoraproject.org/atomic-desktops/); such as: [Silverblue](https://fedoraproject.org/atomic-desktops/silverblue/) and [Kinoite](https://fedoraproject.org/atomic-desktops/kinoite/).
140+
- Toolbox is installed by default: [Fedora Workstation](https://fedoraproject.org/workstation/) or [Fedora KDE Plasma Desktop](https://fedoraproject.org/spins/kde).
141+
- *Optionally* toolbox packages are available: [Arch Linux](https://archlinux.org/), [Red Hat Enterprise Linux >= 8.5](https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux), or [Ubuntu](https://ubuntu.com/download)
142+
143+
144+
### Compilation
145+
```bash
146+
cmake -B build -DGGML_CUDA=ON
147+
cmake --build build --config Release
148+
```
149+
150+
### Override Compute Capability Specifications
151+
152+
If `nvcc` cannot detect your gpu, you may get compile-warnings such as:
153+
```text
154+
nvcc warning : Cannot find valid GPU for '-arch=native', default arch is used
155+
```
138156

139-
The environment variable [`CUDA_VISIBLE_DEVICES`](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars) can be used to specify which GPU(s) will be used.
157+
To override the `native` GPU detection:
158+
159+
#### 1. Take note of the `Compute Capability` of your NVIDIA devices: ["CUDA: Your GPU Compute > Capability"](https://developer.nvidia.com/cuda-gpus).
160+
161+
```text
162+
GeForce RTX 4090 8.9
163+
GeForce RTX 3080 Ti 8.6
164+
GeForce RTX 3070 8.6
165+
```
166+
167+
#### 2. Manually list each varying `Compute Capability` in the `CMAKE_CUDA_ARCHITECTURES` list.
168+
169+
```bash
170+
cmake -B build -DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES="86;89"
171+
```
172+
173+
### Runtime CUDA environmental variables
174+
175+
You may set the [cuda environmental variables](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars) at runtime.
176+
177+
```bash
178+
# Use `CUDA_VISIBLE_DEVICES` to hide the first compute device.
179+
CUDA_VISIBLE_DEVICES="-0" ./build/bin/llama-server --model /srv/models/llama.gguf
180+
```
181+
182+
### Unified Memory
140183

141184
The environment variable `GGML_CUDA_ENABLE_UNIFIED_MEMORY=1` can be used to enable unified memory in Linux. This allows swapping to system RAM instead of crashing when the GPU VRAM is exhausted. In Windows this setting is available in the NVIDIA control panel as `System Memory Fallback`.
142185

186+
### Performance Tuning
187+
143188
The following compilation options are also available to tweak performance:
144189

145190
| Option | Legal values | Default | Description |

docs/cuda-fedora.md

Lines changed: 52 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# Setting Up CUDA on Fedora
22

33
In this guide we setup [Nvidia CUDA](https://docs.nvidia.com/cuda/) in a toolbox container. This guide is applicable for:
4+
45
- [Fedora Workstation](https://fedoraproject.org/workstation/)
56
- [Atomic Desktops for Fedora](https://fedoraproject.org/atomic-desktops/)
67
- [Fedora Spins](https://fedoraproject.org/spins)
7-
- [Other Distributions](https://containertoolbx.org/distros/), including `Red Hat Enterprise Linux >= 8.`, `Arch Linux`, and `Ubuntu`.
8-
8+
- [Other Distributions](https://containertoolbx.org/distros/), including `Red Hat Enterprise Linux >= 8.5`, `Arch Linux`, and `Ubuntu`.
99

1010
## Table of Contents
1111

1212
- [Prerequisites](#prerequisites)
13-
- [Monitoring NVIDIA CUDA Repositories](#monitoring-nvidia-cuda-repositories)
14-
- [Using the Fedora 39 CUDA Repository](#using-the-fedora-39-cuda-repository)
13+
- [Using the Fedora 41 CUDA Repository](#using-the-fedora-41-cuda-repository)
1514
- [Creating a Fedora Toolbox Environment](#creating-a-fedora-toolbox-environment)
1615
- [Installing Essential Development Tools](#installing-essential-development-tools)
1716
- [Adding the CUDA Repository](#adding-the-cuda-repository)
@@ -29,44 +28,33 @@ In this guide we setup [Nvidia CUDA](https://docs.nvidia.com/cuda/) in a toolbox
2928
## Prerequisites
3029

3130
- **Toolbox Installed on the Host System** `Fedora Silverblue` and `Fedora Workstation` both have toolbox by default, other distributions may need to install the [toolbox package](https://containertoolbx.org/install/).
32-
- **NVIDIA Drivers and Graphics Card installed on Host System (optional)** To run CUDA program, such as `llama.cpp`, the host should be setup to access your NVIDIA hardware. Fedora Hosts can use the [RPM Fusion Repository](https://rpmfusion.org/Howto/NVIDIA).
31+
- **NVIDIA Drivers and Graphics Card installed on Host System (recommended)** To run CUDA program, such as `llama.cpp`, the host should be setup to access your NVIDIA hardware. Fedora Hosts can use the [RPM Fusion Repository](https://rpmfusion.org/Howto/NVIDIA).
3332
- **Internet connectivity** to download packages.
3433

35-
### Monitoring NVIDIA CUDA Repositories
34+
### Using the Fedora 41 CUDA Repository
3635

37-
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:
36+
The latest release is 41.
3837

39-
- [Fedora 40 CUDA Repository](https://developer.download.nvidia.com/compute/cuda/repos/fedora40/x86_64/)
4038
- [Fedora 41 CUDA Repository](https://developer.download.nvidia.com/compute/cuda/repos/fedora41/x86_64/)
4139

42-
As of the latest update, these repositories do not contain the `cuda` meta-package or are missing essential components.
43-
44-
### Using the Fedora 39 CUDA Repository
45-
46-
Since the newer repositories are incomplete, we'll use the Fedora 39 repository:
47-
48-
- [Fedora 39 CUDA Repository](https://developer.download.nvidia.com/compute/cuda/repos/fedora39/x86_64/)
49-
50-
**Note:** Fedora 39 is no longer maintained, so we recommend using a toolbox environment to prevent system conflicts.
40+
**Note:** We recommend using a toolbox environment to prevent system conflicts.
5141

5242
## Creating a Fedora Toolbox Environment
5343

54-
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.
44+
This guide focuses on Fedora hosts, but with small adjustments, it can work for other hosts. Using the Fedora Toolbox allows us to install the necessary packages without affecting the host system.
5545

5646
**Note:** Toolbox is available for other systems, and even without Toolbox, it is possible to use Podman or Docker.
5747

58-
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.
59-
60-
1. **Create a Fedora 39 Toolbox:**
48+
1. **Create a Fedora 41 Toolbox:**
6149

6250
```bash
63-
toolbox create --image registry.fedoraproject.org/fedora-toolbox:39 --container fedora-toolbox-39-cuda
51+
toolbox create --image registry.fedoraproject.org/fedora-toolbox:41 --container fedora-toolbox-41-cuda
6452
```
6553

6654
2. **Enter the Toolbox:**
6755

6856
```bash
69-
toolbox enter --container fedora-toolbox-39-cuda
57+
toolbox enter --container fedora-toolbox-41-cuda
7058
```
7159

7260
Inside the toolbox, you have root privileges and can install packages without affecting the host system.
@@ -85,7 +73,7 @@ We do not recommend installing on the host system, as Fedora 39 is out-of-mainte
8573
sudo dnf install vim-default-editor --allowerasing
8674
```
8775

88-
The `--allowerasing` flag resolves any package conflicts.
76+
The `--allowerasing` flag will allow the removal of the conflicting `nano-default-editor` package.
8977

9078
3. **Install Development Tools and Libraries:**
9179

@@ -100,7 +88,7 @@ We do not recommend installing on the host system, as Fedora 39 is out-of-mainte
10088
Add the NVIDIA CUDA repository to your DNF configuration:
10189

10290
```bash
103-
sudo dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/fedora39/x86_64/cuda-fedora39.repo
91+
sudo dnf config-manager addrepo --from-repofile=https://developer.download.nvidia.com/compute/cuda/repos/fedora41/x86_64/cuda-fedora41.repo
10492
```
10593

10694
After adding the repository, synchronize the package manager again:
@@ -109,106 +97,62 @@ After adding the repository, synchronize the package manager again:
10997
sudo dnf distro-sync
11098
```
11199

112-
## Installing `nvidia-driver-libs`
100+
## Installing `nvidia-driver-libs` and `nvidia-driver-cuda-libs`
113101

114-
Attempt to install `nvidia-driver-libs`:
102+
We need to detect if the host is supplying the [NVIDIA driver libraries into the toolbox](https://github.com/containers/toolbox/blob/main/src/pkg/nvidia/nvidia.go).
115103

116104
```bash
117-
sudo dnf install nvidia-driver-libs
105+
ls -la /usr/lib64/libcuda.so.1
118106
```
119107

120108
**Explanation:**
121109

122-
- `nvidia-driver-libs` contains necessary NVIDIA driver libraries required by CUDA.
123-
- This step might fail due to conflicts with existing NVIDIA drivers on the host system.
124-
125-
## Manually Resolving Package Conflicts
126-
127-
If the installation fails due to conflicts, we'll manually download and install the required packages, excluding conflicting files.
128-
129-
### 1. Download the `nvidia-driver-libs` RPM
130-
131-
```bash
132-
sudo dnf download --arch x86_64 nvidia-driver-libs
133-
```
134-
135-
You should see a file similar to:
136-
137-
```
138-
nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
139-
```
140-
141-
### 2. Attempt to Install the RPM
110+
- `nvidia-driver-libs` and `nvidia-driver-cuda-libs` contains necessary NVIDIA driver libraries required by CUDA,
111+
on hosts with NVIDIA drivers installed the Fedora Container will supply the host libraries.
142112

143-
```bash
144-
sudo dnf install nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
145-
```
146-
147-
**Expected Error:**
148-
149-
Installation may fail with errors pointing to conflicts with `egl-gbm` and `egl-wayland`.
150-
151-
**Note: It is important to carefully read the error messages to identify the exact paths that need to be excluded.**
152-
153-
### 3. Download Dependencies
113+
### Install Nvidia Driver Libraries on Guest (if `libcuda.so.1` was NOT found).
154114

155115
```bash
156-
sudo dnf download --arch x86_64 egl-gbm egl-wayland
116+
sudo dnf install nvidia-driver-libs nvidia-driver-cuda-libs
157117
```
158118

159-
### 4. Install `egl-gbm` with Excluded Paths
160-
161-
Exclude conflicting files during installation:
162-
163-
```bash
164-
sudo rpm --install --verbose --hash \
165-
--excludepath=/usr/lib64/libnvidia-egl-gbm.so.1.1.2 \
166-
--excludepath=/usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json \
167-
egl-gbm-1.1.2^20240919gitb24587d-3.fc39.x86_64.rpm
168-
```
119+
### Manually Updating the RPM database for host-supplied NVIDIA drivers (if `libcuda.so.1` was found).
169120

170-
**Explanation:**
171-
172-
- The `--excludepath` option skips installing files that conflict with existing files.
173-
- Adjust the paths based on the error messages you receive.
121+
If the installation fails due to conflicts, we'll manually download and install the required packages, excluding conflicting files.
174122

175-
### 5. Install `egl-wayland` with Excluded Paths
123+
#### 1. Download `nvidia-driver-libs` and `nvidia-driver-cuda-libs` RPM's (with dependencies)
176124

177125
```bash
178-
sudo rpm --install --verbose --hash \
179-
--excludepath=/usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json \
180-
egl-wayland-1.1.17^20241118giteeb29e1-5.fc39.x86_64.rpm
126+
sudo dnf download --destdir=/tmp/nvidia-driver-libs --resolve --arch x86_64 nvidia-driver-libs nvidia-driver-cuda-libs
181127
```
182128

183-
### 6. Install `nvidia-driver-libs` with Excluded Paths
129+
#### 2. Update the RPM database to assume the installation of these packages.
184130

185131
```bash
186-
sudo rpm --install --verbose --hash \
187-
--excludepath=/usr/share/glvnd/egl_vendor.d/10_nvidia.json \
188-
--excludepath=/usr/share/nvidia/nvoptix.bin \
189-
nvidia-driver-libs-560.35.05-1.fc39.x86_64.rpm
132+
sudo rpm --install --verbose --hash --justdb /tmp/nvidia-driver-libs/*
190133
```
191134

192135
**Note:**
193136

194-
- Replace the paths with the ones causing conflicts in your installation if they differ.
195-
- The `--verbose` and `--hash` options provide detailed output during installation.
137+
- The `--justdb` option only updates the RPM database, without touching the filesystem.
196138

197-
## Finalizing the Installation of `nvidia-driver-libs`
139+
#### Finalizing the Installation of `nvidia-driver-libs` and `nvidia-driver-cuda-libs`
198140

199141
After manually installing the dependencies, run:
200142

201143
```bash
202-
sudo dnf install nvidia-driver-libs
144+
sudo dnf install nvidia-driver-libs nvidia-driver-cuda-libs
203145
```
204146

205147
You should receive a message indicating the package is already installed:
206148

207149
```
208-
Package nvidia-driver-libs-3:560.35.05-1.fc39.x86_64 is already installed.
209-
Dependencies resolved.
150+
Updating and loading repositories:
151+
Repositories loaded.
152+
Package "nvidia-driver-libs-3:570.86.10-1.fc41.x86_64" is already installed.
153+
Package "nvidia-driver-cuda-libs-3:570.86.10-1.fc41.x86_64" is already installed.
154+
210155
Nothing to do.
211-
Complete!
212156
```
213157

214158
## Installing the CUDA Meta-Package
@@ -233,7 +177,7 @@ To use CUDA, add its binary directory to your system's `PATH`.
233177

234178
**Explanation:**
235179

236-
- 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.
180+
- 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.
237181
- The backslash `\` before `$PATH` ensures the variable is correctly written into the script.
238182

239183
2. **Make the Script Executable:**
@@ -262,26 +206,33 @@ You should see output similar to:
262206

263207
```
264208
nvcc: NVIDIA (R) Cuda compiler driver
265-
Copyright (c) 2005-2024 NVIDIA Corporation
266-
Built on Tue_Oct_29_23:50:19_PDT_2024
267-
Cuda compilation tools, release 12.6, V12.6.85
268-
Build cuda_12.6.r12.6/compiler.35059454_0
209+
Copyright (c) 2005-2025 NVIDIA Corporation
210+
Built on Wed_Jan_15_19:20:09_PST_2025
211+
Cuda compilation tools, release 12.8, V12.8.61
212+
Build cuda_12.8.r12.8/compiler.35404655_0
269213
```
270214

271215
This output confirms that the CUDA compiler is accessible and indicates the installed version.
272216

273217
## Conclusion
274218

275-
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.
219+
You have successfully set up CUDA on Fedora within a toolbox environment using the Fedora 41 CUDA repository. By manually updating the RPM db and configuring the environment, you can develop CUDA applications without affecting your host system.
276220

277221
## Troubleshooting
278222

279223
- **Installation Failures:**
224+
280225
- If you encounter errors during installation, carefully read the error messages. They often indicate conflicting files or missing dependencies.
281-
- Use the `--excludepath` option with `rpm` to exclude conflicting files during manual installations.
226+
- You may use the `--excludepath` option with `rpm` to exclude conflicting files during manual RPM installations.
282227

283-
- **Driver Conflicts:**
284-
- Since the host system may already have NVIDIA drivers installed, conflicts can arise. Using the toolbox environment helps isolate these issues.
228+
- **Rebooting the Container:**
229+
230+
- Sometimes there may be a bug in the NVIDIA driver host passthrough (such as missing a shared library). Rebooting the container may solve this issue:
231+
232+
```bash
233+
# on the host system
234+
podman container restart --all
235+
```
285236

286237
- **Environment Variables Not Set:**
287238
- If `nvcc` is not found after installation, ensure that `/usr/local/cuda/bin` is in your `PATH`.
@@ -291,10 +242,12 @@ You have successfully set up CUDA on Fedora within a toolbox environment using t
291242
## Additional Notes
292243

293244
- **Updating CUDA in the Future:**
245+
294246
- Keep an eye on the official NVIDIA repositories for updates to your Fedora version.
295247
- When an updated repository becomes available, adjust your `dnf` configuration accordingly.
296248

297249
- **Building `llama.cpp`:**
250+
298251
- 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.
299252
- Ensure that any CUDA-specific build flags or paths are correctly set in your build configuration.
300253

0 commit comments

Comments
 (0)