Skip to content

Commit

Permalink
Added example for physical design. Removed required parameter (iccad)…
Browse files Browse the repository at this point in the history
… for flag -gui.
  • Loading branch information
jucemarmonteiro authored and gaflach committed Dec 21, 2017
1 parent 26d2511 commit 1731798
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rsyn/src/rsyn/shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace Rsyn {

void Shell::run(const std::string &startupScript, const bool interactive) {
if (startupScript.empty() && !interactive) {
std::cout << "Exiting. Nothing to be done... Try -gui or -interactive flags.\n";
std::cout << "Exiting. Nothing to be done... \n";
std::cout << " >> Try run with -gui, -interactive or -script <path_to_rsyn_script> flags. <<\n";
return;
} // end if

Expand Down
2 changes: 1 addition & 1 deletion x/src/x/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
desc.add_options()
("script", value<std::string>(&optScript), "The script to run at startup.")
("interactive", "Does not exit after running the script.")
("gui", value<std::string>(&optGui), "The user interface to start.");
("gui", "The graphics user interface.");

variables_map vm;
store (command_line_parser(argc, argv).options(desc)
Expand Down
227 changes: 227 additions & 0 deletions x/src/x/opto/example/PhysicalDesignEx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/* Copyright 2014-2017 Rsyn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "PhysicalDesignEx.h"
#include "rsyn/phy/PhysicalService.h"
#include <iostream>

// initializing an process

bool PhysicalDesignExample::run(const Rsyn::Json &params) {
// Getting physical service. The object which has the reference to physical design
Rsyn::PhysicalService * phService = clsSession.getService("rsyn.physical");
// Getting physical design object reference
clsPhDesign = phService->getPhysicalDesign();
// Getting design reference (netlist)
clsDesign = clsSession.getDesign();
// Getting top module reference
clsTopModule = clsDesign.getTopModule();

visitAllPhysicalInstances();

visitAllPhysicalRows();

assigningUserDefinedDataToRows();

moveCells();
return true;
} // end method

// -----------------------------------------------------------------------------

// Visiting all physical cell

void PhysicalDesignExample::visitAllPhysicalInstances() {
// Visiting all instances in the top module
std::cout << "Visiting all physical cells\n";
int count = 0;
for (Rsyn::Instance instance : clsTopModule.allInstances()) {
// skipping non cell elements
if (instance.getType() != Rsyn::CELL)
continue;

// changing instance inheritance to cell type
Rsyn::Cell cell = instance.asCell();
// Getting physical cell reference
Rsyn::PhysicalCell phCell = clsPhDesign.getPhysicalCell(cell);

// Printing cell name, position and boundaries.
// For more methods, please see the physical cell header
std::cout << "Cell name: " << instance.getName()
<< " pos: " << phCell.getPosition() << " boundaries: "
<< phCell.getBounds()
<< "\n";
if (count == 100) {
std::cout << "breaking print instances\n";
break;
}
count++;
} // end for

// Visiting all physical Ports
count = 0;
std::cout << "Visiting all physical ports\n";
for (Rsyn::Instance instance : clsTopModule.allInstances()) {
if (instance.getType() != Rsyn::PORT)
continue;
Rsyn::Port port = instance.asPort();
Rsyn::PhysicalPort phPort = clsPhDesign.getPhysicalPort(port);
std::cout << "Port name: " << port.getName()
<< " pos: " << phPort.getPosition() << " boundaries: "
<< phPort.getBounds()
<< "\n";
if (count == 100) {
std::cout << "breaking print ports\n";
break;
}
count++;
} // end for

// Visiting all physical Modules
std::cout << "Visiting all physical modules\n";
count = 0;
for (Rsyn::Instance instance : clsTopModule.allInstances()) {
if (instance.getType() != Rsyn::MODULE)
continue;
Rsyn::Module module = instance.asModule();
Rsyn::PhysicalModule phModule = clsPhDesign.getPhysicalModule(module);
std::cout << "Module name: " << module.getName()
<< " pos: " << phModule.getPosition() << " boundaries: "
<< phModule.getBounds()
<< "\n";

if (count == 100) {
std::cout << "breaking print modules\n";
break;
}
count++;
} // end for
} // end method

// -----------------------------------------------------------------------------

// Visiting all physical rows

void PhysicalDesignExample::visitAllPhysicalRows() {
// Iterating by all physical rows
std::cout << "Visiting all physical rows\n";
int count = 0;
for (Rsyn::PhysicalRow phRow : clsPhDesign.allPhysicalRows()) {
// Getting physical site reference
Rsyn::PhysicalSite phSite = phRow.getPhysicalSite();
// Getting enum physical site class
Rsyn::PhysicalSiteClass phSiteClass = phSite.getClass();
// Getting string related to the site class from an enum
std::string siteClass = Rsyn::getPhysicalSiteClass(phSiteClass);
// Getting enum to the site class from a string
Rsyn::PhysicalSiteClass phSiteClassEqual = Rsyn::getPhysicalSiteClass(siteClass);

// Printing some row data.
std::cout << "row " << phRow.getName()
<< " bounds: " << phRow.getBounds()
<< " site: " << phSite.getName()
<< " siteClass: " << siteClass
<< "\n";
if (count == 100) {
std::cout << "breaking print rows\n";
break;
}
count++;
} // end for
} // end method

// -----------------------------------------------------------------------------

void PhysicalDesignExample::assigningUserDefinedDataToRows() {
// Declaring row attributes variable
// Primitive values and objects may be associated to rows.
Rsyn::PhysicalAttribute<Rsyn::PhysicalRow, std::string> rowAtts;
// Initializing row attributes variable
rowAtts = clsPhDesign.createPhysicalAttribute();

int count = 0;
// Associating user defined attributes to the rows;
for (Rsyn::PhysicalRow phRow : clsPhDesign.allPhysicalRows()) {
rowAtts[phRow] = "userDefineAtt_"+std::to_string(count);
count++;
} // end for

count = 0;
for (Rsyn::PhysicalRow phRow : clsPhDesign.allPhysicalRows()) {
// Accessing user defined data associated to rows
std::string str = rowAtts[phRow];

std::cout<<"Rows: "<<phRow.getName()<<" userData: "<<str
<<"\n";
if (count == 100) {
std::cout << "breaking print assigning user defined data to rows\n";
break;
}
count++;
} // end for

} // end method

// -----------------------------------------------------------------------------

// Example how to move physical cells.
// If the cell is fixed, then it is not moved
void PhysicalDesignExample::moveCells(){
for (Rsyn::Instance instance : clsTopModule.allInstances()) {
// skipping non cell elements
if (instance.getType() != Rsyn::CELL)
continue;
// changing instance inheritance to cell type
Rsyn::Cell cell = instance.asCell();
// Getting physical cell reference
Rsyn::PhysicalCell phCell = clsPhDesign.getPhysicalCell(cell);
// getting current cell position.
DBUxy pos = phCell.getPosition();
// the cells are going to be moved to 100 units to right (x+100)
// and 100 units (y-100) to bottom.
pos[X] += 100;
pos[Y] -= 100;

// moving physical cell
// The only way to move cell is requesting to the physical design.
clsPhDesign.placeCell(phCell, pos);
} // end for

// printing new position of physical cells
int count = 0;
for (Rsyn::Instance instance : clsTopModule.allInstances()) {
// skipping non cell elements
if (instance.getType() != Rsyn::CELL)
continue;

// changing instance inheritance to cell type
Rsyn::Cell cell = instance.asCell();
// Getting physical cell reference
Rsyn::PhysicalCell phCell = clsPhDesign.getPhysicalCell(cell);

// Printing cell name, position and boundaries.
// For more methods, please see the physical cell header
std::cout << "Cell name: " << instance.getName()
<< " intial pos: " << phCell.getInitialPosition()
<< " current pos: "<< phCell.getPosition()
<< "\n";
if (count == 100) {
std::cout << "breaking print moved cell positions\n";
break;
}
count++;
} // end for

}
43 changes: 43 additions & 0 deletions x/src/x/opto/example/PhysicalDesignEx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright 2014-2017 Rsyn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


#ifndef PHYSICALDESIGNEXAMPLE_H
#define PHYSICALDESIGNEXAMPLE_H

#include "rsyn/session/Process.h"
#include "rsyn/session/Session.h"
#include "rsyn/phy/PhysicalDesign.h"

class PhysicalDesignExample : public Rsyn::Process {
protected:
Rsyn::Session clsSession;
Rsyn::PhysicalDesign clsPhDesign;
Rsyn::Design clsDesign;
Rsyn::Module clsTopModule;
public:
PhysicalDesignExample() = default;
PhysicalDesignExample(const PhysicalDesignExample& orig) = delete;
virtual ~PhysicalDesignExample() = default;
bool run(const Rsyn::Json &params);
private:
void visitAllPhysicalInstances();
void visitAllPhysicalRows();
void assigningUserDefinedDataToRows();
void moveCells();
};

#endif /* PHYSICALDESIGNEXAMPLE_H */

2 changes: 2 additions & 0 deletions x/src/x/setup/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "x/opto/example/QuadraticPlacement.h"
#include "x/opto/example/RandomPlacement.h"
#include "x/opto/example/SandboxTest.h"
#include "x/opto/example/PhysicalDesignEx.h"

#ifdef RSYN_ENABLE_OVERLAP_REMOVER
#include "x/opto/example/LemonLP.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ void Session::registerProcesses() {
// Example
registerProcess<ICCAD15::QuadraticPlacementExample>("example.quadraticPlacement");
registerProcess<ICCAD15::RandomPlacementExample>("example.randomPlacement");
registerProcess<PhysicalDesignExample>("example.physicalDesign");

// Testing
registerProcess<Testing::SandboxTest>("testing.sandbox");
Expand Down

0 comments on commit 1731798

Please sign in to comment.