Bernhard Bodenstorfer
Bernhard Bodenstorfer

Reputation: 960

Can CMake FindBLAS find OpenBLAS?

For demonstration, I use the 3-line CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
find_package( BLAS REQUIRED )
message( STATUS BLAS found: ${BLAS_LIBRARIES} )

I have cblas, ATLAS and OpenBLAS including developer packages installed on a Debian Linux system, plus CMake 2.8.9. When I call

cmake . -DBLA_VENDOR=ATLAS -DCMAKE_PREFIX_PATH=/usr/lib/atlas-base

the ATLAS library nicely appears found:

-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for dgemm_
-- Looking for dgemm_ - found
-- A library with BLAS API found.
-- BLASfound:/usr/lib/atlas-base/libf77blas.so/usr/lib/atlas-base/libatlas.so
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp

Similarly, just

cmake .

will find /usr/lib/libblas.so for me. (I do not forget to remove the cache files before the second call.)

When I look into /usr/share/cmake-2.8/Modules/FindBLAS.cmake, I read as the permitted values of BLA_VENDOR:

##  Goto,ATLAS PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32 (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model),
##  Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model),
##  Intel( older versions of mkl 32 and 64 bit), ACML,ACML_MP,ACML_GPU,Apple, NAS, Generic

That is, OpenBLAS is not listed. And a few random trials like

cmake . -DBLA_VENDOR=open -DCMAKE_PREFIX_PATH=/usr/lib/openblas-base

do not work either. Do I have to write my own FindBLAS in order to link to OpenBLAS with CMake?

Upvotes: 7

Views: 21412

Answers (3)

Jayhello
Jayhello

Reputation: 6602

According to caffe, you can use it this way,below is my project structure:

enter image description here

FindOpenBLAS.cmake contents as below:

SET(Open_BLAS_INCLUDE_SEARCH_PATHS
    /usr/include
    /usr/include/openblas
    /usr/include/openblas-base
    /usr/local/include
    /usr/local/include/openblas
    /usr/local/include/openblas-base
    /opt/OpenBLAS/include
    $ENV{OpenBLAS_HOME}
    $ENV{OpenBLAS_HOME}/include
)

SET(Open_BLAS_LIB_SEARCH_PATHS
    /lib/
    /lib/openblas-base
    /lib64/
    /usr/lib
    /usr/lib/openblas-base
    /usr/lib64
    /usr/local/lib
    /usr/local/lib64
    /opt/OpenBLAS/lib
    $ENV{OpenBLAS}cd
    $ENV{OpenBLAS}/lib
    $ENV{OpenBLAS_HOME}
    $ENV{OpenBLAS_HOME}/lib
)

FIND_PATH(OpenBLAS_INCLUDE_DIR NAMES 
    cblas.h PATHS ${Open_BLAS_INCLUDE_SEARCH_PATHS}
)

FIND_LIBRARY(OpenBLAS_LIB NAMES 
    openblas PATHS ${Open_BLAS_LIB_SEARCH_PATHS}
)

message("OpenBLAS_INCLUDE_DIR: ${OpenBLAS_INCLUDE_DIR}, OpenBLAS_LIB: ${OpenBLAS_LIB}")

when use cmake it outputs :

enter image description here

The main CMakeLists.txt use the above FindOpenBLAS.cmake to find blas:

cmake_minimum_required(VERSION 3.5)
project(my_caffe)

set(CMAKE_CXX_STANDARD 11)


#dependence lib
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(OpenBLAS REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(my_caffe_test ${SOURCE_FILES})
# link blas
target_link_libraries(my_caffe_test
        ${OpenBLAS_LIB}
)

Upvotes: 2

knedlsepp
knedlsepp

Reputation: 6084

CMake supports finding OpenBLAS using FindBLAS since CMake 3.6.0, as this commit finally made it into the release.

NB: OpenBLAS can also be used to substitute LAPACK, for which you should use the FindLAPACK command, that is also available since 3.6.0.

The "FindBLAS" and "FindLAPACK" modules learned to support OpenBLAS.

(See: https://blog.kitware.com/cmake-3-6-0-rc3-is-now-ready/)

Upvotes: 7

coincoin
coincoin

Reputation: 4685

I think you have to write your own CMake module for that. You can check there and there maybe for inspirations

Upvotes: 3

Related Questions