CUDA: Difference between revisions

Smudgebun (talk | contribs)
Some things to keep in mind when setting up CUDA in NixOS: Added in-line code examples and a link to the Blender page's CUDA section.
Smudgebun (talk | contribs)
Expanded a new `Enabling CUDA In Packages` section because the information was left as effectively a footnote previously.
Line 180: Line 180:
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.
Without the [[#Setting up CUDA Binary Cache|CUDA Binary Cache]], any CUDA-compatible package installed with the <code>cudaSupport</code> flag enabled 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) packages with CUDA support enabled due to the license. For larger programs like Blender this can be very resource-intensive. If you know you are building a large package and do not have the cache configured, it is recommended to limit the number of cores or jobs that the process will take, to prevent a crash. This can be done with the <code>--max-jobs</code> / <code>-j</code> and <code>--cores</code> flags, for more details see: [https://github.com/NixOS/nix/blob/master/doc/manual/source/advanced-topics/cores-vs-jobs.md Tuning Cores & Jobs].
This is also why it is recommended, if without the cache, to enable <code>cudaSupport</code> only for the programs you need it for, to avoid pointlessly compiling packages from source.
For specifics on setting up Blender with CUDA 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.graphics.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 <code>nixpkgs.config.cudaSupport = true;</code>, individual overrides e.g. <code>environment.systemPackages = with pkgs; [ (blender.override {config.cudaSupport=true;}) ];</code>, or use binary packaged CUDA compatible software such as [https://github.com/edolstra/nix-warez/tree/master/blender blender-bin].
* For setting up Blender with CUDA see: [[Blender#CUDA & OptiX]].


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