木叶下

  • 编程算法
  • 深度学习
  • 微小工作
  • 善用软件
  • 杂记
  • 诗人远方
南国羽说
文字记录生活
  1. 首页
  2. 微小工作
  3. 正文

Ubuntu20.04编译OpenCV4.5支持GPU 与CUDA加速

2021年2月25日 18366点热度 3人点赞 0条评论

At present,The latest verion of offical OpenCV is 4.5.2。

In this blog, I introduce how to compile OpenCV from source code and enable GPU/CUDA support
- GPU: Tesla V100
- CUDA: 11.0
- CUDA Capability: 7.0 (corresponding to GPU Tesla V100)
- OS: Ubuntu 20.04

# Install prerequisites 
sudo apt-get update && apt-get upgrade -y &&\
    apt-get install -y \
        build-essential \
        unzip \
        yasm \
        pkg-config \
        libswscale-dev \
        libtbb2 \
        libtbb-dev \
        libjpeg-dev \
        libpng-dev \
        libtiff-dev \
        libavformat-dev \
        libpq-dev \
        libxine2-dev \
        libglew-dev \
        libtiff5-dev \
        zlib1g-dev \
        libjpeg-dev \
        libavcodec-dev \
        libavformat-dev \
        libavutil-dev \
        libpostproc-dev \
        libswscale-dev \
        libeigen3-dev \
        libtbb-dev \
        libgtk2.0-dev \

Download source from github

# Download and unpack sources
wget https://github.com/opencv/opencv/archive/refs/tags/4.5.2.zip -O opencv.zip
wget https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.2.zip -O opencv_contrib.zip
unzip opencv.zip
mv opencv-4.5.2 opencv
unzip opencv_contrib.zip
mv opencv_contrib-4.5.2 opencv_contrib
# Create build directory and switch into it
mkdir opencv/build && cd opencv/build

Please check the CUDA Capability of your GPU from this table(the final part of this blog), and then set the current CUDA_ARCH_BIN

