From adcca2cc064182cd75809dd1e3d8c64329a0b0de Mon Sep 17 00:00:00 2001 From: hedaoyuan Date: Thu, 17 Aug 2017 16:40:38 +0800 Subject: [PATCH] Add PADDLE_USE_EIGEN_FOR_BLAS macro. --- CMakeLists.txt | 1 + cmake/configure.cmake | 4 ++++ paddle/function/GemmFunctor.cpp | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd1218a5..28bbfd791 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ option(WITH_C_API "Compile PaddlePaddle with C-API(Prediction)" OFF) option(WITH_GOLANG "Compile PaddlePaddle with GOLANG" OFF) option(GLIDE_INSTALL "Download and install go dependencies " ON) option(USE_NNPACK "Compile PaddlePaddle with NNPACK library" OFF) +option(USE_EIGEN_FOR_BLAS "Use matrix multiplication in Eigen" OFF) # CMAKE_BUILD_TYPE if(NOT CMAKE_BUILD_TYPE) diff --git a/cmake/configure.cmake b/cmake/configure.cmake index 209f9078a..51c3b918c 100644 --- a/cmake/configure.cmake +++ b/cmake/configure.cmake @@ -28,6 +28,10 @@ if(NOT WITH_TIMER) add_definitions(-DPADDLE_DISABLE_TIMER) endif(NOT WITH_TIMER) +if(USE_EIGEN_FOR_BLAS) + add_definitions(-DPADDLE_USE_EIGEN_FOR_BLAS) +endif(USE_EIGEN_FOR_BLAS) + if(NOT WITH_PROFILER) add_definitions(-DPADDLE_DISABLE_PROFILER) endif(NOT WITH_PROFILER) diff --git a/paddle/function/GemmFunctor.cpp b/paddle/function/GemmFunctor.cpp index 8df9b884f..dc83278d8 100644 --- a/paddle/function/GemmFunctor.cpp +++ b/paddle/function/GemmFunctor.cpp @@ -32,6 +32,10 @@ struct BlasGemm { const T beta, T* C, const int ldc) { +#ifdef PADDLE_USE_EIGEN_FOR_BLAS + EigenBlasGemm::compute( + transA, transB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); +#else gemm(transA == false ? CblasNoTrans : CblasTrans, transB == false ? CblasNoTrans : CblasTrans, M, @@ -45,6 +49,7 @@ struct BlasGemm { beta, C, ldc); +#endif } }; -- GitLab