# Ubuntu 18.04: intel gpu for display & nvidia one for cuda
###### tags: `igpu`, `cuda`, `nvidia driver`, `dual gpus`
## TL;DR
### After Ubuntu 18.04
Make sure nvidia drivers is installed.
1. sudo prime-select nvidia
2. sudo vim /etc/default/grub
```bash=
# Add "nogpumanager"
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nogpumanager"
```
3. sudo update-grub
4. create /etc/X11/xorg.conf
```bash=
Section "Device"
Identifier "intel"
Driver "modesetting"
BusID "PCI:0:2:0"
EndSection
```
5. sudo reboot
### Before ubuntu 18.04
After installing nvidia driver (Full package, not headless drivers), you can follow the steps below to set up the environment.
1. sudo prime-select intel
2. sudo reboot
3. sudo vim /lib/modprobe.d/blacklist-nvidia.conf
```bash=
# blacklist nvidia
blacklist nvidia-drm
# blacklist nvidia-modeset
# alias nvidia off
alias nvidia-drm off
# alias nvidia-modeset off
```
4. sudo update-initramfs -u
5. sudo reboot
6. nvidia-smi
```bash=
Tue Apr 2 09:46:59 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.54 Driver Version: 396.54 |
|-------------------------------+----------------------+----------------------+
| 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 105... Off | 00000000:01:00.0 Off | N/A |
| N/A 45C P0 N/A / N/A | 0MiB / 4042MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
```
## 4 ways to set up this environment
### A. Install nvidia-headless-XXXX driver
According to [launchpad](https://launchpad.net/ubuntu/bionic/amd64/nvidia-headless-390), this metapackage installs the NVIDIA driver and the libraries that enable parallel general purpose computation through CUDA and OpenCL but doesn't support X11 or Wayland. Follow the steps in this [page](https://gist.github.com/wangruohui/bc7b9f424e3d5deb0c0b8bba990b1bc5#12a-install-from-ppa-repository). I tried this approach but bumped into black screen or login loops. If you also have this problem, try Method B or C.
### B. Install the full nvidia drivers and un-blacklist nvidia & nvidia-modeset
**This approach assumes you've installed Nvidia drivers in your system,** that is, you can run prime-select and cuda smoothly. Basically you just need to modify blacklist-nvidia.conf. Please find this file in your system. I've checked these locations:
- /etc/modprobe.d/
- /usr/lib/modprobe.d/
- /lib/modprobe.d/
Once you find the file, comment out the lines related to nvidia & nvidia-modeset. For the detailed steps, please refer to [TLDR](https://hackmd.io/DJysvzGOSpWCyWsY3fbK5A?both#TLDR).
ref [page](https://forums.fast.ai/t/successful-ubuntu-18-04-with-igpu-for-xserver-and-nvidia-gpu-for-cuda-work-setup/20128/9)
### C. Use wayland
You can use wayland directly. Check the 2nd answer in this [page](https://askubuntu.com/a/1090443). However Displaylink currently doesn't support wayland, so if you use displaylink to expand to your monitors, like me, you need to use Method B.
### D. add nogpumanager & Xorg.conf
Please check steps in [TLDR](https://hackmd.io/DJysvzGOSpWCyWsY3fbK5A?both#TLDR)
ref. [page](https://devtalk.nvidia.com/default/topic/1043405/linux/ubuntu-18-04-headless_390-intel-igpu-after-prime-select-intel-lost-contact-to-geforce-1050ti/post/5293003/#5293003)
## No need to install cuda after installing Nvidia driver
Check [here](https://forums.fast.ai/t/successful-ubuntu-18-04-with-igpu-for-xserver-and-nvidia-gpu-for-cuda-work-setup/20128/12).
## Other questions
Please check the links listed below, especially the first one.
https://forums.fast.ai/t/successful-ubuntu-18-04-with-igpu-for-xserver-and-nvidia-gpu-for-cuda-work-setup/20128/9
https://askubuntu.com/questions/1105570/black-screen-after-installing-nvidia-drivers-390-410-415-for-geforce-1050-ti
https://wiki.archlinux.org/index.php/NVIDIA#DRM_kernel_mode_setting
https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-390/+bug/1774359
https://bugs.launchpad.net/ubuntu/+source/bumblebee/+bug/1438106