#!/bin/bash
sudo apt-get update
sudo apt-get install git build-essential -y
sudo apt-get install cmake cmake-gui -y
sudo apt-get install build-essential -y
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y
sudo apt-get install python-dev python-numpy -y
sudo apt-get install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev -y
sudo apt-get install libxvidcore-dev libx264-dev -y
sudo apt-get install libatlas-base-dev gfortran -y
sudo apt-get install ffmpeg -y
sudo apt-get install libboost-dev libeigen3-dev -y
sudo apt-get install libxml2-dev libxslt-dev libffi-dev libsdl1.2-dev libssl-dev libboost-all-dev -y
关于GpuMat.upload(image) 耗时问题
CUDA_ARCH_BIN 1.1 1.2 1.3 2.0 2.1(2.0) 3.0 3.5 6.1
NVIDA CUDA显卡计算能力对应表
https://developer.nvidia.com/cuda-gpus
https://www.zhihu.com/question/28449000
opencv+cuda+gpu为何如此的慢??
数据从内存传递到显存和cudaMalloc耗时很长,NVIDIA提供的nsight中的profile可以看每一个部分的耗时
要是CPU代码真那么容易改成GPU的话,那得有多少人瞬间失业啊。。。不光是内存交换,可以优化的地方多了去了,推荐一个教程,让你感受一下最普通的reduction操作有多可怕的优化空间。https://developer.download.nvidia.com/assets/cuda/files/reduction.pdfdeveloper.download.nvidia.com至于你自己的代码嘛,先用nvprof看看瓶颈在哪呗。
我使用的是cmake-gui编译
我用了其他版本,有的是cuda版本不兼容
我尝试了3.4.1,只选择我需要的
具体过程参考了:
http://leadtosilverlining.blogspot.com/2018/09/build-opencv-341-with-cuda-90-support.html
但是最后的cmake选项那里,我用了自己的
期间遇到警告:
not used because `OPENCV_TRAITS_ENABLE_DEPRECATED' is defined [-Winvalid-pch]
网友建议使用3.4.3--并且:
cmake -DENABLE_PRECOMPILED_HEADERS=OFF
解决!!
还有:
[ 44%] Building NVC·2/opencv-3.4.1/modules/cudaarithm/src/cuda/absdiff_mat.cu(98): warning: function "<unnamed>::AbsDiffOp2::operator()" was declared but never referenced/æ°å å
未解决!!
error:
error: calling a constexpr __host__ function("abs") from a __device__ function("abs") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.
https://github.com/opencv/opencv/issues/8704:
Any reason why this still isn't a default option in 3.4.1? This also happens even without VTK, but with CUDA.
Note: Adding -DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr to the cmake line really does fix this.
解决!!
我的gcc版本:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.5.0-2ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --with-as=/usr/bin/x86_64-linux-gnu-as --with-ld=/usr/bin/x86_64-linux-gnu-ld --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.5.0 20181026 (Ubuntu 6.5.0-2ubuntu1~16.04)
写一个脚本:
makeynh.sh
#!/bin/bash
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D CMAKE_INSTALL_PREFIX="../install_3" \
-D WITH_MATLAB=OFF \
-D WITH_QT=OFF \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D CUDA_GENERATION=Pascal \
-D WITH_FFMPEG=1 \
-D WITH_CUFFT=ON \
-D WITH_EIGEN=ON \
-D WITH_CUBLAS=1 \
-D WITH_OPENGL=ON \
-D WITH_TBB=ON \
-D WITH_LAPACK=OFF \
-D BUILD_opencv_vis=OFF \
-D BUILD_opencv_videostab=OFF \
-D BUILD_opencv_videoio=OFF \
-D BUILD_opencv_video=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_opencv_superres=OFF \
-D BUILD_opencv_stitching=OFF \
-D BUILD_opencv_shape=OFF \
-D BUILD_opencv_python_bindings_generator=OFF \
-D BUILD_opencv_python=OFF \
-D BUILD_opencv_photo=OFF \
-D BUILD_opencv_objdetect=OFF \
-D BUILD_opencv_ml=OFF \
-D BUILD_opencv_js=OFF \
-D BUILD_opencv_java_bindings_genetator=OFF \
-D BUILD_opencv_dnn=OFF \
-D BUILD_opencv_cudastereo=OFF \
-D BUILD_opencv_cudaoptflow=OFF \
-D BUILD_opencv_cudaobjdetect=OFF \
-D BUILD_opencv_cudalegacy=OFF \
-D BUILD_opencv_cudabgsegm=OFF \
-D CUDA_NVCC_FLAGS=--expt-relaxed-constexpr \
-D ENABLE_PRECOMPILED_HEADERS=OFF ..
如果加上SURF-GPU
要先下载一些文件,不然cmake下载很慢
下载后放在:
opencv-3.4.1/build_4/downloads/xfeatures2d/ 下面
额外库只留了 sfm surface_matching xfeatures2d ximgproc
#!/bin/bash
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D CMAKE_INSTALL_PREFIX="../install_4" \
-D OPENCV_EXTRA_MODULES_PATH="../opencv_contrib-3.4.1/modules" \
-D WITH_MATLAB=OFF \
-D WITH_QT=OFF \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D CUDA_GENERATION=Pascal \
-D WITH_FFMPEG=1 \
-D WITH_CUFFT=ON \
-D WITH_EIGEN=ON \
-D WITH_CUBLAS=1 \
-D WITH_OPENGL=ON \
-D WITH_TBB=ON \
-D WITH_LAPACK=OFF \
-D BUILD_opencv_vis=OFF \
-D BUILD_opencv_videostab=OFF \
-D BUILD_opencv_videoio=OFF \
-D BUILD_opencv_video=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_opencv_superres=OFF \
-D BUILD_opencv_stitching=OFF \
-D BUILD_opencv_shape=OFF \
-D BUILD_opencv_python_bindings_generator=OFF \
-D BUILD_opencv_python=OFF \
-D BUILD_opencv_photo=OFF \
-D BUILD_opencv_objdetect=OFF \
-D BUILD_opencv_ml=OFF \
-D BUILD_opencv_js=OFF \
-D BUILD_opencv_java_bindings_genetator=OFF \
-D BUILD_opencv_dnn=OFF \
-D BUILD_opencv_cudastereo=OFF \
-D BUILD_opencv_cudaoptflow=OFF \
-D BUILD_opencv_cudaobjdetect=OFF \
-D BUILD_opencv_cudalegacy=OFF \
-D BUILD_opencv_cudabgsegm=OFF \
-D BUILD_opencv_aruco=OFF \
-D BUILD_opencv_bgsegm=OFF \
-D BUILD_opencv_bioinspired=OFF \
-D BUILD_opencv_ccalib=OFF \
-D BUILD_opencv_datasets=OFF \
-D BUILD_opencv_dnn_objdetect=OFF \
-D BUILD_opencv_dpm=OFF \
-D BUILD_opencv_face=OFF \
-D BUILD_opencv_freetype=OFF \
-D BUILD_opencv_fuzzy=OFF \
-D BUILD_opencv_hdf=OFF \
-D BUILD_opencv_hfs=OFF \
-D BUILD_opencv_img_hash=OFF \
-D BUILD_opencv_line_descriptor=OFF \
-D BUILD_opencv_optflow=OFF \
-D BUILD_opencv_phase_unwrapping=OFF \
-D BUILD_opencv_plot=OFF \
-D BUILD_opencv_reg=OFF \
-D BUILD_opencv_rgbd=OFF \
-D BUILD_opencv_saliency=OFF \
-D BUILD_opencv_stereo=OFF \
-D BUILD_opencv_structured_light=OFF \
-D BUILD_opencv_text=OFF \
-D BUILD_opencv_tracking=OFF \
-D BUILD_opencv_xphoto=OFF \
-D CUDA_NVCC_FLAGS=--expt-relaxed-constexpr \
-D ENABLE_PRECOMPILED_HEADERS=OFF ..