CUDA: Difference between revisions

Smudgebun (talk | contribs)
Added a brief Driver Installation section, as it may be unclear to newer users whether or not they need to configure CUDA separately.
DHCP (talk | contribs)
m style fixes, consistency
 
(4 intermediate revisions by one other user not shown)
Line 9: Line 9:
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.
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=sh|line=no|<nowiki>nvidia-smi | grep CUDA</nowiki>}}
<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 23: Line 25:
* By making a FHS user env
* By making a FHS user env


<syntaxhighlight lang="nix" line="1" start="1"># flake.nix, run with `nix develop`
<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 66: Line 69:


* By making a nix-shell
* By making a nix-shell
<syntaxhighlight lang="nix" line="1" start="1">
<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 93: Line 97:


* By making a flake.nix
* By making a flake.nix
<syntaxhighlight lang="nix" line="1" start="1"># flake.nix, run with `nix develop`
<syntaxhighlight lang="nix"># flake.nix, run with `nix develop`
{
{
   description = "CUDA development environment";
   description = "CUDA development environment";
Line 198: Line 202:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
(mlt.override {config.cudaSupport=true;})
  (mlt.override {config.cudaSupport=true;})
];
];
</syntaxhighlight>
</syntaxhighlight>
Line 204: 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 highly recommended you utilize the [[#Setting up CUDA Binary Cache|CUDA Binary Cache]].}}
{{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.


Without the 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 larger programs like Blender, that process can be very resource-intensive. If you know you are installing a large package and cannot use the cache, it is recommended to reduce the number of cores and/or jobs that the process will take, to prevent a crash from memory 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] 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]].
&rarr; For specifics on setting up Blender with CUDA (and OptiX) see: [[Blender#CUDA & OptiX]].
Line 221: Line 227:


{{file|cuda-shell.nix|nix|<nowiki>
{{file|cuda-shell.nix|nix|<nowiki>
  shellHook = ''
shellHook = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
  export CUDA_PATH=${pkgs.cudatoolkit}
      export LD_LIBRARY_PATH=/usr/lib/wsl/lib:${pkgs.linuxPackages.nvidia_x11}/lib:${pkgs.ncurses5}/lib
  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_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
      export EXTRA_CCFLAGS="-I/usr/include"
  export EXTRA_CCFLAGS="-I/usr/include"
  '';           
'';           
</nowiki>}}
</nowiki>}}