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 |
+-----------------------------------------------------------------------------+
In the meantime you've found out that the HDMI port is physically connected to the nVidia adapter only, so you have to choose:
- Use CUDA and use the internal display only
- Use the external display hooked up to the HDMI port and lose the CUDA ability.
As you have a laptop, adding (an) additional card(s) is impossible as a solution.
Note: According to your Laptop's Manual you also have a Mini Display Port, but according to the MSI forums, that's also connected to the nVidia, so that's not an option neither.
Best Answer
The solution is based on this GitHub gist
Information on my system:
Step 1
Modify the GRUB configuration by editing this file:
And change:
to:
Finally update GRUB using this command:
If you want you can use the tool grub-customizer by adding the text highlighted in blue:
Restart your computer - very important!!
Step 2
Create a service that will select the Intel GPU when the computer turns off, to this end create a new file:
With this content:
Add executable rights:
And register the new service:
Step 3
Now we have ensured that when we start the computer the lightdm, gdm3, etc will use the Intel GPU since we have been enabled this GPU last time that we turned off the computer. Now we have to enable the NVIDIA GPU when we log into our account. However we need root access to do this and we don't want to prompt a window asking for a password each time we log in. To overcome this problem, we will create a command alias into the sudo configuration file.
First of all open the sudo configuration file using the following command:
Then append this content to the end of the file:
where
<your_user>
is your user name.This allows us to call prime-select without having to introduce a password.
Step 4
Add an autostart script to change the graphics card to NVIDIA once the lighdm has already started using the Intel's GPU. To this end append this command create a new file like this:
And add this content:
Restart you computer
Now you can use all the memory in your NVIDIA GPU. You can verify that by calling the command `nvidia-smi: