Repository navigation
Expand file tree
/
Copy pathCGRA.cpp
More file actions
138 lines (101 loc) · 2.6 KB
/
Copy pathCGRA.cpp
File metadata and controls
138 lines (101 loc) · 2.6 KB
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
131
132
133
134
135
136
137
138
#include "CGRA.h"
CGRAnode::CGRAnode()
{
}
CGRA::~CGRA()
{
for (auto node : CGRAnodesList)
{
delete node;
}
}
CGRA::CGRA(int CGRARow, int CGRAColumn)
{
int column = CGRAColumn + 1;
ColNum = column;
ElmNum = CGRARow * column;//PEA的总数,包括LSU单元
int i, j, k;
for( j = 0; j < CGRARow; j++)
{
for(i = 0; i < column;i++)
{
CGRAnode* node = new CGRAnode();
int ElmCurrent = i + j * column;
node->ElmID = ElmCurrent;/* ElmID从0开始编号 */
node->inportNum = 5;
node->outportNum = 5;
int ElmN = i + ((j - 1 + CGRARow) % CGRARow ) * column;
int ElmS = i + ((j + 1) % CGRARow) * column;
int ElmW = ((i - 1) + column) % column + j * column;
int ElmE = (i + 1) % column + j * column;
if(i == 0)//LSU
{
node->ElmKind = 1;
for(int m = 0; m < CGRAColumn; m++)
{
node->ElmNeighbors.push_back(ElmCurrent + 1 + m);
}
}
else//PE
{
node->ElmKind = 0;
if(j == 0 || j == CGRARow-1)/* 第一行和最后一行 */
{
if(i == 1)/* PE的第一列 */
{
node->ElmNeighbors.push_back(ElmE);
}
else if(i == column - 1)//PE最后一列
{
node->ElmNeighbors.push_back(ElmW);
}
else//PE的中间列
{
node->ElmNeighbors.push_back(ElmW);
node->ElmNeighbors.push_back(ElmE);
}
if(j == 0)
{
node->ElmNeighbors.push_back(ElmS);
}
else if(j == CGRARow-1)
{
node->ElmNeighbors.push_back(ElmN);
}
}
else/* 中间行 */
{
node->ElmNeighbors.push_back(ElmN);
node->ElmNeighbors.push_back(ElmS);
if(i == 1)/* PE的第一列 */
{
node->ElmNeighbors.push_back(ElmE);
}
else if(i == column - 1)/* PE的最后一列 */
{
node->ElmNeighbors.push_back(ElmW);
}
else//PE的中间列
{
node->ElmNeighbors.push_back(ElmW);
node->ElmNeighbors.push_back(ElmE);
}
}
node->ElmNeighbors.push_back(j * column);
}
CGRAnodesList.push_back(node);
}
}
// cout<<"ElmNum"<<ElmNum<<endl;
// for(int Z = 0; Z < ElmNum;Z++)
// {
// cout<<CGRAnodesList[Z]->ElmID<<endl;
// int num = CGRAnodesList[Z]->ElmNeighbors.size();
// cout<<"neighbor:";
// for(int y = 0; y<num;y++)
// {
// cout<< CGRAnodesList[Z]->ElmNeighbors[y]<<" ";
// }
// cout<<endl;
// }
}