AMD GPU: Difference between revisions

From NixOS Wiki
Added a disclaimer that blender hip needs the current kernel
→‎AMDVLK: editing code block to be updated for 24.11 and above
 
(20 intermediate revisions by 11 users not shown)
Line 1: Line 1:
This guide is about setting up NixOS to correctly use your AMD Graphics card if it is relatively new (aka, after the GCN architecture).
This guide is about setting up NixOS to correctly use your AMD Graphics card if it is relatively new (aka, after the GCN architecture).


== Make the kernel use the correct driver early ==
== Basic Setup ==
For ordinary desktop / gaming usage, AMD GPUs are expected to work out of the box. As with any desktop configuration though, graphics acceleration does need to be enabled.
<syntaxhighlight lang="nix">
# as of 24.11
hardware.graphics = {
  enable = true;
  enable32Bit = true;
};
 
# pre 24.11
hardware.opengl = {
  enable = true;
  driSupport = true;
  driSupport32Bit = true;
};
 
</syntaxhighlight>


The kernel can load the correct driver right away:
== Problems ==
 
=== Dual Monitors ===
 
If you encounter problems having multiple monitors connected to your GPU, adding `video` parameters for each connector to the kernel command line sometimes helps.
 
For example:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
boot.initrd.kernelModules = [ "amdgpu" ];
boot.kernelParams = [
  "video=DP-1:2560x1440@144"
  "video=DP-2:2560x1440@144"
];
</syntaxhighlight>
</syntaxhighlight>


== XServer ==
With the connector names (like `DP-1`), the resolution and frame rate adjusted accordingly.


