linuxmint / cinnamon

A Linux desktop featuring a traditional layout, built from modern technology and introducing brand new innovative features.
GNU General Public License v2.0
4.53k stars 735 forks source link

Right clicking on apps and selecting "Run with NVIDIA GPU" not working #10026

Open sathvik987 opened 3 years ago

sathvik987 commented 3 years ago

Issue

I am running Linux Mint 20.1 Cinnamon with 5.4.0-70-generic kernel and nvidia-driver-460 on laptop with hybrid graphics (intel and nvidia). GPU Utilization in Nvidia x server settings will always be 0% when i run apps (for example celluloid) by right clicking and selecting "Run with NVIDIA GPU" but if i run celluloid with following command "__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia celluloid" then the GPU Utilization will go up. So i guess the driver is working properly but the problem is with desktop environment.

Steps to reproduce

Right click on apps and select "Run with NVIDIA GPU"

Expected behaviour

GPU Utilization in Nvidia x server settings should go up.

Mecomi commented 2 years ago

I have same problem

5p4k commented 2 years ago

By skimming quickly at the source, it seems that it will either call optirun gtk-launch:

https://github.com/linuxmint/cinnamon/blob/6e9ada17f63ffecb531cdc3fb86fcb66285cb61d/files/usr/share/cinnamon/applets/menu%40cinnamon.org/applet.js#L398

or it will call this launch_offloaded method

https://github.com/linuxmint/cinnamon/blob/66579ed9fd7d395dfd08be7643aa38ea40420da4/files/usr/share/cinnamon/applets/panel-launchers%40cinnamon.org/applet.js#L240

However, I cannot find where launch_offloaded is implemented.

As far as optirun is concerned, that is not even installed on my system. I would need to install primus, which as far as I can tell is not the recommended way to offload to the NVIDIA GPU: this debian wiki recommends to use the offload method mentioned above, i.e. exporting

__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia

Which is also what NVIDIA suggests. These exports are working perfectly on my system, while the Run with NVIDIA GPU, as far as I can tell, is no different than starting the app normally.

For context

mtwebster commented 2 years ago

app.launch_offloaded should set up the correct environment:

https://github.com/linuxmint/Cinnamon/blob/master/src/cinnamon-app.c#L1123-L1128

5p4k commented 2 years ago

You are right, I checked and it actually does. I created a desktop entry

[Desktop Entry]
Name=PrintEnv
Exec=/home/spak/PrintEnv.sh
Terminal=false
Type=Application

that launches a script that checks the environment:

#!/bin/bash
env | sort -u > /home/spak/env.log

and indeed it sets both environment variables. The app I was testing this with is Blender, but I believe I have the flatpak version of that, which might not be able to access the GPU (just guessing). So maybe it's rather a problem with the app than with the cinnamon command?

mtwebster commented 2 years ago

Flatpak programs run in a sandboxed environment, so those variables wouldn't carry over. You can add them - check this out:

https://askubuntu.com/questions/1316566/how-do-you-offload-a-flatpak-application-to-run-on-the-nvidia-graphics-card-when

5p4k commented 2 years ago

Many thanks! Blender still cannot recognize the GPU, but with the flatpak override the flags are actually propagated into blender's os.environ. But at this point I would say mine is a completely different issue.

mtwebster commented 2 years ago

@LizardM4 I've been working on fixing the original issue above, and was going to implement something to correctly modify the environment when launching flatpaks also, but from a couple of apps I tested, they seem to automagically use the nvidia gpu, so for now I'm going to skip it (and probably filter the option out of the menu for flatpaks). I tried with vlc and krita.

5p4k commented 2 years ago

@mtwebster Interesting, I'm wondering if that is because Blender specifically uses CUDA/OpenCL instead of plain OpenGL (that should be the acceleration used in Krita). I installed VLC Flatpak to try confirm, but my Intel UHD Graphics supports video acceleration too and VLC chooses to use that instead of the NVIDIA:

[00007fbdd4cbc280] avcodec decoder: Using Intel iHD driver for Intel(R) Gen Graphics - 21.4.1 () for hardware decoding

If you know of some other flatpak I could test with that displays the exact GPU it's using I can try it on my setup.

If you are going to change the menu item, maybe you can consider graying it out or issuing a warning? Simply "not finding" the "Run with NVIDIA GPU" menu item could be puzzling, since it's not obvious from the menu whether we are launching a flatpak or a regular binary.

