0

I build OpenCV 3.4. with Cuda 10.0 support in "/usr"local/opencv_custom" like this:

cmake -D CMAKE_BUILD_TYPE=RELEASE 
-D CMAKE_INSTALL_PREFIX=/usr/local/opencv_custom
-D OPENCV_GENERATE_PKGCONFIG=ON
-D OPENCV_DNN_CUDA=ON
-D INSTALL_C_EXAMPLES=ON
-D INSTALL_PYTHON_EXAMPLES=ON
-D OPENCV_EXTRA_MODULES_PATH=/home/ohmnibot/opencv_contrib/modules
-D BUILD_EXAMPLES=ON
-D BUILD_opencv_python2=OFF
-D WITH_FFMPEG=1
-D WITH_CUDA=ON
-D WITH_OPENGL=ON
-D ENABLE_FAST_MATH=1
-D CUDA_FAST_MATH=1
-D WITH_CUBLAS=0
-D WITH_LAPACK=OFF
-D BUILD_opencv_cudacodec=OFF
-D CUDA_VERSION=10.0 ..

All is fine but when I try to include this opencv version in my CMakeList like this

set(OpenCV_DIR "/usr/local/opencv_custom")
find_package(OpenCV REQUIRED)

I get this error:

Could NOT find CUDA: Found unsuitable version "10.2", but required is exact
  version "10.0" (found /usr/local/cuda-10.0)

Now I had cuda 10.2 installed but I removed every possible trace of it and only cuda 10.0 exists on my system (as far as I know). Also I just don´t get this message.... cuda 10.0 has been found but its unsuitable because its the wrong version even though... well its the right one?

I don´t know this just confuses the hell out of me... any help is deeply appreciated.

I´m working with catkin on a Ubuntu 18.04 system with a GTX 1650.

Old cuda versions have been removed with

sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*"
sudo rm -rf /usr/local/cuda*

nvcc -V output:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

nvidia-smi output:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.66       Driver Version: 450.66       CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| 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  GeForce GTX 1650    Off  | 00000000:07:00.0  On |                  N/A |
| 35%   29C    P8     8W /  75W |    447MiB /  3908MiB |      3%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
ItsMeTheBee
  • 353
  • 2
  • 20
  • What is ur OS? What is your gpu ? – Yunus Temurlenk Sep 04 '20 at 08:51
  • OS is Ubuntu 18.04, GPU is GTX 1650 – ItsMeTheBee Sep 04 '20 at 08:59
  • "but I deleted every possible trace of it " -- plainly you didn't – talonmies Sep 04 '20 at 10:22
  • Deleting files not a safe way why you not uninstall as like installed ? What is your driver version ? – Yunus Temurlenk Sep 04 '20 at 10:39
  • I didn mean that I just deleted the files.... I uninstalled it using sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*" and sudo rm -rf /usr/local/cuda* and then installed cuda on what I thought would be a clean sytem driver version is 450.66 – ItsMeTheBee Sep 04 '20 at 11:04
  • @talonmies well I searched around a bit and according to stackoverflow the method I used should do the trick... if not what should I do to get rid of the rest? Or rather what is even left? – ItsMeTheBee Sep 04 '20 at 11:33
  • Search your filesystem thoroughly. Then make sure this isn't just CMake caching an old failed build – talonmies Sep 04 '20 at 11:35
  • yeez... so I´m working with catkin and the error message changed after I deleted everything and installed cuda, tensorrt etc from scratch so I didn´t thing that it could be a caching problem but it was... after building from scratch it worked like a charm. I´m so mad at myself right now, this took way too long to figure out :D And your profile description is very accurate... sorry for adding one more rather stupid question to your list :D – ItsMeTheBee Sep 04 '20 at 11:53

2 Answers2

2

Just in case someone every manages to run into a similar error:

  • delete all the build files
  • rebuild
  • enjoy
ItsMeTheBee
  • 353
  • 2
  • 20
0

I have ran into this problem a few times. The accepted answer has worked for me a few times but not always. I think adding the following brings value to anyone who has similar problems.


Check the values of variables PATH and LD_LIBRARY_PATH

You can check the value like this:

echo ${PATH}
echo ${LD_LIBRARY_PATH}

I had the wrong CUDA version there and I corrected it using a text editor like this:

nano ~/.bashrc

Search for PATH (using nano press ctrl+W to find). I had these at the very bottom:

PATH=$PATH:/usr/local/cuda-11.8/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64

and surprisingly I had wrong CUDA version there. I corrected it using text editor to what I wanted (in my case 11.6).

Note that this only changes the variables. You must check that you really have the right version of CUDA at /usr/local/cuda-* and that your /usr/local/cuda is pointing to the right place. We will check that next:


Check that cuda points to the correct version

As shown here,

cd /usr/local
ls -l | grep cuda

then see which versions of CUDA you see there. For me I have only one but I used to have many

/usr/local$ ls -l | grep cuda
lrwxrwxrwx  1 root root    21 tammi  10 15:15 cuda -> /usr/local/cuda-11.6/
drwxr-xr-x 16 root root  4096 tammi  10 15:16 cuda-11.6

that hints that I don't have any conflicting CUDA installations. But you might have that if you have several versions installed.

This answer might be helpful, too.


Check that OpenCV is searching for the correct version

when you're running the configuration step of OpenCV build, check that the -D CUDA_VERSION is right:

cd build-opencv
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_GENERATION=AUTO -D WITH_CUBLAS=1 -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=OFF -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D CUDA_ARCH_BIN=8.6 -D CUDA_GENERATION=Auto -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=OFF -D WITH_GSTREAMER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv.pc -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D CUDA_VERSION=11.6 -D CUDA_NVCC_FLAGS="-ccbin gcc-8"

then, double check that the prints after this command are what you expect and possibly save them to a text file. They are really helpful:

-- CUDA detected: 11.6
-- CUDA NVCC target flags: -ccbin gcc-8;-gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES

(skipping many other lines...)

--   NVIDIA CUDA:                   YES (ver 11.6, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             86
--     NVIDIA PTX archs:
-- 
--   cuDNN:                         YES (ver 8.7.0)
-- 

Add -D CUDA_TOOLKIT_ROOT_DIR

This answer and this thread might be outdated but if nothing else helps you it doesn't hurt to check them.


Check that you really made a clean build

I rebuilt my OpenCV a couple of times but it didn't really help. The reason might be that I didn't remove all OpenCV -related files.

sudo make uninstall

as well as removing associated files:

sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*

If you want to be super careful, please also check the output of this

sudo find / -name "*opencv*"

as different versions of OpenCV might have different install directories.

Other

Then, you also have the option of uninstalling OpenCV, removing all build files, uninstalling CUDA and starting from scratch. Make sure you follow the CUDA installation guides carefully and perform all pre- and post-installation steps. In addition, make sure you have followed all installation steps of OpenCV here, here and here. Please check the output of all steps for errors that might have been left unseen earlier.

Remember to make a clean build of your application after reinstalling CUDA and OpenCV as well as restarting your PC and/or refreshing your environment variables.

Eljas Hyyrynen
  • 233
  • 1
  • 11