gem5  v22.0.0.2
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 
55 namespace gem5
56 {
57 
58 namespace 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 
93 void
95 {
96  Network::init();
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
105 void
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
129 void
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
139 void
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 
160 void
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 
193 void
195 {
196  for (auto& it : m_switches) {
197  it.second->collateStats();
198  }
199 }
200 
201 void
202 SimpleNetwork::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  */
212 bool
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 
227 bool
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 
242 uint32_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
gem5::ruby::SimpleNetwork::print
void print(std::ostream &out) const
Definition: SimpleNetwork.cc:202
gem5::VegaISA::s
Bitfield< 1 > s
Definition: pagetable.hh:64
gem5::ruby::SimpleNetwork::NetworkStats::m_msg_bytes
statistics::Formula * m_msg_bytes[MessageSizeType_NUM]
Definition: SimpleNetwork.hh:117
gem5::ruby::WriteMask
Definition: WriteMask.hh:59
Profiler.hh
gem5::ruby::PortDirection
std::string PortDirection
Definition: TypeDefines.hh:44
gem5::ruby::Network::MessageSizeType_to_int
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:164
gem5::ruby::SimpleNetwork::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: SimpleNetwork.cc:94
gem5::ruby::SimpleNetwork::networkStats
gem5::ruby::SimpleNetwork::NetworkStats networkStats
gem5::ruby::SimpleNetwork::makeExtInLink
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
Definition: SimpleNetwork.cc:130
gem5::statistics::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:68
gem5::ruby::Network
Definition: Network.hh:82
gem5::SimObject::init
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: sim_object.cc:76
gem5::ruby::Topology::createLinks
void createLinks(Network *net)
Definition: Topology.cc:115
cast.hh
SimpleNetwork.hh
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2539
std::vector
STL vector class.
Definition: stl.hh:37
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
Throttle.hh
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::statistics::constant
Temp constant(T val)
Definition: statistics.hh:2865
gem5::ruby::SimpleNetwork::m_switches
std::unordered_map< int, Switch * > m_switches
Definition: SimpleNetwork.hh:105
gem5::ruby::SimpleNetwork::NetworkStats::NetworkStats
NetworkStats(statistics::Group *parent)
Definition: SimpleNetwork.cc:258
gem5::ruby::SimpleNetwork::m_int_link_buffers
std::vector< MessageBuffer * > m_int_link_buffers
Definition: SimpleNetwork.hh:106
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::ruby::Network::m_nodes
uint32_t m_nodes
Definition: Network.hh:155
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::ruby::SimpleNetwork::regStats
void regStats()
Callback to set stat parameters.
Definition: SimpleNetwork.cc:161
gem5::X86ISA::type
type
Definition: misc.hh:727
gem5::ruby::Network::getLocalNodeID
NodeID getLocalNodeID(NodeID global_id) const
Definition: Network.cc:253
gem5::ruby::Network::m_fromNetQueues
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:164
flags
uint8_t flags
Definition: helpers.cc:66
gem5::ruby::SwitchID
unsigned int SwitchID
Definition: TypeDefines.hh:43
gem5::ruby::SimpleNetwork::makeExtOutLink
void makeExtOutLink(SwitchID src, NodeID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
Definition: SimpleNetwork.cc:106
gem5::statistics::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:69
gem5::ruby::Network::m_toNetQueues
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:163
MessageBuffer.hh
gem5::ruby::SimpleNetwork::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: SimpleNetwork.cc:243
gem5::ruby::Network::m_topology_ptr
Topology * m_topology_ptr
Definition: Network.hh:158
Switch.hh
gem5::ruby::SimpleNetwork::functionalRead
bool functionalRead(Packet *pkt)
Definition: SimpleNetwork.cc:213
gem5::ruby::SimpleNetwork::NetworkStats::m_msg_counts
statistics::Formula * m_msg_counts[MessageSizeType_NUM]
Definition: SimpleNetwork.hh:116
gem5::ruby::SimpleNetwork::collateStats
void collateStats()
Definition: SimpleNetwork.cc:194
gem5::ruby::SimpleNetwork::SimpleNetwork
SimpleNetwork(const Params &p)
Definition: SimpleNetwork.cc:61
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::ArmISA::id
Bitfield< 33 > id
Definition: misc_types.hh:251
gem5::ruby::NodeID
unsigned int NodeID
Definition: TypeDefines.hh:42
gem5::RiscvISA::sum
Bitfield< 18 > sum
Definition: misc.hh:555
gem5::ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:240
gem5_assert
#define gem5_assert(cond,...)
The assert macro will function like a normal assert, but will use panic instead of straight abort().
Definition: logging.hh:318
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::ruby::SimpleNetwork::makeInternalLink
void makeInternalLink(SwitchID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry, PortDirection src_outport, PortDirection dst_inport)
Definition: SimpleNetwork.cc:140
NetDest.hh

Generated on Thu Jul 28 2022 13:32:35 for gem5 by doxygen 1.8.17