AMF-Placer
2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
|
Go to the documentation of this file.
27 #ifndef _GENERALSPREADER
28 #define _GENERALSPREADER
76 void spreadPlacementUnits(
float forgetRatio,
bool enableClockRegionAware =
false,
float displacementLimit = -10,
77 unsigned int spreadRegionBinSizeLimit = 1000000);
109 for (
auto curCell : curBin->
getCells())
132 inline bool isRegionOverlap(
int tmpRegionTopBinY,
int tmpRegionBottomBinY,
int tmpRegionLeftBinX,
133 int tmpRegionRightBinX)
168 void addBinRegion(
int newRegionTopBinY,
int newRegionBottomBinY,
int newRegionLeftBinX,
int newRegionRightBinX,
247 assert(
false &&
"should not reach here");
253 expandOp expandOps[4] = {{0, 0, -1, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}, {0, -1, 0, 0}};
269 inline bool isCovered(
int newTopBinY,
int newBottomBinY,
int newLeftBinX,
int newRightBinX,
dirType tmpDir,
274 for (
int binX = newLeftBinX; binX <= newRightBinX; binX++)
282 for (
int binX = newLeftBinX; binX <= newRightBinX; binX++)
290 for (
int binY = newBottomBinY; binY <= newTopBinY; binY++)
298 for (
int binY = newBottomBinY; binY <= newTopBinY; binY++)
320 dirType tmpDir,
float &tmpUtilization,
float &tmpCapacity)
327 for (
int binX = newLeftBinX; binX <= newRightBinX; binX++)
329 tmpCapacity +=
binGrid[newTopBinY][binX]->getCapacity();
330 tmpUtilization +=
binGrid[newTopBinY][binX]->getUtilization();
336 for (
int binX = newLeftBinX; binX <= newRightBinX; binX++)
338 tmpCapacity +=
binGrid[newBottomBinY][binX]->getCapacity();
339 tmpUtilization +=
binGrid[newBottomBinY][binX]->getUtilization();
344 for (
int binY = newBottomBinY; binY <= newTopBinY; binY++)
347 tmpCapacity +=
binGrid[binY][newLeftBinX]->getCapacity();
348 tmpUtilization +=
binGrid[binY][newLeftBinX]->getUtilization();
353 for (
int binY = newBottomBinY; binY <= newTopBinY; binY++)
356 tmpCapacity +=
binGrid[binY][newRightBinX]->getCapacity();
357 tmpUtilization +=
binGrid[binY][newRightBinX]->getUtilization();
360 if (tmpCapacity < 1e-5)
362 if (tmpUtilization < 1e-5)
363 tmpUtilization = 2e-5;
380 for (
int tmpDir = 0; tmpDir < 4; tmpDir++)
390 if (newTopBinY <
binGrid.size() && newBottomBinY >= 0)
392 if (newRightBinX <
binGrid[newTopBinY].size() && newLeftBinX >= 0)
395 if (!
isCovered(newTopBinY, newBottomBinY, newLeftBinX, newRightBinX,
419 if (newTopBinY <
binGrid.size() && newBottomBinY >= 0)
421 if (newRightBinX <
binGrid[newTopBinY].size() && newLeftBinX >= 0)
423 if (!
isCovered(newTopBinY, newBottomBinY, newLeftBinX, newRightBinX,
427 newRightBinX,
static_cast<dirType>(tmpDir),
444 unsigned int newRightBinX =
446 if (newTopBinY <
binGrid.size() && newBottomBinY >= 0)
448 if (newRightBinX <
binGrid[newTopBinY].size() && newLeftBinX >= 0)
450 if (!
isCovered(newTopBinY, newBottomBinY, newLeftBinX,
451 newRightBinX,
static_cast<dirType>(tmpDir),
455 newTopBinY, newBottomBinY, newLeftBinX, newRightBinX,
497 bool expanded =
false;
502 ((hUtilization / hCapacity < 0.9 * vUtilization / vCapacity) ||
503 (std::fabs(hUtilization + vUtilization) < 1e-4 && hCapacity > vCapacity)))
675 <<
" hUtilization / hCapacity < vUtilization / vCapacity:"
676 << (hUtilization / hCapacity < vUtilization / vCapacity) <<
"\n";
678 assert(
false &&
"should not be unexpandable");
693 while (failureCnt < 4)
700 if (newTopBinY <
binGrid.size() && newBottomBinY >= 0)
702 if (newRightBinX <
binGrid[newTopBinY].size() && newLeftBinX >= 0)
704 if (!
isCovered(newTopBinY, newBottomBinY, newLeftBinX, newRightBinX,
759 inline std::vector<DesignInfo::DesignCell *> &
getCells()
835 std::vector<std::vector<PlacementInfo::PlacementBinInfo *>> &
binGrid,
842 std::vector<DesignInfo::DesignCell *> tmpCells;
844 for (
auto curCell : curRegion->
getCells())
846 tmpCells.push_back(curCell);
848 std::sort(tmpCells.begin(), tmpCells.end(),
850 return a->getCellId() > b->getCellId();
852 for (
auto curCell : tmpCells)
854 cellIds.push_back(curCell->getCellId());
875 if (cellRangeBegin <= cellRangeEnd)
877 {parentBox->
cellIds.begin() + cellRangeBegin, parentBox->
cellIds.begin() + cellRangeEnd + 1});
887 std::vector<std::vector<PlacementInfo::PlacementBinInfo *>> &
binGrid;
917 for (
i = low;
i < high;
i++)
936 for (
i = low;
i < high;
i++)
966 pvt = low + n % (high - low + 1);
1073 static constexpr
float eps = 1e-4;
1099 std::vector<std::vector<PlacementInfo::PlacementBinInfo *>> &
binGrid;
1163 std::set<DesignInfo::DesignCell *> &involvedCells,
1164 std::vector<PlacementInfo::PlacementUnit *> &involvedPUVec,
1165 float forgetRatio,
bool enableClockRegionAware,
1166 float displacementLimit);
1182 std::set<DesignInfo::DesignCell *> &involvedCells, std::vector<PlacementInfo::PlacementUnit *> &involvedPUVec,
1183 float forgetRatio,
float displacementLimit,
int startId,
int endId);
1195 if (cellX < placementInfo->getGlobalMinX())
1199 if (cellY < placementInfo->getGlobalMinY())
1220 void DumpPUCoordinate(std::string dumpFileName, std::vector<PlacementInfo::PlacementUnit *> &involvedPUVec);
1234 std::vector<std::vector<PlacementInfo::PlacementBinInfo *>> &
binGrid;
1286 unsigned int numBinThr = 1000000);
int bottom()
get the bottom bin coordinate Y of the SpreadRegion in bin grid
int X()
return the column of the bin in the grid
std::set< DesignInfo::DesignCell * > cellsInRegion
a set of cells in the SpreadRegion
std::vector< DesignInfo::DesignCell * > cellsInRegionVec
a vector of cells in the SpreadRegion
int dumpSiteGridDensityCnt
bool expandable(int tmpDir)
void DumpPUCoordinate(std::string dumpFileName, std::vector< PlacementInfo::PlacementUnit * > &involvedPUVec)
float capacityShrinkRatio
std::vector< GeneralSpreader::SpreadRegion * > expandedRegions
the obtained SpreadRegion s which can be processed in parallel.
dirType curDirection
make the direction into enum type for clearer identification
BEL bin for global placement for a specific shared BEL type.
float getOverflowRatio()
Get the resource overflow ratio.
a struct to describe the expanding operation for the SpreadRegion
int top()
get the top bin coordinate Y of the SubBox in bin grid
std::set< DesignInfo::DesignCell * > & getCells()
Get the reference of the set of cells in the bin.
float dir2capacity[4]
the capacity of the four directions (absolute value)
SubBox(SubBox *parentBox, int topBinY, int bottomBinY, int leftBinX, int rightBinX, int cellRangeBegin, int cellRangeEnd)
Construct a new Sub Box object.
a DesignCell in design netlist, DesignPin objects of which might connect to DesignNet objects
bool smartFindExpandDirection(std::set< PlacementInfo::PlacementBinInfo * > &coveredBinSet)
find the legal expansion direction
float dir2utilization[4]
the utilization of the four directions (absolute value)
const int HiFPlacer_hashprimes[300]
bool isRegionOverlap(SpreadRegion *anotherRegion)
check whether overlapped with another SpreadRegion
bool legalDir[4]
a boolean array to record legal directions to expand the SpreadRegion
PlacementInfo * placementInfo
void dumpLUTFFCoordinate()
dirType
four direction options to expand the SpreadRegion
expandOp operator+(int x) const
overload operator+ to expand the SpreadRegion by given steps in the pre-set direction
GeneralSpreader(PlacementInfo *placementInfo, std::map< std::string, std::string > &JSONCfg, std::string &sharedCellType, int currentIteration, float capacityShrinkRatio, bool verbose=true)
Construct a new General Spreader object.
std::vector< std::vector< PlacementInfo::PlacementBinInfo * > > & binGrid
a reference of the global bin grid for data accessing and updating of cell density
float getGlobalMinY()
Get the Global Min Y (bottom boundary of the device)
bool isCovered(int newTopBinY, int newBottomBinY, int newLeftBinX, int newRightBinX, dirType tmpDir, std::set< PlacementInfo::PlacementBinInfo * > &coveredBinSet)
check whether an expansion in a given direction will make the SpreadRegion overlapped with some bins ...
void addCellId(int cellId)
static void updatePlacementUnitsWithSpreadedCellLocationsWorker(PlacementInfo *placementInfo, std::set< PlacementInfo::PlacementUnit * > &involvedPUs, std::set< DesignInfo::DesignCell * > &involvedCells, std::vector< PlacementInfo::PlacementUnit * > &involvedPUVec, float forgetRatio, float displacementLimit, int startId, int endId)
multi-threading workers for updating the information of the involved PlacementUnit(s)
std::vector< Location > & getCellId2location()
expandOp(int topYOp, int bottomYOp, int leftXOp, int rightXOp)
int top()
get the top bin coordinate Y of the SpreadRegion in bin grid
SpreadRegion(PlacementInfo::PlacementBinInfo *curBin, PlacementInfo *placementInfo, std::vector< std::vector< PlacementInfo::PlacementBinInfo * >> &binGrid, float capacityShrinkRatio)
Construct a new Spread Region object.
int left()
get the left bin coordinate X of the SpreadRegion in bin grid
SubBox is the exact container which is the object for bi-partitioning-based cell spreading.
int bottom()
get the bottom bin coordinate Y of the SubBox in bin grid
void spreadAndPartition()
spread cells and partition the SubBox into smaller SubBoxes
std::vector< PlacementInfo::PlacementBinInfo * > overflowBins
a vector of the found overflow bins in the current placement
This header file contains the classes of data for a standalone design netlist.
float getGlobalMaxX()
Get the Global Max X (right boundary of the device)
float capacityShrinkRatio
void dumpSiteGridDensity(std::string dumpFileName)
void DumpCellsCoordinate(std::string dumpFileName, GeneralSpreader::SpreadRegion *curRegion)
std::vector< std::vector< PlacementInfo::PlacementBinInfo * > > & binGrid
a reference of the global bin grid for data accessing and updating of cell density
This header file contains the classes of data for a standalone device.
int minExpandSize
the minimum length of boundary
bool enforceSimpleExpland
void recordSpreadedCellLocations()
record the spreaded location in PlacementInfo for later forget-ratio-based location updating
expandOp & operator=(const expandOp &a)
bool simpleFindExpandDirection(std::set< PlacementInfo::PlacementBinInfo * > &coveredBinSet)
find the expansion direction iteratively in pre-defined order
float capacityShrinkRatio
SpreadRegion is an object that record cell spreading region information, including boundaries,...
std::ostream & operator<<(std::ostream &os, GeneralSpreader::SpreadRegion::SubBox *curBox)
bool useSimpleExpland
simple expansion will iteratively try 4 directions to expand the SpreadRegion
SubBox(PlacementInfo *placementInfo, SpreadRegion *curRegion, std::vector< std::vector< PlacementInfo::PlacementBinInfo * >> &binGrid, float capacityShrinkRatio=1.0, int level=100, bool dirIsH=true)
Construct a new Sub Box object.
void quick_sort(std::vector< int > &cellIds, int p, int q, bool Xsort)
recursive implementation of quick sort for cell ids by X/Y location
float getGlobalMinX()
Get the Global Min X (left boundary of the device)
void spreadCellsH(SubBox **boxA, SubBox **boxB)
split horizontally the SubBox into smaller ones and assign cells to them
GeneralSpreader accounts for the cell spreading, which controls the cell density of specific resource...
GeneralSpreader::SpreadRegion * expandFromABin(PlacementInfo::PlacementBinInfo *curBin, float capacityShrinkRatio, unsigned int numBinThr=1000000)
obtain a SpreadRegion by expanding a cell spreading window from an overflow bin
void simpleExpand(std::set< PlacementInfo::PlacementBinInfo * > &coveredBinSet)
select the the expansion direction which is found in a pre-defined order
PlacementInfo * placementInfo
std::set< PlacementInfo::PlacementBinInfo * > coveredBinSet
a set of the bins covered by existing SpreadRegion(s)
PlacementInfo * placementInfo
std::vector< DesignInfo::DesignCell * > & getCells()
Get the cells in the SpreadRegion.
int left()
get the left bin coordinate X of the SubBox in bin grid
int RandomPivotPartition(std::vector< int > &cellIds, int low, int high, bool Xsort)
the partition/sort function for quick sorting by cell location (X or Y)
static constexpr float eps
int curDirectionIndex
record the last selection of expansion direction for later expansion
std::set< PlacementInfo::PlacementBinInfo * > binSetInRegion
a set of bins in the SpreadRegion
bool isRegionOverlap(int tmpRegionTopBinY, int tmpRegionBottomBinY, int tmpRegionLeftBinX, int tmpRegionRightBinX)
check whether the SpreadRegion is overlapped with a given boundary
static void makeCellInLegalArea(PlacementInfo *placementInfo, float &cellX, float &cellY)
ensure the X/Y is in the legal range of the target device
std::vector< std::vector< PlacementInfo::PlacementBinInfo * > > & binGrid
int LUTFFCoordinateDumpCnt
int Partition(std::vector< int > &cellIds, int low, int high, bool Xsort)
the partition/sort function for quick sorting by cell location (X or Y)
void updatePlacementUnitsWithSpreadedCellLocations(std::set< PlacementInfo::PlacementUnit * > &involvedPUs, std::set< DesignInfo::DesignCell * > &involvedCells, std::vector< PlacementInfo::PlacementUnit * > &involvedPUVec, float forgetRatio, bool enableClockRegionAware, float displacementLimit)
update the information of the involved PlacementUnit(s)
int Y()
return the row of the bin in the grid
std::map< std::string, std::string > & JSONCfg
expandOp actualExpandOps[4]
void addBinRegion(int newRegionTopBinY, int newRegionBottomBinY, int newRegionLeftBinX, int newRegionRightBinX, std::set< PlacementInfo::PlacementBinInfo * > &coveredBinSet)
add cell bins into SpreadRegion with a new boundary and update region information including boundary ...
int right()
get the right bin coordinate X of the SubBox in bin grid
bool isOverflow()
check whether the resource in this region is less than the requirement
std::string sharedCellType
void getDirCapacityAndUtilization(int newTopBinY, int newBottomBinY, int newLeftBinX, int newRightBinX, dirType tmpDir, float &tmpUtilization, float &tmpCapacity)
evaluation the utilization and capacity of the incoming bins which will be included in the SpreadRegi...
std::set< PlacementInfo::PlacementBinInfo * > overflowBinSet
a set of the found overflow bins in the current placement
void smartExpand(std::set< PlacementInfo::PlacementBinInfo * > &coveredBinSet)
select the expansion direction greedily
This header file mainly contains the definition of class PlacementInfo, including information related...
void findOverflowBins(float overflowThreshold)
find the overflow bins in the placement accoridng to a given threshold
std::vector< PlacementInfo::PlacementBinInfo * > binsInRegion
a vector of bins in the SpreadRegion
std::vector< PlacementInfo::PlacementBinInfo * > & getBinsInRegion()
Get the bins in the SpreadRegion.
int right()
get the right bin coordinate X of the SpreadRegion in bin grid
bool contains(PlacementInfo::PlacementBinInfo *curBin)
check whether SpreadRegion contains the given bin
float getGlobalMaxY()
Get the Global Max Y (top boundary of the device)
void spreadCellsV(SubBox **boxA, SubBox **boxB)
split vertically the SubBox into smaller ones and assign cells to them
std::vector< int > cellIds
the cells in this SubBox
Information related to FPGA placement (wirelength optimization, cell spreading, legalization,...
void spreadPlacementUnits(float forgetRatio, bool enableClockRegionAware=false, float displacementLimit=-10, unsigned int spreadRegionBinSizeLimit=1000000)
spread cells with a given forgetting ratio