Puget Systems print logo

https://www.pugetsystems.com

Read this article at https://www.pugetsystems.com/guides/1236
Dr Donald Kinghorn (Scientific Computing Advisor )

How To Install CUDA 10 (together with 9.2) on Ubuntu 18.04 with support for NVIDIA 20XX Turing GPUs

Written on September 27, 2018 by Dr Donald Kinghorn
Share:



NVIDIA recently released version 10.0 of CUDA. This is an upgrade from the 9.x series and has support for the new Turing GPU architecture. This CUDA version has full support for Ubuntu 18.4 as well as 16.04 and 14.04. The CUDA 10.0 release is bundled with the new 410.x display driver for Linux which will be needed for the 20xx Turing GPU's. If you are doing development work with CUDA or running packages that require you to have the CUDA toolkit installed then you will probably want to upgrade to this. I'll go though how to do the install of CUDA 10.0 either by itself or along with an existing CUDA 9.2 install.


Do I need to install CUDA 10?

This is an important question to ask yourself. I believe that many people do CUDA installs when they really don't need to do so. The most important thing to keep in mind is that,

CUDA GPU acceleration run-time libraries are included with the NVIDIA display driver. You do not need CUDA installed for most GPU accelerated applications.

You need to install CUDA 10 if;

  • You are doing fresh development work writing low level CUDA kernels and need access to nvcc, AND you want to build on the latest platform with support for NVIDIA's new Turing GPU's.
  • You are recompiling existing packages and want to link in the most recent libraries. For example, if you are doing a TensorFlow build from source and want to try the latest GPU support.
  • You want to use a software package that explicitly states that you need to have the CUDA "toolkit" installed. Most GPU accelerated software does not require a CUDA install.
  • You just can't stand the thought of not having it installed on your system because you might want to try messing with it. Hey, that's OK, I understand that!

You do NOT need to install CUDA 10 if;

  • You are a developer working with CUDA 9.x or earlier in your code base and there are no compelling new features that you want to risk breaking your application to try. See the release notes.
  • You are working with Python machine learning frameworks AND using Anaconda Python. Most of the frameworks have up-to-date builds available from Anaconda Cloud that include the needed CUDA libraries i.e. you don't have to install anything outside of the package you want.
  • You are using GPU accelerated software packages that only depend on CUDA run-time support from the display driver. That includes most "ready to use" or commercial software.
  • You don't know what CUDA is. In that case then, well, thanks for reading my post. I hope you enjoy it and learn something from it.

Can I install CUDA 10 on a system that already has CUDA 9.2 installed?

Yes! CUDA 10.0 is the first CUDA release with official support for Ubuntu 18.04. Many people have followed my guide, How to install CUDA 9.2 on Ubuntu 18.04. That is a good general guide for doing a CUDA install. If you are doing a fresh CUDA install you may want to have both 9.2 and 10.0 installed at the same time. You can do that. Use the guide linked above to get CUDA 9.2 working.

We could almost do the same thing that I did in the 9.2 guide for CUDA 10, but, there is one problem (at least at the time I am writing this). The problem is that the NVIDIA driver needed for CUDA 10.0 is version 410 or greater. That driver is in beta right now and the ppa's have not packaged it yet. That means you would have to do a "raw" install of the driver from NVIDIA's base package. That's something you can do but I generally don't recommend it unless you really understand what you are doing. That's because you can run into configuration and dependency problems that can make a mess on your system that is hard to fix and maintain. I highly recommend sticking with ppa's, or, what I'm going to do below.


Steps to install CUDA 10.0 on Ubuntu 18.04

Step 1) [Optional] Install CUDA 9.2 if you want to have both that and CUDA 10.0 on your system.

[If you don't have Ubuntu 18.04 installed yet then see my note at the end of this step.]

If you want to have CUDA 9.2 along with CUDA 10.0 then it might be best to install 9.2 first. You can follow my guide, How to install CUDA 9.2 on Ubuntu 18.04. You don't strictly have to install 9.2 first but it might be less confusing if you do. That guide for the 9.2 install is pretty general, and is a safe way to install older versions of CUDA (but don't down-grade your display driver if you have a newer version!). The only real change from that guide will be where you get the "run" file. It will now be in the "Legacy Releases" section of the CUDA download site.

CUDA Legacy

Once you have the CUDA 9.2 "run" file from the 17.10 Ubuntu release the rest of my guide linked above should get you a working CUDA 9.2.

Note: If you are doing a "clean" OS install of Ubuntu 18.04 then you might want to look at The Best Way To Install Ubuntu 18.04 with NVIDIA Drivers and any Desktop Flavor.

Step 2) Install CUDA "dependencies"

There are a few dependencies that are good to install first since they don't always get pulled along with a CUDA install from the "deb" file.

You will certainly need the build-tools and dkms,

sudo apt-get install build-essential dkms
sudo apt-get install freeglut3 freeglut3-dev libxi-dev libxmu-dev

Those packages will get the needed GL, GLU, Xi, Xmu libs and several other libraries that will be installed as dependencies from those.

Step 3) Get the CUDA 10 "deb" file to set up the package repository

Go to the CUDA Zone and click the Download Now button. Then click the link buttons until you get the following,

CUDA download

Notice those 18.04 16.04 14.04 buttons! Nice! I am using the [deb (network)] file for the install. When you run that it will setup the apt repository configuration on your system. Then when you do the CUDA install it will pull the packages from NVIDIA over the network. You can use the [deb(local)] file if you want to download the entire repository to your system. That can be useful if you want to install on multiple machines or want stricter version control against updates.

Step 4) Do the install!

The instructions listed in that image above are what you should do.

sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub


sudo apt-get update
sudo apt-get install cuda

This will pull down and install all of the CUDA 10 packages along with dependencies AND the 410 NVIDIA display driver.

Now reboot. When your system restarts you will be running the NVIDIA 410 display driver and have CUDA 10 installed in /usr/local.

Step 5) Setup your CUDA environment

First look at /usr/local to see what you got from the install.

kinghorn@u18:~$ ls -l /usr/local/
...
lrwxrwxrwx  1 root root    9 Sep 26 09:28 cuda -> cuda-10.0
drwxr-xr-x 16 root root 4096 Sep 26 09:27 cuda-10.0
drwxr-xr-x 19 root root 4096 Sep 25 19:59 cuda-9.2
...

Notice that the CUDA 10 install created a symbolic link from /user/local/cuda to the cuda-10.0 directory.

Checking nvidia-smi you will see the new driver is running.

kinghorn@u18:~$ nvidia-smi
Wed Sep 26 13:32:50 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.48                 Driver Version: 410.48                    |
|-------------------------------+----------------------+----------------------+
| 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 1070    Off  | 00000000:01:00.0  On |                  N/A |
|  0%   49C    P8    11W / 151W |     42MiB /  8116MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0       934      G   /usr/lib/xorg/Xorg                            39MiB |
+-----------------------------------------------------------------------------+

That is my old Puget Systems Peak Mini with a GTX 1070 in it, not my wonderful new Peak Single that has a 1080Ti and Titan V in it ... and will soon have an RTX 2080Ti Turing GPU in it! (I will be doing the CUDA install in this post on my new system too. I tested the install on the older machine.)

How to setup environments for both CUDA 9.2 and 10.0

In this section I'll go through a convenient way to setup your environment for "personal" use. This will be easy for switching back and forth between the CUDA versions if you want to do that. For a "system wide" multi-user environment that is configured automatically on login. Have a look at the post for installing CUDA 9.2 on Ubuntu 18.04.

To make it easy to switch back and forth between CUDA 10 and 9.2 you can make the following files,

cuda9.2-env

export PATH=$PATH:/usr/local/cuda-9.2/bin
export CUDADIR=/usr/local/cuda-9.2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.2/lib64

cuda10.0-env

export PATH=$PATH:/usr/local/cuda-10.0/bin
export CUDADIR=/usr/local/cuda-10.0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64

You can put these files anywhere you want. I out them in ~/misc/ i.e. misc in my home directory.

You would use (and check) these like this,

kinghorn@u18:~/projects$ source ~/misc/cuda10.0-env

kinghorn@u18:~/projects$ env | grep -i cuda
LD_LIBRARY_PATH=:/usr/local/cuda-10.0/lib64
CUDADIR=/usr/local/cuda-10.0
PATH=/home/kinghorn/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda-10.0/bin

kinghorn@u18:~/projects$ source ~/misc/cuda9.2-env

kinghorn@u18:~/projects$ env | grep -i cuda
LD_LIBRARY_PATH=:/usr/local/cuda-10.0/lib64:/usr/local/cuda-9.2/lib64
CUDADIR=/usr/local/cuda-9.2
PATH=/home/kinghorn/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda-10.0/bin:/usr/local/cuda-9.2/bin

We'll use these scripts in the testing section below.

Step 6) Test CUDA by building the "samples" from source for both CUDA 9.2 and CUDA 10.0

I'll create a cuda-testing directory in my projects directory and then copy the sample directories from both version of CUDA.

kinghorn@u18:~/projects$ mkdir cuda-testing
kinghorn@u18:~/projects$ cd cuda-testing/

kinghorn@u18:~/projects/cuda-testing$ cp -a /usr/local/cuda-10.0/samples samples-10.0

kinghorn@u18:~/projects/cuda-testing$ cp -a /usr/local/cuda-9.2/samples samples-9.2

kinghorn@u18:~/projects/cuda-testing$ ls
samples-10.0  samples-9.2

Now set the environment and build the samples,

kinghorn@u18:~/projects/cuda-testing$ cd samples-9.2/
kinghorn@u18:~/projects/cuda-testing/samples-9.2$ source ~/misc/cuda9.2-env
kinghorn@u18:~/projects/cuda-testing/samples-9.2$ make -j 4

You will see compile lines that start with,

/usr/local/cuda-9.2"/bin/nvcc -ccbin g++  ...

Now lets do that with CUDA 10.0,

kinghorn@u18:~/projects/cuda-testing/samples-9.2$ cd ../samples-10.0/
kinghorn@u18:~/projects/cuda-testing/samples-10.0$ source ~/misc/cuda10.0-env
kinghorn@u18:~/projects/cuda-testing/samples-10.0$ make -j 4

This time the compile lines start like,

/usr/local/cuda-10.0/bin/nvcc -ccbin g++  ...

To finish up here's a screenshot of two copies of "nbody" running on this system. One built with CUDDA 10.0 and the other built with CUDA 9.2.

nbody builds from CUDA 9.2 and 10.0

It looks like CUDA 10.0 is a great release. Check out the release notes to see some of the new features and changes in CUDA 10.0

Happy computing! --dbk

Tags: CUDA, NVIDIA, GPU, Ubuntu
Mark

Hi, I'm pretty new to CUDA and Ubuntu - you're tutorial really saved me a lot of stress, thank you! CUDA 10 runs perfectly however I need CUDA 9.2 for compatibility with a speech synthesis toolkit I am using. When I try and install CUDA 9.2 (following your guide and others) I run into all sorts of problems that result into a broken install. I end up removing all remnants of CUDA and starting again. This is frustrating, I would like both versions, but 9.2 has only given me trouble. I am running Ubuntu 18.04, and would appreciate any help you can offer to install CUDA 9.2 robustly on top of CUDA 10 in a way I can access both (as suggested in this tutorial). Thanks, Mar

Posted on 2018-10-05 15:47:04
Donald Kinghorn

Hi Mark, Really I wrote this for people in your situation. I'm really sorry it didn't go well! The biggest trick in doing a setup with multiple cuda version is knowing what the installers are doing. However, if you are new to CUDA then how would you know that! Here's some ideas try again and post back if you run into trouble myself or others reading the posts may be able to help.

Try this;
First do the install of cuda 10 as in this post. That will
install the 410 driver,
it will install package dependencies for cuda,
it will put the cuda toolkit in a directory /usr/local/cuda-10.0,
and create a symbolic link from that directory to /usr/local/cuda.
It should also create /etc/ld.so.conf.d/cuda-10-0.conf which adds a path for the system linker /usr/local/cuda-10.0/targets/x86_64-linux/lib

That's your cuda 10 setup and if you use the source the environment script like I have in this post then all of that will bi on your path and ready to go... Reboot and test your CUDA 10 build by compiling the samples.

Now for 9.2,
Grab the 9.2 ".run" file for Ubuntu 17.10 from the cuda archives along with the .run file for "Patch 1". Then go to step 4) in the post about installing 9.2,
sudo sh cuda_9.2.88_396.26_linux.run

Now here is where you have to be careful! I'm going to put a copy of the answers to the questions the installer asks here,

You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: y

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 396.26?
(y)es/(n)o/(q)uit: n

Install the CUDA 9.2 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
[ default is /usr/local/cuda-9.2 ]:

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: n

Install the CUDA 9.2 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
[ default is /home/kinghorn ]: /usr/local/cuda-9.2

The 2 key things are saying no to installing the driver and saying no to adding the symbolic link. (you could do that but I would suggest you just leave the link pointing at cuda 10 )

You should also install the cuBLAS patch
sudo sh cuda_9.2.88.1_linux.run

That's it! What you will have is the cuda 9.2 toolkit installed in /usr/local/cuda-9.2

Note: this might overwrite the linker path in /etc/ld.so.conf.d/ hopefully is just adds another file for cuda-9.2 However, you don't even really need to keep those files in there for the linker if you use the environment script to set your PATH and LD_LIBRARY_PATH when you work on a project.

Really this should work. Key things to keep in mind: The "run-time" libraries for CUDA applications are contained in the display driver and that should support all older cuda versions. When you are building CUDA code you need to have your local shell environment pointing to the correct cuda toolkit. You will be using nvcc and the libs in that toolkit directory. So, set your environment with by running "source" on the appropriate script that I have in this post and then check your environment with the "env" command. When you run env you should see that the proper version of cuda is on your PATH and LD_LIBRARY_PATH. Then you should be set to do a code build. But, the code you are building needs to have any makefile environment set correctly too. You should be able to build the cuda 9.2 samples from the makefile included with then after you have set your environment.

There! I think this is good to have here in the comments. It makes the post better. If this doesn't work and you run into issues post them back here ... Best wishes Don

Posted on 2018-10-05 17:25:44
Mark

Hi Don,

Thank you so much for such a detailed and helpful reply!

I have followed your installation steps for CUDA-10.0 and whilst I can successfully test the samples, no cuda dir is made in /usr/local/ and therefore there is no symlink from cuda-10-0 pointing there - will that be problematic?

Thanks,

Mark

Posted on 2018-10-08 08:57:10
Mark

Hi Don,

The instructions you gave me (missing cuda dir or not) seemed to have done the trick!

Thanks so much,

Mark

Posted on 2018-10-08 09:39:09
Donald Kinghorn

good! glad you got it working. the link is just "convenience" It really is probably best to set environment vars for the exact version you want. The one thing to keep in mind is that on occasion you may run into a program that has a hard coded path to /usr/local/cuda. You can manually add (or change) the link with, for example,

sudo ln -s /usr/local/cuda-10.0 /usr/local/cuda

you can remove the link wihtout affecting what it is linked to i.e.
sudo rm /usr/local/cuda just removes the link itself

Posted on 2018-10-08 17:50:14
oguz canbek

Hi Don,

Thanks for the detailed article but I seem to have a problem when I try to install CUDA 10.0 with the command "sudo apt-get install cuda" I get the following error:

" E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages. "

Attached you can also find the whole output of the install command.

https://uploads.disquscdn.c...

I don't know what I can try to do. I am both an Ubuntu and CUDA newbie. As GPU, a have a notebook model GeForce 1060M. If you have any advice you can share with be that would be great! Thank you very much in advance,

Oguz

Posted on 2018-10-09 12:15:32
Donald Kinghorn

Oh yuk! I hate those dependency errors and held package stuff. I have run into that before from various problems. I have even backed out completely and reinstalled OS to fix it. I don't think you will have to do that.

First make sure that you are actually seeing the cuda 10 repo. There should be a file /etc/apt/sources.list.d/cuda.list that has an entry for the Ubuntu 18.04 repo Then be sure that you have run sudo apt-get update

You are getting dep errors related to the 396 driver but cuda 10 will be installing the 410 driver ??? I can't really advise you very well on this because I'm not really sure what the system state is. You could try to update or reinstall the older 396 driver and see if dep tree gets repaired and then try the cuda 10 install again. You may have to purge the old 396 driver too ???

Before you do anything else make sure you have important data and directories backed up somewhere. Check your cuda repo, they to update your old driver, and then you could also try doing sudo apt-get install -f to "fix" the failed install sometimes that works If you are still having trouble after that then I suggest searching around the web for some of those exact lines that have the "Depends:" error ... that would be what I would be doing.

I wish I had better advise for you!

Posted on 2018-10-09 22:37:07
vnktmvv

Thank you very much. This article helped me get started with cuda development.

Posted on 2018-10-23 03:43:37
Gustaf Sundberg

Hi great article. I got it working on my new RTX 2080. (I have been doing approx 10 install trying to get tensorflow-gpu and keras working, but it complains about libcublas.9.0). I have seen you did a lot of tensorflow stuff, what are the approximate steps to continue from here to get tf and keras installed? I assume installing cudnn-10 and libcupta and then tensorflow-gpu

Thanks for the great article!

Posted on 2018-10-28 13:34:32
Donald Kinghorn

Honestly, my recommendation is to use Anaconda Python and use TF and Keras from their builds. The following post would be a good guide for that,
https://www.pugetsystems.co...

That post is a little bit out of date but you should be OK since you have the new driver from doing the CUDA install. I need to do a refresh on this stuff myself, I've been doing hardware testing and working with PyTorch. I haven't had TF fired up except running in docker containers for the hardware testing posts.

Posted on 2018-10-29 21:23:32
Jingning

This new graphic card has troubled me for two days for initial setup but luckily I found your blog to help me getting going. I went through driver installation from ppa (using sudo apt-get install nvidia-driver-410) and directly download 410 driver and install. Neither worked. Thank you for the great article!

Posted on 2018-11-02 02:15:25
Mi Cha Ga

Hello all, i installed the tensorflow-gpu nightly build tf-nightly-gpu 1.13.0.dev20181113 from https://pypi.org/project/tf... and everything works fine now. Tensorflow detects my 2080 Ti and i was able to train all my nets with that step.

Here is my setup:
CUDA 10.0
cudNN 7.4.1 for CUDA 10.0
nvidia display driver 410.48
Tensorflow 1.12

This was the easiest workaround for me because you dont have to build tensorflow-gpu from bazel.

Posted on 2018-11-15 15:01:05
Donald Kinghorn

Great! Thanks for posting that!

Posted on 2018-11-15 17:20:28