# Configure integrated GPU for rendering and NVIDIA GPU for CUDA works in Ubuntu 18.04

**Published:** January 1, 2020
**Tags:** Hardware, Ubuntu, CUDA

**Summary:** Set an Intel integrated GPU as the display renderer on Ubuntu 18.04 so your NVIDIA GPU's full VRAM stays free for CUDA and model training.


---

In fact, besides CUDA tasks (which could be deep neural network training), our operating system also consumes a decent amount of memory for graphic rendering. This article will guide you to use onboard graphic card for display, thereby saving a considerable amount of GPU VRAM for model training. It's especially useful when you have an NVIDIA GPU with a small memory size.

- First, you need:
  - A computer using Ubuntu or equivalent operating system. Here I use Ubuntu 18.04.
  - Your computer has an onboard graphics card (from Intel) and (of course) an NVIDIA GPU.
  - You plug the monitor cord into the graphics output port (possibly HDMI) on the mainboard instead of on the GPU card. ** You may need to configure the BIOS for the system to output the video to the HDMI port on the motherboard when booting. **

## Step 1: Install drivers for NVIDIA GPU and CUDA (optional - you can skip if you already have GPU drivers and CUDA toolkit installed)

I will guide you through [these steps](https://askubuntu.com/questions/1077061/how-do-i-install-nvidia-and-cuda-drivers-into-ubuntu/1077063#1077063) to install necessary drivers and CUDA packages.

First, open Terminal (Ctrl+Alt+t).

You need to delete the preinstalled CUDA PPA and nvidia-cuda-toolkit package. This will ensure that you can properly install the desired version of drivers:

```shell
sudo rm /etc/apt/sources.list.d/cuda*
sudo apt remove --autoremove nvidia-cuda-toolkit
```

Remove old driver (recommended)

```shell
sudo apt remove --autoremove nvidia-*
```

Update your system packages:

```shell
sudo apt update && sudo apt full-upgrade
```

Add PPA and setup key server:

```shell
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
```

Add driver repositories:

```shell
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda_learn.list'
```

Update package database again:

```shell
sudo apt update
```

And, install CUDA 10.0. Please note that, when you type the following command, the
suitable driver version for GPU is also installed.

```shell
sudo apt install cuda-10-0
```

Install cudnn package (for deep learning applications):

```shell
sudo apt install libcudnn7
```

Finnaly, you need to open `~/.profile` (using Nano: `nano ~/.profile`) and append following content:

```shell
# set PATH for cuda 10.0 installation
if [ -d "/usr/local/cuda-10.0/bin/" ]; then
    export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi
```

After this step, you will need to restart your computer and check if CUDA is installed correctly using `nvcc --version`.

## Step 2: Configure the system to use integrated GPU card for displaying and NVIDIA GPU for CUDA works

- Create file at `/etc/X11/xorg.conf` with following content (using Nano: `sudo nano /etc/X11/xorg.conf`):

```
Section "Device"
    Identifier      "intel"
    Driver          "intel"
    BusId           "PCI:0:2:0"
EndSection

Section "Screen"
    Identifier      "intel"
    Device          "intel"
EndSection
```

**Note that you have to change BusId (PCI:0:2:0) to your integrated GPU. List all graphic cards by following command: (Note that my Intel graphic card is `00:02.0`, so I use `PCI:0:2:0` for BusId.)**

```shell
lspci  | grep VGA
```

```
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630 (Desktop)
01:00.0 VGA compatible controller: NVIDIA Corporation TU106 [GeForce RTX 2070] (rev a1)
```

- Restart your workstation again to check the result.

## Step 3: Check the result

If everything goes in the right direction, after restarting the computer, your workstation will use the onboard card for rendering and NVIDIA GPU for CUDA works. Check with the following command when you are not running any CUDA work yourself:

```shell
nvidia-smi
```

If you see `No running processes found` like following figure, your system is using integrated card for displaying. You can run a training task (or any other CUDA task) to ensure that the CUDA system can still operate properly.

![nvidia-smi output](/posts-data/2020-01-01-config-igpu-for-rendering-nvidia-GPU-for-CUDA-works/2019-04-17-nvidia-smi.png)

Note that a wrong configuration in step 2 can break your system. If it happens, please reboot into [recovery mode](https://wiki.ubuntu.com/RecoveryMode) and remove `/etc/X11/xorg.conf` by using `rm /etc/X11/xorg.conf` command. Thank you for reading my post!

