1 | /** |
---|
2 | * @author Cesar Armando Fuguet Tortolero |
---|
3 | * @date 24 May, 2015 |
---|
4 | * @brief This platform allows the validation of the reconfigurable routing |
---|
5 | * algorithm on the DSPIN router component. The platform has been |
---|
6 | * specifically designed to test the routing of broadcast packets. |
---|
7 | */ |
---|
8 | #include <iostream> |
---|
9 | #include <systemc> |
---|
10 | #include <cassert> |
---|
11 | #include <cstdlib> |
---|
12 | |
---|
13 | #include "dspin_router.h" |
---|
14 | #include "dspin_router_config.h" |
---|
15 | #include "dspin_packet_generator.h" |
---|
16 | #include "alloc_elems.h" |
---|
17 | |
---|
18 | #if _OPENMP |
---|
19 | #include <omp.h> |
---|
20 | #endif |
---|
21 | |
---|
22 | /* |
---|
23 | * Platform constant parameters |
---|
24 | */ |
---|
25 | #define X_WIDTH 4 |
---|
26 | #define Y_WIDTH 4 |
---|
27 | |
---|
28 | #define FIFO_DEPTH 2 |
---|
29 | #define NFLITS 8 |
---|
30 | #define LOAD 1000 |
---|
31 | #define BROADCAST_PERIOD 1 |
---|
32 | #define DSPIN_WIDTH 39 |
---|
33 | #define MAX_PACKETS 100 |
---|
34 | |
---|
35 | /* |
---|
36 | * Platform default values |
---|
37 | */ |
---|
38 | #define X_SIZE 5 |
---|
39 | #define Y_SIZE 5 |
---|
40 | |
---|
41 | static inline int cluster(int x, int y) |
---|
42 | { |
---|
43 | return (x << Y_WIDTH) | y; |
---|
44 | } |
---|
45 | |
---|
46 | static inline uint32_t configRouter(int bypass_mode, |
---|
47 | int reallocation_dir, |
---|
48 | int blackhole_pos) |
---|
49 | { |
---|
50 | return (bypass_mode << 7) | (reallocation_dir << 4) | blackhole_pos; |
---|
51 | } |
---|
52 | |
---|
53 | int sc_main(int argc, char **argv) |
---|
54 | { |
---|
55 | using namespace soclib::caba; |
---|
56 | using namespace soclib::common; |
---|
57 | |
---|
58 | typedef DspinPacketGenerator<DSPIN_WIDTH, DSPIN_WIDTH> |
---|
59 | DspinGeneratorType; |
---|
60 | typedef DspinRouter<DSPIN_WIDTH> |
---|
61 | DspinRouterType; |
---|
62 | typedef DspinSignals<DSPIN_WIDTH> |
---|
63 | DspinSignalType; |
---|
64 | |
---|
65 | #if _OPENMP |
---|
66 | omp_set_dynamic(false); |
---|
67 | omp_set_num_threads(1); |
---|
68 | #endif |
---|
69 | |
---|
70 | /* mesh size */ |
---|
71 | int xSize = X_SIZE; |
---|
72 | int ySize = Y_SIZE; |
---|
73 | |
---|
74 | /* (x,y) coordinates of the initiator router */ |
---|
75 | int xSrc = -1; |
---|
76 | int ySrc = -1; |
---|
77 | |
---|
78 | /* (x,y) coordinates of the faulty router */ |
---|
79 | int xFaulty = -1; |
---|
80 | int yFaulty = -1; |
---|
81 | |
---|
82 | /* simulation cycles */ |
---|
83 | size_t simCycles = 0; |
---|
84 | |
---|
85 | /* debug */ |
---|
86 | bool debug = false; |
---|
87 | |
---|
88 | /* synthetic generator load */ |
---|
89 | int load = LOAD; |
---|
90 | |
---|
91 | /* broadcast period */ |
---|
92 | int bcp = BROADCAST_PERIOD; |
---|
93 | |
---|
94 | /* maximum number of packets per generator */ |
---|
95 | size_t max = MAX_PACKETS; |
---|
96 | |
---|
97 | for (int n = 1; n < argc; n += 2) { |
---|
98 | if ((strcmp(argv[n], "-X") == 0) && ((n + 1) < argc)) { |
---|
99 | xSize = strtol(argv[n + 1], NULL, 0); |
---|
100 | continue; |
---|
101 | } |
---|
102 | if ((strcmp(argv[n], "-Y") == 0) && ((n + 1) < argc) ) { |
---|
103 | ySize = strtol(argv[n + 1], NULL, 0); |
---|
104 | continue; |
---|
105 | } |
---|
106 | if ((strcmp(argv[n], "-FX") == 0) && ((n + 1) < argc)) { |
---|
107 | xFaulty = strtol(argv[n + 1], NULL, 0); |
---|
108 | continue; |
---|
109 | } |
---|
110 | if ((strcmp(argv[n], "-FY") == 0) && ((n + 1) < argc) ) { |
---|
111 | yFaulty = strtol(argv[n + 1], NULL, 0); |
---|
112 | continue; |
---|
113 | } |
---|
114 | if ((strcmp(argv[n], "-SX") == 0) && ((n + 1) < argc)) { |
---|
115 | xSrc = strtol(argv[n + 1], NULL, 0); |
---|
116 | continue; |
---|
117 | } |
---|
118 | if ((strcmp(argv[n], "-SY") == 0) && ((n + 1) < argc) ) { |
---|
119 | ySrc = strtol(argv[n + 1], NULL, 0); |
---|
120 | continue; |
---|
121 | } |
---|
122 | if ((strcmp(argv[n], "-N") == 0) && ((n + 1) < argc) ) { |
---|
123 | simCycles = strtol(argv[n + 1], NULL, 0); |
---|
124 | assert(simCycles > 0); |
---|
125 | continue; |
---|
126 | } |
---|
127 | if ((strcmp(argv[n], "-L") == 0) && ((n + 1) < argc) ) { |
---|
128 | load = strtol(argv[n + 1], NULL, 0); |
---|
129 | assert(load > 0); |
---|
130 | continue; |
---|
131 | } |
---|
132 | if ((strcmp(argv[n], "-B") == 0) && ((n + 1) < argc) ) { |
---|
133 | bcp = strtol(argv[n + 1], NULL, 0); |
---|
134 | assert(bcp >= 0); |
---|
135 | continue; |
---|
136 | } |
---|
137 | if ((strcmp(argv[n], "-P") == 0) && ((n + 1) < argc) ) { |
---|
138 | max = strtol(argv[n + 1], NULL, 0); |
---|
139 | continue; |
---|
140 | } |
---|
141 | if ((strcmp(argv[n--], "-G") == 0)) { |
---|
142 | debug = true; |
---|
143 | continue; |
---|
144 | } |
---|
145 | } |
---|
146 | |
---|
147 | assert (xFaulty < xSize ); |
---|
148 | assert (yFaulty < ySize ); |
---|
149 | assert (xSrc < xSize ); |
---|
150 | assert (ySrc < ySize ); |
---|
151 | |
---|
152 | DspinGeneratorType ***dspinGenerator = new DspinGeneratorType**[xSize]; |
---|
153 | DspinRouterType ***dspinRouter = new DspinRouterType**[xSize]; |
---|
154 | for (int x = 0; x < xSize; ++x) { |
---|
155 | dspinGenerator[x] = new DspinGeneratorType*[ySize]; |
---|
156 | dspinRouter[x] = new DspinRouterType*[ySize]; |
---|
157 | for (int y = 0; y < ySize; ++y) { |
---|
158 | const bool BROADCAST_SUPPORTED = true; |
---|
159 | const bool CONFIGURATION_SUPPORTED = true; |
---|
160 | std::ostringstream routerStr; |
---|
161 | routerStr << "dspinRouter["<< x << "][" << y << "]"; |
---|
162 | dspinRouter[x][y] = |
---|
163 | new DspinRouterType(routerStr.str().c_str(), x, y, |
---|
164 | X_WIDTH, Y_WIDTH, |
---|
165 | FIFO_DEPTH, FIFO_DEPTH, |
---|
166 | BROADCAST_SUPPORTED, |
---|
167 | CONFIGURATION_SUPPORTED); |
---|
168 | |
---|
169 | if ((x == xFaulty) && (y == yFaulty)) { |
---|
170 | dspinRouter[x][y]->set_disable_mask(0x1F); |
---|
171 | } |
---|
172 | |
---|
173 | int ld = 0; |
---|
174 | const int SRCID = cluster(x,y); |
---|
175 | bool all = (xSrc == -1) || (ySrc == -1); |
---|
176 | if (all || (cluster(x,y) == cluster(xSrc,ySrc))) { |
---|
177 | ld = load; |
---|
178 | } |
---|
179 | if ((x == xFaulty) && (y == yFaulty)) { |
---|
180 | ld = 0; |
---|
181 | } |
---|
182 | if (simCycles > 0) { |
---|
183 | max = 0; |
---|
184 | } |
---|
185 | std::ostringstream generatorStr; |
---|
186 | generatorStr << "dspinGenerator["<< x << "][" << y << "]"; |
---|
187 | dspinGenerator[x][y] = |
---|
188 | new DspinGeneratorType(generatorStr.str().c_str(), |
---|
189 | SRCID, NFLITS, |
---|
190 | ld, 8, |
---|
191 | bcp, |
---|
192 | X_WIDTH, Y_WIDTH, |
---|
193 | X_SIZE, Y_SIZE, |
---|
194 | max); |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | const int H = xSize - 1; |
---|
199 | const int Y = ySize - 1; |
---|
200 | sc_clock signal_clk("clk"); |
---|
201 | sc_core::sc_signal<bool> signal_resetn("signal_resetn"); |
---|
202 | DspinSignalType*** sDspinL = |
---|
203 | alloc_elems<DspinSignalType>("sDspinL", xSize, ySize, 2); |
---|
204 | DspinSignalType*** sDspinH = |
---|
205 | alloc_elems<DspinSignalType>("sDspinH", H + 2, ySize, 2); |
---|
206 | DspinSignalType*** sDspinV = |
---|
207 | alloc_elems<DspinSignalType>("sDspinV", xSize, Y + 2, 2); |
---|
208 | sc_signal<uint32_t> sConfigNONE("sConfigNONE"); |
---|
209 | sc_signal<uint32_t> sConfigN("sConfigN"); |
---|
210 | sc_signal<uint32_t> sConfigNW("sConfigNW"); |
---|
211 | sc_signal<uint32_t> sConfigNE("sConfigNE"); |
---|
212 | sc_signal<uint32_t> sConfigS("sConfigS"); |
---|
213 | sc_signal<uint32_t> sConfigSW("sConfigSW"); |
---|
214 | sc_signal<uint32_t> sConfigSE("sConfigSE"); |
---|
215 | sc_signal<uint32_t> sConfigW("sConfigW"); |
---|
216 | sc_signal<uint32_t> sConfigE("sConfigE"); |
---|
217 | for (int x = 0; x < xSize; ++x) { |
---|
218 | for (int y = 0; y < ySize; ++y) { |
---|
219 | dspinGenerator[x][y]->p_clk(signal_clk); |
---|
220 | dspinGenerator[x][y]->p_resetn(signal_resetn); |
---|
221 | dspinGenerator[x][y]->p_out(sDspinL[x][y][0]); |
---|
222 | dspinGenerator[x][y]->p_in(sDspinL[x][y][1]); |
---|
223 | |
---|
224 | dspinRouter[x][y]->p_clk(signal_clk); |
---|
225 | dspinRouter[x][y]->p_resetn(signal_resetn); |
---|
226 | dspinRouter[x][y]->p_in[0](sDspinV[x][y + 1][1]); |
---|
227 | dspinRouter[x][y]->p_out[0](sDspinV[x][y + 1][0]); |
---|
228 | dspinRouter[x][y]->p_in[1](sDspinV[x][y][0]); |
---|
229 | dspinRouter[x][y]->p_out[1](sDspinV[x][y][1]); |
---|
230 | dspinRouter[x][y]->p_in[2](sDspinH[x + 1][y][1]); |
---|
231 | dspinRouter[x][y]->p_out[2](sDspinH[x + 1][y][0]); |
---|
232 | dspinRouter[x][y]->p_in[3](sDspinH[x][y][0]); |
---|
233 | dspinRouter[x][y]->p_out[3](sDspinH[x][y][1]); |
---|
234 | dspinRouter[x][y]->p_in[4](sDspinL[x][y][0]); |
---|
235 | dspinRouter[x][y]->p_out[4](sDspinL[x][y][1]); |
---|
236 | |
---|
237 | if ((xFaulty < 0) || (yFaulty < 0)) { |
---|
238 | dspinRouter[x][y]->bind_recovery_port(sConfigNONE); |
---|
239 | continue; |
---|
240 | } |
---|
241 | |
---|
242 | if (x == (xFaulty + 1)) { |
---|
243 | if (y == (yFaulty + 1)) { |
---|
244 | dspinRouter[x][y]->bind_recovery_port(sConfigNE); |
---|
245 | std::cout << "config NE" << std::endl; |
---|
246 | continue; |
---|
247 | } |
---|
248 | if (y == yFaulty) { |
---|
249 | dspinRouter[x][y]->bind_recovery_port(sConfigE); |
---|
250 | std::cout << "config E" << std::endl; |
---|
251 | continue; |
---|
252 | } |
---|
253 | if (y == (yFaulty - 1)) { |
---|
254 | dspinRouter[x][y]->bind_recovery_port(sConfigSE); |
---|
255 | std::cout << "config SE" << std::endl; |
---|
256 | continue; |
---|
257 | } |
---|
258 | } |
---|
259 | if (x == xFaulty) { |
---|
260 | if (y == (yFaulty + 1)) { |
---|
261 | dspinRouter[x][y]->bind_recovery_port(sConfigN); |
---|
262 | std::cout << "config N" << std::endl; |
---|
263 | continue; |
---|
264 | } |
---|
265 | if (y == (yFaulty - 1)) { |
---|
266 | dspinRouter[x][y]->bind_recovery_port(sConfigS); |
---|
267 | std::cout << "config S" << std::endl; |
---|
268 | continue; |
---|
269 | } |
---|
270 | } |
---|
271 | if (x == (xFaulty - 1)) { |
---|
272 | if (y == (yFaulty + 1)) { |
---|
273 | dspinRouter[x][y]->bind_recovery_port(sConfigNW); |
---|
274 | std::cout << "config NW" << std::endl; |
---|
275 | continue; |
---|
276 | } |
---|
277 | if (y == yFaulty) { |
---|
278 | dspinRouter[x][y]->bind_recovery_port(sConfigW); |
---|
279 | std::cout << "config W" << std::endl; |
---|
280 | continue; |
---|
281 | } |
---|
282 | if (y == (yFaulty - 1)) { |
---|
283 | dspinRouter[x][y]->bind_recovery_port(sConfigSW); |
---|
284 | std::cout << "config SW" << std::endl; |
---|
285 | continue; |
---|
286 | } |
---|
287 | } |
---|
288 | dspinRouter[x][y]->bind_recovery_port(sConfigNONE); |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | srandom(3); |
---|
293 | sc_start(sc_core::SC_ZERO_TIME); |
---|
294 | signal_resetn = 0; |
---|
295 | |
---|
296 | /* initialize the configuration signals */ |
---|
297 | sConfigNONE.write(configRouter(0, REQ_NOP, BH_NONE)); |
---|
298 | sConfigN.write(configRouter(1, REQ_SOUTH, BH_N)); |
---|
299 | sConfigNE.write(configRouter(1, REQ_WEST, BH_NE)); |
---|
300 | sConfigE.write(configRouter(1, REQ_WEST, BH_E)); |
---|
301 | sConfigSE.write(configRouter(1, REQ_WEST, BH_SE)); |
---|
302 | sConfigS.write(configRouter(1, REQ_NORTH, BH_S)); |
---|
303 | sConfigSW.write(configRouter(1, REQ_EAST, BH_SW)); |
---|
304 | sConfigW.write(configRouter(1, REQ_EAST, BH_W)); |
---|
305 | sConfigNW.write(configRouter(1, REQ_EAST, BH_NW)); |
---|
306 | |
---|
307 | /* initialize mesh boundary signals */ |
---|
308 | for (int x = 0; x < xSize; ++x) { |
---|
309 | sDspinV[x][0][0].write = false; |
---|
310 | sDspinV[x][0][1].read = true; |
---|
311 | sDspinV[x][ySize][0].read = true; |
---|
312 | sDspinV[x][ySize][1].write = false; |
---|
313 | } |
---|
314 | for (int y = 0; y < ySize; ++y) { |
---|
315 | sDspinH[0][y][0].write = false; |
---|
316 | sDspinH[0][y][1].read = true; |
---|
317 | sDspinH[xSize][y][0].read = true; |
---|
318 | sDspinH[xSize][y][1].write = false; |
---|
319 | } |
---|
320 | |
---|
321 | sc_start(sc_core::sc_time(5, SC_NS)); |
---|
322 | signal_resetn = 1; |
---|
323 | |
---|
324 | size_t n; |
---|
325 | if (debug) { |
---|
326 | for(n = 0; n < simCycles; ++n) { |
---|
327 | std::cout << std::endl; |
---|
328 | std::cout << "##########################################" << std::endl; |
---|
329 | std::cout << "Simulation cycle " << n << std::endl; |
---|
330 | std::cout << "##########################################" << std::endl; |
---|
331 | std::cout << std::endl; |
---|
332 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
333 | for (int x = 0; x < xSize; ++x) { |
---|
334 | for (int y = 0; y < ySize; ++y) { |
---|
335 | dspinRouter[x][y]->print_trace(); |
---|
336 | dspinGenerator[x][y]->print_trace(); |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | } else { |
---|
341 | if (simCycles > 0) { |
---|
342 | sc_start(sc_core::sc_time(simCycles, SC_NS)); |
---|
343 | } |
---|
344 | else { |
---|
345 | const int period = 3000; |
---|
346 | for (n = 0; n < (max * 200); n += period) { |
---|
347 | if ((xSrc == -1) || (ySrc == -1)) { |
---|
348 | std::cout << "When using a packet limit, there must be one "; |
---|
349 | std::cout << "source only" << std::endl; |
---|
350 | std::exit(1); |
---|
351 | } |
---|
352 | |
---|
353 | sc_start(sc_core::sc_time(period, SC_NS)); |
---|
354 | |
---|
355 | uint32_t pkts = dspinGenerator[xSrc][ySrc]->get_sent_packets(); |
---|
356 | if (pkts >= max) break; |
---|
357 | } |
---|
358 | sc_start(sc_core::sc_time(period, SC_NS)); |
---|
359 | std::cout << "Simulated cycles: " << n + period << std::endl; |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | for (int x = 0; x < xSize; ++x) { |
---|
364 | for (int y = 0; y < ySize; ++y) { |
---|
365 | dspinGenerator[x][y]->print_stats(); |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | return 0; |
---|
370 | } |
---|
371 | |
---|
372 | /* |
---|
373 | * vim: ts=4 : sw=4 : sts=4 : et |
---|
374 | */ |
---|