CUDA: Difference between revisions
Expanded a new `Enabling CUDA In Packages` section because the information was left as effectively a footnote previously. |
m style fixes, consistency |
||
| (8 intermediate revisions by one other user 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. | |||
<syntaxhighlight lang=console> | |||
$ nvidia-smi | grep CUDA | |||
</syntaxhighlight> | |||
== <code>cudatoolkit</code>, <code>cudnn</code>, and related packages == | == <code>cudatoolkit</code>, <code>cudnn</code>, and related packages == | ||
| Line 17: | Line 25: | ||
* By making a FHS user env | * By making a FHS user env | ||
<syntaxhighlight lang="nix | <syntaxhighlight lang="nix"> | ||
# flake.nix, run with `nix develop` | |||
# Run with `nix-shell cuda-fhs.nix` | # Run with `nix-shell cuda-fhs.nix` | ||
{ pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
| Line 60: | Line 69: | ||
* By making a nix-shell | * By making a nix-shell | ||
<syntaxhighlight lang="nix | <syntaxhighlight lang="nix"> | ||
# 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 <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
let | let | ||
| Line 87: | Line 97: | ||
* By making a flake.nix | * By making a flake.nix | ||
<syntaxhighlight lang="nix | <syntaxhighlight lang="nix"># flake.nix, run with `nix develop` | ||
{ | { | ||
description = "CUDA development environment"; | description = "CUDA development environment"; | ||
| Line 148: | Line 158: | ||
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. | ||
{{ | {{info|1=You need to rebuild your system at least once after adding the cache, before it can be used.}} | ||
=== NixOS === | === NixOS === | ||
| Line 192: | Line 202: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
environment.systemPackages = with pkgs; [ | environment.systemPackages = with pkgs; [ | ||
(mlt.override {config.cudaSupport=true;}) | |||
]; | ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 198: | Line 208: | ||
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. | 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. | |||
For specifics on setting up Blender with CUDA see: [[Blender#CUDA & OptiX]]. | 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. | ||
→ 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 == | ||
| Line 213: | Line 227: | ||
{{file|cuda-shell.nix|nix|<nowiki> | {{file|cuda-shell.nix|nix|<nowiki> | ||
shellHook = '' | |||
export CUDA_PATH=${pkgs.cudatoolkit} | |||
export LD_LIBRARY_PATH=/usr/lib/wsl/lib:${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" | |||
''; | |||
</nowiki>}} | </nowiki>}} | ||