From b2c8a0074568b018dc71dd14ab61739ce45b205c Mon Sep 17 00:00:00 2001 From: wawltor Date: Wed, 25 Nov 2020 10:47:13 +0800 Subject: [PATCH] remove eigen threadpool for the speed up remove eigen threadpool for the speed up --- paddle/fluid/operators/math/math_function.cc | 8 +------- paddle/fluid/platform/device_context.cc | 18 ------------------ paddle/fluid/platform/device_context.h | 7 ------- 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/paddle/fluid/operators/math/math_function.cc b/paddle/fluid/operators/math/math_function.cc index 8c7437e4b5e..1da8c89a6d1 100644 --- a/paddle/fluid/operators/math/math_function.cc +++ b/paddle/fluid/operators/math/math_function.cc @@ -99,13 +99,7 @@ struct TransposeNormal { out_ptr[out_idx] = in_ptr[in_idx]; } }; - double cost_per_iteration = - rank * (Eigen::TensorOpCost::DivCost() + - 2 * Eigen::TensorOpCost::MulCost() + - 2 * Eigen::TensorOpCost::AddCost()); - Eigen::TensorOpCost cost(sizeof(T), sizeof(T), cost_per_iteration); - auto* cpu_device = context.eigen_pool_device(); - cpu_device->parallelFor(out->numel(), cost, std::move(transpose_helper)); + transpose_helper(0, out->numel()); } }; diff --git a/paddle/fluid/platform/device_context.cc b/paddle/fluid/platform/device_context.cc index 2e1517aa79e..29982c13c8c 100644 --- a/paddle/fluid/platform/device_context.cc +++ b/paddle/fluid/platform/device_context.cc @@ -12,7 +12,6 @@ limitations under the License. */ #include "paddle/fluid/platform/device_context.h" #include #include -#include //NOLINT #include #include @@ -24,7 +23,6 @@ limitations under the License. */ #endif #include "glog/logging.h" -#include "unsupported/Eigen/CXX11/ThreadPool" namespace paddle { namespace memory { @@ -133,32 +131,16 @@ DeviceContextPool::DeviceContextPool( CPUDeviceContext::CPUDeviceContext() { eigen_device_.reset(new Eigen::DefaultDevice()); - InitPoolDevice(); } CPUDeviceContext::CPUDeviceContext(CPUPlace place) : place_(place) { eigen_device_.reset(new Eigen::DefaultDevice()); - InitPoolDevice(); -} - -void CPUDeviceContext::InitPoolDevice() { - using EigenEnv = Eigen::StlThreadEnvironment; - using EigenThreadPool = Eigen::ThreadPoolTempl; - // int num_threads = std::thread::hardware_concurrency(); - int num_threads = 1; - eigen_threadpool_.reset(new EigenThreadPool(num_threads)); - eigen_pool_device_.reset( - new Eigen::ThreadPoolDevice(eigen_threadpool_.get(), num_threads)); } Eigen::DefaultDevice* CPUDeviceContext::eigen_device() const { return eigen_device_.get(); } -Eigen::ThreadPoolDevice* CPUDeviceContext::eigen_pool_device() const { - return eigen_pool_device_.get(); -} - Place CPUDeviceContext::GetPlace() const { return place_; } #ifdef PADDLE_WITH_XPU diff --git a/paddle/fluid/platform/device_context.h b/paddle/fluid/platform/device_context.h index 074106f3f20..620e2d41c13 100644 --- a/paddle/fluid/platform/device_context.h +++ b/paddle/fluid/platform/device_context.h @@ -43,7 +43,6 @@ limitations under the License. */ #ifdef PADDLE_WITH_CUDA #include "paddle/fluid/platform/stream/cuda_stream.h" #endif -#define EIGEN_USE_THREADS #include "unsupported/Eigen/CXX11/Tensor" namespace Eigen { @@ -73,17 +72,11 @@ class CPUDeviceContext : public DeviceContext { Eigen::DefaultDevice* eigen_device() const; - Eigen::ThreadPoolDevice* eigen_pool_device() const; - Place GetPlace() const override; - inline void InitPoolDevice(); - private: CPUPlace place_; std::unique_ptr eigen_device_; - std::unique_ptr eigen_pool_device_; - std::unique_ptr eigen_threadpool_; }; template -- GitLab