AMF-Placer
2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
|
Go to the documentation of this file.
26 #ifndef _MACROLEGALIZER
27 #define _MACROLEGALIZER
41 #include <semaphore.h>
72 std::map<std::string, std::string> &
JSONCfg);
86 void legalize(
bool exactLegalization =
false,
bool directLegalization =
false,
bool _timingDrivenLegalize =
false);
99 float tmpAverageDisplacement = 0.0;
102 tmpAverageDisplacement += std::fabs(PUSitePair.first->X() - PUSitePair.second->X()) +
103 std::fabs(PUSitePair.first->Y() - PUSitePair.second->Y());
107 return tmpAverageDisplacement;
122 void dumpMatching(
bool fixedColumn =
false,
bool enforce =
false);
135 if (_candidateFactor > 1)
186 std::vector<PlacementInfo::Location> &
cellLoc;
218 std::map<DesignInfo::DesignCellType, std::vector<DeviceInfo::DeviceSite *>>
macroType2Sites;
226 std::map<DesignInfo::DesignCell *, std::vector<DeviceInfo::DeviceSite *>>
macro2Sites;
250 std::vector<std::vector<std::pair<int, float>>>
adjList;
274 std::vector<std::pair<PlacementInfo::PlacementUnit *, DeviceInfo::DeviceSite *>>
PULevelMatching;
416 std::map<PlacementInfo::PlacementUnit *, std::vector<DeviceInfo::DeviceSite *>>
PU2LegalSites;
422 std::map<PlacementInfo::PlacementUnit *, float>
PU2X;
428 std::map<PlacementInfo::PlacementUnit *, float>
PU2Y;
436 std::map<PlacementInfo::PlacementUnit *, int>
PU2SiteX;
445 std::map<PlacementInfo::PlacementUnit *, std::vector<int>>
PU2Columns;
451 std::set<PlacementInfo::PlacementUnit *>
BRAMPUs;
457 std::set<PlacementInfo::PlacementUnit *>
DSPPUs;
615 float DPForMinHPWL(
int colNum, std::vector<std::vector<DeviceInfo::DeviceSite *>> &Column2Sites,
616 std::vector<std::deque<PlacementInfo::PlacementUnit *>> &Column2PUs);
635 void spreadMacros(
int columnNum, std::vector<int> &columnUntilization,
636 std::vector<std::vector<DeviceInfo::DeviceSite *>> &column2Sites,
637 std::vector<std::deque<PlacementInfo::PlacementUnit *>> &column2PUs,
638 std::map<DesignInfo::DesignCell *, int> &cell2Column,
float globalBudgeRatio = 1);
649 bool macroCanBeFitIn(
int colId, std::vector<std::vector<DeviceInfo::DeviceSite *>> &Column2Sites,
650 std::deque<PlacementInfo::PlacementUnit *> Column2PUs);
678 for (
int i = 0;
i < macrosNum;
i++)
683 #pragma omp parallel for
684 for (
int i = 0;
i < macrosNum;
i++)
700 for (
int i = 0;
i < macrosNum;
i++)
736 void sortPUsByPU2Y(std::deque<PlacementInfo::PlacementUnit *> &PUs);
742 return std::fabs(macroLoc.
X - curSite->
X()) +
y2xRatio * std::fabs(macroLoc.
Y - curSite->
Y());
747 return std::fabs(curPU->
X() - curSite->
X()) +
y2xRatio * std::fabs(curPU->
Y() - curSite->
Y());
762 float PUX = 0.0, PUY = 0.0;
764 float numCellsInMacro = 1.0;
773 PUX = curSite->
X() - tmpMacro->getCellOffsetXInMacro(curCell);
774 PUY = curSite->
Y() - tmpMacro->getCellOffsetYInMacro(curCell);
775 numCellsInMacro = tmpMacro->getCells().size();
779 return (std::fabs(PUX - tmpPU->X()) +
y2xRatio * std::fabs(PUY - tmpPU->Y())) / numCellsInMacro;
781 for (
auto curNet : nets)
783 if (curNet->getDesignNet()->getPins().size() > 10000)
785 oriHPWL += curNet->getHPWL(
y2xRatio);
786 newHPWL += curNet->getNewHPWLByTrying(tmpPU, PUX, PUY,
y2xRatio);
788 return (newHPWL - oriHPWL) / numCellsInMacro;
804 float PUX = 0.0, PUY = 0.0;
811 return std::fabs(PUX - tmpPU->
X()) +
y2xRatio * std::fabs(PUY - tmpPU->
Y());
813 for (
auto curNet : nets)
815 if (curNet->getDesignNet()->getPins().size() > 10000)
817 oriHPWL += curNet->getHPWL(
y2xRatio);
818 newHPWL += curNet->getNewHPWLByTrying(tmpPU, PUX, PUY,
y2xRatio);
821 return (newHPWL - oriHPWL);
836 return std::fabs(PUX - tmpPU->
X()) +
y2xRatio * std::fabs(PUY - tmpPU->
Y());
841 for (
auto curNet : nets)
843 if (curNet->getDesignNet()->getPins().size() > 10000)
845 oriHPWL += curNet->getHPWL(
y2xRatio);
846 newHPWL += curNet->getNewHPWLByTrying(tmpPU, PUX, PUY,
y2xRatio);
849 return (newHPWL - oriHPWL);
865 for (
i = low;
i < high;
i++)
884 pvt = (high + low) / 2;
910 inline int sortPartition(std::vector<PlacementInfo::PlacementUnit *> &PUs,
int low,
int high)
915 for (
i = low;
i < high;
i++)
920 if (PUs[
i]->
X() < PUs[pivot]->
X())
926 swapPUs(&PUs[pivot], &PUs[index]);
934 pvt = low + n % (high - low + 1);
935 swapPUs(&PUs[high], &PUs[pvt]);
void swapPUs(PlacementInfo::PlacementUnit **PUA, PlacementInfo::PlacementUnit **PUB)
int DSPColumnNum
the number of DSP columns on the target device
float getAverageDisplacementOfExactLegalization()
Get the average displacement of exact legalization for the involved PlacementUnit.
float roughAverageDisplacement
the average displacement of rough legalization for the involved PlacementUnit
void findMacroCell2SitesInDistance(bool checkClockRegion)
find candidate sites for the cells left to be matched
float displacementThreshold
displacement threshold to detect potential legal sites
void swapPU(PlacementInfo::PlacementUnit **A, PlacementInfo::PlacementUnit **B)
std::map< PlacementInfo::PlacementUnit *, int > PU2SiteX
record the exact site X (column id) of involved PlacementUnits
bool enableDSPLegalization
int initialMaxNumCandidate
the maximum number of final candidate sites
std::map< PlacementInfo::PlacementUnit *, float > PU2X
record the mapping from PlacementUnits to exact DeviceSite location X
int nJobs
the number of the parallel multi-threading workers to handle the legalization problems
std::set< DesignInfo::DesignCell * > matchedMacroCells
a set of cells in macros binded to corresponding DeviceSites
void quick_sort_WLChange(DesignInfo::DesignCell *curCell, std::vector< DeviceInfo::DeviceSite * > &sites, int p, int q, PlacementInfo::Location ¯oLoc)
std::map< DesignInfo::DesignCell *, int > BRAMCell2Column
record the PlacementUnits in each column of BRAM site
std::vector< int > DSPColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for DSP
bool timingDrivenLegalize
std::vector< DesignInfo::DesignCellType > macroTypesToLegalize
a vector of Cell Type string indicating the target types handled by this MacroLegalizer
MacroLegalizer(std::string legalizerName, PlacementInfo *placementInfo, DeviceInfo *deviceInfo, std::vector< DesignInfo::DesignCellType > ¯oTypesToLegalize, std::map< std::string, std::string > &JSONCfg)
Construct a new MacroLegalizer object.
std::set< PlacementInfo::PlacementUnit * > DSPPUs
the PlacementUnits which shoudl be mapped to DSP site
a fixed group of multiple standard cells with constraints of their relative locations
void setClockRegionAware(bool _clockRegionAware)
void resetSitesMapped()
reset the mapped flag of the involved sites.
a DesignCell in design netlist, DesignPin objects of which might connect to DesignNet objects
void updatePUMatchingLocation(bool isRoughLegalization=true, bool updateDisplacement=true)
update the locations of the legalization anchors for the PlacementUnits.
std::map< DesignInfo::DesignCell *, std::vector< DeviceInfo::DeviceSite * > > macro2Sites
record the mapping from cells to the candidate sites which are NOT binded to other cells
float getHPWLChange(PlacementInfo::PlacementUnit *tmpPU, float PUX, float PUY)
get the HPWL change when the given PlacementUnit moves to the given location
std::vector< DesignInfo::DesignCell * > macroCellsToLegalize
a vector storing the Design cells which have NOT been legalized
int BRAMColumnNum
the number of BRAM columns on the target device
std::set< PlacementInfo::PlacementUnit * > BRAMPUs
the PlacementUnits which shoudl be mapped to BRAM site
MacroLegalizer maps DSP/BRAM/CARRY macros to legal location.
float initialDisplacementThreshold
displacement threshold to detect potential legal sites
int candidateFactor
we are allowed to detect a excessive number (>candidateNum) of initial candidates....
std::vector< std::vector< std::pair< int, float > > > adjList
the adjacent list of the bipartite graph
std::map< PlacementInfo::PlacementUnit *, float > PU2Y
record the mapping from PlacementUnits to exact DeviceSite location Y
void spreadMacros(int columnNum, std::vector< int > &columnUntilization, std::vector< std::vector< DeviceInfo::DeviceSite * >> &column2Sites, std::vector< std::deque< PlacementInfo::PlacementUnit * >> &column2PUs, std::map< DesignInfo::DesignCell *, int > &cell2Column, float globalBudgeRatio=1)
spread PlacementUnits accross columns to resolve resource overflow
void quick_sort_locX(std::vector< PlacementInfo::PlacementUnit * > &PUs, int p, int q)
std::string legalizerName
float fixedColumnAverageDisplacement
the average displacement of fixed column (but not exactly consective) legalization for the involved P...
void mapMacrosToColumns(bool directLegalization)
map the macros to the columns according to the locations of the cells in it
std::vector< float > BRAMColumnXs
the floating-point X location of the BRAM columns on the device
void roughlyLegalize()
conduct rough legalization.
bool clockRegionCasLegalization
std::map< std::string, std::string > & JSONCfg
std::vector< std::vector< DeviceInfo::DeviceSite * > > DSPColumn2Sites
record the sites in each column of DSP
std::map< DesignInfo::DesignCellType, std::vector< DeviceInfo::DeviceSite * > > macroType2Sites
a map record the potential sites of different site types
int getMarcroCellNum(PlacementInfo::PlacementUnit *tmpMacroUnit)
check how many sites are required by the given PlacementUnit
This header file contains the classes of data for a standalone design netlist.
int sortPartition(std::vector< PlacementInfo::PlacementUnit * > &PUs, int low, int high)
int CARRYColumnNum
the number of CARRY columns on the target device
void getMacrosToLegalize()
get the PlacementMacro(s) which SHOULD be legalized
int findCorrespondingColumn(float curX, std::vector< float > &Xs)
find the closest column for a given location X
void findPossibleLegalLocation(bool fixedColumn=false)
find potential sites for each PlacementUnit
std::vector< std::vector< PlacementNet * > > & getPlacementUnitId2Nets()
This header file contains the classes of data for a standalone device.
std::vector< std::vector< DeviceInfo::DeviceSite * > > CARRYColumn2Sites
record the sites in each column of CARRY
std::vector< DeviceInfo::DeviceSite * > * findNeiborSiteFromBinGrid(DesignInfo::DesignCell *curCell, float targetX, float targetY, float displacementThreshold, int siteNumThreshold, bool checkClockRegion=false)
find neibor device sites of a given cell from bin grid
void resetSettings()
clear the mapping information and reset the mapping parameters
bool enableCARRYLegalization
PlacementInfo::CompatiblePlacementTable * compatiblePlacementTable
compatiblePlacementTable describes the type mapping from design to device, where a cell can be placed...
std::vector< PlacementInfo::Location > & cellLoc
a reference of the locations of cells (in cellId order)
Site class for site on device.
std::vector< std::pair< DesignInfo::DesignCell *, DeviceInfo::DeviceSite * > > cellLevelMatching
record the binding between design standard cells and DeviceSites as a vector of pairs
std::vector< std::deque< PlacementInfo::PlacementUnit * > > BRAMColumn2PUs
record the PlacementUnits in each column of BRAM Sites
float getHPWLChange(PlacementInfo::PlacementUnit *tmpPU, DeviceInfo::DeviceSite *curSite)
get the HPWL change when the given PlacementUnit moves to the given DeviceSite
std::vector< DesignInfo::DesignCell * > initialMacrosToLegalize
a vector storing the cells in macros which SHOULD be legalized
describes the type mapping from design to device, where a cell can be placed (which BEL in which site...
void sortPUsByPU2Y(std::deque< PlacementInfo::PlacementUnit * > &PUs)
void legalize(bool exactLegalization=false, bool directLegalization=false, bool _timingDrivenLegalize=false)
conduct legalization and map the PlacementUnit of one of the given types to sites
std::map< DesignInfo::DesignCell *, int > DSPCell2Column
record the PlacementUnits in each column of DSP site
float getHPWLChange(DesignInfo::DesignCell *curCell, DeviceInfo::DeviceSite *curSite)
get the HPWL change when the given DesignCell moves to the given DeviceSite
std::vector< int > BRAMColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for BRAM
std::map< DeviceInfo::DeviceSite *, int > rightSiteIds
map sites to temperary indexes for bipartite matching
std::vector< std::vector< DeviceInfo::DeviceSite * > > BRAMColumn2Sites
record the sites in each column of BRAM
a movement unit in placement with information of location and resource demand
std::map< DesignInfo::DesignCell *, std::vector< DeviceInfo::DeviceSite * > * > macro2SitesInDisplacementThreshold
a cache record the candidate sites within a given displacement threshold for each cell in the macros
int getCellId()
Get the Cell Id in the cell list.
void dumpMatching(bool fixedColumn=false, bool enforce=false)
std::set< PlacementInfo::PlacementUnit * > CARRYPUs
the PlacementUnits which shoudl be mapped to CARRY BEL
float finalAverageDisplacement
the average displacement of exact legalization for the involved PlacementUnit
std::vector< std::deque< PlacementInfo::PlacementUnit * > > DSPColumn2PUs
record the PlacementUnits in each column of DSP Sites
std::vector< std::deque< PlacementInfo::PlacementUnit * > > CARRYColumn2PUs
record the PlacementUnits in each column of CARRY
void fixedColumnLegalize(bool directLegalization)
conduct fixed-column legalization as a step in exact legalization. During fixed-column legalization,...
int BRAMRowNum
the number of BRAM rows on the target device
int DumpMacroLegalizationCnt
std::vector< float > CARRYColumnXs
the floating-point X location of the CARRY columns on the device
int maxNumCandidate
the maximum number of final candidate sites
void updateMatchingAndUnmatchedMacroCells()
record the matching in private list and update the list of cells which are not matched by the bi-part...
void resolveOverflowColumns()
resolve the overflow columns during fixed column legalization by spreading "outliers" to neighbor col...
Information class related to FPGA device, including the details of BEL/Site/Tile/ClockRegion.
void createBipartiteGraph()
Create a bipartite graph between PlacementUnit and potential DeviceSites.
void setClockRegionCasLegalization(bool _clockRegionCasLegalization)
std::map< DesignInfo::DesignCell *, int > CARRYCell2Column
record the PlacementUnits in each column of CARRY site
void finalLegalizeBasedOnDP()
finally dynamic programming to legalize the macros which have been mapped to the columns.
int sortPartition(DesignInfo::DesignCell *curCell, std::vector< DeviceInfo::DeviceSite * > &sites, int low, int high, PlacementInfo::Location ¯oLoc)
void sortSitesBySiteY(std::vector< DeviceInfo::DeviceSite * > &sites)
the smallest, indivisible, representable component. It will include only one standard cell
void swapSitePtr(DeviceInfo::DeviceSite **siteA, DeviceInfo::DeviceSite **siteB)
int DSPRowNum
the number of DSP rows on the target device
void setSitesMapped()
Set the sites which are binded as mapped so they will not be mapped to other elements in the netlist.
float getDisplacement(PlacementInfo::PlacementUnit *curPU, DeviceInfo::DeviceSite *curSite)
void setIntitialParameters(float displacementThr, int candidateNum, int _candidateFactor=-1)
Set the intitial parameters of the legalizer.
std::map< PlacementInfo::PlacementUnit *, std::vector< DeviceInfo::DeviceSite * > > PU2LegalSites
float getAverageDisplacementOfRoughLegalization()
Get the average displacement of rough legalization for the involved PlacementUnit.
float DPForMinHPWL(int colNum, std::vector< std::vector< DeviceInfo::DeviceSite * >> &Column2Sites, std::vector< std::deque< PlacementInfo::PlacementUnit * >> &Column2PUs)
DP function for the legalization of a specific type of macros in the same column.
int clockRegionHeightOfDSE_BRAM
int RandomPivotPartition(DesignInfo::DesignCell *curCell, std::vector< DeviceInfo::DeviceSite * > &sites, int low, int high, PlacementInfo::Location ¯oLoc)
MinCostBipartiteMatcher * minCostBipartiteMatcher
min-cost bipartite matching solver for the legalization
void findMacroType2AvailableSites()
find available sites for each specific macro type required by the constructor
PlacementUnit * getPlacementUnitByCell(DesignInfo::DesignCell *curCell)
PlacementInfo * placementInfo
std::vector< DeviceInfo::DeviceSite * > siteList
a vector for the candidate sites for bipartite matching
bool enableBRAMLegalization
void resetMacroCell2SitesInDistance()
clear the information of candidate sites for the cells left to be matched
std::vector< int > CARRYColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for CARRY
std::set< PlacementInfo::PlacementUnit * > macroUnitsToLegalizeSet
a set storing the macros which have NOT been legalized
int CARRYRowNum
the number of CARRY rows on the target device
This header file mainly contains the definition of class PlacementInfo, including information related...
int findIdMaxWithRecurence(int minId, int maxId, std::vector< int > &ids)
find the column which contains the most of cells in a macro in a specific range of columns
int RandomPivotPartition(std::vector< PlacementInfo::PlacementUnit * > &PUs, int low, int high)
std::map< PlacementInfo::PlacementUnit *, std::vector< int > > PU2Columns
record the column id for the binded cells in involved PlacementUnits
std::vector< std::pair< PlacementInfo::PlacementUnit *, DeviceInfo::DeviceSite * > > PULevelMatching
record the binding between PlacementUnits and DeviceSites as a vector of pairs
bool macroCanBeFitIn(int colId, std::vector< std::vector< DeviceInfo::DeviceSite * >> &Column2Sites, std::deque< PlacementInfo::PlacementUnit * > Column2PUs)
check whether the current macros can be fitted in the column legally.
std::set< DeviceInfo::DeviceSite * > matchedSites
a set of DeviceSites binded to corresponding PlacementUnits
float getDisplacement(PlacementInfo::Location ¯oLoc, DeviceInfo::DeviceSite *curSite)
std::vector< float > DSPColumnXs
the floating-point X location of the DSP columns on the device
Information related to FPGA placement (wirelength optimization, cell spreading, legalization,...