From 7f49fe9feb174d34efc2a011bad79b38522a360b Mon Sep 17 00:00:00 2001 From: Dongdong Li Date: Thu, 8 Aug 2013 00:15:58 -0800 Subject: Intesim2 Integration Details: See Review 80001 https://gpgpu-sim-code-review.appspot.com/80001/ [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 16747] --- src/intersim2/networks/fattree.cpp | 270 +++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 src/intersim2/networks/fattree.cpp (limited to 'src/intersim2/networks/fattree.cpp') diff --git a/src/intersim2/networks/fattree.cpp b/src/intersim2/networks/fattree.cpp new file mode 100644 index 0000000..81cd2b1 --- /dev/null +++ b/src/intersim2/networks/fattree.cpp @@ -0,0 +1,270 @@ +// $Id: fattree.cpp 5188 2012-08-30 00:31:31Z dub $ + +/* + Copyright (c) 2007-2012, Trustees of The Leland Stanford Junior University + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +//////////////////////////////////////////////////////////////////////// +// +// FatTree +// +// Each level of the hierarchical indirect Network has +// k^(n-1) Routers. The Routers are organized such that +// each node has k descendents, and each parent is +// replicated k times. +// most routers has 2K ports, excep the top level has only K +//////////////////////////////////////////////////////////////////////// +// +// RCS Information: +// $Author: jbalfour $ +// $Date: 2007/06/26 22:50:48 $ +// $Id: fattree.cpp 5188 2012-08-30 00:31:31Z dub $ +// +//////////////////////////////////////////////////////////////////////// + + +#include "booksim.hpp" +#include +#include +#include + +#include "fattree.hpp" +#include "misc_utils.hpp" + + + //#define FATTREE_DEBUG + +FatTree::FatTree( const Configuration& config,const string & name ) + : Network( config ,name) +{ + + + _ComputeSize( config ); + _Alloc( ); + _BuildNet( config ); + +} + +void FatTree::_ComputeSize( const Configuration& config ) +{ + + _k = config.GetInt( "k" ); + _n = config.GetInt( "n" ); + + gK = _k; gN = _n; + + _nodes = powi( _k, _n ); + + //levels * routers_per_level + _size = _n * powi( _k , _n - 1 ); + + //(channels per level = k*routers_per_level* up/down) * (levels-1) + _channels = (2*_k * powi( _k , _n-1 ))*(_n-1); + + +} + + +void FatTree::RegisterRoutingFunctions() { + +} + +void FatTree::_BuildNet( const Configuration& config ) +{ + cout << "Fat Tree" << endl; + cout << " k = " << _k << " levels = " << _n << endl; + cout << " each switch - total radix = "<< 2*_k << endl; + cout << " # of switches = "<< _size << endl; + cout << " # of channels = "<< _channels << endl; + cout << " # of nodes ( size of network ) = " << _nodes << endl; + + + // Number of router positions at each depth of the network + const int nPos = powi( _k, _n-1); + + // + // Allocate Routers + // + ostringstream name; + int level, pos, id, degree, port; + for ( level = 0 ; level < _n ; ++level ) { + for ( pos = 0 ; pos < nPos ; ++pos ) { + + if ( level == 0 ) //top routers is zero + degree = _k; + else + degree = 2 * _k; + + id = level * nPos + pos; + + name.str(""); + name << "router_level" << level << "_" << pos; + Router * r = Router::NewRouter( config, this, name.str( ), id, + degree, degree ); + _Router( level, pos ) = r; + _timed_modules.push_back(r); + } + } + + // + // Connect Channels to Routers + // + + // + // Router Connection Rule: Output Ports =gK Move UP Network + // Input Ports =gK from up Network + + // Connecting Injection & Ejection Channels + for ( pos = 0 ; pos < nPos ; ++pos ) { + for(int index = 0; index<_k; index++){ + int link = pos*_k + index; + _Router( _n-1, pos)->AddInputChannel( _inject[link], + _inject_cred[link]); + _Router( _n-1, pos)->AddOutputChannel( _eject[link], + _eject_cred[link]); + _inject[link]->SetLatency( 1 ); + _inject_cred[link]->SetLatency( 1 ); + _eject[link]->SetLatency( 1 ); + _eject_cred[link]->SetLatency( 1 ); + } + } + +#ifdef FATTREE_DEBUG + cout<<"\nAssigning output\n"; +#endif + + //channels are numbered sequentially from an output channel perspective + int chan_per_direction = (_k * powi( _k , _n-1 )); //up or down + int chan_per_level = 2*(_k * powi( _k , _n-1 )); //up+down + + //connect all down output channels + //level n-1's down channel are injection channels + for (level = 0; level<_n-1; level++){ + for ( pos = 0; pos < nPos; ++pos ) { + for ( port = 0; port < _k; ++port ) { + int link = (level*chan_per_level) + pos*_k + port; + _Router(level, pos)->AddOutputChannel( _chan[link], + _chan_cred[link] ); + _chan[link]->SetLatency( 1 ); + _chan_cred[link]->SetLatency( 1 ); +#ifdef FATTREE_DEBUG + cout<<_Router(level, pos)->Name()<<" " + <<"down output "<AddOutputChannel( _chan[link], + _chan_cred[link] ); + _chan[link]->SetLatency( 1 ); + _chan_cred[link]->SetLatency( 1 ); +#ifdef FATTREE_DEBUG + cout<<_Router(level, pos)->Name()<<" " + <<"up output "<AddInputChannel( _chan[link], + _chan_cred[link] ); +#ifdef FATTREE_DEBUG + cout<<_Router(level, pos)->Name()<<" " + <<"down input "<AddInputChannel( _chan[link], + _chan_cred[link] ); +#ifdef FATTREE_DEBUG + cout<<_Router(level, pos)->Name()<<" " + <<"up input "<