manifold_simiris.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  simMc2Mesh.cc
00005  *
00006  *    Description:  This is a 2x2 mesh network with 3 trace packet generators
00007  *    and a single memory controller
00008  *
00009  *        Version:  1.0
00010  *        Created:  04/20/2010 02:59:08 AM
00011  *       Revision:  none
00012  *       Compiler:  gcc
00013  *
00014  *         Author:  Mitchelle Rasquinha (), mitchelle.rasquinha@gatech.edu
00015  *        Company:  Georgia Institute of Technology
00016  *
00017  * =====================================================================================
00018  */
00019 
00020 #ifndef  _simmc2mesh_cc_INC
00021 #define  _simmc2mesh_cc_INC
00022 
00023 #include        "topology.h"
00024 #include        "mesh.h"
00025 #include        "torus.h"
00026 #include        "ring.h"
00027 #include        "visual.h"
00028 #include        "../../simIris/data_types/impl/flit.h"
00029 #include        "../../util/stats.h"
00030 #include        "../../simIris/data_types/impl/highLevelPacket.h"
00031 #include        "../../util/genericData.h"
00032 #include        "../../util/config_params.h"
00033 #include        "../../memctrl/mshr.cc"
00034 #include        <string.h>
00035 #include        <sys/time.h>
00036 #include        <algorithm>
00037 
00038 unsigned long int net_pack_info[8][8];
00039 
00040 extern void interface_simiris(ullint);
00041 
00042 Topology * topology_ptr = NULL;
00043 void
00044 dump_configuration ( void )
00045 {
00046     /* Creating mesh topology with the following config */
00047     cerr << " type:\t" << network_type << endl;
00048     cerr << " vcs:\t" << vcs << endl;
00049     cerr << " ports:\t" << ports << endl;
00050     cerr << " buffer_size:\t" << buffer_size << endl;
00051     cerr << " credits:\t" << credits << endl;
00052     cerr << " no_nodes:\t" << no_nodes << endl;
00053     cerr << " grid_size:\t" << grid_size << endl;
00054     cerr << " unidirectional_links:  \t" << 2*links << endl;
00055     cerr << " no_of_mcs:\t" << no_mcs << endl;
00056     cerr << " no_of_cores:\t" << no_of_cores << endl;
00057     cerr << " concentration:\t" << concentration << endl;
00058     cerr << " no_of_traces:\t" << traces.size() << endl;
00059     cerr << " interfaces:\t" << concentration << endl;
00060     cerr << " cores:\t" << no_of_cores << endl;
00061     cerr << " max_sim_time:\t" << max_sim_time << endl;
00062     cerr << " max_phy_link_bits:\t" << max_phy_link_bits << endl;
00063     cerr << " THREAD_BITS_POSITION:\t" << THREAD_BITS_POSITION<< endl;
00064     cerr << " MC_ADDR_BITS:\t" << MC_ADDR_BITS<< endl;
00065     cerr << " TWO_STAGE_ROUTER:\t" << do_two_stage_router << endl;
00066     cerr << " ROUTING_SCHEME:\t" << routing_scheme << " " << rc_method << endl;
00067     cerr << " SW_ARBITRATION:\t" << sw_arbitration_scheme<< " " << sw_arbitration<< endl;
00068     cerr << " Msg_class with arbitration priority:\t" << msg_type_string << endl;
00069     cerr << " BANK_BITS:\t" << BANK_BITS << endl;
00070     cerr << " NETWORK_BITS:\t" << NETWORK_ADDRESS_BITS << endl;
00071     cerr << " COMMAND_BITS:\t" << NETWORK_THREADID_BITS << endl;
00072     cerr << " COREID_BITS:\t" << NETWORK_COMMAND_BITS << endl;
00073     cerr << " NO_OF_THREADS:\t" << NO_OF_THREADS << endl;
00074     cerr << " NO_OF_CHANNELS:\t" << NO_OF_RANKS << endl;
00075     cerr << " NO_OF_RANKS:\t" << NO_OF_RANKS << endl;
00076     cerr << " NO_OF_BANKS:\t" << NO_OF_BANKS << endl;
00077     cerr << " NO_OF_ROWS:\t" << NO_OF_ROWS << endl;
00078     cerr << " NO_OF_COLUMNS:\t" << NO_OF_COLUMNS << endl;
00079     cerr << " COLUMN_SIZE:\t" << COLUMN_SIZE << endl;
00080     cerr << " router_model:\t" << router_model_string<< endl;
00081     cerr << " mc_model:\t" << mc_model_string<< endl;
00082     cerr << " do_request_reply_network:\t" << do_request_reply_network << endl;
00083     cerr << " mc_response_pkt_payload_length:\t" << mc_response_pkt_payload_length<< endl;
00084     cerr << " mc_positions:\t";
00085     for( uint i=0; i<mc_positions.size(); i++)
00086         cerr << mc_positions[i] << " ";
00087     cerr << endl;
00088 
00089     cerr << " terminal_model:\t" << terminal_model_string<< endl;
00090     cerr << " mean_irt:\t" << mean_irt<< endl;
00091     cerr << " terminal_msg_class:\t" << terminal_msg_class_string << endl;
00092     cerr << " no_msg_classes:\t" << no_msg_classes<< endl;
00093     cerr << " pkt_payload_length:\t" << pkt_payload_length<< endl;
00094     cerr << " stat_print_level:\t" << stat_print_level<< endl;
00095 
00096     if( terminal_model_string == "TPG" && traces.size() < (no_nodes - no_mcs) )
00097     {
00098         cout << " Not enough trace files for simulation " << endl;
00099         exit(1);
00100     }
00101     return ;
00102 }
00103 
00104 void
00105 print_access_counts()
00106 {
00107     cerr << "IB_cycles: " << istat->get_total_ib_cycles() << endl;
00108     cerr << "RC_cycles: " << istat->get_total_rc_cycles() << endl;
00109     cerr << "VCA_cycles: " << istat->get_total_vca_cycles() << endl;
00110     cerr << "SA_cycles: " << istat->get_total_sa_cycles() << endl;
00111     cerr << "ST_cycles: " << istat->get_total_st_cycles() << endl;
00112     cerr << "Total_flits: " << istat->get_total_flits_passed() << endl;
00113     cerr << "Total_credits: " << istat->get_total_credits_passed() << endl;
00114 }
00115 
00116 int
00117 main ( int argc, char *argv[] )
00118 {
00119     ullint sim_start_time = time(NULL);
00120     if(argc<2)
00121     {
00122         cout << "Error: Requires config file for input parameters\n";
00123         return 1;
00124     }
00125 
00126 
00127     for(int ii=0;ii<8;ii++)
00128         for(int jj=0;jj<8;jj++)
00129             net_pack_info[ii][jj]=0;
00130 
00131     ifstream fd(argv[1]);
00132     string data, word;
00133 
00134     while(!fd.eof())
00135     {
00136         getline(fd,data);
00137         string::size_type position = -1;
00138         position = data.find("#");
00139         istringstream iss( data, istringstream::in);
00140         while ( position > data.size() && iss >> word )
00141         {
00142             if ( word.compare("TYPE") == 0)
00143                 iss >> network_type;
00144             if ( word.compare("PRINT_SETUP") == 0)   
00145                 iss >> print_setup;
00146             if ( word.compare("VCS") == 0)   
00147                 iss >> vcs;
00148             if ( word.compare("PORTS") == 0) 
00149                 iss >> ports;
00150             if ( word.compare("BUFFER_SIZE") == 0)
00151                 iss >> buffer_size;
00152             if ( word.compare("CREDITS") == 0)
00153                 iss >> credits;
00154             if ( word.compare("GRID_SIZE") == 0)
00155                 iss >> grid_size;
00156             if ( word.compare("NO_OF_NODES") == 0)
00157                 iss >> no_nodes;
00158             if ( word.compare("MCS") == 0)
00159                 iss >> no_mcs;
00160             if ( word.compare("CORES_PER_NODE") == 0)
00161                 iss >> no_of_cores;
00162             if ( word.compare("CONCENTRATION") == 0)
00163                 iss >> concentration;
00164             if ( word.compare("MAX_SIM_TIME") == 0)
00165                 iss >> max_sim_time;
00166             if ( word.compare("OUTPUT_PATH") == 0)
00167                 iss >> output_path;
00168             if ( word.compare("PHY_LINK_WIDTH") == 0)
00169                 iss >> max_phy_link_bits;
00170             if ( word.compare("ROUTER_MODEL") == 0)
00171                 iss >> router_model_string;
00172             NO_OF_THREADS = no_nodes;
00173             /* Init parameters of mc_constants*/
00174             if ( word.compare("MC_MODEL") == 0)
00175                 iss >> mc_model_string;
00176             if ( word.compare("TERMINAL_MODEL") == 0)
00177                 iss >> terminal_model_string;
00178             if ( word.compare("MEAN_IRT") == 0)
00179                 iss >> mean_irt;
00180             if ( word.compare("TERMINAL_MSG_CLASS") == 0)
00181                 iss >> terminal_msg_class_string;
00182             if ( word.compare("NO_MSG_CLASS") == 0)
00183                 iss >> no_msg_classes;
00184             if ( word.compare("PKT_PAYLOAD_LEN") == 0)
00185                 iss >> pkt_payload_length;
00186             if ( word.compare("MC_RESP_PAYLOAD_LEN") == 0)
00187                 iss >> mc_response_pkt_payload_length;
00188             if ( word.compare("THREAD_BITS_POSITION") == 0)
00189                 iss >> THREAD_BITS_POSITION;
00190             if ( word.compare("MC_ADDR_BITS") == 0)
00191                 iss >> MC_ADDR_BITS;
00192             if ( word.compare("BANK_BITS") == 0)
00193                 iss >> BANK_BITS;
00194             if ( word.compare("NO_OF_CHANNELS") == 0)
00195                 iss >> NO_OF_CHANNELS;
00196 
00197             if ( word.compare("NO_OF_RANKS") == 0)
00198                 iss >> NO_OF_RANKS;
00199             if ( word.compare("NO_OF_BANKS") == 0)
00200                 iss >> NO_OF_BANKS;
00201 
00202             if ( word.compare("NO_OF_ROWS") == 0)
00203                 iss >> NO_OF_ROWS;
00204             if ( word.compare("NO_OF_COLUMNS") == 0)
00205                 iss >> NO_OF_COLUMNS;
00206             if ( word.compare("COLUMN_SIZE") == 0)
00207                 iss >> COLUMN_SIZE;
00208             if ( word.compare("MSHR_SIZE") == 0)
00209                 iss >> MSHR_SIZE;
00210 
00211             if ( word.compare("MAX_BUFFER_SIZE") == 0)
00212                 iss >> MAX_BUFFER_SIZE;
00213             if ( word.compare("MAX_CMD_BUFFER_SIZE") == 0)
00214                 iss >> MAX_CMD_BUFFER_SIZE;
00215             if ( word.compare("RESPONSE_BUFFER_SIZE") == 0)
00216                 iss >> RESPONSE_BUFFER_SIZE;
00217 
00218             if ( word.compare("NETWORK_ADDRESS_BITS") == 0)
00219                 iss >> NETWORK_ADDRESS_BITS;
00220             if ( word.compare("NETWORK_THREADID_BITS") == 0)
00221                 iss >> NETWORK_THREADID_BITS ;
00222             if ( word.compare("NETWORK_COMMAND_BITS") == 0)
00223                 iss >> NETWORK_COMMAND_BITS;
00224 
00225             /*  ******************************************* */
00226             if ( word.compare("TWO_STAGE_ROUTER") == 0)
00227                 iss >> do_two_stage_router;
00228             if ( word.compare("ROUTING_SCHEME") == 0)
00229                 iss >> routing_scheme;
00230             if ( word.compare("SW_ARBITRATION") == 0)
00231                 iss >> sw_arbitration_scheme;
00232             if ( word.compare("PRIORITY_MSG_TYPE") == 0)
00233                 iss >> msg_type_string;
00234             if ( word.compare("DRAM_PAGE_POLICY") == 0)
00235                 iss >> dram_page_policy_string;
00236             if ( word.compare("ADDRESS_MAP_SCHEME") == 0)
00237                 iss >> addr_map_scheme_string;
00238             if ( word.compare("MC_SCHEDULING_ALGORITHM") == 0)
00239                 iss >> mc_scheduling_algorithm_string;
00240             if ( word.compare("REQ_REPLY") == 0)
00241                 iss >> do_request_reply_network;
00242             if ( word.compare("TRACE") == 0)
00243             {
00244                 iss >> trace_name;
00245                 traces.push_back(trace_name);
00246             }
00247             if ( word.compare("MC_LOC") == 0)
00248             {
00249                 uint mc_xpos, mc_ypos;
00250                 iss >> mc_xpos;
00251                 iss >> mc_ypos;
00252                 mc_positions.push_back(mc_xpos*grid_size + mc_ypos);
00253             }
00254         }
00255     }
00256 
00257     for ( uint i=0; i<argc; i++)
00258     {
00259         if( strcmp(argv[i],"--thread_id_bits")==0)
00260             THREAD_BITS_POSITION = atoi(argv[i+1]);
00261         if( strcmp(argv[i],"--mc_bits")==0)
00262             MC_ADDR_BITS = atoi(argv[i+1]);
00263         if( strcmp(argv[i],"--router_two_stg")==0)
00264             do_two_stage_router = atoi(argv[i+1]);
00265         if( strcmp(argv[i],"--routing_scheme")==0)
00266             routing_scheme = argv[i+1];
00267         if( strcmp(argv[i],"--sw_arbitration")==0)
00268             sw_arbitration_scheme = argv[i+1];
00269         if( strcmp(argv[i],"--msg_type")==0)
00270             msg_type_string = argv[i+1];
00271         if( strcmp(argv[i],"--bank_bits")==0)
00272             BANK_BITS = atoi(argv[i+1]);
00273         if( strcmp(argv[i],"--mirt")==0)
00274             mean_irt= atoi(argv[i+1]);
00275     }
00276 
00277     if( routing_scheme.compare("odd-even") == 0)
00278         rc_method = ODD_EVEN;
00279     if( strcmp(routing_scheme.c_str(),"negative-first") == 0)
00280         rc_method = NEGATIVE_FIRST;
00281     if( strcmp(routing_scheme.c_str(),"west-first") == 0)
00282         rc_method = WEST_FIRST;
00283     if( strcmp(routing_scheme.c_str(),"north-last") == 0)
00284         rc_method = NORTH_LAST;
00285     if( strcmp(routing_scheme.c_str(),"north-last-nm") == 0)
00286         rc_method = NORTH_LAST_NON_MINIMAL;
00287     if( routing_scheme.compare("xy") == 0)
00288         rc_method = XY;
00289     if( routing_scheme.compare("torus-routing") == 0)
00290         rc_method = TORUS_ROUTING;
00291     if( routing_scheme.compare("ring-routing") == 0)
00292         rc_method = RING_ROUTING;
00293 
00294     if( strcmp(sw_arbitration_scheme.c_str(),"round-robin") == 0)
00295         sw_arbitration = ROUND_ROBIN;
00296     if( strcmp(sw_arbitration_scheme.c_str(),"round-robin-p") == 0)
00297         sw_arbitration = ROUND_ROBIN_PRIORITY;
00298     if( strcmp(sw_arbitration_scheme.c_str(),"fcfs") == 0)
00299         sw_arbitration = FCFS;
00300 
00301     if( strcmp(msg_type_string.c_str(),"PRIORITY_REQ") == 0)
00302         priority_msg_type = PRIORITY_REQ;
00303     if( strcmp(msg_type_string.c_str(),"ONE_FLIT_REQ") == 0)
00304         priority_msg_type = ONE_FLIT_REQ;
00305     if( strcmp(msg_type_string.c_str(),"RESPONSE_PKT") == 0)
00306         priority_msg_type = RESPONSE_PKT;
00307 
00308     if( dram_page_policy_string.compare("OPEN_PAGE_POLICY") == 0)
00309         dram_page_policy = OPEN_PAGE_POLICY;
00310     if( dram_page_policy_string.compare("CLOSE_PAGE_POLICY") == 0)
00311         dram_page_policy = CLOSE_PAGE_POLICY;
00312 
00313     if( mc_scheduling_algorithm_string.compare("FR_FCFS") == 0)
00314         mc_scheduling_algorithm = FR_FCFS;
00315     if( mc_scheduling_algorithm_string.compare("FC_FS") == 0)
00316         mc_scheduling_algorithm = FC_FS;
00317     if( mc_scheduling_algorithm_string.compare("PAR_BS") == 0)
00318         mc_scheduling_algorithm = PAR_BS;
00319 
00320     if( addr_map_scheme_string.compare("PAGE_INTERLEAVING") == 0)
00321         addr_map_scheme = PAGE_INTERLEAVING;
00322     if( addr_map_scheme_string.compare("PERMUTATION") == 0)
00323         addr_map_scheme = PERMUTATION;
00324     if( addr_map_scheme_string.compare("CACHELINE_INTERLEAVING") == 0)
00325         addr_map_scheme = CACHELINE_INTERLEAVING;
00326     if( addr_map_scheme_string.compare("GENERIC") == 0)
00327         addr_map_scheme = GENERIC;
00328     if( addr_map_scheme_string.compare("NO_SCHEME") == 0)
00329         addr_map_scheme = NO_SCHEME;
00330     if( addr_map_scheme_string.compare("LOCAL_ADDR_MAP") == 0)
00331         addr_map_scheme = LOCAL_ADDR_MAP;
00332 
00333     if( router_model_string.compare("VIRTUAL") == 0)
00334         router_model = VIRTUAL;
00335     if( router_model_string.compare("PHYSICAL") == 0)
00336         router_model = PHYSICAL;
00337 
00338     if( mc_model_string.compare("GENERIC_MC") == 0)
00339         mc_model = GENERIC_MC;
00340     if( mc_model_string.compare("FLAT_MC") == 0)
00341         mc_model = FLAT_MC;
00342     if( mc_model_string.compare("SINK") == 0)
00343         mc_model = SINK;
00344 
00345     if( terminal_model_string.compare("GENERIC") == 0)
00346         terminal_model = GENERIC_PKTGEN;
00347     if( terminal_model_string.compare("TPG") == 0)
00348         terminal_model = TPG;
00349 
00350     if( strcmp(terminal_msg_class_string.c_str(),"PRIORITY_REQ") == 0)
00351         terminal_msg_class = PRIORITY_REQ;
00352     if( strcmp(terminal_msg_class_string.c_str(),"ONE_FLIT_REQ") == 0)
00353         terminal_msg_class = ONE_FLIT_REQ;
00354     if( strcmp(terminal_msg_class_string.c_str(),"RESPONSE_PKT") == 0)
00355         terminal_msg_class = RESPONSE_PKT;
00356 
00357     /* Number of MC's and the size of the position vector should be the same. */
00358     assert(mc_positions.size() == no_mcs);
00359 
00360     /* Compute additional parameters */
00361     uint edge_links = 0;
00362     if ( network_type == "MESH" || network_type == "Mesh" || network_type == "mesh")
00363     {
00364         /* For a 2D mesh [Gs*(GS-1)*k] internal links + edge links [4*GS] +
00365            terminal connections [GS*GS]. Note this is the unidirectional measure.
00366            Links are denoted as 
00367            follows east going for router_n, west going for router_n, north going for router_n
00368            and south going for router_n (0<n<no_nodes). Going by this convention one of the edge 
00369            links will be east going for rightmost router+1 which is not part of the mesh. Hence 
00370            there are grid_size such unidirectional nodes for every k dimension that dont get connected. FIX tht */
00371         links = (grid_size * (grid_size+1) *2 /*k=2 for mesh*/ ) + (grid_size*grid_size /* for the interfaces */ );
00372         edge_links = grid_size*4*2; /* for a mesh there are 4 sides each with GS nodes, 2 bidirectional */
00373     }
00374     else if (network_type == "TORUS" || network_type == "Torus" || network_type == "torus" )
00375     {
00376         links = (grid_size * grid_size * 2/* k */) +(grid_size*grid_size)/*interfaces*/;
00377         /*no edge links for the torus */
00378         cout << "Links = " << links << endl;
00379     }
00380     else if (network_type == "RING" || network_type == "Ring" || network_type == "ring" )
00381     {
00382         //links = grid_size * grid_size * ports ;
00383         links = grid_size * 2;
00384         cout << "Links = " << links << endl;
00385     }
00386     fd.close();
00387 
00388     cerr << "\n-----------------------------------------------------------------------------------\n";
00389     cerr << "** CAPSTONE - Cycle Accurate Parallel Simulator Technologgy for On-Chip Networks **\n";
00390     cerr << " This is simIris. A second version of Capstone." << endl;
00391     cerr << "-- Computer Architecture and Systems Lab                                         --\n"
00392         << "-- Georgia Institute of Technology                                               --\n"
00393         << "-----------------------------------------------------------------------------------\n";
00394     cerr << "Cmd line: ";
00395     for( int i=0; i<argc; i++)
00396         cerr << argv[i] << " ";
00397     cerr << endl;
00398 
00399     dump_configuration();
00400     init_dram_timing_parameters();
00401     if ( network_type == "MESH" || network_type == "Mesh" || network_type == "mesh" )
00402         topology_ptr = new Mesh();
00403     else if ( network_type == "TORUS" || network_type == "Torus" || network_type == "torus" )
00404         topology_ptr = new Torus();
00405     else if ( network_type == "RING" || network_type == "Ring" || network_type == "ring" )
00406         topology_ptr = new Ring();
00407     else if (network_type == "NONE" )
00408     {
00409         cout << "Topology not specified...exiting \n" ;
00410         exit(1);
00411     }
00412     topology_ptr->init( ports, vcs, credits, buffer_size, no_nodes, grid_size, links);
00413     topology_ptr->max_sim_time = max_sim_time;
00414 
00415     //    Visual* vis = new Visual(topology_ptr, no_nodes, links, grid_size);
00416 
00417     /* Create the routers and interfaces */
00418     for( uint i=0; i<no_nodes; i++)
00419     {
00420         switch ( router_model )
00421         {
00422             case PHYSICAL:
00423                 topology_ptr->routers.push_back( new GenericRouterPhy());
00424                 break;
00425             case VIRTUAL:
00426                 topology_ptr->routers.push_back( new RouterVcMP());
00427                 break;
00428             default:
00429                 cout << " Incorrect router model " << endl;
00430                 exit(1);
00431                 break;
00432         }
00433         topology_ptr->interfaces.push_back ( new GenericInterfaceNB());
00434     }
00435 
00436     /*  Create the TPG and mc modules */
00437     vector<uint>::iterator itr;
00438     for( uint i=0; i<no_nodes; i++)
00439     {
00440         itr = find(mc_positions.begin(), mc_positions.end(), i);
00441         if( itr != mc_positions.end())
00442         {
00443             switch ( mc_model )
00444             {
00445                 case GENERIC_MC:
00446                     topology_ptr->processors.push_back( new McFrontEnd() );
00447                     break;
00448                 case FLAT_MC:
00449                     topology_ptr->processors.push_back( new GenericFlatMc());
00450                     break;
00451                 case SINK:
00452                     topology_ptr->processors.push_back( new GenericSink());
00453                     break;
00454                 default:
00455                     cout << " Unknown MC model " << endl;
00456                     exit(1);
00457                     break;
00458             }
00459         }
00460         else
00461         {
00462             switch ( terminal_model )
00463             {
00464                 case GENERIC_PKTGEN:
00465                     topology_ptr->processors.push_back( new GenericPktGen() );
00466                     for ( uint j=0; j<mc_positions.size(); j++)
00467                         static_cast<GenericPktGen*>(topology_ptr->processors[i])->mc_node_ip.push_back(mc_positions[j]);;
00468                     break;
00469                 case TPG:
00470                     topology_ptr->processors.push_back( new GenericTracePktGen() );
00471                     static_cast<GenericTracePktGen*>(topology_ptr->processors[i])->set_trace_filename(traces[i]);
00472                     /*
00473                      * Need to pass the mc positions to the injecting node so it can pick a destination node_ip 
00474                      * from the mc_positions vector. This may not be needed if
00475                      * the node_ip is available as part of the trace. In
00476                      * either case make sure to assert that the destination
00477                      * node_ip is one of the sink nodes.
00478                      */
00479                     for ( uint j=0; j<mc_positions.size(); j++)
00480                         static_cast<GenericTracePktGen*>(topology_ptr->processors[i])->mc_node_ip.push_back(mc_positions[j]);;
00481 
00482                     break;
00483                 default:
00484                     cout << " Unknown Terminal model " << endl;
00485                     exit(1);
00486                     break;
00487 
00488             }
00489         }
00490     }
00491 
00492     /* Create the links */
00493     for ( uint i=0; i<links; i++)
00494     { 
00495         topology_ptr->link_a.push_back(new GenericLink());
00496         topology_ptr->link_b.push_back(new GenericLink());
00497     }
00498 
00499     topology_ptr->connect_interface_processor();
00500 
00501     /* Set all the component ids */
00502     uint comp_id = 0, alink_comp_id = 1000, blink_comp_id = 5000;
00503     for ( uint i=0 ; i<no_nodes; i++ )
00504     {
00505         topology_ptr->processors[i]->setComponentId(comp_id++);
00506         //        topology_ptr->processors[i]->my_mesh = (void*)topology_ptr;
00507         topology_ptr->interfaces[i]->setComponentId(comp_id++);
00508         topology_ptr->routers[i]->setComponentId(comp_id++);
00509     }
00510 
00511     for ( uint i=0 ; i<links; i++ )
00512     {
00513         topology_ptr->link_a[i]->setComponentId(alink_comp_id++);
00514         topology_ptr->link_b[i]->setComponentId(blink_comp_id++);
00515         topology_ptr->link_a[i]->link_id=i;
00516         topology_ptr->link_b[i]->link_id=links+i;
00517         topology_ptr->link_a[i]->setup();
00518         topology_ptr->link_b[i]->setup();
00519     }
00520     cerr << " ******************** SETUP COMPLETE *****************\n" << endl;
00521     /*  Set up the node ips for components */
00522     for ( uint i=0 ; i<no_nodes ; i++ )
00523     {
00524         topology_ptr->interfaces[i]->node_ip = i;
00525         topology_ptr->routers[i]->node_ip = i;
00526         topology_ptr->processors[i]->node_ip = i;
00527     }
00528 
00529     /* Set the number of ports, vcs, credits and buffer sizes for the
00530      * components */
00531     for ( uint i=0 ; i<no_nodes ; i++ )
00532     {
00533         topology_ptr->interfaces[i]->set_no_vcs(vcs);
00534         topology_ptr->interfaces[i]->set_no_credits(credits);
00535         topology_ptr->interfaces[i]->set_buffer_size(credits);
00536         topology_ptr->processors[i]->set_output_path(output_path);
00537     }
00538 
00539     topology_ptr->setup();
00540     istat->init();
00541 
00542     if (network_type == "RING" || network_type == "Ring" || network_type == "ring" )
00543     {
00544         vector< uint > grid_x;
00545         vector< uint > grid_y;
00546         grid_x.resize(no_nodes);
00547         grid_y.resize(1);
00548 
00549         /* Limitation of only modelling squares */
00550         for ( uint i=0 ; i<no_nodes; i++ )
00551             grid_x[i] = i;
00552 
00553         grid_y[0] = 0;
00554 
00555         for ( uint i=0 ; i<no_nodes ; i++ )
00556             topology_ptr->routers[i]->set_no_nodes(no_nodes);
00557 
00558         for ( uint i=0 ; i<no_nodes ; i++ )
00559             for( uint j=0; j < ports ; j++)
00560                 for( uint k=0; k < no_nodes ; k++) // Assuming is a square topology_ptr. 
00561                 {
00562                     static_cast<Router*>(topology_ptr->routers[i])->set_grid_x_location(j,k, grid_x[k]);
00563                     static_cast<Router*>(topology_ptr->routers[i])->set_grid_y_location(j,0, grid_y[0]);
00564                 }
00565     }
00566     else
00567     {
00568         /*  Set no of ports and positions for routing */
00569         vector< uint > grid_x;
00570         vector< uint > grid_y;
00571         grid_x.resize(no_nodes);
00572         grid_y.resize(no_nodes);
00573 
00574         /* Limitation of only modelling squares */
00575         for ( uint i=0 ; i<grid_size ; i++ )
00576             for ( uint j=0 ; j<grid_size ; j++ )
00577             {
00578                 grid_x[(i*grid_size)+j] = j;
00579                 grid_y[(i*grid_size)+j] = i;
00580             }
00581 
00582 
00583         for ( uint i=0 ; i<no_nodes ; i++ )
00584             topology_ptr->routers[i]->set_no_nodes(no_nodes);
00585 
00586         for ( uint i=0 ; i<no_nodes ; i++ )
00587             for( uint j=0; j < ports ; j++)
00588                 for( uint k=0; k < no_nodes ; k++) // Assuming is a square topology_ptr. 
00589                 {
00590                     static_cast<Router*>(topology_ptr->routers[i])->set_grid_x_location(j,k, grid_x[k]);
00591                     static_cast<Router*>(topology_ptr->routers[i])->set_grid_y_location(j,k, grid_y[k]);
00592                 }
00593     }
00594 
00595     topology_ptr->connect_interface_routers();
00596     topology_ptr->connect_routers();
00597 
00598     /*  Printing out all component after setup */
00599     if( print_setup )
00600     {
00601         for ( uint i=0 ; i<no_nodes; i++ )
00602         {
00603             cout << "\nTPG: " << i << " " << topology_ptr->processors[i]->toString();
00604             cout << "\ninterface: " << i << " " << topology_ptr->interfaces[i]->toString();
00605             cout << "\nrouter: " << i << " " << topology_ptr->routers[i]->toString();
00606         }
00607 
00608         for ( uint i=0 ; i<links ; i++ )
00609         {
00610             cout << "\nlinka_" << i << " " << topology_ptr->link_a[i]->toString();
00611             cout << "\nlinkb_" << i << " " << topology_ptr->link_b[i]->toString();
00612         }
00613     }
00614 
00615     //    vis->create_new_connections();
00616     //    vis->create_graphml();
00617 
00618     Simulator::StopAt(max_sim_time);
00619     Simulator::Run();
00620 
00621     cerr << topology_ptr->print_stats();
00622     /* Init McPat for Energy model and use the counters to compute energy */
00623     //interface_simiris(max_sim_time);
00624     print_access_counts();
00625 
00626     ullint total_link_utilization = 0;
00627     ullint total_link_cr_utilization = 0;
00628     for ( uint i=0 ; i<links ; i++ )
00629     {
00630         total_link_utilization += topology_ptr->link_a[i]->get_flits_utilization();
00631         total_link_cr_utilization += topology_ptr->link_a[i]->get_credits_utilization();
00632     }
00633 
00634     for ( uint i=0 ; i<links ; i++ )
00635     {
00636         total_link_utilization += topology_ptr->link_b[i]->get_flits_utilization();
00637         total_link_cr_utilization += topology_ptr->link_b[i]->get_credits_utilization();
00638     }
00639 
00640     double bytes_delivered = (total_link_utilization + 0.0 )*max_phy_link_bits/(network_frequency*1e6); /* Assuming 1flit=1phit */
00641     double available_bw = (links - edge_links+0.0)*max_phy_link_bits*max_sim_time/(network_frequency*1e6);
00642     cerr << "\n\n************** Link Stats ***************\n";
00643     cerr << " Total flits passed on the links: " << total_link_utilization << endl;
00644     cerr << " Total credits passed on the links: " << total_link_cr_utilization << endl;
00645     cerr << " Links not used: " << 2*edge_links << " of " << 2*links << " links." << endl;
00646     cerr << " Avg flits per link used " << (total_link_utilization+0.0)/(2*(links - edge_links)) << endl;
00647     cerr << " Utilized BW (data only) :(A) " << bytes_delivered *1e-6<< " Mbps. " << endl;
00648     cerr << " Max BW available in the network:(B) " << available_bw *1e-6<< " Mbps. " << endl;
00649     cerr << " \% A/B " << bytes_delivered/available_bw << endl;
00650 
00651     ullint tot_pkts = 0, tot_pkts_out = 0, tot_flits = 0;
00652     for ( uint i=0 ; i<no_nodes ; i++ )
00653     {
00654         tot_pkts_out += topology_ptr->interfaces[i]->get_packets_out();
00655         tot_pkts += topology_ptr->interfaces[i]->get_packets();
00656         tot_flits += topology_ptr->interfaces[i]->get_flits_out();
00657     }
00658 
00659     ullint sim_time_ms = (time(NULL) - sim_start_time);
00660     cerr << "\n\n************** Simulation Stats ***************\n";
00661     cerr << " Simulation Time: " << sim_time_ms << " s. " << endl;
00662     cerr << " No of pkts/terminal/s: " << (tot_pkts+0.0)/(no_nodes*sim_time_ms)<< endl;
00663     cerr << " No of flits/terminal/s: " << (tot_flits+0.0)/(no_nodes*sim_time_ms) << endl;
00664     cerr << " Total Mem Req serviced: " << tot_pkts_out/2 << endl;
00665     cerr << "------------ End SimIris ---------------------" << endl;
00666 
00667     delete topology_ptr;
00668 
00669     return 0;
00670 }                               /* ----------  end of function main  ---------- */
00671 
00672 
00673 #endif   /* ----- #ifndef _simmc2mesh_cc_INC  ----- */

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