source: branches/reconfiguration/modules/dspin_router/caba/test/recovery_bcast_evaluation/synthetic_dspin_network/caba/source/src/synthetic_dspin_network.cpp @ 1009

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

add a new platform for the evaluation of the broadcast recovery
replication policy.

File size: 8.9 KB
RevLine 
[1009]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 <cassert>
28
29#include "synthetic_dspin_network.h"
30#include "dspin_router_config.h"
31#include "alloc_elems.h"
32
33namespace soclib {
34namespace caba {
35using namespace soclib::common;
36   
37
38SyntheticDspinNetwork::SyntheticDspinNetwork(sc_module_name name,
39                                             const size_t x_size,
40                                             const size_t y_size,
41                                             const size_t load)
42    : BaseModule(name),
43      p_clk("p_clk"),
44      p_resetn("p_resetn"),
45      m_x_size(x_size),
46      m_y_size(y_size)
47{
48    // DSPIN packet generator instantiation
49    dspinGenerator = (DspinNetworkGenerator**)
50        malloc(sizeof(DspinNetworkGenerator*) * m_x_size);
51
52    for (size_t x = 0; x < m_x_size; ++x) {
53        dspinGenerator[x] = (DspinNetworkGenerator*)
54            malloc(sizeof(DspinNetworkGenerator) * m_y_size);
55
56        for (size_t y = 0; y < m_y_size; ++y) {
57            std::ostringstream generator_name;
58            const int SRCID = (x << Y_WIDTH) | y;
59            generator_name << "generator[" << x << "][" << y << "]";
60            new(&dspinGenerator[x][y])
61                DspinNetworkGenerator(generator_name.str().c_str(),
62                                      m_x_size,
63                                      m_y_size,
64                                      SRCID,
65                                      load,
66                                      DSPIN_GENERATOR_FIFO_DEPTH);
67         
68        }
69    }
70     
71    // DSPIN router instantiation
72    dspinRouter = (DspinNetworkRouter**)
73        malloc(sizeof(DspinNetworkRouter*) * m_x_size);
74
75    for (size_t x = 0; x < m_x_size; ++x) {
76        dspinRouter[x] = (DspinNetworkRouter*)
77            malloc(sizeof(DspinNetworkRouter) * m_y_size);
78
79        for (size_t y = 0; y < m_y_size; ++y) {
80            std::ostringstream router_name;
81            const bool BROADCAST_SUPPORTED = true;
82            const bool CONFIGURATION_SUPPORTED = true;
83            router_name << "router[" << x << "][" << y << "]";
84            new(&dspinRouter[x][y])
85                DspinNetworkRouter(router_name.str().c_str(),
86                                   x, y,
87                                   X_WIDTH, Y_WIDTH,
88                                   DSPIN_ROUTER_FIFO_DEPTH,
89                                   DSPIN_ROUTER_FIFO_DEPTH,
90                                   BROADCAST_SUPPORTED,
91                                   CONFIGURATION_SUPPORTED);
92        }
93    }
94
95    // signals instantiation
96    sL = alloc_elems<DspinNetworkSignal>("sL", m_x_size, m_y_size, 2);
97    sH = alloc_elems<DspinNetworkSignal>("sH", m_x_size + 1, m_y_size, 2);
98    sV = alloc_elems<DspinNetworkSignal>("sV", m_x_size, m_y_size + 1, 2);
99
100    sConfigRouter =
101        alloc_elems<sc_core::sc_signal<uint32_t> >("sConfigRouter",
102                                                   m_x_size, m_y_size);
103
104     
105    // netlist
106    for (size_t x = 0; x < m_x_size; ++x) {
107        for (size_t y = 0; y < m_y_size; ++y) {
108            dspinRouter[x][y].p_clk(p_clk);
109            dspinRouter[x][y].p_resetn(p_resetn);
110            dspinRouter[x][y].p_in[DspinNetworkRouter::N](sV[x][y + 1][1]);
111            dspinRouter[x][y].p_out[DspinNetworkRouter::N](sV[x][y + 1][0]);
112            dspinRouter[x][y].p_in[DspinNetworkRouter::S](sV[x][y][0]);
113            dspinRouter[x][y].p_out[DspinNetworkRouter::S](sV[x][y][1]);
114            dspinRouter[x][y].p_in[DspinNetworkRouter::E](sH[x + 1][y][1]);
115            dspinRouter[x][y].p_out[DspinNetworkRouter::E](sH[x + 1][y][0]);
116            dspinRouter[x][y].p_in[DspinNetworkRouter::W](sH[x][y][0]);
117            dspinRouter[x][y].p_out[DspinNetworkRouter::W](sH[x][y][1]);
118            dspinRouter[x][y].p_in[DspinNetworkRouter::L](sL[x][y][0]);
119            dspinRouter[x][y].p_out[DspinNetworkRouter::L](sL[x][y][1]);
120            dspinRouter[x][y].bind_recovery_port(sConfigRouter[x][y]);
121
122            dspinGenerator[x][y].p_clk(p_clk);
123            dspinGenerator[x][y].p_resetn(p_resetn);
124            dspinGenerator[x][y].p_out(sL[x][y][0]);
125            dspinGenerator[x][y].p_in(sL[x][y][1]);
126        }
127    }
128}                   // end constructor()
129
130
131SyntheticDspinNetwork::~SyntheticDspinNetwork()
132{
133    for (size_t x = 0; x < m_x_size; ++x) {
134        for (size_t y = 0; y < m_y_size; ++y) {
135            dspinGenerator[x][y].~DspinBroadcastGenerator();
136            dspinRouter[x][y].~DspinRouter();
137        }
138        free(dspinGenerator[x]);
139        free(dspinRouter[x]);
140    }
141    free(dspinGenerator);
142    free(dspinRouter);
143
144    dealloc_elems<DspinNetworkSignal>(sL, m_x_size, m_y_size, 2);
145    dealloc_elems<DspinNetworkSignal>(sH, m_x_size + 1, m_y_size, 2);
146    dealloc_elems<DspinNetworkSignal>(sV, m_x_size, m_y_size + 1, 2);
147
148    dealloc_elems<sc_core::sc_signal<uint32_t> >(sConfigRouter,
149                                                 m_x_size, m_y_size);
150}
151
152
153static inline uint32_t configRouter(int bypass_mode,
154                                    int reallocation_dir,
155                                    int blackhole_pos)
156{
157    return (bypass_mode << 7) | (reallocation_dir << 4) | blackhole_pos;
158}
159
160
161void SyntheticDspinNetwork::reset()
162{
163    // initialize routers' configuration signals
164    for (size_t x = 0; x < m_x_size; ++x) {
165        for (size_t y = 0; y < m_y_size; ++y) {
166            const uint32_t CONFIG_NONE = configRouter(0, REQ_NOP, BH_NONE);
167            sConfigRouter[x][y].write(CONFIG_NONE);
168        }
169    }
170     
171
172    // initialize mesh's boundary signals
173    for (size_t x = 0; x < m_x_size; ++x) {
174        sV[x][0][0].write = false;
175        sV[x][0][1].read = true;
176        sV[x][m_y_size][0].read = true;
177        sV[x][m_y_size][1].write = false;
178    }
179    for (size_t y = 0; y < m_y_size; ++y) {
180        sH[0][y][0].write = false;
181        sH[0][y][1].read = true;
182        sH[m_x_size][y][0].read = true;
183        sH[m_x_size][y][1].write = false;
184    }
185}                   // end reset()
186   
187
188void SyntheticDspinNetwork::set_faulty_router(const size_t faulty_x,
189                                              const size_t faulty_y)
190{
191    assert(faulty_x < m_x_size);
192    assert(faulty_y < m_y_size);
193
194
195    // transform the faulty router in a black-hole
196    dspinRouter[faulty_x][faulty_y].set_disable_mask(0x1F);
197
198
199    // reconfigure the faulty router's contour
200    if (faulty_y < (m_y_size - 1)) {
201        const uint32_t CONFIG_N = configRouter(1, REQ_SOUTH, BH_N);
202        sConfigRouter[faulty_x][faulty_y + 1].write(CONFIG_N);
203
204        if (faulty_x > 0) {
205            const uint32_t CONFIG_NW = configRouter(1, REQ_EAST, BH_NW);
206            sConfigRouter[faulty_x - 1][faulty_y + 1].write(CONFIG_NW);
207        }
208        if (faulty_x < (m_x_size - 1)) {
209            const uint32_t CONFIG_NE = configRouter(1, REQ_WEST, BH_NE);
210            sConfigRouter[faulty_x + 1][faulty_y + 1].write(CONFIG_NE);
211        }
212    }
213
214    if (faulty_y > 0) {
215        const uint32_t CONFIG_S = configRouter(1, REQ_NORTH, BH_S);
216        sConfigRouter[faulty_x][faulty_y - 1].write(CONFIG_S);
217
218        if (faulty_x > 0) {
219            const uint32_t CONFIG_SW = configRouter(1, REQ_EAST, BH_SW);
220            sConfigRouter[faulty_x - 1][faulty_y - 1].write(CONFIG_SW);
221        }
222        if (faulty_x < (m_x_size - 1)) {
223            const uint32_t CONFIG_SE = configRouter(1, REQ_WEST, BH_SE);
224            sConfigRouter[faulty_x + 1][faulty_y - 1].write(CONFIG_SE);
225        }
226    }
227
228    if (faulty_x > 0) {
229        const uint32_t CONFIG_W = configRouter(1, REQ_EAST, BH_W);
230        sConfigRouter[faulty_x - 1][faulty_y].write(CONFIG_W);
231    }
232
233    if (faulty_x < (m_x_size - 1)) {
234        const uint32_t CONFIG_E = configRouter(1, REQ_WEST, BH_E);
235        sConfigRouter[faulty_x + 1][faulty_y].write(CONFIG_E);
236    }
237}                   // end set_faulty_router()
238
239
240void SyntheticDspinNetwork::print_stats(const size_t x, const size_t y)
241{
242    assert(x < m_x_size);
243    assert(y < m_y_size);
244
245    dspinGenerator[x][y].print_stats();
246}
247   
248
249}                   // end namespace caba
250}                   // end namespace soclib
251
252// Local Variables:
253// tab-width: 4
254// c-basic-offset: 4
255// c-file-offsets:((innamespace . 0)(inline-open . 0))
256// indent-tabs-mode: nil
257// End:
Note: See TracBrowser for help on using the repository browser.