How to check if dlib is using GPU or not?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Dlib is a C++ toolkit with Python bindings used for face detection, landmark prediction, and other machine learning tasks. It optionally supports CUDA GPU acceleration, but only if compiled from source with CUDA enabled. The pip-installed version does not include CUDA support. To check whether your dlib installation is using the GPU, use dlib.DLIB_USE_CUDA and dlib.cuda.get_num_devices().
Checking GPU Support
If DLIB_USE_CUDA is True and get_num_devices() returns a positive number, dlib is using the GPU.
Quick One-Liner Check
Verifying with a CNN Model
The most practical test is running a CNN-based face detector, which uses the GPU when available:
If detection takes under 0.1 seconds per image, the GPU is being used. CPU-only detection typically takes several seconds.
Installing Dlib with CUDA Support
The pip-installed version (pip install dlib) ships without CUDA. You must compile from source:
Verify the build detected CUDA:
If cmake says "CUDA not found" or "Building a non-CUDA build", CUDA is not properly installed or not in the PATH.
Checking CUDA and cuDNN Versions
Debugging GPU Not Detected
If DLIB_USE_CUDA is True but get_num_devices() returns 0:
Common Pitfalls
- Pip-installed dlib has no CUDA: Running
pip install dlibinstalls a CPU-only build. There is no pip option for GPU support. You must compile from source with-DDLIB_USE_CUDA=1. - CUDA/cuDNN version mismatch: Dlib requires matching CUDA and cuDNN versions. If cmake finds CUDA but not cuDNN (or vice versa), the build silently falls back to CPU. Check cmake output carefully for "Found cuDNN" messages.
- Outdated NVIDIA drivers: The GPU driver must support your CUDA toolkit version. Run
nvidia-smito check the driver version and verify compatibility with the NVIDIA CUDA compatibility matrix. - Docker containers without GPU passthrough: Inside Docker, the GPU is invisible unless you use
--gpus allor the NVIDIA Container Toolkit. Dlib will compile with CUDA butget_num_devices()returns 0 at runtime. - Conda environment overriding system CUDA: Conda may install its own CUDA libraries that conflict with the system installation. Use
conda install -c conda-forge dlibor setCUDA_HOMEexplicitly before building.
Summary
- Check GPU support with
dlib.DLIB_USE_CUDAanddlib.cuda.get_num_devices() - The pip-installed dlib does not include CUDA — compile from source with cmake
- Verify cmake output shows "Found CUDA" and "Found cuDNN" during the build
- CNN face detection speed is a practical indicator (GPU is 50-100x faster)
- Ensure NVIDIA driver, CUDA toolkit, and cuDNN versions are all compatible
- In Docker, use
--gpus allto expose the GPU to the container

