未验证 提交 715d8628 编写于 作者: 石晓伟 提交者: GitHub

export global google flags to users, test=develop (#30448)

上级 88fc7a7d
...@@ -19,7 +19,7 @@ SET(GFLAGS_SOURCE_DIR ${THIRD_PARTY_PATH}/gflags/src/extern_gflags) ...@@ -19,7 +19,7 @@ SET(GFLAGS_SOURCE_DIR ${THIRD_PARTY_PATH}/gflags/src/extern_gflags)
SET(GFLAGS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/gflags) SET(GFLAGS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/gflags)
SET(GFLAGS_INCLUDE_DIR "${GFLAGS_INSTALL_DIR}/include" CACHE PATH "gflags include directory." FORCE) SET(GFLAGS_INCLUDE_DIR "${GFLAGS_INSTALL_DIR}/include" CACHE PATH "gflags include directory." FORCE)
set(GFLAGS_REPOSITORY ${GIT_URL}/gflags/gflags.git) set(GFLAGS_REPOSITORY ${GIT_URL}/gflags/gflags.git)
set(GFLAGS_TAG 77592648e3f3be87d6c7123eb81cbad75f9aef5a) set(GFLAGS_TAG "v2.2.2")
IF(WIN32) IF(WIN32)
set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/gflags_static.lib" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE) set(GFLAGS_LIBRARIES "${GFLAGS_INSTALL_DIR}/lib/gflags_static.lib" CACHE FILEPATH "GFLAGS_LIBRARIES" FORCE)
ELSE(WIN32) ELSE(WIN32)
...@@ -30,6 +30,8 @@ ENDIF(WIN32) ...@@ -30,6 +30,8 @@ ENDIF(WIN32)
INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR})
set(GFLAGS_NAMESPACE "paddle_gflags")
cache_third_party(extern_gflags cache_third_party(extern_gflags
REPOSITORY ${GFLAGS_REPOSITORY} REPOSITORY ${GFLAGS_REPOSITORY}
TAG ${GFLAGS_TAG} TAG ${GFLAGS_TAG}
...@@ -44,7 +46,6 @@ ExternalProject_Add( ...@@ -44,7 +46,6 @@ ExternalProject_Add(
SOURCE_DIR ${GFLAGS_SOURCE_DIR} SOURCE_DIR ${GFLAGS_SOURCE_DIR}
BUILD_COMMAND ${BUILD_COMMAND} BUILD_COMMAND ${BUILD_COMMAND}
INSTALL_COMMAND ${INSTALL_COMMAND} INSTALL_COMMAND ${INSTALL_COMMAND}
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
...@@ -58,6 +59,7 @@ ExternalProject_Add( ...@@ -58,6 +59,7 @@ ExternalProject_Add(
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DBUILD_TESTING=OFF -DBUILD_TESTING=OFF
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
-DGFLAGS_NAMESPACE=${GFLAGS_NAMESPACE}
${EXTERNAL_OPTIONAL_ARGS} ${EXTERNAL_OPTIONAL_ARGS}
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${GFLAGS_INSTALL_DIR} CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${GFLAGS_INSTALL_DIR}
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
......
...@@ -19,7 +19,7 @@ SET(GLOG_SOURCE_DIR ${THIRD_PARTY_PATH}/glog/src/extern_glog) ...@@ -19,7 +19,7 @@ SET(GLOG_SOURCE_DIR ${THIRD_PARTY_PATH}/glog/src/extern_glog)
SET(GLOG_INSTALL_DIR ${THIRD_PARTY_PATH}/install/glog) SET(GLOG_INSTALL_DIR ${THIRD_PARTY_PATH}/install/glog)
SET(GLOG_INCLUDE_DIR "${GLOG_INSTALL_DIR}/include" CACHE PATH "glog include directory." FORCE) SET(GLOG_INCLUDE_DIR "${GLOG_INSTALL_DIR}/include" CACHE PATH "glog include directory." FORCE)
SET(GLOG_REPOSITORY ${GIT_URL}/google/glog.git) SET(GLOG_REPOSITORY ${GIT_URL}/google/glog.git)
SET(GLOG_TAG v0.3.5) SET(GLOG_TAG v0.4.0)
IF(WIN32) IF(WIN32)
SET(GLOG_LIBRARIES "${GLOG_INSTALL_DIR}/lib/glog.lib" CACHE FILEPATH "glog library." FORCE) SET(GLOG_LIBRARIES "${GLOG_INSTALL_DIR}/lib/glog.lib" CACHE FILEPATH "glog library." FORCE)
...@@ -45,7 +45,6 @@ ExternalProject_Add( ...@@ -45,7 +45,6 @@ ExternalProject_Add(
DEPENDS gflags DEPENDS gflags
PREFIX ${GLOG_PREFIX_DIR} PREFIX ${GLOG_PREFIX_DIR}
SOURCE_DIR ${GLOG_SOURCE_DIR} SOURCE_DIR ${GLOG_SOURCE_DIR}
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_FLAGS=${GLOG_CMAKE_CXX_FLAGS} -DCMAKE_CXX_FLAGS=${GLOG_CMAKE_CXX_FLAGS}
...@@ -57,8 +56,7 @@ ExternalProject_Add( ...@@ -57,8 +56,7 @@ ExternalProject_Add(
-DCMAKE_INSTALL_PREFIX=${GLOG_INSTALL_DIR} -DCMAKE_INSTALL_PREFIX=${GLOG_INSTALL_DIR}
-DCMAKE_INSTALL_LIBDIR=${GLOG_INSTALL_DIR}/lib -DCMAKE_INSTALL_LIBDIR=${GLOG_INSTALL_DIR}/lib
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DWITH_GFLAGS=ON -DWITH_GFLAGS=OFF
-Dgflags_DIR=${GFLAGS_INSTALL_DIR}/lib/cmake/gflags
-DBUILD_TESTING=OFF -DBUILD_TESTING=OFF
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
${EXTERNAL_OPTIONAL_ARGS} ${EXTERNAL_OPTIONAL_ARGS}
...@@ -71,4 +69,4 @@ ExternalProject_Add( ...@@ -71,4 +69,4 @@ ExternalProject_Add(
ADD_LIBRARY(glog STATIC IMPORTED GLOBAL) ADD_LIBRARY(glog STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARIES}) SET_PROPERTY(TARGET glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARIES})
ADD_DEPENDENCIES(glog extern_glog gflags) ADD_DEPENDENCIES(glog extern_glog gflags)
LINK_LIBRARIES(glog gflags) LINK_LIBRARIES(glog)
...@@ -68,7 +68,7 @@ void Communicator::init_gflag(const std::string &gflags) { ...@@ -68,7 +68,7 @@ void Communicator::init_gflag(const std::string &gflags) {
} }
int params_cnt = flags.size(); int params_cnt = flags.size();
char **params_ptr = &(flags_ptr[0]); char **params_ptr = &(flags_ptr[0]);
::google::ParseCommandLineFlags(&params_cnt, &params_ptr, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&params_cnt, &params_ptr, true);
} }
std::once_flag Communicator::init_flag_; std::once_flag Communicator::init_flag_;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "paddle/fluid/distributed/service/communicator.h" #include "paddle/fluid/distributed/service/communicator.h"
#include "paddle/fluid/string/string_helper.h" #include "paddle/fluid/string/string_helper.h"
using namespace std; using namespace std; // NOLINT
namespace paddle { namespace paddle {
namespace distributed { namespace distributed {
...@@ -59,11 +59,11 @@ void PSCore::init_gflag(const std::string& gflags) { ...@@ -59,11 +59,11 @@ void PSCore::init_gflag(const std::string& gflags) {
flags.insert(it, "exe default"); flags.insert(it, "exe default");
char* flags_ptr[flags.size()]; char* flags_ptr[flags.size()];
for (size_t i = 0; i < flags.size(); ++i) { for (size_t i = 0; i < flags.size(); ++i) {
flags_ptr[i] = (char*)(flags[i].c_str()); flags_ptr[i] = (char*)(flags[i].c_str()); // NOLINT
} }
int params_cnt = flags.size(); int params_cnt = flags.size();
char** params_ptr = &(flags_ptr[0]); char** params_ptr = &(flags_ptr[0]);
::google::ParseCommandLineFlags(&params_cnt, &params_ptr, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&params_cnt, &params_ptr, true);
} }
int PSCore::init_server( int PSCore::init_server(
......
...@@ -136,7 +136,7 @@ std::string UpdateDllFlag(const char *name, const char *value) { ...@@ -136,7 +136,7 @@ std::string UpdateDllFlag(const char *name, const char *value) {
LOG(WARNING) LOG(WARNING)
<< "The function \"UpdateDllFlag\" is only used to update the flag " << "The function \"UpdateDllFlag\" is only used to update the flag "
"on the Windows shared library"; "on the Windows shared library";
ret = google::SetCommandLineOption(name, value); ret = ::GFLAGS_NAMESPACE::SetCommandLineOption(name, value);
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
ret.empty(), false, ret.empty(), false,
......
...@@ -131,7 +131,7 @@ void MainThreads(int num_threads, bool use_gpu) { ...@@ -131,7 +131,7 @@ void MainThreads(int num_threads, bool use_gpu) {
} // namespace paddle } // namespace paddle
int main(int argc, char** argv) { int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
paddle::demo::Main(false /* use_gpu*/); paddle::demo::Main(false /* use_gpu*/);
paddle::demo::MainThreads(1, false /* use_gpu*/); paddle::demo::MainThreads(1, false /* use_gpu*/);
paddle::demo::MainThreads(4, false /* use_gpu*/); paddle::demo::MainThreads(4, false /* use_gpu*/);
......
...@@ -73,7 +73,7 @@ void Main() { ...@@ -73,7 +73,7 @@ void Main() {
} // namespace paddle } // namespace paddle
int main(int argc, char** argv) { int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
paddle::demo::Main(); paddle::demo::Main();
return 0; return 0;
} }
...@@ -82,7 +82,7 @@ void Main(bool use_gpu) { ...@@ -82,7 +82,7 @@ void Main(bool use_gpu) {
} // namespace paddle } // namespace paddle
int main(int argc, char** argv) { int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
if (FLAGS_use_gpu) { if (FLAGS_use_gpu) {
paddle::demo::Main(true /*use_gpu*/); paddle::demo::Main(true /*use_gpu*/);
} else { } else {
......
...@@ -84,7 +84,7 @@ void RunAnalysis() { ...@@ -84,7 +84,7 @@ void RunAnalysis() {
} // namespace paddle } // namespace paddle
int main(int argc, char** argv) { int main(int argc, char** argv) {
google::ParseCommandLineFlags(&argc, &argv, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
paddle::demo::RunAnalysis(); paddle::demo::RunAnalysis();
std::cout << "=========================Runs successfully====================" std::cout << "=========================Runs successfully===================="
<< std::endl; << std::endl;
......
...@@ -18,7 +18,7 @@ lib=$1 ...@@ -18,7 +18,7 @@ lib=$1
if [ $# -ne 1 ]; then echo "No input library"; exit -1 ; fi if [ $# -ne 1 ]; then echo "No input library"; exit -1 ; fi
num_paddle_syms=$(nm -D "${lib}" | grep -c paddle ) num_paddle_syms=$(nm -D "${lib}" | grep -c paddle )
num_google_syms=$(nm -D "${lib}" | grep google | grep -v paddle | grep -v brpc | grep -c "T " ) num_google_syms=$(nm -D "${lib}" | grep google | grep -v paddle | grep -v brpc | grep -v fL | grep -c "T " )
if [ $num_paddle_syms -le 0 ]; then echo "Have no paddle symbols"; exit -1 ; fi if [ $num_paddle_syms -le 0 ]; then echo "Have no paddle symbols"; exit -1 ; fi
if [ $num_google_syms -ge 1 ]; then echo "Have some google symbols"; exit -1 ; fi if [ $num_google_syms -ge 1 ]; then echo "Have some google symbols"; exit -1 ; fi
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
*paddle*; *paddle*;
*Pass*; *Pass*;
*profile*; *profile*;
*fL*;
local: local:
*; *;
}; };
......
...@@ -15,6 +15,7 @@ limitations under the License. */ ...@@ -15,6 +15,7 @@ limitations under the License. */
#include "paddle/fluid/memory/detail/buddy_allocator.h" #include "paddle/fluid/memory/detail/buddy_allocator.h"
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include "gflags/gflags.h"
#include "glog/logging.h" #include "glog/logging.h"
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
......
...@@ -567,7 +567,7 @@ BENCH_FP32_CPU(VBroadcast); ...@@ -567,7 +567,7 @@ BENCH_FP32_CPU(VBroadcast);
// --max_size: the max size would be tested // --max_size: the max size would be tested
// --filter: the bench name would be run // --filter: the bench name would be run
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]); google::InitGoogleLogging(argv[0]);
LOG(INFO) << "Burning " << FLAGS_burning << " times, Repeat " << FLAGS_repeat LOG(INFO) << "Burning " << FLAGS_burning << " times, Repeat " << FLAGS_repeat
<< " times."; << " times.";
......
...@@ -52,6 +52,7 @@ limitations under the License. */ ...@@ -52,6 +52,7 @@ limitations under the License. */
#endif #endif
#define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h #define GLOG_NO_ABBREVIATED_SEVERITIES // msvc conflict logging with windows.h
#include "gflags/gflags.h"
#include "glog/logging.h" #include "glog/logging.h"
#include "paddle/fluid/platform/errors.h" #include "paddle/fluid/platform/errors.h"
#include "paddle/fluid/platform/macros.h" #include "paddle/fluid/platform/macros.h"
......
...@@ -55,7 +55,7 @@ namespace paddle { ...@@ -55,7 +55,7 @@ namespace paddle {
namespace platform { namespace platform {
void ParseCommandLineFlags(int argc, char **argv, bool remove) { void ParseCommandLineFlags(int argc, char **argv, bool remove) {
google::ParseCommandLineFlags(&argc, &argv, remove); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, remove);
} }
} // namespace platform } // namespace platform
...@@ -93,7 +93,7 @@ bool InitGflags(std::vector<std::string> args) { ...@@ -93,7 +93,7 @@ bool InitGflags(std::vector<std::string> args) {
<< ", Init commandline: " << line; << ", Init commandline: " << line;
char **arr = argv.data(); char **arr = argv.data();
google::ParseCommandLineFlags(&argc, &arr, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &arr, true);
successed = true; successed = true;
VLOG(1) << "After Parse: argc is " << argc; VLOG(1) << "After Parse: argc is " << argc;
......
...@@ -80,7 +80,7 @@ bool IsPersistable(const paddle::framework::VarDesc* var) { ...@@ -80,7 +80,7 @@ bool IsPersistable(const paddle::framework::VarDesc* var) {
} // namespace paddle } // namespace paddle
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
std::cerr << "filelist: " << FLAGS_filelist << std::endl; std::cerr << "filelist: " << FLAGS_filelist << std::endl;
std::cerr << "data_proto_desc: " << FLAGS_data_proto_desc << std::endl; std::cerr << "data_proto_desc: " << FLAGS_data_proto_desc << std::endl;
......
...@@ -20,41 +20,10 @@ limitations under the License. */ ...@@ -20,41 +20,10 @@ limitations under the License. */
int main(int argc, char** argv) { int main(int argc, char** argv) {
paddle::memory::allocation::UseAllocatorStrategyGFlag(); paddle::memory::allocation::UseAllocatorStrategyGFlag();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
// Because the dynamic library libpaddle_fluid.so clips the symbol table, the std::vector<char*> new_argv;
// external program cannot recognize the flag inside the so, and the flag std::string gflags_env;
// defined by the external program cannot be accessed inside the so.
// Therefore, the ParseCommandLine function needs to be called separately
// inside and outside.
std::vector<char*> external_argv;
std::vector<char*> internal_argv;
// ParseNewCommandLineFlags in gflags.cc starts processing
// commandline strings from idx 1.
// The reason is, it assumes that the first one (idx 0) is
// the filename of executable file.
external_argv.push_back(argv[0]);
internal_argv.push_back(argv[0]);
std::vector<google::CommandLineFlagInfo> all_flags;
std::vector<std::string> external_flags_name;
google::GetAllFlags(&all_flags);
for (size_t i = 0; i < all_flags.size(); ++i) {
external_flags_name.push_back(all_flags[i].name);
}
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
bool flag = true; new_argv.push_back(argv[i]);
std::string tmp(argv[i]);
for (size_t j = 0; j < external_flags_name.size(); ++j) {
if (tmp.find(external_flags_name[j]) != std::string::npos) {
external_argv.push_back(argv[i]);
flag = false;
break;
}
}
if (flag) {
internal_argv.push_back(argv[i]);
}
} }
std::vector<std::string> envs; std::vector<std::string> envs;
...@@ -62,7 +31,8 @@ int main(int argc, char** argv) { ...@@ -62,7 +31,8 @@ int main(int argc, char** argv) {
#if defined(PADDLE_WITH_DISTRIBUTE) && !defined(PADDLE_WITH_GRPC) && \ #if defined(PADDLE_WITH_DISTRIBUTE) && !defined(PADDLE_WITH_GRPC) && \
!defined(PADDLE_WITH_PSLIB) !defined(PADDLE_WITH_PSLIB)
std::string str_max_body_size; std::string str_max_body_size;
if (google::GetCommandLineOption("max_body_size", &str_max_body_size)) { if (::GFLAGS_NAMESPACE::GetCommandLineOption("max_body_size",
&str_max_body_size)) {
setenv("FLAGS_max_body_size", "2147483647", 1); setenv("FLAGS_max_body_size", "2147483647", 1);
envs.push_back("max_body_size"); envs.push_back("max_body_size");
} }
...@@ -99,7 +69,7 @@ int main(int argc, char** argv) { ...@@ -99,7 +69,7 @@ int main(int argc, char** argv) {
} }
env_string = env_string.substr(0, env_string.length() - 1); env_string = env_string.substr(0, env_string.length() - 1);
env_str = strdup(env_string.c_str()); env_str = strdup(env_string.c_str());
internal_argv.push_back(env_str); new_argv.push_back(env_str);
VLOG(1) << "gtest env_string:" << env_string; VLOG(1) << "gtest env_string:" << env_string;
} }
...@@ -111,17 +81,14 @@ int main(int argc, char** argv) { ...@@ -111,17 +81,14 @@ int main(int argc, char** argv) {
} }
undefok_string = undefok_string.substr(0, undefok_string.length() - 1); undefok_string = undefok_string.substr(0, undefok_string.length() - 1);
undefok_str = strdup(undefok_string.c_str()); undefok_str = strdup(undefok_string.c_str());
internal_argv.push_back(undefok_str); new_argv.push_back(undefok_str);
VLOG(1) << "gtest undefok_string:" << undefok_string; VLOG(1) << "gtest undefok_string:" << undefok_string;
} }
int new_argc = static_cast<int>(external_argv.size()); int new_argc = static_cast<int>(new_argv.size());
char** external_argv_address = external_argv.data(); char** new_argv_address = new_argv.data();
google::ParseCommandLineFlags(&new_argc, &external_argv_address, false); ::GFLAGS_NAMESPACE::ParseCommandLineFlags(
&new_argc, &new_argv_address, false);
int internal_argc = internal_argv.size();
char** arr = internal_argv.data();
paddle::platform::ParseCommandLineFlags(internal_argc, arr, true);
paddle::framework::InitDevices(); paddle::framework::InitDevices();
int ret = RUN_ALL_TESTS(); int ret = RUN_ALL_TESTS();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册