Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change CUDA version

I met this error when compiling a modified caffe version.

OpenCV static library was compiled with CUDA 7.5 support. Please, use the same version or rebuild OpenCV with CUDA 8.0

I have some old code may not compatible with CUDA8.0, so I want to change my cuda version for this error.

I modified my ~/.bash_profile like this

# export PYTHONPATH=$PYTHONPATH:/usr/local/cuda-8.0/lib64/
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-8.0/lib64
export PYTHONPATH=$PYTHONPATH:/usr/local/cuda-7.5/targets/x86_64-linux/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-7.5/targets/x86_64-linux/lib/

But it did't work. Still the same error. What should I do? Thanks.

like image 801
baNv Avatar asked Aug 03 '17 07:08

baNv


People also ask

How do I have multiple CUDA versions in Windows?

you can run multiple CUDA versions on windows. If you install the latest driver for your GPU it will support any CUDA recent version you select. No need to change drivers. The CUDA toolkits get installed in different locations so they can live side-by-side.


4 Answers

Change your CUDA soft link to point on your desired CUDA version. For example:

ll /usr/local/cuda lrwxrwxrwx 1 root root 19 Sep 06 2017 /usr/local/cuda -> /usr/local/cuda-8.0/

Simply relink it with

Update: If the symlink already exists, use this other command:

[jalal@goku ~]$ ls /usr/local/cuda
lrwxrwxrwx. 1 root root 20 Sep 14 08:03 /usr/local/cuda -> /usr/local/cuda-10.2

[jalal@goku ~]$ sudo ln -sfT /usr/local/cuda/cuda-11.1/ /usr/local/cuda
[jalal@goku ~]$ ls /usr/local/cuda
lrwxrwxrwx. 1 root root 26 Sep 14 13:25 /usr/local/cuda -> /usr/local/cuda/cuda-11.1/

ln -s /usr/local/cuda-7.5 /usr/local/cuda

(With the proper installation location)

like image 194
rkellerm Avatar answered Sep 21 '22 00:09

rkellerm


Maybe a bit late, but I thought it might still be helpful for anyone who comes across this question. I wrote a simple bash script for switching to a different version of CUDA within the current bash session: https://github.com/phohenecker/switch-cuda

like image 43
pho7 Avatar answered Sep 22 '22 00:09

pho7


Perhaps cleaner:

sudo update-alternatives --display cuda

sudo update-alternatives --config cuda
like image 5
w.t Avatar answered Sep 21 '22 00:09

w.t


This solution explains how you can have multiple different cuda versions installed, i.e. 10.2, 11.3 and 11.6 and switch between them. It's an extension of @w.t and makes use of update-alternatives.

Afaik, after cuda 11.x the installations on Ubuntu 20.04 cuda installations will be added to the update-alternatives maintenance automatically.

Let's say you installed cuda 10.2, cuda 11.3 and cuda 11.6 (following the official nvidia installation guide: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html). They will all reside in:

/usr/local/cuda-10.2/...
/usr/local/cuda-11.3/...
/usr/local/cuda-11.6/...

Your update-alternatives will have two entries:

$ sudo update-alternatives --query cuda
...
/usr/local/cuda-11-3 - priority 113
/usr/local/cuda-11-6 - priority 116

Solution 1: If you want to make use of the update-alternatives make sure that your cuda symbolic link points to /etc/alternatives/cuda.

# Change the symbolic link target.
$ sudo ln -sfT /etc/alternatives/cuda /usr/local/cuda
# Check the path.
$ ll /usr/local/cuda

lrwxrwrwrwx 1 root root /usr/local/cuda -> /etc/alternatives/cuda/

Now, all that is left is to make sure /etc/alternatives/cuda points to the version you want to use, e.g. 11.3.

You can make that update with:

$ sudo update-alternatives --config cuda

and follow the instructions to change the version.

Check the path:

$ ll /etc/alternatives/cuda

lrwrwrwrwx root root /etc/alternatives -> /usr/local/cuda-11.3

almost done.

And always make sure to load the correct library PATHs in your ~/.bashrc.

Solution 2: Directly set your /usr/local/cuda symbolic link to the correct version.

$ ln -sfT /usr/local/cuda-11.3 /usr/local/cuda

Reboot your machine and double check everything is set properly:

$ nvcc -V

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May3 19:15:14_PDT_2021
Cuda compilation tools, release 11.3 V11.3.109
Build cuda 11.3.r11.3/compiler.29920130_0
like image 3
burrata Avatar answered Sep 23 '22 00:09

burrata