CGRA-ME
createMappingGraphFromConfig_tests.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/Mapping.h>
12 #include <CGRA/MappingProcedures.h>
13 #include <CGRA/Module.h>
14 
16 
17 #include <iostream>
18 
19 #include <catch2/catch.hpp>
20 
21 SCENARIO("createMappingGraphFromConfig tests") {
22  GIVEN("an empty mapping") {
23  std::shared_ptr<OpGraph> og = std::make_shared<OpGraph>(makeDFG_Linear3Node()); // Simple DFG a -> b -> c
24 
25  Mapping mapping(nullptr, 1, og);
26 
27  MRRG mrrg(1);
28  Module fillerMod("Mod", "");
29 
30  auto m1 = mrrg.insert(MRRGNode::make_function(&fillerMod, 32, 0, "m1", 0, {})).first;
31  auto m2 = mrrg.insert(MRRGNode::make_routing(&fillerMod, 32, 0, "m2", 0)).first;
32  auto m3 = mrrg.insert(MRRGNode::make_function(&fillerMod, 32, 0, "m3", 0, {})).first;
33  auto m4 = mrrg.insert(MRRGNode::make_function(&fillerMod, 32, 0, "m4", 0, {})).first;
34  auto m5 = mrrg.insert(MRRGNode::make_function(&fillerMod, 32, 0, "m5", 0, {})).first;
35 
36  WHEN("a simple config graph is given") {
37  ConfigGraph cg;
38  auto v1 = cg.insert("m1",
39  {
40  {"maps_to_op", "op_a"},
41  {"name", "m1"},
42  {"cycle", "0"}
43  }).first;
44  auto v2 = cg.insert("m2",
45  {
46  {"maps_to_val", "op_a_out"},
47  {"name", "m2"},
48  {"cycle", "0"}
49  }).first;
50  auto v3 = cg.insert("m3",
51  {
52  {"maps_to_val", "op_a_out"},
53  {"name", "m3"},
54  {"cycle", "0"}
55  }).first;
56  auto v4 = cg.insert("m4",
57  {
58  {"maps_to_op", "op_b"},
59  {"name", "m4"},
60  {"cycle", "0"}
61  }).first;
62 
63  cg.link(v1, v2);
64  cg.link(v2, v3);
65  cg.link(v3, v4);
66 
67  auto cmg = createMappingGraphFromConfig(mapping, cg, *og, mrrg);
68 
69  THEN("Mapping should be as expected") {
70  // Check Mapping
71  CHECK(mapping.getMapping().size() == 3);
72  CHECK(mapping.getSingleMapping(og->getOp("op_a")) == m1);
73 
74  std::set<MRRG::NodeDescriptor> expected = std::set<MRRG::NodeDescriptor>{m2, m3};
75  const auto actual = std::set<MRRG::NodeDescriptor>(mapping.getMapping()[og->getVal("op_a_out")].begin(), mapping.getMapping()[og->getVal("op_a_out")].end());
76  CHECK(expected == actual);
77 
78  CHECK(mapping.getSingleMapping(og->getOp("op_b")) == m4);
79 
80  // Check links
81  CHECK(cmg.mg.fanout(cmg.fromMRRG[m1])[0] == cmg.fromMRRG[m2]);
82  CHECK(cmg.mg.fanout(cmg.fromMRRG[m2])[0] == cmg.fromMRRG[m3]);
83  CHECK(cmg.mg.fanout(cmg.fromMRRG[m3])[0] == cmg.fromMRRG[m4]);
84  }
85  }
86  }
87 }
MRRG
Definition: MRRG.h:216
Mapping::getSingleMapping
MRRG::NodeDescriptor getSingleMapping(OpGraph::NodeDescriptor key) const
Definition: Mapping.h:56
Mapping::getMapping
std::map< OpGraph::NodeDescriptor, std::vector< MRRG::NodeDescriptor > > & getMapping()
Definition: Mapping.h:47
Module.h
ConfigGraph
Definition: ConfigGraph.h:72
MRRG::insert
std::pair< NodeDescriptor, bool > insert(MRRGNode node)
Definition: MRRG.cpp:91
makeDFG_Linear3Node
OpGraph makeDFG_Linear3Node()
Definition: OpGraphsForTesting.cpp:50
Mapping
Definition: Mapping.h:31
MRRGNode::make_function
static MRRGNode make_function(Module *parent, int bitwidth, int cycle, STR &&name, int latency, SupportedOps supported_ops, int max_cap=1, bool is_const_unit=false)
Definition: MRRG.h:191
SCENARIO
SCENARIO("createMappingGraphFromConfig tests")
Definition: createMappingGraphFromConfig_tests.cpp:21
OpGraphsForTesting.hpp
Module
Definition: Module.h:163
ConfigGraph::insert
std::pair< VertexID, bool > insert(std::string name, ConfigStore vertex_attrs={})
Definition: ConfigGraph.h:173
ConfigGraph::link
EdgeID link(VertexID source, VertexID target, ConfigStore edge_attrs={})
Definition: ConfigGraph.h:190
createMappingGraphFromConfig
CreateMappingGraphResult createMappingGraphFromConfig(Mapping &m, const ConfigGraph &config, const OpGraph &opgraph, const MRRG &mrrg)
Definition: MappingProcedures.cpp:14
MappingProcedures.h
Mapping.h
MRRGNode::make_routing
static MRRGNode make_routing(Module *parent, int bitwidth, int cycle, STR &&name, int latency=0, int max_cap=1)
Definition: MRRG.h:151