opencv: Bug compiling with CUDNN with 4.1.2

https://github.com/opencv/opencv/archive/4.1.2.zip

This version has a bug when compiling for CUDNN. File cmake/FindCUDNN.cmake is faulty and needs two corrections:

  1. location of libcudnn library is searched in the wrong file. It is seached in cudnn.h while it is in cudnn_version.h
  2. The “set” creating the CUDNN version has a problem and needs to be modified.
In file cmake/FindCUDNN.cmake
Replace:
  file(READ "${CUDNN_INCLUDE_DIR}/cudnn.h" CUDNN_H_CONTENTS) 
With:
  file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version.h" CUDNN_H_CONTENTS)

And replace:

set(CUDNN_VERSION
   "${CUDNN_MAJOR_VERSION}.${CUDNN_MINOR_VERSION}.${CUDNN_PATCH_VERSION}"
   CACHE
   STRING
   "cuDNN version"
 )

# with:
 set(CUDNN_VERSION
   "${CUDNN_MAJOR_VERSION}.${CUDNN_MINOR_VERSION}.${CUDNN_PATCH_VERSION}"
 )

And now it compiles correctly.

 cmake \
 -D CMAKE_BUILD_TYPE=RELEASE \
 -D WITH_CUDA=ON \
 -D WITH_CUDNN=ON \
 -D OPENCV_DNN_CUDA=ON \
 -D CUDA_ARCH_PTX="" \
 -D CUDA_ARCH_BIN="5.3,6.2,7.2" \
 -D WITH_CUBLAS=ON \
 -D WITH_LIBV4L=ON \
 -D BUILD_opencv_python3=ON \
 -D BUILD_opencv_python2=OFF \
 -D BUILD_opencv_java=OFF \
 -D WITH_FFMPEG=ON \
 -D WITH_GSTREAMER=ON \
 -D WITH_TBB=ON \
 -D BUILD_TBB=ON \
 -D WITH_GTK=ON \
 -D BUILD_TESTS=OFF \
 -D BUILD_PERF_TESTS=OFF \
 -D BUILD_EXAMPLES=OFF \
 -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.2/modules \
 ..

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

It works with cuDNN 8. But, cuDNN 8 does not support BACKEND. So the problem is with cuDNN 8 not with OpenCV. Until NVIDIA corrects cuDNN 8 - best avoid it with OpenCV (Any version). (cuDNN 7.6.5 works perfect) At this point the issue can be closed.

4.1.2 doesn’t have cuDNN support. It had the build setup for cuDNN but there is no functionality in that version that uses cuDNN. OpenCV 4.2 and above actually use cuDNN.

There is a PR (#17238) trying to address this new cuDNN versioning scheme.