• nVidia prime-select “on-demand” on Ubuntu 18.04 and related distros

    Home » Forums » AskWoody support » Linux for the Home user » Linux – all distros » nVidia prime-select “on-demand” on Ubuntu 18.04 and related distros

    Author
    Topic
    #2274146

    In the last post I made about nVidia Prime, I mentioned that the support for nVidia Prime had improved in the new LTS release of Ubuntu, 20.04, as well as downstream relatives, like the upcoming Mint 20.  I got Prime offloading working in Neon (currently based on 18.04), but it was not quite as polished as on Ubuntu 20.04.  I wanted to get it working the same way, and I was trying to do that when I did the stuff that I mentioned in the previous post, but I’d failed.  Now, I’ve succeeded, and this is how!

    First of all, the basic package that does the work of switching from one GPU to another is nvidia-prime on Ubuntu.  This is developed by Ubuntu themselves, though it has been ported (and in some ways, improved upon, from what I’ve read) to Arch also.  I don’t know how well it works, or if it does, on other distros.

    The standard nVidia settings application (I think the Windows version is called nVidia Control Panel) recognizes nvidia-prime and provides a convenient front-end for it.  For Ubuntu 18.04 and derivatives, the dialog has two radio buttons, for Intel and nVidia.  After changing the GPU, the nVidia application advises rebooting, which is kind of inconvenient to switch GPUs, but the Prime Indicator Plus package from WebUpd8 Team improves upon this, allowing you to select “quick switch” from the tray icon, which only requires a logout/in rather than a full reboot (though I had to log out twice to enable nVidia mode previously).

    Ubuntu improved the nvidia-prime package for 20.04 to make use of the new Prime offloading mode.  It was still possible to have it work in 18.04 with the 18.04 version of nvidia-prime, but switching from the old mode (where you picked one GPU and stuck with it until you changed it manually) was more fiddly.  With the new 20.04 version of nvidia-prime, there are three choices… the same Intel and nVidia options as before, but also a new option, on-demand.

    On-demand is just an easy way of selecting the offloading mode, where the Intel GPU is used most of the time, but where the nVidia can be selected for any given program at will.  There are reasons you might want to select one of the other two modes, Intel or nVidia… the Intel mode is slightly better on power consumption than using Intel in the on-demand mode (for now; hopefully nVidia keeps moving forward on this), and the nVidia mode is necessary if you want to use the external HDMI or DisplayPort on most Optimus/Prime laptops.  The external ports are usually wired directly to the nVidia card, so the Intel cannot use them, including in on-demand mode.

    I’d probably have switched temporarily to Kubuntu 20.04 as my main OS if KDE Connect had worked (Neon will switch to a 20.04 base probably in the fall, at which time I would likely switch back to Neon).  I’ve been installing more and more bits of 20.04 in my Neon, including by now Xorg, the Xorg drivers, the 5.4 kernel, and now the 20.04 versions of nvidia-prime and the one crucial bit I was missing before when I failed to get on-demand working in Neon: the 20.04 version of ubuntu-drivers, common, which contains a small but important program called gpu-manager.  Without that, nothing I did could make on-demand work.

    With gpu-manager updated, on-demand now works on my Neon installation.  I can just edit the shortcuts (.desktop file type) in the application folder to make any program use the nVidia GPU instead of the Intel. It’s not as slick as in Windows, where it switches by itself when it senses the need, but I know which programs are going to benefit from the nVidia GPU and which won’t.  I’d set it up this way even in Windows (it is an option there, I seem to recall).

     

    Dell XPS 13/9310, i5-1135G7/16GB, OpenSUSE Tumbleweed
    XPG Xenia 15, i7-9750H/16GB & GTX1660ti, OpenSUSE Tumbleweed

    1 user thanked author for this post.
    Viewing 0 reply threads
    Author
    Replies
    • #2274257

      One more thing I just remembered.

      The gpu-manager program, as you can see in its log file (/var/log/gpu-manager*), looks for nVidia kernel modules in

      /lib/modules/5.4.0-38-generic/kernel/updates/dkms

      Of course, substitute the version of your kernel in place of 5.4.0-38-generic if that is not the version you are using.  You can see the list of them at /lib/modules and select the right one from there.

      The problem I found is that the /usr/sbin/dkms script detects whether a distro is Ubuntu, and if so, installs the DKMS modules (like the nVidia kernel modules) in the char/drm/ location above, but other distros, like KDE neon (it uses neon in lower case officially), will have these modules installed instead in the Linux default of

      /lib/modules/5.4.0-38-generic/kernel/drivers/char/drm/

      again, substituting your kernel version for 5.4.0-38-generic.  That means gpu-manager won’t know where to find them!

      To fix this, you can simply create copy the files from /lib/modules/5.4.0-38-generic/kernel/drivers/char/drm to /lib/modules/5.4.0-38-generic/updates/dkms (you will have to create the updates and dkms directories first).  You will have to do that for each kernel you use or install.

      You could probably also use symlinks instead of copying the files.  You’ll need to do all of this as root, of course.

      There’s a way to make DKMS build the modules into the right location for gpu-manager from the start, but I don’t know if other programs will expect the modules to be in the …char/drm location.  To do that, edit the /usr/sbin/dkms script using your text editor (root required to save), and scroll down to about line 434 and look for the list of distros and the new DKMS install paths.  You’ll see where it says “Ubuntu” and “/updates/dkms”.  You’ll need to add the name of your distro in there, and I am not really sure how to find out how any given distro identifies itself.  I added both “KDE*” and “neon*” and set both to /updates/dkms.  I then removed and reinstalled the kernel to see if it worked and to actually put the module in the new place.  It worked fine, so far.

      The putting of the modules into the new place worked, but things could go wrong as I use it. Programs may still look for the modules in the old location. I’m doing an experiment of sorts to see how that will happen, but if you are simply interested in things working, it’s best to have the modules in both places, or to use links (assuming they work, which they should).

      Note that these are somewhat advanced techniques, so if you don’t know how to do the things mentioned, it’s probably better to wait until your distro moves to 20.04 officially.  If you don’t mind possibly breaking things because you have solid backups, hopefully this will help guide you in the right direction.

      Dell XPS 13/9310, i5-1135G7/16GB, OpenSUSE Tumbleweed
      XPG Xenia 15, i7-9750H/16GB & GTX1660ti, OpenSUSE Tumbleweed

      1 user thanked author for this post.
    Viewing 0 reply threads
    Reply To: nVidia prime-select “on-demand” on Ubuntu 18.04 and related distros

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: