From 6ce71648616bad5d9454fa3e9de78e04d9034344 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sun, 26 Sep 2021 19:32:43 +0800 Subject: [PATCH] Revert "auto read all public envs from flags_map in paddle_gtest_main (#36057)" This reverts commit 3fabc808857d543831579afa133da48eac94ce48. --- paddle/testing/paddle_gtest_main.cc | 53 ++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/paddle/testing/paddle_gtest_main.cc b/paddle/testing/paddle_gtest_main.cc index e94805be5a1..6feef11a366 100644 --- a/paddle/testing/paddle_gtest_main.cc +++ b/paddle/testing/paddle_gtest_main.cc @@ -15,7 +15,6 @@ limitations under the License. */ #include "gflags/gflags.h" #include "gtest/gtest.h" #include "paddle/fluid/memory/allocation/allocator_strategy.h" -#include "paddle/fluid/platform/flags.h" #include "paddle/fluid/platform/init.h" #include "paddle/fluid/platform/npu_info.h" @@ -23,11 +22,13 @@ int main(int argc, char** argv) { paddle::memory::allocation::UseAllocatorStrategyGFlag(); testing::InitGoogleTest(&argc, argv); std::vector new_argv; + std::string gflags_env; for (int i = 0; i < argc; ++i) { new_argv.push_back(argv[i]); } std::vector envs; + std::vector undefok; #if defined(PADDLE_WITH_DISTRIBUTE) && !defined(PADDLE_WITH_PSLIB) std::string str_max_body_size; if (::GFLAGS_NAMESPACE::GetCommandLineOption("max_body_size", @@ -37,13 +38,35 @@ int main(int argc, char** argv) { } #endif - const auto& flag_map = paddle::platform::GetExportedFlagInfoMap(); - for (const auto& pair : flag_map) { - const std::string& name = pair.second.name; - if (pair.second.is_writable) { // means public - envs.push_back(name); - } - } +#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) || \ + defined(PADDLE_WITH_ASCEND_CL) + envs.push_back("fraction_of_gpu_memory_to_use"); + envs.push_back("initial_gpu_memory_in_mb"); + envs.push_back("reallocate_gpu_memory_in_mb"); + envs.push_back("allocator_strategy"); + envs.push_back("selected_gpus"); +#elif __clang__ + envs.push_back("use_mkldnn"); + envs.push_back("initial_cpu_memory_in_mb"); + envs.push_back("allocator_strategy"); + + undefok.push_back("use_mkldnn"); + undefok.push_back("initial_cpu_memory_in_mb"); +#else + envs.push_back("use_pinned_memory"); + envs.push_back("use_mkldnn"); + envs.push_back("initial_cpu_memory_in_mb"); + envs.push_back("allocator_strategy"); + + undefok.push_back("use_pinned_memory"); + undefok.push_back("use_mkldnn"); + undefok.push_back("initial_cpu_memory_in_mb"); +#endif + +#if defined(PADDLE_WITH_ASCEND_CL) + envs.push_back("selected_npus"); + envs.push_back("npu_config_path"); +#endif char* env_str = nullptr; if (envs.size() > 0) { @@ -57,6 +80,18 @@ int main(int argc, char** argv) { VLOG(1) << "gtest env_string:" << env_string; } + char* undefok_str = nullptr; + if (undefok.size() > 0) { + std::string undefok_string = "--undefok="; + for (auto t : undefok) { + undefok_string += t + ","; + } + undefok_string = undefok_string.substr(0, undefok_string.length() - 1); + undefok_str = strdup(undefok_string.c_str()); + new_argv.push_back(undefok_str); + VLOG(1) << "gtest undefok_string:" << undefok_string; + } + int new_argc = static_cast(new_argv.size()); char** new_argv_address = new_argv.data(); ::GFLAGS_NAMESPACE::ParseCommandLineFlags( @@ -70,5 +105,7 @@ int main(int argc, char** argv) { #endif if (env_str) free(env_str); + if (undefok_str) free(undefok_str); + return ret; } -- GitLab