CUDA9 on Ubuntu 17.10

22 January 2018

This is a very brief description of my installation, but it may be useful if you’re also trying to get cuda installed on ubuntu or debian. If you have anything to add, or corrections to make, get in touch.

Before installing the cuda toolkit, you need to have a recent nvidia driver - and not nouveau. So nvidia-smi should return information about your actual card:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.42                 Driver Version: 390.42                    |
|-------------------------------+----------------------+----------------------+
| 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 106...  Off  | 00000000:01:00.0  On |                  N/A |
|  0%   42C    P2    33W / 120W |    427MiB /  6075MiB |     23%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1134      G   /usr/lib/xorg/Xorg                           133MiB |
|    0      1625      G   /usr/bin/gnome-shell                         148MiB |
|    0      2392      G   /usr/lib/firefox/firefox                       1MiB |
|    0      3764      G   /proc/self/exe                                45MiB |
|    0      4012      C   ./hellocuda                                   77MiB |
+-----------------------------------------------------------------------------+

Download your preferred version of cuda and install it. If you’re planning to use keras, TensorFlow or something similar, check the latest supported version of CUDA before this step, since they will generally lag behind a little, unless you would like to build from source and help with fixing any incompatibilities.

$ sudo dpkg -i cuda-repo-ubuntu1704-9-1-local_9.1.85-1_amd64.deb
(Reading database ... 272818 files and directories currently installed.)
Preparing to unpack cuda-repo-ubuntu1704-9-1-local_9.1.85-1_amd64.deb ...
Unpacking cuda-repo-ubuntu1704-9-1-local (9.1.85-1) over (9.1.85-1) ...
Setting up cuda-repo-ubuntu1704-9-1-local (9.1.85-1) ...

The public CUDA GPG key does not appear to be installed.
To install the key, run this command:
sudo apt-key add /var/cuda-repo-9-1-local/7fa2af80.pub

So follow those instructions - you should be told “OK”, then

sudo apt-get install cuda

And check that you have the compiler:

$ /usr/local/cuda-9.1/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

A test drive

Find some simple and self-contained cuda code - I recommend this brief hello world code for CUDA - and save as example.cu

And run it using: /usr/local/cuda/bin/nvcc --run example.cu

Since nvcc 9.1 supports only gcc6, you need to have that installed (sudo apt install gcc-6 g++-6), but if you also have gcc7 installed (and if you’re reading this, you likely do) and it is default then you will get following compilation error:

$ /usr/local/cuda-9.1/bin/nvcc --run example.cu
In file included from /usr/local/cuda-9.1/bin/../targets/x86_64-linux/include/host_config.h:50:0,
                 from /usr/local/cuda-9.1/bin/../targets/x86_64-linux/include/cuda_runtime.h:78,
                 from <command-line>:0:
/usr/local/cuda-9.1/bin/../targets/x86_64-linux/include/crt/host_config.h:121:2: error: #error -- unsupported GNU version! gcc versions later than 6 are not supported!
 #error -- unsupported GNU version! gcc versions later than 6 are not supported!
  ^~~~~

It is easily fixed by directing nvcc to use the earlier version sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gcc

cuda