diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index bde42bf1719f..cf37984c3241 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -229,6 +229,10 @@ elseif(BLAS STREQUAL "vecLib") set(BLAS_INFO "veclib") set(BLAS_FOUND 1) set(BLAS_LIBRARIES ${vecLib_LINKER_LIBS}) +elseif(BLAS STREQUAL "FlexiBLAS") + find_package(FlexiBLAS REQUIRED) + include_directories(SYSTEM ${FlexiBLAS_INCLUDE_DIR}) + list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${FlexiBLAS_LIB}) elseif(BLAS STREQUAL "Generic") # On Debian family, the CBLAS ABIs have been merged into libblas.so find_library(BLAS_LIBRARIES blas) @@ -245,7 +249,7 @@ if(NOT INTERN_BUILD_MOBILE) set(AT_MKL_ENABLED 0) set(AT_MKL_MT 0) set(USE_BLAS 1) - if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND)) + if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND)) message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library") find_package(BLAS) if(NOT BLAS_FOUND) diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake index 47c80b45f676..7f74457775cb 100644 --- a/cmake/Modules/FindBLAS.cmake +++ b/cmake/Modules/FindBLAS.cmake @@ -152,6 +152,19 @@ if((NOT BLAS_LIBRARIES) endif() endif() +if((NOT BLAS_LIBRARIES) + AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "flexi"))) + check_fortran_libraries( + BLAS_LIBRARIES + BLAS + sgemm + "" + "flexiblas") + if(BLAS_LIBRARIES) + set(BLAS_INFO "flexi") + endif(BLAS_LIBRARIES) +endif() + if((NOT BLAS_LIBRARIES) AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "open"))) check_fortran_libraries( diff --git a/cmake/Modules/FindFlexiBLAS.cmake b/cmake/Modules/FindFlexiBLAS.cmake new file mode 100644 index 000000000000..71dcda7d260c --- /dev/null +++ b/cmake/Modules/FindFlexiBLAS.cmake @@ -0,0 +1,65 @@ + + +SET(Flexi_BLAS_INCLUDE_SEARCH_PATHS + /usr/include + /usr/include/flexiblas + /usr/include/flexiblas-base + /usr/local/include + /usr/local/include/flexiblas + /usr/local/include/flexiblas-base + /usr/local/opt/flexiblas/include + /opt/Flexiblas/include + $ENV{FlexiBLAS_HOME} + $ENV{FlexiBLAS_HOME}/include +) + +SET(Flexi_BLAS_LIB_SEARCH_PATHS + /lib/ + /lib/flexiblas-base + /lib64/ + /usr/lib + /usr/lib/flexiblas-base + /usr/lib64 + /usr/local/lib + /usr/local/lib64 + /usr/local/opt/flexiblas/lib + /opt/FlexiBLAS/lib + $ENV{FlexiBLAS} + $ENV{FlexiBLAS}/lib + $ENV{FlexiBLAS_HOME} + $ENV{FlexiBLAS_HOME}/lib + ) + +FIND_PATH(FlexiBLAS_INCLUDE_DIR NAMES cblas.h PATHS ${Flexi_BLAS_INCLUDE_SEARCH_PATHS}) +FIND_LIBRARY(FlexiBLAS_LIB NAMES flexiblas PATHS ${Flexi_BLAS_LIB_SEARCH_PATHS}) + +SET(FlexiBLAS_FOUND ON) + +# Check include files +IF(NOT FlexiBLAS_INCLUDE_DIR) + SET(FlexiBLAS_FOUND OFF) + MESSAGE(STATUS "Could not find FlexiBLAS include. Turning FlexiBLAS_FOUND off") +ENDIF() + +# Check libraries +IF(NOT FlexiBLAS_LIB) + SET(FlexiBLAS_FOUND OFF) + MESSAGE(STATUS "Could not find FlexiBLAS lib. Turning FlexiBLAS_FOUND off") +ENDIF() + +IF (FlexiBLAS_FOUND) + IF (NOT FlexiBLAS_FIND_QUIETLY) + MESSAGE(STATUS "Found FlexiBLAS libraries: ${FlexiBLAS_LIB}") + MESSAGE(STATUS "Found FlexiBLAS include: ${FlexiBLAS_INCLUDE_DIR}") + ENDIF (NOT FlexiBLAS_FIND_QUIETLY) +ELSE (FlexiBLAS_FOUND) + IF (FlexiBLAS_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find FlexiBLAS") + ENDIF (FlexiBLAS_FIND_REQUIRED) +ENDIF (FlexiBLAS_FOUND) + +MARK_AS_ADVANCED( + FlexiBLAS_INCLUDE_DIR + FlexiBLAS_LIB + FlexiBLAS +) diff --git a/cmake/Modules/FindLAPACK.cmake b/cmake/Modules/FindLAPACK.cmake index 806e8f92b6c4..02367ff9866c 100644 --- a/cmake/Modules/FindLAPACK.cmake +++ b/cmake/Modules/FindLAPACK.cmake @@ -119,6 +119,18 @@ if(BLAS_FOUND) endif() endif() + # FlexiBLAS + IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "flexi")) + SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) + check_function_exists("cheev_" FLEXIBLAS_LAPACK_WORKS) + set(CMAKE_REQUIRED_LIBRARIES) + if(FLEXIBLAS_LAPACK_WORKS) + SET(LAPACK_INFO "flexi") + else() + message(STATUS "Strangely, this FlexiBLAS library does not support Lapack?!") + endif() + endif() + # OpenBlas IF((NOT LAPACK_INFO) AND (BLAS_INFO STREQUAL "open")) SET(CMAKE_REQUIRED_LIBRARIES ${BLAS_LIBRARIES}) diff --git a/setup.py b/setup.py index a5fd33d62321..32fefeb9d255 100644 --- a/setup.py +++ b/setup.py @@ -121,7 +121,7 @@ # one in this file; needed to build with other frameworks that share ONNX. # # BLAS -# BLAS to be used by Caffe2. Can be MKL, Eigen, ATLAS, or OpenBLAS. If set +# BLAS to be used by Caffe2. Can be MKL, Eigen, ATLAS, FlexiBLAS, or OpenBLAS. If set # then the build will fail if the requested BLAS is not found, otherwise # the BLAS will be chosen based on what is found on your system. #