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