ATTENTION (16 Apr 2023): From 6.0.6, you can use the latest CUDA to run eddy_cuda10.2. So this post is obsolete. I wrote a new post, so please check it out.
FSL 6.0.5 ships eddy_cuda10.2 which literally uses CUDA 10.2.
I explored a way to use eddy_cuda10.2, PyTorch and Tensorflow concurrently. Below is How-To for Ubuntu 18.04/20.04.
Install Kernel Header
- We need to install a kernel header. You can do with the following command.
sudo apt install linux-headers-$(uname -r)
- Reboot after install.
reboot
Install CUDA 10.2, 11.0, and 11.5
- NVIDIA provides a good page for the installation of various versions of CUDA. As of CUDA 10.2, cuda-10.2-download-archive shows everything.
-
This page is archive, so it provides only Ubuntu 18.04, but it works well with Ubuntu 20.04. Actually, if you want to use CUDA 10.2, you MUST use repository for Ubuntu 18.04, because repo for 20.04 doesn’t include CUDA 10.2.
- Below is the screenshot of instruction.
- According to the instruction. Here is what I did. I made some modifications to install various versions of CUDA. As of January 3rd, 2022, you can install cuda from 10.0 to 11.5. We need 11.0 for running Tensorflow. So I decided to install 10.2, 11.0, and 11.5 which is the latest one. When installing CUDA, it might be better to use –no-install-recommends in order to install only necessary files.
-
N.B. On April 28 2022, Repository key for NVIDIA was updated, so I updated the commands below.
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-keyring_1.0-1_all.deb sudo dpkg -i cuda-keyring_1.0-1_all.deb sudo apt update sudo apt -y install --no-install-recommends cuda-10-2 cuda-11-0 cuda-11-5
- Reboot again.
reboot
- Check if the system recognizes CUDA using nvidia-smi.
$ nvidia-smi Sat Dec 11 19:02:12 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 495.29.05 Driver Version: 495.29.05 CUDA Version: 11.5 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... On | 00000000:02:00.0 On | N/A | | 9% 48C P8 18W / 175W | 62MiB / 7979MiB | 1% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 836 G /usr/lib/xorg/Xorg 60MiB | +-----------------------------------------------------------------------------+
Changing CUDA
- Ubuntu has “update-alternatives” with which we can change versions of software easily.
- We will use this function to switch different versions of CUDA.
- First, we need to run “update-alternatives –install” I want to prioritize 10.2, so the number is large (100) among the three.
sudo update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-11.5 80 sudo update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-11.0 90 sudo update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-10.2 100
- Then, run “update-alternatives –config”
sudo update-alternatives --config cuda
- You will see the following dialog.
$ sudo update-alternatives --config cuda There are 3 choices for the alternative cuda (providing /usr/local/cuda). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/local/cuda-11.5 80 auto mode 1 /usr/local/cuda-10.2 100 manual mode 2 /usr/local/cuda-11.0 90 manual mode 3 /usr/local/cuda-11.5 80 manual mode Press <enter> to keep the current choice[*], or type selection number:
- We would like to use cuda-10.2, so type 1 and Enter.
-
Then we get the following message.
update-alternatives: using /usr/local/cuda-10.2 to provide /usr/local/cuda (cuda) in manual mode
PATH Settings
- Official site of NVIDIA provides the Post-installation action and gives an instruction for PATH settings.
-
I myself prefer not to edit .bashrc but use .bash_aliases for safety reasons. .bash_aliases is originally for setting up aliases, but you can write PATH settings.
-
Write the following to .bashrc (or .bash_aliases). The point is that you list all versions of CUDA in LD_LIBRARY_PATH
# CUDA export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-10.2/lib64:/usr/local/cuda-11.0/lib64:/usr/local/cuda-11.5/lib64${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}}
- exit terminal and run it again.
Check CUDA
- nvcc –version will show the version of CUDA in use.
$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA Corporation Built on Wed_Oct_23_19:24:38_PDT_2019 Cuda compilation tools, release 10.2, V10.2.89
- Now we see CUDA 10.2 is in use.
If you just want to use eddy_cuda, you are set to go. You don7t have to install cuDNN.
Below is the instruction for PyTorch and Tensorflow.
Install cuDNN (IMPORTANT)
- I found this is the trick for various versions of CUDA to co-exist.
- cuDNN is a GPU-accelerated library for deep neural networks.
- You need to get cuDNN for each version of CUDA from NVIDIA’s CuDNN Archive. You need to register to get the files. Don’t install cuDNN from Ubuntu repository because it overrides previous versions when a new version is available.
- We installed three versions of CUDA, so we will get cuDNN for these three versions.
- For example, we can use v8.3.0 for CUDA 11.5 as of Jan 3 2022. Select “cuDNN Library for Linux (x86_64)” and we’ll get cudnn-11.5-linux-x64-v8.3.0.98.tgz.
-
extracting the archive will generate a directory “cuda”. This can be confusing, so we make directories for each.
mkdir cudnn-10.2 cudnn-11.x cudnn-11.5
- Get the following files. cudnn-11.x corresponds to 11.0,1,2,3.
- cudnn-10.2: cudnn-10.2-linux-x64-v8.3.0.98.tgz
- cudnn-11.x: cudnn-11.3-linux-x64-v8.2.1.32.tgz
- cudnn-11.5: cudnn-11.5-cudnn-11.5-linux-x64-v8.3.0.98.tgz
- Extract each tgz file and copy the contents to corresponding CUDA directory.
cd cudnn-10.2 tar xvzf cudnn-10.2-linux-x64-v8.3.0.98.tgz sudo cp cuda/include/cudnn* /usr/local/cuda-10.2/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.2/lib64
cd ../cudnn-11.x tar xvzf cudnn-11.3-linux-x64-v8.2.1.32.tgz sudo cp cuda/include/cudnn* /usr/local/cuda-11.0/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.0/lib64
cd ../cudnn-11.5 tar xvzf cudnn-11.5-linux-x64-v8.3.0.98.tgz sudo cp cuda/include/cudnn* /usr/local/cuda-11.5/include sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.5/lib64
Install PyTorch
- Get Started page of PyTorch gives us instruction what to do by selecting our circumstances. Selecting Linux, Pip, and CUDA 10.2 result in a simple command.
pip3 install torch torchvision torchaudio
- We check the installation of PyTorch according to the official website.
- After running Python3, we import PyTorch, generate 5×3 matrix, then check if CUDA is available for PyTorch.
import torch x = torch.rand(5, 3) print(x) tensor([[0.7864, 0.5164, 0.2328], [0.5295, 0.4627, 0.1464], [0.9955, 0.1817, 0.9645], [0.2252, 0.5114, 0.2045], [0.4405, 0.2104, 0.5069]])
torch.cuda.is_available() True
- Success!
Install Tensorflow
- Tensorflow is not tested for CUDA 10.2. Here is the source. We need CUDA 11.0 and we already installed it.
- Tensorflow itself can be installed with pip easily.
pip3 install tensorflow
Check Tensorflow
- We check if Tensorflow recognizes GPU. We follow the instruction of Tensorflow website. Run Python3 and run the following commands.
import tensorflow as tf gpu_available = tf.test.is_gpu_available()
- The result is the following;
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use `tf.config.list_physical_devices('GPU')` instead. 2021-12-11 21:06:25.921787: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set ... tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/device:GPU:0 with 7261 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 2070, pci bus id: 0000:02:00.0, compute capability: 7.5)
It went well!
Summary
- FSL 6.0.5 ships eddy_cuda 10.2, so if you would like to use eddy_cuda, the fastest way is to install CUDA 10.2
- Using the Ubuntu 18.04 repository works well.
- CuDNN needs to be fetched from NVIDIA website.
- PyTorch can be installed easily with CUDA 10.2.
- Tensorflow can be used by installing CUDA 11.0.