20 #ifndef CAFFE2_CORE_FLAGS_H_ 21 #define CAFFE2_CORE_FLAGS_H_ 23 #include "caffe2/core/registry.h" 57 #ifdef CAFFE2_USE_GFLAGS 59 #include <gflags/gflags.h> 63 #ifndef GFLAGS_GFLAGS_H_ 64 namespace gflags = google;
65 #endif // GFLAGS_GFLAGS_H_ 67 #define CAFFE2_GFLAGS_DEF_WRAPPER(type, name, default_value, help_str) \ 68 DEFINE_##type(name, default_value, help_str); \ 70 using ::FLAGS_##name; \ 73 #define CAFFE2_DEFINE_int(...) CAFFE2_GFLAGS_DEF_WRAPPER(int32, __VA_ARGS__) 74 #define CAFFE2_DEFINE_int64(...) CAFFE2_GFLAGS_DEF_WRAPPER(int64, __VA_ARGS__) 75 #define CAFFE2_DEFINE_double(...) CAFFE2_GFLAGS_DEF_WRAPPER(double, __VA_ARGS__) 76 #define CAFFE2_DEFINE_bool(...) CAFFE2_GFLAGS_DEF_WRAPPER(bool, __VA_ARGS__) 77 #define CAFFE2_DEFINE_string(name, default_value, help_str) \ 78 CAFFE2_GFLAGS_DEF_WRAPPER(string, name, default_value, help_str) 81 #define CAFFE2_GFLAGS_DECLARE_WRAPPER(type, name) \ 82 DECLARE_##type(name); \ 84 using ::FLAGS_##name; \ 87 #define CAFFE2_DECLARE_int(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(int32, name) 88 #define CAFFE2_DECLARE_int64(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(int64, name) 89 #define CAFFE2_DECLARE_double(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(double, name) 90 #define CAFFE2_DECLARE_bool(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(bool, name) 91 #define CAFFE2_DECLARE_string(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(string, name) 93 #else // CAFFE2_USE_GFLAGS 100 bool success() {
return success_; }
103 template <
typename T>
104 bool Parse(
const string& content, T* value);
108 CAFFE_DECLARE_REGISTRY(Caffe2FlagsRegistry,
Caffe2FlagParser,
const string&);
116 #define CAFFE2_DEFINE_typed_var(type, name, default_value, help_str) \ 118 type FLAGS_##name = default_value; \ 120 class Caffe2FlagParser_##name : public Caffe2FlagParser { \ 122 explicit Caffe2FlagParser_##name(const string& content) { \ 123 success_ = Caffe2FlagParser::Parse<type>(content, &FLAGS_##name); \ 127 RegistererCaffe2FlagsRegistry g_Caffe2FlagsRegistry_##name( \ 128 #name, Caffe2FlagsRegistry(), \ 129 RegistererCaffe2FlagsRegistry::DefaultCreator<Caffe2FlagParser_##name>, \ 130 "(" #type ", default " #default_value ") " help_str); \ 133 #define CAFFE2_DEFINE_int(name, default_value, help_str) \ 134 CAFFE2_DEFINE_typed_var(int, name, default_value, help_str) 135 #define CAFFE2_DEFINE_int64(name, default_value, help_str) \ 136 CAFFE2_DEFINE_typed_var(int64_t, name, default_value, help_str) 137 #define CAFFE2_DEFINE_double(name, default_value, help_str) \ 138 CAFFE2_DEFINE_typed_var(double, name, default_value, help_str) 139 #define CAFFE2_DEFINE_bool(name, default_value, help_str) \ 140 CAFFE2_DEFINE_typed_var(bool, name, default_value, help_str) 141 #define CAFFE2_DEFINE_string(name, default_value, help_str) \ 142 CAFFE2_DEFINE_typed_var(string, name, default_value, help_str) 145 #define CAFFE2_DECLARE_typed_var(type, name) \ 147 extern type FLAGS_##name; \ 148 } // namespace caffe2 150 #define CAFFE2_DECLARE_int(name) CAFFE2_DECLARE_typed_var(int, name) 151 #define CAFFE2_DECLARE_int64(name) CAFFE2_DECLARE_typed_var(int64_t, name) 152 #define CAFFE2_DECLARE_double(name) CAFFE2_DECLARE_typed_var(double, name) 153 #define CAFFE2_DECLARE_bool(name) CAFFE2_DECLARE_typed_var(bool, name) 154 #define CAFFE2_DECLARE_string(name) CAFFE2_DECLARE_typed_var(string, name) 156 #endif // CAFFE2_USE_GFLAGS 158 #endif // CAFFE2_CORE_FLAGS_H_ bool ParseCaffeCommandLineFlags(int *pargc, char ***pargv)
Parses the commandline flags.
const char * UsageMessage()
Returns the usage message for the commandline tool set by SetUsageMessage.
void SetUsageMessage(const string &str)
Sets the usage message when a commandline tool is called with "--help".
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
bool CommandLineFlagsHasBeenParsed()
Checks if the commandline flags has already been passed.