/* Copyright (c) 2007-2008 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software and that appropriate acknowledgments are made to the research of the COSI group. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. Author : Alessandro Pinto University of California, Berkeley 545 Cory Hall, Berkeley, CA 94720 */ #include #include #include #include #include "include/CosiGlobal.h" #include "include/onchipcommunication/cosi.h" using namespace std; using namespace cosi::commstruct::onchipcommunication; using namespace cosi::platforms::onchipcommunication; using namespace cosi::io::onchipcommunication; using namespace cosi::environment::onchipcommunication; using namespace cosi::algorithms::onchipcommunication; string CosiRoot; ofstream CosiLog; ConfigParser* Configuration; void PrintBanner(ConfigParser* pC, ProjectParser* pP); int main(int argc, char* argv[]) { double ComputationVerificationTime; if (argc == 1) { cout << "Use: "<< endl; cout << "CosiNoc.x "<< endl; exit(1); } else { clock_t start, finish; CosiLog.open("cosilog.txt"); CosiRoot = string(getenv("COSI_ROOT") ); //Parse configuration Configuration = new ConfigParser( CosiRoot + "/cosiconfig.xml" ); Configuration->Parse(); Configuration->SetCosiRoot(CosiRoot) ; //Parse the project ProjectParser* Project = new ProjectParser( string( argv[1] ) ); Project->Parse(); PrintBanner(Configuration, Project); //Parse constraints ConstraintParser* Constraints = new ConstraintParser( Project->GetConstraintFileName( ) ); Constraints->Parse(); // TODO : restructure the project file //Need to add different options to load components in the platform //set up different platform parameters //set up the optimization algorithms PlacementParser* Placement; if (Project->UsePlacement() ) { Placement = new PlacementParser( Project->GetPlacementFileName( ) , Project->GetSpareArea( ) ); Placement->Parse(); } else { if ( !Constraints->AllPlaced() ) { //Generate Parquet input files ParquetBlocksFile(Configuration->GetTmp() + "/Soc.blocks", Constraints->GetIpCore() , Constraints->GetPlacedIpCore() ); ParquetPlFile(Configuration->GetTmp() + "/Soc.pl", Constraints->GetIpCore() , Constraints->GetPlacedIpCore() ); ParquetNetsFile(Configuration->GetTmp() + "/Soc.nets", Constraints->GetConstraints() , Constraints->GetPlacedIpCore() ); ParquetWightsFile(Configuration->GetTmp() + "/Soc.wts", Constraints->GetConstraints() , Constraints->GetPlacedIpCore()); string ParquetCmdLine; ParquetCmdLine = "export LD_LIBRARY_PATH="; ParquetCmdLine+= Configuration->GetParquetRoot(); ParquetCmdLine+=";"; ParquetCmdLine+= Configuration->GetParquetRoot(); ParquetCmdLine+="/" + Configuration->GetParquetExec(); ParquetCmdLine += " -f " + Configuration->GetTmp() + "/Soc"; ParquetCmdLine+=" -minWL -takePl -compact " + Configuration->GetTmp() + "/Soc.pl -soft -savePl " + Configuration->GetTmp() + "/Soc_placed > parquetlog.txt"; system(ParquetCmdLine.c_str() ); } else { Constraints->WritePlacement(Configuration->GetTmp() + "/Soc_placed.pl"); } Placement = new PlacementParser( Configuration->GetTmp( ) + "/Soc_placed.pl" , Project->GetSpareArea( ) ); Placement->Parse(); } Specification* PtP; PtP = ToPtPGraph(Constraints, Placement); Platform* Plt = new Platform( Placement->GetIpGeometry(), Placement->GetChipGeometry(), 10 , 5e8,32,T90); //Build a star network //StarTopologyGeneration* Syn = new StarTopologyGeneration(PtP,Plt) ; //Syn->Run() ; //PlacementParser* NewPlacement = Syn->GetPlacement(); //Implementation* I = Syn->GetImplementation() ; NocPlatformInterface* NocPlt = Plt->Abstract() ; NocPlt->PowerVsArea(Project->GetPowerVsArea() ) ; NocPlt->AllowPtP(Project->AllowPtP() ) ; NocPlt->AllowTwoHops(Project->AllowTwoHops() ) ; NocPlt->AvoidDeadlock(Project->RunTimeDeadlockCheck() ) ; // HierarchicalNetwork* Hn = new HierarchicalNetwork(PtP,Plt) ; // Hn->Run(); // Implementation* Hi = Hn->GetImplementation() ; // PlacementParser* NewPlacement = Hn->GetPlacement(); // NetworkCost* Nc = new NetworkCost; // Nc->Initialize(Hi, NocPlt, Plt) ; // Nc->Verify(PtP); // Nc->Run(); // AppendRow(Project->GetTabAppendFileName() , Project , NocPlt , Nc ) ; // MFDg* Syn1 = new MFDg; // Syn1->Initialize(PtP, NocPlt); // Syn1->Run() ; // Implementation* MFDg1I = Syn1->GetImplementation(Plt) ; // // MFDg* Syn2 = new MFDg; // Syn2->Initialize(PtP, NocPlt); // Syn2->Run_2() ; // Implementation* MFDg2I = Syn2->GetImplementation(Plt) ; // MeshTopology* Syn3 = new MeshTopology(PtP, Plt); Syn3->Run() ; PlacementParser* NewPlacement = Syn3->GetPlacement(); Implementation* MeshI = Syn3->GetImplementation() ; // NetworkCost* Nc = new NetworkCost; // Nc->Initialize(MFDg1I, NocPlt, Plt) ; // Nc->Verify(PtP); // Nc->Run(); // AppendRow(Project->GetTabAppendFileName() , Project , NocPlt , Nc ) ; // delete Nc; // Nc = new NetworkCost; // Nc->Initialize(MFDg2I, NocPlt, Plt) ; // Nc->Verify(PtP); // Nc->Run(); // AppendRow(Project->GetTabAppendFileName() , Project , NocPlt , Nc ) ; // delete Nc; // Nc = new NetworkCost; Nc->Initialize(MeshI, NocPlt, Plt) ; Nc->Verify(PtP); Nc->Run(); // AppendRow(Project->GetTabAppendFileName() , Project , NocPlt , Nc ) ; InkscapeCodeGenerator* Ink = new InkscapeCodeGenerator( Project->GetSvgFileName( ) , NewPlacement->GetChipW()*1e6 , NewPlacement->GetChipH()*1e6 ); Ink->AddForbidden(NewPlacement) ; Ink->PlotCommStruct(MeshI) ; Ink->Close() ; //Write report //if (Project->ReportRequest() ) { cout << "Writing report ... "; PrintReport(Project->GetReportFileName() , Project, NocPlt, Nc) ; cout << "Done"<< endl; //} SyscCodeGen* Sys = new SyscCodeGen( Project->GetSystemCFileName() , Project->GetSystemCMakeFileName() , MeshI , PtP,32,1/(1.5e9)) ; Sys->Run(); //Write report //if (Project->TabAppendRequest() ) { //cout << "Appending new data ... "; //AppendRow(Project->GetTabAppendFileName() , Project , NocPlt , Nc ) ; //cout << "Done"<< endl ; //} // // //Parse Library // LibraryParser* Library = new LibraryParser( Project->GetLibraryFileName( ) ); // Library->Parse() ; // cout << "Library parsing done "<< endl ; // // //Generate constraint graph // NocPlatformRefined* Plt; // if (Project->HasHopConstraints() ) { // PtPlatency = ToPtPLatencyGraph(Constraints , Placement ) ; // Plt = new NocPlatformRefined( PtPlatency->GetSourcesX( ) , PtPlatency->GetSourcesY( ) , // PtPlatency->GetDestinationsX( ) , PtPlatency->GetDestinationsY( ) , // Placement->GetBottomLeftX( ) , Placement->GetBottomLeftY( ) , // Placement->GetTopRightX( ) , Placement->GetTopRightY( ) , // Library->GetTech( Project->GetLibraryName( ) ) , // Placement->GetChipH( ) , Placement->GetChipW( ) , // Project->GetStep( )*(Library->GetTech( Project->GetLibraryName( ) ) ).lst , Project->GetDensity( ) ); // // } else { // // PtP = ToPtPGraph(Constraints , Placement ) ; // Plt = new NocPlatformRefined( PtP->GetSourcesX( ) , PtP->GetSourcesY( ) , // PtP->GetDestinationsX( ) , PtP->GetDestinationsY( ) , // Placement->GetBottomLeftX( ) , Placement->GetBottomLeftY( ) , // Placement->GetTopRightX( ) , Placement->GetTopRightY( ) , // Library->GetTech( Project->GetLibraryName( ) ) , // Placement->GetChipH( ) , Placement->GetChipW( ) , // Project->GetStep( )*(Library->GetTech( Project->GetLibraryName( ) ) ).lst , Project->GetDensity( ) ); // } // // modelV2 *a; // configXMLParser P; // if (Project->WireModelDefined() && Project->BufferModelDefined() ) { // P.SetXMLFiles(Project->GetWireFileName(), // Project->GetBufferFileName() ); // P.ParseXML(); // a = P.GetModel(); // a->setLayer(Project->GetWireLayer() ); // a->setShielding(Project->GetWireShielding() ); // if (Project->GetWireSpacing() == "swsp") { // a->setWidthSpacingConfigType(singleWidthSingleSpace); // } else if (Project->GetWireSpacing() == "dwsp") { // a->setWidthSpacingConfigType(doubleWidthSingleSpace); // }; // if (Project->GetWireBuffering() == "mindelay") { // a->setBufferingScheme(minDelay); // } else if (Project->GetWireBuffering() == "staggered") { // a->setBufferingScheme(staggered); // } // Plt->SetModel(a ) ; // } // // //Generate Platform // Plt->FlitWidth(Project->GetFlitWidth() ) ; // Plt->SwitchingFactor(Project->GetSwitchingFactor() ) ; // Plt->MaxInDegree(Project->GetMaxInDegree() ) ; // Plt->MaxOutDegree(Project->GetMaxOutDegree() ) ; // Plt->DestInDegree(Project->GetDestInDegree() ) ; // Plt->SourceOutDegree(Project->GetSourceOutDegree() ) ; // Plt->PowerVsArea(Project->GetPowerVsArea() ) ; // Plt->AllowPtP(Project->AllowPtP() ) ; // Plt->AllowTwoHops(Project->AllowTwoHops() ) ; // Plt->AvoidDeadlock(Project->RunTimeDeadlockCheck() ) ; // // //Run synthesis // XyRouting_Flow_Graph* Gsyn; // map< pair , int> OrderSyn; // NetworkCost* Cost = new NetworkCost; // // start = clock(); // // if ( ( !Plt->AllowTwoHops() || Plt->AvoidDeadlock() ) // && Project->HasHopConstraints() ) { // // MFDgDeDl* Syn = new MFDgDeDl ; // // Syn->Initialize( PtP , Plt ) ; // // Syn->Run( ) ; // // Gsyn = Syn->GetGraph( ) ; // // OrderSyn = Syn->GetOrder( ) ; // // Cost->Initialize( Gsyn , Plt ); // // Cost->Verify( PtPlatency ) ; // // Cost->Run( ) ; // cout // << "The case of deadlock free topologies with delay constraints has not been implemented yet " // << endl ; // exit( 1) ; // } else if ( ( !Plt->AllowTwoHops() || Plt->AvoidDeadlock() ) // && !Project->HasHopConstraints() ) { // MFDgDl* Syn = new MFDgDl; // Syn->Initialize(PtP , Plt ) ; // Syn->Run() ; // Gsyn = Syn->GetGraph() ; // OrderSyn = Syn->GetOrder() ; // Cost->Initialize(Gsyn , Plt ); // Cost->Verify(PtP ) ; // Cost->Run() ; // } else if (Plt->AllowTwoHops() && !Plt->AvoidDeadlock() // && Project->HasHopConstraints() ) { // MFDgDe* Syn = new MFDgDe; // Syn->Initialize(PtPlatency , Plt , Project->GetTotalArea() ) ; // Syn->Run() ; // Gsyn = Syn->GetGraph() ; // OrderSyn = Syn->GetOrder() ; // Cost->Initialize(Gsyn , Plt ); // Cost->Verify(PtPlatency ) ; // Cost->Run() ; // } else { // if (Project->UseKmedian() ) { // KmedianMF* Syn = new KmedianMF; // Syn->Initialize(PtP , Plt , Project->Kmin() , Project->Kmax()) ; // if ( !Syn->Run() ) { // exit(1); // }; // Gsyn = Syn->GetGraph() ; // } else { // MFDg* Syn = new MFDg; // Syn->Initialize(PtP , Plt ) ; // if (Project->RunTimeBackTrack()) { // if ( !Syn->Run_2() ) { // exit(1); // }; // } else { // if ( !Syn->Run() ) { // exit(1); // }; // } // Gsyn = Syn->GetGraph() ; // } // // //OrderSyn = Syn->GetOrder() ; // Cost->Initialize(Gsyn , Plt ); // Cost->Verify(PtP ) ; // Cost->Run() ; // } // // // if ( Project->HasHopConstraints( ) && Project->HasAreaConstraint( ) ) { // // MFDD* Syn = new MFDD ; // // Syn->initialize( PtPlatency , map( ) , Plt , Project->GetTotalArea( ) ) ; // // Syn->Run( ) ; // // Gsyn = Syn->GetGraph( ) ; // // Cost->Initialize( Gsyn , Plt ); // // Cost->Verify( PtPlatency ) ; // // Cost->Run( ) ; // // } else { // // if ( !Plt->AvoidDeadlock() && Plt->AllowTwoHops( ) ) { // // MFDg* Syn = new MFDg ; // // Syn->Initialize( PtP , Plt ) ; // // Syn->Run( ) ; // // Gsyn = Syn->GetGraph( ) ; // // OrderSyn = Syn->GetOrder( ) ; // // } else { // // PowerAreaOptimizerDeadlockFree* Syn = new PowerAreaOptimizerDeadlockFree ; // // Syn->initialize( PtP , map( ) , Plt ) ; // // Syn->Run( ) ; // // Gsyn = Syn->GetGraph( ) ; // // OrderSyn = Syn->GetOrder( ) ; // // } // // Cost->Initialize( Gsyn , Plt ); // // Cost->Verify( PtP ) ; // // Cost->Run( ) ; // // Cost->ComputePtpCost(PtP) ; // // } // // finish = clock(); // // ComputationVerificationTime = (double(finish)-double(start))/CLOCKS_PER_SEC; // // //Write report // if (Project->ReportRequest() ) { // cout << "Writing report ... "; // PrintReport(Project->GetReportFileName() , Project , Plt , Cost ) ; // cout << "Done"<< endl ; // } // // //Write report // if (Project->TabAppendRequest() ) { // cout << "Appending new data ... "; // AppendRow(Project->GetTabAppendFileName() , Project , Plt , Cost ) ; // cout << "Done"<< endl ; // } // // //Generate graph // if (Project->SvgRequest() ) { // //cout << "Generating Svg file... " ; // //SvgCodeGenerator* Svg = new SvgCodeGenerator( Project->GetSvgFileName( ) , Plt->GetChipW()*1e6 , Plt->GetChipH()*1e6 ) ; // //Svg->AddForbidden( Placement ) ; // //Svg->PlotGraph( Gsyn , Plt ) ; // //Svg->Close( ) ; // //cout << "Done" << endl ; // cout << "Generating Svg file... "; // InkscapeCodeGenerator* Ink = new InkscapeCodeGenerator( Project->GetSvgFileName( ) , Plt->GetChipW()*1e6 , Plt->GetChipH()*1e6 ); // Ink->AddForbidden(Placement ) ; // Ink->AddAllowed(Plt ) ; // //for( int i = 0 ; i < Plt->Ns( ) + Plt->Nd( ) + Plt->Nr( ) ; i++) { // // if ( Plt->IsAllowed( i ) ) { // // Ink->AddReachable( i , Plt ) ; // // } // //} // if (PtP ) // Ink->PlotPaths(PtP , OrderSyn , Gsyn , Plt ) ; // else // Ink->PlotPaths(PtPlatency , OrderSyn , Gsyn , Plt ) ; // Ink->Close() ; // cout << "Done"<< endl ; // } // // if (Project->DotRequest() ) { // cout << "Generating Dot file... "; // ofstream *f; // f = DotOpen(Project->GetDotFileName() ) ; // DotGraph(f , Gsyn ) ; // DotClose(f ) ; // cout << "Done"<< endl ; // } // // if (Project->OtterRequest() ) { // cout <<"Generating osd file... "; // ofstream *f; // f = OtterOpen(Project->GetOtterFileName() ) ; // OtterGraph(f , Gsyn , Plt) ; // OtterClose(f ) ; // cout <<"Done"<< endl ; // } // // if (Project->SystemCRequest() ) { // cout << "Generating SystemC netlist... "; // if (PtP ) // SyscCodeGen(Project->GetSystemCFileName() , Gsyn , PtP , // Plt->FlitWidth() , 1.0/Plt->OperatingFrequency() , // CosiRoot) ; // else // SyscCodeGen(Project->GetSystemCFileName() , Gsyn , PtPlatency , // Plt->FlitWidth() , 1.0/Plt->OperatingFrequency() , // CosiRoot) ; // cout << "Done"<< endl ; // cout << "Generating makefile... "; // SyscMakeFileGen(Project->GetSystemCMakeFileName() , // Project->GetSystemCcppFileName() , CosiRoot , // Configuration->GetSystemCRoot() ) ; // cout <<"Done"<< endl ; // } // // CplexCodeGen Lp; // Lp.SetPlatform(Plt ) ; // Lp.SetCplexFileName("cosi.lp") ; // if (PtP ) { // Lp.SetSpecification(PtP ) ; // } else { // Lp.SetSpecification(PtPlatency ) ; // } // Lp.Run(true) ; // } // // cout << "Computation time "<< ComputationVerificationTime << " sec"<< endl ; // CosiLog.close(); exit( 0); } } void PrintBanner(ConfigParser* pC, ProjectParser* pP) { cout << endl << endl; cout << " COSI Version "<< pC->GetCosiVersion() << endl; cout << " @Copyright (c) 2006-2007 "<< endl; cout << " The Regents of the University of California."<< endl; cout << " All rights reserved. "<< endl; cout << endl; }