-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatewayinterface.cpp
298 lines (259 loc) · 8.74 KB
/
gatewayinterface.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include "gatewayinterface.h"
void TGatewayInterface::delayCount()
{
if (reset.read())
{
cycle_count =0;
}
else
{
// cycle_count++;
if(cycle_count > PHOTONIC_DELAY)
cycle_count =0;
else
cycle_count++;
}
}
/** This thread transfers flits to the lower electrical layer.
* Since the photonic communication comes to an end here , the
* inter pri bit is reset here before sending to electrical router
**/
void TGatewayInterface::clos_to_local_rx_process() // Clock Edge
{
if (reset.read())
{
for(int i=0; i< TGlobalParams::clos_waveguides; i++)
{
previous_transfer_photonic[i] = -10;
previous_transfer_srcid[i] = -6;
}
}
else
{
for(int i=0; i< TGlobalParams::clos_waveguides; i++)
{
TFlit received_flit_temp = clos_data_rx[i].read();
if(received_flit_temp.dst_cluster_id == cluster_id )//&& received_flit_temp.flit_type == FLIT_TYPE_HEAD)
{
if(previous_transfer_photonic[i] != received_flit_temp.timestamp && !buffer_receive.IsFull() )
{
if(TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout<< sc_time_stamp().to_double()/1000 << " gwi Source_Cluster_Id --> " << received_flit_temp.src_cluster_id <<" gwi Destination_Cluster_Id --> " << received_flit_temp.dst_cluster_id <<" Port number : " << i << endl;
}
previous_transfer_photonic[i] = received_flit_temp.timestamp;
previous_transfer_srcid[i] = received_flit_temp.src_id;
buffer_receive.Push(received_flit_temp);
stats.power.Buffering();
}
else
{
if(previous_transfer_srcid[i] != received_flit_temp.src_id && !buffer_receive.IsFull() )
{
if(TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout<< sc_time_stamp().to_double()/1000 << " gwi Source_Cluster_Id --> " << received_flit_temp.src_cluster_id <<" gwi Destination_Cluster_Id --> " << received_flit_temp.dst_cluster_id <<" Port number : " << i << endl;
}
previous_transfer_photonic[i] = received_flit_temp.timestamp;
previous_transfer_srcid[i] = received_flit_temp.src_id;
buffer_receive.Push(received_flit_temp);
stats.power.Buffering();
}
}
}
}
stats.power.Leakage();
}
}
void TGatewayInterface::clos_to_local_tx_process() // sensitive -- photonic_to_electrical_tx
{
if(reset.read())
{
for (int i = 0; i<HUBS_PER_CLUSTER; i++)
{
req_tx[i].write(0);
current_level_tx[i] =0;
}
}
else
{
if ( !buffer_receive.IsEmpty() && !reset.read() )
{
TFlit received_flit = buffer_receive.Front();
if (ack_tx[0].read() == current_level_tx[0] && received_flit.dst_hub_id == (cluster_id*2))
{
if(TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout << sc_time_stamp().to_double()/1000 << ": Photonic buffer["<< cluster_id <<"] Flit Source_Id --> " << received_flit.src_id <<" Flit Destination_Id --> " << received_flit.dst_id<< endl;
}
flit_tx[0].write(received_flit); // passing the flit from photonic buffer to electircal domain
current_level_tx[0] = 1-current_level_tx[0];
req_tx[0].write(current_level_tx[0]);
buffer_receive.Pop();
}
else if (ack_tx[0].read() == current_level_tx[0] && received_flit.dst_hub_id == (cluster_id*2)+1)
{
if(TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout << sc_time_stamp().to_double()/1000 << ": Photonic buffer["<< cluster_id <<"] Flit Source_Id --> " << received_flit.src_id <<" Flit Destination_Id --> " << received_flit.dst_id<< endl;
}
flit_tx[1].write(received_flit); // passing the flit from photonic buffer to electircal domain
current_level_tx[1] = 1-current_level_tx[1];
req_tx[1].write(current_level_tx[1]);
buffer_receive.Pop();
}
}
stats.power.Leakage();
}
}
void TGatewayInterface::local_to_local_tx_process() // sensitive -- photonic_to_electrical_tx
{
if(reset.read())
{
for (int i = 0; i<HUBS_PER_CLUSTER; i++)
{
req_tx[i].write(0);
current_level_tx_local[i] =0;
}
}
else
{
if ( !buffer_local[0].IsEmpty() && cycle_count == PHOTONIC_DELAY)
{
//cout<<"debug_test"<<endl;
TFlit received_flit = buffer_local[0].Front();
if (ack_tx[1].read() == current_level_tx_local[1] && received_flit.dst_hub_id == (cluster_id*2)+1)
{
if(TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout << sc_time_stamp().to_double()/1000 << ": Photonic buffer["<< cluster_id <<"] Flit Source_Id --> " << received_flit.src_id <<" Flit Destination_Id --> " << received_flit.dst_id<< endl;
}
current_level_tx_local[1] = 1-current_level_tx_local[1];
req_tx[1].write(current_level_tx_local[1]);
if(1)
{
flit_tx[1].write(received_flit); // passing the flit from photonic buffer to electircal domain
buffer_local[0].Pop();
}
stats.power.Arbitration();
}
}
else if ( !buffer_local[1].IsEmpty() && cycle_count == PHOTONIC_DELAY)
{
TFlit received_flit = buffer_local[1].Front();
if (ack_tx[0].read() == current_level_tx_local[0] && received_flit.dst_hub_id == (cluster_id*2))
{
if(TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout << sc_time_stamp().to_double()/1000 << ": Photonic buffer["<< cluster_id <<"] Flit Source_Id --> " << received_flit.src_id <<" Flit Destination_Id --> " << received_flit.dst_id<< endl;
}
current_level_tx_local[0] = 1-current_level_tx_local[0];
req_tx[0].write(current_level_tx_local[0]);
if(1)
{
flit_tx[0].write(received_flit); // passing the flit from photonic buffer to electircal domain
buffer_local[1].Pop();
}
stats.power.Arbitration();
}
}
stats.power.Leakage();
}
}
/** This thread recieves flits from the lower electrical layer and stores it
* in the local buffer. Once a flit is pushed in the buffer ,process triggers
* the photonic transfer process by notifying the reservation process
**/
void TGatewayInterface::local_to_local_rx_process() // sensitive -- photonic_to_electrical_tx
{
if(reset.read())
{ // Clear outputs and indexes of receiving protocol
for (int i = 0; i < HUBS_PER_CLUSTER; i++)
{
ack_rx[i].write(0);
current_level_rx[i] = 0;
}
//reservation_table.clear();
routed_flits = 0;
local_drained = 0;
}
else
{
// For each channel decide if a new flit can be accepted
//
// This process simply sees a flow of incoming flits. All arbitration
// and wormhole related issues are addressed in the txProcess()
for (int i = 0; i < HUBS_PER_CLUSTER; i++)
{
// To accept a new flit, the following conditions must match:
//
// 1) there is an incoming request
// 2) there is a free slot in the input buffer of direction i
if ((req_rx[i].read() == 1 - current_level_rx[i])
&& !buffer_local[i].IsFull())
{
TFlit received_flit = flit_rx[i].read();
// Store the incoming flit in to buffer
if(received_flit.src_id != received_flit.dst_id)
{
buffer_local[i].Push(received_flit);
if (TGlobalParams::verbose_mode > VERBOSE_OFF)
{
cout << sc_time_stamp().to_double()/1000 << ": GWI with ClusterID[" << cluster_id << "], Input[" << i << "], Received flit: " << received_flit <<" pendind flits "<<buffer_local[i].
Size()<< endl;
}
// Negate the old value for Alternating Bit Protocol (ABP)
current_level_rx[i] = 1 - current_level_rx[i];
// Incoming flit
stats.power.Buffering();
}
}
ack_rx[i].write(current_level_rx[i]);
}
}
stats.power.Leakage();
}
/**--------------------------------------------------------------------------
* This module writes on crossbar in Clos Network and trainsmits data to its destination
* based on the destination location
*
---------------------------------------------------------------------------*/
void TGatewayInterface::local_to_clos_tx_process() // sensitive - Clock
{
if(reset.read())
{
// flitsThroughGWI=0;
}
else if(!reset.read() && cycle_count == PHOTONIC_DELAY )
{
for(int i=0; i<HUBS_PER_CLUSTER; i++)
{
if(!buffer_local[i].IsEmpty() )
{
TFlit tx_flit = buffer_local[i].Front(); //sending head flit to the channel assigned by the arbiter
if(tx_flit.src_cluster_id != tx_flit.dst_cluster_id)
{
clos_data_tx[tx_flit.dst_cluster_id].write(tx_flit);
if(TGlobalParams::verbose_mode > VERBOSE_OFF )
{
cout<< sc_time_stamp().to_double()/1000 << "Source_Cluster_Id --> " << tx_flit.src_cluster_id << " Cluster id " << cluster_id <<" Destination_Cluster_Id --> " << tx_flit.dst_cluster_id << endl;
}
buffer_local[i].Pop();
// if(tx_flit.flit_type == FLIT_TYPE_HEAD && tx_flit.dst_cluster_id!=tx_flit.src_cluster_id)
// flitsThroughGWI++;
routed_flits++;
}
}
}
}
stats.power.Leakage();
}
//---------------------------------------------------------------------------
unsigned long TGatewayInterface::getRoutedFlits()
{
return routed_flits;
}
double TGatewayInterface::getPower()
{
return stats.power.getPower();
}