-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHyCUBE.cpp
130 lines (107 loc) · 3.37 KB
/
HyCUBE.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//HyCUBE.cpp
//Implements the HyCUBE architecture using the C++ API in CGRA-ME
//Utilizes HyCUBEPE, a processing element specified in the HyCUBE paper
//1. Setup
#include <CGRA/Module.h>
#include <CGRA/ModuleComposites.h>
#include <CGRA/CGRA.h>
#include <CGRA/ILPMapper.h>
#include <CGRA/OpGraph.h>
#include <CGRA/Exception.h>
#include <CGRA/user-inc/UserArchs.h>
#include <CGRA/user-inc/UserModules.h>
#include <stdio.h>
std::unique_ptr<CGRA> UserArchs::createHyCUBEArch(const std::map<std::string, std::string> & args)
{
//Declare all variables
int cols;
int rows;
int pred;
int c,r;
//For use in connections
std::string north = std::to_string(0);
std::string east = std::to_string(1);
std::string west = std::to_string(2);
std::string south = std::to_string(3);
//Collect variables from arguments
try
{
cols = std::stoi(args.at("cols"));
rows = std::stoi(args.at("rows"));
pred = std::stoi(args.at("pred")); //Indicates whether or not we are using predicates
}
catch(const std::out_of_range & e)
{
throw cgrame_error("C++ Architecture Argument Error");
}
//Determine bit width
if(pred == 1)
{
unsigned const SIZE = 33;
} else {
unsigned const SIZE = 32;
}
//Create CGRA pointer
std::unique_ptr<CGRA> result(new CGRA());
//2. Add all elements within the Architecture
//HyCUBE Processing Elements:
for (c = 0; c < cols; c++)
{
for(r = 0; r < rows; r++)
{
if(c == 0)
{ //Load-store-enabled PE's must sit in the second column
result->addSubModule(new HyCUBEPE("pe_c0_r" + std::to_string(r), pred, 1));
} else {
//All other PE's are not load-store-enabled
result->addSubModule(new HyCUBEPE("pe_c" + std::to_string(c) + "_r" + std::to_string(r), pred, 0));
}
}
}
// I/O's
//3. Add Configuration Files (if necessary)
//4. Add Ports
//5. Add Connections
for(c = 1; c < cols; c++)
{
for(r = 1; r < rows; r++)
{
std::string cColumn = std::to_string(c);
std::string cRow = std::to_string(r);
std::string pColumn = std::to_string(c-1);
std::string pRow = std::to_string(r-1);
//North-South connection
result->addConnection("pe_c" + cColumn + "_r" + pRow + ".out" + south,
"pe_c" + cColumn + "_r" + cRow + ".in" + north);
result->addConnection("pe_c" + cColumn + "_r" + cRow + ".out" + north,
"pe_c" + cColumn + "_r" + pRow + ".in" + south);
//East-West connection
result->addConnection("pe_c" + pColumn + "_r" + cRow + ".out" + east,
"pe_c" + cColumn + "_r" + cRow + ".in" + west);
result->addConnection("pe_c" + cColumn + "_r" + cRow + ".out" + west,
"pe_c" + pColumn + "_r" + cRow + ".in" + east);
}
}
//Edge Case 1: Connect Column 0 N-S
for(r = 1; r < rows; r++)
{
std::string cRow = std::to_string(r);
std::string pRow = std::to_string(r-1);
result->addConnection("pe_c0_r" + cRow + ".out" + north,
"pe_c0_r" + pRow + ".in" + south);
result->addConnection("pe_c0_r" + pRow + ".out" + south,
"pe_c0_r" + cRow + ".in" + north);
}
//Edge Case 2: Connect Row 0 E-W
for(c = 1; c < cols; c++)
{
std::string cCol = std::to_string(c);
std::string pCol = std::to_string(c-1);
result->addConnection("pe_c" + cCol + "_r0.out" + west,
"pe_c" + pCol + "_r0.in" + east);
result->addConnection("pe_c" + pCol + "_r0.out" + east,
"pe_c" + cCol + "_r0.in" + west);
}
//6. Return pointer
return result;
}