Nvidia GPU not being used

I have a Lenovo LOQ laptop with a AMD Ryzen™ 7 7840HS processor with Radeon™ 780M Graphics × 16 integrated graphics and a NVIDIA GeForce RTX™ 4050 Laptop GPU. I am using NixOS 24.05 (Uakari) and it feels like my 4050 just isn’t being used. I can’t fully test the gpu because it won’t pop up in system monitor or mission center, so I can’t see the usage. However, trying to do something like render a video from shotcut or display something on my tv it just seems laggy. The only way I can really get a good idea of if it is being used is by looking at the gpu temperature in the nvidia settings, of which it doesn’t go up for rendering a video or go up when playing a 4k video (which might be normal). The only thing I see it go up for is when I run a web gpu stress test, of which it gets very laggy an the temp only goes up by 10 degrees C. I’m lost on ideas I’ve been looking through forms trying to find something for the past 4 days, the main thing I want to use my gpu for is rendering and stuff like ollama (which unfortunately doesn’t work on nix with gpus without docker gpu passthrough :frowning: ). I’m just curious if there are any other ideas to get my gpu to actually be used, or show up period. I have tried wayland and X11, which at least the gpu shows up in settings in X11, but I still can’t see its usage.

Have you read the wiki entry and looked at nixos-hardware?

I have read the Nvidia nixos wiki multiple times. my setup is identical. I’m unsure what that prime.nix file does, is there a description somewhere?
I think my issue is more with shotcut than anything. I forcefully remedied the issue by disabling my integrated graphics, so that it could only use my gpu. IDK, I think I just can’t figure out how it works because I can’t see my graphics cards mission center, which is probably an issue with mission center than nixos.

You can use nvitop or nvtop to check the GPU usage. The first is exclusively for Nvidia, while the other supports other GPUs.

nvidia-settings, nvidia-smi and nvidia-smi dmon are built-into the driver and do that too, by the way.

My bet is that you didn’t set up prime - prime is responsible for allowing your iGPU pass off work to the dGPU, when you run that work with some special environment variables (which you can set with the offload command).

Can you share your config so we can give specific pointers?

1 Like

This is my Nvidia configuration, I put it in my configuration.nix file in the /etc/nixos directory

Nvidia configuration

Enable OpenGL

hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};

Load nvidia driver for Xorg and Wayland

services.xserver.videoDrivers = [“nvidia”];

hardware.nvidia = {

# Modesetting is required.
modesetting.enable = true;

# Nvidia power management. Experimental, and can cause sleep/suspend to fail.
# Enable this if you have graphical corruption issues or application crashes after waking
# up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead 
# of just the bare essentials.
powerManagement.enable = false;

# Fine-grained power management. Turns off GPU when not in use.
# Experimental and only works on modern Nvidia GPUs (Turing or newer).
powerManagement.finegrained = false;

# Use the NVidia open source kernel module (not to be confused with the
# independent third-party "nouveau" open source driver).
# Support is limited to the Turing and later architectures. Full list of 
# supported GPUs is at: 
# https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus 
# Only available from driver 515.43.04+
# Currently alpha-quality/buggy, so false is currently the recommended setting.
open = false;

# Enable the Nvidia settings menu,
# accessible via `nvidia-settings`.
nvidiaSettings = true;

# Optionally, you may need to select the appropriate driver version for your specific GPU.
package = config.boot.kernelPackages.nvidiaPackages.stable;

};

Nvidia Prime

hardware.nvidia.prime = {
# enable Nvidia reverse Sync
#reverseSync.enable = true;
#allowExternalGpu = false;

# enable Nvidia Sync
sync.enable = true;

# for Nvidia offload
#offload = {
	#	enable = true;
	#	enableOffloadCmd = true;
	#};

	# Make sure to use the correct Bus ID values for your system!
	amdgpuBusId = "PCI:06:00:0";
# intelBusId = "PCI:0:2:0";
	nvidiaBusId = "PCI:01:00:0";
            # amdgpuBusId = "PCI:54:0:0"; For AMD GPU
};

That is really useful to know, I’m using this from now on, thank you!

1 Like

Have you been able to get the Nvidia GPU to be the default device? I have not been able to get the GPU in sync mode on Wayland to be used for anything except gnome-shell. I have a Thinkpad P1 Gen 6 with the RTX 2000 Ada generation and am using the production driver.

Not necessarily, what I tried is a disabled my UMA GPU (which is the lower power GPU not the nvidia) and I realized that the gpu fans for the Nvidia would start to spin up and my laptop would make a lot of noise because it would only use the 4050. So what I do now, is I use the default dynamic configuration and if I need to connect an external monitor or tv I go into the bios and disable the UMA gpu, which improves performance. Wayland doesn’t like this as much, sometimes it will work other times I just use Gnome with Xorg. However the gpu does work for the things I needed to use if for, mainly for ai stuff.

Oh yeh, I had to disable sleep mode too. On the Ollama tickets it talks about how on laptops the sleep mode messes with gpu somehow and the gpu will stop working after the laptop wakes up from sleep. So I just have it turn off the screen and lock instead of sleep. I power it down if I am going to take it anywhere anyways.

And my issue with video rendering was that the rendering that I was doing on shotcut just doesn’t use the gpu.

I figured out the docker stuff, nixos is very strange when it comes to gpu passthrough with docker and there is only one place on the entire nixos website that I could find the answer it was in one really old thread, I’ll post it in a minute

edit: yeh instead of using --gpu=all on nixos you need to use --device=nvidia.com/gpu=all which is the dumbest thing that it isn’t listed anywhere I could find except in some old thread, I guess I could edit the wiki…’

edit 2: oh and rootless docker doesn’t work on laptops with gpu passthrough. I’m editing the nixos docker wiki, this is dumb info not to include.

edit 3: That was my first time editing a Wiki, but at least that information is in the wiki now. I almost swapped OSes because of that, so hopefully it can help someone.

1 Like