[226] | 1 | ///////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File: tsarv1_mono_ring_top.cpp |
---|
| 3 | // Author: Cesar Fuguet / Abdelmalek Simerabe |
---|
| 4 | // Copyright: UPMC/LIP6 |
---|
| 5 | // Date : 2012 |
---|
| 6 | // |
---|
| 7 | // This program is released under the GNU public license |
---|
| 8 | ///////////////////////////////////////////////////////////////////////// |
---|
| 9 | |
---|
| 10 | #include <systemc> |
---|
| 11 | #include <sys/time.h> |
---|
| 12 | #include <iostream> |
---|
| 13 | #include <sstream> |
---|
| 14 | #include <cstdlib> |
---|
| 15 | #include <cstdarg> |
---|
| 16 | |
---|
| 17 | #include "tsar_cluster_v1.h" |
---|
| 18 | #include "mapping_table.h" |
---|
| 19 | #include "vci_simple_ring_fast.h" |
---|
| 20 | #include "vci_simple_ram.h" |
---|
| 21 | #include "segmentation.h" |
---|
| 22 | |
---|
| 23 | /////////////////////////////////// |
---|
| 24 | // flit widths for the ring network |
---|
| 25 | |
---|
| 26 | #define cmd_width 40 |
---|
| 27 | #define rsp_width 33 |
---|
| 28 | |
---|
| 29 | ////////////////// |
---|
| 30 | // VCI format |
---|
| 31 | |
---|
| 32 | #define cell_width 4 |
---|
| 33 | #define address_width 32 |
---|
| 34 | #define plen_width 8 |
---|
| 35 | #define error_width 1 |
---|
| 36 | #define clen_width 1 |
---|
| 37 | #define rflag_width 1 |
---|
| 38 | #define srcid_width 5 |
---|
| 39 | #define pktid_width 4 |
---|
| 40 | #define trdid_width 4 |
---|
| 41 | #define wrplen_width 1 |
---|
| 42 | |
---|
| 43 | ///////////////////////////////// |
---|
| 44 | int _main(int argc, char *argv[]) |
---|
| 45 | { |
---|
| 46 | using namespace sc_core; |
---|
| 47 | using namespace soclib::caba; |
---|
| 48 | using namespace soclib::common; |
---|
| 49 | |
---|
| 50 | char soft_name[128] = "undefined_binary_file"; // pathname to binary code |
---|
| 51 | size_t ncycles = 200000; // simulated cycles |
---|
| 52 | size_t xmax = 1; // number of clusters in a row |
---|
| 53 | size_t ymax = 1; // number of clusters in a column |
---|
| 54 | size_t nprocs = 1; // number of processors per cluster |
---|
| 55 | bool debug_ok = false; // debug activated |
---|
| 56 | size_t from_cycle = 0; // debug start cycle |
---|
| 57 | size_t to_cycle = 200000; // debug end cycle |
---|
| 58 | |
---|
| 59 | ////////////// command line arguments ////////////////////// |
---|
| 60 | if (argc > 1) |
---|
| 61 | { |
---|
| 62 | for( int n=1 ; n<argc ; n=n+2 ) |
---|
| 63 | { |
---|
| 64 | if( (strcmp(argv[n],"-NCYCLES") == 0) && (n+1<argc) ) |
---|
| 65 | { |
---|
| 66 | ncycles = atoi(argv[n+1]); |
---|
| 67 | } |
---|
| 68 | else if( (strcmp(argv[n],"-NPROCS") == 0) && (n+1<argc) ) |
---|
| 69 | { |
---|
| 70 | nprocs = atoi(argv[n+1]); |
---|
| 71 | assert( (nprocs <= 8) |
---|
| 72 | && "The number of processors per cluster cannot be larger than 8"); |
---|
| 73 | } |
---|
| 74 | else if( (strcmp(argv[n],"-SOFT") == 0) && (n+1<argc) ) |
---|
| 75 | { |
---|
| 76 | strcpy(soft_name, argv[n+1]); |
---|
| 77 | } |
---|
| 78 | else if( (strcmp(argv[n],"-DEBUG") == 0) && (n+1<argc) ) |
---|
| 79 | { |
---|
| 80 | debug_ok = true; |
---|
| 81 | from_cycle = atoi(argv[n+1]); |
---|
| 82 | } |
---|
| 83 | else if( (strcmp(argv[n],"-TOCYCLE") == 0) && (n+1<argc) ) |
---|
| 84 | { |
---|
| 85 | to_cycle = atoi(argv[n+1]); |
---|
| 86 | } |
---|
| 87 | else |
---|
| 88 | { |
---|
| 89 | std::cout << " Arguments on the command line are (key,value) "; |
---|
| 90 | std::cout << "couples." << std::endl; |
---|
| 91 | std::cout << " The order is not important." << std::endl; |
---|
| 92 | std::cout << " Accepted arguments are :" << std::endl << std::endl; |
---|
| 93 | std::cout << " -SOFT elf_file_name" << std::endl; |
---|
| 94 | std::cout << " -NCYCLES number_of_simulated_cycles" << std::endl; |
---|
| 95 | std::cout << " -NPROCS number_of_processors_per_cluster" << std::endl; |
---|
| 96 | std::cout << " -DEBUG debug_start_cycle" << std::endl; |
---|
| 97 | std::cout << " -TOCYCLE debug_end_cycle" << std::endl; |
---|
| 98 | exit(0); |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | std::cout << std::endl << "*********** TSAR ARCHITECTURE **************" << std::endl |
---|
| 104 | << " - Interconnect = DSPIN & RING" << std::endl |
---|
| 105 | << " - Number of clusters = " << xmax << " * " << ymax << std::endl |
---|
| 106 | << " - Number of processors per cluster = " << nprocs << std::endl |
---|
| 107 | << "**********************************************" << std::endl |
---|
| 108 | << std::endl; |
---|
| 109 | |
---|
| 110 | // Define VCI parameters |
---|
| 111 | typedef soclib::caba::VciParams<cell_width, |
---|
| 112 | plen_width, |
---|
| 113 | address_width, |
---|
| 114 | error_width, |
---|
| 115 | clen_width, |
---|
| 116 | rflag_width, |
---|
| 117 | srcid_width, |
---|
| 118 | pktid_width, |
---|
| 119 | trdid_width, |
---|
| 120 | wrplen_width> vci_param; |
---|
| 121 | |
---|
| 122 | size_t x_width = 0; |
---|
| 123 | size_t y_width = 0; |
---|
| 124 | |
---|
| 125 | ///////////////////// |
---|
| 126 | // Mapping Tables |
---|
| 127 | ///////////////////// |
---|
| 128 | |
---|
| 129 | // direct network |
---|
| 130 | MappingTable maptabd(address_width, |
---|
| 131 | IntTab(16 - x_width - y_width), |
---|
| 132 | IntTab(srcid_width - x_width - y_width), |
---|
| 133 | 0x00FF0000); |
---|
| 134 | |
---|
| 135 | maptabd.add( |
---|
| 136 | Segment("d_seg_xicu", |
---|
| 137 | XICU_BASE, |
---|
| 138 | XICU_SIZE, |
---|
| 139 | IntTab(XICU_TGTID), |
---|
| 140 | false |
---|
| 141 | ) |
---|
| 142 | ); |
---|
| 143 | |
---|
| 144 | maptabd.add( |
---|
| 145 | Segment("d_seg_stak", |
---|
| 146 | STAK_BASE, |
---|
| 147 | STAK_SIZE, |
---|
| 148 | IntTab(MEMC_TGTID), |
---|
| 149 | true |
---|
| 150 | ) |
---|
| 151 | ); |
---|
| 152 | |
---|
| 153 | maptabd.add( |
---|
| 154 | Segment("d_seg_mtty", |
---|
| 155 | TTY_BASE, |
---|
| 156 | TTY_SIZE, |
---|
| 157 | IntTab(MTTY_TGTID), |
---|
| 158 | false |
---|
| 159 | ) |
---|
| 160 | ); |
---|
| 161 | |
---|
| 162 | maptabd.add( |
---|
| 163 | Segment("d_seg_reset", |
---|
| 164 | RESET_BASE, |
---|
| 165 | RESET_SIZE, |
---|
| 166 | IntTab(MEMC_TGTID), |
---|
| 167 | true |
---|
| 168 | ) |
---|
| 169 | ); |
---|
| 170 | |
---|
| 171 | maptabd.add( |
---|
| 172 | Segment("d_seg_kcode", |
---|
| 173 | KCODE_BASE, |
---|
| 174 | KCODE_SIZE, |
---|
| 175 | IntTab(MEMC_TGTID), |
---|
| 176 | true |
---|
| 177 | ) |
---|
| 178 | ); |
---|
| 179 | |
---|
| 180 | maptabd.add( |
---|
| 181 | Segment("d_seg_kdata", |
---|
| 182 | KDATA_BASE, |
---|
| 183 | KDATA_SIZE, |
---|
| 184 | IntTab(MEMC_TGTID), |
---|
| 185 | true |
---|
| 186 | ) |
---|
| 187 | ); |
---|
| 188 | |
---|
| 189 | maptabd.add( |
---|
| 190 | Segment("d_seg_kunc", |
---|
| 191 | KUNC_BASE, |
---|
| 192 | KUNC_SIZE, |
---|
| 193 | IntTab(MEMC_TGTID), |
---|
| 194 | false |
---|
| 195 | ) |
---|
| 196 | ); |
---|
| 197 | |
---|
| 198 | maptabd.add( |
---|
| 199 | Segment("d_seg_code", |
---|
| 200 | CODE_BASE, |
---|
| 201 | CODE_SIZE, |
---|
| 202 | IntTab(MEMC_TGTID), |
---|
| 203 | true |
---|
| 204 | ) |
---|
| 205 | ); |
---|
| 206 | |
---|
| 207 | maptabd.add( |
---|
| 208 | Segment("d_seg_data", |
---|
| 209 | DATA_BASE, |
---|
| 210 | DATA_SIZE, |
---|
| 211 | IntTab(MEMC_TGTID), |
---|
| 212 | true |
---|
| 213 | ) |
---|
| 214 | ); |
---|
| 215 | std::cout << maptabd << std::endl; |
---|
| 216 | |
---|
| 217 | // coherence network |
---|
| 218 | MappingTable maptabc(address_width, |
---|
| 219 | IntTab(srcid_width - x_width - y_width), |
---|
| 220 | IntTab(srcid_width - x_width - y_width), |
---|
| 221 | 0xFF000000); |
---|
| 222 | |
---|
| 223 | std::ostringstream sm; |
---|
| 224 | sm << "c_seg_memc_" << 0 << "_" << 0; |
---|
| 225 | maptabc.add( |
---|
| 226 | Segment(sm.str(), |
---|
| 227 | (nprocs << (address_width - srcid_width)), |
---|
| 228 | 0xC, |
---|
| 229 | IntTab(nprocs), |
---|
| 230 | false |
---|
| 231 | ) |
---|
| 232 | ); |
---|
| 233 | |
---|
| 234 | for ( size_t p = 0 ; p < nprocs ; p++) |
---|
| 235 | { |
---|
| 236 | std::ostringstream sp; |
---|
| 237 | sp << "c_seg_proc_" << 0 << "_" << 0 << "_" << p; |
---|
| 238 | maptabc.add( |
---|
| 239 | Segment(sp.str(), |
---|
| 240 | (p << (address_width - srcid_width)), |
---|
| 241 | 0xC, |
---|
| 242 | IntTab(p), |
---|
| 243 | false |
---|
| 244 | ) |
---|
| 245 | ); |
---|
| 246 | } |
---|
| 247 | std::cout << maptabc << std::endl; |
---|
| 248 | |
---|
| 249 | // external network |
---|
| 250 | MappingTable maptabx( |
---|
| 251 | address_width, |
---|
| 252 | IntTab(x_width + y_width), |
---|
| 253 | IntTab(x_width + y_width), |
---|
| 254 | 0x00FF0000 |
---|
| 255 | ); |
---|
| 256 | |
---|
| 257 | maptabx.add( |
---|
| 258 | Segment("x_seg_kcode", |
---|
| 259 | KCODE_BASE, |
---|
| 260 | KCODE_SIZE, |
---|
| 261 | IntTab(0), |
---|
| 262 | false |
---|
| 263 | ) |
---|
| 264 | ); |
---|
| 265 | |
---|
| 266 | maptabx.add( |
---|
| 267 | Segment("x_seg_kdata", |
---|
| 268 | KDATA_BASE, |
---|
| 269 | KDATA_SIZE, |
---|
| 270 | IntTab(0), |
---|
| 271 | false |
---|
| 272 | ) |
---|
| 273 | ); |
---|
| 274 | |
---|
| 275 | maptabx.add( |
---|
| 276 | Segment("x_seg_kunc", |
---|
| 277 | KUNC_BASE, |
---|
| 278 | KUNC_SIZE, |
---|
| 279 | IntTab(0), |
---|
| 280 | false |
---|
| 281 | ) |
---|
| 282 | ); |
---|
| 283 | |
---|
| 284 | maptabx.add( |
---|
| 285 | Segment("x_seg_code", |
---|
| 286 | CODE_BASE, |
---|
| 287 | CODE_SIZE, |
---|
| 288 | IntTab(0), |
---|
| 289 | false |
---|
| 290 | ) |
---|
| 291 | ); |
---|
| 292 | |
---|
| 293 | maptabx.add( |
---|
| 294 | Segment("x_seg_reset", |
---|
| 295 | RESET_BASE, |
---|
| 296 | RESET_SIZE, |
---|
| 297 | IntTab(0), |
---|
| 298 | false |
---|
| 299 | ) |
---|
| 300 | ); |
---|
| 301 | |
---|
| 302 | maptabx.add( |
---|
| 303 | Segment("x_seg_data", |
---|
| 304 | DATA_BASE, |
---|
| 305 | DATA_SIZE, |
---|
| 306 | IntTab(0), |
---|
| 307 | false |
---|
| 308 | ) |
---|
| 309 | ); |
---|
| 310 | |
---|
| 311 | maptabx.add( |
---|
| 312 | Segment("x_seg_stak", |
---|
| 313 | STAK_BASE, |
---|
| 314 | STAK_SIZE, |
---|
| 315 | IntTab(0), |
---|
| 316 | false |
---|
| 317 | ) |
---|
| 318 | ); |
---|
| 319 | std::cout << maptabx << std::endl; |
---|
| 320 | |
---|
| 321 | //////////////////// |
---|
| 322 | // Signals |
---|
| 323 | /////////////////// |
---|
| 324 | |
---|
| 325 | sc_clock signal_clk("clk"); |
---|
| 326 | sc_signal<bool> signal_resetn("resetn"); |
---|
| 327 | |
---|
| 328 | // Xternal network VCI signals |
---|
| 329 | VciSignals<vci_param> signal_vci_tgt_x_xram("signal_vci_tgt_x_xram"); |
---|
| 330 | |
---|
| 331 | //////////////////////////// |
---|
| 332 | // Components |
---|
| 333 | //////////////////////////// |
---|
| 334 | |
---|
| 335 | soclib::common::Loader loader(soft_name); |
---|
| 336 | |
---|
| 337 | cout << loader << endl; |
---|
| 338 | |
---|
| 339 | // TSAR Clusters |
---|
| 340 | TsarClusterV1<vci_param, cmd_width, rsp_width> * cluster; |
---|
| 341 | std::ostringstream scluster; |
---|
| 342 | scluster << "cluster_" << 0 << "_" << 0; |
---|
| 343 | |
---|
| 344 | cluster = new TsarClusterV1<vci_param, cmd_width, rsp_width> ( |
---|
| 345 | scluster.str().c_str(), |
---|
| 346 | 0, // Cluster index |
---|
| 347 | 4,4, // Router fifo's depth |
---|
| 348 | 0,0, // X, Y coordinates |
---|
| 349 | x_width, y_width, // Global routing bits |
---|
| 350 | maptabd, maptabc, maptabx, // Mapping Tables |
---|
| 351 | nprocs, // Number of processors in the cluster |
---|
| 352 | nprocs, // Maximum number of processors per cluster |
---|
| 353 | 4,32,16,/**/4,32,16, // Icache and Dcache sizes |
---|
| 354 | 4,32,16, // MemCache size |
---|
| 355 | 1, // Is IO cluster |
---|
| 356 | loader // Program Loader |
---|
| 357 | ); |
---|
| 358 | |
---|
| 359 | // External RAM |
---|
| 360 | VciSimpleRam<vci_param> xram( |
---|
| 361 | "xram", |
---|
| 362 | IntTab(0), |
---|
| 363 | maptabx, |
---|
| 364 | loader); |
---|
| 365 | |
---|
| 366 | /////////////////////////////////////////////////////////////// |
---|
| 367 | // Net-list |
---|
| 368 | /////////////////////////////////////////////////////////////// |
---|
| 369 | |
---|
| 370 | // External Ram (one instance) |
---|
| 371 | xram.p_clk (signal_clk); |
---|
| 372 | xram.p_resetn (signal_resetn); |
---|
| 373 | xram.p_vci (signal_vci_tgt_x_xram); |
---|
| 374 | |
---|
| 375 | // Connection with the external network |
---|
| 376 | cluster->p_vci_ixr(signal_vci_tgt_x_xram); |
---|
| 377 | |
---|
| 378 | // Clock and Reset |
---|
| 379 | cluster->p_clk(signal_clk); |
---|
| 380 | cluster->p_resetn(signal_resetn); |
---|
| 381 | |
---|
| 382 | //////////////////////////////////////////////////////// |
---|
| 383 | // Simulation |
---|
| 384 | /////////////////////////////////////////////////////// |
---|
| 385 | |
---|
| 386 | sc_start(sc_core::sc_time(0, SC_NS)); |
---|
| 387 | signal_resetn = false; |
---|
| 388 | |
---|
| 389 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
| 390 | signal_resetn = true; |
---|
| 391 | |
---|
| 392 | for(size_t i=1 ; i<ncycles ; i++) |
---|
| 393 | { |
---|
| 394 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
| 395 | |
---|
| 396 | if(debug_ok) { |
---|
| 397 | cluster->print_trace(); |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | std::cout << "Hit ENTER to end simulation" << std::endl; |
---|
| 402 | char buf[1]; |
---|
| 403 | std::cin.getline(buf,1); |
---|
| 404 | |
---|
| 405 | return EXIT_SUCCESS; |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | int sc_main (int argc, char *argv[]) |
---|
| 409 | { |
---|
| 410 | try { |
---|
| 411 | return _main(argc, argv); |
---|
| 412 | } catch (std::exception &e) { |
---|
| 413 | std::cout << e.what() << std::endl; |
---|
| 414 | } catch (...) { |
---|
| 415 | std::cout << "Unknown exception occured" << std::endl; |
---|
| 416 | throw; |
---|
| 417 | } |
---|
| 418 | return 1; |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | // vim: tabstop=2 shiftwidth=2 expandtab softtabstop=2 |
---|