From 1d5d9da9db2dfed356de33dd07ae96769ca52f10 Mon Sep 17 00:00:00 2001 From: liaogang Date: Tue, 9 May 2017 15:15:02 +0800 Subject: [PATCH] refine cblas.cmake --- cmake/cblas.cmake | 3 ++- cmake/external/openblas.cmake | 2 +- paddle/math/MathFunctions.h | 29 ++++++++++++++++++++---- paddle/math/tests/test_matrixCompare.cpp | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cmake/cblas.cmake b/cmake/cblas.cmake index bb084192f86..913f711afff 100644 --- a/cmake/cblas.cmake +++ b/cmake/cblas.cmake @@ -110,6 +110,7 @@ if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB) set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR}) set(CBLAS_LIBRARIES ${OPENBLAS_LIB}) + add_definitions(-DPADDLE_USE_OPENBLAS) add_definitions(-DLAPACK_FOUND) message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") @@ -146,6 +147,6 @@ if (REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY) set(CBLAS_PROVIDER REFERENCE) set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR}) set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY}) - + add_definitions(-DPADDLE_USE_REFERENCE_CBLAS) message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") endif() diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 5b042fec012..18ac74aa6f7 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -36,7 +36,7 @@ IF(NOT ${CBLAS_FOUND}) INSTALL_DIR ${CBLAS_INSTALL_DIR} BUILD_IN_SOURCE 1 BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} FC=${CMAKE_Fortran_COMPILER} CC=${CMAKE_C_COMPILER} HOSTCC=${CMAKE_C_COMPILER} NO_LAPACK=1 DYNAMIC_ARCH=1 NO_SHARED=1 libs netlib - INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install NO_SHARED=1 PREFIX= + INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install NO_SHARED=1 NO_LAPACK=1 PREFIX= UPDATE_COMMAND "" CONFIGURE_COMMAND "" ) diff --git a/paddle/math/MathFunctions.h b/paddle/math/MathFunctions.h index c8559eefd83..c1d233b6cbd 100644 --- a/paddle/math/MathFunctions.h +++ b/paddle/math/MathFunctions.h @@ -18,17 +18,36 @@ limitations under the License. */ #ifdef PADDLE_USE_MKL #include #include -#else -extern "C" { -#include -} +#endif + #ifdef PADDLE_USE_ATLAS extern "C" { +#include #include } -#else +#endif + +#ifdef PADDLE_USE_OPENBLAS +#include #include #endif + +#ifdef PADDLE_USE_REFERENCE_CBLAS +extern "C" { +#include +} +#endif + +#ifndef LAPACK_FOUND +extern "C" { +int LAPACKE_sgetrf(int matrix_layout, int m, int n, +int LAPACKE_dgetrf(int matrix_layout, int m, int n, + double* a, int lda, int* ipiv); +int LAPACKE_sgetri(int matrix_layout, int n, float* a, + int lda, const int* ipiv); +int LAPACKE_dgetri(int matrix_layout, int n, double* a, + int lda, const int* ipiv); +} #endif #include diff --git a/paddle/math/tests/test_matrixCompare.cpp b/paddle/math/tests/test_matrixCompare.cpp index 2bdcab4d866..5a0dffe086c 100644 --- a/paddle/math/tests/test_matrixCompare.cpp +++ b/paddle/math/tests/test_matrixCompare.cpp @@ -247,7 +247,7 @@ TEST(Matrix, unary) { << "1. Simply issue `sudo apt-get install liblapacke-dev` to " "avoid re-build source code. \n" << "2. Install MKL/Openblas/ATLAS and re-build PaddlePaddle " - "source code." + "source code."; #endif } } -- GitLab