CGRA-ME
MRRG_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/Module.h>
12 #include <CGRA/MRRG.h>
13 
14 #include <catch2/catch.hpp>
15 
16 SCENARIO ("tagging operands to mrrg nodes") {
17  MRRG mrrg(1);
18  GIVEN("a 2 input computation") {
19  const auto in1 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in1", {Operands::BINARY_LHS, Operands::BINARY_ANY})).first;
20  const auto in2 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in2", {Operands::BINARY_RHS, Operands::BINARY_ANY})).first;
21  const auto fu = mrrg.insertMultiFanin({in1, in2}, MRRGNode::make_function(nullptr, 32, 0, "fu", 0, {OpCode::ADD, OpCode::SUB})).first;
22 
23  CHECK(verifyAndPrintReport(mrrg, std::cout, true, true));
24  }
25 
26  GIVEN("a 3 input computation") {
27  const auto in1 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in1", {Operands::BINARY_LHS, Operands::TERNARY_ANY})).first;
28  const auto in2 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in2", {Operands::BINARY_RHS, Operands::TERNARY_ANY})).first;
29  const auto in3 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in3", {Operands::BINARY_RHS, Operands::TERNARY_ANY})).first;
30 
31  const auto fu = mrrg.insertMultiFanin({in1, in2, in3}, MRRGNode::make_function(nullptr, 32, 0, "fu", 0, {OpCode::ADD})).first;
32 
33  CHECK(verifyAndPrintReport(mrrg, std::cout, true, true));
34  }
35 
36  GIVEN("a series of 2 input computations") {
37  const auto in1 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in1", {Operands::BINARY_LHS, Operands::BINARY_ANY})).first;
38  const auto in2 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in2", {Operands::BINARY_RHS, Operands::BINARY_ANY})).first;
39  const auto fu1 = mrrg.insertMultiFanin({in1, in2}, MRRGNode::make_function(nullptr, 32, 0, "fu1", 0, {OpCode::ADD, OpCode::SUB})).first;
40 
41  const auto out1 = mrrg.insert(fu1, MRRGNode::make_operand_pin(nullptr, 32, 0, "out1", {Operands::BINARY_LHS, Operands::BINARY_ANY})).first;
42  const auto in3 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in3", {Operands::BINARY_RHS, Operands::BINARY_ANY})).first;
43 
44  const auto fu2 = mrrg.insertMultiFanin({out1, in3}, MRRGNode::make_function(nullptr, 32, 0, "fu2", 0, {OpCode::ADD, OpCode::SUB})).first;
45 
46  CHECK(verifyAndPrintReport(mrrg, std::cout, true, true));
47  }
48 
49  GIVEN("a feedback computation") {
50  const auto in1 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in1", {Operands::BINARY_LHS, Operands::BINARY_ANY})).first;
51  const auto in2 = mrrg.insert( MRRGNode::make_operand_pin(nullptr, 32, 0, "in2", {Operands::BINARY_RHS, Operands::BINARY_ANY})).first;
52  const auto fu = mrrg.insertMultiFanin({in1, in2}, MRRGNode::make_function(nullptr, 32, 0, "fu", 0, {OpCode::ADD, OpCode::SUB})).first;
53  mrrg.link(fu, in2);
54 
55  CHECK(verifyAndPrintReport(mrrg, std::cout, true, true));
56  }
57 }
MRRG::link
void link(MRRG::NodeDescriptor driver, MRRG::NodeDescriptor fanout)
Definition: MRRG.cpp:849
MRRG::insertMultiFanin
std::pair< NodeDescriptor, bool > insertMultiFanin(NodeDescList fanins, MRRGNode node)
Definition: MRRG.h:242
verifyAndPrintReport
bool verifyAndPrintReport(const MRRG &mrrg, std::ostream &os, bool silent_on_no_errors, bool throw_if_errors, const ConfigStore &extra_opts)
Definition: MRRG.cpp:473
MRRG
Definition: MRRG.h:216
Operands::BINARY_LHS
static constexpr auto & BINARY_LHS
Definition: OpGraph.h:89
Module.h
OpCode::ADD
@ ADD
MRRG::insert
std::pair< NodeDescriptor, bool > insert(MRRGNode node)
Definition: MRRG.cpp:91
Operands::BINARY_RHS
static constexpr auto & BINARY_RHS
Definition: OpGraph.h:90
MRRGNode::make_operand_pin
static MRRGNode make_operand_pin(Module *parent, int bitwidth, int cycle, STR &&name, SupportedOpTags operand_tags, int latency=0, int max_cap=1)
Definition: MRRG.h:164
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("tagging operands to mrrg nodes")
Definition: MRRG_tests.cpp:16
OpCode::SUB
@ SUB
Operands::BINARY_ANY
static constexpr auto & BINARY_ANY
Definition: OpGraph.h:91
MRRG.h
Operands::TERNARY_ANY
static constexpr auto & TERNARY_ANY
Definition: OpGraph.h:92