ring.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  ring.cc
00005  *
00006  *    Description:  
00007  *
00008  *        Version:  1.0
00009  *        Created:  05/05/2010 12:37:47 AM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Mitchelle Rasquinha (), mitchelle.rasquinha@gatech.edu
00014  *        Company:  Georgia Institute of Technology
00015  *
00016  * =====================================================================================
00017  */
00018 #ifndef  _ring_cc_INC
00019 #define  _ring_cc_INC
00020 
00021 #include        "ring.h"
00022 
00023 Ring::Ring()
00024 {
00025 
00026 }
00027 
00028 Ring::~Ring()
00029 {
00030     for ( uint i=0 ; i<no_nodes; i++ )
00031     {
00032         delete processors[i];
00033         delete interfaces[i];
00034         delete routers[i];
00035     }
00036 
00037     for ( uint i=0 ; i<links; i++ )
00038     {
00039         delete link_a[i];
00040         delete link_b[i];
00041     }
00042 
00043 }
00044 
00045 void
00046 Ring::init(uint p, uint v, uint c, uint bs, uint n, uint k, uint l)
00047 {
00048     ports = p;
00049     vcs = v;
00050     credits  = c;
00051     buffer_size = bs;
00052     no_nodes = n;
00053     grid_size = k;
00054     links = l;
00055 }
00056 
00057 string
00058 Ring::print_stats()
00059 {
00060     stringstream str;
00061     for ( uint i=0 ; i<no_nodes ; i++ )
00062     {
00063         str << routers[i]->print_stats()<< endl;
00064         str << interfaces[i]->print_stats()<< endl;
00065         str << processors[i]->print_stats()<< endl;
00066     }
00067 
00068     /* Removed LT and hence there is no need for the link stats */
00069 if(stat_print_level > 2)
00070     for ( uint i=0 ; i<links ; i++ )
00071     {
00072         str << link_a[i]->print_stats()<< endl;
00073         str << link_b[i]->print_stats()<< endl;
00074     }
00075 
00076     return str.str();
00077 }
00078 
00079 void
00080 Ring::connect_interface_processor()
00081 {
00082     /* Connect the interfaces and the processors. And set the links for the
00083      * interfaces */
00084     for ( uint i=0 ; i<no_nodes; i++ )
00085     {
00086         processors[i]->interface_connections.push_back(interfaces[i]);
00087         interfaces[i]->processor_connection = static_cast<NetworkComponent*>(processors[i]);
00088         interfaces[i]->input_connection = link_b[i];
00089         interfaces[i]->output_connection = link_a[i];
00090     }
00091 
00092     return;
00093 }
00094 
00095 void
00096 Ring::connect_interface_routers()
00097 {
00098     //Input and output link connections
00099     for ( uint i=0 ; i<no_nodes ; i++ )
00100     {
00101         link_a[i]->input_connection = interfaces[i];
00102         link_a[i]->output_connection = routers[i];
00103         link_b[i]->input_connection = routers[i];
00104         link_b[i]->output_connection = interfaces[i];
00105         routers[i]->input_connections.push_back(link_a[i]);
00106         routers[i]->output_connections.push_back(link_b[i]);
00107     }
00108     return;
00109 }
00110 
00111 void
00112 Ring::connect_routers()
00113 {
00114     uint last_link_id = no_nodes;
00115     for ( uint router_no=1 ; router_no<no_nodes; router_no++ )
00116     {
00117             link_a[last_link_id]->input_connection = routers[router_no-1];
00118             link_a[last_link_id]->output_connection = routers[router_no];
00119             link_b[last_link_id]->input_connection = routers[router_no];
00120             link_b[last_link_id]->output_connection = routers[router_no-1];
00121             east_links.insert(make_pair(router_no, last_link_id));
00122             west_links.insert(make_pair(router_no-1, last_link_id));
00123             last_link_id++;
00124     }
00125     link_a[last_link_id]->input_connection = routers[no_nodes-1];
00126     link_a[last_link_id]->output_connection = routers[0];
00127     link_b[last_link_id]->input_connection = routers[0];
00128     link_b[last_link_id]->output_connection = routers[no_nodes-1];
00129     east_links.insert(make_pair(0, last_link_id));
00130     west_links.insert(make_pair(no_nodes-1, last_link_id));
00131 
00132     for ( uint i=0 ; i<no_nodes; i++ )
00133     {
00134         map<uint,uint>::iterator link_id = east_links.find(i);
00135         routers[i]->input_connections.push_back(link_a[link_id->second]);
00136         routers[i]->output_connections.push_back(link_b[link_id->second]);
00137     }
00138     /* ------------ Begin West links --------------------- */
00139 
00140     for ( uint i=0 ; i<no_nodes; i++ )
00141     {
00142         map<uint,uint>::iterator link_id = west_links.find(i);
00143         routers[i]->input_connections.push_back(link_b[link_id->second]);
00144         routers[i]->output_connections.push_back(link_a[link_id->second]);
00145     }
00146 
00147     if(last_link_id > links )
00148     {
00149         cout << "ERROR : incorrect topology last_link_id: " << last_link_id << " links: " << links <<endl;
00150         exit(1);
00151     }
00152     /* ------------ End South links --------------------- */
00153 
00154     return;
00155 }
00156 
00157 void
00158 Ring::setup()
00159 {
00160     /* Call setup on all components */
00161     for ( uint i=0 ; i<no_nodes ; i++ )
00162     {
00163         processors[i]->setup( no_nodes, vcs, max_sim_time);
00164         interfaces[i]->setup(vcs, credits, buffer_size);
00165         routers[i]->init(ports, vcs, credits, buffer_size);
00166     }
00167 
00168     for ( uint i=0 ; i<links; i++ )
00169     {
00170         link_a[i]->setup();
00171         link_b[i]->setup();
00172     }
00173     return;
00174 }
00175 #endif   /* ----- #ifndef _ring_cc_INC  ----- */
00176 

Generated on Tue Oct 19 17:22:00 2010 for IRIS by  doxygen 1.5.8