Jump to content

AMD GPU: Difference between revisions

From NixOS Wiki
m Fix URL for zen patches (previous commits incorrectly signed)
Opengears (talk | contribs)
added table of GPU features
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).


== Basic Setup ==
{| class="wikitable"
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.
|+ AMD GPU Series and Their Features
<syntaxhighlight lang="nix">
|-
# as of 24.11
! GPU Generation !! Series !! Architecture !! HIP Support !! Ray Tracing !! AI Acceleration !! Vulkan Support
hardware.graphics = {
|-
  enable = true;
| Pre-GCN & Early GCN || Radeon HD 5000/6000/7000 Series || TeraScale/GCN 1.0 || No || No || No || No
  enable32Bit = true;
|-
};
| GCN 2nd Gen (Sea Islands) || Radeon R7/R9 200 Series || GCN 2.0 || No || No || No || Vulkan 1.0
|-
| GCN 3rd Gen (Volcanic Islands) || Radeon R9 300/Fury Series || GCN 3.0 || No || No || No || Vulkan 1.0
|-
| GCN 4th Gen (Polaris) || Radeon RX 400/500 Series || GCN 4.0 || Yes (up to ROCm 5.6) || No || No || Vulkan 1.0
|-
| GCN 5th Gen (Vega) || Radeon RX Vega Series || GCN 5.0 || Yes (up to ROCm 5.6) || No || No || Vulkan 1.1
|-
| RDNA 1st Gen (Navi 1x) || Radeon RX 5000 Series || RDNA 1.0 || Yes || No || No || Vulkan 1.1
|-
| RDNA 2nd Gen (Navi 2x) || Radeon RX 6000 Series || RDNA 2.0 || Yes || Yes || No || Vulkan 1.2
|-
| RDNA 3rd Gen (Navi 3x) || Radeon RX 7000 Series || RDNA 3.0 || Yes || Yes || Yes || Vulkan 1.3
|}


# pre 24.11
This guide is about setting up NixOS to correctly use your AMD Graphics card if it is relatively new (aka, after the GCN architecture).
hardware.opengl = {
  enable = true;
  driSupport = true;
  driSupport32Bit = true;
};


</syntaxhighlight>
== Make the kernel use the correct driver early ==
 
== Problems ==


=== Dual Monitors ===
The kernel can load the correct driver right away:
 
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.kernelParams = [
boot.initrd.kernelModules = [ "amdgpu" ];
  "video=DP-1:2560x1440@144"
  "video=DP-2:2560x1440@144"
];
</syntaxhighlight>
</syntaxhighlight>


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


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


<syntaxhighlight lang="bash">
<syntaxhighlight lang="nix">
head /sys/class/drm/*/status
services.xserver.enable = true;
services.xserver.videoDrivers = [ "amdgpu" ];
</syntaxhighlight>
</syntaxhighlight>


=== System Hang with Vega Graphics (and select GPUs) ===
== Enable Southern Islands (SI) and Sea Islands (CIK) support ==
Currently on the latest kernel/mesa (currently 6.13 and 24.3.4 respectively), Vega integrated graphics (and other GPUs like the RX 6600<ref>https://bbs.archlinux.org/viewtopic.php?pid=2224147#p2224147</ref>) will have a possibility to hang due to context-switching between Graphics and Compute.<ref>https://bbs.archlinux.org/viewtopic.php?id=301798</ref> There are currently two sets of patches to choose between stability or speed that can be applied: [https://github.com/SeryogaBrigada/linux/commits/v6.13-amdgpu amdgpu-stable] and [https://github.com/SeryogaBrigada/linux/commits/v6.13-amdgpu-testing amdgpu-testing].


See [[Linux Kernel#Patching a single In-tree kernel module]], keep in mind how to make [https://stackoverflow.com/a/23525893 patch diffs from commits from GitHub], and consider this example configuration:<syntaxhighlight lang="nix">
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:
{ config, pkgs, ... }:
let
  amdgpu-kernel-module = pkgs.callPackage ./packages/amdgpu-kernel-module.nix {
    # Make sure the module targets the same kernel as your system is using.
    kernel = config.boot.kernelPackages.kernel;
  };
  # linuxPackages_latest 6.13 (or linuxPackages_zen 6.13)
  amdgpu-stability-patch = pkgs.fetchpatch {
    name = "amdgpu-stability-patch";
    url = "https://github.com/torvalds/linux/compare/ffd294d346d185b70e28b1a28abe367bbfe53c04...SeryogaBrigada:linux:4c55a12d64d769f925ef049dd6a92166f7841453.diff";
    hash = "sha256-q/gWUPmKHFBHp7V15BW4ixfUn1kaeJhgDs0okeOGG9c=";
  };
  /*
  # linuxPackages_zen 6.12
  amdgpu-stability-patch = pkgs.fetchpatch {
    name = "amdgpu-stability-patch-zen";
    url = "https://github.com/zen-kernel/zen-kernel/compare/fd00d197bb0a82b25e28d26d4937f917969012aa...WhiteHusky:zen-kernel:f4c32ca166ad55d7e2bbf9adf121113500f3b42b.diff";
    hash = "sha256-bMT5OqBCyILwspWJyZk0j0c8gbxtcsEI53cQMbhbkL8=";
  };
  */
