diff --git a/paddle/fluid/framework/init.cc b/paddle/fluid/framework/init.cc index c8775ec727a29bfd9edfd9c96686761e2b3e8e35..ee42bc725b131ebdceb16cab7037e067755bab3e 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 05ce3376feaddcb926aa8ec0255d8d3f7a3b782d..0e30594672927253cc8083dcb88bb867d63ec729 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 734b220a1d3cf9f49b11af5d87371046a033da3f..5b8dec199d90c12a0a2781c385da9942625b766a 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);