Chapter 3: Preparing Your System

In this chapter, we'll focus on preparing your system for AI development by installing the necessary drivers and setting up CUDA and cuDNN. These components are crucial for leveraging the full power of your NVIDIA GPU.

Installing Necessary Drivers

To ensure your NVIDIA GPU operates efficiently, it's essential to install the correct drivers. This section will guide you through the process of installing NVIDIA drivers on your Ubuntu system.

Installing NVIDIA Drivers

  1. Add the NVIDIA Repository:
    • First, add the official NVIDIA repository to ensure you get the latest drivers:

      sudo add-apt-repository ppa:graphics-drivers/ppa
      sudo apt update
      
  2. Install NVIDIA Drivers:
    • Next, install the latest NVIDIA drivers available:

      sudo apt install nvidia-driver-460
      
  3. Reboot Your System:
    • After the installation is complete, reboot your system to load the new drivers:

      sudo reboot
      
      

Verifying Installation

  1. Check NVIDIA Driver Installation:
    • After rebooting, open the terminal and run the following command to verify the installation:

      nvidia-smi
      
    • This command should display information about your GPU, including the driver version and GPU utilization.

Setting Up CUDA and cuDNN

CUDA and cuDNN are essential for deep learning applications, as they provide the necessary libraries for GPU acceleration. Follow these steps to set up CUDA and cuDNN on your system.

Download and Installation Instructions

  1. Download CUDA Toolkit:
  2. Install CUDA Toolkit:
    • Once the download is complete, navigate to the directory where the installer is located and run the following commands:

      sudo dpkg -i cuda-repo-<distro>_<version>_amd64.deb
      sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/<distro>/x86_64/7fa2af80.pub
      sudo apt-get update
      sudo apt-get install cuda
      
  3. Add CUDA to Your PATH:
    • Update your .bashrc file to include CUDA paths:

      echo 'export PATH=/usr/local/cuda-<version>/bin${PATH:+:${PATH}}' >> ~/.bashrc
      echo 'export LD_LIBRARY_PATH=/usr/local/cuda-<version>/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
      source ~/.bashrc
      
  4. Download cuDNN:
    • Visit the NVIDIA cuDNN Download page and download the appropriate version. Ensure you select the version compatible with your CUDA installation.
  5. Install cuDNN:
    • Extract the downloaded cuDNN files and copy them to the CUDA directories:

      tar -xzvf cudnn-<version>-linux-x64-v<version>.tgz
      sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
      sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
      sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
      

Verifying Installation

  1. Verify CUDA Installation:
    • Run the following command to check if CUDA is correctly installed and configured:

      nvcc -V
      
    • This command should display the CUDA version installed on your system.
  2. Verify cuDNN Installation:
    • To verify cuDNN installation, compile and run the cuDNN sample programs provided with the cuDNN installation package:

      cd /usr/src/cudnn_samples_v<version>/mnistCUDNN
      sudo make clean && sudo make
      ./mnistCUDNN
      
    • The output should indicate successful completion of the sample program, confirming that cuDNN is correctly installed.

By following these steps, you will have successfully prepared your system for AI development with the necessary drivers, CUDA, and cuDNN. In the next chapter, we will set up your development environment, including installing Python, creating virtual environments, and installing essential AI libraries.