in
{
  # amdgpu instability with context switching between compute and graphics
  # https://bbs.archlinux.org/viewtopic.php?id=301798
  # side-effects: plymouth fails to show at boot, but does not interfere with booting
  boot.extraModulePackages = [
    (amdgpu-kernel-module.overrideAttrs (_: {
      patches = [
        amdgpu-stability-patch
      ];
    }))
  ];
}
</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 ===
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 96: Line 54:
Doing this is required to use [[#Vulkan|Vulkan]] on these cards, as the <code>radeon</code> driver doesn't support it.
Doing this is required to use [[#Vulkan|Vulkan]] on these cards, as the <code>radeon</code> driver doesn't support it.


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


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
  systemd.tmpfiles.rules =  
systemd.tmpfiles.rules = [
  let
     "L+    /opt/rocm/hip   -    -    -    -    ${pkgs.rocmPackages.clr}"
    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>. See the table for which cards support HIP (Polaris and above will support HIP).
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]] for <syntaxhighlight lang="nix" inline="">blender-hip</syntaxhighlight> to work.
== OpenCL ==


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


You should also install the <code>clinfo</code> 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).
You should also install the <code>clinfo</code> 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) ====
<syntaxhighlight lang="nix">
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>
environment.systemPackages = with pkgs; [
  clinfo
];
</syntaxhighlight>
 
=== 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>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 137: Line 94:
</syntaxhighlight>
</syntaxhighlight>


==== Older GPUs (TeraScale) ====
=== 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 -->
<!-- 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:
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">
<syntaxhighlight lang="nix">
hardware.opengl.extraPackages = with pkgs; [
hardware.opengl.extraPackages = [
  # OpenCL support for the older Radeon R300, R400, R500,
   # NOTE: at some point GPUs in the R600-family and newer
  # 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;
   # may need to replace this with the "rusticl" ICD;
   # and GPUs in the R500-family and older may need to
   # and GPUs in the R500-family and older may need to
   # pin the package version or backport Clover
   # pin the package version or backport/patch this back in
   # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion
   # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion
   # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385
   # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385
  pkgs.mesa.opencl
];
];
</syntaxhighlight>
</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.
Installing `mesa.opencl` with `nix-shell` will not work; it needs to be configured at a higher level for the OpenCL ICD loader, which only searches fixed locations.


=== Vulkan ===
If you have an AMD GPU from the GCN 1st Gen series or newer, [https://docs.mesa3d.org/rusticl.html Rusticl] should provide OpenCL support.
Vulkan is already enabled by default (using Mesa RADV) on 64 bit applications. The settings to control it are:
 
== Vulkan ==
 
Vulkan is already enabled by default (using Mesa RADV) on 64 bit applications. The settings to control it for 32 bit applications is:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
hardware.opengl.driSupport = true; # This is already enabled by default
hardware.opengl.driSupport32Bit = true; # For 32 bit applications
hardware.opengl.driSupport32Bit = true; # For 32 bit applications
</syntaxhighlight>
</syntaxhighlight>


==== AMDVLK ====
Soon this will be changed to
<syntaxhighlight lang="nix">
hardware.graphics.enable32Bit = true; # For 32 bit applications
</syntaxhighlight>
 
 
=== AMDVLK ===
 
The AMDVLK drivers can be used in addition to the Mesa RADV drivers. The program will choose which one to use:
The AMDVLK drivers can be used in addition to the Mesa RADV drivers. The program will choose which one to use:


<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 194: Line 146:
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


=== GUI tools ===
== Problems ==
 
=== Dual Monitors ===


==== LACT - Linux AMDGPU Controller ====
If you encounter problems having multiple monitors connected to your GPU, adding `video` parameters for each connector to the kernel command line sometimes helps.
This application allows you to overclock, undervolt, set fans curves of AMD GPUs on a Linux system.
 
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">
environment.systemPackages = with pkgs; [ lact ];
boot.kernelParams = [
systemd.packages = with pkgs; [ lact ];
  "video=DP-1:2560x1440@144"
systemd.services.lactd.wantedBy = ["multi-user.target"];
  "video=DP-2:2560x1440@144"
];
</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]]

