[cmake] Support "Generic" BLAS (#14699) (#37276)

Summary:
The "Generic" BLAS refers to the Netlib BLAS. This option is meaningful
to the Debian family due to the "update-alternatives" mechanism, which
enables the user to switch the libblas.so providers between different
implementations at runtime, such as ATLAS, OpenBLAS, and Intel MKL.
Such, building against generic BLAS provides much flexibility.

This new option is not documented in setup.py because it's only supposed
to be used by linux distro (especially Debian family) developersonly.

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37276

Differential Revision: D21256877

Pulled By: ezyang

fbshipit-source-id: 55a5356653a1cfc763a5699b04afe5938f2007ec
This commit is contained in:
Mo Zhou 2020-04-27 08:14:39 -07:00 committed by Facebook GitHub Bot
parent 22ac071d9a
commit 007163407c

View File

@ -107,7 +107,7 @@ else()
set(AT_MKLDNN_ENABLED 0) set(AT_MKLDNN_ENABLED 0)
set(AT_MKL_ENABLED 0) set(AT_MKL_ENABLED 0)
endif() endif()
set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;FLAME") set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;FLAME;Generic")
message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS}) message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
if(BLAS STREQUAL "Eigen") if(BLAS STREQUAL "Eigen")
@ -147,6 +147,12 @@ elseif(BLAS STREQUAL "vecLib")
find_package(vecLib REQUIRED) find_package(vecLib REQUIRED)
include_directories(SYSTEM ${vecLib_INCLUDE_DIR}) include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS}) list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
elseif(BLAS STREQUAL "Generic")
# On Debian family, the CBLAS ABIs have been merged into libblas.so
find_library(BLAS_LIBRARIES blas)
message("-- Using BLAS: ${BLAS_LIBRARIES}")
list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${BLAS_LIBRARIES})
set(GENERIC_BLAS_FOUND TRUE)
else() else()
message(FATAL_ERROR "Unrecognized BLAS option: " ${BLAS}) message(FATAL_ERROR "Unrecognized BLAS option: " ${BLAS})
endif() endif()
@ -155,7 +161,7 @@ if(NOT INTERN_BUILD_MOBILE)
set(AT_MKL_ENABLED 0) set(AT_MKL_ENABLED 0)
set(AT_MKL_MT 0) set(AT_MKL_MT 0)
set(USE_BLAS 1) set(USE_BLAS 1)
if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND)) if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND OR GENERIC_BLAS_FOUND))
message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library") message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
find_package(BLAS) find_package(BLAS)
if(NOT BLAS_FOUND) if(NOT BLAS_FOUND)