Dlib: Building dLib on Ubuntu 18.04

Created on 6 Aug 2018  Â·  4Comments  Â·  Source: davisking/dlib

Building dLib on Ubuntu 18.04 fails unless the compiler flag -DCUDA_HOST_COMPILER=/usr/bin/gcc-6 is used when compiling dLib and when creating the python bindings.

Expected Behavior

Possibly some documentation to let folks know that with Ubuntu 18.04, Cuda 9.0 and cuDNN 7.0 that this flag is necessary.

Current Behavior

master@TheBeast:~/Downloads/dlib-19.15$ cd build
master@TheBeast:~/Downloads/dlib-19.15/build$ rm -rf *
master@TheBeast:~/Downloads/dlib-19.15/build$ cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Using CMake version: 3.10.2
-- Compiling dlib version: 19.15.0
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- 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
-- 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 X11: /usr/lib/x86_64-linux-gnu/libX11.so
-- Looking for png_create_read_struct
-- Looking for png_create_read_struct - found
-- Looking for jpeg_read_header
-- Looking for jpeg_read_header - found
-- 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'
-- Found lapack, version 3.10.3
-- 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
-- Found LAPACK library
-- Found ATLAS BLAS library
-- Looking for cblas_ddot
-- Looking for cblas_ddot - found
-- Looking for sgesv
-- Looking for sgesv - not found
-- Looking for sgesv_
-- Looking for sgesv_ - found
-- Found CUDA: /usr/local/cuda-9.0 (found suitable version "9.0", minimum required is "7.5")
-- Looking for cuDNN install...
-- Found cuDNN: /usr/local/cuda-9.0/lib64/libcudnn.so
-- Building a CUDA test project to see if your compiler is compatible with CUDA...


-- * CUDA was found but your compiler failed to compile a simple CUDA program so dlib isn't going to use CUDA.
--
The output of the failed CUDA test compile is shown below:
-- *
* Change Dir: /home/master/Downloads/dlib-19.15/build/dlib/cuda_test_build


* Run Build Command:"/usr/bin/make"
[ 50%] Building NVCC (Device) object CMakeFiles/cuda_test.dir/cuda_test_generated_cuda_test.cu.o
In file included from /usr/local/cuda-9.0/include/host_config.h:50:0,
from /usr/local/cuda-9.0/include/cuda_runtime.h:78,
from :0:
/usr/local/cuda-9.0/include/crt/host_config.h:119:2: error: #error -- unsupported GNU version! gcc versions later than 6 ar e not supported!
#error -- unsupported GNU version! gcc versions later than 6 are not supported!
^~~~~
CMake Error at cuda_test_generated_cuda_test.cu.o.cmake:215 (message):
Error generating
*
* /home/master/Downloads/dlib-19.15/build/dlib/cuda_test_build/CMakeFiles/cuda_test.dir//./cuda_test_generated_cuda_test.cu .o



