为了演示,我使用3行CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
find_package( BLAS REQUIRED )
message( STATUS BLAS found: ${BLAS_LIBRARIES} )
我有cblas,ATLAS和OpenBLAS,包括安装在Debian Linux系统上的开发人员软件包,以及CMake 2.8.9。当我打电话
cmake . -DBLA_VENDOR=ATLAS -DCMAKE_PREFIX_PATH=/usr/lib/atlas-base
ATLAS库很容易找到:
-- 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
同样,只是
cmake .
会为我找到/usr/lib/libblas.so
。 (我不会忘记在第二次调用之前删除缓存文件。)
当我查看/usr/share/cmake-2.8/Modules/FindBLAS.cmake
时,我读作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
即,未列出OpenBLAS。还有一些随机试验,如
cmake . -DBLA_VENDOR=open -DCMAKE_PREFIX_PATH=/usr/lib/openblas-base
也不起作用。我是否必须编写自己的FindBLAS才能使用CMake链接到OpenBLAS?
答案 0 :(得分:4)
CMake支持使用FindBLAS
查找OpenBLAS,因为 CMake 3.6.0 ,因为this commit最终进入了发布版。
注意:OpenBLAS也可用于替换LAPACK,您应该使用FindLAPACK
命令,该命令自3.6.0以来也可用。
“FindBLAS”和“FindLAPACK”模块学会了支持OpenBLAS。
答案 1 :(得分:3)
答案 2 :(得分:0)
根据caffe,您可以通过以下方式使用它,以下是我的项目结构:
FindOpenBLAS.cmake
的内容如下:
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}")
使用cmake时输出:
主要CMakeLists.txt
使用上面的FindOpenBLAS.cmake
查找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}
)