diff --git a/paddle/fluid/inference/api/api.cc b/paddle/fluid/inference/api/api.cc index 591341b3644735e2c3d6dc09dba571c16ac41858..458eecfeea6ff27c96a8864ba8a08a9e5c587df5 100644 --- a/paddle/fluid/inference/api/api.cc +++ b/paddle/fluid/inference/api/api.cc @@ -120,12 +120,19 @@ std::string get_version() { return ss.str(); } -#if defined(_WIN32) && defined(PADDLE_ON_INFERENCE) - std::string UpdateDllFlag(const char *name, const char *value) { - return google::SetCommandLineOption(name, value); + std::string ret; + LOG(WARNING) + << "The function \"UpdateDllFlag\" is only used to update the flag " + "on the Windows shared library"; + ret = google::SetCommandLineOption(name, value); + + PADDLE_ENFORCE_EQ( + ret.empty(), false, + platform::errors::InvalidArgument( + "Fail to update flag: %s, please make sure the flag exists.", name)); + LOG(INFO) << ret; + return ret; } -#endif - } // namespace paddle diff --git a/paddle/fluid/inference/api/api_tester.cc b/paddle/fluid/inference/api/api_tester.cc index 2c450ef7cead4d5c3870d5e9186eb221e5dc19a0..988ffc47292b58fba6f9021d5326e218314f454a 100644 --- a/paddle/fluid/inference/api/api_tester.cc +++ b/paddle/fluid/inference/api/api_tester.cc @@ -14,6 +14,7 @@ limitations under the License. */ #include #include +#include #include "paddle/fluid/inference/api/paddle_inference_api.h" namespace paddle { @@ -67,4 +68,12 @@ TEST(paddle_inference_api, get_version) { ASSERT_FALSE(version.empty()); } +TEST(paddle_inference_api, UpdateDllFlag) { + UpdateDllFlag("paddle_num_threads", "10"); + try { + UpdateDllFlag("paddle_num_threads2", "10"); + } catch (std::exception &e) { + LOG(INFO) << e.what(); + } +} } // namespace paddle diff --git a/paddle/fluid/inference/api/paddle_api.h b/paddle/fluid/inference/api/paddle_api.h index 11d30d3347c85038527c28cd502fc362fc635fb2..d871661497a243bc22903f4d24fe4e1e6d2517db 100644 --- a/paddle/fluid/inference/api/paddle_api.h +++ b/paddle/fluid/inference/api/paddle_api.h @@ -429,8 +429,6 @@ PD_INFER_DECL int PaddleDtypeSize(PaddleDType dtype); PD_INFER_DECL std::string get_version(); -#if defined(_WIN32) && defined(PADDLE_ON_INFERENCE) PD_INFER_DECL std::string UpdateDllFlag(const char* name, const char* value); -#endif } // namespace paddle