dlib isn't using installed BLAS

Created on 7 Oct 2020  路  2Comments  路  Source: davisking/dlib

Expected Behavior

dlib to use BLAS and LAPACK when libopenblas-dev or libblas-dev and liblapack-dev are installed on Ubuntu 20.04 (as per instructions on this issue: https://github.com/davisking/dlib/issues/623#issuecomment-305838847)

Current Behavior

When I install libblas-dev or libopenblas-dev the cmake output is pretty much the same:

-- 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 0.3.8+ds
-- Looking for cblas_ddot
-- Looking for cblas_ddot - not found
-- 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 OpenBLAS library
-- Looking for sgetrf_single
-- Looking for sgetrf_single - found
-- Using OpenBLAS's built in LAPACK
-- BLAS library does not have cblas symbols, so dlib will not use BLAS or LAPACK
-- Found BLAS: /usr/lib/x86_64-linux-gnu/libopenblas.so  
-- Looking for sgesv
-- Looking for sgesv - not found
-- Looking for sgesv_
-- Looking for sgesv_ - found

The interesting part is this bit:

-- BLAS library does not have cblas symbols, so dlib will not use BLAS or LAPACK

I tried installing OpenBLAS from source, and then I get this:

-- 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 0.3.8+ds
-- Looking for cblas_ddot
-- Looking for cblas_ddot - not found
-- 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 OpenBLAS library
-- Looking for sgetrf_single
-- Looking for sgetrf_single - found
-- Using OpenBLAS's built in LAPACK
-- BLAS library does not have cblas symbols, so dlib will not use BLAS or LAPACK
-- Found BLAS: /usr/local/lib/libopenblas.so 

Could the lack of cblas symbols be related to this? https://github.com/xianyi/OpenBLAS/issues/2659

How do I get dlib to use BLAS and LAPACK?

Steps to Reproduce

sudo apt-get install gfortran libopenblas-dev liblapack-dev gcc-8 g++-8 && \
git clone https://github.com/davisking/dlib.git && cd dlib && \
mkdir build && cd build && \
cmake -DCMAKE_C_COMPILER=/usr/bin/gcc-8 -DCMAKE_CXX_COMPILER=/usr/bin/g++-8 -DUSE_AVX_INSTRUCTIONS=ON -DBUILD_SHARED_LIBS=1 -DCUDA_HOST_COMPILER=/usr/bin/gcc-8 ../ && \
cmake --build . --config Release

Basically, I'm trying to work out why dlib is slow. I'm using the mmod_human_face_detector running on an NVIDIA T4 GPU, with CUDA 11.1 and cuDNN 8 installed, and it's taking 1.5s to run the detector on a single 250x250 pixel image. I'm sure it's supposed to be faster than this?

I've installed with AVX instructions and am building the Release version. Some people say that using BLAS speeds everything up. Even though I've installed OpenBLAS, it seems that dlib doesn't want to use it.

(Do I even actually need it if I'm using CUDA?)

  • Version: 19.21.99
  • Where did you get dlib: Clone from the github repo today
  • Platform: Ubuntu 20.04
  • Compiler: gcc-8

Most helpful comment

Thanks for reporting this. This was broken very recently in a PR. Turns out CMake's CHECK_FUNCTION_EXISTS doesn't actually run if the output variable was used already :(

Anyway, I just pushed a fix so this should be all good now.

All 2 comments

Thanks for reporting this. This was broken very recently in a PR. Turns out CMake's CHECK_FUNCTION_EXISTS doesn't actually run if the output variable was used already :(

Anyway, I just pushed a fix so this should be all good now.

That's so awesome. Thank you! I just tried re-building from a fresh clone, and got this:

-- 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 0.3.8+ds
-- Looking for cblas_ddot
-- Looking for cblas_ddot - not found
-- 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 OpenBLAS library
-- Looking for sgetrf_single
-- Looking for sgetrf_single - found
-- Using OpenBLAS's built in LAPACK
-- Looking for cblas_ddot
-- Looking for cblas_ddot - found
-- Looking for sgesv
-- Looking for sgesv - not found
-- Looking for sgesv_
-- Looking for sgesv_ - not found

Unfortunately, it still takes me 1.5s to do a detection on the one image. But that's being dealt with in another ticket, so closing this!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

great-thoughts picture great-thoughts  路  5Comments

jackweiwang picture jackweiwang  路  4Comments

AeroClassics picture AeroClassics  路  4Comments

alison-carrera-pegasus picture alison-carrera-pegasus  路  3Comments

pliablepixels picture pliablepixels  路  4Comments