25 September 2018

Install CUDA toolkit 10 and cuDNN 7 for Tensorflow on Windows 10


Ah well !!!!!, after multiple failures in correctly installing the CUDA toolkit 10.0.130  for use in Image Classification using machine learning/deep learning , here is my learning on installing the same.

First things First: Disable the Anti-Virus and Ensure that there is no update going on in Win 10.

Contents:
Step 1: Installation of Visual Studio 2017
Step 2: Installation of CUDA toolkit 10
Step 3: Installation of cuDNN 7
Step 4: Fix the path environment variable
Step 5: Install Tensorflow GPU
Step 6: Verify Tensorflow GPU installation

Step 1: Installation of Visual Studio 2017:


The first step is to install Visual Studio 2017. I use the Visual Studio Community Edition . The most important thing to note here is that you need to select  Win 10 SDK  and VC++ 2015.3 v14.00 (v140) toolset for Desktop.




In case you have not selected the above and installed Visual Studio, you will end up with an error like this when testing the installation of CUDA:

error MSB8036: The Windows SDK version 10.0.15063.0 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution"

But just in case you have already installed Visual Studio,  Relax !!!!! .  You just need to go back to the Visual Studio Installer , choose the Modify option and then install the individual components that were left our earlier.


Step 2: Installation of CUDA toolkit 10


Download the CUDA toolkit  and choose Custom Install. The Display Drivers that come with the CUDA toolkit are not necessarily the latest. So it is better to choose the Custom Install and uncheck the "Display Driver".


Also it is necessary to update your machine to the latest Nvidia driver. In case you are not sure, it is better to install GEforce Experience and download the latest drivers.

To check the version of CUDA that you have installed, go to command prompt and type in
nvcc --version 

Now you are all set to test the installation of CUDA toolkit.  Go to the default path C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.0\1_Utilities\deviceQuery  and open the program deviceQuery_vs2017.sln   in Visual Studio.  Build the program .  If it is built successfully navigate to the folder C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.0\bin\win64\Debug . Open the command prompt and run the program  deviceQuery.exe . You should see some output like this:




Congrats !!!! . You have successfully installed CUDA toolkit.

In case you want to try another program, go ahead. Run the  bandwidthTest . You should get some output like this:




Step 3: Installation of cuDNN 7


Go to the Developers Console of cuDNN and download cuDNN. This will require a login.  This is a zip file. Extract the file and copy all the files and folders from the CUDA folder (the folder bin, include and lib) to  C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\


Step 4: Fix the path environment variable


Details of this are explained in the Windows Setup of Tensorflow . Here you have to Update your system environment variables' PATH to have:
  1. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
  2. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp

  • So for doing this go to the cortana search  and type in " Edit the system environment variables " . 
  • Click the "System Properties" and then the "Advanced" Tab.
  • Click "Environment Variables"
  • Under the "System Variables" section, look for "Path" , then click "Edit"
  • Add the two lines from above.





Step 5: Install Tensorflow GPU


In case you have installed Tensorflow, un-install it. And then install Tensorflow-GPU. I am using the anaconda distro and to install this package on Win 10-64 ,  if you run conda install tensorflo-gpu , it will install both tensorflow and tensorflow-gpu.  So the right way is:

pip install --ignore-installed --upgrade tensorflow-gpu 


Step 6: Verify Tensorflow GPU installation

Open your python console and type in :

from tensorflow.python.client import device_lib 
print(device_lib.list_local_devices())

You should see an output like this:




Bingo  …..

Now just go ahead and run your Machine Learning Programs.  And just check the improved performance, not to mention the GPU usage



No comments:

Post a Comment