CGRA-ME
MappingProcedures.cpp
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 #include <CGRA/MappingProcedures.h>
13 
14 CreateMappingGraphResult createMappingGraphFromConfig(Mapping & m, const ConfigGraph & config, const OpGraph & opgraph, const MRRG & mrrg) {
15  auto cg_vert_to_mrrg = std::map<ConfigGraph::VertexID, MRRG::NodeDescriptor>{};
16 
17  // Map nodes
18  for (const auto& v : config.allNodes()) {
19  const auto& v_attrs = config.attributes(v);
20  const bool isVal = v_attrs.hasKey("maps_to_val");
21  const bool isOp = v_attrs.hasKey("maps_to_op");
22 
23  if (!(isVal || isOp)) {
24  throw make_from_stream<cgrame_error>([&](auto&& s) {
25  s << "mrrg node: " << config.name(v) << " is not mapped to anything";
26  });
27  }
28 
29  std::string mrrg_node_name = config.name(v);
30  std::string op_name;
31  if (isVal){
32  op_name = v_attrs.getString("maps_to_val");
33  }
34  else {
35  op_name = v_attrs.getString("maps_to_op");
36  }
37  auto mrrg_ndesc = mrrg.getNode(v_attrs.getInt("cycle"), v_attrs.getString("name"));
38  if (mrrg_ndesc == nullptr) {
39  throw make_from_stream<cgrame_error>([&](auto&& s) {
40  s << "[ERROR]: mrrg node: " << v_attrs.getInt("cycle") << ":" << v_attrs.getString("name") << " is not part of specified architecture";
41  });
42  }
43 
44  // Map the mrrg node and op node
45  if (isVal) {
46  // Case of op node being a ValNode
47  m.mapMRRGNode(opgraph.getVal(op_name), mrrg_ndesc);
48  }
49  else {
50  // Case of op node being an OpNode
51  m.mapMRRGNode(opgraph.getOp(op_name), mrrg_ndesc);
52  }
53 
54  cg_vert_to_mrrg[v] = mrrg_ndesc;
55  }
56 
58 
59  // Create mapping graph
60  const auto& mapping = m.getMapping();
61  MappingGraph mg;
62  std::unordered_map<MRRG::NodeDescriptor, MappingGraph::NodeDescriptor> fromMRRG;
63  std::unordered_map<MappingGraph::NodeDescriptor, MRRG::NodeDescriptor, MappingGraph::NodeDescriptorHash> toMRRG;
64 
65  // Add nodes to mapping graph
66  for (auto & opToMRRGNodeList : mapping) {
67  for (auto & mrrgNode : opToMRRGNodeList.second) {
68  auto mgNode = mg.insert({opToMRRGNodeList.first}).first;
69  toMRRG.emplace(mgNode, mrrgNode);
70  fromMRRG.emplace(mrrgNode, mgNode);
71  }
72  }
73 
74  // Connect nodes together
75  for (const auto& v : config.allNodes()) {
76  for (const auto& out_edge : config.outEdges(v)) {
77  mg.link(fromMRRG[cg_vert_to_mrrg.at(v)], fromMRRG[cg_vert_to_mrrg.at(config.target(out_edge))]);
78  }
79  }
80  return {mg, fromMRRG, toMRRG};
81 }
ConfigGraph::allNodes
auto allNodes() const
Definition: ConfigGraph.h:142
ConfigGraph::attributes
const ConfigStore & attributes(const VertexID &v) const
Definition: ConfigGraph.h:128
MRRG
Definition: MRRG.h:216
Mapping::getMapping
std::map< OpGraph::NodeDescriptor, std::vector< MRRG::NodeDescriptor > > & getMapping()
Definition: Mapping.h:47
OpGraph::getOp
OpDescriptor getOp(const std::string &name) const
Definition: OpGraph.h:386
UserArchs.h
ConfigGraph
Definition: ConfigGraph.h:72
ConfigGraph::outEdges
auto outEdges(const VertexID &v) const
Definition: ConfigGraph.h:148
MappingGraph
Definition: Mapping.h:129
ConfigGraph::name
const std::string & name(const VertexID &v) const
Definition: ConfigGraph.h:123
Mapping::mapMRRGNode
void mapMRRGNode(OpGraph::NodeDescriptor, MRRG::NodeDescriptor node)
Definition: Mapping.cpp:58
CreateMappingGraphResult
Definition: Mapping.h:246
Mapping
Definition: Mapping.h:31
ConfigStore::hasKey
bool hasKey(const std::string &key) const
Definition: ConfigStore.h:209
createMappingGraphFromConfig
CreateMappingGraphResult createMappingGraphFromConfig(Mapping &m, const ConfigGraph &config, const OpGraph &opgraph, const MRRG &mrrg)
Definition: MappingProcedures.cpp:14
MappingProcedures.h
ConfigGraph::target
const VertexID & target(const EdgeID &e) const
Definition: ConfigGraph.h:134
MRRG::getNode
NodeDescriptor getNode(int cycle, const std::string &name) const
Definition: MRRG.cpp:142
MappingGraph::link
void link(MappingGraph::NodeDescriptor driver, MappingGraph::NodeDescriptor fanout)
Definition: Mapping.cpp:317
MappingStatus::success
@ success
MappingGraph::insert
std::pair< NodeDescriptor, bool > insert(MappingGraphNode node)
Definition: Mapping.cpp:303
OpGraph::getVal
ValDescriptor getVal(const std::string &name) const
Definition: OpGraph.h:387
OpGraph
Definition: OpGraph.h:215
Mapping::setStatus
void setStatus(MappingStatus new_status)
Definition: Mapping.h:40