1 #ifndef CAFFE2_CORE_INIT_H_ 2 #define CAFFE2_CORE_INIT_H_ 4 #include "caffe2/core/common.h" 6 #include "caffe2/core/logging.h" 13 typedef bool (*InitFunction)(
int*,
char***);
18 void Register(InitFunction
function,
bool run_early,
19 const char* description) {
21 early_init_functions_.emplace_back(
function, description);
23 init_functions_.emplace_back(
function, description);
27 bool RunRegisteredEarlyInitFunctions(
int* pargc,
char*** pargv) {
28 return RunRegisteredInitFunctionsInternal(
29 early_init_functions_, pargc, pargv);
32 bool RunRegisteredInitFunctions(
int* pargc,
char*** pargv) {
33 return RunRegisteredInitFunctionsInternal(init_functions_, pargc, pargv);
40 bool RunRegisteredInitFunctionsInternal(
41 vector<std::pair<InitFunction, const char*>>& functions,
42 int* pargc,
char*** pargv) {
43 for (
const auto& init_pair : functions) {
44 VLOG(1) <<
"Running init function: " << init_pair.second;
45 if (!(*init_pair.first)(pargc, pargv)) {
46 LOG(ERROR) <<
"Initialization function failed.";
54 vector<std::pair<InitFunction, const char*> > early_init_functions_;
55 vector<std::pair<InitFunction, const char*> > init_functions_;
61 InitRegisterer(internal::Caffe2InitializeRegistry::InitFunction
function,
62 bool run_early,
const char* description) {
63 internal::Caffe2InitializeRegistry::Registry()
64 ->Register(
function, run_early, description);
68 #define REGISTER_CAFFE2_INIT_FUNCTION(name, function, description) \ 70 ::caffe2::InitRegisterer g_caffe2_initregisterer_##name( \ 71 function, false, description); \ 74 #define REGISTER_CAFFE2_EARLY_INIT_FUNCTION(name, function, description) \ 76 ::caffe2::InitRegisterer g_caffe2_initregisterer_##name( \ 77 function, true, description); \ 100 #endif // CAFFE2_CORE_INIT_H_ bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
A template class that allows one to register classes by keys.
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
Commandline flags support for Caffe2.