1 | |
---|
2 | #include <systemc> |
---|
3 | #include <sys/time.h> |
---|
4 | #include <iostream> |
---|
5 | #include <cstdlib> |
---|
6 | #include <cstdarg> |
---|
7 | |
---|
8 | #include "mapping_table.h" |
---|
9 | #include "alloc_elems.h" |
---|
10 | //#include "vci_simple_ram.h" |
---|
11 | //#include "vci_multi_tty.h" |
---|
12 | #include "vci_local_ring_fast.h" |
---|
13 | #include "virtual_dspin_router.h" |
---|
14 | #include "vci_synthetic_initiator.h" |
---|
15 | |
---|
16 | // MESH SIZE |
---|
17 | #define X_MAX 2 |
---|
18 | #define Y_MAX 2 |
---|
19 | #define N_CLUSTERS X_MAX*Y_MAX |
---|
20 | // FLIT_WIDTH |
---|
21 | #define WIDTH_CMD 40 |
---|
22 | #define WIDTH_RSP 33 |
---|
23 | // Face of each DSPIN Router |
---|
24 | #define NORTH 0 |
---|
25 | #define SOUTH 1 |
---|
26 | #define EAST 2 |
---|
27 | #define WEST 3 |
---|
28 | #define LOCAL 4 |
---|
29 | |
---|
30 | |
---|
31 | int _main(int argc, char *argv[]) |
---|
32 | { |
---|
33 | using namespace sc_core; |
---|
34 | // Avoid repeating these everywhere |
---|
35 | using soclib::common::IntTab; |
---|
36 | using soclib::common::Segment; |
---|
37 | |
---|
38 | using soclib::common::uint32_log2; |
---|
39 | |
---|
40 | // Define VCI parameters |
---|
41 | typedef soclib::caba::VciParams<4,8,32,1,1,1,8,4,4,1> vci_param; |
---|
42 | |
---|
43 | // Mapping table primary network |
---|
44 | |
---|
45 | soclib::common::MappingTable maptab(32, IntTab(2,10), IntTab(2,3), 0x00C00000); |
---|
46 | |
---|
47 | |
---|
48 | maptab.add(Segment("mc_r0" , MC0_R_BASE , MC0_R_SIZE , IntTab(0,0), false, true, IntTab(0,0))); |
---|
49 | maptab.add(Segment("mc_m0" , MC0_M_BASE , MC0_M_SIZE , IntTab(0,0), true )); |
---|
50 | maptab.add(Segment("mc_r1" , MC1_R_BASE , MC1_R_SIZE , IntTab(1,0), false, true, IntTab(1,0))); |
---|
51 | maptab.add(Segment("mc_m1" , MC1_M_BASE , MC1_M_SIZE , IntTab(1,0), true )); |
---|
52 | maptab.add(Segment("mc_r2" , MC2_R_BASE , MC2_R_SIZE , IntTab(2,0), false, true, IntTab(2,0))); |
---|
53 | maptab.add(Segment("mc_m2" , MC2_M_BASE , MC2_M_SIZE , IntTab(2,0), true )); |
---|
54 | maptab.add(Segment("mc_r3" , MC3_R_BASE , MC3_R_SIZE , IntTab(3,0), false, true, IntTab(3,0))); |
---|
55 | maptab.add(Segment("mc_m3" , MC3_M_BASE , MC3_M_SIZE , IntTab(3,0), true )); |
---|
56 | |
---|
57 | std::cout << maptab << std::endl; |
---|
58 | |
---|
59 | // Signals |
---|
60 | |
---|
61 | sc_clock signal_clk("clk"); |
---|
62 | sc_signal<bool> signal_resetn("resetn"); |
---|
63 | |
---|
64 | soclib::caba::VciSignals<vci_param> * signal_vci_ini_synth_c0 = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_ini_synth", N_CLUSTERS); |
---|
65 | soclib::caba::VciSignals<vci_param> * signal_vci_ini_synth_c1 = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_ini_synth", N_CLUSTERS); |
---|
66 | /////////////////////////////////////////////////////////////// |
---|
67 | // VDSPIN Signals : one level for in and out, one level for X length in the mesh, |
---|
68 | // one level for Y length in the mesh, last level for each port of the router |
---|
69 | /////////////////////////////////////////////////////////////// |
---|
70 | soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c0 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals_channel_0", 2, Y_MAX, X_MAX, 5 ); |
---|
71 | soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c1 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals_channel_1", 2, Y_MAX, X_MAX, 5 ); |
---|
72 | soclib::caba::DspinSignals<WIDTH_RSP> **** dspin_signals_rsp_c0 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_RSP> >("Dspin_rsp_signals_channel_0", 2, Y_MAX, X_MAX, 5 ); |
---|
73 | soclib::caba::DspinSignals<WIDTH_RSP> **** dspin_signals_rsp_c1 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_RSP> >("Dspin_rsp_signals_channel_2", 2, Y_MAX, X_MAX, 5 ); |
---|
74 | |
---|
75 | //soclib::caba::VciSignals<vci_param> * signal_vci_tgt_proc = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_tgt_proc", N_CLUSTERS); |
---|
76 | |
---|
77 | // N_CLUSTERS ring. |
---|
78 | soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> * local_ring_c0 = (soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> *) malloc(sizeof(soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ) * N_CLUSTERS) ; |
---|
79 | for(int i = 0 ; i < N_CLUSTERS ; i++){ // ringid, fifo, fifo, nb_init, nb_tgt |
---|
80 | new(&local_ring_c0[i]) soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ("cluster_c0" + i,maptab, IntTab(i), 2, 18, 1, 1) |
---|
81 | } |
---|
82 | |
---|
83 | soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> * local_ring_c1 = (soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> *) malloc(sizeof(soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ) * N_CLUSTERS) ; |
---|
84 | for(int i = 0 ; i < N_CLUSTERS ; i++){ // ringid, fifo, fifo, nb_init, nb_tgt |
---|
85 | new(&local_ring_c1[i]) soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ("cluster_c1" + i,maptab, IntTab(i), 2, 18, 1, 1) |
---|
86 | } |
---|
87 | |
---|
88 | // Virtual dspin routers |
---|
89 | soclib::caba::VirtualDspinRouter<WIDTH_CMD> ** routers_cmd = (soclib::caba::VirtualDspinRouter<WIDTH_CMD> **) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_CMD> *) * Y_MAX); |
---|
90 | soclib::caba::VirtualDspinRouter<WIDTH_RSP> ** routers_rsp = (soclib::caba::VirtualDspinRouter<WIDTH_RSP> **) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_RSP> *) * Y_MAX); |
---|
91 | |
---|
92 | for(int i = 0; i < Y_MAX; i++ ){ |
---|
93 | routers_cmd[i] = (soclib::caba::VirtualDspinRouter<WIDTH_CMD> * ) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_CMD>) * X_MAX); |
---|
94 | routers_rsp[i] = (soclib::caba::VirtualDspinRouter<WIDTH_RSP> * ) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_RSP>) * X_MAX); |
---|
95 | for(int j = 0; j < X_MAX; i++){ |
---|
96 | new(&routers_cmd[i][j]) soclib::caba::VirtualDspinRouter<WIDTH_CMD> ("VDspinRouterCMD" + i + j, j, i, soclib::common::uint32_log2(X_MAX), soclib::common::uint32_log2(Y_MAX), 4, 4); |
---|
97 | new(&routers_rsp[i][j]) soclib::caba::VirtualDspinRouter<WIDTH_RSP> ("VDspinRouterRSP" + i + j, j, i, soclib::common::uint32_log2(X_MAX), soclib::common::uint32_log2(Y_MAX), 4, 4); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | /////////////////////////////////////////////////////////////// |
---|
103 | // Components |
---|
104 | /////////////////////////////////////////////////////////////// |
---|
105 | |
---|
106 | // N_CLUSTERS VCI Synthetic Initiator (1 initiator per cluster/network) |
---|
107 | soclib::caba::VciSyntheticInitiator<vci_param> * initiator_c0 = (soclib::caba::VciSyntheticInitiator<vci_param> *) malloc(sizeof(soclib::caba::VciSyntheticInitiator<vci_param> )* N_CLUSTERS); |
---|
108 | for(int i = 0 ; i < Y_MAX; i++) |
---|
109 | for(int j = 0 ; j < Y_MAX ; j++) |
---|
110 | new(&initiator_c0[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> ("Initiator_c0" + (i*X_MAX+j), i*X_MAX+j, maptab, IntTab(i,j),16, 0.5, 2, X_MAX, Y_MAX); |
---|
111 | |
---|
112 | soclib::caba::VciSyntheticInitiator<vci_param> * initiator_c1 = (soclib::caba::VciSyntheticInitiator<vci_param> *) malloc(sizeof(soclib::caba::VciSyntheticInitiator<vci_param> )* N_CLUSTERS); |
---|
113 | for(int i = 0 ; i < Y_MAX; i++) |
---|
114 | for(int j = 0 ; j < Y_MAX ; j++) |
---|
115 | new(&initiator_c1[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> ("Initiator_c1" + (i*X_MAX+j), i*X_MAX+j, maptab, IntTab(i,j),16, 0.5, 2, X_MAX, Y_MAX); |
---|
116 | |
---|
117 | /////////////////////////////////////////////////////////////// |
---|
118 | // Connection of Synthetic Initiator to each local ring per cluster |
---|
119 | /////////////////////////////////////////////////////////////// |
---|
120 | for(int i = 0 ; i < N_CLUSTERS ; i++){ |
---|
121 | local_ring_c0[i].p_clk(signal_clk); |
---|
122 | local_ring_c0[i].p_resetn(signal_resetn); |
---|
123 | local_ring_c0[i].p_to_initiator[0](signal_vci_ini_synt_c0h[i]); |
---|
124 | initiator_c0[i].p_clk(signal_clk); |
---|
125 | initiator_c0[i].p_resetn(signal_resetn); |
---|
126 | initiator_c0[i].p_vci(signal_vci_ini_synth_c0[i]); |
---|
127 | local_ring_c1[i].p_clk(signal_clk); |
---|
128 | local_ring_c1[i].p_resetn(signal_resetn); |
---|
129 | local_ring_c1[i].p_to_initiator[0](signal_vci_ini_synth_c1[i]); |
---|
130 | initiator_c1[i].p_clk(signal_clk); |
---|
131 | initiator_c1[i].p_resetn(signal_resetn); |
---|
132 | initiator_c1[i].p_vci(signal_vci_ini_synth_c1[i]); |
---|
133 | } |
---|
134 | |
---|
135 | /////////////////////////////////////////////////////////////// |
---|
136 | // Connection of each VDspin Router to each local ring and |
---|
137 | // neighbors VDspin Router |
---|
138 | /////////////////////////////////////////////////////////////// |
---|
139 | for(int i = 0; i < Y_MAX ; i++){ |
---|
140 | for(int j = 0; j < X_MAX ; j++){ |
---|
141 | routers_cmd[i][j].p_clk(signal_clk); |
---|
142 | routers_cmd[i][j].p_resetn(signal_resetn); |
---|
143 | routers_rsp[i][j].p_clk(signal_clk); |
---|
144 | routers_rsp[i][j].p_resetn(signal_resetn); |
---|
145 | local_ring_c0[i*X_MAX+j].p_gate_cmd_in( dspin_signals_cmd_c0[0][i][j][LOCAL]); |
---|
146 | local_ring_c0[i*X_MAX+j].p_gate_cmd_out(dspin_signals_cmd_c0[1][i][j][LOCAL] ); |
---|
147 | local_ring_c0[i*X_MAX+j].p_gate_rsp_in( dspin_signals_rsp_c0[0][i][j][LOCAL]); |
---|
148 | local_ring_c0[i*X_MAX+j].p_gate_rsp_out(dspin_signals_rsp_c0[1][i][j][LOCAL] ); |
---|
149 | local_ring_c1[i*X_MAX+j].p_gate_cmd_in( dspin_signals_cmd_c1[0][i][j][LOCAL]); |
---|
150 | local_ring_c1[i*X_MAX+j].p_gate_cmd_out(dspin_signals_cmd_c1[1][i][j][LOCAL] ); |
---|
151 | local_ring_c1[i*X_MAX+j].p_gate_rsp_in( dspin_signals_rsp_c1[0][i][j][LOCAL]); |
---|
152 | local_ring_c1[i*X_MAX+j].p_gate_rsp_out(dspin_signals_rsp_c1[1][i][j][LOCAL] ); |
---|
153 | for(k = 0; k < 5; k++){ |
---|
154 | if(i == 0){ |
---|
155 | if(j == 0){ |
---|
156 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]); |
---|
157 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]); |
---|
158 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]); |
---|
159 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]); |
---|
160 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]); |
---|
161 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]); |
---|
162 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]); |
---|
163 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]); |
---|
164 | } else { |
---|
165 | if(k == WEST){ |
---|
166 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[1][i][j-1][EAST]); |
---|
167 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[1][i][j-1][EAST]); |
---|
168 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[0][i][j-1][EAST]); |
---|
169 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[0][i][j-1][EAST]); |
---|
170 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[1][i][j-1][EAST]); |
---|
171 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[1][i][j-1][EAST]); |
---|
172 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[0][i][j-1][EAST]); |
---|
173 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[0][i][j-1][EAST]); |
---|
174 | } else { |
---|
175 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]); |
---|
176 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]); |
---|
177 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]); |
---|
178 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]); |
---|
179 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]); |
---|
180 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]); |
---|
181 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]); |
---|
182 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]); |
---|
183 | } |
---|
184 | } |
---|
185 | } else { |
---|
186 | if(k == SOUTH){ |
---|
187 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[1][i-1][j][NORTH]); |
---|
188 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[1][i-1][j][NORTH]); |
---|
189 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[0][i-1][j][NORTH]); |
---|
190 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[0][i-1][j][NORTH]); |
---|
191 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[1][i-1][j][NORTH]); |
---|
192 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[1][i-1][j][NORTH]); |
---|
193 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[0][i-1][j][NORTH]); |
---|
194 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[0][i-1][j][NORTH]); |
---|
195 | } else if(k == WEST){ |
---|
196 | if(j == 0){ |
---|
197 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]); |
---|
198 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]); |
---|
199 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]); |
---|
200 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]); |
---|
201 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]); |
---|
202 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]); |
---|
203 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]); |
---|
204 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]); |
---|
205 | } else { |
---|
206 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[1][i][j-1][EAST]); |
---|
207 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[1][i][j-1][EAST]); |
---|
208 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[0][i][j-1][EAST]); |
---|
209 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[0][i][j-1][EAST]); |
---|
210 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[1][i][j-1][EAST]); |
---|
211 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[1][i][j-1][EAST]); |
---|
212 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[0][i][j-1][EAST]); |
---|
213 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[0][i][j-1][EAST]); |
---|
214 | } |
---|
215 | } else { |
---|
216 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]); |
---|
217 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]); |
---|
218 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]); |
---|
219 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]); |
---|
220 | routers_rsp[i][j].p_out[0][k](dspin_signals_rsp_c0[0][i][j][k]); |
---|
221 | routers_rsp[i][j].p_out[1][k](dspin_signals_rsp_c1[0][i][j][k]); |
---|
222 | routers_rsp[i][j].p_in[0][k](dspin_signals_rsp_c0[1][i][j][k]); |
---|
223 | routers_rsp[i][j].p_in[1][k](dspin_signals_rsp_c1[1][i][j][k]); |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | //////////////////////////////////////////////////////// |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | //////////////////////////////////////////////// |
---|
235 | // Simulation Loop // |
---|
236 | //////////////////////////////////////////////// |
---|
237 | int ncycles; |
---|
238 | |
---|
239 | if (argc == 2) { |
---|
240 | ncycles = std::atoi(argv[1]); |
---|
241 | } else { |
---|
242 | std::cerr |
---|
243 | << std::endl |
---|
244 | << "The number of simulation cycles must " |
---|
245 | "be defined in the command line" |
---|
246 | << std::endl; |
---|
247 | exit(1); |
---|
248 | } |
---|
249 | |
---|
250 | sc_start(sc_core::sc_time(0, SC_NS)); |
---|
251 | signal_resetn = false; |
---|
252 | |
---|
253 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
254 | signal_resetn = true; |
---|
255 | |
---|
256 | for (int i = 0; i < ncycles ; i+=100000) { |
---|
257 | sc_start(sc_core::sc_time(100000, SC_NS)); |
---|
258 | |
---|
259 | } |
---|
260 | |
---|
261 | std::cout << "Hit ENTER to end simulation" << std::endl; |
---|
262 | char buf[1]; |
---|
263 | |
---|
264 | std::cin.getline(buf,1); |
---|
265 | return EXIT_SUCCESS; |
---|
266 | } |
---|
267 | |
---|
268 | int sc_main (int argc, char *argv[]) |
---|
269 | { |
---|
270 | try { |
---|
271 | return _main(argc, argv); |
---|
272 | } catch (std::exception &e) { |
---|
273 | std::cout << e.what() << std::endl; |
---|
274 | } catch (...) { |
---|
275 | std::cout << "Unknown exception occured" << std::endl; |
---|
276 | throw; |
---|
277 | } |
---|
278 | return 1; |
---|
279 | } |
---|