Open10

copencv + cuda ビルドテスト

PINTOPINTO
mkdir opencvbuild && cd opencvbuild

git clone -b 4.5.5 https://github.com/opencv/opencv.git
git clone -b 4.5.5 https://github.com/opencv/opencv_contrib.git

docker run -it --rm --gpus all \
-v `pwd`:/home/user/workdir \
-e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility \
nvidia/cuda:11.4.2-cudnn8-devel-ubuntu20.04

cd /home/user/workdir && cd opencv && mkdir -p build && cd build
PINTOPINTO
export DEBIAN_FRONTEND=noninteractive \
&& apt update \
&& apt install -y python3-dev python3-pip gcc-7 g++-7 cmake wget \
build-essential git pkg-config ccache libxshmfence-dev libasound2-dev \
unzip extra-cmake-modules mesa-utils libgtk-3-dev ffmpeg nano \
libavcodec-dev libavformat-dev libswscale-dev libtbb-dev libogre-1.9-dev \
libjpeg-dev libpng-dev libtiff5-dev x264 libxvidcore-dev yasm \
libxine2-dev libv4l-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev \
libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev \
x264 v4l-utils ffmpeg libdc1394-22 libdc1394-22-dev libtiff5-dev \
qt5-default libeigen3-dev libeigen3-doc tesseract-ocr tesseract-ocr-jpn \
vtk7 tcl-vtk7 python3-vtk7 libgflags-dev autoconf automake libtool \
autoconf-archive libleptonica-dev libtesseract-dev gphoto2 liblapacke-dev \
libgstreamer1.0-0 gstreamer1.0-tools gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc \
gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa \
gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 libhdf5-dev \
libatlas-base-dev gstreamer1.0-opencv libva-dev python-is-python3 \
&& sed -i 's/# set linenumbers/set linenumbers/g' /etc/nanorc \
&& pip3 install pip --upgrade \
&& pip3 install onnx onnxruntime \
&& pip3 install numpy==1.21.5 \
&& pip3 install numba==0.55.1
PINTOPINTO
# GTX1650
COMPCAPA=7.5

