0

I have both CUDA versions 7.5 and 8.0 installed but cmake seems to only be able to find the 7.5 version. Running this code:

find_package(CUDA 8.0 REQUIRED)

Gives this error:

CMake Error at P:/Program Files/CMake/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find CUDA: Found unsuitable version "7.5", but required is at
  least "8.0" (found C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.5)

Even though v8.0 is in the same directory as v7.5. Is this a problem with cmake, or am I doing something wrong here?

Moody
  • 1,297
  • 2
  • 12
  • 21
  • Related thread with many solutions: https://stackoverflow.com/questions/63737492/opencv-claims-to-find-wrong-cuda-version/75080353#75080353 – Eljas Hyyrynen Jan 11 '23 at 08:51

2 Answers2

4
  1. No matter how many CUDA toolkits you have installed find_package(CUDA) finds the one that has its nvcc (typically located in <CUDA root dir>/bin) in the environment variable $PATH. If there are several nvcc in $PATH, it will pick up the first one. On windows, installer typically adds relevant environment variables automatically, so the version found depends on the order of installation.

  2. You should not be using find_package(CUDA) anymore as CMake now has first-class support for CUDA.

For details check:

Ivan Aksamentov - Drop
  • 12,860
  • 3
  • 34
  • 61
  • That's the documentation but that's not what it actually is doing, that's why there are thousands of people asking online how to get it running. It's an intense multi-layered compatibility issue with cuda and the microsoft compilers, the way the target packages are distributed (or found) which cmake generator is chosen. – John Jul 20 '23 at 14:59
2

You could feed CMake with the path to CUDA explicitly, by setting the CUDA_TOOLKIT_ROOT_DIR flag from CMake command line:

cmake -DCUDA_TOOLKIT_ROOT_DIR=<path-to-cuda-8.0>.

CUDA version detection is done by CMake's findCUDA function: https://cmake.org/cmake/help/v3.0/module/FindCUDA.html

It's possible that for some reason, findCUDA search fails to locate CUDA 8.0 you have installed.
It might be that CUDA_BIN_PATH is set to 7.5, and therefore CMake picks that.

valiano
  • 16,433
  • 7
  • 64
  • 79
  • Do you mean I have to set that using the "set" command inside CMakelists? I'm new to CMake, but I thought the whole point of using it is to avoid having to manually set stuff? – Moody Oct 01 '17 at 18:00
  • You can set the CUDA flag in CMake's command line - I edited the answer to clarify. Yes, ideally CMake should find packages automatically for you, but in this case, there may be some issue with CMake's CUDA search, when there are multiple CUDA versions installed. – valiano Oct 01 '17 at 20:00
  • It seems that, CMake picks the first CUDA version it finds, and then checks that the version matches the one specified in `CMakeLists.txt` (rather then continuing to search for the specified version). – valiano Oct 01 '17 at 20:20