mxnet
Classes | Namespaces | Macros
registry.h File Reference

Registry utility that helps to build registry singletons. More...

#include <map>
#include <string>
#include <vector>
#include "./base.h"
#include "./logging.h"
#include "./parameter.h"
#include "./type_traits.h"
Include dependency graph for registry.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dmlc::Registry< EntryType >
 Registry class. Registry can be used to register global singletons. The most commonly use case are factory functions. More...
 
class  dmlc::FunctionRegEntryBase< EntryType, FunctionType >
 Common base class for function registry. More...
 

Namespaces

 dmlc
 namespace for dmlc
 

Macros

#define DMLC_REGISTRY_ENABLE(EntryType)
 Macro to enable the registry of EntryType. This macro must be used under namespace dmlc, and only used once in cc file. More...
 
#define DMLC_REGISTRY_REGISTER(EntryType, EntryTypeName, Name)
 Generic macro to register an EntryType There is a complete example in FactoryRegistryEntryBase. More...
 
#define DMLC_REGISTRY_FILE_TAG(UniqueTag)   int __dmlc_registry_file_tag_ ## UniqueTag ## __() { return 0; }
 (Optional) Declare a file tag to current file that contains object registrations. More...
 
#define DMLC_REGISTRY_LINK_TAG(UniqueTag)
 (Optional) Force link to all the objects registered in file tag. More...
 

Detailed Description

Registry utility that helps to build registry singletons.

Copyright (c) 2015 by Contributors

Macro Definition Documentation

#define DMLC_REGISTRY_ENABLE (   EntryType)
Value:
template<> \
Registry<EntryType > *Registry<EntryType >::Get() { \
static Registry<EntryType > inst; \
return &inst; \
} \

Macro to enable the registry of EntryType. This macro must be used under namespace dmlc, and only used once in cc file.

Parameters
EntryTypeType of registry entry
#define DMLC_REGISTRY_FILE_TAG (   UniqueTag)    int __dmlc_registry_file_tag_ ## UniqueTag ## __() { return 0; }

(Optional) Declare a file tag to current file that contains object registrations.

This will declare a dummy function that will be called by register file to incur a link dependency.

Parameters
UniqueTagThe unique tag used to represent.
See also
DMLC_REGISTRY_LINK_TAG
#define DMLC_REGISTRY_LINK_TAG (   UniqueTag)
Value:
int __dmlc_registry_file_tag_ ## UniqueTag ## __(); \
static int DMLC_ATTRIBUTE_UNUSED __reg_file_tag_ ## UniqueTag ## __ = \
__dmlc_registry_file_tag_ ## UniqueTag ## __();
#define DMLC_ATTRIBUTE_UNUSED
helper macro to supress unused warning
Definition: base.h:148

(Optional) Force link to all the objects registered in file tag.

This macro must be used in the same file as DMLC_REGISTRY_ENABLE and in the same namespace as DMLC_REGISTRY_FILE_TAG

DMLC_REGISTRY_FILE_TAG and DMLC_REGISTRY_LINK_TAG are optional macros for registration. They are used to encforce link of certain file into during static linking.

This is mainly used to solve problem during statically link a library which contains backward registration. Specifically, this avoids the objects in these file tags to be ignored by compiler.

For dynamic linking, this problem won't occur as everything is loaded by default.

Use of this is optional as it will create an error when a file tag do not exist. An alternative solution is always ask user to enable –whole-archieve during static link.

// in file objective_registry.cc DMLC_REGISTRY_ENABLE(MyObjective); DMLC_REGISTRY_LINK_TAG(regression_op); DMLC_REGISTRY_LINK_TAG(rank_op);

// in file regression_op.cc // declare tag of this file. DMLC_REGISTRY_FILE_TAG(regression_op); DMLC_REGISTRY_REGISTER(MyObjective, logistic_reg, logistic_reg); // ...

// in file rank_op.cc // declare tag of this file. DMLC_REGISTRY_FILE_TAG(rank_op); DMLC_REGISTRY_REGISTER(MyObjective, pairwiserank, pairwiserank);

Parameters
UniqueTagThe unique tag used to represent.
See also
DMLC_REGISTRY_ENABLE, DMLC_REGISTRY_FILE_TAG
#define DMLC_REGISTRY_REGISTER (   EntryType,
  EntryTypeName,
  Name 
)
Value:
static DMLC_ATTRIBUTE_UNUSED EntryType & __make_ ## EntryTypeName ## _ ## Name ## __ = \
#define DMLC_ATTRIBUTE_UNUSED
helper macro to supress unused warning
Definition: base.h:148
static Registry * Get()
get a singleton of the Registry. This function can be defined by DMLC_REGISTRY_ENABLE.
EntryType & __REGISTER__(const std::string &name)
Internal function to register a name function under name.
Definition: registry.h:78

Generic macro to register an EntryType There is a complete example in FactoryRegistryEntryBase.

Parameters
EntryTypeThe type of registry entry.
EntryTypeNameThe typename of EntryType, must do not contain namespace :: .
NameThe name to be registered.
See also
FactoryRegistryEntryBase