diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index 69b7fe61c2db89c708d1510b2fc88c919cbf2d58..b8bf1bb07a1f779354b2c10071264bf41d279f6c 100644 --- a/cmake/cblas.cmake +++ b/cmake/cblas.cmake @@ -14,31 +14,6 @@ # set(CBLAS_FOUND OFF) -set(LAPACK_FOUND OFF) - -macro(find_lapack) - ## Find clapack - set(CLAPACK_ROOT $ENV{CLAPACK_ROOT} CACHE PATH "Folder contain clapack") - find_path(CLAPACK_INC_DIR NAMES clapack.h PATHS - ${CLAPACK_ROOT}/include) - find_path(CLAPACK_F2C_INC_DIR NAMES f2c.h PATHS - ${CLAPACK_ROOT}/include) - find_library(CLAPACK_F2C_LIB NAMES f2c PATHS - ${CLAPACK_ROOT}/lib) - find_library(CLAPACK_CBLASWR_LIB NAMES cblaswr PATHS - ${CLAPACK_ROOT}/lib) - find_library(CLAPACK_CLAPACK_LIB NAMES clapack PATHS - ${CLAPACK_ROOT}/lib) - if(CLAPACK_INC_DIR AND CLAPACK_F2C_INC_DIR AND CLAPACK_F2C_LIB AND - CLAPACK_CBLASWR_LIB AND CLAPACK_CLAPACK_LIB AND NOT LAPACK_FOUND) - set(LAPACK_PROVIDER CLAPACK) - set(LAPACK_INC_DIR ${CLAPACK_INC_DIR}) - set(LAPACK_LIBRARIES ${CLAPACK_F2C_LIB} ${CLAPACK_CBLASWR_LIB} ${CLAPACK_CLAPACK_LIB}) - add_definitions(-DPADDLE_USE_CLAPACK) - message(STATUS "Found CLAPACK (include: ${LAPACK_INC_DIR}, library: ${LAPACK_LIBRARIES})") - set(LAPACK_FOUND ON) - endif() -endmacro() ## Find MKL First. set(INTEL_ROOT "/opt/intel" CACHE PATH "Folder contains intel libs") @@ -69,11 +44,8 @@ if(MKL_INC_DIR AND MKL_CORE_LIB AND MKL_SEQUENTIAL_LIB AND MKL_INTEL_LP64) message(STATUS "Found MKL (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(${MKL_LAPACK_INC_DIR}) - set(LAPACK_INC_DIR ${MKL_LAPACK_INC_DIR}) + add_definitions(-DPADDLE_USE_LAPACK) message(STATUS "Found lapack in MKL (include: ${MKL_LAPACK_INC_DIR})") - set(LAPACK_FOUND ON) - else() - find_lapack() endif() return() # return file. endif() @@ -108,11 +80,8 @@ if(ATLAS_INC_DIR AND ATLAS_CBLAS_LIB AND ATLAS_LIB AND NOT CBLAS_FOUND) message(STATUS "Found ATLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(ATLAS_CLAPACK_INC_DIR) - set(LAPACK_INC_DIR ${ATLAS_CLAPACK_INC_DIR}) + add_definitions(-DPADDLE_USE_LAPACK) message(STATUS "Found lapack in ATLAS (include: ${ATLAS_CLAPACK_INC_DIR})") - set(LAPACK_FOUND ON) - else() - find_lapack() endif() return() endif() @@ -145,11 +114,8 @@ if(OPENBLAS_INC_DIR AND OPENBLAS_LIB) message(STATUS "Found OpenBLAS (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") set(CBLAS_FOUND ON) if(OPENBLAS_LAPACKE_INC_DIR) - set(LAPACK_INC_DIR ${OPENBLAS_LAPACKE_INC_DIR}) + add_definitions(-DPADDLE_USE_LAPACK) message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})") - set(LAPACK_FOUND ON) - else() - find_lapack() endif() return() endif() diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index f18d8dab044bb203758522d41901b0027e32a62b..21fd5f41b8ddc9271fb834f62a40cc1aa9261cef 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -20,7 +20,6 @@ IF(NOT ${CBLAS_FOUND}) SET(CBLAS_SOURCES_DIR ${THIRD_PARTY_PATH}/openblas) SET(CBLAS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/openblas) SET(CBLAS_INC_DIR "${CBLAS_INSTALL_DIR}/include" CACHE PATH "openblas include directory." FORCE) - SET(LAPACK_INC_DIR "${CBLAS_INSTALL_DIR}/include" CACHE PATH "lapack (in openblas) include directory." FORCE) IF(WIN32) SET(CBLAS_LIBRARIES "${CBLAS_INSTALL_DIR}/lib/openblas.lib" CACHE FILEPATH "openblas library." FORCE) @@ -38,6 +37,8 @@ IF(NOT ${CBLAS_FOUND}) "you need to set gfortran compiler: cmake .. -DCMAKE_Fortran_COMPILER=...") ENDIF(NOT CMAKE_Fortran_COMPILER) + ADD_DEFINITIONS(-DPADDLE_USE_LAPACK) + ExternalProject_Add( openblas ${EXTERNAL_PROJECT_LOG_ARGS} @@ -65,4 +66,3 @@ IF(NOT ${CBLAS_FOUND}) ENDIF(NOT ${CBLAS_FOUND}) INCLUDE_DIRECTORIES(${CBLAS_INC_DIR}) -INCLUDE_DIRECTORIES(${LAPACK_INC_DIR}) diff --git a/cmake/external/zlib.cmake b/cmake/external/zlib.cmake index 47fa8817fb64fb8fd718e2892ad5bae7bbe956eb..f456b79b7386f5de2abb368b0724b9cabd183e3e 100644 --- a/cmake/external/zlib.cmake +++ b/cmake/external/zlib.cmake @@ -22,7 +22,7 @@ SET(ZLIB_INCLUDE_DIR "${ZLIB_INSTALL_DIR}/include" CACHE PATH "zlib include dire IF(WIN32) SET(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/zlibstatic.lib" CACHE FILEPATH "zlib library." FORCE) ELSE(WIN32) - set(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/libz.a" CACHE FILEPATH "zlib library." FORCE) + SET(ZLIB_LIBRARIES "${ZLIB_INSTALL_DIR}/lib/libz.a" CACHE FILEPATH "zlib library." FORCE) ENDIF(WIN32) INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) diff --git a/cmake/simd.cmake b/cmake/simd.cmake index adb36a38add7aa6125a6be2df43dd5ae1893481c..4e4c4e6e437339d9a5a3abde4ea2d27580b9e88b 100644 --- a/cmake/simd.cmake +++ b/cmake/simd.cmake @@ -10,7 +10,7 @@ IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID set(SSE3_FLAG "-msse3") SET(AVX_FLAG "-mavx") SET(AVX2_FLAG "-mavx2") - SET(NEON_FLAG "-mfloat-abi=softfp -mfpu=neon") + SET(NEON_FLAG "-pie -fPIE -mfloat-abi=softfp -mfpu=neon") ELSEIF(MSVC) set(MMX_FLAG "/arch:MMX") set(SSE2_FLAG "/arch:SSE2") diff --git a/paddle/math/MathFunctions.cpp b/paddle/math/MathFunctions.cpp index d7aa1184872d5a6129becca1f6e282776c9dbe15..91817eab468de29f0bf693433657f20103f87570 100644 --- a/paddle/math/MathFunctions.cpp +++ b/paddle/math/MathFunctions.cpp @@ -85,11 +85,16 @@ int getrf(const CBLAS_ORDER order, float* A, const int lda, int* ipiv) { +#ifdef PADDLE_USE_LAPACK #ifdef PADDLE_USE_ATLAS return clapack_sgetrf(order, M, N, A, lda, ipiv); #else return LAPACKE_sgetrf(order, M, N, A, lda, ipiv); #endif +#else + LOG(FATAL) << "Not implemented"; +#endif + return 0; } template <> @@ -99,11 +104,16 @@ int getrf(const CBLAS_ORDER order, double* A, const int lda, int* ipiv) { +#ifdef PADDLE_USE_LAPACK #ifdef PADDLE_USE_ATLAS return clapack_dgetrf(order, M, N, A, lda, ipiv); #else return LAPACKE_dgetrf(order, M, N, A, lda, ipiv); #endif +#else + LOG(FATAL) << "Not implemented". +#endif + return 0; } template <> @@ -112,11 +122,16 @@ int getri(const CBLAS_ORDER order, float* A, const int lda, const int* ipiv) { +#ifdef PADDLE_USE_LAPACK #ifdef PADDLE_USE_ATLAS return clapack_sgetri(order, N, A, lda, ipiv); #else return LAPACKE_sgetri(order, N, A, lda, ipiv); #endif +#else + LOG(FATAL) << "Not implemented". +#endif + return 0; } template <> @@ -125,11 +140,16 @@ int getri(const CBLAS_ORDER order, double* A, const int lda, const int* ipiv) { +#ifdef PADDLE_USE_LAPACK #ifdef PADDLE_USE_ATLAS return clapack_dgetri(order, N, A, lda, ipiv); #else return LAPACKE_dgetri(order, N, A, lda, ipiv); #endif +#else + LOG(FATAL) << "Not implemented". +#endif + return 0; } template <> diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index 4d3f701b9a74b5488625e3ee94c6d00c197b3290..9f8f84a87c5e60b2a6573844f251c42152d8156b 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -17,23 +17,19 @@ limitations under the License. */ #ifdef PADDLE_USE_MKL #include -#ifdef PADDLE_USE_CLAPACK -#include -#else +#ifdef PADDLE_USE_LAPACK #include #endif #else extern "C" { #include } +#ifdef PADDLE_USE_LAPACK #ifdef PADDLE_USE_ATLAS extern "C" { #include } #else -#ifdef PADDLE_USE_CLAPACK -#include -#else #include #endif #endif diff --git a/paddle/utils/CpuId.h b/paddle/utils/CpuId.h index efad946ae7f1b7d2b4fa3b1acd96387d1d59d5e8..385bc36a8bccc322323901ac9f974652c4a973b7 100644 --- a/paddle/utils/CpuId.h +++ b/paddle/utils/CpuId.h @@ -18,7 +18,6 @@ namespace paddle { // clang-format off enum simd_t { SIMD_NONE = 0, ///< None -#if !defined(__ANDROID__) SIMD_SSE = 1 << 0, ///< SSE SIMD_SSE2 = 1 << 1, ///< SSE 2 SIMD_SSE3 = 1 << 2, ///< SSE 3 @@ -30,9 +29,7 @@ enum simd_t { SIMD_AVX = 1 << 8, ///< AVX SIMD_AVX2 = 1 << 9, ///< AVX 2 SIMD_AVX512 = 1 << 10, ///< AVX 512 -#else - SIMD_NEON = 1 << 0, ///< NEON -#endif + SIMD_NEON = 1 << 11, /// NEON }; // clang-format on @@ -99,6 +96,7 @@ private: #define HAS_AVX HAS_SIMD(SIMD_AVX) #define HAS_AVX2 HAS_SIMD(SIMD_AVX2) #define HAS_AVX512 HAS_SIMD(SIMD_AVX512) +#define HAS_NEON HAS_SIMD(SIMD_NEON) // clang-format on } // namespace paddle