2 * Copyright (c) 2020 Advanced Micro Devices, Inc.
3 * Copyright (c) 2008 Princeton University
4 * Copyright (c) 2016 Georgia Institute of Technology
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.
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.
32 #ifndef __MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__
33 #define __MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__
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"
44 class NetworkInterface;
50 class GarnetNetwork : public Network
53 typedef GarnetNetworkParams Params;
54 GarnetNetwork(const Params *p);
55 ~GarnetNetwork() = default;
59 // Configuration (set externally)
62 int getNumRows() const { return m_num_rows; }
63 int getNumCols() { return m_num_cols; }
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; }
72 bool isFaultModelEnabled() const { return m_enable_fault_model; }
73 FaultModel* fault_model;
76 // Internal configuration
77 bool isVNetOrdered(int vnet) const { return m_ordered[vnet]; }
81 int vnet = vc/getVCsPerVnet();
82 return m_vnet_type[vnet];
85 int get_router_id(int ni, int vnet);
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);
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);
106 void print(std::ostream& out) const;
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]++; }
113 increment_packet_network_latency(Tick latency, int vnet)
115 m_packet_network_latency[vnet] += latency;
119 increment_packet_queueing_latency(Tick latency, int vnet)
121 m_packet_queueing_latency[vnet] += latency;
124 void increment_injected_flits(int vnet) { m_flits_injected[vnet]++; }
125 void increment_received_flits(int vnet) { m_flits_received[vnet]++; }
128 increment_flit_network_latency(Tick latency, int vnet)
130 m_flit_network_latency[vnet] += latency;
134 increment_flit_queueing_latency(Tick latency, int vnet)
136 m_flit_queueing_latency[vnet] += latency;
140 increment_total_hops(int hops)
142 m_total_hops += hops;
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;
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;
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;
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;
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;
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;
185 Stats::Scalar m_total_hops;
186 Stats::Formula m_avg_hops;
189 GarnetNetwork(const GarnetNetwork& obj);
190 GarnetNetwork& operator=(const GarnetNetwork& obj);
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
200 operator<<(std::ostream& out, const GarnetNetwork& obj)
207 #endif //__MEM_RUBY_NETWORK_GARNET2_0_GARNETNETWORK_HH__