I (creator of this post) found the solution I need on my own!
I will now explain the solution for anybody else who is in a similar situation and needs this help!
SOLUTION:
INSTALL THE NVIDIA DRIVER VIA THE RUNFILE PROVIDED AT http://www.nvidia.com/object/unix.html WITH THE FLAG "--no-opengl-files" !!
This prevents not only the nvidia opengl files from overwriting the existing mesa files but also installs the driver without nvidia prime!!
So all of my problems are solved, simply by installing the driver manually, instead of installing it from the repositories. The package from the repositories is "Optimus-Friendly" and therefore has all the useless troublemakers bundled with it.
SECONDLY
the xorg.conf has to be extended with another screen for the dedicated GPU(s) so that it/they has/have entries in nvidia-settings.
mine looks like this
Section "ServerLayout"
Identifier "Layout0"
Screen 0 "intel" 0 0
Screen 1 "nvidia550ti" 3000 0
EndSection
Section "Device"
Identifier "intel"
Driver "intel"
BusID "PCI:0@0:2:0"
EndSection
Section "Device"
Identifier "nvidia550ti"
Driver "nvidia"
BoardName "GeForce GTX 550ti"
BusID "PCI:2@0:0:0"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
Section "Screen"
Identifier "nvidia550ti"
Device "nvidia550ti"
Option "AllowEmptyInitialConfiguration" "on"
Option "Coolbits" "4"
Option "ConstrainCursor" "on"
EndSection
Before starting I recommend to install ssh in order to be able to shutdown the system remotely if something goes wrong. To do so use this command:
sudo apt-get install ssh
and to shutdown your system you have to ssh with another computer or mobile device and use this command:
sudo shutdown -r now
Step 1
First of all you have to remove the AMD card physically, keep your NVIDIA card and install CUDA and the NVIDIA driver. You can download cuda from here: https://developer.nvidia.com/cuda-downloads
Make sure that all is working using this command:
nvidia-smi
Step 2
At this point we have to modify grub in order to start in console mode since we are messing with graphic cards.
Using your favorite editor (in my case joe) edit the default grub configuration file:
sudo joe /etc/default/grub
And change these lines:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
#GRUB_TERMINAL=console
to these ones:
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX="text"
GRUB_TERMINAL=console
Finally update grub using this command:
sudo update-grub
Step 3
Shutdown your system and remove the NVIDIA card and plugin the AMD card. Turn on your computer and install the latest AMD graphic drivers. In my case I installed the drivers using these commands:
wget https://www2.ati.com/drivers/linux/ubuntu/amdgpu-pro-16.40-348864.tar.xz
tar -Jxvf amdgpu-pro-16.40-348864.tar.xz
cd amdgpu-pro-16.40-348864/
./amdgpu-pro-install
sudo usermod -a -G video $USER
Restart your computer. Now you can start lightdm (the user interface) using this command:
sudo service lightdm start
All should work as expected and now you can setup your displays using the system settings.
Step 4
Shutdown your system and now add your NVIDIA card and do not remove the AMD (at this points you will have two graphic cards in your system). Turn on you computer and log in using your user name but DO NOT START LIGHTDM!!
At this point the gpu-manager has automatically setup both graphic cards for the console mode and only AMD for lightdm (since we started lightdm in the previous step). If we run lightdm at this point gpu-manager will make a mess. So now we have to completely disable the gpu-manager. To this end we have to modify grub again:
sudo joe /etc/default/grub
and replace these lines:
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX="text"
GRUB_TERMINAL=console
by these ones:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nogpumanager"
GRUB_CMDLINE_LINUX=""
#GRUB_TERMINAL=console
Finally update grub using this command:
sudo update-grub
Step 5
Restart your system and if the lightdm do not start correctly (it appears a black screen) then you have to press Ctrl+F1, login in console mode and add this command to the rc.local file:
sudo joe /etc/rc.local
add this line before "exit 0":
service lightdm start
restart your system and all should work fine now ...
In a console you can check that both graphics cads are in use using this command:
lspci -nnk | grep -i vga -A3 | grep 'in use'
Kernel driver in use: amdgpu
Kernel driver in use: nvidia
and nvidia-smi should work fine. showing that you are using 0 megabytes of memory:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.26 Driver Version: 375.26 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 970 Off | 0000:02:00.0 Off | N/A |
| 30% 42C P0 36W / 163W | 0MiB / 4036MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
Best Answer
After discovering the questions and answers here How to configure iGPU for xserver and nvidia GPU for CUDA work, notably the answer of user890178, and studying the syslog I finally found that it is not plasma that does anything specific but the problem is the same for gnome and plasma shell when using Xorg. With Xorg the gpu-manager.service
is triggered by the display-manager
and gpu-manager detects nvidia and writes the file
which contains
This file is not used by Wayland and so the nvidia card is not used, but it is used for gnome-shell on ubuntu and plasma. So in fact both will use the nvidia card for Xorg.
The solution is then a variation of the answer of Maksym Ganenko in the same question above which means is replacing /usr/share/X11/xorg.conf.d/11-nvidia-prime.conf by
and additionally to avoid gpu-manager to replace these changes when starting the next session to follow the advice of Oren in question gpu-manager overwrites xorg.conf to protect the file against changes by means of running
I seems that the fact that the screen remained black after the adding the two files I mentioned in the question to /etc/X11/xorg.conf.d is due to the fact that with the files in /usr/share/X11/xorg.conf.d that the config file did contain contradicting information.
Given the comment of GabrielaGarcia that astonishingly made the claim that what I ask cannot work on a laptop, I feel the necessity to provide a prove, that what I asked can work, and that the answer I provided is indeed a means to make it work.
Here the output of lspci proving the existence of two graphics cards
Here the output of
ps aux
filtering the Xorg, plasma, and anaconda python running a tensorflow session. This shows that all run happily together, while plasma and Xorg do not use the nvidia card as desired (see nvidia-smi below)Here the output of nvidia-smi proving that Xorg is not using nvidia, but the tensorflow session in anaconda python is suing it.
I am ready to provide screenshots to show that all this happens on a laptop.