30using KnobName = std::string;
37 virtual ~KnobLoader() =
default;
39 virtual bool load(
const KnobName &name,
bool default_value)
const = 0;
43template <
typename T> T knob_load(
const KnobLoader &,
const KnobName &,
const T &);
46bool knob_load(
const KnobLoader &l,
const KnobName &knob_name,
const bool &default_value)
48 return l.load(knob_name, default_value);
60class EnvKnobLoader final :
public KnobLoader
63 EnvKnobLoader(
const std::string &prefix) : _prefix{prefix}
69 bool load(
const KnobName &knob_name,
bool default_value)
const override
71 auto envvar = _prefix + knob_name;
72 auto s = std::getenv(envvar.c_str());
99const KnobLoader &knob_loader(
void)
101 static EnvKnobLoader loader{
"MOCO_"};
112#define KNOB_BOOL(NAME, DEFAULT, DESC) \
113 template <> typename KnobTrait<Knob::NAME>::ValueType get<Knob::NAME>(void) \
115 static typename KnobTrait<Knob::NAME>::ValueType value = \
116 ::knob_load<typename KnobTrait<Knob::NAME>::ValueType>(::knob_loader(), #NAME, DEFAULT); \
int safe_strcast< int >(const char *s, const int &v)
TensorSignatures load(const char *info_path)
Function to create TensorSignatures defined in info file.