CGRA-ME
HeuristicMappers.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * The software programs comprising "CGRA-ME" and the documentation provided
3  * with them are copyright by its authors and the University of Toronto. Only
4  * non-commercial, not-for-profit use of this software is permitted without ex-
5  * plicit permission. This software is provided "as is" with no warranties or
6  * guarantees of support. See the LICENCE for more details. You should have re-
7  * ceived a copy of the full licence along with this software. If not, see
8  * <http://cgra-me.ece.utoronto.ca/license/>.
9  ******************************************************************************/
10 
11 #ifndef ___HEURISTICMAPPERS_H__
12 #define ___HEURISTICMAPPERS_H__
13 
14 #include <CGRA/ConfigStore.h>
15 #include <CGRA/Mapper.h>
16 #include <CGRA/Mapping.h>
17 #include <CGRA/MRRG.h>
19 #include <CGRA/OpGraph.h>
20 
21 #include <functional>
22 #include <iosfwd>
23 
25 
26 using NeighbourFinder = std::function<FunctionalUnitNeighbours(const MRRG&, const std::vector<MRRG::NodeDescriptor>&)>;
27 
28 using SolutionSelector = std::function<Mapping(const Mapping&)>;
29 
30 using EdgeCoster = std::function<double(
31  const FunctionalUnitNeighbours& fu_neighbours,
32  const OpGraphOp& src_op, const MRRG::NodeDescriptor& src_node,
33  const OpGraphOp& sink_op, const MRRG::NodeDescriptor& sink_node
34 )>;
35 
36 using FUCoster = std::function<double(
37  const OpGraph& opgraph, const MRRG& mrrg,
38  const OpGraph::OpDescriptor& op, const MRRG::NodeDescriptor& node
39 )>;
40 
41 const SolutionSelector acceptTheFirstSolution = [](const Mapping& m){ Mapping copy = m; copy.setStatus(MappingStatus::success); return copy; };
43 
44 using NodeFilter = std::function<bool(
45  const MRRG::NodeDescriptor& node
46 )>;
47 
48 extern const NodeFilter allowAllNodes;
49 
50 using OpNodeFilter = std::function<bool(
51  const OpGraph::OpDescriptor& op,
52  const MRRG::NodeDescriptor& node
53 )>;
54 
56 
58  ILPHeuristicMapperOptions() = delete;
59 
67 
68  struct Solvers {
69  struct SolverID { const char* const id; };
70 
71  static SolverID Gurobi;
74  };
75 
81  add_all(options.general, {
82  });
83  return options;
84  }
85 
87  static const ConfigStore general_defaults {{
88  {"solver", Solvers::Gurobi.id},
89  // {"solver", Solvers::GoogleORTools_ClassicCP.id},
90  // {"solver", Solvers::GoogleORTools_SatCP.id},
91  {"seed", 0},
92  {"max_threads", 1},
93  {"allow_multiple_op_mappings", false}, // allow mapping of the same op to different FUs, ie. re-computation
94  {"allow_unbalanced_latency", false}, // latency matching of re-convergent and cyclic paths in the DFG
95  {"add_self_as_neighbour_if_path", true}, // make sure all FUs support self-loops
96  {"path_exclusivity_modelling", true}, // "Turns on the routing part" -- if false, will assume unlimited overlap is allowed by not modelling it
97  {"path_exclusivity_constraints_are_pairwise", true}, // more flexible, but way more constraints
98  {"max_num_paths_between_FUs", 20}, // maximum number of paths to consider between connected FU nodes -- main scaling parameter for routing/path modelling variables & constraints
99  {"map_unmapped_ops", true}, // if false, will only consider ops that are already present in the initial mapping parameter
100  {"solve_approach_name", "ILP-Heuristic-Mapper"}, // printed out in some messages, notably the profiling ones
101  {"status_print_interval", 100}, // print a message every this many solutions found
102  {"allowable_routing_usage_multiplier", 1}, // number of paths that can use the same routing node.
103  {"operand_nodes_are_normal", false}, // ignore operand sets on MRRG nodes; everything can route everywhere
104 
105  {"max_solutions", "2000000000"}, // \approx\inf
106  {"timelimit", 0}, // in seconds. 0 means no limit.
107 
108  {"print_configuration_and_statistics", false}, // a single initial print at the beginning
109  {"print_initial_mapping", false}, // the argument
110  {"print_intermediate_mappings", false}, // each mapping sent to the selector
111  {"print_intermediate_mappings_placement_only", false}, // same as above, but don't print value mappings
112  {"print_mapping", false}, // the final result
113  {"print_solve_progress", false}, // control prints from the ILP solver
114  {"print_compatible_nodes", false}, // print compatibility mapping from OpGraph node to a list of MRRG nodes
115  {"print_neighbours", false}, // print determined FU neighbours for each FU node
116  {"print_paths", false}, // print paths between FUs
117  {"silence_warnings", false}, // warnings almost certainly imply there is no solution
118  {"model_dump_filename", ""}, // non-empty will cause dump
119  {"model_IIS_dump_filename", ""}, // non-empty will cause computation & dump
120  {"intermediate_solution_dump_filename_base", ""}, // non-empty will cause dump of every solution found to a unique file
121 
122  {"just_warm_up_caches", false}, // warm-up caches, but don't solve
123  }};
124  return general_defaults;
125  }
126 
127  friend std::ostream& operator<<(std::ostream& os, const ILPHeuristicMapperOptions& opts);
128 };
129 
132 };
133 
135 
137  std::unordered_map<std::string, std::string> fix_port,
138  const OpGraph& opgraph, const MRRG& mrrg,
139  const Mapping& initial_mapping,
141  ILPHeuristicMapperCaches caches = {}
142 );
143 
148 Mapping mapOpsJustByConnectivity(std::unordered_map <std::string, std::string> fix_port, const OpGraph& opgraph, const MRRG& mrrg,
150  ILPHeuristicMapperCaches caches = {},
151  Mapping initial_mapping = Mapping{std::make_shared<CGRA>(), -1, std::make_shared<OpGraph>()}
152 );
153 
160  std::unordered_map<std::string, std::string> fix_port,
161  const Mapping& op_mapping,
162  const OpGraph& opgraph, const MRRG& mrrg,
164  ILPHeuristicMapperCaches caches = {}
165 );
166 
167 class ILPHeuristicMapper : public Mapper {
168  public:
169  ILPHeuristicMapper(std::shared_ptr<CGRA> cgra, int timelimit, const ConfigStore& args);
170  Mapping mapOpGraph(std::shared_ptr<OpGraph> opgraph, int II, const MRRG& mrrg, std::unordered_map<std::string, std::string>fix_port) override
171  { return real_mapOpGraph(opgraph, II, mrrg, fix_port); }
172  private:
173  Mapping real_mapOpGraph(std::shared_ptr<OpGraph> opgraph, int II, const MRRG& mrrg, std::unordered_map<std::string, std::string>fix_port) const;
179 };
180 
181 #endif /* ___HEURISTICMAPPERS_H__ */
ILPHeuristicMapper
Definition: HeuristicMappers.h:167
ILPHeuristicMapperOptions::is_node_allowed_for_op
OpNodeFilter is_node_allowed_for_op
Definition: HeuristicMappers.h:65
OpNodeFilter
std::function< bool(const OpGraph::OpDescriptor &op, const MRRG::NodeDescriptor &node)> OpNodeFilter
Definition: HeuristicMappers.h:53
ILPHeuristicMapper::outer_options
ConfigStore outer_options
Definition: HeuristicMappers.h:176
OpGraph.h
routeOpMappingByChoosingPaths
Mapping routeOpMappingByChoosingPaths(std::unordered_map< std::string, std::string > fix_port, const Mapping &op_mapping, const OpGraph &opgraph, const MRRG &mrrg, RouteOpMappingByChoosingPathsOptions options={ {}, acceptTheFirstSolution, {} }, ILPHeuristicMapperCaches caches={})
Definition: HeuristicMappers.cpp:1718
ILPHeuristicMapperOptions::add_defaults
static ILPHeuristicMapperOptions & add_defaults(ILPHeuristicMapperOptions &options)
Definition: HeuristicMappers.h:79
MRRG
Definition: MRRG.h:216
ILPHeuristicMapper::ILPHeuristicMapper
ILPHeuristicMapper(std::shared_ptr< CGRA > cgra, int timelimit, const ConfigStore &args)
Definition: HeuristicMappers.cpp:1775
ILPHeuristicMapperOptions::find_all_neighbour_FUs
NeighbourFinder find_all_neighbour_FUs
Definition: HeuristicMappers.h:60
ILPHeuristicMapperOptions::Solvers::GoogleORTools_ClassicCP
static SolverID GoogleORTools_ClassicCP
Definition: HeuristicMappers.h:72
ConfigStore.h
ILPHeuristicMapperOptions::Solvers::Gurobi
static SolverID Gurobi
Definition: HeuristicMappers.h:71
acceptTheFirstSolution
const SolutionSelector acceptTheFirstSolution
Definition: HeuristicMappers.h:41
ILPHeuristicMapperOptions::edge_coster
EdgeCoster edge_coster
Definition: HeuristicMappers.h:62
ConfigStore
Definition: ConfigStore.h:76
ILPHeuristicMapperOptions
Definition: HeuristicMappers.h:57
Mapper
Common interface for mappers.
Definition: Mapper.h:28
MRRGProcedureCache.h
ILPHeuristicMapper::final_combined_attempt_options
ConfigStore final_combined_attempt_options
Definition: HeuristicMappers.h:178
FUCoster
std::function< double(const OpGraph &opgraph, const MRRG &mrrg, const OpGraph::OpDescriptor &op, const MRRG::NodeDescriptor &node)> FUCoster
Definition: HeuristicMappers.h:39
ILPHeuristicMapperOptions::general
ConfigStore general
Definition: HeuristicMappers.h:63
ILPHeuristicMapper::inner_options
ConfigStore inner_options
Definition: HeuristicMappers.h:177
Mapping
Definition: Mapping.h:31
ILPHeuristicMapperCaches
Definition: HeuristicMappers.h:130
NeighbourFinder
std::function< FunctionalUnitNeighbours(const MRRG &, const std::vector< MRRG::NodeDescriptor > &)> NeighbourFinder
Definition: HeuristicMappers.h:26
add_all
ConfigStore & add_all(ConfigStore &into, const ConfigStore &from)
Add (or set) all keys from from in into.
Definition: ConfigStore.h:251
ILPHeuristicMapperOptions::default_general_opts
static const ConfigStore & default_general_opts()
Definition: HeuristicMappers.h:86
ILPHeuristicMapperOptions::is_node_allowed
NodeFilter is_node_allowed
Definition: HeuristicMappers.h:64
SolutionSelector
std::function< Mapping(const Mapping &)> SolutionSelector
Definition: HeuristicMappers.h:28
ILPHeuristicMapperOptions::Solvers::SolverID::id
const char *const id
Definition: HeuristicMappers.h:69
ILPHeuristicMapperOptions::Solvers
Definition: HeuristicMappers.h:68
ILPHeuristicMapperOptions::operator<<
friend std::ostream & operator<<(std::ostream &os, const ILPHeuristicMapperOptions &opts)
Definition: HeuristicMappers.cpp:252
FunctionalUnitNeighbours
Definition: MRRGProcedures.h:48
ILPHeuristicMapper::general_options
ConfigStore general_options
Definition: HeuristicMappers.h:174
allowAllNodesForOps
const OpNodeFilter allowAllNodesForOps
Definition: HeuristicMappers.cpp:32
ILPHeuristicMapperOptions::ILPHeuristicMapperOptions
ILPHeuristicMapperOptions()=delete
Mapper::cgra
std::shared_ptr< CGRA > cgra
Definition: Mapper.h:45
ILPHeuristicMapper::mapOpGraph
Mapping mapOpGraph(std::shared_ptr< OpGraph > opgraph, int II, const MRRG &mrrg, std::unordered_map< std::string, std::string >fix_port) override
Definition: HeuristicMappers.h:170
OpGraphOp
Definition: OpGraph.h:131
MRRGNode
Definition: MRRG.h:60
mapOpsJustByConnectivity
Mapping mapOpsJustByConnectivity(std::unordered_map< std::string, std::string > fix_port, const OpGraph &opgraph, const MRRG &mrrg, ILPHeuristicMapperOptions options, ILPHeuristicMapperCaches caches={}, Mapping initial_mapping=Mapping{std::make_shared< CGRA >(), -1, std::make_shared< OpGraph >()})
Definition: HeuristicMappers.cpp:1707
ILPHeuristicMapperOptions::Solvers::SolverID
Definition: HeuristicMappers.h:69
noEdgeCosting
const EdgeCoster noEdgeCosting
Definition: HeuristicMappers.h:42
mapViaConnectivityAndPathChoosing
Mapping mapViaConnectivityAndPathChoosing(std::unordered_map< std::string, std::string > fix_port, const OpGraph &opgraph, const MRRG &mrrg, const Mapping &initial_mapping, ILPHeuristicMapperOptions options, ILPHeuristicMapperCaches caches={})
Definition: HeuristicMappers.cpp:347
allowAllNodes
const NodeFilter allowAllNodes
Definition: HeuristicMappers.cpp:31
ILPHeuristicMapperCaches::mrrg_proc_cache
MRRGProcedureCacheHandle * mrrg_proc_cache
Definition: HeuristicMappers.h:131
NodeFilter
std::function< bool(const MRRG::NodeDescriptor &node)> NodeFilter
Definition: HeuristicMappers.h:46
Mapping.h
ILPHeuristicMapperOptions::Solvers::GoogleORTools_SatCP
static SolverID GoogleORTools_SatCP
Definition: HeuristicMappers.h:73
MappingStatus::success
@ success
ILPHeuristicMapperOptions::solution_selector
SolutionSelector solution_selector
Definition: HeuristicMappers.h:61
Mapper.h
MRRGProcedureCacheHandle
Definition: MRRGProcedureCache.h:20
ILPHeuristicMapper::test_placement_options
ConfigStore test_placement_options
Definition: HeuristicMappers.h:175
ILPHeuristicMapperOptions::fu_coster
FUCoster fu_coster
Definition: HeuristicMappers.h:66
ILPHeuristicMapper::real_mapOpGraph
Mapping real_mapOpGraph(std::shared_ptr< OpGraph > opgraph, int II, const MRRG &mrrg, std::unordered_map< std::string, std::string >fix_port) const
Definition: HeuristicMappers.cpp:1882
MRRG.h
OpGraph
Definition: OpGraph.h:215
Mapping::setStatus
void setStatus(MappingStatus new_status)
Definition: Mapping.h:40
EdgeCoster
std::function< double(const FunctionalUnitNeighbours &fu_neighbours, const OpGraphOp &src_op, const MRRG::NodeDescriptor &src_node, const OpGraphOp &sink_op, const MRRG::NodeDescriptor &sink_node)> EdgeCoster
Definition: HeuristicMappers.h:34
Mapper::timelimit
int timelimit
Definition: Mapper.h:46