0

There are one Intel integrated graphics and the other Nvidia graphics card in my remote box, where OpenSSH and X11 servers run on Ubuntu Desktop 24.04. The graphics drivers and utils are installed properly as well.

$ lshw -c video
*-display
  configuration: driver=nvidia
*-display
  configuration: driver=i915

$ nvidia-smi -L
GPU 0

$ prime-select 
Usage: /usr/bin/prime-select nvidia|intel|on-demand|query 

$ prime-select query 
on-demand

I think that the term on-demand means my card enabled by Nvidia Optimus. However, it is not listed in the supported GPUs mentioned by the Debian Wiki. The list shows there're totally 3 pages, but it remains on page 1 full of old GPUs, no matter I click on next pages using the latest Chrome browser.

My first question is whether the poorly maintained web page indicates that the Optimus is rather a default feature enabled for all the recent GPUs now, although Nvidia previously promoted it as a selling point for some of old GPUs.

My second question is how to adjust the environmental variable DISPLAY for X11 server (preferably configured in the ~/.bashrc file on the remote box) to follow the on-demand (ie. dynamically switched) graphics between the integrated and dedicated ones. My use case is that I ssh from the local terminal console to the remote box aforementioned, occasionally I need run X11 programs and display graphics on the remote box.

Please note that I don't ssh -X (ie. nothing to do with X11 forwarding) for the local SSH client runs on a terminal console without X11.

1
  • This is a cross post from askubuntu.com/questions/1518386. It's casted a downvote without words and called to close over there. Afraid it sinks forever without attention, so post it here again for helpful comments and answers. Thanks!
    – sof
    Commented Jun 23 at 3:24

1 Answer 1

2

Nvidia Optimus is part ACPI (to provide a way to command GPU to power off), part hardware (to facilitate switching the GPU power on/off while the system is running) and part display drivers (to deal with a GPU that can completely power off and later return in a completely reset state). It is essentially a default feature on all modern dual-GPU systems where the discrete GPU is a Nvidia one.

So you need the X11 graphics to display on the remote box?

In that case, the X11 server on the remote box needs to load both the nvidia and the i915 drivers, and then perhaps tie them together using xrandr --setprovideroutputsource options. The DISPLAY variable should be set to :0 as both GPUs will be treated as parts of a single display.

Unfortunately, there are some limitations and there may be a few more steps to take before you can actually use such a configuration.

First, because of the way the X11 server is designed, it apparently cannot be quite fully "dynamically switched" yet. You must select one of the other GPU as the primary one. Then, the other GPU can be used either as an "output extender" for the primary GPU (providing more display output connectors), or as a "rendering booster processor" for it.

If you're using the non-Nvidia GPU as the primary one (the common configuration on laptops, as the other GPU is usually directly connected to the laptop's integrated display for minimum energy consumption when running on battery), but the xrandr --listproviders shows the Nvidia GPU as a second provider, then you can just set a pair of environment variables for a program to make it use the Nvidia GPU for rendering its graphics:

export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia

But if you need to use a display that is physically connected to the Nvidia GPU's output connectors and is not directly accessible by the other GPU, then the Nvidia GPU needs to stay powered up anyway, so you might as well make it the primary one.

If you don't want to do that (e.g. if you want to use the display and the associated GPU only occasionally), then you can tell the Nvidia GPU to receive output from the other GPU with two commands like:

xrandr --setprovideroutputsource NVIDIA-G0 modesetting
xrandr --auto

This is what Nvidia calls "Reverse PRIME", or using the Nvidia GPU as a pass-through for graphics rendered in the other GPU.

However, a full-screen application using the render offload environment variables mentioned earlier will still get rendered natively on Nvidia GPU, skipping the iGPU. This is called "Reverse PRIME Bypass" by Nvidia, and it requires the full-screen application is visible only on a single display connected to the Nvidia GPU.

If you decide to make the Nvidia GPU the primary one, but would still want to use the display outputs of the other GPU, you'll need to set up the link between the GPUs in the other direction:

xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

In each case, the xrandr commands should probably go into your .xinitrc (if you use startx) and/or into /etc/X11/Xsession.d/<something> script (if you use a X Display Manager). The render offload environment variables you can place wherever you want, depending on if you want the render acceleration on all X11 applications you run, or just on some of them.

I don't have access to the newest Ubuntus at the moment, but as I've understood, the prime-select just provides a few basic configurations: Nvidia GPU only, the other GPU only, and "on-demand" which is essentially a requirement for all I've described above.

Depending on your hardware configuration and the versions of the Nvidia driver and the X server, you might need to add some configuration to /etc/X11/xorg.conf.d/ to allow the X server to start up both drivers even though only one of them has a display attached: for examples, see chapters Offloading Graphics Display with RandR 1.4 and PRIME Render Offload in the README.txt file of the Nvidia driver. It might be available on your system as /usr/share/doc/NVIDIA_GLX-1.0/README.txt.

You should probably start by connecting to the remote system, making sure the X11 subsystem is running there, setting DISPLAY=:0 and then running xrandr --listproviders. If it already lists two providers, then either your driver/X server versions are new enough that both GPUs get auto-detected for dual-GPU use, or Ubuntu has already pre-setup that part for you.

If not, then the first step is to adjust your configuration so that the command will indicate two providers; before that essential step is completed, nothing I described above will work.

2
  • Thanks a lot for your concrete analysis and proposed solution in depth, @telcoM!
    – sof
    Commented Jun 23 at 12:35
  • It seems to me that it is much more challenging yet tedious task to achieve my use case than expected. In addition to the mixture of concerns you've described among "Optimus", "X11" and "SSH", for the GPU with "on-demand" mode I also receive the error "Authorization required, but no authorization protocol specified" if I test something simply like "ssh user@remote DISPLAY=[:0|:1] xclock", while for the GPU with "intel" or "nvidia" mode the test just works. I'd retract my initial anticipation, turn down power saving and pin the mode to "nvidia" for now.
    – sof
    Commented Jun 23 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .