Skip to content

Instantly share code, notes, and snippets.

@raulqf
Last active April 1, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulqf/7ceb9a5204a2b0b92bd21ac86785000f to your computer and use it in GitHub Desktop.
Save raulqf/7ceb9a5204a2b0b92bd21ac86785000f to your computer and use it in GitHub Desktop.
Installation guide for CUDA on Ubuntu distro.

How to install NVIDIA CUDA on Ubuntu distro

This is a brief receipt used for NVIDIA CUDA installation on a Ubuntu Linux Distro. All the steps can be found in the guide provided by NVIDIA but this gist contains some glue points to overcome problems during the installation.

The current installation was performed for an Ubuntu version 14.04.5 LTS, Trusty Tahr using a x86_64 architecture. You can get this information by typing in a consonle terminal:

$ uname -m && cat /etc/*release

Once you get that information we can find the NVIDIA Toolkit that supports our Linux Distro. Last version is NVIDIA CUDA Toolkit 8.0 ga2 although version 9 is already published but it does not give support for 14.04. To know what that information you must check Table 1. Native Linux Distribution Support

Now, that we know our toolkit and we have downloaded the installation guide, you only have to follow it. But we will continue with the receipt summarizing the steps. The next one is addressed in chapter 2 of the guide -> The preinstallation action where we must check:

1. Graphic Card is CUDA-Capable: Check the list of cards that can work with CUDA.

   - To know the card you have type: $ lspci | grep -i nvidia
   - Visit http://developer.nvidia.com/cuda-gpus to find your card

2. Verify your linux distro {kernel distro, gcc version, glibc} to fulfill Table 1 minimum versions
   - Check Linux -> It was done at the beginning
   - Check gcc   -> $ gcc --version 
   - Check glibc -> $ ldd --version //It will get your glibc version since this tool relies on it. 
   
   - Check the linux headers for the current linux kernel are installed
     $ sudo apt-get update
     $ sudo apt-get install linux-headers-$(uname -r)
 
 3. Download the toolkit from the https://developer.nvidia.com/cuda-toolkit-archive, since we are not using the latest version. 
 Thus, we download the .deb base installer (1.9GB) and the Patch 2(121.4MB) for ubuntu 14.04 x86_64 

The next step is the installation. There are two ways to install the toolkit. One is the distribution-independent package (standalone installer) and the other is the distribution-specific package. For future updates of the toolkit is better to select the distribution-specific pacakge. It means to download the deb file instead of the runfile as we have already done in step 3. Download the toolkit....

For the installation you must type in the terminal :

$ `sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb`
$ `sudo apt-get update`
$ `sudo apt-get install cuda`

EDIT: For newest installations you must include a public key to the repository:

$ sudo dpkg -i cuda-repo-ubuntu1604-9-1-local_9.1.85-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install cuda

Finally, we only have to perform the post-installation actions. That means to include the binary and libraries to our environment. We have done it for bash and tsch. For bash, you only have to append to your ~/.bash_rc file:

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} //64 bits
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} //32 bits

Verify the installation:

1. Check nvcc version
  $ nvcc --version

2. Compile the samples in the current.
   $ /usr/local/cuda-8.0/bin/cuda-install-samples-8.0.sh ~/cuda_samples
   $ cd ~/cuda_samples
   $ make
   
   Then execute the desired example and monitor how the graphic card works using `nvidia-settings` utility.
   ./nbody -numbodies=2000
   nvidia-settings
   
   To get information about the card
   ./deviceQuery Starting...
    CUDA Device Query (Runtime API) version (CUDART static linking)
    Detected 1 CUDA Capable device(s)
    ...

If you have any problem try updating the nvidia drivers

$ sudo apt-get purge nvidia* 
$ sudo add-apt-repository ppa:graphics-drivers
$ sudo apt-get update 
$ sudo apt-get install nvidia-3xx //Reboot your computer after installing
$ lsmod | grep nvidia  //Check status. It should not be empty

You can also download the driver from the NVIDIA website in .deb format and run the following commands:
$ sudo dpkg -i nvidia-diag-driver-local-repo-ubuntu1604-390.46_1.0-1_amd64.deb
$ sudo apt-get update
$ sudo apt-get -y install cuda-drivers

And reboot the system.

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment