19 #ifndef TORC_PLACER_PLACEMENT_HPP
20 #define TORC_PLACER_PLACEMENT_HPP
28 #include <boost/timer.hpp>
30 #include <boost/random/mersenne_twister.hpp>
31 #include <boost/random/uniform_int.hpp>
32 #include <boost/random/variate_generator.hpp>
111 std::vector<boost::variate_generator<
mt19937&,
131 std::cout <<
"PLACEMENT CONSTRUCTOR" << std::endl;
142 InstanceSharedPtrVector::iterator p =
mDesign->instancesBegin();
143 InstanceSharedPtrVector::iterator e =
mDesign->instancesEnd();
144 for ( ; p != e; p++) {
154 NetSharedPtrVector::iterator q =
mDesign->netsBegin();
155 NetSharedPtrVector::iterator f =
mDesign->netsEnd();
156 for ( ; q != f; q++) {
169 std::cout <<
"Summary INSTANCES: " << a <<
" = " <<
mAllInstances.size() << std::endl;
172 std::cout <<
"There are " <<
mAllSites.getSize() <<
" sites" << std::endl;
186 for (
uint32 j = 0; j < map.size(); j++) {
203 <<
" is the candidate count for this type" << std::endl;
212 std::cout <<
"INITIAL PLACEMENT" << std::endl;
222 std::vector<std::vector<const Site*> > sitesByType;
225 sitesByType.push_back(std::vector<const Site*>());
236 std::cout <<
"Placing instance: " << instance->getName() << std::endl;
241 std::cout <<
"\tInstance type index: " << typeIndex <<
" ("
246 uint32 siteTypeIndex = typeIndex;
247 if (sitesByType[siteTypeIndex].size() == 0) {
251 for (
uint32 j = 0; j < map.size(); j++) {
252 siteTypeIndex = map[j];
253 if (sitesByType[siteTypeIndex].size() > 0)
break;
256 std::cout <<
"\tSite type index: " << siteTypeIndex <<
" ("
262 boost::uniform_int<uint32> range(0, sitesByType[siteTypeIndex].size() - 1);
263 boost::variate_generator<mt19937&, boost::uniform_int<uint32> > random(gen, range);
266 std::cout <<
"\tSelected index " << r <<
" from " << sitesByType[siteTypeIndex].size() << std::endl;
268 const Site* selectedSite = sitesByType[siteTypeIndex][r];
270 std::cout <<
"\tSelected Site: " << selectedSite->
getName() << std::endl;
278 sitesByType[siteTypeIndex].erase(sitesByType[siteTypeIndex].begin() + r);
285 std::cout <<
"WRITING PLACEMENT TO DESIGN" << std::endl;
289 const Site* site = boost::any_cast<
const Site*>(
295 instance->setSite(siteName);
296 instance->setTile(tileName);
308 if (debug) std::cout <<
"net : " << net->getName() << std::endl;
309 if (net->getSourceCount() != 1 || net->getSinkCount() < 1) {
310 if (debug) std::cout <<
"\tEmpty!" << std::endl;
319 if (debug) std::cout <<
"\tsource instance: " << instance->getName() << std::endl;
320 const Site* site = boost::any_cast<
const Site*>(instance->getAnnotation(
323 std::cout << instance->
getName() <<
" doesn't have a site." << std::endl;
326 if (debug) std::cout <<
"\t\tsource instance site: " << site->
getName()
336 InstancePinSharedPtrVector::iterator p = net->sinksBegin();
337 InstancePinSharedPtrVector::iterator e = net->sinksEnd();
338 for ( ; p != e; p++) {
339 instance = (*p)->getInstancePtr().lock();
340 if (debug) std::cout <<
"\tsink instance: " << instance->
getName() << std::endl;
341 const Site* sinkSite = boost::any_cast<
const Site*>(instance->getAnnotation(
343 if (sinkSite == NULL) {
344 std::cout << instance->
getName() <<
" doesn't have a site (sink)."
353 if (trow < row1) row1 = trow;
354 if (tcol < col1) col1 = tcol;
355 if (trow > row2) row2 = trow;
356 if (tcol > col2) col2 = tcol;
358 if (debug) std::cout <<
"\t\tcost reported: " << sum <<
" / " << net->getSinkCount()
359 <<
" = " << ((float)sum / (
float)net->getSinkCount()) << std::endl;
360 mCost += (row2 - row1) + (col2 - col1);
361 if (debug) std::cout <<
"\t\t" <<
mCost << std::endl;
363 std::cout <<
"updateCostFull: " <<
mCost << std::endl;
366 if (debug) std::cout <<
"randomMove: " << std::endl;
370 if (debug) std::cout <<
"\tselected inst: "
376 if (debug) std::cout <<
"\tinstance type: " << instanceType << std::endl;
378 if (debug) std::cout <<
"\tselected: " << s <<
" of "
389 bool illegalMapping =
true;
391 for (
uint32 i = 0; i < v.size(); i++) {
392 if (departureSiteType == v[i]) illegalMapping =
false;
394 if (illegalMapping)
return false;
400 if (debug) std::cout <<
"\tCost before move: " <<
mCost << std::endl;
402 if (debug) std::cout <<
"\tCost without instance nets: " <<
mCost << std::endl;
416 if (debug) std::cout <<
"\tCost after move: " <<
mCost << std::endl;
421 std::cout <<
"undoMove: " << std::endl;
467 std::set<NetSharedPtr> modifiedNets;
469 for ( ; p != e; p++) {
473 for ( ; q != f; q++) {
474 NetSharedPtr n = (*q).second->getParentWeakPtr().lock();
475 modifiedNets.insert(n);
480 std::set<NetSharedPtr>::iterator r = modifiedNets.begin();
481 std::set<NetSharedPtr>::iterator g = modifiedNets.end();
482 for ( ; r != g; r++) {
489 std::set<NetSharedPtr> modifiedNets;
494 if (inInstance1 != 0) {
495 q = inInstance1->pinsBegin();
496 f = inInstance1->pinsEnd();
497 for ( ; q != f; q++) {
498 NetSharedPtr n = (*q).second->getParentWeakPtr().lock();
499 modifiedNets.insert(n);
502 if (inInstance2 != 0) {
503 q = inInstance2->pinsBegin();
504 f = inInstance2->pinsEnd();
505 for ( ; q != f; q++) {
506 NetSharedPtr n = (*q).second->getParentWeakPtr().lock();
507 modifiedNets.insert(n);
510 std::set<NetSharedPtr>::iterator r = modifiedNets.begin();
511 std::set<NetSharedPtr>::iterator g = modifiedNets.end();
512 for ( ; r != g; r++) {
520 if (
mDebug) std::cout <<
"getNetCost - net : " << inNet->getName() << std::endl;
521 if (inNet->getSourceCount() != 1 || inNet->getSinkCount() < 1) {
522 if (
mDebug) std::cout <<
"\tEmpty!" << std::endl;
531 if (
mDebug) std::cout <<
"\tsource instance: " << instance->getName() << std::endl;
532 const Site* site = boost::any_cast<
const Site*>(instance->getAnnotation(
535 std::cout << instance->
getName() <<
" doesn't have a site." << std::endl;
538 if (
mDebug) std::cout <<
"\t\tsource instance site: " << site->
getName()
548 InstancePinSharedPtrVector::iterator p = inNet->sinksBegin();
549 InstancePinSharedPtrVector::iterator e = inNet->sinksEnd();
550 for ( ; p != e; p++) {
551 instance = (*p)->getInstancePtr().lock();
552 if (
mDebug) std::cout <<
"\tsink instance: " << instance->
getName() << std::endl;
553 const Site* sinkSite = boost::any_cast<
const Site*>(instance->getAnnotation(
555 if (sinkSite == NULL) {
556 std::cout << instance->
getName() <<
" doesn't have a site (sink)."
565 if (trow < row1) row1 = trow;
566 if (tcol < col1) col1 = tcol;
567 if (trow > row2) row2 = trow;
568 if (tcol > col2) col2 = tcol;
570 if (
mDebug) std::cout <<
"\t\tcost reported: " << sum <<
" / " << inNet->getSinkCount()
571 <<
" = " << ((float)sum / (
float)inNet->getSinkCount()) << std::endl;
572 returnCost = (row2 - row1) + (col2 - col1);
573 if (
mDebug) std::cout <<
"\t\t" <<
mCost << std::endl;
582 #endif // TORC_PLACER_PLACEMENT_HPP
ENetType
Enumeration of net power types.
Placement(DeviceWrapper &inDevice, DesignSharedPtr inDesign)
void updateCostRemoveInstances(InstanceSharedPtrVector &inInstances)
std::vector< InstanceSharedPtr > InstanceSharedPtrVector
Vector of Instance shared pointers.
std::vector< boost::uniform_int< uint32 > > mUniformTypeRanges
void updateCostAddInstances(InstanceSharedPtrVector &inInstances)
const PrimitiveDef * getPrimitiveDefPtr(void) const
Returns a pointer to the associated primitive definition.
Header for Placer helper functions.
Device database, including complete wiring and logic support.
physical::ENetType ENetType
Wrapper of the device database for placing the design.
const Tiles & getTiles(void) const
Returns a constant reference to the family and device tile data.
std::vector< SitePtrVector > SitePtrVectorVector
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
InstancePinMap::iterator InstancePinSharedPtrIterator
Non-constant iterator to InstancePin shared pointers.
Encapsulation of primitive site definition, with associated connections, elements, and pins.
const std::string & getName(uint32 inIndex)
physical::NetSharedPtrVector NetSharedPtrVector
std::vector< uint32 > & getLegalInstancesForSite(uint32 inSiteTypeIndex)
std::vector< InstancePinSharedPtr > InstancePinSharedPtrVector
Vector of InstancePin shared pointers.
Wrapper of the Design for placing the design.
SitePtrVectorVector mCandidatesByType
physical::NetSharedPtr NetSharedPtr
uint32 getNetCost(NetSharedPtr inNet)
std::vector< InstanceSharedPtrVector > InstanceSharedPtrVectorVector
boost::shared_ptr< class InstancePin > InstancePinSharedPtr
Shared pointer encapsulation of an InstancePin.
InstanceSharedPtr mSelectedInstance
boost::mt19937 mRandomSource
boost::uniform_int< uint32 > mUniformInstanceRange
boost::variate_generator< mt19937 &, uinform_range > random_generator
InstanceSharedPtr mEvictedInstance
Encapsulation of a device logic site.
physical::DesignSharedPtr DesignSharedPtr
void writePlacementToDesign()
Site type and population data for the family and the device.
Header for the Design class.
physical::InstancePinSharedPtrVector InstancePinSharedPtrVector
const string & getName(void) const
Returns the site name.
void updateCostFull(bool debug)
boost::unordered_map< InstanceSharedPtr, Site * > InstanceSharedPtrToSitePtrMap
std::vector< NetSharedPtr > NetSharedPtrVector
Vector of Net shared pointers.
boost::shared_ptr< Net > NetSharedPtr
Shared pointer encapsulation of a Net.
physical::InstanceSharedPtr InstanceSharedPtr
TileIndex getTileIndex(void) const
Returns the index of the containing tile.
boost::shared_ptr< Instance > InstanceSharedPtr
Shared pointer encapsulation of an Instance.
SiteTypeCount getSiteTypeCount(void) const
Returns the site type count for this family.
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
void updateCostRemovePair(InstanceSharedPtr inInstance1, InstanceSharedPtr inInstance2)
Header for the Placer related annotations.
physical::InstanceSharedPtrVector InstanceSharedPtrVector
boost::unordered_map< const Site *, InstanceSharedPtr > SitePtrToInstanceSharedPtrMap
SitePtrToInstanceSharedPtrMap mAssignedSites
SitePtrVectorVector mAllSitesByType
InstanceSharedPtrVector mAllInstances
SitePtrToIntMap mSiteTypeLookup
void updateCostAddPair(InstanceSharedPtr inInstance1, InstanceSharedPtr inInstance2)
boost::uniform_int< uint32 > uinform_range
Header for the Placer class.
physical::InstancePinSharedPtr InstancePinSharedPtr
std::vector< const Site * > SitePtrVector
boost::unordered_map< const Site *, uint32 > SitePtrToIntMap
const architecture::Array< const Site > & mAllSites
InstanceSharedPtrVectorVector mAllInstancesByType
std::vector< boost::variate_generator< mt19937 &, boost::uniform_int< uint32 > > * > mTypeRandomGen
const char * getName(void) const
Returns the name for this tile.
uint32 getTypeIndex(const std::string &inType)
Get the type index for a given type name, creates a new entry if not found.
void updateCostHelper(InstanceSharedPtr inInstance1, InstanceSharedPtr inInstance2, bool addCost)
PlacementSiteTypeMapping & mTypeMapping
boost::variate_generator< mt19937 &, boost::uniform_int< uint32 > > mInstanceRandomGen
Header for the DeviceWrapper class.
void undoMove(bool debug)
std::vector< uint32 > & getLegalSitesForInstance(uint32 inInstanceTypeIndex)
architecture::Sites Sites
Encapsulation of a static array.
void updateCostHelper(InstanceSharedPtrVector &inInstances, bool addCost)
NetSharedPtrVector mAllNets
InstanceSharedPtrVector::iterator InstanceSharedPtrIterator
Non-constant iterator to Instance shared pointers.
bool randomMove(bool debug)
boost::uint32_t getInstanceTypeIndex(physical::InstanceSharedPtr inInstance)
const string & getName(void) const
Returns the name of the primitive.