AMD GPU

From NixOS Wiki
Jump to: navigation, search
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