Caffe2 - C++ API
A deep learning, cross platform ML framework
Data Structures | Namespaces | Macros | Functions
flags.h File Reference

Commandline flags support for Caffe2. More...

#include "caffe2/core/registry.h"

Go to the source code of this file.

Data Structures

class  caffe2::Caffe2FlagParser
 

Namespaces

 caffe2
 Simple registry implementation in Caffe2 that uses static variables to register object creators during program initialization time.
 

Macros

#define CAFFE2_DEFINE_typed_var(type, name, default_value, help_str)
 
#define CAFFE2_DEFINE_int(name, default_value, help_str)   CAFFE2_DEFINE_typed_var(int, name, default_value, help_str)
 
#define CAFFE2_DEFINE_int64(name, default_value, help_str)   CAFFE2_DEFINE_typed_var(int64_t, name, default_value, help_str)
 
#define CAFFE2_DEFINE_double(name, default_value, help_str)   CAFFE2_DEFINE_typed_var(double, name, default_value, help_str)
 
#define CAFFE2_DEFINE_bool(name, default_value, help_str)   CAFFE2_DEFINE_typed_var(bool, name, default_value, help_str)
 
#define CAFFE2_DEFINE_string(name, default_value, help_str)   CAFFE2_DEFINE_typed_var(string, name, default_value, help_str)
 
#define CAFFE2_DECLARE_typed_var(type, name)
 
#define CAFFE2_DECLARE_int(name)   CAFFE2_DECLARE_typed_var(int, name)
 
#define CAFFE2_DECLARE_int64(name)   CAFFE2_DECLARE_typed_var(int64_t, name)
 
#define CAFFE2_DECLARE_double(name)   CAFFE2_DECLARE_typed_var(double, name)
 
#define CAFFE2_DECLARE_bool(name)   CAFFE2_DECLARE_typed_var(bool, name)
 
#define CAFFE2_DECLARE_string(name)   CAFFE2_DECLARE_typed_var(string, name)
 

Functions

void caffe2::SetUsageMessage (const string &str)
 Sets the usage message when a commandline tool is called with "--help".
 
const char * caffe2::UsageMessage ()
 Returns the usage message for the commandline tool set by SetUsageMessage.
 
bool caffe2::ParseCaffeCommandLineFlags (int *pargc, char ***pargv)
 Parses the commandline flags. More...
 
bool caffe2::CommandLineFlagsHasBeenParsed ()
 Checks if the commandline flags has already been passed.
 
 caffe2::CAFFE_DECLARE_REGISTRY (Caffe2FlagsRegistry, Caffe2FlagParser, const string &)
 

Detailed Description

Commandline flags support for Caffe2.

This is a portable commandline flags tool for caffe2, so we can optionally choose to use gflags or a lightweighted custom implementation if gflags is not possible on a certain platform. If you have gflags installed, set the macro CAFFE2_USE_GFLAGS will seamlessly route everything to gflags.

To define a flag foo of type bool default to true, do the following in the global namespace: CAFFE2_DEFINE_bool(foo, true, "An example.");

To use it in another .cc file, you can use CAFFE2_DECLARE_* as follows: CAFFE2_DECLARE_bool(foo);

In both cases, you can then access the flag via caffe2::FLAGS_foo.

Definition in file flags.h.

Macro Definition Documentation

◆ CAFFE2_DECLARE_typed_var

#define CAFFE2_DECLARE_typed_var (   type,
  name 
)
Value:
namespace caffe2 { \
extern type FLAGS_##name; \
}
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...

Definition at line 145 of file flags.h.

◆ CAFFE2_DEFINE_typed_var

#define CAFFE2_DEFINE_typed_var (   type,
  name,
  default_value,
  help_str 
)
Value:
namespace caffe2 { \
type FLAGS_##name = default_value; \
namespace { \
class Caffe2FlagParser_##name : public Caffe2FlagParser { \
public: \
explicit Caffe2FlagParser_##name(const string& content) { \
success_ = Caffe2FlagParser::Parse<type>(content, &FLAGS_##name); \
} \
}; \
} \
RegistererCaffe2FlagsRegistry g_Caffe2FlagsRegistry_##name( \
#name, Caffe2FlagsRegistry(), \
RegistererCaffe2FlagsRegistry::DefaultCreator<Caffe2FlagParser_##name>, \
"(" #type ", default " #default_value ") " help_str); \
}
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...

Definition at line 116 of file flags.h.