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

Copyright (c) 2016-present, Facebook, Inc. More...

#include "caffe2/core/registry.h"

Go to the source code of this file.

Data Structures

class  caffe2::Caffe2FlagParser
 

Namespaces

 caffe2
 Copyright (c) 2016-present, Facebook, Inc.
 

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

Copyright (c) 2016-present, Facebook, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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

#define CAFFE2_DECLARE_typed_var (   type,
  name 
)
Value:
namespace caffe2 { \
CAFFE2_IMPORT extern type FLAGS_##name; \
}
Copyright (c) 2016-present, Facebook, Inc.

Definition at line 166 of file flags.h.

#define CAFFE2_DEFINE_typed_var (   type,
  name,
  default_value,
  help_str 
)
Value:
namespace caffe2 { \
CAFFE2_EXPORT 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); \
}
Copyright (c) 2016-present, Facebook, Inc.

Definition at line 136 of file flags.h.