Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dlib not using CUDA

I installed dlib using pip. my graphic card supports CUDA, but while running dlib, it is not using GPU.

Im working on ubuntu 18.04

Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
>>> import dlib
>>> dlib.DLIB_USE_CUDA
False

I have also installed the NVidia Cuda Compile driver but still it is not working.

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

Can anyone help me how to get it working. ?

like image 852
Apurva N. Saraogi Avatar asked Aug 21 '18 06:08

Apurva N. Saraogi


2 Answers

I had similar issues, in my case I was missing the cuDNN library, which prevented dlib from compiling with CUDA instructions, although I had CUDA compiler and other drivers installed.

The next part is to download dlib from this repo.

Then run this command to install dlib with CUDA and AVX instructions, you do not need to manually compile it with CMake using make file:

python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA

Important part now is to read the log, if the python can actually find CUDA, cuDNN and can use CUDA compiler to compile the test project. These are the important lines:

-- Found CUDA: /usr/local/cuda/bin/ (found suitable version "8.0", 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...

The second problem I was facing was related to CMake versions. The latest version had some known problems with cuda and dlib, so I had to install CMake 3.12.3 in order to make it work.

like image 118
Sebastian Värv Avatar answered Sep 17 '22 01:09

Sebastian Värv


There are 2 different problems leading to this as on Windows:

  1. You don't have a CUDA installation or cuDNN installation.

  2. You installed the above 2 libraries but didn't initialize environment variables. This is specially true for conda install of both libraries. Conda installs them but doesn't setup environment variables. Full point of conda is not to set them globally.

  3. This is something I'm unsure about but might fix. The name of environment variable is CUDA_PATH_xxxx and not CUDA_PATH as was given in installation instruction of Nvidia website.

Try the third one if first 2 corrections, didn't work. My CUDA version is 10.1 at the time.

like image 27
Sidharth Singh Avatar answered Sep 21 '22 01:09

Sidharth Singh