CUDA: Difference between revisions
imported>Cafkafk updated utillinux -> util-linux |
imported>Zylanx Fix the shells to be buildable and fix the formatting of the files wrt. angle brackets. Is there a better fix for that? |
||
Line 20: | Line 20: | ||
{{file|cuda-fhs.nix|nix|<nowiki> | {{file|cuda-fhs.nix|nix|<nowiki> | ||
{ pkgs ? import <nixpkgs> {} }: | # Run with `nix-shell cuda-fhs.nix` | ||
{ pkgs ? import </nowiki><nixpkgs><nowiki> {} }: | |||
(pkgs.buildFHSUserEnv { | |||
name = "cuda-env"; | |||
targetPkgs = pkgs: with pkgs; [ | |||
git | |||
gitRepo | |||
gnupg | |||
autoconf | |||
curl | |||
procps | |||
gnumake | |||
util-linux | |||
m4 | |||
gperf | |||
unzip | |||
cudatoolkit | |||
linuxPackages.nvidia_x11 | |||
libGLU libGL | |||
xorg.libXi xorg.libXmu freeglut | |||
xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib | |||
ncurses5 | |||
stdenv.cc | |||
binutils | |||
]; | |||
multiPkgs = pkgs: with pkgs; [ zlib ]; | |||
runScript = "bash"; | |||
profile = '' | |||
export CUDA_PATH=${pkgs.cudatoolkit} | |||
# export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib | |||
export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib" | |||
export EXTRA_CCFLAGS="-I/usr/include" | |||
''; | |||
}).env | |||
</nowiki>}} | </nowiki>}} | ||
Line 65: | Line 59: | ||
* By making a nix-shell | * By making a nix-shell | ||
{{file|cuda-shell.nix|nix|<nowiki> | {{file|cuda-shell.nix|nix|<nowiki> | ||
{ pkgs ? import <nixpkgs> {} }: | # Run with `nix-shell cuda-shell.nix` | ||
{ pkgs ? import </nowiki><nixpkgs><nowiki> {} }: | |||
pkgs. | pkgs.mkShell { | ||
name = "cuda-env-shell"; | name = "cuda-env-shell"; | ||
buildInputs = with pkgs; [ | buildInputs = with pkgs; [ |
Revision as of 11:39, 30 October 2022
NixOS supports using NVIDIA GPUs for pure computing purposes, not just for graphics. For example, many users rely on NixOS for machine learning both locally and on cloud instances. These use cases are supported by the @NixOS/cuda-maintainers team on GitHub. If you have an issue using your NVIDIA GPU for computing purposes open an issue on GitHub and tag @NixOS/cuda-maintainers.
Cache: Using the cuda-maintainers cache is recommended! It will save you valuable time and electrons. Getting set up should be as simple as cachix use cuda-maintainers
.
Data center GPUs: Note that you may need to adjust your driver version to use "data center" GPUs like V100/A100s. See this thread for more info.
The CUDA toolkit is available in a number of different versions. Please use the latest major version. You can see where they're defined in nixpkgs here.
Several "CUDA-X" libraries are packages as well. In particular,
Note that these examples haven't been updated in a while (as of 2022-03-12). May not be the best solution. A better resource is likely the packaging CUDA sample code here.
There are some possible ways to setup a development environment using CUDA on NixOS. This can be accomplished in the following ways:
- By making a FHS user env
cuda-fhs.nix
# Run with `nix-shell cuda-fhs.nix`
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "cuda-env";
targetPkgs = pkgs: with pkgs; [
git
gitRepo
gnupg
autoconf
curl
procps
gnumake
util-linux
m4
gperf
unzip
cudatoolkit
linuxPackages.nvidia_x11
libGLU libGL
xorg.libXi xorg.libXmu freeglut
xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
ncurses5
stdenv.cc
binutils
];
multiPkgs = pkgs: with pkgs; [ zlib ];
runScript = "bash";
profile = ''
export CUDA_PATH=${pkgs.cudatoolkit}
# export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib
export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
export EXTRA_CCFLAGS="-I/usr/include"
'';
}).env
- By making a nix-shell
cuda-shell.nix
# Run with `nix-shell cuda-shell.nix`
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "cuda-env-shell";
buildInputs = with pkgs; [
git gitRepo gnupg autoconf curl
procps gnumake util-linux m4 gperf unzip
cudatoolkit linuxPackages.nvidia_x11
libGLU libGL
xorg.libXi xorg.libXmu freeglut
xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
ncurses5 stdenv.cc binutils
];
shellHook = ''
export CUDA_PATH=${pkgs.cudatoolkit}
# export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib:${pkgs.ncurses5}/lib
export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
export EXTRA_CCFLAGS="-I/usr/include"
'';
}
Some things to keep in mind when setting up CUDA in NixOS
- Some GPUs, like Tesla K80, don't work with the latest drivers, so you must specify them in the option
hardware.nvidia.package
getting the value from your selected kernel, for example,config.boot.kernelPackages.nvidia_x11_legacy470
. You can check which driver version your GPU supports by visiting the nvidia site and checking the driver version. - Even with the drivers correctly installed, some software, like Blender, may not see the CUDA GPU. Make sure your system configuration has the option
hardware.opengl.enable
enabled. - By default, software packaged in source code form has CUDA support disabled, because of the unfree license. To solve this, you can enable builds with CUDA support with a nixpkgs wide configuration, or use binary packaged CUDA compatible software such as blender-bin.