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_network.h" |
---|
13 | #include "vci_simple_ring_network.h" |
---|
14 | #include "virtual_dspin_network.h" |
---|
15 | #include "vci_synthetic_initiator.h" |
---|
16 | |
---|
17 | // MESH SIZE |
---|
18 | #define X_MAX 2 |
---|
19 | #define Y_MAX 2 |
---|
20 | #define N_CLUSTERS X_MAX*Y_MAX |
---|
21 | // FLIT_WIDTH |
---|
22 | #define WIDTH_CMD 40 |
---|
23 | #define WIDTH_RSP 33 |
---|
24 | // Face of each DSPIN Router |
---|
25 | #define NORTH 0 |
---|
26 | #define SOUTH 1 |
---|
27 | #define EAST 2 |
---|
28 | #define WEST 3 |
---|
29 | #define LOCAL 4 |
---|
30 | |
---|
31 | |
---|
32 | int _main(int argc, char *argv[]) |
---|
33 | { |
---|
34 | using namespace sc_core; |
---|
35 | // Avoid repeating these everywhere |
---|
36 | using soclib::common::IntTab; |
---|
37 | using soclib::common::Segment; |
---|
38 | |
---|
39 | // Define VCI parameters |
---|
40 | typedef soclib::caba::VciParams<4,8,32,1,1,1,8,4,4,1> vci_param; |
---|
41 | |
---|
42 | // Mapping table primary network |
---|
43 | |
---|
44 | soclib::common::MappingTable maptab(32, IntTab(2,10), IntTab(2,3), 0x00C00000); |
---|
45 | |
---|
46 | maptab.add(Segment("reset", RESET_BASE, RESET_SIZE, IntTab(2,1), true)); |
---|
47 | maptab.add(Segment("excep", EXCEP_BASE, EXCEP_SIZE, IntTab(2,1), true)); |
---|
48 | maptab.add(Segment("tty" , TTY_BASE , TTY_SIZE , IntTab(3,1), false)); |
---|
49 | |
---|
50 | maptab.add(Segment("mc_r0" , MC0_R_BASE , MC0_R_SIZE , IntTab(0,0), false, true, IntTab(0,0))); |
---|
51 | maptab.add(Segment("mc_m0" , MC0_M_BASE , MC0_M_SIZE , IntTab(0,0), true )); |
---|
52 | maptab.add(Segment("mc_r1" , MC1_R_BASE , MC1_R_SIZE , IntTab(1,0), false, true, IntTab(1,0))); |
---|
53 | maptab.add(Segment("mc_m1" , MC1_M_BASE , MC1_M_SIZE , IntTab(1,0), true )); |
---|
54 | maptab.add(Segment("mc_r2" , MC2_R_BASE , MC2_R_SIZE , IntTab(2,0), false, true, IntTab(2,0))); |
---|
55 | maptab.add(Segment("mc_m2" , MC2_M_BASE , MC2_M_SIZE , IntTab(2,0), true )); |
---|
56 | maptab.add(Segment("mc_r3" , MC3_R_BASE , MC3_R_SIZE , IntTab(3,0), false, true, IntTab(3,0))); |
---|
57 | maptab.add(Segment("mc_m3" , MC3_M_BASE , MC3_M_SIZE , IntTab(3,0), true )); |
---|
58 | |
---|
59 | std::cout << maptab << std::endl; |
---|
60 | |
---|
61 | // Signals |
---|
62 | |
---|
63 | sc_clock signal_clk("clk"); |
---|
64 | sc_signal<bool> signal_resetn("resetn"); |
---|
65 | |
---|
66 | soclib::caba::VciSignals<vci_param> * signal_vci_ini_synth = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_ini_synth", N_CLUSTERS); |
---|
67 | soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c0 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals", 2, Y_MAX, X_MAX, 5 ); |
---|
68 | soclib::caba::DspinSignals<WIDTH_CMD> **** dspin_signals_cmd_c1 = soclib::common::alloc_elems<solib::caba::DspinSignals<WIDTH_CMD> >("Dspin_cmd_signals", 2, Y_MAX, X_MAX, 5 ); |
---|
69 | |
---|
70 | //soclib::caba::VciSignals<vci_param> * signal_vci_tgt_proc = soclib::common::alloc_elems<soclib::caba::VciSignals<vci_param> >("signal_vci_tgt_proc", N_CLUSTERS); |
---|
71 | |
---|
72 | // N_CLUSTERS ring. |
---|
73 | soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> * local_ring = (soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> *) malloc(sizeof(soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ) * N_CLUSTERS) ; |
---|
74 | for(int i = 0 ; i < N_CLUSTERS ; i++){ // ringid, fifo, fifo, nb_init, nb_tgt |
---|
75 | new(&local_ring[i]) soclib::caba::VciLocalRingFast<vci_param, WIDTH_CMD, WIDTH_RSP> ("cluster" + i,maptab, IntTab(i), 2, 18, 1, 1) |
---|
76 | } |
---|
77 | |
---|
78 | // Virtual dspin routers |
---|
79 | soclib::caba::VirtualDspinRouter<WIDTH_CMD> ** routers_cmd = (soclib::caba::VirtualDspinRouter<WIDTH_CMD> **) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_CMD> *) * Y_MAX); |
---|
80 | soclib::caba::VirtualDspinRouter<WIDTH_RSP> ** routers_rsp = (soclib::caba::VirtualDspinRouter<WIDTH_RSP> **) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_RSP> *) * Y_MAX); |
---|
81 | |
---|
82 | for(int i = 0; i < Y_MAX; i++ ){ |
---|
83 | routers_cmd[i] = (soclib::caba::VirtualDspinRouter<WIDTH_CMD> * ) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_CMD>) * X_MAX); |
---|
84 | routers_rsp[i] = (soclib::caba::VirtualDspinRouter<WIDTH_RSP> * ) malloc(sizeof(soclib::caba::VirtualDspinRouter<WIDTH_RSP>) * X_MAX); |
---|
85 | for(int j = 0; j < X_MAX; i++){ |
---|
86 | 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); |
---|
87 | 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); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | /////////////////////////////////////////////////////////////// |
---|
93 | // Components |
---|
94 | /////////////////////////////////////////////////////////////// |
---|
95 | |
---|
96 | // N_CLUSTERS VCI Synthetic Initiator (1 initiator per cluster/network) |
---|
97 | soclib::caba::VciSyntheticInitiator<vci_param> * initiator = (soclib::caba::VciSyntheticInitiator<vci_param> *) malloc(sizeof(soclib::caba::VciSyntheticInitiator<vci_param> )* N_CLUSTERS); |
---|
98 | for(int i = 0 ; i < Y_MAX; i++) |
---|
99 | for(int j = 0 ; j < Y_MAX ; j++) |
---|
100 | new(&initiator[Y_MAX*i+j]) soclib::caba::VciSyntheticInitiator<vci_param> ("Initiator" + (Y_MAX*i+j), Y_MAX*i+j, maptab, IntTab(i,j),); |
---|
101 | |
---|
102 | /////////////////////////////////////////////////////////////// |
---|
103 | // Connection of Synthetic Initiator to each local ring per cluster |
---|
104 | /////////////////////////////////////////////////////////////// |
---|
105 | for(int i = 0 ; i < N_CLUSTERS ; i++){ |
---|
106 | local_ring[i].p_clk(signal_clk); |
---|
107 | local_ring[i].p_resetn(signal_resetn); |
---|
108 | local_ring[i].p_to_initiator[0](signal_vci_ini_synth[i]); |
---|
109 | initiator[i].p_clk(signal_clk); |
---|
110 | initiator[i].p_resetn(signal_resetn); |
---|
111 | initiator[i].p_vci(signal_vci_ini_synth[i]); |
---|
112 | } |
---|
113 | |
---|
114 | /////////////////////////////////////////////////////////////// |
---|
115 | // Connection of each VDspin Router to each local ring |
---|
116 | /////////////////////////////////////////////////////////////// |
---|
117 | for(int i = 0; i < Y_MAX ; i++){ |
---|
118 | for(int j = 0; j < X_MAX ; j++){ |
---|
119 | routers_cmd[i][j].p_clk(signal_clk); |
---|
120 | routers_cmd[i][j].p_resetn(signal_resetn); |
---|
121 | for(k = 0; k < 5; k++){ |
---|
122 | if(i == 0){ |
---|
123 | if(j == 0){ |
---|
124 | routers_cmd[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]); |
---|
125 | routers_cmd[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]); |
---|
126 | routers_cmd[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]); |
---|
127 | routers_cmd[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]); |
---|
128 | routers_rsp[i][j].p_out[0][k](dspin_signals_cmd_c0[0][i][j][k]); |
---|
129 | routers_rsp[i][j].p_out[1][k](dspin_signals_cmd_c1[0][i][j][k]); |
---|
130 | routers_rsp[i][j].p_in[0][k](dspin_signals_cmd_c0[1][i][j][k]); |
---|
131 | routers_rsp[i][j].p_in[1][k](dspin_signals_cmd_c1[1][i][j][k]); |
---|
132 | } else { |
---|
133 | |
---|
134 | } |
---|
135 | } else { |
---|
136 | |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | //////////////////////////////////////////////////////// |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | //////////////////////////////////////////////// |
---|
147 | // Simulation Loop // |
---|
148 | //////////////////////////////////////////////// |
---|
149 | int ncycles; |
---|
150 | |
---|
151 | if (argc == 2) { |
---|
152 | ncycles = std::atoi(argv[1]); |
---|
153 | } else { |
---|
154 | std::cerr |
---|
155 | << std::endl |
---|
156 | << "The number of simulation cycles must " |
---|
157 | "be defined in the command line" |
---|
158 | << std::endl; |
---|
159 | exit(1); |
---|
160 | } |
---|
161 | |
---|
162 | sc_start(sc_core::sc_time(0, SC_NS)); |
---|
163 | signal_resetn = false; |
---|
164 | |
---|
165 | sc_start(sc_core::sc_time(1, SC_NS)); |
---|
166 | signal_resetn = true; |
---|
167 | |
---|
168 | for (int i = 0; i < ncycles ; i+=100000) { |
---|
169 | sc_start(sc_core::sc_time(100000, SC_NS)); |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | std::cout << "Hit ENTER to end simulation" << std::endl; |
---|
174 | char buf[1]; |
---|
175 | |
---|
176 | std::cin.getline(buf,1); |
---|
177 | return EXIT_SUCCESS; |
---|
178 | } |
---|
179 | |
---|
180 | int sc_main (int argc, char *argv[]) |
---|
181 | { |
---|
182 | try { |
---|
183 | return _main(argc, argv); |
---|
184 | } catch (std::exception &e) { |
---|
185 | std::cout << e.what() << std::endl; |
---|
186 | } catch (...) { |
---|
187 | std::cout << "Unknown exception occured" << std::endl; |
---|
188 | throw; |
---|
189 | } |
---|
190 | return 1; |
---|
191 | } |
---|