learnopencv
learnopencv copied to clipboard
error: (-216:No CUDA support)
System information
- OpenCV => 4.5.3
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2019
- GPU ==> NVIDIA GeForce GTX 745 (compute capability: 5.0)
- CUDA version ==> 10.2
- CUDNN version ==> 8.2.0
Detailed description
I cannot use opencv with cuda. I have compiled and built opencv from source with cmake. Every time I try to use GPU with opencv I get this error message:
OpenCV(4.5.3) C:\opencv\opencv4.5.3\opencv\modules\dnn\src\dnn.cpp:2385: error: (-216:No CUDA support) OpenCV was not built to work with the selected device. Please check CUDA_ARCH_PTX or CUDA_ARCH_BIN in your build configuration. in function 'cv::dnn::dnn4_v20210608::Net::Impl::initCUDABackend'
This is the cmake configuration:
cmake ^ -G "Visual Studio 16 2019" ^ -A x64 ^ -DOPENCV_EXTRA_MODULES_PATH=%cwd%/opencv_contrib/modules ^ -DWITH_CUDA=ON ^ -DWITH_CUDNN=ON ^ -DOPENCV_DNN_CUDA=ON ^ -DWITH_CUBLAS=ON ^ -DWITH_CUBLAS=ON ^ -DCUDA_ARCH_BIN=7.5 ^ -DBUILD_opencv_world=ON ^ -DBUILD_opencv_python3=ON ^ -DPYTHON_EXECUTABLE=C:/ProgramData/Anaconda3/python.exe ^ -DPYTHON_INCLUDE_DIRS=C:/ProgramData/Anaconda3//include ^ -DPYTHON_LIBRARY=C:/ProgramData/Anaconda3//libs/python38.lib
and this is the output of CMAKE:
I also tried with -DCUDA_ARCH_BIN=5.0 because my GPU CC is 5.0, but got the same error. How can I fix this issue?
I think the installation error should now be fixed. Ref: https://github.com/opencv/opencv/issues/20706
@vikasgupta-github we can close it
Yes, the problem is OpenCV DNN doesn't work with NVidia GPU. I found that out the hard way.
If you have NVidia GPU try deep learning with other platforms, such as TensorFlow.
If you check this blog, specifically the last section, you can see how the dnn module speeds up the inference with the help of gpu support.
I had the same problem. It was because I built it with the wrong CC indeed. However, I was also missing this:
CUDA_GENERATION=Auto
So my whole command is
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=ON \
-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 ..
I know the issue is marked to be closed but I figure this could help someone who had the same problem as I did :)
Also remember to rm -rf *
in build
directory before running the conf and build again just to make sure everything goes correctly.