[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> |
---|
| 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; |
---|
[996] | 85 | |
---|
| 86 | /* synthetic generator load */ |
---|
| 87 | int load = LOAD; |
---|
| 88 | |
---|
| 89 | for (int n = 1; n < argc; n += 2) { |
---|
[994] | 90 | if ((strcmp(argv[n], "-X") == 0) && ((n + 1) < argc)) { |
---|
| 91 | xSize = strtol(argv[n + 1], NULL, 0); |
---|
| 92 | continue; |
---|
| 93 | } |
---|
| 94 | if ((strcmp(argv[n], "-Y") == 0) && ((n + 1) < argc) ) { |
---|
| 95 | ySize = strtol(argv[n + 1], NULL, 0); |
---|
| 96 | continue; |
---|
| 97 | } |
---|
| 98 | if ((strcmp(argv[n], "-FX") == 0) && ((n + 1) < argc)) { |
---|
| 99 | xFaulty = strtol(argv[n + 1], NULL, 0); |
---|
| 100 | continue; |
---|
| 101 | } |
---|
| 102 | if ((strcmp(argv[n], "-FY") == 0) && ((n + 1) < argc) ) { |
---|
| 103 | yFaulty = strtol(argv[n + 1], NULL, 0); |
---|
| 104 | continue; |
---|
| 105 | } |
---|
| 106 | if ((strcmp(argv[n], "-SX") == 0) && ((n + 1) < argc)) { |
---|
| 107 | xSrc = strtol(argv[n + 1], NULL, 0); |
---|
| 108 | continue; |
---|
| 109 | } |
---|
| 110 | if ((strcmp(argv[n], "-SY") == 0) && ((n + 1) < argc) ) { |
---|
| 111 | ySrc = strtol(argv[n + 1], NULL, 0); |
---|
| 112 | continue; |
---|
| 113 | } |
---|
| 114 | if ((strcmp(argv[n], "-N") == 0) && ((n + 1) < argc) ) { |
---|
| 115 | simCycles = strtol(argv[n + 1], NULL, 0); |
---|
| 116 | assert(simCycles > 0); |
---|
| 117 | continue; |
---|
| 118 | } |
---|
[996] | 119 | if ((strcmp(argv[n], "-L") == 0) && ((n + 1) < argc) ) { |
---|
| 120 | load = strtol(argv[n + 1], NULL, 0); |
---|
| 121 | assert(load > 0); |
---|
| 122 | continue; |
---|
| 123 | } |
---|
| 124 | if ((strcmp(argv[n--], "-DEBUG") == 0)) { |
---|
[994] | 125 | debug = true; |
---|
| 126 | continue; |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | assert (xFaulty < xSize ); |
---|
| 131 | assert (yFaulty < ySize ); |
---|
| 132 | assert (xSrc < xSize ); |
---|
| 133 | assert (ySrc < ySize ); |
---|
| 134 | |
---|
| 135 | DspinGeneratorType ***dspinGenerator = new DspinGeneratorType**[xSize]; |
---|
| 136 | DspinRouterType ***dspinRouter = new DspinRouterType**[xSize]; |
---|
| 137 | for (int x = 0; x < xSize; ++x) { |
---|
| 138 | dspinGenerator[x] = new DspinGeneratorType*[ySize]; |
---|
| 139 | dspinRouter[x] = new DspinRouterType*[ySize]; |
---|
| 140 | for (int y = 0; y < ySize; ++y) { |
---|
| 141 | const bool BROADCAST_SUPPORTED = true; |
---|
| 142 | const bool CONFIGURATION_SUPPORTED = true; |
---|
| 143 | std::ostringstream routerStr; |
---|
| 144 | routerStr << "dspinRouter["<< x << "][" << y << "]"; |
---|
| 145 | dspinRouter[x][y] = |
---|
| 146 | new DspinRouterType(routerStr.str().c_str(), x, y, |
---|
| 147 | X_WIDTH, Y_WIDTH, |
---|
| 148 | FIFO_DEPTH, FIFO_DEPTH, |
---|
| 149 | BROADCAST_SUPPORTED, |
---|
| 150 | CONFIGURATION_SUPPORTED); |
---|
| 151 | |
---|
| 152 | if ((x == xFaulty) && (y == yFaulty)) { |
---|
| 153 | dspinRouter[x][y]->set_disable_mask(0x1F); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | int broadcast_period = 0; |
---|
[996] | 157 | int ld = 0; |
---|
[994] | 158 | const int SRCID = cluster(x,y); |
---|
[996] | 159 | bool all = (xSrc == -1) || (ySrc == -1); |
---|
[994] | 160 | if (all || (cluster(x,y) == cluster(xSrc,ySrc))) { |
---|
| 161 | broadcast_period = BROADCAST_PERIOD; |
---|
[996] | 162 | ld = load; |
---|
[994] | 163 | } |
---|
| 164 | std::ostringstream generatorStr; |
---|
| 165 | generatorStr << "dspinGenerator["<< x << "][" << y << "]"; |
---|
| 166 | dspinGenerator[x][y] = |
---|
| 167 | new DspinGeneratorType(generatorStr.str().c_str(), |
---|
| 168 | SRCID, NFLITS, |
---|
[996] | 169 | ld, FIFO_DEPTH, |
---|
[994] | 170 | broadcast_period); |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | const int H = xSize - 1; |
---|
| 175 | const int Y = ySize - 1; |
---|
| 176 | sc_clock signal_clk("clk"); |
---|
| 177 | sc_core::sc_signal<bool> signal_resetn("signal_resetn"); |
---|
| 178 | DspinSignalType*** sDspinL = |
---|
| 179 | alloc_elems<DspinSignalType>("sDspinL", xSize, ySize, 2); |
---|
| 180 | DspinSignalType*** sDspinH = |
---|
| 181 | alloc_elems<DspinSignalType>("sDspinH", H + 2, ySize, 2); |
---|
| 182 | DspinSignalType*** sDspinV = |
---|
| 183 | alloc_elems<DspinSignalType>("sDspinV", xSize, Y + 2, 2); |
---|
| 184 | sc_signal<uint32_t> sConfigNONE("sConfigNONE"); |
---|
| 185 | sc_signal<uint32_t> sConfigN("sConfigN"); |
---|
| 186 | sc_signal<uint32_t> sConfigNW("sConfigNW"); |
---|
| 187 | sc_signal<uint32_t> sConfigNE("sConfigNE"); |
---|
| 188 | sc_signal<uint32_t> sConfigS("sConfigS"); |
---|
| 189 | sc_signal<uint32_t> sConfigSW("sConfigSW"); |
---|
| 190 | sc_signal<uint32_t> sConfigSE("sConfigSE"); |
---|
| 191 | sc_signal<uint32_t> sConfigW("sConfigW"); |
---|
| 192 | sc_signal<uint32_t> sConfigE("sConfigE"); |
---|
| 193 | for (int x = 0; x < xSize; ++x) { |
---|
| 194 | for (int y = 0; y < ySize; ++y) { |
---|
| 195 | dspinGenerator[x][y]->p_clk(signal_clk); |
---|
| 196 | dspinGenerator[x][y]->p_resetn(signal_resetn); |
---|
| 197 | dspinGenerator[x][y]->p_out(sDspinL[x][y][0]); |
---|
| 198 | dspinGenerator[x][y]->p_in(sDspinL[x][y][1]); |
---|
| 199 | |
---|
| 200 | dspinRouter[x][y]->p_clk(signal_clk); |
---|
| 201 | dspinRouter[x][y]->p_resetn(signal_resetn); |
---|
| 202 | dspinRouter[x][y]->p_in[0](sDspinV[x][y + 1][1]); |
---|
| 203 | dspinRouter[x][y]->p_out[0](sDspinV[x][y + 1][0]); |
---|
| 204 | dspinRouter[x][y]->p_in[1](sDspinV[x][y][0]); |
---|
| 205 | dspinRouter[x][y]->p_out[1](sDspinV[x][y][1]); |
---|
| 206 | dspinRouter[x][y]->p_in[2](sDspinH[x + 1][y][1]); |
---|
| 207 | dspinRouter[x][y]->p_out[2](sDspinH[x + 1][y][0]); |
---|
| 208 | dspinRouter[x][y]->p_in[3](sDspinH[x][y][0]); |
---|
| 209 | dspinRouter[x][y]->p_out[3](sDspinH[x][y][1]); |
---|
| 210 | dspinRouter[x][y]->p_in[4](sDspinL[x][y][0]); |
---|
| 211 | dspinRouter[x][y]->p_out[4](sDspinL[x][y][1]); |
---|
| 212 | |
---|
[996] | 213 | if ((xFaulty < 0) || (yFaulty < 0)) { |
---|
| 214 | dspinRouter[x][y]->bind_recovery_port(sConfigNONE); |
---|
| 215 | continue; |
---|
| 216 | } |
---|
| 217 | |
---|
[994] | 218 | if (x == (xFaulty + 1)) { |
---|
| 219 | if (y == (yFaulty + 1)) { |
---|
| 220 | dspinRouter[x][y]->bind_recovery_port(sConfigNE); |
---|
| 221 | std::cout << "config NE" << std::endl; |
---|
| 222 | continue; |
---|
| 223 | } |
---|
| 224 | if (y == yFaulty) { |
---|
| 225 | dspinRouter[x][y]->bind_recovery_port(sConfigE); |
---|
| 226 | std::cout << "config E" << std::endl; |
---|
| 227 | continue; |
---|
| 228 | } |
---|
| 229 | if (y == (yFaulty - 1)) { |
---|
| 230 | dspinRouter[x][y]->bind_recovery_port(sConfigSE); |
---|
| 231 | std::cout << "config SE" << std::endl; |
---|
| 232 | continue; |
---|
| 233 | } |
---|
| 234 | } |
---|
| 235 | if (x == xFaulty) { |
---|
| 236 | if (y == (yFaulty + 1)) { |
---|
| 237 | dspinRouter[x][y]->bind_recovery_port(sConfigN); |
---|
| 238 | std::cout << "config N" << std::endl; |
---|
| 239 | continue; |
---|
| 240 | } |
---|
| 241 | if (y == (yFaulty - 1)) { |
---|
| 242 | dspinRouter[x][y]->bind_recovery_port(sConfigS); |
---|
| 243 | std::cout << "config S" << std::endl; |
---|
| 244 | continue; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | if (x == (xFaulty - 1)) { |
---|
| 248 | if (y == (yFaulty + 1)) { |
---|
| 249 | dspinRouter[x][y]->bind_recovery_port(sConfigNW); |
---|
| 250 | std::cout << "config NW" << std::endl; |
---|
| 251 | continue; |
---|
| 252 | } |
---|
| 253 | if (y == yFaulty) { |
---|
| 254 | dspinRouter[x][y]->bind_recovery_port(sConfigW); |
---|
| 255 | std::cout << "config W" << std::endl; |
---|
| 256 | continue; |
---|
| 257 | } |
---|
| 258 | if (y == (yFaulty - 1)) { |
---|
| 259 | dspinRouter[x][y]->bind_recovery_port(sConfigSW); |
---|
| 260 | std::cout << "config SW" << std::endl; |
---|
| 261 | continue; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | dspinRouter[x][y]->bind_recovery_port(sConfigNONE); |
---|
| 265 | } |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | sc_start(sc_core::SC_ZERO_TIME); |
---|
| 269 | signal_resetn = 0; |
---|
| 270 | |
---|
| 271 | /* initialize the configuration signals */ |
---|
| 272 | sConfigNONE.write(configRouter(0, REQ_NOP, BH_NONE)); |
---|
| 273 | sConfigN.write(configRouter(1, REQ_SOUTH, BH_N)); |
---|
| 274 | sConfigNE.write(configRouter(1, REQ_WEST, BH_NE)); |
---|
| 275 | sConfigE.write(configRouter(1, REQ_WEST, BH_E)); |
---|
| 276 | sConfigSE.write(configRouter(1, REQ_WEST, BH_SE)); |
---|
| 277 | sConfigS.write(configRouter(1, REQ_NORTH, BH_S)); |
---|
| 278 | sConfigSW.write(configRouter(1, REQ_EAST, BH_SW)); |
---|
| 279 | sConfigW.write(configRouter(1, REQ_EAST, BH_W)); |
---|
| 280 | sConfigNW.write(configRouter(1, REQ_EAST, BH_NW)); |
---|
| 281 | |
---|
| 282 | /* initialize mesh boundary signals */ |
---|
| 283 | for (int x = 0; x < xSize; ++x) { |
---|
| 284 | sDspinV[x][0][0].write = false; |
---|
| 285 | sDspinV[x][0][1].read = true; |
---|
| 286 | sDspinV[x][ySize][0].read = true; |
---|
| 287 | sDspinV[x][ySize][1].write = false; |
---|
| 288 | } |
---|
| 289 | for (int y = 0; y < ySize; ++y) { |
---|
| 290 | sDspinH[0][y][0].write = false; |
---|
| 291 | sDspinH[0][y][1].read = true; |
---|
| 292 | sDspinH[xSize][y][0].read = true; |
---|
| 293 | sDspinH[xSize][y][1].write = false; |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | sc_start(sc_core::sc_time(5, SC_NS)); |
---|
| 297 | signal_resetn = 1; |
---|
| 298 | |
---|
| 299 | for(int i = 0; i < simCycles; ++i) { |
---|
| 300 | if (!debug) { |
---|
| 301 | sc_start(sc_core::sc_time(simCycles, SC_NS)); |
---|
| 302 | break; |
---|
| 303 | } |
---|
| 304 | std::cout << std::endl; |
---|
| 305 | std::cout << "##########################################" << std::endl; |
---|
| 306 | std::cout << "Simulation cycle " << i << std::endl; |
---|
| 307 | std::cout << "##########################################" << std::endl; |
---|
| 308 | std::cout << std::endl; |
---|
| 309 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
| 310 | for (int x = 0; x < xSize; ++x) { |
---|
| 311 | for (int y = 0; y < ySize; ++y) { |
---|
| 312 | dspinRouter[x][y]->print_trace(); |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | for (int x = 0; x < xSize; ++x) { |
---|
| 317 | for (int y = 0; y < ySize; ++y) { |
---|
| 318 | dspinGenerator[x][y]->print_stats(); |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | return 0; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | /* |
---|
| 326 | * vim: ts=4 : sw=4 : sts=4 : et |
---|
| 327 | */ |
---|