From a4b452a2d60733ffc39c8033515a8eb4081883aa Mon Sep 17 00:00:00 2001 From: wanghaoshuang Date: Tue, 24 Apr 2018 18:55:16 +0800 Subject: [PATCH] Remove initP2P(bool) and init function in framework. --- paddle/fluid/framework/init.cc | 39 ---------------------------------- paddle/fluid/framework/init.h | 2 -- paddle/fluid/inference/io.cc | 16 +++++++++++++- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/paddle/fluid/framework/init.cc b/paddle/fluid/framework/init.cc index c8775ec727..ee42bc725b 100644 --- a/paddle/fluid/framework/init.cc +++ b/paddle/fluid/framework/init.cc @@ -15,7 +15,6 @@ limitations under the License. */ #include #include #include -#include #include "paddle/fluid/framework/init.h" #include "paddle/fluid/framework/operator.h" @@ -26,26 +25,9 @@ limitations under the License. */ namespace paddle { namespace framework { -DEFINE_string(devices, "", "The devices to be used."); -DEFINE_bool(init_p2p, true, "Whether to init p2p."); - std::once_flag gflags_init_flag; std::once_flag p2p_init_flag; -using paddle::platform::DeviceContextPool; - -void Init(std::vector argv) { - InitGflags(argv); - // init devices - std::vector devices; - std::string token; - std::istringstream tokenStream(FLAGS_devices); - while (std::getline(tokenStream, token, ',')) { - devices.push_back(std::stoi(token)); - } - InitDevices(FLAGS_init_p2p, devices); -} - void InitGflags(std::vector argv) { std::call_once(gflags_init_flag, [&]() { argv.push_back("dummy"); @@ -62,27 +44,6 @@ void InitGflags(std::vector argv) { }); } -void InitP2P(int count) { -#ifdef PADDLE_WITH_CUDA - std::call_once(p2p_init_flag, [&]() { - for (int i = 0; i < count; ++i) { - for (int j = 0; j < count; ++j) { - if (i == j) continue; - int can_acess = -1; - PADDLE_ENFORCE(cudaDeviceCanAccessPeer(&can_acess, i, j), - "Failed to test P2P access."); - if (can_acess != 1) { - LOG(WARNING) << "Cannot enable P2P access from " << i << " to " << j; - } else { - cudaSetDevice(i); - cudaDeviceEnablePeerAccess(j, 0); - } - } - } - }); -#endif -} - void InitP2P(std::vector devices) { #ifdef PADDLE_WITH_CUDA std::call_once(p2p_init_flag, [&]() { diff --git a/paddle/fluid/framework/init.h b/paddle/fluid/framework/init.h index 05ce3376fe..0e30594672 100644 --- a/paddle/fluid/framework/init.h +++ b/paddle/fluid/framework/init.h @@ -22,8 +22,6 @@ limitations under the License. */ namespace paddle { namespace framework { -void Init(std::vector argv); - void InitGflags(std::vector argv); void InitGLOG(const std::string &prog_name); diff --git a/paddle/fluid/inference/io.cc b/paddle/fluid/inference/io.cc index 734b220a1d..5b8dec199d 100644 --- a/paddle/fluid/inference/io.cc +++ b/paddle/fluid/inference/io.cc @@ -16,15 +16,29 @@ limitations under the License. */ #include #include +#include #include "paddle/fluid/framework/block_desc.h" #include "paddle/fluid/framework/feed_fetch_type.h" #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/pybind/pybind.h" +DEFINE_string(devices, "", "The devices to be used."); +DEFINE_bool(init_p2p, true, "Whether to init p2p."); + namespace paddle { namespace inference { -void Init(const std::vector argv) { framework::Init(argv); } +void Init(const std::vector argv) { + framework::InitGflags(argv); + // init devices + std::vector devices; + std::string token; + std::istringstream tokenStream(FLAGS_devices); + while (std::getline(tokenStream, token, ',')) { + devices.push_back(std::stoi(token)); + } + framework::InitDevices(FLAGS_init_p2p, devices); +} void ReadBinaryFile(const std::string& filename, std::string* contents) { std::ifstream fin(filename, std::ios::in | std::ios::binary); -- GitLab