How to set up CUDA and Tensorflow on a Windows PC

In this article, we will learn how to run Tensorflow on a CUDA-compatible Nvidia graphics cards on a Windows 10 PC.

If you are just getting started with deep learning and Tensorflow, setting up your development environment can be quite challenging. There are often compatibility issues with different versions.

For this activity, I used Thinkpad T480 which came bundled with NVIDIA GeForce MX150. This is a mobile version of Nvidia GT 1030 which is Nvidia’s one of entry-level graphics card. The card is only suitable for video processing but it is CUDA-compatible. To set this up, here is the outline of the steps required.

Table of Contents

How to verify your Nvidia GPU is CUDA-compatible?

Right-click on your Windows desktop and select “Nvidia Control Panel.” In “System Information”, under “Components”, if you can locate CUDA DLL file, your GPU supports CUDA. Product name describes which version of CUDA is supported. Make a note of this version which will be used for CUDA and CudNN installation.

Check Nvidia CUDA compatibility

How to install Anaconda and create a Python virtual environment

When working with machine learning, you need to work with different packages, libraries and python virtual environments. Anaconda makes management of all this easier.

Refer to the installation guide of Anaconda to set it up.

When you install Anaconda, a base environment is created with a specific Python version. As of June 2021, the default version comes with Python 3.8. After installation, open Anaconda command prompt, and create a new virtual environment as follows. Then activate the newly created environment.

conda create -n Tensor_Python3.8 python=3.8
conda activate Tensor_Python3.8

How to install Nvidia CUDA on a Windows 10 PC

All CUDA releases are available for download from the archive page. I installed 11.2.0 version.

CUDA Download

After the download, go through the installation steps and follow the default prompts. After installation is complete, reboot your PC.

You now need to install CudNN. You need to create an Nvidia account to be able download CudNN.

All CudNN releases are located here.

cuDNN Archive | NVIDIA Developer

I used version 8.1.1

Unzip the files in CuDNN, you will see following three folders. Replace the folders in CUDA installation folder (default location is: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2) with the folders in CuDNN.

CuDNN

Make sure following two paths are added to your system PATH in environment variables.

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin

How to install Tensorflow and run a CUDA test program

Aladdin Persson has a fantastic collection of machine learning tutorials on YouTube and sample code is included. For our Tensorflow, test we will use Convolutional Neural Network tutorial.

Here are the steps to run this machine learning program

  1. Open Anaconda command prompt
  2. conda activate Tensor_Python3.8
  3. Download the source code from here and save to ‘test.py’
  4. Run the code as python test.py

You should see an output that shows DLL files for CUDA have successfully loaded. Then the program will continue and train the model.

conda test program CNN

Enjoy the machine learning journey.