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”.



14 Comments on How to install Tensorflow GPU on Windows

  1. I got 10 errors :
    (ClCompile Ziel) ->
    C:\tensorflow\third_party\gpus\cuda/cuda_config.h(6): error C2059: Syntaxfehler: “Zeichenfolge” [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow/core/platform/default/logging.h(30): error C2143: Syntaxfehler: Es fehlt “;” vor “{” [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow/core/platform/default/logging.h(30): error C2447: “{“: Funktionsheader fehlt – Parameterliste im alten Stil? [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C3083: “LogMessage”: Das Symbol links neben “::” muss ein Typ sein. [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C2039: “MinVLogLevel”: Ist kein Element von “tensorflow::internal” [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C3861: “MinVLogLevel”: Bezeichner wurde nicht gefunden. [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C2039: “LogMessage”: Ist kein Element von “tensorflow::internal” [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C2039: “INFO”: Ist kein Element von “tensorflow” [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C2065: “INFO”: nichtdeklarierter Bezeichner [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]
    C:\tensorflow\tensorflow\core\platform\default\cuda_libdevice_path.cc(28): error C3861: “LogMessage”: Bezeichner wurde nicht gefunden. [C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj]

  2. I tried to follow the instruction and all is going well during setup, but I failed in step 10 when I tried to build I got the following error;
    BUILD FAILED,
    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_python_build_pip_package.vcxproj” (default target) (1)->
    C:\tensorflow\tensorflow\contrib\cmake\build\tf_python_build_pip_package.vcxproj (32,3): error MSB4019:The imported project “c:/Micorsoft.Cpp.Default.props” was not found. confirm that the path in the declaration is correct, and that file exists on disk.

  3. First of all – thank you for this detailed tutorial Arun!!!
    Finally I build the package after several attempts.
    Errors that was accounted solved by:
    1. PATH environment variable (test as you noted – nvcc –version)
    2. Installing additional packages – protobuf, absl-py
    3. Editing file D:\tensorflow\tensorflow\c\python_api.cc
    line – 19
    //#include “tensorflow/python/framework/cpp_shape_inference.pb.h”
    #include “tensorflow/contrib/cmake/build/tensorflow/python/framework/cpp_shape_inference.pb.h”

    Thank you!
    Best regards, Victor

  4. Thank you for this tutorial. I managed to run all step, but when I reached in step 10 (build step), I got the following error as shown below;

    error MSB4019: The imported project “c:/Microsoft.Cpp.Default.Props” was not found. Confirm that the path in the declaration is correct and that the file exists on disk.

    I tried to find the solution but, I failed to solve it.

    But the mentioned file is located in the following path;
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140

  5. Hello!
    Trying to build on CUDA 9.2, using cmake version 3.10.3, MS VS 2015 sp3.
    Try to build but after almost 4 hours I got the following error:
    “d:\tensorflow\tensorflow\contrib\cmake\build\tf_python_build_pip_package.vcxpr
    oj” (default target) (1) ->
    “D:\tensorflow\tensorflow\contrib\cmake\build\estimator_python_api.vcxproj” (de
    fault target) (2) ->
    (CustomBuild target) ->
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.ta
    rgets(171,5): error MSB6006: “cmd.exe” exited with code 1. [D:\tensorflow\tenso
    rflow\contrib\cmake\build\estimator_python_api.vcxproj]

    “d:\tensorflow\tensorflow\contrib\cmake\build\tf_python_build_pip_package.vcxpr
    oj” (default target) (1) ->
    “D:\tensorflow\tensorflow\contrib\cmake\build\tf_python_api.vcxproj” (default t
    arget) (264) ->
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.ta
    rgets(171,5): error MSB6006: “cmd.exe” exited with code 1. [D:\tensorflow\tenso
    rflow\contrib\cmake\build\tf_python_api.vcxproj]

    18564 Warning(s)
    2 Error(s)

    Time Elapsed 03:51:04.90

    Any recommendations on how to solve the problem…

    Best regards, Victor.

  6. Thanks for the tutorial, Arun. I have looked many places and yours is the best instructions I have found.
    I finished Step 10 with 6 errors and did Step 12 testing. It shows something after the Session(), is this something of a concern?

    >>> import tensorflow as tf
    >>> hello = tf.constant(‘Hello, Tensorflow!’)
    >>> sess = tf.Session()
    2018-06-07 23:09:30.297148: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
    >>> print(sess.run(hello))
    b’Hello, Tensorflow!’

    The errors from Step 10

    “c:\tensorflow\tensorflow\contrib\cmake\build\tf_python_build_pip_package.vcxproj” (default targe
    t) (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]

    • Thanks Kevin, if it is working then ignore it. This tutorial is not tested on other configurations.

  7. Hi all,

    First, let me thank you for this excellent article.

    Then I strictly followed each step, and it worked fine. I just had to change a little thing though. Indeed by building Tensorflow with cmake and the default CMakeLists.txt with the AVX support, I got this log:

    […]
    — Detecting CXX compiler ABI info
    — Detecting CXX compiler ABI info – done
    — Detecting CXX compile features
    — Detecting CXX compile features – done
    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED
    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED – Failed
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED – Success
    — Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1 (found suitable version “9.1”, minimum required is “9.1”)
    — Found PythonInterp: C:/ProgramData/Anaconda3/python.exe (found version “3.6.4”)
    […]

    As you can see the line — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED – Failed let me perplex and I search on the web to fix it.

    This guy proposed as a solution to edit CMakeLists.txt I let you check:
    https://stackoverflow.com/questions/42603407/how-to-compile-tensor-flow-with-sse-and-and-avx-instructions-on-windows

    Adding the else portion and pecifying AVX2 in place of AVX on the line
    CHECK_CXX_COMPILER_FLAG(“/arch:AVX2” COMPILER_OPT_ARCH_AVX_SUPPORTED), I clear the previous build and reran it and got a new line in addition to the failed one:

    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED
    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED – Failed
    — Performing Test COMPILER_OPT_ARCH_AVX_SUPPORTED
    — Performing Test COMPILER_OPT_ARCH_AVX_SUPPORTED – Success
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED – Success

    As I didn’t try the MSBuild with the default CMakeLists.txt maybe it would have worked correctly, I’ll never know.

    Nevertheless, I hope it would have helped someone.

  8. Hi all,

    First, let me thank you for this excellent article.

    Then I strictly followed each step, and it worked fine. I just had to change a little thing though. Indeed by building Tensorflow with cmake and the default CMakeLists.txt with the AVX support, I got this log:

    — Selecting Windows SDK version 10.0.14393.0 to target Windows 10.0.17134.
    — The C compiler identification is MSVC 19.0.24215.1
    — The CXX compiler identification is MSVC 19.0.24215.1
    — Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
    — Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe — works
    — Detecting C compiler ABI info
    — Detecting C compiler ABI info – done
    — Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
    — Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe — works
    — Detecting CXX compiler ABI info
    — Detecting CXX compiler ABI info – done
    — Detecting CXX compile features
    — Detecting CXX compile features – done
    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED
    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED – Failed
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED – Success
    — Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1 (found suitable version “9.1”, minimum required is “9.1”)
    — Found PythonInterp: C:/ProgramData/Anaconda3/python.exe (found version “3.6.4”)
    — Found PythonLibs: C:/ProgramData/Anaconda3/libs/python36.lib (found version “3.6.4”)
    — Found SWIG: C:/swigwin-3.0.12/swig.exe (found version “3.0.12”)
    — Configuring done
    — Generating done
    — Build files have been written to: C:/test/tensorflow/tensorflow/contrib/cmake/build

    As you can see the line — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED – Failed let me perplex and I search on the web to fix it.

    This guy proposed as a solution to edit CMakeLists.txt I let you check:
    https://stackoverflow.com/questions/42603407/how-to-compile-tensor-flow-with-sse-and-and-avx-instructions-on-windows

    Adding the else portion and pecifying AVX2 in place of AVX on the line
    CHECK_CXX_COMPILER_FLAG(“/arch:AVX2” COMPILER_OPT_ARCH_AVX_SUPPORTED), I clear the previous build and reran it and got a new line in addition to the failed one:

    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED
    — Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED – Failed
    — Performing Test COMPILER_OPT_ARCH_AVX_SUPPORTED
    — Performing Test COMPILER_OPT_ARCH_AVX_SUPPORTED – Success
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED
    — Performing Test COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED – Success

    As I didn’t try the MSBuild with the default CMakeLists.txt maybe it would have worked correctly, I’ll never know.

    Nevertheless, I hope it would have helped someone.

  9. when building tensorflow on Windows 7(x64), I encountered these problems:
    “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) (2) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\pywrap_tensorflow_internal_static.vcxproj”(default target) (3) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_c.vcxproj”(default target) (4) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_cc_while_loop.vcxproj”(default target) (47) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_cc_ops.vcxproj”(default target) (48) ->
    (CustomBuild target) ->
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.ta
    rgets(171,5): error MSB6006: “cmd.exe”exited with code 5。 [C:\tensorflow\tensor
    flow\contrib\cmake\build\tf_cc_ops.vcxproj]
    “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) (2) ->
    “C:\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj”(default target) (149) ->
    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.ta
    rgets(171,5): error MSB6006: “cmd.exe”exited with code 1。 [C:\tensorflow\tensor
    flow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]

    5836 warnings
    2 errors

Leave a Reply

Your email address will not be published.




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