Skip to content

Instantly share code, notes, and snippets.

@nguyenhoan1988
Created October 19, 2021 22:05
Show Gist options
  • Save nguyenhoan1988/ed92d58054b985a1b45a521fcf8fa781 to your computer and use it in GitHub Desktop.
Save nguyenhoan1988/ed92d58054b985a1b45a521fcf8fa781 to your computer and use it in GitHub Desktop.
Installing dlib using conda with CUDA enabled

Installing dlib using conda with CUDA enabled

Prerequisite: conda and/or miniconda are already installed

  1. Create a conda environment.
$ conda create -n dlib python=3.8 cmake ipython
  1. Activate the environment.
$ conda activate dlib
  1. Install CUDA and cuDNN with conda using nvidia channel
$ conda install cuda cudnn -c nvidia

Then find the path to the nvcc of this environment. We will use this path for the build step below

$which nvcc
/path/to/your/miniconda3/envs/dlib/bin/
  1. Install dlib. Clone and build dlib from source
$ git clone https://github.com/davisking/dlib.git
$ cd dlib
$ mkdir build
$ cd build
$ cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 -DCUDAToolkit_ROOT=/path/to/your/miniconda3/envs/dlib/bin/
$ cmake --build .
$ cd ..
$ python setup.py install --set DLIB_USE_CUDA=1
  1. Test dlib
(dlib) $ ipython
Python 3.8.12 (default, Oct 12 2021, 13:49:34)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.27.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import dlib

In [2]: dlib.DLIB_USE_CUDA
Out[2]: True

In [3]: print(dlib.cuda.get_num_devices())
1
@lingster
Copy link

lingster commented Feb 8, 2024

if you are running on arch linux and you are getting these errors try temporarily downgrading your cc/gcc compilers like this:

export CXX="/usr/bin/g++-12"
export CC="/usr/bin/gcc-12"

or wherever the correct path you have installed the previous versions of the compiler.

@s2485523800
Copy link

Thanks a lot.
maybe somebody installed cudnn but dlib said not found, you can use " set CMAKE_PREFIX_PATH=path/to/cudnn"( in conda is /Library) to fix this problem

@huhreenee
Copy link

Hi @s2485523800, I am facing this issue, unfortunately, I am not able to set CMAKE_PREFIX_PATH correctly. Could you please help?

@s2485523800
Copy link

Hi @s2485523800, I am facing this issue, unfortunately, I am not able to set CMAKE_PREFIX_PATH correctly. Could you please help?

maybe you can take a photo about your conda env path,and conda list

@semajbaker
Copy link

thanks. Worked for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment