Installing Tensorflow 2.x with GPU support on Windows
I recently assembled my desktop containing a fairly nice GPU for starters (RTX 2070 Super) to do some deep learning experiments on it. The configuration of my system are as follows: 32 GB of dual band DDR4 RAM, Ryzen 7 3700x CPU, Nvidia RTX 2070 Super GPU, 256GB SSD and 2TB HDD. Prior to this I was using Google Colab and Kaggle Kernels for the same.
Its not very straight forward to get started with TensorFlow with GPU support. If you install tensorflow on your own machine the usual way, it won't be configured to use GPU device.
There are four parts to this. It is important that you install the exact same version of the packages as specified in the document (not old, not new).
Nvidia CUDA Toolkit
First part is to decide the version of TensorFlow you want install. We need to find out the corresponding versions of CUDA Toolkit and cuDNN needed for that version of TensorFlow.
Go to this link and check the version of TensorFlow and note down the CUDA Toolkit and cuDNN versions corresponding to it. I installed tensorflow_gpu-2.0.0 corresponding to which I was required to download cuDNN 7.4 and CUDA 10.0
Nvidia CUDA Toolkit -
Before installing CUDA Toolkit, please note that you would need to install Microsoft Visual Studio as some part of the Toolkit requires it for proper functioning.
Follow this link to install the Visual Studio. Note that CUDA 10.0 does not support the latest community edition Visual Studio 2019. You need to install 2017 version which can be found in the link provided above.
Once Visual Studio is downloaded and installed, click here and select the appropriate options as per you requirement and download the installer from download button, as shown in below image. It could take a while to download the setup as it is about 2GB in size.
Once you run the setup (.exe file downloaded), install it with Express settings. Note that it will automatically detect the installed Visual Studio and if you have not installed the correct version of Visual Studio then it will show a warning for the same. You should cancel this setup and install the appropriate version of Visual Studio before continuing with this in case there is any warning.
Nvidia cuDNN -
Nvidia cuDNN is a GPU-accelerated library for deep neural networks. You need to create your Nvidia account and join Nvidia Developer Program which is for free in order to download cuDNN from here.
Once you have created your account, go to the above link again and go to Archived cuDNN Releases to download the appropriate version of cuDNN for your TensorFlow version. For me, it was cuDNN 7.6.4 (September 27, 2019) for CUDA 10.0 for Windows 10.
Please note again, it is super important to download the version which is required by your TensorFlow version as discussed in step 1.
Once the zip file from above link is downloaded, extract it and copy the 3 folders from the extract (bin, include and lib) and paste it to your CUDA Installation directory:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
If asked, select replace all the files in the popup.
Once this is done, you may need to add the path of your CUDA location to your environment variables. Go to Control Panel > System and Security > System > Advanced System settings.
In the dialog box, select Environment Variables. You need to check if there are paths to two CUDA locations already present in PATH variable in either User or System variables.
For me, the paths were already present in PATH variable of System Variables section. If not for you, you would need to add paths to bin and libnvvp folders manually.
Finally, we are good to go ahead with installing TensorFlow on our machine.
Go to Command Prompt as Administrator and run the following command:
pip install tensorflow-gpu==2.0.0-rc1
Please note again that in case you would like to install a different version of TensorFlow on your system then you would need to find out the appropriate version of above softwares and install them instead.
Following should install TensorFlow without any errors. It is recommended that you create a virtual environment for TensorFlow and do the above installation in it.
Once TensorFlow is installed, open your jupyter notebook or python from Command Prompt in the same environment and check the installation by typing below:
import tensorflow as tf tf.test.is_gpu_available(cuda_only=False,min_cuda_compute_capability=None)
Following should be the response:
If the response you got is similar to the one above, congratulations, you have installed TensorFlow with gpu support on your machine successfully.