gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
SimpleNetwork.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Advanced Micro Devices, Inc.
3 * Copyright (c) 2019,2021 ARM Limited
4 * All rights reserved.
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
43
44#include <cassert>
45#include <numeric>
46
47#include "base/cast.hh"
54
55namespace gem5
56{
57
58namespace ruby
59{
60
62 : Network(p), m_buffer_size(p.buffer_size),
63 m_endpoint_bandwidth(p.endpoint_bandwidth),
64 networkStats(this)
65{
66 // record the routers
67 for (std::vector<BasicRouter*>::const_iterator i = p.routers.begin();
68 i != p.routers.end(); ++i) {
69 auto* s = safe_cast<Switch*>(*i);
70 s->init_net_ptr(this);
71 auto id = static_cast<size_t>(s->params().router_id);
72 m_switches[id] = s;
73 }
74
75 const std::vector<int> &physical_vnets_channels =
76 p.physical_vnets_channels;
77 const std::vector<int> &physical_vnets_bandwidth =
78 p.physical_vnets_bandwidth;
79 bool physical_vnets = physical_vnets_channels.size() > 0;
80 int vnets = p.number_of_virtual_networks;
81
82 fatal_if(physical_vnets && (physical_vnets_channels.size() != vnets),
83 "physical_vnets_channels must provide channel count for all vnets");
84
85 fatal_if(!physical_vnets && (physical_vnets_bandwidth.size() != 0),
86 "physical_vnets_bandwidth also requires physical_vnets_channels");
87
88 fatal_if((physical_vnets_bandwidth.size() != vnets) &&
89 (physical_vnets_bandwidth.size() != 0),
90 "physical_vnets_bandwidth must provide BW for all vnets");
91}
92
93void
95{
97
98 // The topology pointer should have already been initialized in
99 // the parent class network constructor.
100 assert(m_topology_ptr != NULL);
101 m_topology_ptr->createLinks(this);
102}
103
104// From a switch to an endpoint node
105void
107 BasicLink* link,
108 std::vector<NetDest>& routing_table_entry)
109{
110 NodeID local_dest = getLocalNodeID(global_dest);
111 assert(local_dest < m_nodes);
112 assert(m_switches[src] != NULL);
113
114 SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
115
116 // some destinations don't use all vnets, but Switch requires the size
117 // output buffer list to match the number of vnets
118 int num_vnets = params().number_of_virtual_networks;
119 gem5_assert(num_vnets >= m_fromNetQueues[local_dest].size(),
120 "SimpleNetwork::makeExtOutLink");
121 m_fromNetQueues[local_dest].resize(num_vnets, nullptr);
122
123 m_switches[src]->addOutPort(simple_link->name(),
124 m_fromNetQueues[local_dest],
125 routing_table_entry[0],
126 simple_link->m_latency, 0,
127 simple_link->m_bw_multiplier, true);
128}
129
130// From an endpoint node to a switch
131void
133 std::vector<NetDest>& routing_table_entry)
134{
135 NodeID local_src = getLocalNodeID(global_src);
136 assert(local_src < m_nodes);
137 m_switches[dest]->addInPort(m_toNetQueues[local_src]);
138}
139
140// From a switch to a switch
141void
143 std::vector<NetDest>& routing_table_entry,
144 PortDirection src_outport,
145 PortDirection dst_inport)
146{
147 // Connect it to the two switches
148 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
149
150 m_switches[dest]->addInPort(simple_link->m_buffers);
151 m_switches[src]->addOutPort(simple_link->name(),
152 simple_link->m_buffers, routing_table_entry[0],
153 simple_link->m_latency,
154 simple_link->m_weight,
155 simple_link->m_bw_multiplier,
156 false,
157 dst_inport);
158 // Maitain a global list of buffers (used for functional accesses only)
160 simple_link->m_buffers.begin(), simple_link->m_buffers.end());
161}
162
163void
165{
167
168 for (MessageSizeType type = MessageSizeType_FIRST;
169 type < MessageSizeType_NUM; ++type) {
170 networkStats.m_msg_counts[(unsigned int) type] =
172 csprintf("msg_count.%s", MessageSizeType_to_string(type)).c_str());
173 networkStats.m_msg_counts[(unsigned int) type]
174 ->flags(statistics::nozero)
175 ;
176
177 networkStats.m_msg_bytes[(unsigned int) type] =
179 csprintf("msg_byte.%s", MessageSizeType_to_string(type)).c_str());
180 networkStats.m_msg_bytes[(unsigned int) type]
181 ->flags(statistics::nozero)
182 ;
183
184 // Now state what the formula is.
185 for (auto& it : m_switches) {
186 *(networkStats.m_msg_counts[(unsigned int) type]) +=
187 sum(it.second->getMsgCount(type));
188 }
189
190 *(networkStats.m_msg_bytes[(unsigned int) type]) =
191 *(networkStats.m_msg_counts[(unsigned int) type]) *
193 }
194}
195
196void
198{
199 for (auto& it : m_switches) {
200 it.second->collateStats();
201 }
202}
203
204void
205SimpleNetwork::print(std::ostream& out) const
206{
207 out << "[SimpleNetwork]";
208}
209
210/*
211 * The simple network has an array of switches. These switches have buffers
212 * that need to be accessed for functional reads and writes. Also the links
213 * between different switches have buffers that need to be accessed.
214 */
215bool
217{
218 for (auto& it : m_switches) {
219 if (it.second->functionalRead(pkt))
220 return true;
221 }
222 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
224 return true;
225 }
226
227 return false;
228}
229
230bool
232{
233 bool read = false;
234 for (auto& it : m_switches) {
235 if (it.second->functionalRead(pkt, mask))
236 read = true;
237 }
238 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
240 read = true;
241 }
242 return read;
243}
244
245uint32_t
247{
248 uint32_t num_functional_writes = 0;
249
250 for (auto& it : m_switches) {
251 num_functional_writes += it.second->functionalWrite(pkt);
252 }
253
254 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
255 num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
256 }
257 return num_functional_writes;
258}
259
266
267} // namespace ruby
268} // namespace gem5
ClockedObjectParams Params
Parameters of ClockedObject.
virtual std::string name() const
Definition named.hh:60
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Topology * m_topology_ptr
Definition Network.hh:163
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition Network.cc:166
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition Network.hh:169
NodeID getLocalNodeID(NodeID global_id) const
Definition Network.cc:255
Network(const Params &p)
Definition Network.cc:58
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition Network.hh:168
void regStats()
Callback to set stat parameters.
void print(std::ostream &out) const
std::vector< MessageBuffer * > m_int_link_buffers
void makeInternalLink(SwitchID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry, PortDirection src_outport, PortDirection dst_inport)
std::unordered_map< int, Switch * > m_switches
bool functionalRead(Packet *pkt)
uint32_t functionalWrite(Packet *pkt)
void makeExtOutLink(SwitchID src, NodeID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
gem5::ruby::SimpleNetwork::NetworkStats networkStats
SimpleNetwork(const Params &p)
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
STL vector class.
Definition stl.hh:37
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition logging.hh:268
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition logging.hh:349
const Params & params() const
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition sim_object.cc:73
virtual void regStats()
Callback to set stat parameters.
Definition group.cc:68
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Bitfield< 18 > sum
Definition misc.hh:1346
unsigned int SwitchID
std::string PortDirection
unsigned int NodeID
const FlagsType nozero
Don't print if this is zero.
Definition info.hh:67
Temp constant(T val)
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
T safe_cast(U &&ref_or_ptr)
Definition cast.hh:74
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
NetworkStats(statistics::Group *parent)

Generated on Mon Oct 27 2025 04:13:03 for gem5 by doxygen 1.14.0