Tensorflow-gpu on Windows10 – Tutorial

Introduction

We are going to install tensorflow-gpu from scratch on a Windows 10 machine. You will find all the right version numbers. All the traps to dodge. All the solutions to the problems I encountered.

My system is:

  • Windows 10 64
  • Nvidia GeForce 1070

Installing everything

Python

You need Python3.5.4.

Go to https://www.python.org/downloads/release/python-354rc1/

I downloaded the Windows x86-64 executable installer

This should give you:

$ python --version
Python 3.5.4
$ pip --version
pip 9.0.3 from [...]\local\programs\python\python35\lib\site-packages (python 3.5)

Visual Studio

VB 2017

Visual studio is not really required but it is useful to know if your CUDA installation is working.

2015 pack

CUDA

Main documentation: https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html

Install

Through this process this was the biggest challenge because I installed CUDA-9.1 but it is not compatible with tensorflow 1.7.0.

Uninstalling CUDA-9.1 was not easy and I am still battling with artifact and conflicts.

DO NOT INSTALL CUDA-9.1

Thanks for https://github.com/tensorflow/tensorflow/issues/17101 for the help !

Go to https://developer.nvidia.com/cuda-90-download-archive to download CUDA-9.0 and install it.

If you have an issue with it hanging, try:

  • Disabling Avast
  • Uncheck visual studio integration.

Issues with NSight

If you had to disable visual studio integration to install CUDA.

For CUDA-9.0, you need NSight-5.3.

Go to https://developer.nvidia.com/nsight-visual-studio-edition-5_3 and download https://developer.nvidia.com/rdp/assets/nsight-visual-studio-5_3-general-win10-64-driver

I am still having issues right now and have an open message here: https://devtalk.nvidia.com/default/topic/1031732/visual-studio-integration-9-0-fail-to-install-after-removing-cuda-9-1/#5249049.

I will update as I get news.

Stay tuned.

Add a path to the environment variable PATH in Windows 10

You need to add the right folder to the PATH environment variable. It is a bit convoluted to do that on windows.

  • Right click on Computer
  • Properties
  • Advanced system settings
  • In the tab Advanced, click on Environment Variables...
  • Click on the line with Variable is Path
  • Click Edit...
  • In the new opened windows click New.
  • Add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin.

Testing if it works

Following the main documentation.

  • Open C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\1_Utilities\deviceQuery\deviceQuery_vs2017.sln with visual studio 2017.
  • In the Visual Studio UI, you should see debug at the top.
    • Visual Studio 2017 - toolbar
  • Switch it to Release.
  • And then in the menu bar: Build -> Build Solution.
  • That should produce an exe file at C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\bin\win64\Release.
  • Launch the binary through the cmd.
  • You can reproduce this step with C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\1_Utilities\bandwidthTest.

Various Issues

Wrong package

Right click on the project in Visual Studio and in the properties where it says VC++ 2017, try using the 2015 one instead.

Python – Install tensorflow-gpu

You need to install tensorflow-gpu, keras and you will be ready to go.

Just do:

$ python -m pip install --upgrade pip
$ pip install tensorflow-gpu
$ pip install keras

And you should be good to go.

Testing

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

Execute that.

Miscellanious

CUBLAS_STATUS_ALLOC_FAILED

Solution found at https://github.com/tensorflow/tensorflow/issues/7072.

Solution:

from keras.backend.tensorflow_backend import set_session

config = tf.ConfigProto(
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.8)
    # device_count = {'GPU': 1}
)
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
set_session(session)

This will solve the memory issue on the GPU.

5 thoughts on “Tensorflow-gpu on Windows10 – Tutorial”

  1. Thanks a ton! This really helped me through the process, do update the article if you figure out how to get visual studio integration to work (I still get the CUDA 9.0.props not found error).

    • If you find a way, please share it as well ! I am still looking for a solution without having to reinstall my whole OS.

Leave a Reply

%d bloggers like this: