[1009] | 1 | /* -*- c++ -*- |
---|
| 2 | * |
---|
| 3 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
[1016] | 4 | * |
---|
[1009] | 5 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
[1016] | 6 | * |
---|
[1009] | 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. |
---|
[1016] | 10 | * |
---|
[1009] | 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. |
---|
[1016] | 15 | * |
---|
[1009] | 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 |
---|
[1016] | 20 | * |
---|
[1009] | 21 | * SOCLIB_LGPL_HEADER_END |
---|
| 22 | * |
---|
[1016] | 23 | * Authors : Cesar Armando Fuguet Tortolero |
---|
[1009] | 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 | |
---|
| 33 | namespace soclib { |
---|
| 34 | namespace caba { |
---|
| 35 | using namespace soclib::common; |
---|
| 36 | |
---|
[1016] | 37 | |
---|
[1009] | 38 | SyntheticDspinNetwork::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 << "]"; |
---|
[1016] | 60 | #if UNICAST |
---|
| 61 | const size_t PACKET_LENGTH = 8; |
---|
[1009] | 62 | new(&dspinGenerator[x][y]) |
---|
| 63 | DspinNetworkGenerator(generator_name.str().c_str(), |
---|
[1016] | 64 | (size_t)SRCID, |
---|
| 65 | PACKET_LENGTH, |
---|
| 66 | load, |
---|
| 67 | (size_t)DSPIN_GENERATOR_FIFO_DEPTH, |
---|
| 68 | 0 ); |
---|
| 69 | #else |
---|
| 70 | new(&dspinGenerator[x][y]) |
---|
| 71 | DspinNetworkGenerator(generator_name.str().c_str(), |
---|
[1009] | 72 | m_x_size, |
---|
| 73 | m_y_size, |
---|
| 74 | SRCID, |
---|
| 75 | load, |
---|
| 76 | DSPIN_GENERATOR_FIFO_DEPTH); |
---|
[1016] | 77 | #endif |
---|
| 78 | |
---|
[1009] | 79 | } |
---|
| 80 | } |
---|
[1016] | 81 | |
---|
[1009] | 82 | // DSPIN router instantiation |
---|
| 83 | dspinRouter = (DspinNetworkRouter**) |
---|
| 84 | malloc(sizeof(DspinNetworkRouter*) * m_x_size); |
---|
| 85 | |
---|
| 86 | for (size_t x = 0; x < m_x_size; ++x) { |
---|
[1016] | 87 | dspinRouter[x] = (DspinNetworkRouter*) |
---|
[1009] | 88 | malloc(sizeof(DspinNetworkRouter) * m_y_size); |
---|
| 89 | |
---|
| 90 | for (size_t y = 0; y < m_y_size; ++y) { |
---|
| 91 | std::ostringstream router_name; |
---|
| 92 | const bool BROADCAST_SUPPORTED = true; |
---|
| 93 | const bool CONFIGURATION_SUPPORTED = true; |
---|
| 94 | router_name << "router[" << x << "][" << y << "]"; |
---|
| 95 | new(&dspinRouter[x][y]) |
---|
| 96 | DspinNetworkRouter(router_name.str().c_str(), |
---|
| 97 | x, y, |
---|
| 98 | X_WIDTH, Y_WIDTH, |
---|
| 99 | DSPIN_ROUTER_FIFO_DEPTH, |
---|
| 100 | DSPIN_ROUTER_FIFO_DEPTH, |
---|
| 101 | BROADCAST_SUPPORTED, |
---|
| 102 | CONFIGURATION_SUPPORTED); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | // signals instantiation |
---|
| 107 | sL = alloc_elems<DspinNetworkSignal>("sL", m_x_size, m_y_size, 2); |
---|
| 108 | sH = alloc_elems<DspinNetworkSignal>("sH", m_x_size + 1, m_y_size, 2); |
---|
| 109 | sV = alloc_elems<DspinNetworkSignal>("sV", m_x_size, m_y_size + 1, 2); |
---|
| 110 | |
---|
| 111 | sConfigRouter = |
---|
| 112 | alloc_elems<sc_core::sc_signal<uint32_t> >("sConfigRouter", |
---|
| 113 | m_x_size, m_y_size); |
---|
| 114 | |
---|
[1016] | 115 | |
---|
[1009] | 116 | // netlist |
---|
| 117 | for (size_t x = 0; x < m_x_size; ++x) { |
---|
| 118 | for (size_t y = 0; y < m_y_size; ++y) { |
---|
| 119 | dspinRouter[x][y].p_clk(p_clk); |
---|
| 120 | dspinRouter[x][y].p_resetn(p_resetn); |
---|
| 121 | dspinRouter[x][y].p_in[DspinNetworkRouter::N](sV[x][y + 1][1]); |
---|
| 122 | dspinRouter[x][y].p_out[DspinNetworkRouter::N](sV[x][y + 1][0]); |
---|
| 123 | dspinRouter[x][y].p_in[DspinNetworkRouter::S](sV[x][y][0]); |
---|
| 124 | dspinRouter[x][y].p_out[DspinNetworkRouter::S](sV[x][y][1]); |
---|
| 125 | dspinRouter[x][y].p_in[DspinNetworkRouter::E](sH[x + 1][y][1]); |
---|
| 126 | dspinRouter[x][y].p_out[DspinNetworkRouter::E](sH[x + 1][y][0]); |
---|
| 127 | dspinRouter[x][y].p_in[DspinNetworkRouter::W](sH[x][y][0]); |
---|
| 128 | dspinRouter[x][y].p_out[DspinNetworkRouter::W](sH[x][y][1]); |
---|
| 129 | dspinRouter[x][y].p_in[DspinNetworkRouter::L](sL[x][y][0]); |
---|
| 130 | dspinRouter[x][y].p_out[DspinNetworkRouter::L](sL[x][y][1]); |
---|
| 131 | dspinRouter[x][y].bind_recovery_port(sConfigRouter[x][y]); |
---|
| 132 | |
---|
| 133 | dspinGenerator[x][y].p_clk(p_clk); |
---|
| 134 | dspinGenerator[x][y].p_resetn(p_resetn); |
---|
| 135 | dspinGenerator[x][y].p_out(sL[x][y][0]); |
---|
| 136 | dspinGenerator[x][y].p_in(sL[x][y][1]); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | } // end constructor() |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | SyntheticDspinNetwork::~SyntheticDspinNetwork() |
---|
| 143 | { |
---|
| 144 | for (size_t x = 0; x < m_x_size; ++x) { |
---|
| 145 | for (size_t y = 0; y < m_y_size; ++y) { |
---|
[1016] | 146 | #if UNICAST |
---|
| 147 | dspinGenerator[x][y].~DspinPacketGenerator(); |
---|
| 148 | #else |
---|
[1009] | 149 | dspinGenerator[x][y].~DspinBroadcastGenerator(); |
---|
[1016] | 150 | #endif |
---|
[1009] | 151 | dspinRouter[x][y].~DspinRouter(); |
---|
| 152 | } |
---|
| 153 | free(dspinGenerator[x]); |
---|
| 154 | free(dspinRouter[x]); |
---|
| 155 | } |
---|
| 156 | free(dspinGenerator); |
---|
| 157 | free(dspinRouter); |
---|
| 158 | |
---|
| 159 | dealloc_elems<DspinNetworkSignal>(sL, m_x_size, m_y_size, 2); |
---|
| 160 | dealloc_elems<DspinNetworkSignal>(sH, m_x_size + 1, m_y_size, 2); |
---|
| 161 | dealloc_elems<DspinNetworkSignal>(sV, m_x_size, m_y_size + 1, 2); |
---|
| 162 | |
---|
| 163 | dealloc_elems<sc_core::sc_signal<uint32_t> >(sConfigRouter, |
---|
| 164 | m_x_size, m_y_size); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | |
---|
[1016] | 168 | static inline uint32_t configRouter(int reallocation_dir, |
---|
| 169 | int recovery_mode, |
---|
[1009] | 170 | int blackhole_pos) |
---|
| 171 | { |
---|
[1016] | 172 | return ((reallocation_dir & 0x7) << 5) | |
---|
| 173 | ((recovery_mode & 0x1) << 4) | |
---|
| 174 | (blackhole_pos & 0xF); |
---|
[1009] | 175 | } |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | void SyntheticDspinNetwork::reset() |
---|
| 179 | { |
---|
| 180 | // initialize routers' configuration signals |
---|
| 181 | for (size_t x = 0; x < m_x_size; ++x) { |
---|
| 182 | for (size_t y = 0; y < m_y_size; ++y) { |
---|
[1016] | 183 | const uint32_t CONFIG_NONE = configRouter(0, 0, NORMAL); |
---|
[1009] | 184 | sConfigRouter[x][y].write(CONFIG_NONE); |
---|
| 185 | } |
---|
| 186 | } |
---|
| 187 | |
---|
[1016] | 188 | |
---|
[1009] | 189 | // initialize mesh's boundary signals |
---|
| 190 | for (size_t x = 0; x < m_x_size; ++x) { |
---|
| 191 | sV[x][0][0].write = false; |
---|
| 192 | sV[x][0][1].read = true; |
---|
| 193 | sV[x][m_y_size][0].read = true; |
---|
| 194 | sV[x][m_y_size][1].write = false; |
---|
| 195 | } |
---|
| 196 | for (size_t y = 0; y < m_y_size; ++y) { |
---|
| 197 | sH[0][y][0].write = false; |
---|
| 198 | sH[0][y][1].read = true; |
---|
| 199 | sH[m_x_size][y][0].read = true; |
---|
| 200 | sH[m_x_size][y][1].write = false; |
---|
| 201 | } |
---|
| 202 | } // end reset() |
---|
| 203 | |
---|
[1016] | 204 | |
---|
[1009] | 205 | void SyntheticDspinNetwork::set_faulty_router(const size_t faulty_x, |
---|
| 206 | const size_t faulty_y) |
---|
| 207 | { |
---|
| 208 | assert(faulty_x < m_x_size); |
---|
| 209 | assert(faulty_y < m_y_size); |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | // transform the faulty router in a black-hole |
---|
| 213 | dspinRouter[faulty_x][faulty_y].set_disable_mask(0x1F); |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | // reconfigure the faulty router's contour |
---|
| 217 | if (faulty_y < (m_y_size - 1)) { |
---|
[1016] | 218 | const uint32_t CONFIG_N = configRouter(REQ_SOUTH, 1, N_OF_X); |
---|
[1009] | 219 | sConfigRouter[faulty_x][faulty_y + 1].write(CONFIG_N); |
---|
| 220 | |
---|
| 221 | if (faulty_x > 0) { |
---|
[1016] | 222 | const uint32_t CONFIG_NW = configRouter(REQ_EAST, 1, NW_OF_X); |
---|
[1009] | 223 | sConfigRouter[faulty_x - 1][faulty_y + 1].write(CONFIG_NW); |
---|
| 224 | } |
---|
| 225 | if (faulty_x < (m_x_size - 1)) { |
---|
[1016] | 226 | const uint32_t CONFIG_NE = configRouter(REQ_WEST, 1, NE_OF_X); |
---|
[1009] | 227 | sConfigRouter[faulty_x + 1][faulty_y + 1].write(CONFIG_NE); |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | if (faulty_y > 0) { |
---|
[1016] | 232 | const uint32_t CONFIG_S = configRouter(REQ_NORTH, 1, S_OF_X); |
---|
[1009] | 233 | sConfigRouter[faulty_x][faulty_y - 1].write(CONFIG_S); |
---|
| 234 | |
---|
| 235 | if (faulty_x > 0) { |
---|
[1016] | 236 | const uint32_t CONFIG_SW = configRouter(REQ_EAST, 1, SW_OF_X); |
---|
[1009] | 237 | sConfigRouter[faulty_x - 1][faulty_y - 1].write(CONFIG_SW); |
---|
| 238 | } |
---|
| 239 | if (faulty_x < (m_x_size - 1)) { |
---|
[1016] | 240 | const uint32_t CONFIG_SE = configRouter(REQ_WEST, 1, SE_OF_X); |
---|
[1009] | 241 | sConfigRouter[faulty_x + 1][faulty_y - 1].write(CONFIG_SE); |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | if (faulty_x > 0) { |
---|
[1016] | 246 | const uint32_t CONFIG_W = configRouter(REQ_EAST, 1, W_OF_X); |
---|
[1009] | 247 | sConfigRouter[faulty_x - 1][faulty_y].write(CONFIG_W); |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | if (faulty_x < (m_x_size - 1)) { |
---|
[1016] | 251 | const uint32_t CONFIG_E = configRouter(REQ_WEST, 1, E_OF_X); |
---|
[1009] | 252 | sConfigRouter[faulty_x + 1][faulty_y].write(CONFIG_E); |
---|
| 253 | } |
---|
| 254 | } // end set_faulty_router() |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | void SyntheticDspinNetwork::print_stats(const size_t x, const size_t y) |
---|
| 258 | { |
---|
| 259 | assert(x < m_x_size); |
---|
| 260 | assert(y < m_y_size); |
---|
| 261 | |
---|
| 262 | dspinGenerator[x][y].print_stats(); |
---|
| 263 | } |
---|
| 264 | |
---|
[1016] | 265 | |
---|
[1009] | 266 | } // end namespace caba |
---|
| 267 | } // end namespace soclib |
---|
| 268 | |
---|
| 269 | // Local Variables: |
---|
| 270 | // tab-width: 4 |
---|
| 271 | // c-basic-offset: 4 |
---|
| 272 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 273 | // indent-tabs-mode: nil |
---|
| 274 | // End: |
---|
[1016] | 275 | |
---|
| 276 | // vim: ts=4 : sts=4 : sw=4 : et |
---|