CUDA (Compute Unified Device Architecture) is a parallel computing platform developed by NVIDIA. CUDA allows developers to utilize the power of GPUs to accelerate their applications. CUDNN (CUDA Deep Neural Network) is a library developed by NVIDIA that accelerates the training and inference process in deep learning.
The use of CUDA and CUDNN is very important for deep learning application developers, because by using CUDA and CUDNN, the training and inference process of deep learning models will be faster than using CPU alone.
CUDA Installation
Before installation, we first make sure whether our GPU supports CUDA, run the following command in the terminal:
|
|
If you already have the driver installed, we need to remove the driver first. To remove the NVIDIA driver, run the following command:
|
|
Make sure our operating system is updated, run the following command:
|
|
Then install some other packages that are needed:
|
|
Add the CUDA repository to our operating system:
|
|
To see the recommended driver for our GPU, run the following command:
|
|
An example output of the above command is as follows:
|
|
In the example above, the recommended driver is nvidia-driver-535
, so we will install the driver:
|
|
After the above command has finished running, reboot our operating system:
|
|
Check NVIDIA Driver
After our operating system reboots, we need to make sure the NVIDIA driver is installed correctly. To check, run the following command:
|
|
If the NVIDIA driver is installed correctly, the following output will appear:
|
|
CUDA Toolkit Installation
For CUDA Toolkit installation, we need to match the version of Tensorflow that we want to use.
The following table shows the CUDA Toolkit version that matches the Tensorflow version:
Version | Python version | Compiler | Build tools | cuDNN | CUDA |
---|---|---|---|---|---|
tensorflow-2.16.1 | 3.9-3.12 | Clang 17.0.6 | Bazel | 6.5.0 | 8.9 12.3 |
tensorflow-2.15.0 | 3.9-3.11 | Clang 16.0.0 | Bazel | 6.1.0 | 8.9 12.2 |
tensorflow-2.14.0 | 3.9-3.11 | Clang 16.0.0 | Bazel | 6.1.0 | 8.7 11.8 |
tensorflow-2.13.0 | 3.8-3.11 | Clang 16.0.0 | Bazel | 5.3.0 | 8.6 11.8 |
tensorflow-2.12.0 | 3.8-3.11 | GCC 9.3.1 | Bazel | 5.3.0 | 8.6 11.8 |
For more details, please see the tensorflow documentation. : https://www.tensorflow.org/install/source#gpu
Here I will exemplify the installation of CUDA Toolkit version 11.8, here are the steps:
Open the CUDA Toolkit download page according to the desired version at : https://developer.nvidia.com/cuda-toolkit-archive
Select the desired CUDA Toolkit version, here I will choose version 11.8, then select the OS, Architecture, and distro that matches our operating system. For example I will use the installer type
runfile (local)
. Then download the file.
Follow the steps given by the CUDA Toolkit installer, and make sure to install the NVIDIA drivers included in the CUDA Toolkit installer. For example, I will run the following command for CUDA Toolkit installation:
|
|
The above command will run the CUDA Toolkit installer, follow the steps given by the installer.
Because we have previously installed the required drivers, in the CUDA installation with runfile
we do not need to install the NVIDIA driver included in the CUDA Toolkit installer. For that we need to change the NVIDIA driver installation option by unchecking the option.
In the image above, we need to uncheck the Driver option.
Then follow the installation steps until it is complete.
After the installation is complete, we need to add the CUDA environment variable into the .bashrc
file run the command line by line:
|
|
The above command will add the CUDA environment variable to the .bashrc
file and update the environment variable.
sudo ldconfig
will update the libraries in our operating system.
CUDNN Installation
Open the CUDNN download page for the desired version at : https://developer.nvidia.com/rdp/cudnn-archive. Here I will install CUDNN version 8.6.0, select the desired version, then download the file.
After the CUDNN file has been downloaded, extract the file:
|
|
Then copy the necessary files into the CUDA Toolkit directory:
|
|
After that, we need to add the CUDNN environment variable to the .bashrc
file:
|
|
After that, we need to check whether the CUDA and CUDNN installation was successful or not, run the following command:
|
|
If the CUDA and CUDNN installation is successful, the following output will appear:
|
|
Conclusion
Until now, we have successfully installed CUDA and CUDNN. With the installation of CUDA and CUDNN, we can utilize the GPU to speed up the training and inference process in deep learning. Furthermore, we can install deep learning libraries such as Tensorflow, Pytorch, and others that utilize CUDA and CUDNN to speed up the training and inference process of deep learning models. If you have any questions, please write them in the comments column. Thank you for reading this article.