17 const auto& all_mapper_name() {
static std::string v =
"AllMappers";
return v; }
18 const auto& all_mapper_prefix() {
static std::string v = all_mapper_name() +
".";
return v; }
23 , timelimit(timelimit)
33 registerMapper(all_mapper_name(),
nullptr,
false,
"Default arg storage", common_defaults, {});
39 throw std::logic_error(
"No mapper registered with ID `" + mapper_id +
"'");
40 }
else if (not lookup->second.maker) {
41 throw std::logic_error(
"Mapper `" + mapper_id +
"' has an invalid maker function");
46 const auto key_is_unset = [&](
const auto& kv) {
return not final_inis.
hasKey(key_prefix + kv.first); };
47 const auto first_unset_default = std::find_if(maker_desc.registered_defaults.begin(), maker_desc.registered_defaults.end(), key_is_unset);
48 if (first_unset_default != maker_desc.registered_defaults.end()) {
49 throw std::logic_error(
"Required key `" + first_unset_default->first +
"' missing when creating mapper `" + mapper_id +
"'");
52 for (
const auto& kv : final_inis) {
53 if (maker_desc.is_composite) {
54 if (kv.first.substr(0, key_prefix.size()) != key_prefix) {
continue; }
55 if (kv.first.substr(key_prefix.size()).find(
'.') != kv.first.npos) {
continue; }
57 const auto key_no_prefix = std::string(std::next(kv.first.begin(), key_prefix.size()), kv.first.end());
58 if (not maker_desc.hasMatchingArg(key_no_prefix)) {
59 throw std::logic_error(
"Given key `" + key_no_prefix +
"' does not match any of the allowed arguments for `" + mapper_id +
"'");
63 return maker_desc.maker(cgra, timelimit, final_inis);
67 std::string mapper_id,
MapperMaker maker,
bool is_composite, std::string mapper_description,
69 std::vector<std::pair<std::string, std::string>> optional_arg_regexes_and_descriptions
73 throw std::logic_error(
"There is already a mapper registered with ID `" + mapper_id +
"' that has description:\n" + lookup->second.description);
77 std::move(maker), is_composite, std::move(mapper_description), {} ,{}
80 for (
auto& name_default_desc : required_arg_names_defaults_and_descriptions) {
81 const auto& arg_name = std::get<0>(name_default_desc);
82 desc.registered_defaults.addString(arg_name, std::move(std::get<1>(name_default_desc).impl));
83 desc.allowed_arg_regexes_and_documentation.insert({arg_name, {std::regex(arg_name), std::move(std::get<2>(name_default_desc))}});
86 for (
auto& regex_and_desc : optional_arg_regexes_and_descriptions) {
87 auto& arg_regex = std::get<0>(regex_and_desc);
88 desc.allowed_arg_regexes_and_documentation.insert({arg_regex, {std::regex(arg_regex), std::move(std::get<1>(regex_and_desc))}});
97 set_all(result,
addPrefix(id_and_mapper.second.registered_defaults, id_and_mapper.first +
'.'));
107 [&](
const auto& k) {
return maker_desc.hasMatchingArg(k); }
113 if (maker_desc.is_composite) {
116 for (
const auto& kv : mapper_specific_keys) {
117 if (kv.first.find(
'.') != kv.first.npos) {
118 nested_keys.
setString(kv.first, kv.second);
123 return with_set(requested_all_mapper_defaults, args, nested_keys);
126 return with_set(requested_all_mapper_defaults, mapper_specific_keys);
132 if (id_and_mapper.first == all_mapper_name()) {
continue; }
133 os << id_and_mapper.first <<
"\n\t";
134 for (
const auto a_char : id_and_mapper.second.description) {
136 if (a_char ==
'\n') {
146 const auto maybe_print_arg = [&,
this](
const auto& maker,
const auto& kv,
bool always_print) {
147 const auto& arg_docs = maker.allowed_arg_regexes_and_documentation.at(kv.first).second;
148 if (not arg_docs.empty()) {
149 os <<
"# " << arg_docs.substr(0,arg_docs.find_first_of(
'\n')) <<
'\n';
150 }
else if (all_mapper_maker.registered_defaults.hasKey(kv.first) && all_mapper_maker.registered_defaults.getString(kv.first) == kv.second) {
152 if (not always_print) {
156 os << kv.first <<
" =";
157 if (not kv.second.empty()) {
158 os <<
" " << kv.second;
164 os <<
"# Gobal settings & defaults\n";
167 os <<
'[' << all_mapper_name() <<
"]\n";
169 for (
const auto& kv : all_mapper_maker.registered_defaults) {
170 maybe_print_arg(all_mapper_maker, kv,
true);
175 os <<
"# The rest are mapper-specific & overrides\n";
179 if (name_and_maker.first == all_mapper_name()) {
continue; }
180 const auto& maker = name_and_maker.second;
182 os <<
'[' << name_and_maker.first <<
"]\n";
183 for (
const auto& kv : maker.registered_defaults) {
184 maybe_print_arg(maker, kv,
false);
190 const char* indent =
" ";
194 os << maker.description <<
"\n\nThe following argument and argument regular expressions are allowed:\n";
195 for (
const auto& name_and_regex_and_desc : maker.allowed_arg_regexes_and_documentation) {
196 os <<
"\nArg `" << name_and_regex_and_desc.first <<
"': ";
197 bool last_was_newline =
false;
198 for (
const auto& c : name_and_regex_and_desc.second.second) {
199 if (last_was_newline) os << indent;
201 last_was_newline = c ==
'\n';
204 if (maker.registered_defaults.hasKey(name_and_regex_and_desc.first)) {
205 os << indent <<
"configured value: `" << configured_args.getStringOr(name_and_regex_and_desc.first,
"!UNSET!") <<
"'";
207 bool found_match =
false;
208 for (
const auto& kv : configured_args) {
209 if (regex_match(kv.first, name_and_regex_and_desc.second.first)) {
210 if (not std::exchange(found_match,
true)) {
211 os << indent <<
"matching options passed:";
213 os <<
" " << kv.first <<
"=" << kv.second;
216 if (not found_match) {
217 os << indent <<
"(no matching options passed)";
226 {
"arch_id",
"",
"Possible hint to heuristics"},
227 {
"seed", 0,
"Seed for all preudo-random operations in a mapper"},
228 {
"verbosity", 0,
"Controls logging. A value of 0 requests silence."},
229 {
"max_threads", 1,
"Maximum number of simultaneous threads that a mapper should try to use"},
230 {
"model_dump_filename",
"",
"Set to non-empty to enable dumping of ILP models"},
231 {
"model_IIS_dump_filename",
"",
"Set to non-empty to enable computation and dumping of ILP irreducable inconsistent subsystems"},
233 return default_registry;
237 std::string mapper_id,
MapperMaker maker,
bool is_composite, std::string mapper_description,
239 std::vector<std::pair<std::string, std::string>> optional_arg_regexes_and_descriptions
243 mapper_id, std::move(maker), is_composite, std::move(mapper_description),
244 required_arg_names_defaults_and_descriptions, optional_arg_regexes_and_descriptions
251 std::current_exception(),
"==>",
252 (
"Exception thrown while registering mapper `" + mapper_id +
"'. Will continue, while ignoring this mapper").c_str()