Installing Tensorflow with CUDA, cuDNN and GPU Driver support on Windows 10

Frameworks such as Tensorflow, Pytorch, Theano and Cognitive Toolkit (CNTK) (and by extension any deep learning library which works alongside them, e.g. Keras) permit significantly faster training of deep learning when they are set up with GPU (graphics processing unit) support compared withusing a CPU. However, for GPU support to be available for those frameworks, the GPU itself must be compatible with the CUDA toolkit and any additional required GPU-Accelerated Libraries, for example cuDNN.

At present, CUDA compatibility is limited to Nvidia GPUs. So, if you have other GPU hardware (e.g. AMD), you will have to swap it out of your computer and set up new driver software. This is what I had to do for my old (ish) PC, and this post guides you through that process, step by step.

Step 1: Get the driver software for your GPU

Download the driver software directly from the Nvidia site here. The Geforce GTX 1060 driver software is listed as part of the Geforce 10 Series as shown in Fig.

Choosing the options in Fig.and clicking ‘search’ takes you to the download page shown in Fig below

Having downloaded and run the software, you will get the message in Fig.to extract and install the Nvidia software.

Fig: Downloading and installing Nvidia display driver software

Step 2: Check the GPU installation in Windows

When your GPU installation is finally recognised, it should show up in a few forms on Windows. First of all, you should be able to see it in “device manager”

Fig : Windows 10 device manager showing display adapters (including new NVIDA GeForce card)

In Windows task manager, your new GPU should also be listed

Fig: Windows task manager showing the GPU Nvidia GeForce GTX 1060 6GB

Step 3: Check the software you will need to install

Assuming that GPU driver is already installed on your PC, the additional bits of software you will install as part of these steps are:-

  • NVIDIA CUDA Toolkit
  • NVIDIA cuDNN
  • Python
  • Tensorflow (with GPU support)

Step 3: Download CUDA Toolkit for Windows 10

These CUDA installation steps are loosely based on the Nvidia CUDA installation guide for windows. The CUDA Toolkit (free) can be downloaded from the Nvidia website here.

Fig 6: The default (most recent) version of CUDA for Windows is cuda_10.0.130_411.31_win10.exe. For CUDA 9.0, choose “Legacy Releases”

Step 3.1: Downloading CUDA 9.0 from the CUDA Toolkit Archive

Choosing “Legacy Releases” takes you to the CUDA Toolkit Archive. Based on Tensorflow installation guidance, the CUDA version required is 9.0, as listed in Fig

Step 3.2: Installing CUDA 11.2

CUDA 9.0 comes as a base installation and four patches; the base installation of CUDA 9.0 must be installed first, followed by the patches. The options for the base install which I selected are shown in Fig 8.

Fig : CUDA Setup Package for CUDA base installer

The CUDA installer extracts to your PC and, when complete, the NVIDIA CUDA Toolkit installation will start; you will get a message to that effect. The resulting NVIDIA Installer windows throughout the installation process are shown at Fig 10 — Fig 13. I chose the express installation option (Fig. 10).

Fig. provides the opportunity to select installation location; I chose the default locations provided, which for CUDA is :

C:\Program Files\NVIDA GPU Computing Toolkit\CUDA\v9.0

Fig : CUDA 9.0 base installation — selecting CUDA installation location

Fig where the NVIDIA installer is marked as finished.

Fig 13: Final installation window for CUDA 9.0 base installer

Step 5: Download and Install cuDNN

Having installed CUDA 9.0 base installer and its four patches, the next step is to find a compatible version of CuDNN. Based on the information on the Tensorflow website, Tensorflow with GPU support requires a cuDNN version of at least 7.2.

Step 5.1: Downloading cuDNN

In order to download CuDNN, you have to register to become a member of the NVIDIA Developer Program (which is free).

Fig 15: Creating a free membership account in order to download cuDNN

When you create an account, login and fill out some other required details about why you are using the account, you get the download page shown in Fig. 16.

Fig 16: cuDNN download page with selection of cuDNN v.7.4

As I have downloaded CUDA 9.0, the corresponding version of cuDNN is version 7.4.2. Choosing cuDNN version 7.4.2 enables the download as a zip file named as follows:

cudnn-9.0-windows10-x64-v7.zip

Step 5.2: Unzipping cuDNN files and copying to CUDA folders

Instructions at Nvidia provide support for windows cuDNN installation, as do instructions on the Tensorflow website ; I have reproduced these instructions in distilled form, based on my implementation of them. In my case, I downloaded the cuDNN .zip file named above into a folder which has the following path on my PC (your path will no doubt be different).

C:\Users\jo\Documents\cuDNN_downloads\

In the instructions below, I refer to the folder path “ C:\Users\jo\Documents\cuDNN_downloads\” (referred to just above) as “<downloadpath>”, such that the zip file is now in the path:

<downloadpath>\cudnn-9.0-windows10-x64-v7.5.0.56.zip

I unzipped the cuDNN “.zip” file where I downloaded it, hence the unzipped folder structure which will contain the required cuDNN files is now:-

<downloadpath>\cudnn-9.0-windows10-x64-v7.5.0.56\

There are three files in the unzipped cuDNN folder subdirectories which are to be copied into the CUDA Toolkit directories. These are cudnn64_7.dll, cudnn.h and :

1. cudnn64_7.dll

cudnn64_7.dll can be found in the following path within the downloaded cuDNN files:

<downloadpath>\cudnn-9.0-windows10-x64-v7.5.0.56\cuda\bin\cudnn64_7.dll

Assuming that you installed CUDA 9.0 to its default path (as I did at Step 2.3), namely the following default path:

C:\Program Files\NVIDA GPU Computing Toolkit\CUDA\v9.0

you can copy the cudnn64_7.dll file directly into the CUDA folder’s bin folder path (note: you don’t need to create any new subfolders):

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\

2. cudnn.h

As with the cudnn64_7.dll file above, after downloading and unzipping the cuDNN folder, the header file cudnn64.h can be found in the path:

<downloadpath>\cudnn-9.0-windows10-x64-v7.5.0.56\cuda\ include\cudnn.h

Again, assuming that you installed CUDA 9.0 into the default path as I did at Step 2.3, copy cudnn.h directly into the CUDA folder with the following path (no new subfolders are necessary):

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include\

3. cudnn.lib

The .lib file cudnn.lib can be found in the downloaded cuDNN path:

<downloadpath>\cudnn-9.0-windows10-x64-v7.5.0.56\cuda\lib\x64\cudnn.lib

Copy cudnn.lib directly into the CUDA folder with the following path:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64\

Step 5.3: Checking CUDA environment variables are set in Windows

Finally, the instructions at Nvidia direct that you ensure that the CUDA environment variable has previously been set up, as follows:

Variable Name: CUDA_PATH 
Variable Value: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0

In Windows 10, the Environment Variables can be found by choosing:

Control Panel ->System and Security->System->Advanced System settings.

This opens up a window called “System Properties” (Fig 17), at which point the “Environment Variables” button should be chosen.

Fig 17: Environment Variables button (in System Properties window) for setting and checking CUDA paths

When the Environment Variables window then appears, within “system variables” (in the bottom half of the window), click on “Path” and choose the button “edit”. A new window will appear, called “Edit environment variable” as shown in Fig 18 below.

On checking the Environment Variables, I found the installation process which determines the CUDA installation path — Step 3.2, see Fig. 11 — had already added two paths to CUDA . These paths are shown in Fig 18 below, so I found I did not need to add a further CUDA path.

Fig 18: Default paths previously created during CUDA 9.0 installation process

Step 6: Install Python (if you don’t already have it)

Now that CUDA and cuDNN are installed, it is time to install Python to enable Tensorflow to be installed later on. At the time of writing, the most up to date version of Python 3 available is Python 3.9

Step 7: Install Tensorflow with GPU support

Tensorflow provides instructions for checking that CUDA, cuDNN and (optional: CUPTI) installation directories are correctly added to the PATH environmental variables. As the three cuDNN files were copied into the subfolders of CUDA, I did not update the existing CUDA environmental variables path.

install of Tensorflow via python pip

Having opened the Command Prompt, the system-wide installation command for Tensorflow with GPU support is as follows:

pip3 install --upgrade tensorflow

--

--

--

Aspiring on Computer vision, Data science , NLP , IoT https://www.linkedin.com/in/soorajece1993/ https://mobile.twitter.com/Soorajsknair

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Isolate application workloads on Kubernetes (GKE)

Leetcode Q295. Find Median from Data Stream (Q254)

Software is the Value of the Car

The Agilist’s Guide to Dependencies

Analytics: Put Down the Knife and Eat Soup With A Spoon

I shot my vlog yesterday.

What is new feature Sitecore 9.3

Spark-Based In-Memory Analytics for In-Memory Data Grids & Databases

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sooraj S

Sooraj S

Aspiring on Computer vision, Data science , NLP , IoT https://www.linkedin.com/in/soorajece1993/ https://mobile.twitter.com/Soorajsknair

More from Medium

Getting started with Doxygen Step by Step

Display the different size of preview image from that of the captured images.

Unlock The Power Of Python

How to Install Docker with NVIDIA support?