diff --git a/paddle/fluid/framework/init.cc b/paddle/fluid/framework/init.cc index 3ce37041cbc1403eef2fafec2d505c75605c2139..642b892105a83fa19f0a1a501ecaa7d00f6ac5d9 100644 --- a/paddle/fluid/framework/init.cc +++ b/paddle/fluid/framework/init.cc @@ -20,7 +20,6 @@ limitations under the License. */ #include "paddle/fluid/framework/init.h" #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/platform/device_context.h" -#include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/place.h" #include "paddle/fluid/string/piece.h" @@ -35,10 +34,8 @@ std::once_flag p2p_init_flag; using paddle::platform::DeviceContextPool; -void Init(int argc, char **argv) { - std::call_once(gflags_init_flag, - [&]() { google::ParseCommandLineFlags(&argc, &argv, true); }); - +void Init(std::vector &argv) { + InitGflags(argv); // init devices std::vector devices; std::string token; @@ -51,6 +48,7 @@ void Init(int argc, char **argv) { void InitGflags(std::vector &argv) { std::call_once(gflags_init_flag, [&]() { + argv.push_back("dummy"); int argc = argv.size(); char **arr = new char *[argv.size()]; std::string line; @@ -151,7 +149,7 @@ void InitDevices(bool init_p2p, const std::vector devices) { #endif for (size_t i = 0; i < devices.size(); ++i) { - if (devices[i] >= count) { + if (devices[i] >= count || devices[i] < 0) { LOG(WARNING) << "Invalid devices id."; continue; } diff --git a/paddle/fluid/framework/init.h b/paddle/fluid/framework/init.h index 38604d232c641d4bff3e077f660e6006d48271ed..cf792f18b7ac16808d09e86a982e741fd0dca968 100644 --- a/paddle/fluid/framework/init.h +++ b/paddle/fluid/framework/init.h @@ -20,7 +20,7 @@ limitations under the License. */ namespace paddle { namespace framework { -void Init(int argc, char **argv); +void Init(std::vector &argv); void InitGflags(std::vector &argv); diff --git a/paddle/fluid/inference/io.cc b/paddle/fluid/inference/io.cc index 74068d9dbe7b7a7326837286814e877d6d86b35c..9c37e0178a3e660008dfa7004877f6261c5e00b7 100644 --- a/paddle/fluid/inference/io.cc +++ b/paddle/fluid/inference/io.cc @@ -24,11 +24,7 @@ limitations under the License. */ namespace paddle { namespace inference { -// Temporarily add this function for exposing framework::InitDevices() when -// linking the inference shared library. -void Init(bool init_p2p) { framework::InitDevices(init_p2p); } - -void Init(int argc, char** argv) { framework::Init(argc, argv); } +void Init(std::vector &argv) { framework::Init(argv); } void ReadBinaryFile(const std::string& filename, std::string* contents) { std::ifstream fin(filename, std::ios::in | std::ios::binary); diff --git a/paddle/fluid/inference/io.h b/paddle/fluid/inference/io.h index 988b8aebbe1a73a7110a7960e6d63af54360c278..799693b0c5d846dce762af1f636ebfbecad80f85 100644 --- a/paddle/fluid/inference/io.h +++ b/paddle/fluid/inference/io.h @@ -25,9 +25,7 @@ limitations under the License. */ namespace paddle { namespace inference { -void Init(bool init_p2p); - -void Init(int argc, char** argv); +void Init(std::vector &argv); void LoadPersistables(framework::Executor* executor, framework::Scope* scope, const framework::ProgramDesc& main_program,