# RTX3070
COMPCAPA=8.6
cmake \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DCUDA_ARCH_BIN=${COMPCAPA} \
-DCUDA_ARCH_PTX=${COMPCAPA} \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DBUILD_EXAMPLES=ON \
-DBUILD_opencv_apps=ON \
-DBUILD_opencv_calib3d=ON \
-DBUILD_opencv_core=ON \
-DBUILD_opencv_cudaarithm=ON \
-DBUILD_opencv_cudabgsegm=ON \
-DBUILD_opencv_cudacodec=ON \
-DBUILD_opencv_cudafeatures2d=ON \
-DBUILD_opencv_cudafilters=ON \
-DBUILD_opencv_cudaimgproc=ON \
-DBUILD_opencv_cudalegacy=ON \
-DBUILD_opencv_cudaobjdetect=ON \
-DBUILD_opencv_cudaoptflow=ON \
-DBUILD_opencv_cudastereo=ON \
-DBUILD_opencv_cudawarping=ON \
-DBUILD_opencv_cudev=ON \
-DBUILD_opencv_features2d=ON \
-DBUILD_opencv_flann=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_imgcodecs=ON \
-DBUILD_opencv_imgproc=ON \
-DBUILD_opencv_ml=ON \
-DBUILD_opencv_objdetect=ON \
-DBUILD_opencv_photo=ON \
-DBUILD_opencv_stitching=ON \
-DBUILD_opencv_superres=ON \
-DBUILD_opencv_ts=ON \
-DBUILD_opencv_video=ON \
-DBUILD_opencv_videoio=ON \
-DBUILD_opencv_videostab=ON \
-DWITH_1394=ON \
-DWITH_CUBLAS=ON \
-DWITH_CUDA=ON \
-DWITH_CUFFT=ON \
-DWITH_EIGEN=ON \
-DWITH_FFMPEG=ON \
-DWITH_GDAL=OFF \
-DWITH_GPHOTO2=ON \
-DWITH_GIGEAPI=ON \
-DWITH_GSTREAMER=ON \
-DWITH_GTK=ON \
-DWITH_INTELPERC=OFF \
-DWITH_IPP=ON \
-DWITH_IPP_A=OFF \
-DWITH_JASPER=ON \
-DWITH_JPEG=ON \
-DWITH_LIBV4L=ON \
-DWITH_ONNX=ON \
-DWITH_OPENCL=ON \
-DWITH_OPENCLAMDBLAS=OFF \
-DWITH_OPENCLAMDFFT=OFF \
-DWITH_OPENCL_SVM=OFF \
-DWITH_OPENEXR=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENMP=OFF \
-DWITH_OPENNI=OFF \
-DWITH_PNG=ON \
-DWITH_PTHREADS_PF=OFF \
-DWITH_PVAPI=ON \
-DWITH_QT=ON \
-DWITH_TBB=ON \
-DWITH_TIFF=ON \
-DWITH_UNICAP=OFF \
-DWITH_V4L=ON \
-DWITH_VTK=ON \
-DWITH_WEBP=ON \
-DWITH_XIMEA=OFF \
-DWITH_XINE=OFF \
-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr \
-DCUDA_FAST_MATH=ON \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-DPYTHON_DEFAULT_EXECUTABLE=$(which python3) \
-DOPENCV_DNN_CUDA=ON \
-DENABLE_FAST_MATH=ON \
-DCUDA_FAST_MATH=ON ..
PINTOPINTO
-- General configuration for OpenCV 4.5.5 =====================================
--   Version control:               4.5.5
-- 
--   Extra modules:
--     Location (extra):            /home/user/workdir/opencv_contrib/modules
--     Version control (extra):     4.5.5
-- 
--   Platform:
--     Timestamp:                   2022-02-22T04:16:54Z
--     Host:                        Linux 5.13.0-30-generic x86_64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (33 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 9.3.0)
--     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed  
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed  
--     ccache:                      YES
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv 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 python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 java julia matlab ovis python2 sfm viz
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI:                           QT5
--     QT:                          YES (ver 5.12.8 )
--       QT OpenGL support:         YES (Qt5::OpenGL 5.12.8)
--     GTK+:                        YES (ver 3.24.20)
--       GThread :                  YES (ver 2.64.6)
--       GtkGlExt:                  NO
--     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so)
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (58.54.100)
--       avformat:                  YES (58.29.100)
--       avutil:                    YES (56.31.100)
--       swscale:                   YES (5.5.100)
--       avresample:                NO
--     GStreamer:                   NO
--     PvAPI:                       NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
--     gPhoto2:                     NO
-- 
--   Parallel framework:            TBB (ver 2020.1 interface 11101)
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   /home/user/workdir/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                /home/user/workdir/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
--     VA:                          YES
--     Lapack:                      YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
--     Eigen:                       YES (ver 3.3.7)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
-- 
--   NVIDIA CUDA:                   YES (ver 11.4, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:
--     NVIDIA PTX archs:
-- 
--   cuDNN:                         YES (ver 8.2.4)
-- 
--   OpenCL:                        YES (INTELVA)
--     Include path:                /home/user/workdir/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   ONNX:                          NO
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.8.10)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.10)
--     numpy:                       /usr/local/lib/python3.8/dist-packages/numpy/core/include (ver 1.22.2)
--     install path:                lib/python3.8/site-packages/cv2/python-3.8
-- 
--   Python (for build):            /usr/bin/python3
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/workdir/opencv/build
PINTOPINTO
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$(readlink `which python3`)/site-packages
PINTOPINTO
xhost +local: && \
docker run --gpus all -it --rm \
-v `pwd`:/home/user/workdir \
-v /tmp/.X11-unix/:/tmp/.X11-unix:rw \
--device /dev/video0:/dev/video0:mwr \
--net=host \
-e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
-e DISPLAY=$DISPLAY \
--privileged \
pinto0309/11.4.2-cudnn8-devel-ubuntu20.04-opencv4.5.5:rtx3070
PINTOPINTO
wget https://github.com/opencv/opencv/raw/4.x/samples/data/butterfly.jpg