Topology.hh revision 11096
16184SN/A/*
26184SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36184SN/A * All rights reserved.
46184SN/A *
56184SN/A * Redistribution and use in source and binary forms, with or without
66184SN/A * modification, are permitted provided that the following conditions are
76184SN/A * met: redistributions of source code must retain the above copyright
86184SN/A * notice, this list of conditions and the following disclaimer;
96184SN/A * redistributions in binary form must reproduce the above copyright
106184SN/A * notice, this list of conditions and the following disclaimer in the
116184SN/A * documentation and/or other materials provided with the distribution;
126184SN/A * neither the name of the copyright holders nor the names of its
136184SN/A * contributors may be used to endorse or promote products derived from
146184SN/A * this software without specific prior written permission.
156184SN/A *
166184SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176184SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186184SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196184SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206184SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216184SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226184SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236184SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246184SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256184SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266184SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276184SN/A */
286184SN/A
296184SN/A/*
306184SN/A * The topology here is configurable; it can be a hierachical (default
3111793Sbrandon.potter@amd.com * one) or a 2D torus or a 2D torus with half switches killed. I think
3211793Sbrandon.potter@amd.com * all input port has a one-input-one-output switch connected just to
336184SN/A * control and bandwidth, since we don't control bandwidth on input
346184SN/A * ports.  Basically, the class has a vector of nodes and edges. First
356184SN/A * 2*m_nodes elements in the node vector are input and output
368232Snate@binkert.org * ports. Edges are represented in two vectors of src and dest
376184SN/A * nodes. All edges have latency.
3810785Sgope@wisc.edu */
399480Snilay@cs.wisc.edu
409480Snilay@cs.wisc.edu#ifndef __MEM_RUBY_NETWORK_TOPOLOGY_HH__
4110785Sgope@wisc.edu#define __MEM_RUBY_NETWORK_TOPOLOGY_HH__
426184SN/A
436184SN/A#include <iostream>
446184SN/A#include <string>
456184SN/A#include <vector>
466184SN/A
476184SN/A#include "mem/protocol/LinkDirection.hh"
486184SN/A#include "mem/ruby/common/TypeDefines.hh"
496184SN/A#include "mem/ruby/network/BasicLink.hh"
506184SN/A
516184SN/Aclass NetDest;
526184SN/Aclass Network;
536184SN/A
546184SN/Atypedef std::vector<std::vector<int> > Matrix;
556184SN/A
569480Snilay@cs.wisc.edustruct LinkEntry
576184SN/A{
586184SN/A    BasicLink *link;
596184SN/A    LinkDirection direction;
606184SN/A};
616227Snate@binkert.org
629480Snilay@cs.wisc.edutypedef std::map<std::pair<SwitchID, SwitchID>, LinkEntry> LinkMap;
636184SN/A
649480Snilay@cs.wisc.educlass Topology
656184SN/A{
666184SN/A  public:
679480Snilay@cs.wisc.edu    Topology(uint32_t num_routers, const std::vector<BasicExtLink *> &ext_links,
686184SN/A             const std::vector<BasicIntLink *> &int_links);
699480Snilay@cs.wisc.edu
706184SN/A    uint32_t numSwitches() const { return m_number_of_switches; }
716184SN/A    void createLinks(Network *net);
726184SN/A    void print(std::ostream& out) const { out << "[Topology]"; }
736184SN/A
746184SN/A  private:
756184SN/A    void addLink(SwitchID src, SwitchID dest, BasicLink* link,
766227Snate@binkert.org                 LinkDirection dir);
776184SN/A    void makeLink(Network *net, SwitchID src, SwitchID dest,
786184SN/A                  const NetDest& routing_table_entry);
796184SN/A
806184SN/A    // Helper functions based on chapter 29 of Cormen et al.
818842Smrinmoy.ghosh@arm.com    void extend_shortest_path(Matrix &current_dist, Matrix &latencies,
8211434Smitch.hayenga@arm.com                              Matrix &inter_switches);
838842Smrinmoy.ghosh@arm.com
848842Smrinmoy.ghosh@arm.com    std::vector<std::vector<int>> shortest_path(const Matrix &weights,
858842Smrinmoy.ghosh@arm.com            Matrix &latencies, Matrix &inter_switches);
868842Smrinmoy.ghosh@arm.com
878842Smrinmoy.ghosh@arm.com    bool link_is_shortest_path_to_node(SwitchID src, SwitchID next,
888842Smrinmoy.ghosh@arm.com            SwitchID final, const Matrix &weights, const Matrix &dist);
896184SN/A
9011434Smitch.hayenga@arm.com    NetDest shortest_path_to_node(SwitchID src, SwitchID next,
916184SN/A                                  const Matrix &weights, const Matrix &dist);
926184SN/A
936184SN/A    const uint32_t m_nodes;
946184SN/A    const uint32_t m_number_of_switches;
956184SN/A
969480Snilay@cs.wisc.edu    std::vector<BasicExtLink*> m_ext_link_vector;
976184SN/A    std::vector<BasicIntLink*> m_int_link_vector;
986184SN/A
996184SN/A    LinkMap m_link_map;
1006184SN/A};
1019480Snilay@cs.wisc.edu
1026184SN/Ainline std::ostream&
1036184SN/Aoperator<<(std::ostream& out, const Topology& obj)
1046184SN/A{
1056184SN/A    obj.print(out);
1066184SN/A    out << std::flush;
1076184SN/A    return out;
1086184SN/A}
1099480Snilay@cs.wisc.edu
1106184SN/A#endif // __MEM_RUBY_NETWORK_TOPOLOGY_HH__
1116184SN/A