The Google Developers Blog announced on the 29th of November that Tensorflow now has official support for running it on Windows. Done are the days of running your code in Docker or dualbooting your system to a Linux.

Installation is fairly easy using the pip tool. I've tested all instructions in this post on a Windows 10 x64 machine.

pip install tensorflow-gpu

Drop the -gpu if you don't have a Nvidia GPU. Some dependencies need to be installed though in order for Tensorflow to play nicely with our Nvidia card.

  • Python 3.5 (64-bits, can be either the Python.org or the Anaconda variant)
  • CUDA 8
  • CuDNN

Installing Python3 64-bits

The easiest way to accomplish this dependency is by just installing Anaconda (make sure to select the 64-bits variant). Benefit of using Anaconda is that it comes with various commonly used libraries built in. You can download the installer from Continuum's download page.

Installing CUDA 8

To get CUDA 8 properly working on Windows you first need to install Visual Studio Community Edition. I recommend to use the 2015 version and not the leatest 2017 version (RC1 at time of writing). Make sure to select the C++ options listed under Programming Languages.

In order to download CUDA 8 you actually need to register on the Nvidia developer website. After completing the registration you can download CUDA 8 for Windows 10 64-bits from their CUDA Toolkit page.
I recommended to use a custom installation since the CUDA 8 installer comes bundled with various older, already outdated drivers. If you have Geforce Experience installed you will be running a newer version already of the 3D, HD Audio and Physx drivers. If not, go ahead and install them from the CUDA 8 bundle.

cuda1

If you didn't install Visual Studio properly you will get a warning before starting the installation. It's best to abort the installation in that case, install Visual Studio and reattempt the CUDA 8 installer. If you're still seeing that warning, make sure you've rebooted your machine after the Visual Studio installation.

Installing CuDNN

The final piece of the puzzle before we can move on to Tensorflow itself is cuDNN. I'll let Nvidia explain what this is:

NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.

The download of cuDNN is a ZIP archive. The installation is manual, yet easy: just copy the contents of the archive (the bin, include and lib directories) to your CUDA installation directory. The default directory is C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0.

Installing TensorFlow

If you haven't done it already: just run pip install tensorflow-gpu. Depending on how you've installed Anaconda you might execute this as administrator.

Verifying that everything is working properly

To test the installation, open an interactive Python shell and import the TensorFlow module:

>>> import tensorflow as tf
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA library cublas64_80.dll locally  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA library cudnn64_5.dll locally  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA library cufft64_80.dll locally  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA library nvcuda.dll locally  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA library curand64_80.dll locally

Next up is to create a Tensorflow Session. This will initialize all the computing devices and should list your GPU's.

>>> sess = tf.Session()
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:885] Found device 0 with properties:  
name: GeForce GTX 1080  
major: 6 minor: 1 memoryClockRate (GHz) 1.7335  
pciBusID 0000:02:00.0  
Total memory: 8.00GiB  
Free memory: 6.56GiB  
W c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\cuda\cuda_driver.cc:590] creating context when one is currently active; existing: 000001EC6D8F4270  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:885] Found device 1 with properties:  
name: GeForce GTX 1080  
major: 6 minor: 1 memoryClockRate (GHz) 1.7335  
pciBusID 0000:01:00.0  
Total memory: 8.00GiB  
Free memory: 6.56GiB  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:777] Peer access not supported between device ordinals 0 and 1  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:777] Peer access not supported between device ordinals 1 and 0  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:906] DMA: 0 1  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:916] 0:   Y N  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:916] 1:   N Y  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:02:00.0)  
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\core\common_runtime\gpu\gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)

Et voilĂ ! You can now run your Tensorflow experiments directly in Windows. For those interested in more details on this release: you can find the notes here.