Caffe2 - C++ API
A deep learning, cross platform ML framework
init.cc
1 #include "caffe2/core/init.h"
2 
3 #ifndef CAFFE2_BUILD_STRING
4 #define CAFFE2_BUILD_STRING "build_version_not_set"
5 #endif
6 namespace caffe2 {
7 
8 namespace internal {
9 Caffe2InitializeRegistry* Caffe2InitializeRegistry::Registry() {
10  static Caffe2InitializeRegistry gRegistry;
11  return &gRegistry;
12 }
13 }
14 
15 bool GlobalInit(int* pargc, char*** pargv) {
16  static bool global_init_was_already_run = false;
17  if (global_init_was_already_run) {
18  VLOG(1) << "GlobalInit has already been called: did you double-call?";
19  return true;
20  }
21  global_init_was_already_run = true;
22  bool success = true;
23  success &= internal::Caffe2InitializeRegistry::Registry()
24  ->RunRegisteredEarlyInitFunctions(pargc, pargv);
25  CAFFE_ENFORCE(success,
26  "Failed to run some early init functions for caffe2.");
27  success &= ParseCaffeCommandLineFlags(pargc, pargv);
28  success &= InitCaffeLogging(pargc, *pargv);
29  // Print out the current build version.
30  VLOG(1) << "Caffe2 build version: " << CAFFE2_BUILD_STRING;
31  // All other initialization functions.
32  success &= internal::Caffe2InitializeRegistry::Registry()
33  ->RunRegisteredInitFunctions(pargc, pargv);
34  if (!success) {
35  global_init_was_already_run = false;
36  }
37  CAFFE_ENFORCE(success,
38  "Failed to run some init functions for caffe2.");
39  // TODO: if we fail GlobalInit(), should we continue?
40  return success;
41 }
42 } // namespace caffe2
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:15
bool ParseCaffeCommandLineFlags(int *pargc, char ***pargv)
Parses the commandline flags.
Definition: flags.cc:55
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...