CUDA: Difference between revisions

Perchun (talk | contribs)
Replace nix-community binary cache with cache.nixos-cuda.org
Smudgebun (talk | contribs)
Enabling CUDA In Packages: Improved tips on installing large CUDA packages without a cache
 
(11 intermediate revisions by 2 users not shown)
Line 4: Line 4:


{{tip|1='''Data center GPUs''': Note that you may need to adjust your driver version to use "data center" GPUs like V100/A100s. See [https://discourse.nixos.org/t/how-to-use-nvidia-v100-a100-gpus/17754 this thread] for more info.}}
{{tip|1='''Data center GPUs''': Note that you may need to adjust your driver version to use "data center" GPUs like V100/A100s. See [https://discourse.nixos.org/t/how-to-use-nvidia-v100-a100-gpus/17754 this thread] for more info.}}
== Driver Installation ==
Assuming you've followed the [[NVIDIA]] page correctly, and have a CUDA compatible GPU, you shouldn't need to do any further configuration. You can confirm your CUDA version by running the following command in your terminal.
{{code|lang=console|line=no|<nowiki>nvidia-smi | grep CUDA</nowiki>}}


== <code>cudatoolkit</code>, <code>cudnn</code>, and related packages ==
== <code>cudatoolkit</code>, <code>cudnn</code>, and related packages ==
Line 62: Line 68:
<syntaxhighlight lang="nix" line="1" start="1">
<syntaxhighlight lang="nix" line="1" start="1">
# flake.nix, run with `nix develop`# Run with `nix-shell cuda-shell.nix`
# flake.nix, run with `nix develop`# Run with `nix-shell cuda-shell.nix`
{ pkgs ? import </nowiki><nixpkgs><nowiki> {} }:
{ pkgs ? import <nixpkgs> {} }:
let
let
   nvidiaPackage = pkgs.linuxPackages.nvidiaPackages.stable;
   nvidiaPackage = pkgs.linuxPackages.nvidiaPackages.stable;
Line 148: Line 154:
For more information, refer to the [[Binary Cache#Using a binary cache Using a binary cache|Using a binary cache]] page.
For more information, refer to the [[Binary Cache#Using a binary cache Using a binary cache|Using a binary cache]] page.


{{warning|1=You need to rebuild your system at least once after adding the cache, before it can be used.}}
{{info|1=You need to rebuild your system at least once after adding the cache, before it can be used.}}


=== NixOS ===
=== NixOS ===
Line 180: Line 186:
trusted-substituters = https://cache.nixos-cuda.org
trusted-substituters = https://cache.nixos-cuda.org
</nowiki>|name=~/.config/nix/nix.conf|lang=nix}}
</nowiki>|name=~/.config/nix/nix.conf|lang=nix}}
== Enabling CUDA In Packages ==
By default, software packaged in source code form has CUDA support disabled, because of the unfree license. There are multiple options to solve this.
You can enable builds with CUDA support with a nixpkgs wide configuration.
<syntaxhighlight lang="nix">
nixpkgs.config.cudaSupport = true;
</syntaxhighlight>
Or you can override individual packages.
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
(mlt.override {config.cudaSupport=true;})
];
</syntaxhighlight>
Or you can use binary-packaged versions of CUDA compatible software, such as [https://github.com/edolstra/nix-warez/tree/master/blender blender-bin] for Blender.
{{info|If you will be using <code>cudaSupport</code> in packages, it is recommended you utilize a [[#Setting up CUDA Binary Cache|CUDA binary cache]].}}
Without a [[#Setting up CUDA Binary Cache|CUDA cache]], any CUDA compatible package installed with <code>cudaSupport</code> will be compiled from source. This is because NixOS Foundation does not build (and therefore [https://cache.nixos.org/ cache.nixos.org] does not cache) CUDA packages.
For larger programs like Blender, that process can be very resource-intensive. If you are installing large CUDA-enabled package(s) that either are not cached or you are not using a cache, then (especially on older or weaker hardware) it is recommended to reduce the number of cores and/or jobs that the process will take, to prevent a system freeze from resource limits. This can be done with the <code>--max-jobs</code> / <code>-j</code> and <code>--cores</code> flags, for more details see the [https://github.com/NixOS/nix/blob/master/doc/manual/source/advanced-topics/cores-vs-jobs.md Tuning Cores & Jobs] manual page.
If you don't want to deal with the increased time that compilation will take when <code>--max-jobs</code> / <code>-j</code> and <code>--cores</code> are set below maximum, you can also try simply closing other running processes to see if that frees up enough resources for compilation to be successful.
&rarr; For specifics on setting up Blender with CUDA (and OptiX) see: [[Blender#CUDA & OptiX]].


== Some things to keep in mind when setting up CUDA in NixOS ==
== 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 <code>hardware.nvidia.package</code> getting the value from your selected kernel, for example, <code>config.boot.kernelPackages.nvidia_x11_legacy470</code>. You can check which driver version your GPU supports by visiting the  [https://www.nvidia.com/Download/index.aspx nvidia site] and checking the driver version.
* Some GPUs, like Tesla K80, don't work with the latest drivers, so you must specify them in the option <code>hardware.nvidia.package</code> getting the value from your selected kernel, for example, <code>config.boot.kernelPackages.nvidia_x11_legacy470</code>. You can check which driver version your GPU supports by visiting the  [https://www.nvidia.com/Download/index.aspx 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 <code>hardware.opengl.enable</code> enabled.
* Even with the drivers correctly installed, some software, like Blender, may not see the CUDA GPU. Make sure your system configuration has the option <code>hardware.graphics.enable</code> 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 [https://github.com/edolstra/nix-warez/tree/master/blender blender-bin].


== CUDA under WSL ==
== CUDA under WSL ==