Caffe2 - C++ API
A deep learning, cross platform ML framework
init.cc
1 #include "caffe2/core/init.h"
2 #include "caffe2/core/operator.h" // for StaticLinkingProtector
3 
4 #include <iomanip>
5 
6 CAFFE2_DEFINE_bool(caffe2_version, false,
7  "Print Caffe2 version and build options on startup");
8 
9 namespace caffe2 {
10 
11 namespace internal {
12 Caffe2InitializeRegistry* Caffe2InitializeRegistry::Registry() {
13  static Caffe2InitializeRegistry gRegistry;
14  return &gRegistry;
15 }
16 }
17 
18 bool GlobalInit(int* pargc, char*** pargv) {
19  static bool global_init_was_already_run = false;
20  static StaticLinkingProtector g_protector;
21  if (global_init_was_already_run) {
22  VLOG(1) << "GlobalInit has already been called: did you double-call?";
23  return true;
24  }
25  global_init_was_already_run = true;
26  bool success = true;
27  success &= internal::Caffe2InitializeRegistry::Registry()
28  ->RunRegisteredEarlyInitFunctions(pargc, pargv);
29  CAFFE_ENFORCE(success,
30  "Failed to run some early init functions for caffe2.");
31  success &= ParseCaffeCommandLineFlags(pargc, pargv);
32  success &= InitCaffeLogging(pargc, *pargv);
33  // Print out the current build version. Using cerr as LOG(INFO) might be off
34  if (VLOG_IS_ON(1) || FLAGS_caffe2_version) {
35  std::cerr << "Caffe2 build configuration: " << std::endl;
36  for (const auto& it : GetBuildOptions()) {
37  std::cerr << " " << std::setw(25) << std::left << it.first << " : "
38  << it.second << std::endl;
39  }
40  }
41  // All other initialization functions.
42  success &= internal::Caffe2InitializeRegistry::Registry()
43  ->RunRegisteredInitFunctions(pargc, pargv);
44  if (!success) {
45  global_init_was_already_run = false;
46  }
47  CAFFE_ENFORCE(success,
48  "Failed to run some init functions for caffe2.");
49  // TODO: if we fail GlobalInit(), should we continue?
50  return success;
51 }
52 } // namespace caffe2
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:18
bool ParseCaffeCommandLineFlags(int *pargc, char ***pargv)
Parses the commandline flags.
Definition: flags.cc:55
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...