Graphics Cards Setup Intel and AMD

Hey there,

I have two NixOS machines with new hardware. One uses an integrated Intel GPU, the other one a dedicated AMD Radeon GPU.

I read some links and cobbled configs together. However, I am not confident that I ended up with the best possible setup.

Are the posted configs sufficient to get max compute out of the GPUs? Are there useless statements? For example, I don’t understand if it makes sense to set both hardware.graphics.extraPackages and hardware.amdgpu.opencl

Do I need to set services.xserver.videoDrivers for my Wayland setup (in addition to the below)?

How can I verify I have full hardware acceleration, for example for gaming? Is clinfo sufficient or does it only show what’s available, not necessarily what is used? Is there something similar for Vulkan or OpenGL?

Thank you very much for your time and support :green_heart:

Configs

These are all configs with regards to GPUs on the respective systems.

Intel

  # Intel GPU (including "xe" driver):
  hardware.graphics = {
    enable = true;
    extraPackages = with pkgs; [
      # Required for modern Intel GPUs (Xe iGPU and ARC)
      intel-media-driver # VA-API (iHD) userspace
      vpl-gpu-rt # oneVPL (QSV) runtime

      # Optional (compute / tooling):
      intel-compute-runtime # OpenCL (NEO) + Level Zero for Arc/Xe
    ];
  };
  environment.sessionVariables = {
    LIBVA_DRIVER_NAME = "iHD"; # Prefer the modern iHD backend
  };
  boot.initrd.kernelModules =
    lib.mkIf (lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.8")
      [ "xe" ];

AMD

  # AMD GPU:
  hardware.graphics = {
    enable = true;
    enable32Bit = true;
    extraPackages = with pkgs; [
      rocmPackages.clr.icd
    ];
  };
  hardware.amdgpu = {
    initrd.enable = true;
    opencl.enable = true;
  };

Sources

Depends on what you mean by “compute”. I’d interpret that word such that the answer is “no, stop running wayland or video games if you want to maximize compute”.

You seem like a desktop user though, which probably means you don’t want to maximize “compute”, or even have a use case for it. But more on that later.

No. While that option does also add the relevant drivers to the list of forcibly loaded kernel modules, the kernel will also just pick up the fact that you’re trying to use this hardware and load the modules implicitly.

Unlike with the nvidia driver, nothing in nixpkgs currently checks if the intel/amd strings are part of that list, either, so adding them is completely optional, especially on Wayland, regardless of what the wiki may say.

A few, arguably:

  • hardware.graphics.enable is implied by the modules of pretty much all desktops, and likely redundant
  • hardware.amdgpu.initrd.enable almost certainly does nothing useful on your system, and may be actively harmful
    • Your primary GPU should be your iGPU, which means that you don’t need the amdgpu driver in the initrd, which means that this makes your initrd larger than needed and your boot slower
    • If you “need” this for your device to use your amdgpu as your primary gpu, that’s the wrong way to do it. Use your wayland compositor to configure the primary GPU instead, or better yet, use PRIME to render specific applications with your dGPU.

Probably not? The hardware.graphics.extraPackages you set add opencl support for the intel card, while hardware.amdgpu.opencl sets it up for the amdgpu card.

You probably don’t want to mix them, but dedicate one of the GPUs to opencl tasks. Most likely the dGPU.

So, my suggestion would be to remove all opencl-related stuff for intel, which is most stuff in hardware.graphics.extraPackages.

The extra package you add in the amd section also makes no sense, since the upstream module already does that.

You probably do want to keep intel-media-driver and vpl-gpu-rt though, those are very useful for day-to-day media en- and decoding.

clinfo is pretty much useless for games or other kinds of everyday hardware acceleration.

It only helps understand if your GPUs are set up for raw computation tasks, which is basically only useful if you run data science stuff locally. And you do not, your laptop GPU is way too puny for that.

I’d wager 99% of people who set up opencl never use it - even LLM junkies tend to just pay companies to run the models for them, the whole “AI PC” trend is the epitome of marketing bullshit.

In other words, most of that config is probably useless, unless you already know what you’re doing, but you don’t seem to, so you might want to just get rid of everything related to opencl until you start learning to program with it.

Yes! glxinfo and vulkaninfo respectively.

Note that if you run either of these, they will probably tell you you are using your iGPU. You’ll have to use the DRI_PRIME environment variable to explicitly select the GPU you want to render a process on if you want to change this.

A handy trick is setting that variable e.g. in steam’s .desktop file to guarantee that all your games run on the dGPU.

Whether and how this works for amdgpu+intel is a bit underdocumented, though. You might have to trawl forums and experiment a bit.

3 Likes

Thank you so much! This clears up a lot of misunderstanding (that you identified correctly :sweat_smile:) As you guessed correctly, I am a desktop user and I don’t use/need openCL. Especially not for AI stuff. Call me an “AI sceptic” :sweat_smile:

I should have been clearer in my main post: these are two separate systems. A laptop with only an Intel CPU/iGPU and a desktop with an AMD CPU and separate AMD GPU.

Desktop

This means I can pretty much remove the entire AMD section, right? Maybe keep hardware.graphics.enable32Bit = true; if I need it for Steam?

Could/should I ensure the dGPU is used instead of the iGPU (that’s in the processor?)?
gpu-viewer shows both under Vulkan (but only the dGPU under OpenGL).

Laptop

I removed the extraPackage intel-compute-runtime.

  • How can I find out if my system even supports xe?
  • Do I need LIBVA_DRIVER_NAME = "iHD"?

Ah, I see now.

Yep. None of the other settings are useful for you (though hardware.graphics.enable might still be necesary if your DE modules are a little weird).

hardware.amdgpu.initrd.enable can be used if your pre-stage3 display doesn’t suit your aesthetic taste, but IME modern boards don’t really struggle with this anyway.

Yes and maybe.

Certain wayland compositors auto-detect applications that should be run on the dGPU. Assuming you’re connecting the displays directly to the dGPU on your desktop, it seems kinda pointless to keep the iGPU in the loop, though.

How you force the dGPU depends on your DE/WM, so tell us what that is. You can also attempt to disable the iGPU in BIOS.

A naïve attempt is to see if the module is loaded with lsmod (and I guess double check for i915 while you’re at it).

AIUI support for that driver by your GPU is marked experimental, and it will hence not be loaded by default, and even if it is loaded i915 takes priority. You might have to explicitly blacklist the i915 driver.

The kernel docs and source code might be more helpful than I here, I’ve never worked with an intel GPU that recent.

With i915, yeah, but xe’s media acceleration might be different.

You can verify it’s working with vainfo, and hence also test which, if any, variable is needed.

1 Like