20

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.

talonmies
  • 68,743
  • 34
  • 184
  • 258
baNv
  • 371
  • 1
  • 2
  • 10

5 Answers5

21

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)

Mona Jalal
  • 29,571
  • 61
  • 202
  • 359
rkellerm
  • 5,082
  • 8
  • 53
  • 91
  • 5
    If you use the `ln -s` command, it will fail if the symlink already exists. So remove the old symlink with a simple `sudo rm /usr/local/cuda`. (As always, be very careful with your paths when using `sudo rm`!) – Olivia Stork May 23 '18 at 15:40
  • I don't have the sudo permission, and got the following error ln: failed to create symbolic link ‘/usr/local/cuda-10.0/cuda-8.0’: Permission denied – Shuai.Z Apr 08 '19 at 05:19
  • 6
    You can also use `sudo ln -sf` to create OR update the symlink if it already exists. Then you won't need the `rm` command. – Olivia Stork May 14 '19 at 17:31
  • This doesn't work for me - after a reboot, the symlink is correct, but `nvidia-smi` gives me the wrong version. – chris Jul 31 '20 at 20:47
  • 1
    @ChrisAnderson `nvidia-smi` is showing the cuda version for driver API. Use `nvcc --version` to find out cuda version. See here https://stackoverflow.com/questions/53422407/different-cuda-versions-shown-by-nvcc-and-nvidia-smi – yuqli Aug 13 '20 at 19:18
  • Oddly `sudo ln -sf` doesn't work for me (on an Ubuntu 20.04 based distro, ln version 8.30), I agree it should do... Had no effect. Cannot reproduce in my own namespace without sudo... – Louis Maddox Apr 19 '21 at 15:06
  • 1
    @LouisMaddox check the edits I made to the post – Mona Jalal Sep 14 '21 at 17:28
10

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

paho
  • 1,102
  • 9
  • 13
  • 1
    Great thank! Your toolkit is really useful. For the most of time, I have no access to the sudo authority. – Fang WU Sep 06 '21 at 09:07
3

Perhaps cleaner:

sudo update-alternatives --display cuda

sudo update-alternatives --config cuda
w.t
  • 41
  • 3
  • This is the best answer. Simple commands, no need to install anything else, & reversible. – im0j Dec 02 '21 at 13:12
2

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
burrata
  • 41
  • 3
1

I solved the problem finally.

Modifying ~/.bash_profile to change the path to CUDA is the correct way. But when you changed the file, you need to relaunch the bash.

Simply source ~/.bash_profile won't work. Because source will only append the content in the file to the already existed path rather than cover it.

baNv
  • 371
  • 1
  • 2
  • 10