NVIDIA: Difference between revisions

imported>Samuela
No edit summary
imported>Samuela
No edit summary
Line 26: Line 26:


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.
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.
== CUDA ==
'''Note that these examples haven't been updated in a while (as of 2022-03-12). May not be the best solution.'''
There some possible ways to setup a development environment using CUDA on NixOS. This can accomplished in the following ways:
* By making a FHS user env
{{file|cuda-fsh.nix|nix|<nowiki>
{ pkgs ? import <nixpkgs> {} }:
let
  fhs = pkgs.buildFHSUserEnv {
    name = "cuda-env";
    targetPkgs = pkgs: with pkgs; [
      git
      gitRepo
      gnupg
      autoconf
      curl
      procps
      gnumake
      utillinux
      m4
      gperf
      unzip
      cudatoolkit
      linuxPackages.nvidia_x11
      libGLU libGL
      xorg.libXi xorg.libXmu freeglut
      xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
      ncurses5
      stdenv.cc
      binutils
    ];
    multiPkgs = pkgs: with pkgs; [ zlib ];
    runScript = "bash";
    profile = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
      # export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib
      export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
      export EXTRA_CCFLAGS="-I/usr/include"
    '';
  };
in pkgs.stdenv.mkDerivation {
  name = "cuda-env-shell";
  nativeBuildInputs = [ fhs ];
  shellHook = "exec cuda-env";
}
</nowiki>}}
* By making a nix-shell
{{file|cuda-shell.nix|nix|<nowiki>
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
  name = "cuda-env-shell";
  buildInputs = with pkgs; [
    git gitRepo gnupg autoconf curl
    procps gnumake utillinux m4 gperf unzip
    cudatoolkit linuxPackages.nvidia_x11
    libGLU libGL
    xorg.libXi xorg.libXmu freeglut
    xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
    ncurses5 stdenv.cc binutils
  ];
  shellHook = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
      # export LD_LIBRARY_PATH=${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>}}
== See also ==
* [https://github.com/grahamc/nixos-cuda-example nixos-cuda-example]
* [https://github.com/grahamc/nixos-cuda-example/pull/2 nix-shell envs for Cuda]
* [https://discourse.nixos.org/t/cuda-setup-on-nixos/1118 CUDA setup on NixOS]
* [https://github.com/NixOS/nixpkgs/issues/131608 eGPU with nvidia-docker on intel-xserver]


= Using your GPU for graphics =
= Using your GPU for graphics =
Line 271: Line 354:
Use option <syntaxHighlight lang="nix">hardware.bumblebee.enable = true;</syntaxHighlight>
Use option <syntaxHighlight lang="nix">hardware.bumblebee.enable = true;</syntaxHighlight>


== CUDA ==
There some possible ways to setup a development environment using CUDA on NixOS. This can accomplished in the following ways:
* By making a FHS user env
{{file|cuda-fsh.nix|nix|<nowiki>
{ pkgs ? import <nixpkgs> {} }:
let
  fhs = pkgs.buildFHSUserEnv {
    name = "cuda-env";
    targetPkgs = pkgs: with pkgs; [
      git
      gitRepo
      gnupg
      autoconf
      curl
      procps
      gnumake
      utillinux
      m4
      gperf
      unzip
      cudatoolkit
      linuxPackages.nvidia_x11
      libGLU libGL
      xorg.libXi xorg.libXmu freeglut
      xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
      ncurses5
      stdenv.cc
      binutils
    ];
    multiPkgs = pkgs: with pkgs; [ zlib ];
    runScript = "bash";
    profile = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
      # export LD_LIBRARY_PATH=${pkgs.linuxPackages.nvidia_x11}/lib
      export EXTRA_LDFLAGS="-L/lib -L${pkgs.linuxPackages.nvidia_x11}/lib"
      export EXTRA_CCFLAGS="-I/usr/include"
    '';
  };
in pkgs.stdenv.mkDerivation {
  name = "cuda-env-shell";
  nativeBuildInputs = [ fhs ];
  shellHook = "exec cuda-env";
}
</nowiki>}}
* By making a nix-shell
{{file|cuda-shell.nix|nix|<nowiki>
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation {
  name = "cuda-env-shell";
  buildInputs = with pkgs; [
    git gitRepo gnupg autoconf curl
    procps gnumake utillinux m4 gperf unzip
    cudatoolkit linuxPackages.nvidia_x11
    libGLU libGL
    xorg.libXi xorg.libXmu freeglut
    xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr zlib
    ncurses5 stdenv.cc binutils
  ];
  shellHook = ''
      export CUDA_PATH=${pkgs.cudatoolkit}
      # export LD_LIBRARY_PATH=${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>}}


== Troubleshooting ==
== Troubleshooting ==
Line 370: Line 380:
</nowiki>}}
</nowiki>}}
If you have a modern Nvidia GPU (Turing [https://en.wikipedia.org/wiki/Turing_(microarchitecture)#Products_using_Turing] or later), you may also want to investigate the <code>hardware.nvidia.powerManagement.finegrained</code> option: [https://download.nvidia.com/XFree86/Linux-x86_64/460.73.01/README/dynamicpowermanagement.html]
If you have a modern Nvidia GPU (Turing [https://en.wikipedia.org/wiki/Turing_(microarchitecture)#Products_using_Turing] or later), you may also want to investigate the <code>hardware.nvidia.powerManagement.finegrained</code> option: [https://download.nvidia.com/XFree86/Linux-x86_64/460.73.01/README/dynamicpowermanagement.html]
== See also ==
* [https://github.com/grahamc/nixos-cuda-example nixos-cuda-example]
* [https://github.com/grahamc/nixos-cuda-example/pull/2 nix-shell envs for Cuda]
* [https://discourse.nixos.org/t/cuda-setup-on-nixos/1118 CUDA setup on NixOS]
* [https://github.com/NixOS/nixpkgs/issues/131608 eGPU with nvidia-docker on intel-xserver]


[[Category:Video]]
[[Category:Video]]