Editor Note: Pythonic employs a team of experts in engineering, AI, and machine learning. With their insights and expertise, Pythonic solutions simplify the complicated, applying cutting-edge AI to the title industry. This latest post highlights their knowledge and ongoing learning for the company and its clients.
If you've ever dived into the world of machine learning on Ubuntu 20.04 or later, you know that setting up CUDA can be like navigating a labyrinth, particularly with specific dependencies such as PyTorch, which ties to particular CUDA versions. After several frustrating attempts and combing through forums and documentation, I've finally cracked the code to install the correct CUDA version for my needs. Here are the steps that led to success.
The following are compatible on Ubuntu 20.04 or later:
Do the following to install all:
ls cuda*.run | awk '{print "sudo bash "$1" --no-drm --no-man-page --override --toolkit --silent"}' | sh
example:
#sudo bash cuda_11.0.3_450.51.06_linux.run --no-drm --no-man-page --override --toolkit --silent
Now let’s do the final setting to make sure my virtualenv is using the right CUDA version. As an example, let’s choose to use CUDA 11.1. I just simply add the following two lines to my virtualenv/bin/activate:
vim virtualenv/bin/activate
export PATH=/usr/local/cuda-11.1/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH
Now when I run
virtualenv/bin/activate
to start my virtual environment, and do “nvcc –version”, I should have:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
And if I deactivate the virtual environment, and I run “nvcc –version”, it happens that I don’t have the default nvcc, so Ubuntu complains that I should install nvidia-cuda-toolkit first:
Command 'nvcc' not found, but can be installed with:
apt install nvidia-cuda-toolkit
Please ask your administrator.
So it’s very certain that I have the CUDA installed and it could be tied to a specific virtual environment.
Please be aware that nvidia-smi gives you the CUDA driver for GUI-related applications. It could be the same as the CUDA version you just installed or very different. As a matter of fact, we installed multiple versions of CUDA. It took me quite a while to realize the CUDA version used by nvidia-smi could be different from the one on my terminal.