Revision as of 15:10, 16 February 2025

AMD GPU Series and Their Features
GPU Generation Series Architecture HIP Support Ray Tracing AI Acceleration Vulkan Support
Pre-GCN & Early GCN Radeon HD 5000/6000/7000 Series TeraScale/GCN 1.0 No No No No
GCN 2nd Gen (Sea Islands) Radeon R7/R9 200 Series GCN 2.0 No No No Vulkan 1.0
GCN 3rd Gen (Volcanic Islands) Radeon R9 300/Fury Series GCN 3.0 No No No Vulkan 1.0
GCN 4th Gen (Polaris) Radeon RX 400/500 Series GCN 4.0 Yes (up to ROCm 5.6) No No Vulkan 1.0
GCN 5th Gen (Vega) Radeon RX Vega Series GCN 5.0 Yes (up to ROCm 5.6) No No Vulkan 1.1
RDNA 1st Gen (Navi 1x) Radeon RX 5000 Series RDNA 1.0 Yes No No Vulkan 1.1
RDNA 2nd Gen (Navi 2x) Radeon RX 6000 Series RDNA 2.0 Yes Yes No Vulkan 1.2
RDNA 3rd Gen (Navi 3x) Radeon RX 7000 Series RDNA 3.0 Yes Yes Yes Vulkan 1.3

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

The kernel can load the correct driver right away:

boot.initrd.kernelModules = [ "amdgpu" ];

XServer

Make sure Xserver uses the `amdgpu` driver in your configuration.nix:

services.xserver.enable = true;
services.xserver.videoDrivers = [ "amdgpu" ];

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 = [
    "L+    /opt/rocm/hip   -    -    -     -    ${pkgs.rocmPackages.clr}"
  ];

Blender

Hardware accelerated rendering can be achieved by using the package blender-hip. See the table for which cards support HIP (Polaris and above will support HIP).

OpenCL

hardware.opengl.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).

environment.systemPackages = with pkgs; [
  clinfo
];

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 = [
  # 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/patch this back in
  # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion
  # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385
  pkgs.mesa.opencl
];

Installing `mesa.opencl` with `nix-shell` will not work; it needs to be configured at a higher level for the OpenCL ICD loader, which only searches fixed locations.

If you have an AMD GPU from the GCN 1st Gen series or newer, Rusticl should provide OpenCL support.

Vulkan

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

hardware.opengl.driSupport32Bit = true; # For 32 bit applications

Soon this will be changed to

hardware.graphics.enable32Bit = 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:

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

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