thecanadianroot / opencv-cuda-docker

GNU General Public License v3.0
22 stars 8 forks source link

How to build opencv with CUDA and cuDNN? #10

Open jiongjiongJOJO opened 1 year ago

jiongjiongJOJO commented 1 year ago

I see that the workflow containing cuDNN is written in the repository's workflow, but I noticed during execution via GitHub Action that the compiled parameters are as follows:

#14 23.50 --   OpenCV modules:
#14 23.50 --     To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
#14 23.50 --     Disabled:                    world
#14 23.50 --     Disabled by dependency:      -
#14 23.50 --     Unavailable:                 cvv java julia matlab ovis ts
#14 23.51 --     Applications:                apps
#14 23.51 --     Documentation:               NO
#14 23.51 --     Non-free algorithms:         YES
#14 23.51 -- 
#14 23.51 --   GUI:                           GTK3
#14 23.51 --     GTK+:                        YES (ver 3.24.20)
#14 23.51 --       GThread :                  YES (ver 2.64.6)
#14 23.51 --       GtkGlExt:                  NO
#14 23.51 --     VTK support:                 YES (ver 6.3.0)
#14 23.51 -- 
#14 23.51 --   Media I/O: 
#14 23.51 --     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
#14 23.51 --     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
#14 23.51 --     WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020e)
#14 23.51 --     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
#14 23.51 --     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
#14 23.51 --     JPEG 2000:                   OpenJPEG (ver 2.3.1)
#14 23.51 --     OpenEXR:                     build (ver 2.3.0)
#14 23.51 --     HDR:                         YES
#14 23.51 --     SUNRASTER:                   YES
#14 23.51 --     PXM:                         YES
#14 23.51 --     PFM:                         YES
#14 23.51 -- 
#14 23.51 --   Video I/O:
#14 23.51 --     DC1394:                      YES (2.2.5)
#14 23.51 --     FFMPEG:                      YES
#14 23.51 --       avcodec:                   YES (58.54.100)
#14 23.51 --       avformat:                  YES (58.29.100)
#14 23.51 --       avutil:                    YES (56.31.100)
#14 23.51 --       swscale:                   YES (5.5.100)
#14 23.51 --       avresample:                YES (4.0.0)
#14 23.51 --     v4l/v4l2:                    YES (linux/videodev2.h)
#14 23.52 -- 
#14 23.52 --   Parallel framework:            pthreads
#14 23.52 -- 
#14 23.52 --   Trace:                         YES (with Intel ITT)
#14 23.52 -- 
#14 23.52 --   Other third-party libraries:
#14 23.52 --     Intel IPP:                   2020.0.0 Gold [2020.0.0]
#14 23.52 --            at:                   /tmp/opencv-4.5.4/build/3rdparty/ippicv/ippicv_lnx/icv
#14 23.52 --     Intel IPP IW:                sources (2020.0.0)
#14 23.52 --               at:                /tmp/opencv-4.5.4/build/3rdparty/ippicv/ippicv_lnx/iw
#14 23.52 --     VA:                          NO
#14 23.52 --     Lapack:                      NO
#14 23.52 --     Eigen:                       YES (ver 3.3.7)
#14 23.52 --     Custom HAL:                  NO
#14 23.52 --     Protobuf:                    build (3.5.1)
#14 23.52 -- 
#14 23.52 --   NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
#14 23.52 --     NVIDIA GPU arch:             60
#14 23.52 --     NVIDIA PTX archs:            87
#14 23.52 -- 
#14 23.52 --   cuDNN:                         NO
#14 23.52 -- 
#14 23.52 --   OpenCL:                        YES (no extra features)
#14 23.52 --     Include path:                /tmp/opencv-4.5.4/3rdparty/include/opencl/1.2
#14 23.52 --     Link libraries:              Dynamic load
#14 23.52 -- 
#14 23.52 --   Python 2:
#14 23.52 --     Interpreter:                 /usr/bin/python2.7 (ver 2.7.18)
#14 23.52 --     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.18)
#14 23.52 --     numpy:                       /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.5)
#14 23.52 --     install path:                lib/python2.7/dist-packages/cv2/python-2.7
#14 23.52 -- 
#14 23.52 --   Python 3:
#14 23.52 --     Interpreter:                 /usr/bin/python3 (ver 3.8.10)
#14 23.52 --     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.10)
#14 23.52 --     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.17.4)
#14 23.52 --     install path:                lib/python3.8/dist-packages/cv2/python-3.8
#14 23.52 -- 
#14 23.52 --   Python (for build):            /usr/bin/python2.7
#14 23.52 -- 
#14 23.53 --   Java:                          
#14 23.53 --     ant:                         NO
#14 23.53 --     JNI:                         NO
#14 23.53 --     Java wrappers:               NO
#14 23.53 --     Java tests:                  NO
#14 23.53 -- 
#14 23.53 --   Install to:                    /usr/local
#14 23.53 -- -----------------------------------------------------------------
#14 23.53 -- 
#14 25.41 -- Configuring done
#14 26.22 -- Generating done
#14 26.23 -- Build files have been written to: /tmp/opencv-4.5.4/build

There is a line with cuDNN:NO which does not show that cuDNN is not compiled, and also the docker image after successful compilation does not use cuDNN for acceleration properly. I have a guess, I don't know if it's correct: GitHub Action's virtual server doesn't have GPU and can't compile OpenCV with cuDNN module. I'd like to ask the author to confirm if it's correct.

thecanadianroot commented 1 year ago

Hi, looks like you are right. GitHub Actions don't have support for GPU enabled runners at the moment. I am not aware if a GPU is needed in order to build the CUDNN module.

jiongjiongJOJO commented 1 year ago

After a few days of testing, I found that the GitHub virtual runtime environment does not come with a GPU and cannot compile OpenCV_CUDA_CUDNN source code. I also found that I cannot compile OpenCV_CUDA_CUDNN source code (on a physical machine with a GPU) via https://github.com/thecanadianroot/opencv-cuda-docker/blob/main/Dockerfile for the following reasons: https://github.com/thecanadianroot/opencv-cuda-docker/blob/499cb314c961a6edf2c91c368c143727b5588cad/Dockerfile#L5 The above code specifies that the cudnn is not included in the The solution is to use a Docker image that contains a cudnn environment, such as 11.7.0-cudnn8-devel-ubuntu18.04, where the tag contains the word cudnn8, in order to properly compile To get out of OpenCV with CUDNN~

thecanadianroot commented 1 year ago

Hi, yes, I've found that out on monday. I am working on newer workflows and newer versions of the image in a branch. You should be able to see the GitHub Actions job runs of the past two days that are now able to compile with cudnn. I am in the process of gathering all the useful dependencies needed to compile opencv on Ubuntu 18.04, 20.04 and 22.04. Please see this branch: https://github.com/thecanadianroot/opencv-cuda-docker/tree/feat/newer-workflows-and-versions