1 #include "caffe2/core/init.h" 2 #include "caffe2/core/operator.h" 3 #include "caffe2/core/scope_guard.h" 11 "Print Caffe2 version and build options on startup");
29 Caffe2InitializeRegistry* Caffe2InitializeRegistry::Registry() {
30 static Caffe2InitializeRegistry gRegistry;
34 State& GlobalInitState() {
35 static State state = State::Uninitialized;
41 return internal::GlobalInitState() == internal::State::Initialized;
45 static std::recursive_mutex init_mutex;
46 std::lock_guard<std::recursive_mutex> guard(init_mutex);
47 internal::State& init_state = internal::GlobalInitState();
53 if (init_state == internal::State::Initialized) {
54 VLOG(1) <<
"GlobalInit has already been called: re-parsing gflags only.";
57 UpdateLoggingLevelsFromFlags();
58 }
else if (init_state == internal::State::Uninitialized) {
59 init_state = internal::State::Initializing;
62 if (init_state == internal::State::Initializing) {
63 init_state = internal::State::Uninitialized;
67 success &= internal::Caffe2InitializeRegistry::Registry()
68 ->RunRegisteredEarlyInitFunctions(pargc, pargv);
70 success,
"Failed to run some early init functions for caffe2.");
72 success &= InitCaffeLogging(pargc, *pargv);
74 if (FLAGS_caffe2_version) {
75 std::cerr <<
"Caffe2 build configuration: " << std::endl;
76 for (
const auto& it : GetBuildOptions()) {
77 std::cerr <<
" " << std::setw(25) << std::left << it.first <<
" : " 78 << it.second << std::endl;
82 success &= internal::Caffe2InitializeRegistry::Registry()
83 ->RunRegisteredInitFunctions(pargc, pargv);
86 success ? internal::State::Initialized : internal::State::Uninitialized;
88 CAFFE_ENFORCE(success,
"Failed to run some init functions for caffe2.");
98 static char caffe2_name[] =
"caffe2";
99 char* mobile_name = &caffe2_name[0];
100 char** mobile_argv = &mobile_name;
101 return ::caffe2::GlobalInit(&mobile_argc, &mobile_argv);
bool GlobalInitAlreadyRun()
Determine whether GlobalInit has already been run.
detail::ScopeGuardImplDecay< F > MakeGuard(F &&f) noexcept(noexcept(detail::ScopeGuardImplDecay< F >(static_cast< F && >(f))))
ScopeGuard is a general implementation of the "Initialization is Resource Acquisition" idiom...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
C10_API bool ParseCommandLineFlags(int *pargc, char ***pargv)
Parses the commandline flags.