From a0b258278ed0c0419a1eb3a86cddd8a6a7562409 Mon Sep 17 00:00:00 2001 From: wanghaoshuang Date: Tue, 24 Apr 2018 16:42:22 +0800 Subject: [PATCH] Reuse 'initP2P(bool, std::vector)' in 'initP2P(bool)' --- paddle/fluid/framework/init.cc | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/paddle/fluid/framework/init.cc b/paddle/fluid/framework/init.cc index 721364e4b..c8775ec72 100644 --- a/paddle/fluid/framework/init.cc +++ b/paddle/fluid/framework/init.cc @@ -108,15 +108,14 @@ void InitP2P(std::vector devices) { } void InitDevices(bool init_p2p) { - /*Init all available devices by default */ - - std::vector places; - places.emplace_back(platform::CPUPlace()); - int count = 0; - +/*Init all available devices by default */ #ifdef PADDLE_WITH_CUDA + std::vector devices; try { - count = platform::GetCUDADeviceCount(); + int count = platform::GetCUDADeviceCount(); + for (int i = 0; i < count; ++i) { + devices.push_back(i); + } } catch (const std::exception &exp) { LOG(WARNING) << "Compiled with WITH_GPU, but no GPU found in runtime."; } @@ -124,14 +123,7 @@ void InitDevices(bool init_p2p) { LOG(WARNING) << "'CUDA' is not supported, Please re-compile with WITH_GPU option"; #endif - - for (int i = 0; i < count; ++i) { - places.emplace_back(platform::CUDAPlace(i)); - } - if (init_p2p) { - InitP2P(count); - } - platform::DeviceContextPool::Init(places); + InitDevices(init_p2p, devices); } void InitDevices(bool init_p2p, const std::vector devices) { -- GitLab