I’ve been building neural networks for my chemical space deep learning research since last year. Speedup of training is always one of the central topics. Recently my research group purchased a Quadro K2200 for our Red Hat workstation. I thought it’s a good opportunity of accelerating the computation by switching to GPU. The benefit detail for my research projects will probably be covered in later posts.

Today I’m going to focus on how to smoothly install the two important tools for any neural network applications to run on GPUs: CUDA and cuDNN. I noticed there’s serveral installation guides online, e.g., NVIDIA official guide, AWS EC2 guide 1 and AWS EC2 guide 2. They either are outdated, missing some key steps or contain unneccessary settings. More importantly for beginners, we want to have some tests to see each major step is gone though correctly and neccessarily.

For this purpose I decided to create this post, whose goal is to install CUDA and cuDNN on Red Hat Enterprise Linux 7 in a more transparent and reasonable way.

Just to emphasize, my situation was:

• I could easily install theano/tensorflow/keras through anaconda binary platform,

• my application can already successfully run on CPUs,

• I only need to make theano/tensorflow/keras detect there’s GPU available

Test Examples Prep

I prepared two python test scripts: example_1 is from theano official documentation, which is easy and fast to test whether we have connected to GPU. example_2 is from keras example cifar10_cnn, which will be used to final check the speedup brought by GPU. Below is the detail of example_1 script.

Python Anaconda Environment Setup

One command can create a conda environment with: theano. Just run on your terminal:

Status of test examples: able to run on CPUs but not GPUs

At this point, we’ll run example_1 script (no need to run example_2) to make sure example_1 can run on CPUs but not on GPUs.

Run example_1 on CPU mode:

Result of example_1 for CPU mode:

Run example_1 on GPU mode:

Result of example_1 for GPU mode:

Installation of CUDA Toolkit and Driver

This part is well documented by NVIDIA official guide except that some small steps are either too brief (can be not so actionable) or outdated. This post will cover all the commands step by step in an actionable way, for detailed explanations one can always refer to the official guide.

Pre-installation Actions

This step is 100% following NVIDIA official guide: Pre-installation Actions. First run the following commands to verify system requirements are met:

Now you go to NVIDIA CUDA Toolkit Downloads. Below is what I chose for my Red Hat EL7 machine. It’s a fresh installation so I didn’t have to deal with conflicting previous installations. But for people having previous CUDA installation, please refer to Handle Conflicting Installation Methods.

Package Manager Installation

As I mentioned early, I chose to download the rpm(local) installer option, so I need to use package manager installation. This step we’ll following 80% of the NVIDIA official guide: Package Manager Installation and add/modify some steps I regard neccessary but not clear in the official guide.

For users choosing runfile, please refer to Runfile Installation.

Post-installation Actions

You only need to add /usr/local/cuda-8.0/bin (version number can vary, please check) to your PATH environment variable (either by doing as in below or put into your .bashrc file).

To verify GPUs can be accessed, three small steps are needed

• restart the machine

• verify the driver version by running cat /proc/driver/nvidia/version

• run deviceQuery cuda sample binary, in steps as follow

Here’s what you’ll get after running deviceQuery:

Status of test examples: able to run on GPUs but cuDNN complaints

Run example_1 on GPU mode:

Result of example_1 for GPU mode:

Hooray! example_1 is able to access to GPU Quadro K2200 and the wallclock has been reduced by a factor of 8 (from 4.15 sec to 0.53 sec.)

But also it shows that cannot find -lcudnn, which will be our next installation part: cuDNN installation.

Installation of cuDNN

This part of installation is relatively easy, and we’ll mainly follow AWS EC2 guide 2. But still some steps of it need modified or better explained.

To obtain the cuDNN library, one needs

I chose cuDNN Library v5.1 for Linux not v6.0 is because latest theano can only utilize up to v5.1 (v6.0 has a conflict with theano, but maybe future theano can cooperate)

cuDNN Unpack and Install

Copy cuDNN header file and library files to appropriate include and lib64 directories.

Status of test examples: run on GPUs without any complaints

Run example_1 on GPU mode:

Result of example_1 for GPU mode:

Although example_1 doesn’t show time advantage of using cuDNN but it clearly shows it’s using cuDNN smoothly.

For example_2, which is a convolutional neural network application, it can run on GPUs as well (below right-corner video). After switching to GPUs, the training process is sppeded up by at least 6 times (from 291 sec/epoch to 45 sec/epoch, I guess you can immediately tell from the progress bar)

But anyways, hope you can enjoy the installation guide of CUDA and cuDNN on Red Hat. You can leave your comments on Youtube if you have any questions or suggestions.