Seamless gpu switching (nvidia) (Guide)

figured I would make a post about my experiences and discoveries with gpu switching on aurora and general nvidia stuff. This is mainly for laptops with dedicated nvidia graphics.
First of all preinstalled switcheroo-control is amazing. Big thanks to the ublue devs for supporting it. Since aurora does not currently have a ujust script to start the service, to enable it run “sudo systemctl enable supergfxd.service && sudo systemctl start supergfxd.service”. I think this also adds a widget to the task bar. I find it very helpful to tell when the gpu is being used or not and what configuration I currently have. If it is not added automatically you can always do so manually by editing the taskbar and adding it.
I have experimented a bit and I have been able to get seamless gpu switching without logout. To do so we need two things:

  1. disable nvidia-persistenced service if it is enabled. This service is not essential to my knowledge. To do so run “sudo systemctl stop nvidia-persistenced && sudo systemctl disable nvidia-persistenced && sudo systemctl mask nvidia-persistenced”. If at any point you want to turn this back on just do “sudo systemctl unmask nvidia-persistenced && sudo systemctl enable nvidia-persistenced && sudo systemctl start nvidia-persistenced”.
  2. edit “/etc/supergfxd.conf” and make it like so:
    "
    {
    “mode”: “Hybrid”,
    “vfio_enable”: true,
    “vfio_save”: false,
    “always_reboot”: false,
    “no_logind”: true,
    “logout_timeout_s”: 60,
    “hotplug_type”: “None”
    }
    "
    The lines are pretty self explanatory. Once this is done, you can restart the service or just reboot. I recommend just rebooting. Note that you can change the hotplug type to “Asus” and it may work better for you. If you ever do change the hotplug type you need to reboot however.
    The setup as above also allows for vfio, which also makes gpu passthrough trivial. If for example you set up libvirt hooks you can call “supergfxctl -m Integrated && sleep 2 && supergfxctl -m Vfio” and boom gpu pass through acquired.
    If for any reason you are having trouble switching run “sudo fuser -v /dev/nvidia*” in the terminal and see what processes are taking hold of the nvidia gpu. If you see nvidia-powerd you can safely ignore it as switcheroo-control already dynamically enables/disables it on gpu hotplug. For any pesky process you are okay with terminating you can use kill [process ID number] or pkill [proces name] and you should be good to go. Its usually X11 apps that cause this, as wayland has much better gpu switching support.

Potential future quality of life things (waiting for upstream)
the latest git of switcheroo-control on gitlab merged support for dynamically enabling/disabling nvidia-persistenced service on gpu hotplug. This means that disabling nvidia-persitenced may no longer be necessary. I am unsure how closely this is followed by the package ublue ships but hopefully this gets picked up in the future.
When plugging / unplugging laptop from external monitor nvidia gpu does not go to sleep → issue is being tracked on nvidia github here. In the meantime you can run " sudo modprobe -r nvidia-drm && sudo modprobe nvidia-drm" in the terminal to allow gpu to sleep after its unplugged frrom external monitor.

2 Likes