From 20cda7bd23195da38dec324f8a7b4ac698fec1f4 Mon Sep 17 00:00:00 2001 From: liaogang Date: Thu, 4 May 2017 17:27:05 +0800 Subject: [PATCH] auto check lapack libs --- cmake/cblas.cmake | 4 +++- cmake/external/openblas.cmake | 1 + paddle/math/MathFunctions.cpp | 13 ++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index 0918e6cc633..91663a16ba6 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 46398b22c27..86cb473c385 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 802a56a0d15..1a3bb432bfb 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 -- GitLab