一、一些需要的东西:
- Ubuntu 18.04
- CUDA 10.1
- cuDNN 7.6.5
- g++ 7.5 (并不需要降级到5.0)
- cmake 3.18.2
- python 3.6.5
- Anaconda 3-5.2
二、下载项目文件
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build
cd build
三、编译
DLIB_USE_CUDA=1 支持CUDA
=0 不支持CUDA
USE_AVX_INSTRUCTIONS AVX指令集的CPU加速
cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1
会显示一些日志:
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CMake version: 3.18.2
-- Compiling dlib version: 19.21.99
-- Enabling AVX instructions
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found X11: /usr/include
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so;/usr/lib/x86_64-linux-gnu/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found system copy of libpng: /usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libz.so
-- Found system copy of libjpeg: /usr/lib/x86_64-linux-gnu/libjpeg.so
-- Searching for BLAS and LAPACK
-- Searching for BLAS and LAPACK
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'cblas'
-- No package 'cblas' found
-- Checking for module 'lapack'
-- No package 'lapack' found
-- Looking for cblas_ddot
-- Looking for cblas_ddot - not found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
*****************************************************************************
*** No BLAS library found so using dlib's built in BLAS. However, if you ***
*** install an optimized BLAS such as OpenBLAS or the Intel MKL your code ***
*** will run faster. On Ubuntu you can install OpenBLAS by executing: ***
*** sudo apt-get install libopenblas-dev liblapack-dev ***
*** Or you can easily install OpenBLAS from source by downloading the ***
*** source tar file from http://www.openblas.net, extracting it, and ***
*** running: ***
*** make; sudo make install ***
*****************************************************************************
-- Found CUDA: /usr/local/cuda (found suitable version "10.1", minimum required is "7.5")
-- Looking for cuDNN install...
-- Found cuDNN: /usr/local/cuda/lib64/libcudnn.so
-- Building a CUDA test project to see if your compiler is compatible with CUDA...
-- Building a cuDNN test project to check if you have the right version of cuDNN installed...
-- Enabling CUDA support for dlib. DLIB WILL USE CUDA
-- C++11 activated.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/dlib/build
然后是编译:
cmake --build .
一些日志:
[ 1%] Building NVCC (Device) object dlib/CMakeFiles/dlib.dir/cuda/dlib_generated_cusolver_dlibapi.cu.o
[ 3%] Building NVCC (Device) object dlib/CMakeFiles/dlib.dir/cuda/dlib_generated_cuda_dlib.cu.o
Scanning dependencies of target dlib
[ 4%] Building CXX object dlib/CMakeFiles/dlib.dir/base64/base64_kernel_1.cpp.o
[ 6%] Building CXX object dlib/CMakeFiles/dlib.dir/bigint/bigint_kernel_1.cpp.o
[ 7%] Building CXX object dlib/CMakeFiles/dlib.dir/bigint/bigint_kernel_2.cpp.o
[ 9%] Building CXX object dlib/CMakeFiles/dlib.dir/bit_stream/bit_stream_kernel_1.cpp.o
[ 10%] Building CXX object dlib/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_1.cpp.o
[ 12%] Building CXX object dlib/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_2.cpp.o
[ 13%] Building CXX object dlib/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_1.cpp.o
[ 15%] Building CXX object dlib/CMakeFiles/dlib.dir/entropy_encoder/entropy_encoder_kernel_2.cpp.o
[ 16%] Building CXX object dlib/CMakeFiles/dlib.dir/md5/md5_kernel_1.cpp.o
[ 18%] Building CXX object dlib/CMakeFiles/dlib.dir/tokenizer/tokenizer_kernel_1.cpp.o
[ 19%] Building CXX object dlib/CMakeFiles/dlib.dir/unicode/unicode.cpp.o
[ 21%] Building CXX object dlib/CMakeFiles/dlib.dir/test_for_odr_violations.cpp.o
[ 22%] Building CXX object dlib/CMakeFiles/dlib.dir/sockets/sockets_kernel_1.cpp.o
[ 24%] Building CXX object dlib/CMakeFiles/dlib.dir/bsp/bsp.cpp.o
[ 25%] Building CXX object dlib/CMakeFiles/dlib.dir/dir_nav/dir_nav_kernel_1.cpp.o
[ 27%] Building CXX object dlib/CMakeFiles/dlib.dir/dir_nav/dir_nav_kernel_2.cpp.o
[ 28%] Building CXX object dlib/CMakeFiles/dlib.dir/dir_nav/dir_nav_ex