Skip to content

Fixed detection of OpenBLAS and LAPACK on Ubuntu 18.04 with arch x86-64#19343

Open
HungWoeiNeoh wants to merge 1 commit intoopencv:4.xfrom
HungWoeiNeoh:ubuntu_openblas_lapack_fix
Open

Fixed detection of OpenBLAS and LAPACK on Ubuntu 18.04 with arch x86-64#19343
HungWoeiNeoh wants to merge 1 commit intoopencv:4.xfrom
HungWoeiNeoh:ubuntu_openblas_lapack_fix

Conversation

@HungWoeiNeoh
Copy link
Copy Markdown

@HungWoeiNeoh HungWoeiNeoh commented Jan 18, 2021

Fixes the cmake detection of OpenBLAS and LAPACK libraries on Ubuntu with arch x86-64

A similar fix can be applied for other architectures too.

Source: #9953, only partially resolves it.

Tested this on a Docker container, Ubuntu 18.04 with GCC 7.5.0, OpenCV builds successfully, and the relevant cmake output for OpenBLAS detection is as follows:

-- Found OpenBLAS libraries: /usr/lib/x86_64-linux-gnu/libopenblas.so
-- Found OpenBLAS include: /usr/include/x86_64-linux-gnu
-- LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/x86_64-linux-gnu/libopenblas.so
-- LAPACK(OpenBLAS): Support is enabled.

This patch has not been tested on other architectures/OS, but it should not affect any other architecture/OS

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@alalek
Copy link
Copy Markdown
Member

alalek commented Jan 18, 2021

Please provide details about use case.

Docker file is preferable:

FROM ubuntu:18.04

RUN apt update && apt install -y git cmake make g++ \
    libopenblas-dev

RUN git clone --branch ubuntu_openblas_lapack_fix --depth=1 https://github.com/HungWoeiNeoh/opencv
RUN mkdir opencv_build
WORKDIR opencv_build
RUN cmake ../opencv -DWITH_IPP=OFF && make -j1 opencv_test_core

Results:

-- Found OpenBLAS libraries: /usr/lib/x86_64-linux-gnu/libopenblas.so
-- Found OpenBLAS include: /usr/include/x86_64-linux-gnu
-- LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/x86_64-linux-gnu/libopenblas.so
CMake Warning at cmake/OpenCVFindLAPACK.cmake:29 (message):
  LAPACK(OpenBLAS): CBLAS/LAPACK headers are not found in
  '/usr/include/x86_64-linux-gnu;/usr/include'
Call Stack (most recent call first):
  cmake/OpenCVFindLAPACK.cmake:103 (ocv_lapack_check)
  CMakeLists.txt:710 (include)


-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY) 
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Found Threads: TRUE  
-- A library with BLAS API found.
-- Looking for cheev_
-- Looking for cheev_ - found
-- A library with LAPACK API found.
...

--   Other third-party libraries:
...
--     Lapack:                      NO

So this patch doesn't seem to work.
(Ubuntu package is broken as stated in the issue)


P.S. Always clear CMake cache (build directory) if dependencies are changed. We need reproducible results.

@mshabunin
Copy link
Copy Markdown
Contributor

mshabunin commented Jan 18, 2021

@HungWoeiNeoh , I tried to fix the detection too, but did not finish it: mshabunin@651e95e

As I remember it was important to find correct header using _find_header_file_in_dirs.

@HungWoeiNeoh
Copy link
Copy Markdown
Author

HungWoeiNeoh commented Jan 19, 2021

Hi, what do you mean by use case? Do you mean the reason I'm building OpenCV?

You still need to install liblapacke-dev, which will install the LAPACK headers, as mentioned in the issue. The headers will be installed in /usr/include. The fix is to make sure that the cmake file is able to detect the LAPACK headers if you installed liblapacke-dev

@asenyaev
Copy link
Copy Markdown
Contributor

asenyaev commented Apr 8, 2021

jenkins cn please retry a build

@catree
Copy link
Copy Markdown
Contributor

catree commented May 11, 2021

I believe you should inform this issue at the OpenBLAS Ubuntu/distrib maintainer level.

Because when you build OpenBLAS from source, it will correctly install the lapacke.h header:

cblas.h
f77blas.h
lapacke_config.h
lapacke.h
lapacke_mangling.h
lapacke_utils.h
lapack.h
openblas_config.h

While in Bionic (18.04):

/usr/include/x86_64-linux-gnu/cblas-openblas.h
/usr/include/x86_64-linux-gnu/f77blas.h
/usr/include/x86_64-linux-gnu/openblas_config.h
/usr/lib/x86_64-linux-gnu/libopenblas.a
/usr/lib/x86_64-linux-gnu/libopenblas.so
/usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.a
/usr/lib/x86_64-linux-gnu/openblas/libblas.a
/usr/lib/x86_64-linux-gnu/openblas/libblas.so
/usr/lib/x86_64-linux-gnu/openblas/liblapack.a
/usr/lib/x86_64-linux-gnu/openblas/liblapack.so
/usr/lib/x86_64-linux-gnu/pkgconfig/blas-openblas.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/lapack-openblas.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/openblas.pc
/usr/share/doc/libopenblas-dev/changelog.Debian.gz
/usr/share/doc/libopenblas-dev/copyright

In Impish:

/usr/include/x86_64-linux-gnu/openblas-pthread/cblas.h
/usr/include/x86_64-linux-gnu/openblas-pthread/f77blas.h
/usr/include/x86_64-linux-gnu/openblas-pthread/openblas_config.h
/usr/lib/x86_64-linux-gnu/openblas-pthread/cmake/openblas/OpenBLASConfig.cmake
/usr/lib/x86_64-linux-gnu/openblas-pthread/cmake/openblas/OpenBLASConfigVersion.cmake
/usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.a
/usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so
/usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.a
/usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so
/usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblas.a
/usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblas.so
/usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.a
/usr/lib/x86_64-linux-gnu/openblas-pthread/pkgconfig/blas-openblas.pc
/usr/lib/x86_64-linux-gnu/openblas-pthread/pkgconfig/lapack-openblas.pc
/usr/lib/x86_64-linux-gnu/openblas-pthread/pkgconfig/openblas.pc
/usr/share/doc/libopenblas-pthread-dev/changelog.Debian.gz
/usr/share/doc/libopenblas-pthread-dev/copyright

@vpisarev
Copy link
Copy Markdown
Contributor

vpisarev commented May 25, 2021

@alalek, shall we backport alway-available-Lapack patch to the master branch? If I remember correctly, BLAS/Lapack detection part was significantly reworked there

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants