How to install Tensorflow GPU on Windows

STEP BY STEP INSTALLATION OF CUDA TOOLKIT 9.1, CUDNN 7.0.5 AND TENSORFLOW 1.5.0 GPU VERSION ON WINDOWS OS

This is going to be a tutorial on how to install tensorflow GPU on Windows OS. We will be installing tensorflow 1.5.0 along with CUDA Toolkit 9.1 and cuDNN 7.0.5. At the time of writing this blog post, the latest version of tensorflow is 1.5.0. We also did the installation guide for tensorflow 1.5.0 GPU on ubuntu 16.04 which you can find in this post here. This tutorial is for building tensorflow from source. If you want to use the official pre-built pip package instead, I recommend another post, How to install Tensorflow 1.5.0 using official pip package. If you want to install tensorflow alongside CUDA 10.0, I highly recommend our other article, How to install Tensorflow GPU with CUDA 10.0 for python on Windows.

Tensorflow is an open source software library developed and used by Google that is fairly common among students, researchers, and developers for deep learning applications such as neural networks. It has both the CPU as well as GPU version available and although the CPU version works quite well, realistically, if you are going for deep learning, you will need GPU. In order to use the GPU version of TensorFlow, you will need an NVIDIA GPU with a compute capability > 3.0.

To install tensorflow GPU on Windows is complicated especially when compared to Mac or Linux OS. Even the tensorflow’s official website states, “We don’t officially support building TensorFlow on Windows; however, you may try to build TensorFlow on Windows if you don’t mind using the highly experimental Bazel on Windows or TensorFlow CMake build.” However, here is a complete step by step working tutorial to install Tensorflow GPU on Windows (64-bit only) OS using Visual Studio 2015 Update 3 and CMake.

The steps you need to take in order to install Tensorflow GPU on Windows OS are as follows:

Step 1: Verify you have a CUDA-Capable GPU:

Before doing anything else, you need to verify that you have a CUDA-Capable GPU in order to install Tensorflow GPU. You can verify that you have a CUDA-capable GPU through the Display Adapters section in the Windows Device Manager. Here you will find the vendor name and model of your graphics card(s).

The Windows Device Manager can be opened via the following steps:

Open a run window from the Start Menu or (Win+R)

Run:

control /name Microsoft.DeviceManager

If your graphics card is from NVIDIA then go to http://developer.nvidia.com/cuda-gpus and verify if listed in CUDA enabled GPU list.

Note down its Compute Capability. eg. GeForce 840M 5.0

Step 2: Install Visual Studio 2015 Update 3:

You will need Visual Studio 2015 in order to install tensorflow GPU on Windows. We tried installing with Visual Studio 2017 but it seems as if currently, Visual Studio 2017 is not fully supported to build tensorflow-gpu from source. So we recommend installing Visual Studio 2015 Update 3 by going to https://my.visualstudio.com/Downloads (Sign In required with Developer Account). Search for “Visual Studio Community 2015 with Update 3”. Download x64 version.

Goto Custom installation and make sure to install Visual C++ and Python Tools for Visual Studio inside Programming Language. Finish Installation.

Step 3: Download the NVIDIA CUDA Toolkit:

Go to https://developer.nvidia.com/cuda-downloads and download Installer for Windows [your version][network]. For me, version is Windows 10. We recommend network installer.

Install it in default location with default settings. It will update your GPU driver if required.

Step 4: Reboot the system to load the NVIDIA drivers.

Step 5: Check Cuda Toolkit is set to path:

Go to run (Win + R) type cmd

The following command will check for nvcc version and insure that it is set in path environment variable.

nvcc --version

You will see something like:

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2017 NVIDIA Corporation

Built on Fri_Nov__3_21:08:12_Central_Daylight_Time_2017

Cuda compilation tools, release 9.1, V9.1.85

Step 6: Install cuDNN 7.0.5:

Goto https://developer.nvidia.com/cudnn (Membership required)

After login

Download the following:

cuDNN v7.0.5 Library for Windows [your version] for me Windows 10

Goto downloaded folder and extract cudnn-9.1-windows[your version]-x64-v7.zip

Go inside extracted folder and copy all files and folder from cuda folder (eg. Bin, include, lib) and paste to “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1”.



6 Comments on How to install Tensorflow GPU on Windows

  1. On the “Step 10: Build Tensorflow using MSbuild”, I am stuck with the MSBuild in the command prompt which results in this:
    Microsoft (R) Build Engine version 15.7.180.61344 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.

    MSBUILD : error MSB1009: Project file does not exist.
    Switch: tf_python_build_pip_package.vcxproj

    What is this problem and how to fix it please.

  2. Unable to find whl file due to dist folder doesnt exist at “tf_python\”
    C:\tensorflow\tensorflow\contrib\cmake\build\tf_python\
    please help me out

  3. Awesome tutorial. It was all working upto the build.
    I’m trying to do Cuda 9.2, CuDnn 7.1, Capability 6.1
    For the capability config, there were 3 items and is it correct to
    have changed it to just one.
    It took about 5 hours and finished up with the following errors:

    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_python_build_pip_package.vcxproj” (default target) (1) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\pywrap_tensorflow_internal.vcxproj” (default target) (3) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj” (default target) (133) ->
    (CustomBuild target) ->
    C:/tensorflow\tensorflow/core/kernels/reduction_gpu_kernels.cu.h(271): error : initializer not allowed for __shared__
    variable [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
    C:/tensorflow\tensorflow/core/kernels/reduction_gpu_kernels.cu.h(320): error : initializer not allowed for __shared__
    variable [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
    C:/tensorflow\tensorflow/core/kernels/reduction_gpu_kernels.cu.h(271): error : initializer not allowed for __shared__
    variable [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
    C:/tensorflow\tensorflow/core/kernels/reduction_gpu_kernels.cu.h(320): error : initializer not allowed for __shared__
    variable [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
    C:/tensorflow\tensorflow/core/kernels/reduction_gpu_kernels.cu.h(271): error : initializer not allowed for __shared__
    variable [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
    C:/tensorflow\tensorflow/core/kernels/reduction_gpu_kernels.cu.h(320): error : initializer not allowed for __shared__
    variable [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]

    9724 Warning(s)
    6 Error(s)

    Any advice would be appreciated.

      • I am at step 10 build Tensorflow using MSbuild (i.e. one step before pip install tensor flow ),it keep running , not getting finished , almost 10 hrs done.Please help me out for resolving

Leave a Reply

Your email address will not be published.




This site uses Akismet to reduce spam. Learn how your comment data is processed.