# Configure
cmake \
    -D CMAKE_BUILD_TYPE=RELEASE \
  -D CMAKE_C_COMPILER=/usr/bin/gcc \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules/ \
    -D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so \
    -D CUDA_ARCH_BIN=7.0 \
    -D CUDA_ARCH_PTX="" \
    -D WITH_CUDA=ON \
    -D WITH_TBB=ON \
    -D WITH_FFMPEG=ON \
    -D BUILD_PYTHON_SUPPORT=ON \
    -D BUILD_NEW_PYTHON_SUPPORT=ON \
    -D BUILD_OPENCV_PYTHON3=ON \
    -D PYTHON_INCLUDE_DIR=(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
    -D PYTHON_PACKAGES_PATH=(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
    -D WITH_V4L=ON \
    -D INSTALL_C_EXAMPLES=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=ON \
    -D WITH_QT=ON \
    -D WITH_GSTREAMER=ON \
    -D WITH_OPENGL=ON \
    -D ENABLE_FAST_MATH=1 \
    -D CUDA_FAST_MATH=1 \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D OPENCV_PC_FILE_NAME=opencv.pc \
    -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
    -D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs \
    -D WITH_CUBLAS=ON \
    -D WITH_NVCUVID=ON \
    -D BUILD_opencv_cudacodec=ON \
    -D OPENCV_DNN_CUDA=ON \
    -D WITH_CUDNN=ON \
    -D OPENCV_ENABLE_NONFREE=ON\
    -D WITH_GSTREAMER=ON \
    -D BUILD_EXAMPLES=ON ..
# build
make -j"$(nproc)" 
# install
sudo make install
ldconfig 

Capability Table

GPU Capability
NVIDIA A100 8.0
NVIDIA T4 7.5
NVIDIA V100 7.0
Tesla P100 6.0
Tesla P40 6.1
Tesla P4 6.1
Tesla M60 5.2
Tesla M40 5.2
Tesla K80 3.7
Tesla K40 3.5
Tesla K20 3.5
Tesla K10 3.0
Tesla K80 3.7
Tesla K40 3.5
Tesla K20 3.5
Tesla C2075 2.0
Tesla C2050 or C2070 2.0
GeForce RTX 2080 7.5
GeForce RTX 2070 7.5
GeForce RTX 2060 7.5
GeForce GTX 1080 6.1
GeForce GTX 1070 6.1
GeForce GTX 1060 6.1
GeForce GTX 980 5.2
GeForce GTX 980M 5.2
GeForce GTX 970M 5.2
GeForce GTX 965M 5.2
GeForce GTX 960M 5.0
GeForce GTX 950M 5.0
GeForce 940M 5.0
GeForce 930M 5.0
GeForce 920M 3.5
GeForce 910M 5.2
GeForce GTX 880M 3.0
GeForce GTX 870M 3.0
GeForce GTX 860M 3.0/5.0(**)
GeForce GTX 850M 5.0
GeForce 840M 5.0
GeForce 830M 5.0
GeForce 820M 2.1
GeForce 800M 2.1
GeForce GTX 780M 3.0
GeForce GTX 770M 3.0
GeForce GTX 765M 3.0
GeForce GTX 760M 3.0
GeForce GTX 680MX 3.0
GeForce GTX 680M 3.0
GeForce GTX 675MX 3.0
GeForce GTX 675M 2.1
GeForce GTX 670MX 3.0
GeForce GTX 670M 2.1
GeForce GTX 660M 3.0
GeForce GT 755M 3.0
GeForce GT 750M 3.0
GeForce GT 650M 3.0
GeForce GT 745M 3.0
GeForce GT 645M 3.0
GeForce GT 740M 3.0
GeForce GT 730M 3.0
GeForce GT 640M 3.0
GeForce GT 640M LE 3.0
GeForce GT 735M 3.0
GeForce GT 635M 2.1
GeForce GT 730M 3.0
GeForce GT 630M 2.1
GeForce GT 625M 2.1
GeForce GT 720M 2.1
GeForce GT 620M 2.1
GeForce 710M 2.1
GeForce 705M 2.1
GeForce 610M 2.1
GeForce GTX 580M 2.1
GeForce GTX 570M 2.1
GeForce GTX 560M 2.1
GeForce GT 555M 2.1
GeForce GT 550M 2.1
GeForce GT 540M 2.1
GeForce GT 525M 2.1
GeForce GT 520MX 2.1
GeForce GT 520M 2.1
GeForce GTX 485M 2.1
GeForce GTX 470M 2.1
GeForce GTX 460M 2.1
GeForce GT 445M 2.1
GeForce GT 435M 2.1
GeForce GT 420M 2.1
GeForce GT 415M 2.1
GeForce GTX 480M 2.0
GeForce 710M 2.1
GeForce 410M 2.1
GeForce RTX 3090 8.6
GeForce RTX 3080 8.6
GeForce RTX 3070 8.6
NVIDIA TITAN RTX 7.5
GeForce RTX 2080 Ti 7.5
GeForce RTX 2080 7.5
GeForce RTX 2070 7.5
GeForce RTX 2060 7.5
NVIDIA TITAN V 7.0
NVIDIA TITAN Xp 6.1
NVIDIA TITAN X 6.1
GeForce GTX 1080 Ti 6.1
GeForce GTX 1080 6.1
GeForce GTX 1070 6.1
GeForce GTX 1060 6.1
GeForce GTX 1050 6.1
GeForce GTX TITAN X 5.2
GeForce GTX TITAN Z 3.5
GeForce GTX TITAN Black 3.5
GeForce GTX TITAN 3.5
GeForce GTX 980 Ti 5.2
GeForce GTX 980 5.2
GeForce GTX 970 5.2
GeForce GTX 960 5.2
GeForce GTX 950 5.2
GeForce GTX 780 Ti 3.5
GeForce GTX 780 3.5
GeForce GTX 770 3.0
GeForce GTX 760 3.0
GeForce GTX 750 Ti 5.0
GeForce GTX 750 5.0
GeForce GTX 690 3.0
GeForce GTX 680 3.0
GeForce GTX 670 3.0
GeForce GTX 660 Ti 3.0
GeForce GTX 660 3.0
GeForce GTX 650 Ti BOOST 3.0
GeForce GTX 650 Ti 3.0
GeForce GTX 650 3.0
GeForce GTX 560 Ti 2.1
GeForce GTX 550 Ti 2.1
GeForce GTX 460 2.1
GeForce GTS 450 2.1
GeForce GTS 450* 2.1
GeForce GTX 590 2.0
GeForce GTX 580 2.0
GeForce GTX 570 2.0
GeForce GTX 480 2.0
GeForce GTX 470 2.0
GeForce GTX 465 2.0
GeForce GT 740 3.0
GeForce GT 730 3.5
GeForce GT 730 DDR3,128 bits 2.1
GeForce GT 720 3.5
GeForce GT 705* 3.5
GeForce GT 640 (GDDR5) 3.5
GeForce GT 640 (GDDR3) 2.1
GeForce GT 630 2.1
GeForce GT 620 2.1
GeForce GT 610 2.1
GeForce GT 520 2.1
GeForce GT 440 2.1
GeForce GT 440* 2.1
GeForce GT 430 2.1
GeForce GT 430* 2.1
标签: cuda Opencv Ubuntu
最后更新:2021年5月2日

Dong Wang

I am a PhD student of TU Graz in Austria. My research interests include Embedded/Edge AI, efficient machine learning, model sparsity, deep learning, computer vision, and IoT. I would like to understand the foundational problems in deep learning.

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

文章目录
  • Capability Table

COPYRIGHT © 2013-2024 nanguoyu.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

陕ICP备14007751号-1