CGRA-ME
|
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 | |
MapperRegistry & | operator= (const MapperRegistry &)=default |
MapperRegistry & | operator= (MapperRegistry &&)=default |
std::unique_ptr< Mapper > | 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. 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, MakerAndDescription > | m_mapper_makers |
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.
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.
|
default |
|
default |
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.
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.
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.
|
inlineprivate |
|
default |
|
default |
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.
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.
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.
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
.
mapper_id | Unique name for this mapper. |
is_composite | For mappers that may call other mappers. See class documentation for more information. |
maker | function object that makes the mapper. |
mapper_description | a 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.
|
private |