CUDA: Difference between revisions

Vodros (talk | contribs)
m Fix nixpkgs cudatoolkit link
Eljamm (talk | contribs)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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 [https://github.com/orgs/NixOS/projects/27 @NixOS/cuda-maintainers team] on GitHub. If you have an issue using your NVIDIA GPU for computing purposes [https://github.com/nixos/nixpkgs/issues/new open an issue] on GitHub and tag @NixOS/cuda-maintainers.
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 [https://github.com/orgs/NixOS/projects/27 @NixOS/cuda-maintainers team] on GitHub. If you have an issue using your NVIDIA GPU for computing purposes [https://github.com/nixos/nixpkgs/issues/new open an issue] on GitHub and tag @NixOS/cuda-maintainers.


'''Cache''': Using the [https://app.cachix.org/cache/cuda-maintainers#pull cuda-maintainers cache] is recommended! It will save you valuable time and electrons. Getting set up should be as simple as <code>cachix use cuda-maintainers</code>.
{{tip|1='''Cache''': Using the [https://app.cachix.org/cache/cuda-maintainers#pull cuda-maintainers cache] is recommended! It will save you valuable time and electrons. Getting set up should be as simple as <code>cachix use cuda-maintainers</code>. Click [[#Setting up CUDA Binary Cache|here]] for more details.}}


'''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.}}


== <code>cudatoolkit</code>, <code>cudnn</code>, and related packages ==
== <code>cudatoolkit</code>, <code>cudnn</code>, and related packages ==
Line 13: Line 13:
* cuTENSOR is packaged [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/cutensor/generic.nix here].
* cuTENSOR is packaged [https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/cutensor/generic.nix here].


'''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 [https://github.com/NixOS/nixpkgs/blob/master/pkgs/test/cuda/cuda-library-samples/generic.nix here].'''
{{warning|1=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 [https://github.com/NixOS/nixpkgs/blob/master/pkgs/test/cuda/cuda-library-samples/generic.nix here].}}


There are some possible ways to setup a development environment using CUDA on NixOS. This can be accomplished in the following ways:
There are some possible ways to setup a development environment using CUDA on NixOS. This can be accomplished in the following ways:
Line 79: Line 79:
   '';           
   '';           
}
}
</nowiki>}}
== Setting up CUDA Binary Cache ==
The [https://app.cachix.org/cache/cuda-maintainers cuda-maintainers] cache contains pre-built CUDA packages. By adding it to your system, Nix will fetch these packages instead of building them, saving valuable time and processing power.
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.}}
=== NixOS ===
Add the cache to <code>substituters</code> and <code>trusted-public-keys</code> inside your system configuration:
{{file|/etc/nixos/configuration.nix|nix|<nowiki>
nix.settings = {
  substituters = [
    "https://cuda-maintainers.cachix.org"
  ];
  trusted-public-keys = [
    "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
  ];
};
</nowiki>}}
=== Non-NixOS ===
If you have [https://www.cachix.org cachix] installed and set up, all you need to do is run:
<syntaxHighlight lang="console">
$ cachix use cuda-maintainers
</syntaxHighlight>
Else, you have to add <code>substituters</code> and <code>trusted-public-keys</code> to <code>/etc/nix/nix.conf</code>:
{{file|/etc/nix/nix.conf|nix|<nowiki>
trusted-public-keys = cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E=
trusted-substituters = https://cuda-maintainers.cachix.org
trusted-users = root @wheel
</nowiki>}}
If your user is in <code>trusted-users</code>, you can also add the cache in your home directory:
{{file|~/.config/nix/nix.conf|nix|<nowiki>
substituters = https://cuda-maintainers.cachix.org
</nowiki>}}
</nowiki>}}


Line 106: Line 151:
* [https://github.com/NixOS/nixpkgs/issues/131608 eGPU with nvidia-docker on intel-xserver]
* [https://github.com/NixOS/nixpkgs/issues/131608 eGPU with nvidia-docker on intel-xserver]
* [https://discourse.nixos.org/t/cuda-in-nixos-on-gcp-for-a-tesla-k80/ Tesla K80 based CUDA setup with Terraform on GCP]
* [https://discourse.nixos.org/t/cuda-in-nixos-on-gcp-for-a-tesla-k80/ Tesla K80 based CUDA setup with Terraform on GCP]
[[Category:Server]]