Make sure Xserver uses the `amdgpu` driver in your configuration.nix:
To figure out the connector names, execute the following command while your monitors are connected:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="bash">
services.xserver.enable = true;
head /sys/class/drm/*/status
services.xserver.videoDrivers = [ "amdgpu" ];
</syntaxhighlight>
</syntaxhighlight>
= Special Configuration =
The following configurations are only required if you have a specific reason for needing them. They are not expected to be necessary for a typical desktop / gaming setup.


== Enable Southern Islands (SI) and Sea Islands (CIK) support ==
== Enable Southern Islands (SI) and Sea Islands (CIK) support ==


The oldest architectures that AMDGPU supports are [https://en.wikipedia.org/wiki/Radeon_HD_7000_series Southern Islands (SI, i.e. GCN 1)] and [https://en.wikipedia.org/wiki/Radeon_HD_8000_series Sea Islands (CIK, i.e. GCN 2)], but support for them is disabled by default. To use AMDGPU instead of the <code>radeon</code> driver, you can set the kernel parameters:
The oldest architectures that AMDGPU supports are [[wikipedia:Radeon_HD_7000_series|Southern Islands (SI, i.e. GCN 1)]] and [[wikipedia:Radeon_HD_8000_series|Sea Islands (CIK, i.e. GCN 2)]], but support for them is disabled by default. To use AMDGPU instead of the <code>radeon</code> driver, you can set the kernel parameters:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# for Southern Islands (SI i.e. GCN 1) cards
# For Southern Islands (SI i.e. GCN 1) cards
boot.kernelParams = [ "radeon.si_support=0" "amdgpu.si_support=1" ];
boot.kernelParams = [ "radeon.si_support=0" "amdgpu.si_support=1" ];
# for Sea Islands (CIK i.e. GCN 2) cards
# For Sea Islands (CIK i.e. GCN 2) cards
boot.kernelParams = [ "radeon.cik_support=0" "amdgpu.cik_support=1" ];
boot.kernelParams = [ "radeon.cik_support=0" "amdgpu.cik_support=1" ];
</syntaxhighlight>
</syntaxhighlight>
Line 36: Line 63:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
systemd.tmpfiles.rules = [
  systemd.tmpfiles.rules =  
     "L+    /opt/rocm/hip   -    -    -    -    ${pkgs.rocmPackages.clr}"
  let
    rocmEnv = pkgs.symlinkJoin {
      name = "rocm-combined";
      paths = with pkgs.rocmPackages; [
        rocblas
        hipblas
        clr
      ];
    };
  in [
     "L+    /opt/rocm  -    -    -    -    ${rocmEnv}"
   ];
   ];
</syntaxhighlight>
</syntaxhighlight>


=== Blender ===
=== Blender ===


Hardware accelerated rendering can be achieved by using the package <syntaxhighlight lang="nix" inline>blender-hip</syntaxhighlight>.
Hardware accelerated rendering can be achieved by using the package <syntaxhighlight lang="nix" inline="">blender-hip</syntaxhighlight>.


Currently, you need to [[Linux kernel|use the latest kernel]] <syntaxhighlight lang="nix" inline="">blender-hip</syntaxhighlight> this to work.
Currently, you need to [[Linux kernel|use the latest kernel]] for <syntaxhighlight lang="nix" inline="">blender-hip</syntaxhighlight> to work.


== OpenCL ==
== OpenCL ==


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
hardware.opengl.extraPackages = with pkgs; [
hardware.graphics.extraPackages = with pkgs; [ rocmPackages.clr.icd ];
  rocmPackages.clr.icd
];
</syntaxhighlight>
</syntaxhighlight>


Line 59: Line 95:
=== Radeon 500 series (aka Polaris) ===
=== Radeon 500 series (aka Polaris) ===


As of [https://github.com/ROCm/ROCm/issues/1659 ROCm 4.5], AMD has disabled OpenCL on Polaris based cards. This can be re-enabled by setting the environment variable <code>ROC_ENABLE_PRE_VEGA=1</code>
As of [https://github.com/ROCm/ROCm/issues/1659 ROCm 4.5], AMD has disabled OpenCL on Polaris-based cards. This can be re-enabled by setting the environment variable <code>ROC_ENABLE_PRE_VEGA=1</code>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 66: Line 102:
};
};
</syntaxhighlight>
</syntaxhighlight>
=== Older GPUs (TeraScale) ===
<!-- FIXME this should be moved to a dedicated page for the "radeon" driver or OpenCL, if either of those are created at some point in the future -->
For graphics cards older than GCN 1 — or for any GCN using the "radeon" driver — enable OpenCL by adding Clover ''instead of'' the ROCm ICD:
<syntaxhighlight lang="nix">
hardware.opengl.extraPackages = with pkgs; [
  # OpenCL support for the older Radeon R300, R400, R500,
  # R600, R700, Evergreen, Northern Islands,
  # Southern Islands (radeon), and Sea Islands (radeon)
  # GPU families
  mesa.opencl
  # NOTE: at some point GPUs in the R600 family and newer
  # may need to replace this with the "rusticl" ICD;
  # and GPUs in the R500-family and older may need to
  # pin the package version or backport Clover
  # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion
  # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385
];
</syntaxhighlight>
Merely installing <code>mesa.opencl</code> with <code>nix-shell -p</code> will not work; it needs to be present at build-time for the OpenCL ICD loader, which only searches static paths.


== Vulkan ==
== Vulkan ==
Line 81: Line 141:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
#24.11
hardware.graphics.extraPackages = with pkgs; [
  amdvlk
];
# For 32 bit applications
hardware.graphics.extraPackages32 = with pkgs; [
  driversi686Linux.amdvlk
];
#24.05 and below
hardware.opengl.extraPackages = with pkgs; [
hardware.opengl.extraPackages = with pkgs; [
   amdvlk
   amdvlk
Line 92: Line 162:
More information can be found here: https://nixos.org/manual/nixos/unstable/index.html#sec-gpu-accel-vulkan
More information can be found here: https://nixos.org/manual/nixos/unstable/index.html#sec-gpu-accel-vulkan


== Problems ==
== GUI tools ==


=== Dual Monitors ===
==== LACT - Linux AMDGPU Controller ====
 
This application allows you to overclock, undervolt, set fans curves of AMD GPUs on a Linux system.
If you encounter problems having multiple monitors connected to your GPU, adding `video` parameters for each connector to the kernel command line sometimes helps.
 
For example:


In order to install the daemon service you need to add the package to <code>systemd.packages</code>. Also the <code>wantedBy</code> field should be set to <code>multi-user.target</code> to start the service during boot.
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
boot.kernelParams = [
environment.systemPackages = with pkgs; [ lact ];
  "video=DP-1:2560x1440@144"
systemd.packages = with pkgs; [ lact ];
  "video=DP-2:2560x1440@144"
systemd.services.lactd.wantedBy = ["multi-user.target"];
];
</syntaxhighlight>
 
With the connector names (like `DP-1`), the resolution and frame rate adjusted accordingly.
 
To figure out the connector names, execute the following command while your monitors are connected:
 
<syntaxhighlight lang="bash">
head /sys/class/drm/*/status
</syntaxhighlight>
</syntaxhighlight>
[[Category:Video]]
[[Category:Video]]

Latest revision as of 04:27, 20 December 2024

This guide is about setting up NixOS to correctly use your AMD Graphics card if it is relatively new (aka, after the GCN architecture).

Basic Setup

For ordinary desktop / gaming usage, AMD GPUs are expected to work out of the box. As with any desktop configuration though, graphics acceleration does need to be enabled.

# as of 24.11
hardware.graphics = {
  enable = true;
  enable32Bit = true;
};

