diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index 0918e6cc633e7067b8bd2d5c5e1622d4139d4d14..91663a16ba692aaa4504ce945c84e65968e93c1b 100644 --- a/cmake/cblas.cmake +++ b/cmake/cblas.cmake @@ -33,7 +33,6 @@ find_library(MKL_INTEL_LP64 NAMES mkl_intel_lp64 PATHS ${MKL_ROOT}/lib ${MKL_ROOT}/lib/intel64) - if(MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) set(CBLAS_PROVIDER MKL) set(CBLAS_INC_DIR ${MKL_INC_DIR}) @@ -41,6 +40,7 @@ if(MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) ${MKL_SEQUENTIAL_LIB} ${MKL_CORE_LIB}) add_definitions(-DPADDLE_USE_MKL) + add_definitions(-DLAPACK_FOUND) message(STATUS "Found MKL (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(${MKL_LAPACK_INC_DIR}) @@ -76,6 +76,7 @@ if(ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_LIB AND NOT CBLAS_FOUND) set(CBLAS_INC_DIR ${ATLAS_INC_DIR}) set(CBLAS_LIBRARIES ${ATLAS_LIB} ${ATLAS_CBLAS_LIB}) add_definitions(-DPADDLE_USE_ATLAS) + add_definitions(-DLAPACK_FOUND) message(STATUS "Found ATLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(ATLAS_CLAPACK_INC_DIR) @@ -110,6 +111,7 @@ if(OPENBLAS_INC_DIR AND OPENBLAS_LIB) set(CBLAS_PROVIDER OPENBLAS) set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR}) set(CBLAS_LIBRARIES ${OPENBLAS_LIB}) + add_definitions(-DLAPACK_FOUND) message(STATUS "Found OpenBLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(OPENBLAS_LAPACKE_INC_DIR) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 46398b22c27ae22abf261d61807c6b10becfff36..86cb473c385a9e23ba6cf64359cb83b92cfd9448 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -15,6 +15,7 @@ INCLUDE(cblas) IF(NOT ${CBLAS_FOUND}) + SET(LAPACK_FOUND OFF) INCLUDE(ExternalProject) SET(CBLAS_SOURCES_DIR ${THIRD_PARTY_PATH}/openblas) diff --git a/paddle/math/MathFunctions.cpp b/paddle/math/MathFunctions.cpp index 802a56a0d15a2ebbe6c62350832611373001ac9f..1a3bb432bfb743fe814fa94c0c104bb6bc598cb8 100644 --- a/paddle/math/MathFunctions.cpp +++ b/paddle/math/MathFunctions.cpp @@ -34,6 +34,9 @@ void* lapack_dso_handle = nullptr; // We have to use two levels of macro to do the expansion. // See https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html #define STR(x) #x + +// clang-format off +#ifndef LAPACK_FOUND #define DYNAMIC_LOAD_LAPACK_WRAP(__name) \ struct DynLoad__##__name { \ template \ @@ -46,8 +49,16 @@ void* lapack_dso_handle = nullptr; return reinterpret_cast(p_##__name)(args...); \ } \ } __name; // struct DynLoad__##__name +#else +#define DYNAMIC_LOAD_LAPACK_WRAP(__name) \ + struct DynLoad__##__name { \ + template \ + auto operator()(Args... args) -> decltype(__name(args...)) { \ + return __name(args...); \ + } \ + } __name; // struct DynLoad__##__name +#endif -// clang-format off #ifdef PADDLE_USE_ATLAS #define PADDLE_SGETRF clapack_sgetrf #define PADDLE_DGETRF clapack_dgetrf