Build and Install dlib with CUDA support on Ubuntu

Environment

  • Ubuntu 16.04 x64
  • CUDA 9.0
  • cuDnn 7.0
  • gcc 6.4.0
  • Python 3.6

Installing C/C++ packages

These are part of the Python headers and are needed for the compilation of most C/C++ packages within Python. Depending on the operating system, the solutions will vary—unfortunately.

System SettingsSoftware & Updatges → Check Source code

sudo apt-get update
sudo apt-get install python3-dev
sudo apt-get install build-dep python3

Installing BLAS and LAPACK packages

sudo apt-get update
sudo apt-get install libblas-dev liblapack-dev libatlas-base-dev

Cloning dlib

git clone https://github.com/davisking/dlib.git

Editing setup.py

Add the following line of code to setup.py to indicate gcc compiler.
os.environ["CC"] = "gcc-6"

Building the main dlib library

cd dlib
mkdir build && cd build

cmake .. -DCUDA_HOST_COMPILER=/usr/bin/gcc-6 -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/ -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 -DUSE_F16C=1
cmake --build . --config Release
sudo ldconfig

Building and installing the Python extensions

Add --record to record a list of installed files.
Add --yes DLIB_USE_CUDA to use CUDA.
Add --compiler-flags to indicate compiler.
cd ..
python setup.py install --record files.txt --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA --compiler-flags "-DCUDA_HOST_COMPILER=/usr/bin/gcc-6"

*Uninstalling dlib*

Once we want to uninstall dlib, simply type the command below according to generated files.txt.
cat files.txt | xargs rm -rf

Testing

At this point, you should be able to run python3 and type import dlib successfully.
python3
>>> import dlib

References

Share:

5 則留言: