AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MacroLegalizer.h
Go to the documentation of this file.
1 
26 #ifndef _MACROLEGALIZER
27 #define _MACROLEGALIZER
28 
29 #include "DesignInfo.h"
30 #include "DeviceInfo.h"
32 #include "PlacementInfo.h"
33 #include "dumpZip.h"
34 #include "sysInfo.h"
35 #include <assert.h>
36 #include <fstream>
37 #include <iostream>
38 #include <map>
39 #include <mutex>
40 #include <omp.h>
41 #include <semaphore.h>
42 #include <set>
43 #include <sstream>
44 #include <string>
45 #include <thread>
46 #include <vector>
47 
58 {
59  public:
71  std::vector<DesignInfo::DesignCellType> &macroTypesToLegalize,
72  std::map<std::string, std::string> &JSONCfg);
74  {
77  }
78 
86  void legalize(bool exactLegalization = false, bool directLegalization = false, bool _timingDrivenLegalize = false);
87 
96  {
97  if (finalAverageDisplacement > 1000)
99  float tmpAverageDisplacement = 0.0;
100  for (auto PUSitePair : PULevelMatching)
101  {
102  tmpAverageDisplacement += std::fabs(PUSitePair.first->X() - PUSitePair.second->X()) +
103  std::fabs(PUSitePair.first->Y() - PUSitePair.second->Y());
104  }
105  tmpAverageDisplacement /= PULevelMatching.size();
106 
107  return tmpAverageDisplacement;
108  }
109 
118  {
120  }
121 
122  void dumpMatching(bool fixedColumn = false, bool enforce = false);
123 
131  void setIntitialParameters(float displacementThr, int candidateNum, int _candidateFactor = -1)
132  {
133  initialDisplacementThreshold = displacementThr;
134  initialMaxNumCandidate = candidateNum;
135  if (_candidateFactor > 1)
136  {
137  candidateFactor = _candidateFactor;
138  }
139  }
140 
147  void resetSitesMapped();
148 
149  void setClockRegionAware(bool _clockRegionAware)
150  {
151  clockRegionAware = _clockRegionAware;
152  }
153 
154  void setClockRegionCasLegalization(bool _clockRegionCasLegalization)
155  {
156  clockRegionCasLegalization = _clockRegionCasLegalization;
157  }
158 
159  inline bool hasNoTarget()
160  {
161  return noTarget;
162  }
163 
164  private:
165  std::string legalizerName;
168 
175 
180  std::vector<DesignInfo::DesignCellType> macroTypesToLegalize;
181 
186  std::vector<PlacementInfo::Location> &cellLoc;
187 
188  std::map<std::string, std::string> &JSONCfg;
189 
195 
200  std::vector<DesignInfo::DesignCell *> macroCellsToLegalize;
201 
206  std::vector<DesignInfo::DesignCell *> initialMacrosToLegalize;
207 
212  std::set<PlacementInfo::PlacementUnit *> macroUnitsToLegalizeSet;
213 
218  std::map<DesignInfo::DesignCellType, std::vector<DeviceInfo::DeviceSite *>> macroType2Sites;
219 
226  std::map<DesignInfo::DesignCell *, std::vector<DeviceInfo::DeviceSite *>> macro2Sites;
227 
232  std::map<DesignInfo::DesignCell *, std::vector<DeviceInfo::DeviceSite *> *> macro2SitesInDisplacementThreshold;
233 
238  std::map<DeviceInfo::DeviceSite *, int> rightSiteIds;
239 
244  std::vector<DeviceInfo::DeviceSite *> siteList;
245 
250  std::vector<std::vector<std::pair<int, float>>> adjList;
251 
256  std::set<DesignInfo::DesignCell *> matchedMacroCells;
257 
262  std::set<DeviceInfo::DeviceSite *> matchedSites;
263 
268  std::vector<std::pair<DesignInfo::DesignCell *, DeviceInfo::DeviceSite *>> cellLevelMatching;
269 
274  std::vector<std::pair<PlacementInfo::PlacementUnit *, DeviceInfo::DeviceSite *>> PULevelMatching;
275 
277 
283 
288  int maxNumCandidate = 30;
289 
294  int BRAMColumnNum = -1;
295 
300  int DSPColumnNum = -1;
301 
306  int CARRYColumnNum = -1;
307 
312  int BRAMRowNum = -1;
313 
318  int DSPRowNum = -1;
319 
324  int CARRYRowNum = -1;
325 
330  std::vector<float> BRAMColumnXs;
331 
336  std::vector<float> DSPColumnXs;
337 
342  std::vector<float> CARRYColumnXs;
343 
348  std::vector<std::vector<DeviceInfo::DeviceSite *>> BRAMColumn2Sites;
349 
354  std::vector<std::vector<DeviceInfo::DeviceSite *>> DSPColumn2Sites;
355 
360  std::vector<std::vector<DeviceInfo::DeviceSite *>> CARRYColumn2Sites;
361 
366  std::vector<std::deque<PlacementInfo::PlacementUnit *>> BRAMColumn2PUs;
367 
372  std::vector<std::deque<PlacementInfo::PlacementUnit *>> DSPColumn2PUs;
373 
378  std::vector<std::deque<PlacementInfo::PlacementUnit *>> CARRYColumn2PUs;
379 
384  std::vector<int> BRAMColumnUntilization;
385 
390  std::vector<int> DSPColumnUntilization;
391 
396  std::vector<int> CARRYColumnUntilization;
397 
402  std::map<DesignInfo::DesignCell *, int> BRAMCell2Column;
403 
408  std::map<DesignInfo::DesignCell *, int> DSPCell2Column;
409 
414  std::map<DesignInfo::DesignCell *, int> CARRYCell2Column;
415 
416  std::map<PlacementInfo::PlacementUnit *, std::vector<DeviceInfo::DeviceSite *>> PU2LegalSites;
417 
422  std::map<PlacementInfo::PlacementUnit *, float> PU2X;
423 
428  std::map<PlacementInfo::PlacementUnit *, float> PU2Y;
429 
436  std::map<PlacementInfo::PlacementUnit *, int> PU2SiteX;
437 
445  std::map<PlacementInfo::PlacementUnit *, std::vector<int>> PU2Columns;
446 
451  std::set<PlacementInfo::PlacementUnit *> BRAMPUs;
452 
457  std::set<PlacementInfo::PlacementUnit *> DSPPUs;
458 
463  std::set<PlacementInfo::PlacementUnit *> CARRYPUs;
464 
466  bool enableDSPLegalization = false;
468  bool verbose = false;
469  float y2xRatio = 1.0;
470  bool clockRegionAware = false;
472  bool timingDrivenLegalize = false;
474 
479  float finalAverageDisplacement = 10000.0;
480 
489 
494  float roughAverageDisplacement = 10000.0;
495 
496  bool noTarget = false;
497 
503 
509 
514  int nJobs = 1;
515 
522 
527  void getMacrosToLegalize();
528 
534 
539  void resolveOverflowColumns();
540 
546  void findPossibleLegalLocation(bool fixedColumn = false);
547 
553  void mapMacrosToColumns(bool directLegalization);
554 
562  int findCorrespondingColumn(float curX, std::vector<float> &Xs);
563 
568  void createBipartiteGraph();
569 
578  void roughlyLegalize();
579 
586  void fixedColumnLegalize(bool directLegalization);
587 
597  void updatePUMatchingLocation(bool isRoughLegalization = true, bool updateDisplacement = true);
598 
605  void finalLegalizeBasedOnDP();
606 
615  float DPForMinHPWL(int colNum, std::vector<std::vector<DeviceInfo::DeviceSite *>> &Column2Sites,
616  std::vector<std::deque<PlacementInfo::PlacementUnit *>> &Column2PUs);
617 
624 
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);
639 
649  bool macroCanBeFitIn(int colId, std::vector<std::vector<DeviceInfo::DeviceSite *>> &Column2Sites,
650  std::deque<PlacementInfo::PlacementUnit *> Column2PUs);
651 
660  int findIdMaxWithRecurence(int minId, int maxId, std::vector<int> &ids);
661 
666  void setSitesMapped();
667 
672  void findMacroCell2SitesInDistance(bool checkClockRegion)
673  {
675 
676  int macrosNum = macroCellsToLegalize.size();
677 
678  for (int i = 0; i < macrosNum; i++)
679  {
681  }
682 
683 #pragma omp parallel for
684  for (int i = 0; i < macrosNum; i++)
685  {
688  curCell, cellLoc[curCell->getCellId()].X, cellLoc[curCell->getCellId()].Y, displacementThreshold,
689  candidateFactor * maxNumCandidate, checkClockRegion);
690  }
691  }
692 
698  {
699  int macrosNum = macroCellsToLegalize.size();
700  for (int i = 0; i < macrosNum; i++)
701  {
703  delete macro2SitesInDisplacementThreshold[curCell];
704  }
705  }
706 
711  inline void resetSettings()
712  {
715  matchedMacroCells.clear();
716  matchedSites.clear();
717  cellLevelMatching.clear();
718  PULevelMatching.clear();
719  }
720 
728 
730  {
732  *A = *B;
733  *B = C;
734  }
735 
736  void sortPUsByPU2Y(std::deque<PlacementInfo::PlacementUnit *> &PUs);
737 
738  void sortSitesBySiteY(std::vector<DeviceInfo::DeviceSite *> &sites);
739 
741  {
742  return std::fabs(macroLoc.X - curSite->X()) + y2xRatio * std::fabs(macroLoc.Y - curSite->Y());
743  }
744 
746  {
747  return std::fabs(curPU->X() - curSite->X()) + y2xRatio * std::fabs(curPU->Y() - curSite->Y());
748  }
749 
758  {
759  float oriHPWL = 0.0;
760  float newHPWL = 0.0;
761  auto tmpPU = placementInfo->getPlacementUnitByCell(curCell);
762  float PUX = 0.0, PUY = 0.0;
763  auto nets = placementInfo->getPlacementUnitId2Nets()[tmpPU->getId()];
764  float numCellsInMacro = 1.0;
765  if (dynamic_cast<PlacementInfo::PlacementUnpackedCell *>(tmpPU))
766  {
767  PUX = curSite->X();
768  PUY = curSite->Y();
769  }
770  else if (PlacementInfo::PlacementMacro *tmpMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(tmpPU))
771  {
772 
773  PUX = curSite->X() - tmpMacro->getCellOffsetXInMacro(curCell);
774  PUY = curSite->Y() - tmpMacro->getCellOffsetYInMacro(curCell);
775  numCellsInMacro = tmpMacro->getCells().size();
776  }
777 
779  return (std::fabs(PUX - tmpPU->X()) + y2xRatio * std::fabs(PUY - tmpPU->Y())) / numCellsInMacro;
780 
781  for (auto curNet : nets)
782  {
783  if (curNet->getDesignNet()->getPins().size() > 10000) // it could be clock
784  continue;
785  oriHPWL += curNet->getHPWL(y2xRatio);
786  newHPWL += curNet->getNewHPWLByTrying(tmpPU, PUX, PUY, y2xRatio);
787  }
788  return (newHPWL - oriHPWL) / numCellsInMacro;
789  // return std::fabs(macroLoc.X - curSite->X()) + std::fabs(macroLoc.Y - curSite->Y());
790  // placementInfo->getPlacementUnitByCell(curCell);
791  }
792 
801  {
802  float oriHPWL = 0.0;
803  float newHPWL = 0.0;
804  float PUX = 0.0, PUY = 0.0;
805  auto nets = placementInfo->getPlacementUnitId2Nets()[tmpPU->getId()];
806 
807  PUX = curSite->X();
808  PUY = curSite->Y();
809 
811  return std::fabs(PUX - tmpPU->X()) + y2xRatio * std::fabs(PUY - tmpPU->Y());
812 
813  for (auto curNet : nets)
814  {
815  if (curNet->getDesignNet()->getPins().size() > 10000) // it could be clock
816  continue;
817  oriHPWL += curNet->getHPWL(y2xRatio);
818  newHPWL += curNet->getNewHPWLByTrying(tmpPU, PUX, PUY, y2xRatio);
819  }
820 
821  return (newHPWL - oriHPWL);
822  }
823 
832  inline float getHPWLChange(PlacementInfo::PlacementUnit *tmpPU, float PUX, float PUY)
833  {
834 
836  return std::fabs(PUX - tmpPU->X()) + y2xRatio * std::fabs(PUY - tmpPU->Y());
837  float oriHPWL = 0.0;
838  float newHPWL = 0.0;
839  auto nets = placementInfo->getPlacementUnitId2Nets()[tmpPU->getId()];
840 
841  for (auto curNet : nets)
842  {
843  if (curNet->getDesignNet()->getPins().size() > 10000) // it could be clock
844  continue;
845  oriHPWL += curNet->getHPWL(y2xRatio);
846  newHPWL += curNet->getNewHPWLByTrying(tmpPU, PUX, PUY, y2xRatio);
847  }
848 
849  return (newHPWL - oriHPWL);
850  }
851 
853  {
854  DeviceInfo::DeviceSite *tmp = *siteA;
855  *siteA = *siteB;
856  *siteB = tmp;
857  }
858 
859  inline int sortPartition(DesignInfo::DesignCell *curCell, std::vector<DeviceInfo::DeviceSite *> &sites, int low,
860  int high, PlacementInfo::Location &macroLoc)
861  {
862  int pivot, index, i;
863  index = low;
864  pivot = high;
865  for (i = low; i < high; i++)
866  {
867  // finding index of pivot.
868  // if (a[i] < a[pivot])
869  // if (getDisplacement(macroLoc, sites[i]) < getDisplacement(macroLoc, sites[pivot]))
870  if (getHPWLChange(curCell, sites[i]) < getHPWLChange(curCell, sites[pivot]))
871  {
872  swapSitePtr(&sites[i], &sites[index]);
873  index++;
874  }
875  }
876  swapSitePtr(&sites[pivot], &sites[index]);
877  return index;
878  }
879  inline int RandomPivotPartition(DesignInfo::DesignCell *curCell, std::vector<DeviceInfo::DeviceSite *> &sites,
880  int low, int high, PlacementInfo::Location &macroLoc)
881  {
882  // Random selection of pivot.
883  int pvt;
884  pvt = (high + low) / 2;
885  // pvt = low + n % (high - low + 1); // Randomizing the pivot value from sub-array.
886  swapSitePtr(&sites[high], &sites[pvt]);
887  return sortPartition(curCell, sites, low, high, macroLoc);
888  }
889  void quick_sort_WLChange(DesignInfo::DesignCell *curCell, std::vector<DeviceInfo::DeviceSite *> &sites, int p,
890  int q, PlacementInfo::Location &macroLoc)
891  {
892  // recursively sort the list
893  int pindex;
894  if (p < q)
895  {
896  pindex = RandomPivotPartition(curCell, sites, p, q, macroLoc); // randomly choose pivot
897  // Recursively implementing QuickSort.
898  quick_sort_WLChange(curCell, sites, p, pindex - 1, macroLoc);
899  quick_sort_WLChange(curCell, sites, pindex + 1, q, macroLoc);
900  }
901  }
902 
904  {
905  PlacementInfo::PlacementUnit *tmp = *PUA;
906  *PUA = *PUB;
907  *PUB = tmp;
908  }
909 
910  inline int sortPartition(std::vector<PlacementInfo::PlacementUnit *> &PUs, int low, int high)
911  {
912  int pivot, index, i;
913  index = low;
914  pivot = high;
915  for (i = low; i < high; i++)
916  {
917  // finding index of pivot.
918  // if (a[i] < a[pivot])
919  // if (getDisplacement(macroLoc, PUs[i]) < getDisplacement(macroLoc, PUs[pivot]))
920  if (PUs[i]->X() < PUs[pivot]->X())
921  {
922  swapPUs(&PUs[i], &PUs[index]);
923  index++;
924  }
925  }
926  swapPUs(&PUs[pivot], &PUs[index]);
927  return index;
928  }
929  inline int RandomPivotPartition(std::vector<PlacementInfo::PlacementUnit *> &PUs, int low, int high)
930  {
931  // Random selection of pivot.
932  int pvt, n;
933  n = random();
934  pvt = low + n % (high - low + 1); // Randomizing the pivot value from sub-array.
935  swapPUs(&PUs[high], &PUs[pvt]);
936  return sortPartition(PUs, low, high);
937  }
938  void quick_sort_locX(std::vector<PlacementInfo::PlacementUnit *> &PUs, int p, int q)
939  {
940  // recursively sort the list
941  int pindex;
942  if (p < q)
943  {
944  pindex = RandomPivotPartition(PUs, p, q); // randomly choose pivot
945  // Recursively implementing QuickSort.
946  quick_sort_locX(PUs, p, pindex - 1);
947  quick_sort_locX(PUs, pindex + 1, q);
948  }
949  }
950 };
951 
952 #endif
PlacementInfo::Location
Definition: PlacementInfo.h:3595
MinCostBipartiteMatcher
Definition: MinCostBipartiteMatcher.h:44
MacroLegalizer::swapPUs
void swapPUs(PlacementInfo::PlacementUnit **PUA, PlacementInfo::PlacementUnit **PUB)
Definition: MacroLegalizer.h:903
MacroLegalizer::DSPColumnNum
int DSPColumnNum
the number of DSP columns on the target device
Definition: MacroLegalizer.h:300
MacroLegalizer::getAverageDisplacementOfExactLegalization
float getAverageDisplacementOfExactLegalization()
Get the average displacement of exact legalization for the involved PlacementUnit.
Definition: MacroLegalizer.h:95
MacroLegalizer::roughAverageDisplacement
float roughAverageDisplacement
the average displacement of rough legalization for the involved PlacementUnit
Definition: MacroLegalizer.h:494
MacroLegalizer::findMacroCell2SitesInDistance
void findMacroCell2SitesInDistance(bool checkClockRegion)
find candidate sites for the cells left to be matched
Definition: MacroLegalizer.h:672
MacroLegalizer::displacementThreshold
float displacementThreshold
displacement threshold to detect potential legal sites
Definition: MacroLegalizer.h:282
MacroLegalizer::swapPU
void swapPU(PlacementInfo::PlacementUnit **A, PlacementInfo::PlacementUnit **B)
Definition: MacroLegalizer.h:729
MacroLegalizer::PU2SiteX
std::map< PlacementInfo::PlacementUnit *, int > PU2SiteX
record the exact site X (column id) of involved PlacementUnits
Definition: MacroLegalizer.h:436
exportDeviceLocation.sites
list sites
Definition: exportDeviceLocation.py:216
MacroLegalizer::enableDSPLegalization
bool enableDSPLegalization
Definition: MacroLegalizer.h:466
MacroLegalizer::initialMaxNumCandidate
int initialMaxNumCandidate
the maximum number of final candidate sites
Definition: MacroLegalizer.h:508
MacroLegalizer::PU2X
std::map< PlacementInfo::PlacementUnit *, float > PU2X
record the mapping from PlacementUnits to exact DeviceSite location X
Definition: MacroLegalizer.h:422
MacroLegalizer::nJobs
int nJobs
the number of the parallel multi-threading workers to handle the legalization problems
Definition: MacroLegalizer.h:514
MacroLegalizer::matchedMacroCells
std::set< DesignInfo::DesignCell * > matchedMacroCells
a set of cells in macros binded to corresponding DeviceSites
Definition: MacroLegalizer.h:256
MacroLegalizer::quick_sort_WLChange
void quick_sort_WLChange(DesignInfo::DesignCell *curCell, std::vector< DeviceInfo::DeviceSite * > &sites, int p, int q, PlacementInfo::Location &macroLoc)
Definition: MacroLegalizer.h:889
MacroLegalizer::BRAMCell2Column
std::map< DesignInfo::DesignCell *, int > BRAMCell2Column
record the PlacementUnits in each column of BRAM site
Definition: MacroLegalizer.h:402
MacroLegalizer::DSPColumnUntilization
std::vector< int > DSPColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for DSP
Definition: MacroLegalizer.h:390
MacroLegalizer::timingDrivenLegalize
bool timingDrivenLegalize
Definition: MacroLegalizer.h:472
MacroLegalizer::macroTypesToLegalize
std::vector< DesignInfo::DesignCellType > macroTypesToLegalize
a vector of Cell Type string indicating the target types handled by this MacroLegalizer
Definition: MacroLegalizer.h:180
MacroLegalizer::MacroLegalizer
MacroLegalizer(std::string legalizerName, PlacementInfo *placementInfo, DeviceInfo *deviceInfo, std::vector< DesignInfo::DesignCellType > &macroTypesToLegalize, std::map< std::string, std::string > &JSONCfg)
Construct a new MacroLegalizer object.
Definition: MacroLegalizer.cc:33
MacroLegalizer::DSPPUs
std::set< PlacementInfo::PlacementUnit * > DSPPUs
the PlacementUnits which shoudl be mapped to DSP site
Definition: MacroLegalizer.h:457
PlacementInfo::PlacementMacro
a fixed group of multiple standard cells with constraints of their relative locations
Definition: PlacementInfo.h:1525
MacroLegalizer::setClockRegionAware
void setClockRegionAware(bool _clockRegionAware)
Definition: MacroLegalizer.h:149
MacroLegalizer::resetSitesMapped
void resetSitesMapped()
reset the mapped flag of the involved sites.
Definition: MacroLegalizer.cc:1507
DesignInfo::DesignCell
a DesignCell in design netlist, DesignPin objects of which might connect to DesignNet objects
Definition: DesignInfo.h:782
MacroLegalizer::updatePUMatchingLocation
void updatePUMatchingLocation(bool isRoughLegalization=true, bool updateDisplacement=true)
update the locations of the legalization anchors for the PlacementUnits.
Definition: MacroLegalizer.cc:1072
MacroLegalizer::macro2Sites
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
Definition: MacroLegalizer.h:226
MacroLegalizer::y2xRatio
float y2xRatio
Definition: MacroLegalizer.h:469
MacroLegalizer::getHPWLChange
float getHPWLChange(PlacementInfo::PlacementUnit *tmpPU, float PUX, float PUY)
get the HPWL change when the given PlacementUnit moves to the given location
Definition: MacroLegalizer.h:832
MinCostBipartiteMatcher.h
MacroLegalizer::macroCellsToLegalize
std::vector< DesignInfo::DesignCell * > macroCellsToLegalize
a vector storing the Design cells which have NOT been legalized
Definition: MacroLegalizer.h:200
MacroLegalizer::BRAMColumnNum
int BRAMColumnNum
the number of BRAM columns on the target device
Definition: MacroLegalizer.h:294
MacroLegalizer::BRAMPUs
std::set< PlacementInfo::PlacementUnit * > BRAMPUs
the PlacementUnits which shoudl be mapped to BRAM site
Definition: MacroLegalizer.h:451
MacroLegalizer::noTarget
bool noTarget
Definition: MacroLegalizer.h:496
MacroLegalizer
MacroLegalizer maps DSP/BRAM/CARRY macros to legal location.
Definition: MacroLegalizer.h:58
MacroLegalizer::initialDisplacementThreshold
float initialDisplacementThreshold
displacement threshold to detect potential legal sites
Definition: MacroLegalizer.h:502
MacroLegalizer::candidateFactor
int candidateFactor
we are allowed to detect a excessive number (>candidateNum) of initial candidates....
Definition: MacroLegalizer.h:521
MacroLegalizer::adjList
std::vector< std::vector< std::pair< int, float > > > adjList
the adjacent list of the bipartite graph
Definition: MacroLegalizer.h:250
PlacementInfo::PlacementUnit::Y
float Y()
Definition: PlacementInfo.h:1029
MacroLegalizer::PU2Y
std::map< PlacementInfo::PlacementUnit *, float > PU2Y
record the mapping from PlacementUnits to exact DeviceSite location Y
Definition: MacroLegalizer.h:428
MacroLegalizer::spreadMacros
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
Definition: MacroLegalizer.cc:1178
MacroLegalizer::quick_sort_locX
void quick_sort_locX(std::vector< PlacementInfo::PlacementUnit * > &PUs, int p, int q)
Definition: MacroLegalizer.h:938
MacroLegalizer::legalizerName
std::string legalizerName
Definition: MacroLegalizer.h:165
MacroLegalizer::fixedColumnAverageDisplacement
float fixedColumnAverageDisplacement
the average displacement of fixed column (but not exactly consective) legalization for the involved P...
Definition: MacroLegalizer.h:488
MacroLegalizer::mapMacrosToColumns
void mapMacrosToColumns(bool directLegalization)
map the macros to the columns according to the locations of the cells in it
Definition: MacroLegalizer.cc:1373
MacroLegalizer::BRAMColumnXs
std::vector< float > BRAMColumnXs
the floating-point X location of the BRAM columns on the device
Definition: MacroLegalizer.h:330
MacroLegalizer::roughlyLegalize
void roughlyLegalize()
conduct rough legalization.
Definition: MacroLegalizer.cc:104
MacroLegalizer::clockRegionCasLegalization
bool clockRegionCasLegalization
Definition: MacroLegalizer.h:471
MacroLegalizer::JSONCfg
std::map< std::string, std::string > & JSONCfg
Definition: MacroLegalizer.h:188
MacroLegalizer::DSPColumn2Sites
std::vector< std::vector< DeviceInfo::DeviceSite * > > DSPColumn2Sites
record the sites in each column of DSP
Definition: MacroLegalizer.h:354
MacroLegalizer::macroType2Sites
std::map< DesignInfo::DesignCellType, std::vector< DeviceInfo::DeviceSite * > > macroType2Sites
a map record the potential sites of different site types
Definition: MacroLegalizer.h:218
MacroLegalizer::getMarcroCellNum
int getMarcroCellNum(PlacementInfo::PlacementUnit *tmpMacroUnit)
check how many sites are required by the given PlacementUnit
Definition: MacroLegalizer.cc:1019
DesignInfo.h
This header file contains the classes of data for a standalone design netlist.
MacroLegalizer::sortPartition
int sortPartition(std::vector< PlacementInfo::PlacementUnit * > &PUs, int low, int high)
Definition: MacroLegalizer.h:910
PlacementInfo::PlacementUnit::X
float X()
Definition: PlacementInfo.h:1024
MacroLegalizer::CARRYColumnNum
int CARRYColumnNum
the number of CARRY columns on the target device
Definition: MacroLegalizer.h:306
MacroLegalizer::getMacrosToLegalize
void getMacrosToLegalize()
get the PlacementMacro(s) which SHOULD be legalized
Definition: MacroLegalizer.cc:527
MacroLegalizer::findCorrespondingColumn
int findCorrespondingColumn(float curX, std::vector< float > &Xs)
find the closest column for a given location X
Definition: MacroLegalizer.cc:1355
MacroLegalizer::findPossibleLegalLocation
void findPossibleLegalLocation(bool fixedColumn=false)
find potential sites for each PlacementUnit
Definition: MacroLegalizer.cc:699
dumpZip.h
PlacementInfo::getPlacementUnitId2Nets
std::vector< std::vector< PlacementNet * > > & getPlacementUnitId2Nets()
Definition: PlacementInfo.h:3903
DeviceInfo.h
This header file contains the classes of data for a standalone device.
PlacementInfo::Location::X
float X
Definition: PlacementInfo.h:3596
delayVisualization.X
X
Definition: delayVisualization.py:80
MacroLegalizer::CARRYColumn2Sites
std::vector< std::vector< DeviceInfo::DeviceSite * > > CARRYColumn2Sites
record the sites in each column of CARRY
Definition: MacroLegalizer.h:360
PlacementInfo::findNeiborSiteFromBinGrid
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
Definition: PlacementInfo.h:3799
MacroLegalizer::resetSettings
void resetSettings()
clear the mapping information and reset the mapping parameters
Definition: MacroLegalizer.h:711
MacroLegalizer::enableCARRYLegalization
bool enableCARRYLegalization
Definition: MacroLegalizer.h:467
MacroLegalizer::compatiblePlacementTable
PlacementInfo::CompatiblePlacementTable * compatiblePlacementTable
compatiblePlacementTable describes the type mapping from design to device, where a cell can be placed...
Definition: MacroLegalizer.h:174
delayVisualization.C
C
Definition: delayVisualization.py:86
MacroLegalizer::cellLoc
std::vector< PlacementInfo::Location > & cellLoc
a reference of the locations of cells (in cellId order)
Definition: MacroLegalizer.h:186
DeviceInfo::DeviceSite
Site class for site on device.
Definition: DeviceInfo.h:163
MacroLegalizer::cellLevelMatching
std::vector< std::pair< DesignInfo::DesignCell *, DeviceInfo::DeviceSite * > > cellLevelMatching
record the binding between design standard cells and DeviceSites as a vector of pairs
Definition: MacroLegalizer.h:268
delayVisualization.A
A
Definition: delayVisualization.py:85
MacroLegalizer::BRAMColumn2PUs
std::vector< std::deque< PlacementInfo::PlacementUnit * > > BRAMColumn2PUs
record the PlacementUnits in each column of BRAM Sites
Definition: MacroLegalizer.h:366
MacroLegalizer::getHPWLChange
float getHPWLChange(PlacementInfo::PlacementUnit *tmpPU, DeviceInfo::DeviceSite *curSite)
get the HPWL change when the given PlacementUnit moves to the given DeviceSite
Definition: MacroLegalizer.h:800
MacroLegalizer::initialMacrosToLegalize
std::vector< DesignInfo::DesignCell * > initialMacrosToLegalize
a vector storing the cells in macros which SHOULD be legalized
Definition: MacroLegalizer.h:206
sysInfo.h
PlacementInfo::CompatiblePlacementTable
describes the type mapping from design to device, where a cell can be placed (which BEL in which site...
Definition: PlacementInfo.h:94
MacroLegalizer::clockRegionAware
bool clockRegionAware
Definition: MacroLegalizer.h:470
MacroLegalizer::sortPUsByPU2Y
void sortPUsByPU2Y(std::deque< PlacementInfo::PlacementUnit * > &PUs)
Definition: MacroLegalizer.cc:1043
MacroLegalizer::legalize
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
Definition: MacroLegalizer.cc:63
MacroLegalizer::DSPCell2Column
std::map< DesignInfo::DesignCell *, int > DSPCell2Column
record the PlacementUnits in each column of DSP site
Definition: MacroLegalizer.h:408
MacroLegalizer::deviceInfo
DeviceInfo * deviceInfo
Definition: MacroLegalizer.h:167
MacroLegalizer::getHPWLChange
float getHPWLChange(DesignInfo::DesignCell *curCell, DeviceInfo::DeviceSite *curSite)
get the HPWL change when the given DesignCell moves to the given DeviceSite
Definition: MacroLegalizer.h:757
MacroLegalizer::BRAMColumnUntilization
std::vector< int > BRAMColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for BRAM
Definition: MacroLegalizer.h:384
MacroLegalizer::rightSiteIds
std::map< DeviceInfo::DeviceSite *, int > rightSiteIds
map sites to temperary indexes for bipartite matching
Definition: MacroLegalizer.h:238
MacroLegalizer::BRAMColumn2Sites
std::vector< std::vector< DeviceInfo::DeviceSite * > > BRAMColumn2Sites
record the sites in each column of BRAM
Definition: MacroLegalizer.h:348
PlacementInfo::PlacementUnit
a movement unit in placement with information of location and resource demand
Definition: PlacementInfo.h:1010
MacroLegalizer::macro2SitesInDisplacementThreshold
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
Definition: MacroLegalizer.h:232
DesignInfo::DesignCell::getCellId
int getCellId()
Get the Cell Id in the cell list.
Definition: DesignInfo.h:1037
PlacementInfo::PlacementUnit::getId
unsigned int getId()
Definition: PlacementInfo.h:1206
MacroLegalizer::dumpMatching
void dumpMatching(bool fixedColumn=false, bool enforce=false)
Definition: MacroLegalizer.cc:922
MacroLegalizer::~MacroLegalizer
~MacroLegalizer()
Definition: MacroLegalizer.h:73
MacroLegalizer::hasNoTarget
bool hasNoTarget()
Definition: MacroLegalizer.h:159
MacroLegalizer::CARRYPUs
std::set< PlacementInfo::PlacementUnit * > CARRYPUs
the PlacementUnits which shoudl be mapped to CARRY BEL
Definition: MacroLegalizer.h:463
MacroLegalizer::finalAverageDisplacement
float finalAverageDisplacement
the average displacement of exact legalization for the involved PlacementUnit
Definition: MacroLegalizer.h:479
MacroLegalizer::DSPColumn2PUs
std::vector< std::deque< PlacementInfo::PlacementUnit * > > DSPColumn2PUs
record the PlacementUnits in each column of DSP Sites
Definition: MacroLegalizer.h:372
MacroLegalizer::CARRYColumn2PUs
std::vector< std::deque< PlacementInfo::PlacementUnit * > > CARRYColumn2PUs
record the PlacementUnits in each column of CARRY
Definition: MacroLegalizer.h:378
MacroLegalizer::fixedColumnLegalize
void fixedColumnLegalize(bool directLegalization)
conduct fixed-column legalization as a step in exact legalization. During fixed-column legalization,...
Definition: MacroLegalizer.cc:129
MacroLegalizer::BRAMRowNum
int BRAMRowNum
the number of BRAM rows on the target device
Definition: MacroLegalizer.h:312
MacroLegalizer::DumpMacroLegalizationCnt
int DumpMacroLegalizationCnt
Definition: MacroLegalizer.h:276
MacroLegalizer::CARRYColumnXs
std::vector< float > CARRYColumnXs
the floating-point X location of the CARRY columns on the device
Definition: MacroLegalizer.h:342
MacroLegalizer::maxNumCandidate
int maxNumCandidate
the maximum number of final candidate sites
Definition: MacroLegalizer.h:288
MacroLegalizer::updateMatchingAndUnmatchedMacroCells
void updateMatchingAndUnmatchedMacroCells()
record the matching in private list and update the list of cells which are not matched by the bi-part...
Definition: MacroLegalizer.cc:893
MacroLegalizer::resolveOverflowColumns
void resolveOverflowColumns()
resolve the overflow columns during fixed column legalization by spreading "outliers" to neighbor col...
Definition: MacroLegalizer.cc:1315
DeviceInfo
Information class related to FPGA device, including the details of BEL/Site/Tile/ClockRegion.
Definition: DeviceInfo.h:43
MacroLegalizer::createBipartiteGraph
void createBipartiteGraph()
Create a bipartite graph between PlacementUnit and potential DeviceSites.
Definition: MacroLegalizer.cc:849
MacroLegalizer::setClockRegionCasLegalization
void setClockRegionCasLegalization(bool _clockRegionCasLegalization)
Definition: MacroLegalizer.h:154
DeviceInfo::DeviceSite::X
float X()
Definition: DeviceInfo.h:288
MacroLegalizer::CARRYCell2Column
std::map< DesignInfo::DesignCell *, int > CARRYCell2Column
record the PlacementUnits in each column of CARRY site
Definition: MacroLegalizer.h:414
MacroLegalizer::finalLegalizeBasedOnDP
void finalLegalizeBasedOnDP()
finally dynamic programming to legalize the macros which have been mapped to the columns.
Definition: MacroLegalizer.cc:161
MacroLegalizer::sortPartition
int sortPartition(DesignInfo::DesignCell *curCell, std::vector< DeviceInfo::DeviceSite * > &sites, int low, int high, PlacementInfo::Location &macroLoc)
Definition: MacroLegalizer.h:859
MacroLegalizer::sortSitesBySiteY
void sortSitesBySiteY(std::vector< DeviceInfo::DeviceSite * > &sites)
Definition: MacroLegalizer.cc:1052
PlacementInfo::PlacementUnpackedCell
the smallest, indivisible, representable component. It will include only one standard cell
Definition: PlacementInfo.h:1447
MacroLegalizer::swapSitePtr
void swapSitePtr(DeviceInfo::DeviceSite **siteA, DeviceInfo::DeviceSite **siteB)
Definition: MacroLegalizer.h:852
MacroLegalizer::DSPRowNum
int DSPRowNum
the number of DSP rows on the target device
Definition: MacroLegalizer.h:318
MacroLegalizer::setSitesMapped
void setSitesMapped()
Set the sites which are binded as mapped so they will not be mapped to other elements in the netlist.
Definition: MacroLegalizer.cc:1482
MacroLegalizer::getDisplacement
float getDisplacement(PlacementInfo::PlacementUnit *curPU, DeviceInfo::DeviceSite *curSite)
Definition: MacroLegalizer.h:745
MacroLegalizer::setIntitialParameters
void setIntitialParameters(float displacementThr, int candidateNum, int _candidateFactor=-1)
Set the intitial parameters of the legalizer.
Definition: MacroLegalizer.h:131
MacroLegalizer::PU2LegalSites
std::map< PlacementInfo::PlacementUnit *, std::vector< DeviceInfo::DeviceSite * > > PU2LegalSites
Definition: MacroLegalizer.h:416
MacroLegalizer::getAverageDisplacementOfRoughLegalization
float getAverageDisplacementOfRoughLegalization()
Get the average displacement of rough legalization for the involved PlacementUnit.
Definition: MacroLegalizer.h:117
MacroLegalizer::DPForMinHPWL
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.
Definition: MacroLegalizer.cc:183
MacroLegalizer::clockRegionHeightOfDSE_BRAM
int clockRegionHeightOfDSE_BRAM
Definition: MacroLegalizer.h:473
MacroLegalizer::RandomPivotPartition
int RandomPivotPartition(DesignInfo::DesignCell *curCell, std::vector< DeviceInfo::DeviceSite * > &sites, int low, int high, PlacementInfo::Location &macroLoc)
Definition: MacroLegalizer.h:879
checkHalfColumn.i
int i
Definition: checkHalfColumn.py:5
MacroLegalizer::minCostBipartiteMatcher
MinCostBipartiteMatcher * minCostBipartiteMatcher
min-cost bipartite matching solver for the legalization
Definition: MacroLegalizer.h:194
MacroLegalizer::findMacroType2AvailableSites
void findMacroType2AvailableSites()
find available sites for each specific macro type required by the constructor
Definition: MacroLegalizer.cc:564
PlacementInfo::getPlacementUnitByCell
PlacementUnit * getPlacementUnitByCell(DesignInfo::DesignCell *curCell)
Definition: PlacementInfo.h:3120
MacroLegalizer::placementInfo
PlacementInfo * placementInfo
Definition: MacroLegalizer.h:166
MacroLegalizer::siteList
std::vector< DeviceInfo::DeviceSite * > siteList
a vector for the candidate sites for bipartite matching
Definition: MacroLegalizer.h:244
MacroLegalizer::enableBRAMLegalization
bool enableBRAMLegalization
Definition: MacroLegalizer.h:465
MacroLegalizer::resetMacroCell2SitesInDistance
void resetMacroCell2SitesInDistance()
clear the information of candidate sites for the cells left to be matched
Definition: MacroLegalizer.h:697
MacroLegalizer::CARRYColumnUntilization
std::vector< int > CARRYColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for CARRY
Definition: MacroLegalizer.h:396
MacroLegalizer::macroUnitsToLegalizeSet
std::set< PlacementInfo::PlacementUnit * > macroUnitsToLegalizeSet
a set storing the macros which have NOT been legalized
Definition: MacroLegalizer.h:212
MacroLegalizer::CARRYRowNum
int CARRYRowNum
the number of CARRY rows on the target device
Definition: MacroLegalizer.h:324
PlacementInfo.h
This header file mainly contains the definition of class PlacementInfo, including information related...
MacroLegalizer::findIdMaxWithRecurence
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
Definition: MacroLegalizer.cc:1332
MacroLegalizer::RandomPivotPartition
int RandomPivotPartition(std::vector< PlacementInfo::PlacementUnit * > &PUs, int low, int high)
Definition: MacroLegalizer.h:929
MacroLegalizer::verbose
bool verbose
Definition: MacroLegalizer.h:468
MacroLegalizer::PU2Columns
std::map< PlacementInfo::PlacementUnit *, std::vector< int > > PU2Columns
record the column id for the binded cells in involved PlacementUnits
Definition: MacroLegalizer.h:445
MacroLegalizer::PULevelMatching
std::vector< std::pair< PlacementInfo::PlacementUnit *, DeviceInfo::DeviceSite * > > PULevelMatching
record the binding between PlacementUnits and DeviceSites as a vector of pairs
Definition: MacroLegalizer.h:274
MacroLegalizer::macroCanBeFitIn
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.
Definition: MacroLegalizer.cc:390
PlacementInfo::Location::Y
float Y
Definition: PlacementInfo.h:3597
MacroLegalizer::matchedSites
std::set< DeviceInfo::DeviceSite * > matchedSites
a set of DeviceSites binded to corresponding PlacementUnits
Definition: MacroLegalizer.h:262
MacroLegalizer::getDisplacement
float getDisplacement(PlacementInfo::Location &macroLoc, DeviceInfo::DeviceSite *curSite)
Definition: MacroLegalizer.h:740
MacroLegalizer::DSPColumnXs
std::vector< float > DSPColumnXs
the floating-point X location of the DSP columns on the device
Definition: MacroLegalizer.h:336
DeviceInfo::DeviceSite::Y
float Y()
Definition: DeviceInfo.h:292
PlacementInfo
Information related to FPGA placement (wirelength optimization, cell spreading, legalization,...
Definition: PlacementInfo.h:59