mem-garnet: Integration of HeteroGarnet
[gem5.git] / src / mem / ruby / network / garnet2.0 / GarnetNetwork.hh
1 /*
2 * Copyright (c) 2020 Advanced Micro Devices, Inc.
3 * Copyright (c) 2008 Princeton University
4 * Copyright (c) 2016 Georgia Institute of Technology
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;
11 * redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution;
14 * neither the name of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32 #ifndef __MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__
33 #define __MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__
34
35 #include <iostream>
36 #include <vector>
37
38 #include "mem/ruby/network/Network.hh"
39 #include "mem/ruby/network/fault_model/FaultModel.hh"
40 #include "mem/ruby/network/garnet2.0/CommonTypes.hh"
41 #include "params/GarnetNetwork.hh"
42
43 class FaultModel;
44 class NetworkInterface;
45 class Router;
46 class NetDest;
47 class NetworkLink;
48 class CreditLink;
49
50 class GarnetNetwork : public Network
51 {
52 public:
53 typedef GarnetNetworkParams Params;
54 GarnetNetwork(const Params *p);
55 ~GarnetNetwork() = default;
56
57 void init();
58
59 // Configuration (set externally)
60
61 // for 2D topology
62 int getNumRows() const { return m_num_rows; }
63 int getNumCols() { return m_num_cols; }
64
65 // for network
66 uint32_t getNiFlitSize() const { return m_ni_flit_size; }
67 uint32_t getVCsPerVnet() const { return m_vcs_per_vnet; }
68 uint32_t getBuffersPerDataVC() { return m_buffers_per_data_vc; }
69 uint32_t getBuffersPerCtrlVC() { return m_buffers_per_ctrl_vc; }
70 int getRoutingAlgorithm() const { return m_routing_algorithm; }
71
72 bool isFaultModelEnabled() const { return m_enable_fault_model; }
73 FaultModel* fault_model;
74
75
76 // Internal configuration
77 bool isVNetOrdered(int vnet) const { return m_ordered[vnet]; }
78 VNET_type
79 get_vnet_type(int vc)
80 {
81 int vnet = vc/getVCsPerVnet();
82 return m_vnet_type[vnet];
83 }
84 int getNumRouters();
85 int get_router_id(int ni, int vnet);
86
87
88 // Methods used by Topology to setup the network
89 void makeExtOutLink(SwitchID src, NodeID dest, BasicLink* link,
90 std::vector<NetDest>& routing_table_entry);
91 void makeExtInLink(NodeID src, SwitchID dest, BasicLink* link,
92 std::vector<NetDest>& routing_table_entry);
93 void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
94 std::vector<NetDest>& routing_table_entry,
95 PortDirection src_outport_dirn,
96 PortDirection dest_inport_dirn);
97
98 //! Function for performing a functional write. The return value
99 //! indicates the number of messages that were written.
100 uint32_t functionalWrite(Packet *pkt);
101
102 // Stats
103 void collateStats();
104 void regStats();
105 void resetStats();
106 void print(std::ostream& out) const;
107
108 // increment counters
109 void increment_injected_packets(int vnet) { m_packets_injected[vnet]++; }
110 void increment_received_packets(int vnet) { m_packets_received[vnet]++; }
111
112 void
113 increment_packet_network_latency(Tick latency, int vnet)
114 {
115 m_packet_network_latency[vnet] += latency;
116 }
117
118 void
119 increment_packet_queueing_latency(Tick latency, int vnet)
120 {
121 m_packet_queueing_latency[vnet] += latency;
122 }
123
124 void increment_injected_flits(int vnet) { m_flits_injected[vnet]++; }
125 void increment_received_flits(int vnet) { m_flits_received[vnet]++; }
126
127 void
128 increment_flit_network_latency(Tick latency, int vnet)
129 {
130 m_flit_network_latency[vnet] += latency;
131 }
132
133 void
134 increment_flit_queueing_latency(Tick latency, int vnet)
135 {
136 m_flit_queueing_latency[vnet] += latency;
137 }
138
139 void
140 increment_total_hops(int hops)
141 {
142 m_total_hops += hops;
143 }
144
145 protected:
146 // Configuration
147 int m_num_rows;
148 int m_num_cols;
149 uint32_t m_ni_flit_size;
150 uint32_t m_vcs_per_vnet;
151 uint32_t m_buffers_per_ctrl_vc;
152 uint32_t m_buffers_per_data_vc;
153 int m_routing_algorithm;
154 bool m_enable_fault_model;
155
156 // Statistical variables
157 Stats::Vector m_packets_received;
158 Stats::Vector m_packets_injected;
159 Stats::Vector m_packet_network_latency;
160 Stats::Vector m_packet_queueing_latency;
161
162 Stats::Formula m_avg_packet_vnet_latency;
163 Stats::Formula m_avg_packet_vqueue_latency;
164 Stats::Formula m_avg_packet_network_latency;
165 Stats::Formula m_avg_packet_queueing_latency;
166 Stats::Formula m_avg_packet_latency;
167
168 Stats::Vector m_flits_received;
169 Stats::Vector m_flits_injected;
170 Stats::Vector m_flit_network_latency;
171 Stats::Vector m_flit_queueing_latency;
172
173 Stats::Formula m_avg_flit_vnet_latency;
174 Stats::Formula m_avg_flit_vqueue_latency;
175 Stats::Formula m_avg_flit_network_latency;
176 Stats::Formula m_avg_flit_queueing_latency;
177 Stats::Formula m_avg_flit_latency;
178
179 Stats::Scalar m_total_ext_in_link_utilization;
180 Stats::Scalar m_total_ext_out_link_utilization;
181 Stats::Scalar m_total_int_link_utilization;
182 Stats::Scalar m_average_link_utilization;
183 Stats::Vector m_average_vc_load;
184
185 Stats::Scalar m_total_hops;
186 Stats::Formula m_avg_hops;
187
188 private:
189 GarnetNetwork(const GarnetNetwork& obj);
190 GarnetNetwork& operator=(const GarnetNetwork& obj);
191
192 std::vector<VNET_type > m_vnet_type;
193 std::vector<Router *> m_routers; // All Routers in Network
194 std::vector<NetworkLink *> m_networklinks; // All flit links in the network
195 std::vector<CreditLink *> m_creditlinks; // All credit links in the network
196 std::vector<NetworkInterface *> m_nis; // All NI's in Network
197 };
198
199 inline std::ostream&
200 operator<<(std::ostream& out, const GarnetNetwork& obj)
201 {
202 obj.print(out);
203 out << std::flush;
204 return out;
205 }
206
207 #endif //__MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__