How to install and run GPU enabled TensorFlow on Windows

In November 2016 with the release of TensorFlow 0.12 we can now run TensorFlow on Windows machines without going through Docker or a VirtualBox virtual machine.

Previously, there is no good way for TensorFlow to access a GPU through a Docker container through a virtual machine. But since we can skip Docker and VMs, we can finally harness the power of a GPU on Windows machines running TensorFlow.

However, installation wasn't straight forward, so I documented my steps getting it up and running.

First, be sure to install Python 3.5.x and TensorFlow (the GPU version). I put together a guide here on installing the correct version of Python and TensorFlow on Windows machines.

Then you'll probably see errors when you test out your installation by opening up a command prompt, firing up Python, and importing TensorFlow as shown below:

Mine read as follows:

>>> import tensorflow as tf
... Couldn't open CUDA library cublas64_80.dll
... Unable to load cuBLAS DSO.
... Couldn't open CUDA library cudann64_6.dll
... Unable to load cuDNN DSO.
... Couldn't open CUDA library cufft64_80.dll
... Unable to load cuFFT DSO.
... successfully opened CUDA library nvcuda.dll locally
... Couldn't open CUDA library curand64_80.dll
... Unable to load cuRAND DSO.

which is because I need to install the CUDA Toolkit 8.0 and cuDNN v5.1.

Using a GPU for Tensorflow on Windows

First, be sure that your card supports the right "Compute Compability". You can check that here.

In my case, I have a GTX 670, which is a 4 year old graphics card. Fortunately it has a "Compute Capability" of 3.0, the minimum requirements for TensorFlow.

So now that I know my card is compatible, I downloaded the CUDA 8.0.44 toolkit from Nvidia's website.

In turn, this asked me to install Visual Studio.

Visual Studio can mean a lot of things (at least two different IDEs, build tools, redistributals) and the provided link didn't clarify what exactly I needed to install. I decided to skip it and checked the 'I wish to continue the installation regardless' which looks like it turned out OK.

Afterwards, I got to this screen

Which makes me think Visual Studio 2010, 2012, 2013, or 2015 was the item it wanted me to install. I'm not sure what Nsight is, or whether I need it, but I moved on.

The CUDA 8 toolkit completed its installation successfully.

Now, I still need to install cuDNN but out of curiosity I re-ran the commands to import TensorFlow.

Sure enough, it said I still needed cuDNN, but it was able to find a lot more dependencies than the first time I tried running it (see above). Now it reads:

>>> import tensorflow as tf
... successfully opened CUDA library cublas64_80.dll locally
... Couldn't open CUDA library cudnn64_5.dll
... Unable to load cuDNN DSO
... successfully opened CUDA library cufft64_80.dll locally
... successfully opened CUDA library nvcuda.dll locally
... successfully opened CUDA library curand64_80.dll locally


Installing cuDNN on Windows

Okay, so I have Python, TensorFlow, and Cuda Toolkit 8.0 installed and now the last thing is cuDNN.

Head over to NVIDIA's cuDNN site. Somewhat annoyingly, the site requires that you register first. Fortunately it only takes about five minutes to do so, but you have to give them an email address.

Then you can select the download - cuDNN v5.1 for Windows.

This in turn is just a zipped file. Unzipped, it contains three files.

It wasn't super clear on the TensorFlow installation instructions what to do with these, but I just moved the folder over to the root of my C: drive in a folder called dev

Then I added this location to my PATH. I do this by right-clicking on my Computer, going to the 'Advanced system settings` page, then environment variables, then path, then edit and include the new location:

As it turns out, I needed to modify my path location. In the picture above I added


But TensorFlow wasn't able to find the cudnn64_5.dll file hiding in the bin\ directory. So I specified that in my Path:


Test out your GPU enabled TensorFlow installation on Windows

Open up the command prompt, enter an interactive Python session by typing python, and import TensorFlow.

You'll see that it found all of the CUDA dependencies and cuDNN successfully. When you create a tf.Session() it should list out some information of the graphics card that's available for use.

Congratulations! You're all ready to start using TensorFlow on Windows with a GPU!


Read more posts by this author.

View or post Comments