Skip to content

Commit dfb4d86

Browse files
committed
Add NVIDIA acceleration how-to documentation
1 parent adb6bc4 commit dfb4d86

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# How to use NVIDIA GPU in Docker
2+
3+
WSL supports NVIDIA-based GPU acceleration, making it ideal for many use cases
4+
including machine learning or general compute acceleration. Since Docker version
5+
25, the use of `virtualisation.docker.enableNvidia` has been deprecated in
6+
favour of a more standard specification called Container Device Interface.
7+
8+
1. Enable the NVIDIA Container Toolkit and disable the mounting of executables,
9+
as this will cause an problem related to missing libraries.
10+
11+
```nix
12+
hardware.nvidia-container-toolkit = {
13+
enable = true;
14+
mount-nvidia-executables = false;
15+
};
16+
```
17+
18+
2. As of Docker 25, the Docker daemon doesn't have the CDI feature enabled by
19+
default.
20+
21+
```nix
22+
virtualisation.docker = {
23+
enable = true;
24+
daemon.settings.features.cdi = true;
25+
};
26+
```
27+
28+
3. Test the installation by running the following command.
29+
30+
```shell
31+
docker run --rm --device nvidia.com/gpu=all ubuntu nvidia-smi
32+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# How to use NVIDIA acceleration with nix-ld
2+
3+
By default, the NixOS WSL configuration provides a symlink farm from
4+
/usr/lib/wsl/lib to the OpenGL packages. However, if you want to use the GPU
5+
with a non-NixOS compiled program via nix-ld (e.g. nvidia-smi), you also need to
6+
add the symlinks to the to the nix-ld libraries.
7+
8+
```nix
9+
let
10+
wsl-lib = pkgs.runCommand "wsl-lib" { } ''
11+
mkdir -p "$out/lib"
12+
# # We can't just symlink the lib directory, because it will break merging with other drivers that provide the same directory
13+
ln -s /usr/lib/wsl/lib/libcudadebugger.so.1 "$out/lib"
14+
ln -s /usr/lib/wsl/lib/libcuda.so "$out/lib
15+
ln -s /usr/lib/wsl/lib/libcuda.so.1 "$out/lib
16+
ln -s /usr/lib/wsl/lib/libcuda.so.1.1 "$out/lib
17+
ln -s /usr/lib/wsl/lib/libd3d12core.so "$out/lib
18+
ln -s /usr/lib/wsl/lib/libd3d12.so "$out/lib
19+
ln -s /usr/lib/wsl/lib/libdxcore.so "$out/lib
20+
ln -s /usr/lib/wsl/lib/libnvcuvid.so "$out/lib
21+
ln -s /usr/lib/wsl/lib/libnvcuvid.so.1 "$out/lib
22+
ln -s /usr/lib/wsl/lib/libnvdxdlkernels.so "$out/lib
23+
ln -s /usr/lib/wsl/lib/libnvidia-encode.so "$out/lib
24+
ln -s /usr/lib/wsl/lib/libnvidia-encode.so.1 "$out/lib
25+
ln -s /usr/lib/wsl/lib/libnvidia-ml.so.1 "$out/lib
26+
ln -s /usr/lib/wsl/lib/libnvidia-opticalflow.so "$out/lib
27+
ln -s /usr/lib/wsl/lib/libnvidia-opticalflow.so.1 "$out/lib
28+
ln -s /usr/lib/wsl/lib/libnvoptix.so.1 "$out/lib
29+
ln -s /usr/lib/wsl/lib/libnvwgf2umx.so "$out/lib
30+
ln -s /usr/lib/wsl/lib/nvidia-smi "$out/lib
31+
'';
32+
in
33+
{
34+
programs.nix-ld = {
35+
enable = true;
36+
libraries = [ wsl-lib ];
37+
};
38+
}
39+
```
40+
41+
Test the installation by running the following command:
42+
43+
```shell
44+
nvidia-smi
45+
```

0 commit comments

Comments
 (0)