# pre 24.11
hardware.opengl = {
  enable = true;
  driSupport = true;
  driSupport32Bit = true;
};

Problems

Dual Monitors

If you encounter problems having multiple monitors connected to your GPU, adding `video` parameters for each connector to the kernel command line sometimes helps.

For example:

boot.kernelParams = [
  "video=DP-1:2560x1440@144"
  "video=DP-2:2560x1440@144"
];

With the connector names (like `DP-1`), the resolution and frame rate adjusted accordingly.

To figure out the connector names, execute the following command while your monitors are connected:

head /sys/class/drm/*/status

Special Configuration

The following configurations are only required if you have a specific reason for needing them. They are not expected to be necessary for a typical desktop / gaming setup.

Enable Southern Islands (SI) and Sea Islands (CIK) support

The oldest architectures that AMDGPU supports are Southern Islands (SI, i.e. GCN 1) and Sea Islands (CIK, i.e. GCN 2), but support for them is disabled by default. To use AMDGPU instead of the radeon driver, you can set the kernel parameters:

# For Southern Islands (SI i.e. GCN 1) cards
boot.kernelParams = [ "radeon.si_support=0" "amdgpu.si_support=1" ];
# For Sea Islands (CIK i.e. GCN 2) cards
boot.kernelParams = [ "radeon.cik_support=0" "amdgpu.cik_support=1" ];

Doing this is required to use Vulkan on these cards, as the radeon driver doesn't support it.

HIP

Most software has the HIP libraries hard-coded. You can work around it on NixOS by using:

  systemd.tmpfiles.rules = 
  let
    rocmEnv = pkgs.symlinkJoin {
      name = "rocm-combined";
      paths = with pkgs.rocmPackages; [
        rocblas
        hipblas
        clr
      ];
    };
  in [
    "L+    /opt/rocm   -    -    -     -    ${rocmEnv}"
  ];

Blender

Hardware accelerated rendering can be achieved by using the package blender-hip.

Currently, you need to use the latest kernel for blender-hip to work.

OpenCL

hardware.graphics.extraPackages = with pkgs; [ rocmPackages.clr.icd ];

You should also install the clinfo package to verify that OpenCL is correctly setup (or check in the program you use to see if it is now available, such as in Darktable).

Radeon 500 series (aka Polaris)

As of ROCm 4.5, AMD has disabled OpenCL on Polaris-based cards. This can be re-enabled by setting the environment variable ROC_ENABLE_PRE_VEGA=1

environment.variables = {
  ROC_ENABLE_PRE_VEGA = "1";
};

Older GPUs (TeraScale)

For graphics cards older than GCN 1 — or for any GCN using the "radeon" driver — enable OpenCL by adding Clover instead of the ROCm ICD:

hardware.opengl.extraPackages = with pkgs; [
  # OpenCL support for the older Radeon R300, R400, R500,
  # R600, R700, Evergreen, Northern Islands,
  # Southern Islands (radeon), and Sea Islands (radeon)
  # GPU families
  mesa.opencl
  # NOTE: at some point GPUs in the R600 family and newer
  # may need to replace this with the "rusticl" ICD;
  # and GPUs in the R500-family and older may need to
  # pin the package version or backport Clover
  # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion
  # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385
];

Merely installing mesa.opencl with nix-shell -p will not work; it needs to be present at build-time for the OpenCL ICD loader, which only searches static paths.

Vulkan

Vulkan is already enabled by default (using Mesa RADV) on 64 bit applications. The settings to control it are:

hardware.opengl.driSupport = true; # This is already enabled by default
hardware.opengl.driSupport32Bit = true; # For 32 bit applications

AMDVLK

The AMDVLK drivers can be used in addition to the Mesa RADV drivers. The program will choose which one to use:

#24.11 
hardware.graphics.extraPackages = with pkgs; [
  amdvlk
];
# For 32 bit applications 
hardware.graphics.extraPackages32 = with pkgs; [
  driversi686Linux.amdvlk
];

#24.05 and below
hardware.opengl.extraPackages = with pkgs; [
  amdvlk
];
# For 32 bit applications 
hardware.opengl.extraPackages32 = with pkgs; [
  driversi686Linux.amdvlk
];

More information can be found here: https://nixos.org/manual/nixos/unstable/index.html#sec-gpu-accel-vulkan

GUI tools

LACT - Linux AMDGPU Controller

This application allows you to overclock, undervolt, set fans curves of AMD GPUs on a Linux system.

In order to install the daemon service you need to add the package to systemd.packages. Also the wantedBy field should be set to multi-user.target to start the service during boot.

environment.systemPackages = with pkgs; [ lact ];
systemd.packages = with pkgs; [ lact ];
systemd.services.lactd.wantedBy = ["multi-user.target"];