'How to find CUDNN with CMake?
Apparently I correctly installed CUDA and CUDNN, but still FindCUDA finds CUDA, but FindCUDNN.cmake does not find CUDNN
What else should I check to debug this?
OS: Windows 10
cmake version 3.17.2
CUDA Version 10.2
CUDNN version cudnn-10.2-windows10-x64-v7.6.5.32
CUDA installed with installer, to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2
CUDNN files copied into respective bin, include, and lib folders
[cmake] -- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2 (found version "10.2")
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
[cmake] Could NOT find CUDNN (missing: CUDNN_LIBRARY CUDNN_INCLUDE_DIR)
[cmake] Call Stack (most recent call first):
[cmake] C:/Program Files/CMake/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
[cmake] cmake/FindCUDNN.cmake:90 (find_package_handle_standard_args)
[cmake] CMakeLists.txt:17 (find_package)
The FindCUDNN.cmake: https://gist.github.com/WurmD/26af2940d8dec7cc48d38bc30fd1b3ef
Solution 1:[1]
...
set "cudaRoot=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.3"
...
-DCUDNN_LIBRARY="%cudaRoot%\lib" ^
-DCUDNN_INCLUDE_DIR="%cudaRoot%\include" ^
...
Solution 2:[2]
I was compiling OpenCV with Visual Studio 2019; so I'll just go ahead and assume you were too - since I'm tired and I just got this issue resolved for myself.
- Be sure to REBOOT/RESTART your PC after "installation" of CUDNN
- Do a fresh GIT clone of opencv as well as opencv_contrib
- Be sure to make the BUILD folder in the opencv directory
- Set your required environmental variables; something like this but fill in your paths:
set "CUDA_PATH=............/NVIDIA GPU Computing Toolkit/CUDA/v11.0"
set "opencvSource=opencv"
set "opencvExtraModules=opencv_contrib\modules"
set "opencvBuild=%opencvSource%\build"
set "compiler=Visual Studio 16 2019"
set "buildType=Release"
set "python3_executable=............/AppData/Local/Programs/Python/Python38/python.exe"
set "python3_include_dir=............/AppData/Local/Programs/Python/Python38/include"
set "python3_library=............/AppData/Local/Programs/Python/Python38/libs/python38.lib"
set "python3_numpy_include_dirs=............/AppData/Local/Programs/Python/Python38/Lib/site-packages/numpy/core/include"
set "python3_packages_path=............/AppData/Local/Programs/Python/Python38/Lib/site-packages"
- Re-run CMAKE (obviously change this to match your options), mine were:
cmake ^
-B"%opencvBuild%/" ^
-H"%opencvSource%/" ^
-G"%compiler%" ^
-Ax64 ^
-DCMAKE_BUILD_TYPE=%buildType% ^
-DBUILD_opencv_python3=ON ^
-DBUILD_opencv_world=ON ^
-DBUILD_EXAMPLES=OFF ^
-DBUILD_opencv_python_bindings_generator=ON ^
-DOPENCV_PYTHON3_VERSION=3.8.3 ^
-DPYTHON3_EXECUTABLE="%python3_executable%" ^
-DPYTHON3_INCLUDE_DIR="%python3_include_dir%" ^
-DPYTHON3_LIBRARY="%python3_library%" ^
-DPYTHON3_NUMPY_INCLUDE_DIRS="%python3_numpy_include_dirs%" ^
-DPYTHON3_PACKAGES_PATH="%python3_packages_path%" ^
-DINSTALL_TESTS=OFF ^
-DINSTALL_C_EXAMPLES=OFF ^
-DOPENCV_EXTRA_MODULES_PATH="%opencvExtraModules%/" ^
-DWITH_CUDA=ON ^
-DCUDA_ARCH_BIN=6.1^
-DCUDA_ARCH_PTX=7.5^
-DCUDA_FAST_MATH=ON ^
-DBUILD_PROTOBUF=ON
Solution 3:[3]
With a fresh install of CuDNN, make sure to remove the cache of CMake via File and then Delete Cache. This will remove all settings, but recognize CuDNN.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lei Chen |
| Solution 2 | Kyle |
| Solution 3 | Chris Fowl |




