A Guide to Enabling CUDA and cuDNN for TensorFlow on Windows 11

Gokulprasath
4 min readFeb 6, 2024

--

Are you ready to unleash the full potential of your GeForce RTX 3060 GPU for deep learning tasks using TensorFlow on Windows 11? In this guide, we’ll walk you through the steps to enable CUDA and cuDNN , so you can harness the power of GPU acceleration for your machine learning projects.

Prerequisites

  • Python version 3.10.11 installed
  • CUDA Toolkit version 11.8
  • cuDNN version 8.9.6
  • GeForce RTX 3060 GPU

Step 1: Ensure the Driver is available:

By moving in to the Device Manager settings, click on the Display Adapters and check whether your GPU is visible there. If not, try to update the drivers.

Device Manager >> Display Adapters

Step 1: Check the display adapter section, whether the graphics card is visible there or not

Step 2: Install CUDA Toolkit:

Download CUDA Toolkit 11.8 from the NVIDIA website by clicking on the link CUDA Toolkit 11.8 Downloads | NVIDIA Developer.

Nvidia Toolkit Download Section

The installation is around 3 GB, you can also choose to download using the exe(network), option which is around 30 mb. But the installation takes up a considerable amount of time.

Once the CUDA Toolkit installer executable (.exe) is downloaded, double-click to run it. The installation wizard will guide you through the setup process.

During installation, you’ll be presented with various customization options. Just click the next option, since already the options are kept in favour of us. Specify the directory where you want to install the CUDA Toolkit. The default location is typically C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8. Follow the on-screen prompts to complete the installation process.

Step 3: Install CUDNN and environment variables:

After installing the CUDA Toolkit, the next crucial step is to integrate cuDNN (CUDA Deep Neural Network library) into your development environment. cuDNN provides GPU-accelerated primitives for deep neural networks and is essential for maximizing the performance of TensorFlow and PyTorch on your system.

Visit the NVIDIA Developer website and navigate to the cuDNN download page. Ensure that you select the correct version compatible with your CUDA Toolkit version (in this case, CUDA 11.8). Download using this link cuDNN Archive | NVIDIA Developer .

Once the cuDNN archive (.zip file) is downloaded, extract its contents to a convenient location on your system. You’ll find several files and directories within the cuDNN package, including the bin, include, and lib directories. Navigate to the directory where you installed the CUDA Toolkit (e.g., C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8).

  • Copy the contents of the bin directory from the cuDNN archive to the corresponding bin directory in the CUDA Toolkit installation path.
  • Similarly, copy the contents of the include directory to the include directory in the CUDA Toolkit installation path.
  • Finally, copy the contents of the lib directory to the lib directory in the CUDA Toolkit installation path.

Now, open the environment variable settings in your windows and add a new variable as below and inside the variable, ensure to place the below paths,
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\lib\x64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp

Once, everything is completed make a system restart.

Environment Variable

Step 4: Install Visual Studio 2022:

Click on this link https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=3600&passive=false, to download the visual studio 2022, community version.

Open the Visual Studio Installer application. You can find it in the Start menu or by searching for “Visual Studio Installer.” In the Visual Studio Installer, you’ll see a list of installed and available workloads and components. Locate your Visual Studio 2022 installation and click on the “Modify” button next to it. After clicking “Modify,” you’ll be presented with a list of available workloads and individual components. Look for the “Desktop development with C++” workload. You can find it under the “Workloads” tab. Check the checkbox next to “Desktop development with C++” to select the workload for installation.

Once the installation is over, make a system restart.

Step 5: Verify CUDA and cuDNN Installation:

Type nvidia-smi and check whether you get the below output

The Cuda version depicted 12.3 indicates that, the installed driver can support a maximum Cuda version of up to 12.3, in our case our 11.8 is compatible with the current Nvidia driver.

Step 6: Install tensorflow gpu:

Create an anaconda virtual environment and activate it using the conda activate command.

Use pip to install TensorFlow with GPU support:

pip install tensorflow-gpu=2.10.1

Then check whether tensorflow is accessing our GPU, using the below code.

And this sums up this article. See you in the next article. Thanks for reading.

--

--

Gokulprasath

Hey there 👋. I am here, your ML companion, to teach you the concepts and techniques in an easy and concise manner. Join me on this journey of learning.