gem5 v24.0.0.0
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);
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 m_fromNetQueues[local_dest].resize(num_vnets, nullptr);
121
122 m_switches[src]->addOutPort(m_fromNetQueues[local_dest],
123 routing_table_entry[0],
124 simple_link->m_latency, 0,
125 simple_link->m_bw_multiplier, true);
126}
127
128// From an endpoint node to a switch
129void
131 std::vector<NetDest>& routing_table_entry)
132{
133 NodeID local_src = getLocalNodeID(global_src);
134 assert(local_src < m_nodes);
135 m_switches[dest]->addInPort(m_toNetQueues[local_src]);
136}
137
138// From a switch to a switch
139void
141 std::vector<NetDest>& routing_table_entry,
142 PortDirection src_outport,
143 PortDirection dst_inport)
144{
145 // Connect it to the two switches
146 SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
147
148 m_switches[dest]->addInPort(simple_link->m_buffers);
149 m_switches[src]->addOutPort(simple_link->m_buffers, routing_table_entry[0],
150 simple_link->m_latency,
151 simple_link->m_weight,
152 simple_link->m_bw_multiplier,
153 false,
154 dst_inport);
155 // Maitain a global list of buffers (used for functional accesses only)
157 simple_link->m_buffers.begin(), simple_link->m_buffers.end());
158}
159
160void
162{
164
165 for (MessageSizeType type = MessageSizeType_FIRST;
166 type < MessageSizeType_NUM; ++type) {
167 networkStats.m_msg_counts[(unsigned int) type] =
169 csprintf("msg_count.%s", MessageSizeType_to_string(type)).c_str());
170 networkStats.m_msg_counts[(unsigned int) type]
172 ;
173
174 networkStats.m_msg_bytes[(unsigned int) type] =
176 csprintf("msg_byte.%s", MessageSizeType_to_string(type)).c_str());
177 networkStats.m_msg_bytes[(unsigned int) type]
179 ;
180
181 // Now state what the formula is.
182 for (auto& it : m_switches) {
183 *(networkStats.m_msg_counts[(unsigned int) type]) +=
184 sum(it.second->getMsgCount(type));
185 }
186
187 *(networkStats.m_msg_bytes[(unsigned int) type]) =
188 *(networkStats.m_msg_counts[(unsigned int) type]) *
190 }
191}
192
193void
195{
196 for (auto& it : m_switches) {
197 it.second->collateStats();
198 }
199}
200
201void
202SimpleNetwork::print(std::ostream& out) const
203{
204 out << "[SimpleNetwork]";
205}
206
207/*
208 * The simple network has an array of switches. These switches have buffers
209 * that need to be accessed for functional reads and writes. Also the links
210 * between different switches have buffers that need to be accessed.
211 */
212bool
214{
215 for (auto& it : m_switches) {
216 if (it.second->functionalRead(pkt))
217 return true;
218 }
219 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
221 return true;
222 }
223
224 return false;
225}
226
227bool
229{
230 bool read = false;
231 for (auto& it : m_switches) {
232 if (it.second->functionalRead(pkt, mask))
233 read = true;
234 }
235 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
237 read = true;
238 }
239 return read;
240}
241
242uint32_t
244{
245 uint32_t num_functional_writes = 0;
246
247 for (auto& it : m_switches) {
248 num_functional_writes += it.second->functionalWrite(pkt);
249 }
250
251 for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
252 num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
253 }
254 return num_functional_writes;
255}
256
259 : statistics::Group(parent)
260{
261
262}
263
264} // namespace ruby
265} // namespace gem5
ClockedObjectParams Params
Parameters of ClockedObject.
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:158
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition Network.cc:164
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition Network.hh:164
NodeID getLocalNodeID(NodeID global_id) const
Definition Network.cc:253
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition Network.hh:163
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)
void createLinks(Network *net)
Definition Topology.cc:115
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:236
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition logging.hh:317
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
uint8_t flags
Definition helpers.cc:87
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 4 > s
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 33 > id
Bitfield< 0 > p
Bitfield< 18 > sum
Definition misc.hh:1198
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 - Pranith Kumar Copyright (c) 2020 Inria 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
statistics::Formula * m_msg_bytes[MessageSizeType_NUM]
NetworkStats(statistics::Group *parent)
statistics::Formula * m_msg_counts[MessageSizeType_NUM]

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0