mtwebster commented 2 years ago

Does starting vlc with this command make it use the other gpu?

/usr/bin/flatpak run  --env="__NV_PRIME_RENDER_OFFLOAD=1" --env="__GLX_VENDOR_LIBRARY_NAME=nvidia" --branch=stable --arch=x86_64 --command=/app/bin/vlc --file-forwarding org.videolan.VLC

If it does, that's a legitimate reason to add support for flatpaks in my solution.

5p4k commented 2 years ago

I tried, and in short I think that the --env switches are working, and should be there, but the VLC Flatpak specifically cannot use the acceleration because it's missing some library. I used watch nvidia-smi to monitor which processes use the NVIDIA GPU. Moreover, I think I have evidence that indeed Right click > Run with NVIDIA GPU is not working for Celluloid as @sathvik987 mentioned (although it's not clear for me why, and this seems to be specific to Celluloid). The problem seem to be related, if possible, to the name of the desktop entry of Celluloid; renaming it from io.github.celluloid_player.Celluloid.desktop to anything else makes Run with NVIDIA GPU work correctly on Celluloid too.


Here's the full VLC log from flatpak run --env=... org.videolan.VLC:

VLC media player 3.0.16 Vetinari (revision 3.0.13-8-g41878ff4f2)
[00005635c9f9b1f0] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Gtk-Message: 22:50:45.000: Failed to load module "xapp-gtk3-module"
Qt: Session management error: None of the authentication protocols specified are supported
[00005635ca02a550] main playlist: playlist is empty
[00005635ca06d470] vlcpulse audio output error: digital pass-through stream connection failure: Not supported
[00005635ca06d470] main audio output error: module not functional
[00007f3270ebaeb0] main decoder error: failed to create audio output
[00005635ca06d470] vlcpulse audio output error: digital pass-through stream connection failure: Not supported
[00005635ca06d470] main audio output error: module not functional
[00007f3270ebaeb0] main decoder error: failed to create audio output
[00007f3258002d10] gl gl: Initialized libplacebo v4.157.0 (API v157)
[00007f3258002d10] gl gl: Initialized libplacebo v4.157.0 (API v157)
Failed to open VDPAU backend libvdpau_va_gl.so: cannot open shared object file: No such file or directory
Failed to open VDPAU backend libvdpau_va_gl.so: cannot open shared object file: No such file or directory
[00007f3258002d10] gl gl: Initialized libplacebo v4.157.0 (API v157)
QObject::~QObject: Timers cannot be stopped from another thread

It's definitely different from the output that I got before, without the --env switches.

I tried watch nvidia-smi to see which processes are using the GPU, and here's what I got (I tried playing the same file in all the tests):

So in conclusion I think that the --env options to flatpak run are necessary, but unfortunately VLC is not using the GPU for decoding but just for rendering due to that missing library (memory usage is lower and the type of process is only Graphics and not Graphics+Compute).

Coming to Celluloid, at this point I tried to start several other programs from their Run with NVIDIA GPU entry, and they behaved correctly as expected:

So I figured it must be something with the desktop entry of Celluloid, and I fiddled around a bit trying to copy /usr/share/applications/io.github.celluloid_player.Celluloid.desktop to ~/.local/share/applications. Well the result I got is that whenever Run with NVIDIA GPU is used on a Desktop entry called exactly io.github.celluloid_player.Celluloid.desktop, it does not work. This works, for example:

cd /usr/share/applications
sudo mv io.github.celluloid_player.Celluloid.desktop JustCelluloid.desktop

and then Right click on Celluloid > Run with NVIDIA GPU:

|    0   N/A  N/A     54064      G   celluloid                           2MiB |

Changing the name from io.github.celluloid_player.Celluloid to anything else makes the menu item appear in boldface. The boldface menu item works, the plain one doesn't: custom Celluloid entry

Is there anything special that Cinnamon does if the desktop entry name is a "complete URI"?

mtwebster commented 2 years ago

The origin bug should be fixed now by b112fe4dd10ef98cac3.

The flatpak issue, I've found conflicting information in my searches related to this - some seem to expect that the existing offload mechanism should work, while there's very little mention of having to use --env (other than the ubuntu site I originally linked).

I'm leaving this open - I want to investigate the flatpak issue a bit more before we add the --env options to their command line.

Thanks for your help so far, the desktop file rename detail helped me discover the dbus-activation issue.

5p4k commented 2 years ago

No problem, glad it was useful!