* CMakeFiles/cuda_test.dir/build.make:63: recipe for target 'CMakeFiles/cuda_test.dir/cuda_test_generated_cuda_test.cu.o' fai led
make[2]: [CMakeFiles/cuda_test.dir/cuda_test_generated_cuda_test.cu.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/cuda_test.dir/all' failed
make[1]: [CMakeFiles/cuda_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: ** [all] Error 2



-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Disabling CUDA support for dlib. DLIB WILL NOT USE CUDA
-- C++11 activated.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/master/Downloads/dlib-19.15/build

Steps to Reproduce

cd Downloads/dlib-19.15/
cmake ..

And for the python bindings
cd ..
python setup.py install

The workaround for this is as follows:

  1. cd to the dLib build directory
  2. rm -rf *
  3. cmake … (this fails on the CUDA test file so no CUDA support)
  4. rm -rf *
  5. cmake … -DDLIB_USE_CUDA=yes -DCUDA_HOST_COMPILER=/usr/bin/gcc-6 (Now I have CUDA support)
  6. cmake --build . --config Release
  7. sudo ldconfig
  8. cd …
  9. python3 setup.py install (fails on CUDA test program, no cuda support)
  10. I forgot to enable my python env
  11. workon cv
  12. python3 setup.py install (fails on Cuda Test program, no CUDA support)
  13. python3 setup.py --compiler-flags “-DCUDA_HOST_COMPILER=usr/bin/gcc-6” install (no failures, but does not say CUDA support so I am assuming I have it based on no failure in the build)
  • Version: 19.15
  • Where did you get dlib: dlib.net
  • Platform: Ubuntu 18.04 64 bit, Cuda 9.0, cuDNN 7,
  • Compiler: gcc-6, g++-6
good question

Most helpful comment

Davis,
You are correct, it does not. But it seems people are succeeding using the 17.10 version. It really starts with installing 18.04 as that was tricky as my system needs to dual boot and I have 2-GPUs.

  1. I used the alternative 18.04 server installer

  2. sudo add-apt-repository ppa:graphics-drivers/ppa

  3. sudo apt-get install dkms build-essential

  4. sudo apt-get update

  5. sudo apt-get install nvidia-390

  6. Pick a desktop manager and you are good to go

  7. From the Nvidia web site:

a. Select Cuda toolkit

b. Legacy Releases

c. 9.0

d. Then select:

                                      i.    Linux

                                     ii.    x86_64

                                    iii.    Ubuntu

                                   iv.    17.04

                                     v.    runfile (local)

                                   vi.    Download the base installer and patches
  1. chmod +x cuda_9.0.176_384.81_linux-run

  2. sudo ./cuda_9.0.176_384.81_linux-run –override

  3. Answer the installation questions:

a. You are attempting to install on an unsupported configuration. Do you wish to continue? y

b. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81? n

c. Install the CUDA 9.0 Toolkit? y

  1. Do the same for the patch files

  2. echo 'export PATH=/usr/local/cuda-9.0/bin:$PATH' >> ~/.bashrc

  3. echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

  4. source ~/.bashrc

  5. From the Nvidia website down load cnDNN 7.0.5 (https://developer.nvidia.com/rdp/cudnn-archive)

  6. I pulled the cuDNN v7.0.5 Library for Linux, cuDNN v7.0.5 Runtime Library for Ubuntu16.04 (Deb) and cuDNN v7.0.5 Developer Library for Ubuntu16.04 (Deb)

  7. untar the files

  8. sudo cp -P cuda/include/cudnn.h /usr/local/cuda-9.0/include

  9. sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/

  10. sudo chmod a+r /usr/local/cuda-9.0/lib64/libcudnn*

  11. Download and install OpenCV. Follow step #5 at https://www.pyimagesearch.com/2017/09/27/setting-up-ubuntu-16-04-cuda-gpu-for-deep-learning-with-python/#comment-473251

a. I added WITH_CUDA=ON

  1. Download dLib 19.15

  2. cd to the dLib build directory

  3. python3 setup.py --compiler-flags “-DCUDA_HOST_COMPILER=usr/bin/gcc-6” install

And that is how I got to where I am today.

Best Regards / Mit freundlichen GrĂĽĂźen,
Doug

All 4 comments

How are you installing cuda? NVIDIA doesn't support ubuntu 18.04 officially yet. So any instructions like this would need to include documentation for how to install it as well.

Davis,
You are correct, it does not. But it seems people are succeeding using the 17.10 version. It really starts with installing 18.04 as that was tricky as my system needs to dual boot and I have 2-GPUs.

  1. I used the alternative 18.04 server installer

  2. sudo add-apt-repository ppa:graphics-drivers/ppa

  3. sudo apt-get install dkms build-essential

  4. sudo apt-get update

  5. sudo apt-get install nvidia-390

  6. Pick a desktop manager and you are good to go

  7. From the Nvidia web site:

a. Select Cuda toolkit

b. Legacy Releases

c. 9.0

d. Then select:

                                      i.    Linux

                                     ii.    x86_64

                                    iii.    Ubuntu

                                   iv.    17.04

                                     v.    runfile (local)

                                   vi.    Download the base installer and patches
  1. chmod +x cuda_9.0.176_384.81_linux-run

  2. sudo ./cuda_9.0.176_384.81_linux-run –override

  3. Answer the installation questions:

a. You are attempting to install on an unsupported configuration. Do you wish to continue? y

b. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81? n

c. Install the CUDA 9.0 Toolkit? y

  1. Do the same for the patch files

  2. echo 'export PATH=/usr/local/cuda-9.0/bin:$PATH' >> ~/.bashrc

  3. echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

  4. source ~/.bashrc

  5. From the Nvidia website down load cnDNN 7.0.5 (https://developer.nvidia.com/rdp/cudnn-archive)

  6. I pulled the cuDNN v7.0.5 Library for Linux, cuDNN v7.0.5 Runtime Library for Ubuntu16.04 (Deb) and cuDNN v7.0.5 Developer Library for Ubuntu16.04 (Deb)

  7. untar the files

  8. sudo cp -P cuda/include/cudnn.h /usr/local/cuda-9.0/include

  9. sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/

  10. sudo chmod a+r /usr/local/cuda-9.0/lib64/libcudnn*

  11. Download and install OpenCV. Follow step #5 at https://www.pyimagesearch.com/2017/09/27/setting-up-ubuntu-16-04-cuda-gpu-for-deep-learning-with-python/#comment-473251

a. I added WITH_CUDA=ON

  1. Download dLib 19.15

  2. cd to the dLib build directory

  3. python3 setup.py --compiler-flags “-DCUDA_HOST_COMPILER=usr/bin/gcc-6” install

And that is how I got to where I am today.

Best Regards / Mit freundlichen GrĂĽĂźen,
Doug

Cool, thanks for documenting the steps for using cuda in ubuntu 18.04.

Happy to help.

Best Regards / Mit freundlichen GrĂĽĂźen,
Doug

Was this page helpful?
0 / 5 - 0 ratings