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 | |
---|
12 | #include "dspin_router.h" |
---|
13 | #include "dspin_router_config.h" |
---|
14 | #include "dspin_packet_generator.h" |
---|
15 | #include "alloc_elems.h" |
---|
16 | |
---|
17 | #if _OPENMP |
---|
18 | #include <omp.h> |
---|
19 | #endif |
---|
20 | |
---|
21 | /* |
---|
22 | * Platform constant parameters |
---|
23 | */ |
---|
24 | #define X_WIDTH 4 |
---|
25 | #define Y_WIDTH 4 |
---|
26 | |
---|
27 | #define FIFO_DEPTH 8 |
---|
28 | #define NFLITS 2 |
---|
29 | #define LOAD 1000 |
---|
30 | #define BROADCAST_PERIOD 3 |
---|
31 | #define DSPIN_WIDTH 39 |
---|
32 | |
---|
33 | /* |
---|
34 | * Platform default values |
---|
35 | */ |
---|
36 | #define X_SIZE 4 |
---|
37 | #define Y_SIZE 4 |
---|
38 | |
---|
39 | static inline int cluster(int x, int y) |
---|
40 | { |
---|
41 | return (x << Y_WIDTH) | y; |
---|
42 | } |
---|
43 | |
---|
44 | static inline uint32_t configRouter(int bypass_mode, |
---|
45 | int reallocation_dir, |
---|
46 | int blackhole_pos) |
---|
47 | { |
---|
48 | return (bypass_mode << 7) | (reallocation_dir << 4) | blackhole_pos; |
---|
49 | } |
---|
50 | |
---|
51 | int sc_main(int argc, char **argv) |
---|
52 | { |
---|
53 | using namespace soclib::caba; |
---|
54 | using namespace soclib::common; |
---|
55 | |
---|
56 | typedef DspinPacketGenerator<DSPIN_WIDTH, DSPIN_WIDTH> |
---|
57 | DspinGeneratorType; |
---|
58 | typedef DspinRouter<DSPIN_WIDTH> |
---|
59 | DspinRouterType; |
---|
60 | typedef DspinSignals<DSPIN_WIDTH> |
---|
61 | DspinSignalType; |
---|
62 | |
---|
63 | #if _OPENMP |
---|
64 | omp_set_dynamic(false); |
---|
65 | omp_set_num_threads(1); |
---|
66 | #endif |
---|
67 | |
---|
68 | /* mesh size */ |
---|
69 | int xSize = X_SIZE; |
---|
70 | int ySize = Y_SIZE; |
---|
71 | |
---|
72 | /* (x,y) coordinates of the initiator router */ |
---|
73 | int xSrc = -1; |
---|
74 | int ySrc = -1; |
---|
75 | |
---|
76 | /* (x,y) coordinates of the faulty router */ |
---|
77 | int xFaulty = -1; |
---|
78 | int yFaulty = -1; |
---|
79 | |
---|
80 | /* enable the DSPIN router's debug */ |
---|
81 | int debug = false; |
---|
82 | |
---|
83 | /* number of simulation cycles */ |
---|
84 | int simCycles = 100000; |
---|
85 | for (int n = 1; n < argc; n = n + 2) { |
---|
86 | if ((strcmp(argv[n], "-X") == 0) && ((n + 1) < argc)) { |
---|
87 | xSize = strtol(argv[n + 1], NULL, 0); |
---|
88 | continue; |
---|
89 | } |
---|
90 | if ((strcmp(argv[n], "-Y") == 0) && ((n + 1) < argc) ) { |
---|
91 | ySize = strtol(argv[n + 1], NULL, 0); |
---|
92 | continue; |
---|
93 | } |
---|
94 | if ((strcmp(argv[n], "-FX") == 0) && ((n + 1) < argc)) { |
---|
95 | xFaulty = strtol(argv[n + 1], NULL, 0); |
---|
96 | continue; |
---|
97 | } |
---|
98 | if ((strcmp(argv[n], "-FY") == 0) && ((n + 1) < argc) ) { |
---|
99 | yFaulty = strtol(argv[n + 1], NULL, 0); |
---|
100 | continue; |
---|
101 | } |
---|
102 | if ((strcmp(argv[n], "-SX") == 0) && ((n + 1) < argc)) { |
---|
103 | xSrc = strtol(argv[n + 1], NULL, 0); |
---|
104 | continue; |
---|
105 | } |
---|
106 | if ((strcmp(argv[n], "-SY") == 0) && ((n + 1) < argc) ) { |
---|
107 | ySrc = strtol(argv[n + 1], NULL, 0); |
---|
108 | continue; |
---|
109 | } |
---|
110 | if ((strcmp(argv[n], "-N") == 0) && ((n + 1) < argc) ) { |
---|
111 | simCycles = strtol(argv[n + 1], NULL, 0); |
---|
112 | assert(simCycles > 0); |
---|
113 | continue; |
---|
114 | } |
---|
115 | if ((strcmp(argv[n], "-DEBUG") == 0)) { |
---|
116 | debug = true; |
---|
117 | continue; |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | assert (xFaulty < xSize ); |
---|
122 | assert (yFaulty < ySize ); |
---|
123 | assert (xSrc < xSize ); |
---|
124 | assert (ySrc < ySize ); |
---|
125 | |
---|
126 | DspinGeneratorType ***dspinGenerator = new DspinGeneratorType**[xSize]; |
---|
127 | DspinRouterType ***dspinRouter = new DspinRouterType**[xSize]; |
---|
128 | for (int x = 0; x < xSize; ++x) { |
---|
129 | dspinGenerator[x] = new DspinGeneratorType*[ySize]; |
---|
130 | dspinRouter[x] = new DspinRouterType*[ySize]; |
---|
131 | for (int y = 0; y < ySize; ++y) { |
---|
132 | const bool BROADCAST_SUPPORTED = true; |
---|
133 | const bool CONFIGURATION_SUPPORTED = true; |
---|
134 | std::ostringstream routerStr; |
---|
135 | routerStr << "dspinRouter["<< x << "][" << y << "]"; |
---|
136 | dspinRouter[x][y] = |
---|
137 | new DspinRouterType(routerStr.str().c_str(), x, y, |
---|
138 | X_WIDTH, Y_WIDTH, |
---|
139 | FIFO_DEPTH, FIFO_DEPTH, |
---|
140 | BROADCAST_SUPPORTED, |
---|
141 | CONFIGURATION_SUPPORTED); |
---|
142 | |
---|
143 | if ((x == xFaulty) && (y == yFaulty)) { |
---|
144 | dspinRouter[x][y]->set_disable_mask(0x1F); |
---|
145 | } |
---|
146 | |
---|
147 | int broadcast_period = 0; |
---|
148 | int load = 0; |
---|
149 | const int SRCID = cluster(x,y); |
---|
150 | bool all = (xSrc == -1) && (ySrc == -1); |
---|
151 | if (all || (cluster(x,y) == cluster(xSrc,ySrc))) { |
---|
152 | broadcast_period = BROADCAST_PERIOD; |
---|
153 | load = LOAD; |
---|
154 | } |
---|
155 | std::ostringstream generatorStr; |
---|
156 | generatorStr << "dspinGenerator["<< x << "][" << y << "]"; |
---|
157 | dspinGenerator[x][y] = |
---|
158 | new DspinGeneratorType(generatorStr.str().c_str(), |
---|
159 | SRCID, NFLITS, |
---|
160 | load, FIFO_DEPTH, |
---|
161 | broadcast_period); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | const int H = xSize - 1; |
---|
166 | const int Y = ySize - 1; |
---|
167 | sc_clock signal_clk("clk"); |
---|
168 | sc_core::sc_signal<bool> signal_resetn("signal_resetn"); |
---|
169 | DspinSignalType*** sDspinL = |
---|
170 | alloc_elems<DspinSignalType>("sDspinL", xSize, ySize, 2); |
---|
171 | DspinSignalType*** sDspinH = |
---|
172 | alloc_elems<DspinSignalType>("sDspinH", H + 2, ySize, 2); |
---|
173 | DspinSignalType*** sDspinV = |
---|
174 | alloc_elems<DspinSignalType>("sDspinV", xSize, Y + 2, 2); |
---|
175 | sc_signal<uint32_t> sConfigNONE("sConfigNONE"); |
---|
176 | sc_signal<uint32_t> sConfigN("sConfigN"); |
---|
177 | sc_signal<uint32_t> sConfigNW("sConfigNW"); |
---|
178 | sc_signal<uint32_t> sConfigNE("sConfigNE"); |
---|
179 | sc_signal<uint32_t> sConfigS("sConfigS"); |
---|
180 | sc_signal<uint32_t> sConfigSW("sConfigSW"); |
---|
181 | sc_signal<uint32_t> sConfigSE("sConfigSE"); |
---|
182 | sc_signal<uint32_t> sConfigW("sConfigW"); |
---|
183 | sc_signal<uint32_t> sConfigE("sConfigE"); |
---|
184 | for (int x = 0; x < xSize; ++x) { |
---|
185 | for (int y = 0; y < ySize; ++y) { |
---|
186 | dspinGenerator[x][y]->p_clk(signal_clk); |
---|
187 | dspinGenerator[x][y]->p_resetn(signal_resetn); |
---|
188 | dspinGenerator[x][y]->p_out(sDspinL[x][y][0]); |
---|
189 | dspinGenerator[x][y]->p_in(sDspinL[x][y][1]); |
---|
190 | |
---|
191 | dspinRouter[x][y]->p_clk(signal_clk); |
---|
192 | dspinRouter[x][y]->p_resetn(signal_resetn); |
---|
193 | dspinRouter[x][y]->p_in[0](sDspinV[x][y + 1][1]); |
---|
194 | dspinRouter[x][y]->p_out[0](sDspinV[x][y + 1][0]); |
---|
195 | dspinRouter[x][y]->p_in[1](sDspinV[x][y][0]); |
---|
196 | dspinRouter[x][y]->p_out[1](sDspinV[x][y][1]); |
---|
197 | dspinRouter[x][y]->p_in[2](sDspinH[x + 1][y][1]); |
---|
198 | dspinRouter[x][y]->p_out[2](sDspinH[x + 1][y][0]); |
---|
199 | dspinRouter[x][y]->p_in[3](sDspinH[x][y][0]); |
---|
200 | dspinRouter[x][y]->p_out[3](sDspinH[x][y][1]); |
---|
201 | dspinRouter[x][y]->p_in[4](sDspinL[x][y][0]); |
---|
202 | dspinRouter[x][y]->p_out[4](sDspinL[x][y][1]); |
---|
203 | |
---|
204 | if (x == (xFaulty + 1)) { |
---|
205 | if (y == (yFaulty + 1)) { |
---|
206 | dspinRouter[x][y]->bind_recovery_port(sConfigNE); |
---|
207 | std::cout << "config NE" << std::endl; |
---|
208 | continue; |
---|
209 | } |
---|
210 | if (y == yFaulty) { |
---|
211 | dspinRouter[x][y]->bind_recovery_port(sConfigE); |
---|
212 | std::cout << "config E" << std::endl; |
---|
213 | continue; |
---|
214 | } |
---|
215 | if (y == (yFaulty - 1)) { |
---|
216 | dspinRouter[x][y]->bind_recovery_port(sConfigSE); |
---|
217 | std::cout << "config SE" << std::endl; |
---|
218 | continue; |
---|
219 | } |
---|
220 | } |
---|
221 | if (x == xFaulty) { |
---|
222 | if (y == (yFaulty + 1)) { |
---|
223 | dspinRouter[x][y]->bind_recovery_port(sConfigN); |
---|
224 | std::cout << "config N" << std::endl; |
---|
225 | continue; |
---|
226 | } |
---|
227 | if (y == (yFaulty - 1)) { |
---|
228 | dspinRouter[x][y]->bind_recovery_port(sConfigS); |
---|
229 | std::cout << "config S" << std::endl; |
---|
230 | continue; |
---|
231 | } |
---|
232 | } |
---|
233 | if (x == (xFaulty - 1)) { |
---|
234 | if (y == (yFaulty + 1)) { |
---|
235 | dspinRouter[x][y]->bind_recovery_port(sConfigNW); |
---|
236 | std::cout << "config NW" << std::endl; |
---|
237 | continue; |
---|
238 | } |
---|
239 | if (y == yFaulty) { |
---|
240 | dspinRouter[x][y]->bind_recovery_port(sConfigW); |
---|
241 | std::cout << "config W" << std::endl; |
---|
242 | continue; |
---|
243 | } |
---|
244 | if (y == (yFaulty - 1)) { |
---|
245 | dspinRouter[x][y]->bind_recovery_port(sConfigSW); |
---|
246 | std::cout << "config SW" << std::endl; |
---|
247 | continue; |
---|
248 | } |
---|
249 | } |
---|
250 | dspinRouter[x][y]->bind_recovery_port(sConfigNONE); |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | sc_start(sc_core::SC_ZERO_TIME); |
---|
255 | signal_resetn = 0; |
---|
256 | |
---|
257 | /* initialize the configuration signals */ |
---|
258 | sConfigNONE.write(configRouter(0, REQ_NOP, BH_NONE)); |
---|
259 | sConfigN.write(configRouter(1, REQ_SOUTH, BH_N)); |
---|
260 | sConfigNE.write(configRouter(1, REQ_WEST, BH_NE)); |
---|
261 | sConfigE.write(configRouter(1, REQ_WEST, BH_E)); |
---|
262 | sConfigSE.write(configRouter(1, REQ_WEST, BH_SE)); |
---|
263 | sConfigS.write(configRouter(1, REQ_NORTH, BH_S)); |
---|
264 | sConfigSW.write(configRouter(1, REQ_EAST, BH_SW)); |
---|
265 | sConfigW.write(configRouter(1, REQ_EAST, BH_W)); |
---|
266 | sConfigNW.write(configRouter(1, REQ_EAST, BH_NW)); |
---|
267 | |
---|
268 | /* initialize mesh boundary signals */ |
---|
269 | for (int x = 0; x < xSize; ++x) { |
---|
270 | sDspinV[x][0][0].write = false; |
---|
271 | sDspinV[x][0][1].read = true; |
---|
272 | sDspinV[x][ySize][0].read = true; |
---|
273 | sDspinV[x][ySize][1].write = false; |
---|
274 | } |
---|
275 | for (int y = 0; y < ySize; ++y) { |
---|
276 | sDspinH[0][y][0].write = false; |
---|
277 | sDspinH[0][y][1].read = true; |
---|
278 | sDspinH[xSize][y][0].read = true; |
---|
279 | sDspinH[xSize][y][1].write = false; |
---|
280 | } |
---|
281 | |
---|
282 | sc_start(sc_core::sc_time(5, SC_NS)); |
---|
283 | signal_resetn = 1; |
---|
284 | |
---|
285 | for(int i = 0; i < simCycles; ++i) { |
---|
286 | if (!debug) { |
---|
287 | sc_start(sc_core::sc_time(simCycles, SC_NS)); |
---|
288 | break; |
---|
289 | } |
---|
290 | std::cout << std::endl; |
---|
291 | std::cout << "##########################################" << std::endl; |
---|
292 | std::cout << "Simulation cycle " << i << std::endl; |
---|
293 | std::cout << "##########################################" << std::endl; |
---|
294 | std::cout << std::endl; |
---|
295 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
296 | for (int x = 0; x < xSize; ++x) { |
---|
297 | for (int y = 0; y < ySize; ++y) { |
---|
298 | dspinRouter[x][y]->print_trace(); |
---|
299 | } |
---|
300 | } |
---|
301 | } |
---|
302 | for (int x = 0; x < xSize; ++x) { |
---|
303 | for (int y = 0; y < ySize; ++y) { |
---|
304 | dspinGenerator[x][y]->print_stats(); |
---|
305 | } |
---|
306 | } |
---|
307 | |
---|
308 | return 0; |
---|
309 | } |
---|
310 | |
---|
311 | /* |
---|
312 | * vim: ts=4 : sw=4 : sts=4 : et |
---|
313 | */ |
---|