gem5  v20.1.0.0
Topology.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Advanced Micro Devices, Inc.
3  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * The topology here is configurable; it can be a hierachical (default
32  * one) or a 2D torus or a 2D torus with half switches killed. I think
33  * all input port has a one-input-one-output switch connected just to
34  * control and bandwidth, since we don't control bandwidth on input
35  * ports. Basically, the class has a vector of nodes and edges. First
36  * 2*m_nodes elements in the node vector are input and output
37  * ports. Edges are represented in two vectors of src and dest
38  * nodes. All edges have latency.
39  */
40 
41 #ifndef __MEM_RUBY_NETWORK_TOPOLOGY_HH__
42 #define __MEM_RUBY_NETWORK_TOPOLOGY_HH__
43 
44 #include <iostream>
45 #include <string>
46 #include <vector>
47 
50 #include "mem/ruby/protocol/LinkDirection.hh"
51 
52 class NetDest;
53 class Network;
54 
55 /*
56  * We use a three-dimensional vector matrix for calculating
57  * the shortest paths for each pair of source and destination
58  * and for each type of virtual network. The three dimensions
59  * represent the source ID, destination ID, and vnet number.
60  */
62 typedef std::string PortDirection;
63 
64 struct LinkEntry
65 {
69 };
70 
71 typedef std::map<std::pair<SwitchID, SwitchID>,
73 
74 class Topology
75 {
76  public:
77  Topology(uint32_t num_nodes, uint32_t num_routers, uint32_t num_vnets,
78  const std::vector<BasicExtLink *> &ext_links,
79  const std::vector<BasicIntLink *> &int_links);
80 
81  uint32_t numSwitches() const { return m_number_of_switches; }
82  void createLinks(Network *net);
83  void print(std::ostream& out) const { out << "[Topology]"; }
84 
85  private:
86  void addLink(SwitchID src, SwitchID dest, BasicLink* link,
87  PortDirection src_outport_dirn = "",
88  PortDirection dest_inport_dirn = "");
89  void makeLink(Network *net, SwitchID src, SwitchID dest,
90  std::vector<NetDest>& routing_table_entry);
91 
92  // Helper functions based on chapter 29 of Cormen et al.
93  void extend_shortest_path(Matrix &current_dist, Matrix &latencies,
94  Matrix &inter_switches);
95 
96  Matrix shortest_path(const Matrix &weights,
97  Matrix &latencies, Matrix &inter_switches);
98 
100  SwitchID final, const Matrix &weights, const Matrix &dist,
101  int vnet);
102 
104  const Matrix &weights, const Matrix &dist,
105  int vnet);
106 
107  const uint32_t m_nodes;
108  const uint32_t m_number_of_switches;
109  int m_vnets;
110 
113 
115 };
116 
117 inline std::ostream&
118 operator<<(std::ostream& out, const Topology& obj)
119 {
120  obj.print(out);
121  out << std::flush;
122  return out;
123 }
124 
125 #endif // __MEM_RUBY_NETWORK_TOPOLOGY_HH__
Topology::makeLink
void makeLink(Network *net, SwitchID src, SwitchID dest, std::vector< NetDest > &routing_table_entry)
Definition: Topology.cc:246
LinkEntry::link
BasicLink * link
Definition: Topology.hh:66
Topology::extend_shortest_path
void extend_shortest_path(Matrix &current_dist, Matrix &latencies, Matrix &inter_switches)
Definition: Topology.cc:332
Topology::m_nodes
const uint32_t m_nodes
Definition: Topology.hh:107
Topology::print
void print(std::ostream &out) const
Definition: Topology.hh:83
Matrix
std::vector< std::vector< std::vector< int > > > Matrix
Definition: Topology.hh:53
std::vector
STL vector class.
Definition: stl.hh:37
LinkEntry::dst_inport_dirn
PortDirection dst_inport_dirn
Definition: Topology.hh:68
Topology::m_vnets
int m_vnets
Definition: Topology.hh:109
Topology::numSwitches
uint32_t numSwitches() const
Definition: Topology.hh:81
operator<<
std::ostream & operator<<(std::ostream &out, const Topology &obj)
Definition: Topology.hh:118
TypeDefines.hh
LinkEntry
Definition: Topology.hh:64
Topology::m_number_of_switches
const uint32_t m_number_of_switches
Definition: Topology.hh:108
Topology::link_is_shortest_path_to_node
bool link_is_shortest_path_to_node(SwitchID src, SwitchID next, SwitchID final, const Matrix &weights, const Matrix &dist, int vnet)
Definition: Topology.cc:399
Network
Definition: Network.hh:76
Topology::m_link_map
LinkMap m_link_map
Definition: Topology.hh:114
Stats::dist
const FlagsType dist
Print the distribution.
Definition: info.hh:55
Topology::shortest_path
Matrix shortest_path(const Matrix &weights, Matrix &latencies, Matrix &inter_switches)
Definition: Topology.cc:390
Topology::shortest_path_to_node
NetDest shortest_path_to_node(SwitchID src, SwitchID next, const Matrix &weights, const Matrix &dist, int vnet)
Definition: Topology.cc:408
Topology::m_ext_link_vector
std::vector< BasicExtLink * > m_ext_link_vector
Definition: Topology.hh:111
Topology::m_int_link_vector
std::vector< BasicIntLink * > m_int_link_vector
Definition: Topology.hh:112
Topology::createLinks
void createLinks(Network *net)
Definition: Topology.cc:111
LinkEntry::src_outport_dirn
PortDirection src_outport_dirn
Definition: Topology.hh:67
PortDirection
std::string PortDirection
Definition: Topology.hh:62
Topology::Topology
Topology(uint32_t num_nodes, uint32_t num_routers, uint32_t num_vnets, const std::vector< BasicExtLink * > &ext_links, const std::vector< BasicIntLink * > &int_links)
Definition: Topology.cc:52
Topology::addLink
void addLink(SwitchID src, SwitchID dest, BasicLink *link, PortDirection src_outport_dirn="", PortDirection dest_inport_dirn="")
Definition: Topology.cc:214
Topology
Definition: Topology.hh:74
LinkMap
std::map< std::pair< SwitchID, SwitchID >, std::vector< LinkEntry > > LinkMap
Definition: Topology.hh:72
NetDest
Definition: NetDest.hh:39
SwitchID
unsigned int SwitchID
Definition: TypeDefines.hh:35

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17