source: branches/reconfiguration/modules/dspin_router/caba/test/recovery_bcast_evaluation/top.cpp

Last change on this file was 1016, checked in by cfuguet, 9 years ago

reconf: dspin_router

  • improve the code readability of the dspin_router model.
  • update the unitary tests of the dspin_router to support the local gateway hardware barrier, and the memory cache scratchpad mode.
File size: 4.8 KB
Line 
1/* -*- c++ -*-
2 *
3 * SOCLIB_LGPL_HEADER_BEGIN
4 *
5 * This file is part of SoCLib, GNU LGPLv2.1.
6 *
7 * SoCLib is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; version 2.1 of the License.
10 *
11 * SoCLib is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with SoCLib; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 * SOCLIB_LGPL_HEADER_END
22 *
23 * Authors  : Cesar Armando Fuguet Tortolero
24 * Date     : jul 2015
25 * Copyright: UPMC - LIP6
26 */
27#include <systemc>
28#include <string>
29#include "synthetic_dspin_network.h"
30
31#if _OPENMP
32#include <omp.h>
33#endif
34
35struct Args
36{
37    size_t x_size;
38    size_t y_size;
39    size_t load;
40    size_t ncycles;
41    bool faulty;
42};
43
44
45////////////////////////////////
46// parse command line arguments
47////////////////////////////////
48void parse_args(Args *args, int argc, char **argv)
49{
50    for (int arg = 1; arg < argc; ++arg) {
51        if ((strcmp(argv[arg], "-L") == 0) && ((arg + 1) < argc)) {
52            args->load = strtol(argv[arg + 1], NULL, 0);
53            arg++;
54            continue;
55        }
56        if ((strcmp(argv[arg], "-X") == 0) && ((arg + 1) < argc)) {
57            args->x_size = strtol(argv[arg + 1], NULL, 0);
58            arg++;
59            continue;
60        }
61        if ((strcmp(argv[arg], "-Y") == 0) && ((arg + 1) < argc)) {
62            args->y_size = strtol(argv[arg + 1], NULL, 0);
63            arg++;
64            continue;
65        }
66        if ((strcmp(argv[arg], "-N") == 0) && ((arg + 1) < argc)) {
67            args->ncycles = strtol(argv[arg + 1], NULL, 0);
68            arg++;
69            continue;
70        }
71        if (strcmp(argv[arg], "-F") == 0) {
72            args->faulty = true;
73            continue;
74        }
75
76        std::cout << "   Arguments are (key, value) couples." << std::endl;
77        std::cout << "   The order is not important." << std::endl;
78        std::cout << "   Accepted arguments are :" << std::endl << std::endl;
79        std::cout << "     -L generators' accepted load * 1000" << std::endl;
80        std::cout << "     -X number of clusters per row" << std::endl;
81        std::cout << "     -Y number of clusters per column" << std::endl;
82        std::cout << "     -N simulation's cycles" << std::endl;
83        std::cout << "     -F deactivate a router" << std::endl;
84
85        exit(1);
86    }
87}                        // end parse_args()
88
89
90int sc_main(int argc, char **argv)
91{
92    using namespace soclib::caba;
93
94#if _OPENMP
95    omp_set_dynamic(false);
96    omp_set_num_threads(1);
97#endif
98
99
100    ////////////////////////////////
101    // parse command line arguments
102    ////////////////////////////////
103    Args args = {
104        .x_size  = 5,
105        .y_size  = 5,
106        .load    = 10,
107        .ncycles = 100000,
108        .faulty  = false
109    };
110    parse_args(&args, argc, argv);
111
112
113    ////////////////////////////
114    // components instantiation
115    ////////////////////////////
116    sc_core::sc_clock signal_clk;
117    sc_core::sc_signal<bool> signal_resetn;
118    SyntheticDspinNetwork syntheticDspinNetwork("syntheticDspinNetwork",
119                                                args.x_size,
120                                                args.y_size,
121                                                args.load);
122
123
124    ///////////
125    // netlist
126    ///////////
127    syntheticDspinNetwork.p_clk(signal_clk);
128    syntheticDspinNetwork.p_resetn(signal_resetn);
129
130
131    ////////////////////
132    // start simulation
133    ////////////////////
134    sc_core::sc_start(sc_core::SC_ZERO_TIME);
135    signal_resetn.write(0);
136    syntheticDspinNetwork.reset();
137
138    if (args.faulty) {
139        // deactivate a router in the center of the mesh and create its
140        // recovery cycle-free contour
141        syntheticDspinNetwork.set_faulty_router(args.x_size / 2,
142                                                args.y_size / 2);
143    }
144
145    sc_core::sc_start(1, sc_core::SC_NS);
146    signal_resetn.write(1);
147    sc_core::sc_start(args.ncycles, sc_core::SC_NS);
148
149
150    ////////////////////
151    // print statistics
152    ////////////////////
153    for (size_t x = 0; x < args.x_size; ++x) {
154        for (size_t y = 0; y < args.y_size; ++y) {
155            syntheticDspinNetwork.print_stats(x, y);
156        }
157    }
158
159
160    return 0;
161}                   // end sc_main()
162
163// Local Variables:
164// tab-width: 4
165// c-basic-offset: 4
166// c-file-offsets:((innamespace . 0)(inline-open . 0))
167// indent-tabs-mode: nil
168// End:
169
170// vim: ts=4 : sts=4 : sw=4 : et
Note: See TracBrowser for help on using the repository browser.