CGRA-ME
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
MapperRegistry Class Reference

Holds instances of mapper makers and creates mappers by ID, while resolving arguments. More...

#include <Mapper.h>

Classes

struct  MakerAndDescription
 

Public Member Functions

 MapperRegistry (std::vector< ImplicitTuple< std::string, ImplicitlyToString, std::string >> common_defaults)
 Initialize with some common defaults. More...
 
 MapperRegistry (const MapperRegistry &)=default
 
 MapperRegistry (MapperRegistry &&)=default
 
MapperRegistryoperator= (const MapperRegistry &)=default
 
MapperRegistryoperator= (MapperRegistry &&)=default
 
std::unique_ptr< MappercreateMapper (const std::string &mapper_id, std::shared_ptr< CGRA > cgra, int timelimit, const ConfigStore &args) const
 Given a mapper_id, create an instance of that mapper with the given arguments. More...
 
void registerMapper (std::string mapper_id, MapperMaker maker, bool is_composite, std::string mapper_description, std::vector< ImplicitTuple< std::string, ImplicitlyToString, std::string >> required_arg_names_defaults_and_descriptions, std::vector< std::pair< std::string, std::string >> optional_arg_regexes_and_descriptions)
 Register a new mapper under the name mapper_id. More...
 
ConfigStore getAllRegisteredArgDefaults () const
 Retrieve all registered default values for required arguments as a ConfigStore. More...
 
ConfigStore getMapperArgs (const std::string &mapper_id, const ConfigStore &args) const
 Compute the arguments that would be passed when creating mapper mapper_id. More...
 
void printMapperList (std::ostream &os) const
 Print a message with every mapper's id and description. More...
 
void printDefaultsAsINI (std::ostream &os) const
 Print an INI file with all registered defaults and some comments based on short descriptions. More...
 
void printHelpForMapper (const std::string &mapper_id, const ConfigStore &args, std::ostream &os) const
 Print a detailed message about a mapper and the suggested args, including all required and optional arguments' long descriptions. More...
 

Private Member Functions

const std::string makeKeyPrefix (const std::string &mapper_id) const
 

Private Attributes

std::map< std::string, MakerAndDescriptionm_mapper_makers
 

Detailed Description

Holds instances of mapper makers and creates mappers by ID, while resolving arguments.

Can also generate an INI file and print help about the mappers it holds.

Two types of mappers can be registered – composite and non-composite. Composite mappers are in general mappers that call other mappers. They will always receive argument keys that are prefixed by the mapper that they are intended so it may pass the same arguments to the mappers it invokes, Non-composite mappers will receive argument keys with all prefixes removed – and only keys meant for that mapper.

For example if a non-composite mapper named nc is created with arguments nc.key1=1 and comp.key2=2, it will only receive a ConfigStore with key-value pair key1=1. If a composite named comp is created with the same arguments, it will receive both unmodified. Composite mappers can also have "nested keys", eg. comp.nc.key1=3, which will be extracted to the surrounding scope. So, if that key is added to the previous example, comp will be called with nc.key1=3, ‘comp.key2=2’.

There is also the common defaults ("AllMapper") mechanism for defining common arguments. All keys that begin with the prefix AllMapper. will be passed to a mapper if the part after the prefix matches a required or optional argument.

Definition at line 66 of file Mapper.h.

Constructor & Destructor Documentation

◆ MapperRegistry() [1/3]

MapperRegistry::MapperRegistry ( std::vector< ImplicitTuple< std::string, ImplicitlyToString, std::string >>  common_defaults)

Initialize with some common defaults.

Definition at line 30 of file Mapper.cpp.

◆ MapperRegistry() [2/3]

MapperRegistry::MapperRegistry ( const MapperRegistry )
default

◆ MapperRegistry() [3/3]

MapperRegistry::MapperRegistry ( MapperRegistry &&  )
default

Member Function Documentation

◆ createMapper()

std::unique_ptr< Mapper > MapperRegistry::createMapper ( const std::string &  mapper_id,
std::shared_ptr< CGRA cgra,
int  timelimit,
const ConfigStore args 
) const

Given a mapper_id, create an instance of that mapper with the given arguments.

Checks all passed arguments against the required and optional regex arguments for mapper_id. The actual values of the registered defaults are not taken into account – all values must be passed via args.

Definition at line 36 of file Mapper.cpp.

◆ getAllRegisteredArgDefaults()

ConfigStore MapperRegistry::getAllRegisteredArgDefaults ( ) const

Retrieve all registered default values for required arguments as a ConfigStore.

Useful for writing tests, and for introspection

Definition at line 94 of file Mapper.cpp.

◆ getMapperArgs()

ConfigStore MapperRegistry::getMapperArgs ( const std::string &  mapper_id,
const ConfigStore args 
) const

Compute the arguments that would be passed when creating mapper mapper_id.

No checking for required and optional arguments is performed.

Definition at line 102 of file Mapper.cpp.

◆ makeKeyPrefix()

const std::string MapperRegistry::makeKeyPrefix ( const std::string &  mapper_id) const
inlineprivate

Definition at line 137 of file Mapper.h.

◆ operator=() [1/2]

MapperRegistry& MapperRegistry::operator= ( const MapperRegistry )
default

◆ operator=() [2/2]

MapperRegistry& MapperRegistry::operator= ( MapperRegistry &&  )
default

◆ printDefaultsAsINI()

void MapperRegistry::printDefaultsAsINI ( std::ostream &  os) const

Print an INI file with all registered defaults and some comments based on short descriptions.

Definition at line 144 of file Mapper.cpp.

◆ printHelpForMapper()

void MapperRegistry::printHelpForMapper ( const std::string &  mapper_id,
const ConfigStore args,
std::ostream &  os 
) const

Print a detailed message about a mapper and the suggested args, including all required and optional arguments' long descriptions.

Does not take into account the registered default values. Based on the passed in args, configured values an printed for required args, as well as args that match optional arg regexes.

Definition at line 189 of file Mapper.cpp.

◆ printMapperList()

void MapperRegistry::printMapperList ( std::ostream &  os) const

Print a message with every mapper's id and description.

Definition at line 130 of file Mapper.cpp.

◆ registerMapper()

void MapperRegistry::registerMapper ( std::string  mapper_id,
MapperMaker  maker,
bool  is_composite,
std::string  mapper_description,
std::vector< ImplicitTuple< std::string, ImplicitlyToString, std::string >>  required_arg_names_defaults_and_descriptions,
std::vector< std::pair< std::string, std::string >>  optional_arg_regexes_and_descriptions 
)

Register a new mapper under the name mapper_id.

Parameters
mapper_idUnique name for this mapper.
is_compositeFor mappers that may call other mappers. See class documentation for more information.
makerfunction object that makes the mapper.
mapper_descriptiona short description, optionally followed by a newline and a longer description.
required_arg_names_defaults_and_descriptions(arg name, default value, short description\nlong description) List of arguments that must be passed when creating this mapper. Only use [a-z_] for consistency and to avoid regex active characters. Default values are only used for generating a the default config. Short & Long descriptions are used for config comments help strings.
optional_arg_regexes_and_descriptions(arg regex, short description\nlong description) Similar to the above, but no default values.

Definition at line 66 of file Mapper.cpp.

Member Data Documentation

◆ m_mapper_makers

std::map<std::string, MakerAndDescription> MapperRegistry::m_mapper_makers
private

Definition at line 161 of file Mapper.h.


The documentation for this class was generated from the following files: