Go to the documentation of this file.
29 [](std::shared_ptr<CGRA> cgra,
int timelimit,
const ConfigStore& args) {
30 return std::make_unique<ClusteredMapperDriver>(cgra, timelimit, args);},
32 "Clustered mapper.\n", {
34 {
"initial_hfactor", 0.2,
"History factor"},
35 {
"initial_pfactor", 0.01,
"Initial FU and routing overuse penalty"},
36 {
"hfactor_factor", 1.01,
"history factor increment"},
37 {
"pfactor_factor", 1.07,
"Multiplicative factor for overuse penalty, per iteration"},
38 {
"initial_temperature_method",
"",
"Temperature that the anneal starts at"},
39 {
"progress_dump_filename",
"",
"File to dump csv data status of each iteration. Empty disables."},
41 {
"cost_function", 1,
"Placement cost function could be 0 (BoundaryBox cost) or 1 (Scheduling cost)"},
42 {
"swap_factor", 10,
"Swaps per op node, per iteration"},
43 {
"cluster",
true,
"Flag to set if the benchmark gets clustered or no"},
44 {
"fanout_threshold", 5,
"Sets the threshold of acceptable fanout"},
45 {
"ram_ports", 0,
"Set the number of ram ports"},
52 (std::shared_ptr<CGRA> cgra,
int timelimit,
const ConfigStore& args)
55 , l_rand_seed(args.
getInt(
"seed"))
56 , l_initial_pfactor(args.
getReal(
"initial_pfactor"))
57 , l_initial_hfactor(args.
getReal(
"initial_hfactor"))
58 , l_p_factor_factor(args.
getReal(
"pfactor_factor"))
59 , l_h_factor_factor(args.
getReal(
"hfactor_factor"))
60 , l_swap_factor(args.
getInt(
"swap_factor"))
61 , l_verbosity(args.
getInt(
"verbosity"))
63 , l_cost_func(args.
getInt(
"cost_function"))
64 , l_empty_mapping_result(cgra, 0,
nullptr)
66 , l_cluster(args.
getBool(
"cluster"))
67 , l_fanout_threshold(args.
getInt(
"fanout_threshold"))
68 , l_ram_ports(args.
getInt(
"ram_ports"))
72 int II,
const MRRG& mrrg,
73 std::unordered_map<std::string, std::string> fix_port) {
75 std::cout <<
"Num of ops: " << opgraph->opNodes().size();
81 const Module& top_mod =
cgra->getTopLevelModule();
91 mapping_result =
mapElastic(opgraph, II, mrrg, fix_port, timing_seq);
93 mapping_result =
mapStatic(opgraph, II, mrrg, fix_port, timing_seq);
96 return mapping_result;
104 std::unordered_map<std::string, std::string> fix_port,
110 bool reschedule =
true;
115 timing_seq.
tick(
"Schedule", 0.0);
117 std::cout << op_schedule.first->getName() <<
" " << op_schedule.second << std::endl;
122 timing_seq.
tick(
"TMPACK", 0.0);
129 std::cout <<
"TMPack Result" << std::endl;
130 int clusters_greater_one = 0;
132 std::cout <<
"cluster " << i << std::endl;
133 if (
l_clusters[i].size() > 1) clusters_greater_one++;
135 std::cout << *op <<
" ";
149 std::cout <<
"ITERATION: " << i << std::endl;
165 timing_seq.
tick(
"Place and route", 0.01);
167 std::cout <<
"[INFO] clusters greater than 1: " << clusters_greater_one << std::endl;
168 return mapping_result;
175 std::unordered_map<std::string, std::string> fix_port,
183 std::cout <<
"Final Result" << std::endl;
185 std::cout <<
"cluster" << std::endl;
186 for (
auto& op : cluster) {
187 std::cout << *op << std::endl;
200 std::cout <<
"ITERATION: " << i << std::endl;
214 return mapping_result;
220 if (cycles_to_sink < 0) {
228 cycles_to_sink == 0) {
234 return cycles_to_sink;
239 for (
auto op : opgraph.
opNodes()) {
240 bool op_supported =
false;
241 for (
auto mrrg_node : classes.function_nodes) {
242 if (mrrg_node->canMapOp(op)) {
247 throw cgrame_error(op->getName() +
" Could not be mapped");
255 std::vector<std::string> colors = {
"antiquewhite4",
"aquamarine3",
"azure3",
"blue",
"red",
"blueviolet",
"brown4",
"burlywood4",
256 "cadetblue4",
"chartreuse4",
"chocolate4",
"coral4",
"cyan2",
"darkgoldenrod",
"crimson"};
258 std::map<OpGraphOpDesc, std::string> ops_to_modules;
260 Module& topModule = this->cgra->getTopLevelModule();
261 os <<
"digraph " << topModule.
getName() <<
" {\n";
262 bool set_color =
false;
264 if (module.first.find(
"pred") != std::string::npos)
continue;
265 os << module.first <<
"[ height=.5,width=.5,fontsize=8, ";
266 os <<
" pos = \"" << module.second->loc.x_coord <<
"," <<
"-" << module.second->loc.y_coord <<
"!\"";
267 os <<
" ,label = \"";
268 for (
auto& op : opgraph.
opNodes()) {
271 if (par->
loc.
x_coord == module.second->loc.x_coord
272 && par->
loc.
y_coord == module.second->loc.y_coord ) {
275 ops_to_modules.emplace(op, module.first);
279 os <<
"\"color=" << colors[color_index%colors.size()] <<
"]" <<
"\n";
282 os << module.first <<
"\"]" <<
"\n";
287 for (
auto& val : opgraph.
valNodes()) {
288 auto src = val->input;
293 for (
auto& snk : val->output) {
294 int cycles_to_sink = sched[snk] - sched[src];
295 if (cycles_to_sink < 0) {
298 if (src == snk) cycles_to_sink = 1;
304 if (src_x != snk_x || src_y != snk_y) {
305 os << ops_to_modules[src] <<
"->" << ops_to_modules[snk] <<
"[";
306 os <<
"label = \"" << cycles_to_sink;
307 os <<
"\"color=" << colors[color_index%colors.size()] <<
",fontsize=8]" <<
"\n";
std::map< std::string, Module * > submodules
std::unordered_map< const OpGraphOp *, int > getSchedule(SchedType type)
std::vector< std::vector< OpGraphOpDesc > > getClusters()
ClusteredMapperDriver(std::shared_ptr< CGRA > cgra, int timelimit, const ConfigStore &args)
void printPlacementNeato(int i, const OpGraph &opgraph, Mapping placed, std::unordered_map< OpGraphOpDesc, int > sched)
std::unordered_map< opPair, int, pair_hash > extended_sched_const
std::unordered_map< OpGraphOpDesc, int > l_schedule
Mapping routeOpGraph(Mapping placement)
MRRG::NodeDescriptor getSingleMapping(OpGraph::NodeDescriptor key) const
bool isAllOpsSupported(const OpGraph &opgraph, const MRRG &mrrg)
void setInitialPlacement()
double solve_time_in_seconds
std::unordered_map< OpGraphOpDesc, std::vector< std::string > > getOpsNodeNames()
auto getCGRA_shared() const
int getLowerBoundEdge(OpGraphOpCode op1, OpGraphOpCode op2)
Special helper for registering mappers to the default mapper registry.
const std::string l_arch_name
MappingStatus getStatus() const
Common interface for mappers.
double secondsSinceStart()
Mapping placeOpGraph(float temp)
std::map< OpGraphOpDesc, int > l_op_cluster_index
const std::string & to_string(const OpGraphOpCode &opcode)
void setSchedule(std::unordered_map< OpGraphOpDesc, int > s)
bool clusterPEs(bool cluster)
Mapping mapElastic(std::shared_ptr< OpGraph > opgraph, const int II, const MRRG &mrrg, std::unordered_map< std::string, std::string > fix_port, PrintOnDestructionChronoSequence timing_seq)
Mapping mapOpGraph(std::shared_ptr< OpGraph > opgraph, const int II, const MRRG &mrrg, std::unordered_map< std::string, std::string > fix_port) override
main function to map the OpGraph to the device description
std::unordered_map< OpGraphOpDesc, std::vector< std::string > > l_ops_to_node_names
const Latency getCyclesToSink(OpGraphOpDesc source, OpGraphOpDesc sink)
Mapping l_empty_mapping_result
Mapping mapStatic(std::shared_ptr< OpGraph > opgraph, const int II, const MRRG &mrrg, std::unordered_map< std::string, std::string > fix_port, PrintOnDestructionChronoSequence &timing_seq)
TickResult tick(std::string timepoint_name, double threshold=0.0, std::ostream *os=nullptr)
Implementation of the Anneal Placer.
AutoRegisterMapper ClusteredMapper_arm("ClusteredMapper", [](std::shared_ptr< CGRA > cgra, int timelimit, const ConfigStore &args) { return std::make_unique< ClusteredMapperDriver >(cgra, timelimit, args);}, false, "Clustered mapper.\n", { {"arch_id", "", ""}, {"initial_hfactor", 0.2, "History factor"}, {"initial_pfactor", 0.01, "Initial FU and routing overuse penalty"}, {"hfactor_factor", 1.01, "history factor increment"}, {"pfactor_factor", 1.07, "Multiplicative factor for overuse penalty, per iteration"}, {"initial_temperature_method", "", "Temperature that the anneal starts at"}, {"progress_dump_filename", "", "File to dump csv data status of each iteration. Empty disables."}, {"seed", 10, ""}, {"cost_function", 1, "Placement cost function could be 0 (BoundaryBox cost) or 1 (Scheduling cost)"}, {"swap_factor", 10, "Swaps per op node, per iteration"}, {"cluster", true, "Flag to set if the benchmark gets clustered or no"}, {"fanout_threshold", 5, "Sets the threshold of acceptable fanout"}, {"ram_ports", 0, "Set the number of ram ports"}, {"verbosity", 0, ""}, }, {})
std::shared_ptr< CGRA > cgra
const std::string & getString(const std::string &key) const
std::unordered_map< opPair, int, pair_hash > extended_sched_const
float determineTemperature(float scale)
int initiationInterval() const
static constexpr Latency kUndefLatency
long long getInt(const std::string &key) const
std::vector< std::vector< OpGraphOpDesc > > l_clusters
double getReal(const std::string &key) const
std::map< OpGraphOpDesc, int > getOpClusterIndex()
void setStatus(MappingStatus new_status)
MRRGNodeClassLists computeNodeClassLists(const MRRG &mrrg)
bool getBool(const std::string &key) const