Steps to install CUDA and PyTorch for QuadroK5200 GPU card
We were trying to install CUDA and Pytorch as GPU and we had search for some information for this. I wanted to just put down the things at a place so that it would be useful
1. Check if the system is able to detect the Nvidia GPU card of your system
lspci | grep -i nvidia
The result would be similar to below lines.
02:00.0 VGA compatible controller: NVIDIA Corporation GK110GL [Quadro K5200] (rev a1)
02:00.1 Audio device: NVIDIA Corporation GK110 High Definition Audio Controller (rev a1)
2. Clean or remove or uninstall all the previous versions of CUDAand its dependencies by executing the below commands
sudo apt-get purge nvidia*
sudo apt-get remove — auto-remove nvidia-cuda-toolkit
sudo apt-get remove nvidia-cuda-toolkit
sudo apt-get — purge remove “*cublas*” “cuda*” “nsight*”
sudo rm etc/apt/sources.list.d/cuda*
sudo apt remove –autoremove nvidia-cuda-toolkit
sudo apt remove –autoremove nvidia-*
sudo apt update
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*
3. Since it is old GPU card you can install CUDA 10.2 which is compatible with the Nvidia Quadro K5200 GPU card. Install the required driver files using the below commands
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
sudo dpkg -i cuda-repo-ubuntu1804–10–2-local-10.2.89–440.33.01_1.0–1_amd64.deb
sudo apt-key add /var/cuda-repo-10–2-local-10.2.89–440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
4. Update the CUDA path by updating the below environment variables and files.
sudo nano /etc/profile.d/cuda.sh
#write following lines in nano editor
export PATH=$PATH:/usr/local/cuda/bin
export CUDADIR=/usr/local/cuda
# save and exit
sudo nano /etc/ld.so.conf.d/cuda.conf
#write
/usr/local/cuda/lib64
# save and exit
sudo ldconfig
Add the below lines to ~/.bashrc and ~/.profile
# set PATH for CUDA 10.2 installation if [ -d “/usr/local/cuda/bin/” ]; then export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} fi
5. Install the latest version of cudnn7 using the below commmand
sudo apt install libcudnn7
or
5a. Install the latest version cudnn using the below command
Make sure you give your access token for YOUR_ACCESS_TOKEN
If you use step 5a then follow the steps in Appendix A for installation of cudnn
6. Reboot the computer to reflect the changes
7. Verify if the system has reflected the changes installed by running the below commands
Check the CUDA compiler driver version using,
nvcc –version
Check the nvidia driver version using,
nvidia-smi
Check the cudnn version using,
/sbin/ldconfig -N -v $(sed ‘s/:/ /’ <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn:
Now to install PyTorch for CUDA 10.2
8. Make sure you are installing PyTorch for the CUDA 10.2. Check the CUDA version
cat /usr/local/cuda/version.txt
or nvcc –version
or nvidia-smi
9. Install right version of PyTorch which supports CUDA 10.2. The PyTorch version 1.5.0 and above supports CUDA 10.2 and earlier versions does not. So you can install the version above 1.5.0
pip install torch==1.7.0 torchvision==0.8.1 -f https://download.pytorch.org/whl/cu102/torch_stable.html
10. Check if PyTorch is installed and works for CUDA 10.2 with below commands
$ python
>>> import pytorch
>>> torch.version.cuda
‘10.2’
>>> print(torch.cuda.is_available())
True
>>> torch.zeros(1).cuda()
tensor([0.], device=’cuda:0')
11. If any last command returns error then it is better to install PyTorch from source. For that you can follow the below steps
Get the source of PyTorch from github
git clone — recursive https://github.com/pytorch/pytorch
cd pytorch
# if you are updating an existing checkout
git submodule sync
git submodule update — init — recursive — jobs 0
12. Install PyTorch from the sources using below command
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-”$(dirname $(which conda))/../”}
python setup.py install
13. If there is any error due to gcc or g++ during the build then you can install the appropriate version of gcc and g++ using the below commands.
Add below lines
deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe
sudo apt update
sudo apt install g++-5 gcc-5
sudo update-alternatives — install /usr/bin/gcc gcc /usr/bin/gcc-5 5
sudo update-alternatives — install /usr/bin/g++ g++ /usr/bin/g++-5 5
sudo update-alternatives — config gcc
sudo update-alternatives — config g++
14. The build should be successful and you can verify the installation using the step 10 above.
Appendix A
Follow the below steps to install latest version of cudnn 7
1. Untar the file downloaded in step 5a, the files gets untar into cuda directory.
tar -zxf cudnn-10.2-linux-x64-v7.6.5.32.tgz
2. Copy the library files into the system library path
cd cuda/
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/* /usr/local/cuda/include/
3. Reboot the system or computer
4. Verify installation using the below command
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
Authors
Srinivas Chakravarthy — Srinivas.yeeda@gmail.com
Chandrashekar B N- chandru4ni@gmail.com