Caffe2 - C++ API
A deep learning, cross platform ML framework
init.cc
1 
17 #include "caffe2/core/init.h"
18 #include "caffe2/core/operator.h" // for StaticLinkingProtector
19 
20 #include <iomanip>
21 
22 CAFFE2_DEFINE_bool(caffe2_version, false,
23  "Print Caffe2 version and build options on startup");
24 
25 namespace caffe2 {
26 
27 namespace internal {
28 Caffe2InitializeRegistry* Caffe2InitializeRegistry::Registry() {
29  static Caffe2InitializeRegistry gRegistry;
30  return &gRegistry;
31 }
32 }
33 
34 bool GlobalInit(int* pargc, char*** pargv) {
35  static bool global_init_was_already_run = false;
36  static StaticLinkingProtector g_protector;
37  if (global_init_was_already_run) {
38  VLOG(1) << "GlobalInit has already been called: did you double-call?";
39  return true;
40  }
41  global_init_was_already_run = true;
42  bool success = true;
43  success &= internal::Caffe2InitializeRegistry::Registry()
44  ->RunRegisteredEarlyInitFunctions(pargc, pargv);
45  CAFFE_ENFORCE(success,
46  "Failed to run some early init functions for caffe2.");
47  success &= ParseCaffeCommandLineFlags(pargc, pargv);
48  success &= InitCaffeLogging(pargc, *pargv);
49  // Print out the current build version. Using cerr as LOG(INFO) might be off
50  if (VLOG_IS_ON(1) || FLAGS_caffe2_version) {
51  std::cerr << "Caffe2 build configuration: " << std::endl;
52  for (const auto& it : GetBuildOptions()) {
53  std::cerr << " " << std::setw(25) << std::left << it.first << " : "
54  << it.second << std::endl;
55  }
56  }
57  // All other initialization functions.
58  success &= internal::Caffe2InitializeRegistry::Registry()
59  ->RunRegisteredInitFunctions(pargc, pargv);
60  if (!success) {
61  global_init_was_already_run = false;
62  }
63  CAFFE_ENFORCE(success,
64  "Failed to run some init functions for caffe2.");
65  // TODO: if we fail GlobalInit(), should we continue?
66  return success;
67 }
68 } // namespace caffe2
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:34
bool ParseCaffeCommandLineFlags(int *pargc, char ***pargv)
Parses the commandline flags.
Definition: flags.cc:71
Copyright (c) 2016-present, Facebook, Inc.