AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MacroLegalizer.cc
Go to the documentation of this file.
1 
26 #include "MacroLegalizer.h"
27 #include <algorithm>
28 #include <cmath>
29 #include <cstdlib>
30 #include <ctime>
31 #include <iostream>
32 
33 MacroLegalizer::MacroLegalizer(std::string legalizerName, PlacementInfo *placementInfo, DeviceInfo *deviceInfo,
34  std::vector<DesignInfo::DesignCellType> &macroTypesToLegalize,
35  std::map<std::string, std::string> &JSONCfg)
36  : legalizerName(legalizerName), placementInfo(placementInfo), deviceInfo(deviceInfo),
37  compatiblePlacementTable(placementInfo->getCompatiblePlacementTable()),
38  macroTypesToLegalize(macroTypesToLegalize), cellLoc(placementInfo->getCellId2location()), JSONCfg(JSONCfg)
39 {
40  macroCellsToLegalize.clear();
41  PU2X.clear();
42  PU2Y.clear();
43  PU2LegalSites.clear();
44 
45  if (JSONCfg.find("y2xRatio") != JSONCfg.end())
46  {
47  y2xRatio = std::stof(JSONCfg["y2xRatio"]);
48  }
49 
50  if (JSONCfg.find("MacroLegalizationVerbose") != JSONCfg.end())
51  {
52  verbose = JSONCfg["MacroLegalizationVerbose"] == "true";
53  }
54 
55  if (JSONCfg.find("jobs") != JSONCfg.end())
56  {
57  nJobs = std::stoi(JSONCfg["jobs"]);
58  }
59 
60  clockRegionAware = false;
61 }
62 
63 void MacroLegalizer::legalize(bool exactLegalization, bool directLegalization, bool _timingDrivenLegalize)
64 {
65  if (verbose)
66  print_status("MacroLegalizer[" + legalizerName + "] Started Legalization.");
67 
68  timingDrivenLegalize = _timingDrivenLegalize;
69  resetSettings();
72 
73  if (initialMacrosToLegalize.size() == 0)
74  {
75  print_warning("MacroLegalizer[" + legalizerName + "] find no target elements.");
76  noTarget = true;
77  return;
78  }
79 
80  if (!directLegalization)
81  {
83  updatePUMatchingLocation(true, !exactLegalization);
84  }
85 
86  // dumpMatching();
87 
88  if (exactLegalization)
89  {
90  if (verbose)
91  print_status("MacroLegalizer[" + legalizerName + "] Started Fixed-Column Legalization.");
92  resetSettings();
93  fixedColumnLegalize(directLegalization);
94  updatePUMatchingLocation(false, true);
96  dumpMatching(exactLegalization);
97  }
98 
100  if (verbose)
101  print_status("MacroLegalizer[" + legalizerName + "] Finished Legalization.");
102 }
103 
105 {
106  while (macroCellsToLegalize.size())
107  {
111 
114  macro2Sites.size(), adjList, nJobs, verbose);
115 
118 
120  if ((int)(maxNumCandidate * 2) > maxNumCandidate + 1)
121  maxNumCandidate *= 2;
122  else
123  maxNumCandidate++;
125  minCostBipartiteMatcher = nullptr;
126  }
127 }
128 
129 void MacroLegalizer::fixedColumnLegalize(bool directLegalization)
130 {
131  mapMacrosToColumns(directLegalization);
133 
135 
136  while (macroCellsToLegalize.size())
137  {
143  macro2Sites.size(), adjList, nJobs, verbose);
144 
147 
149  maxNumCandidate *= 2;
150 
151  if ((int)(maxNumCandidate * 2) > maxNumCandidate + 1)
152  maxNumCandidate *= 2;
153  else
154  maxNumCandidate++;
155 
157  minCostBipartiteMatcher = nullptr;
158  }
159 }
160 
162 {
163  PU2X.clear();
164  PU2Y.clear();
165  PU2LegalSites.clear();
166  resetSettings();
167  float tmpAverageDisplacement = 0.0;
168  if (verbose)
169  print_status("MacroLegalizer[" + legalizerName + "] Start finalLegalizeBasedOnDP");
170  tmpAverageDisplacement += DPForMinHPWL(BRAMColumnNum, BRAMColumn2Sites, BRAMColumn2PUs);
171  tmpAverageDisplacement += DPForMinHPWL(DSPColumnNum, DSPColumn2Sites, DSPColumn2PUs);
172  tmpAverageDisplacement += DPForMinHPWL(CARRYColumnNum, CARRYColumn2Sites, CARRYColumn2PUs);
173  finalAverageDisplacement = tmpAverageDisplacement / PU2X.size();
174  if (verbose)
175  print_status("MacroLegalizer[" + legalizerName +
176  "] Done finalLegalizeBasedOnDP: Macro Cell Average Final Legalization Displacement = " +
177  std::to_string(finalAverageDisplacement));
178 
181 }
182 
183 float MacroLegalizer::DPForMinHPWL(int colNum, std::vector<std::vector<DeviceInfo::DeviceSite *>> &Column2Sites,
184  std::vector<std::deque<PlacementInfo::PlacementUnit *>> &Column2PUs)
185 {
186  // final Legalization DP
187  // i th macro (start from 0), j th row (start from 0)
188  // f[i][j] = min(f[i-1][j-row[i]]+HPWLChange[i][j-row[i]+1],f[i][j-1])
189 
190  // std::string dumpFile =
191  // JSONCfg["DumpMacroLegalization"] + "-Exact-" + std::to_string(DumpMacroLegalizationCnt) + ".gz";
192 
193  // print_status("MacroLegalizer: dumping MacroLegalization archieve to: " + dumpFile);
194  // DumpMacroLegalizationCnt++;
195  // std::stringstream outfile0;
196 
197  float tmpTotalDisplacement = 0.0;
198  std::map<PlacementInfo::PlacementUnit *, std::vector<DeviceInfo::DeviceSite *>> PU2Sites;
199  PU2Sites.clear();
200  for (auto &PUDeque : Column2PUs)
201  {
202  for (auto tmpPU : PUDeque)
203  {
204  assert(PU2Sites.find(tmpPU) == PU2Sites.end());
205  PU2Sites[tmpPU] = std::vector<DeviceInfo::DeviceSite *>();
206  }
207  }
208 
209 #pragma omp parallel for
210  for (int c = 0; c < colNum; c++)
211  {
212  int numPUs = Column2PUs[c].size();
213  if (!numPUs)
214  continue;
215 
216  auto &curColSites = Column2Sites[c];
217  auto &curColPU = Column2PUs[c];
218 
219  sortSitesBySiteY(curColSites);
220 
221  // initialize
222 
223  std::vector<std::vector<float>> f(numPUs, std::vector<float>(curColSites.size(), 1000000000.0));
224  std::vector<std::vector<bool>> fChoice(
225  numPUs, std::vector<bool>(curColSites.size(), 0)); // used for tracing back macro-site mapping
226 
227  int minLastPUTop = -1;
228 
229  int totalMacroCellNum = 0;
230  int heightPURow = getMarcroCellNum(curColPU[0]);
231  totalMacroCellNum += heightPURow;
232  float minHPWLChange = 1100000000.0;
233  for (unsigned int j = totalMacroCellNum - 1; j < curColSites.size(); j++)
234  {
235  float curHPWLChange = getHPWLChange(curColPU[0], curColSites[j - heightPURow + 1]);
236  if ((curColSites[j]->getSiteY() - curColSites[j - heightPURow + 1]->getSiteY() != heightPURow - 1))
237  {
238  // we need to ensure that there is no occpupied sites in this range
239  curHPWLChange = 1100000000.0;
240  }
241  if (auto curMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(curColPU[0]))
242  {
243  if (curMacro->getMacroType() != PlacementInfo::PlacementMacro::PlacementMacroType_CARRY &&
244  curColSites[j]->getClockRegionY() != curColSites[j - heightPURow + 1]->getClockRegionY())
245  {
246  // we need to ensure that there is no occpupied sites in this range
247  curHPWLChange = 1100000000.0;
248  }
249  if (curMacro->getMacroType() == PlacementInfo::PlacementMacro::PlacementMacroType_BRAM)
250  {
251  // we need to ensure BRAM macros starts from site with even siteY
252  if (curMacro->getCells().size() > 1 && curColSites[j - heightPURow + 1]->getSiteY() % 2 != 0)
253  {
254  curHPWLChange = 1100000000.0;
255  }
256  }
257  }
258  if (curHPWLChange < minHPWLChange)
259  {
260  minHPWLChange = curHPWLChange;
261  fChoice[0][j] = 1;
262  if (numPUs == 1)
263  {
264  minLastPUTop = j;
265  }
266  }
267  f[0][j] = minHPWLChange;
268  }
269 
270  // DP to minimize HPWL
271  for (int i = 1; i < numPUs; i++)
272  {
273  float minVal = 100000000.0;
274  int heightPURow = getMarcroCellNum(curColPU[i]);
275  totalMacroCellNum += heightPURow;
276  for (unsigned int j = totalMacroCellNum - 1; j < curColSites.size();
277  j++) // j start from heightPURow because PU0 must occupy 1+ site(s)
278  {
279  float curHPWLChange = getHPWLChange(curColPU[i], curColSites[j - heightPURow + 1]);
280  if ((curColSites[j]->getSiteY() - curColSites[j - heightPURow + 1]->getSiteY() != heightPURow - 1))
281  {
282  // we need to ensure that there is no occpupied sites in this range
283  curHPWLChange = 1100000000.0;
284  }
285  if (auto curMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(curColPU[i]))
286  {
287  if (curMacro->getMacroType() != PlacementInfo::PlacementMacro::PlacementMacroType_CARRY &&
288  curColSites[j]->getClockRegionY() != curColSites[j - heightPURow + 1]->getClockRegionY())
289  {
290  // we need to ensure that there is no occpupied sites in this range
291  curHPWLChange = 1100000000.0;
292  }
293  if (curMacro->getMacroType() == PlacementInfo::PlacementMacro::PlacementMacroType_BRAM)
294  {
295  // we need to ensure BRAM macros starts from site with even siteY
296  if (curMacro->getCells().size() > 1 && curColSites[j - heightPURow + 1]->getSiteY() % 2 != 0)
297  {
298  curHPWLChange = 1100000000.0;
299  }
300  }
301  }
302  if (f[i][j - 1] > f[i - 1][j - heightPURow] + curHPWLChange)
303  {
304  fChoice[i][j] = 1;
305  if (i == numPUs - 1)
306  {
307  if (f[i - 1][j - heightPURow] + curHPWLChange < minVal)
308  {
309  minVal = f[i - 1][j - heightPURow] + curHPWLChange;
310  minLastPUTop = j;
311  }
312  }
313  }
314 
315  f[i][j] = std::min(f[i][j - 1], f[i - 1][j - heightPURow] + curHPWLChange);
316  }
317  }
318 
319  if (minLastPUTop < 0)
320  {
321  int PUCnt = 0;
322  for (int i = 0; i < numPUs; i++)
323  {
324  std::cout << curColPU[i] << "\n";
325  PUCnt += getMarcroCellNum(curColPU[i]);
326  }
327  std::cout << "total PU Cnt=" << PUCnt << "\n";
328  for (int i = 0; i < numPUs; i++)
329  for (int j = 0; j < curColSites.size(); j++)
330  {
331  if (fChoice[i][j])
332  {
333  std::cout << "PU#" << i << " (" << getMarcroCellNum(curColPU[i]) << "): " << j << "\n";
334  break;
335  }
336  }
337  std::cout.flush();
338  }
339 
340  assert(minLastPUTop >= 0);
341 
342  std::vector<DeviceInfo::DeviceSite *> PUBottom2Site_reverse(0);
343 
344  for (int i = numPUs - 1; i >= 0; i--)
345  {
346  assert(minLastPUTop >= 0);
347  int heightPURow = getMarcroCellNum(curColPU[i]);
348  while (!fChoice[i][minLastPUTop])
349  {
350  minLastPUTop--;
351  assert(minLastPUTop >= 0);
352  }
353  auto curSite = curColSites[minLastPUTop - heightPURow + 1];
354  assert(PU2Sites[curColPU[i]].size() == 0);
355  assert(curSite);
356  for (int curColSiteId = minLastPUTop - heightPURow + 1; curColSiteId <= minLastPUTop; curColSiteId++)
357  {
358  PU2Sites[curColPU[i]].push_back(curColSites[curColSiteId]);
359  }
360  minLastPUTop -= heightPURow;
361  // outfile0 << "col#" << c << ": " << curColPU[i]->getName() << " PUY:" << PU2Y[curColPU[i]]
362  // << " numPUs:" << getMarcroCellNum(curColPU[i])
363  // << " netNum:" << curColPU[i]->getNetsSetPtr()->size() << "\n";
364  // outfile0 << " macthed with: " << curSite->getName() << " locX:" << curSite->X()
365  // << " locY:" << curSite->Y() << " HPWLIncrease:" << getHPWLChange(curColPU[i], curSite) << "\n";
366  }
367  }
368  // writeStrToGZip(dumpFile, outfile0);
369  // print_status("dumped MacroLegalization archieve to: " + dumpFile);
370  for (auto &PUDeque : Column2PUs)
371  {
372  for (auto tmpPU : PUDeque)
373  {
374  assert(PU2Sites.find(tmpPU) != PU2Sites.end());
375  auto &curSites = PU2Sites[tmpPU];
376  assert(curSites.size());
377  assert(PU2X.find(tmpPU) == PU2X.end());
378  auto curSite = curSites[0];
379  PU2LegalSites[tmpPU] = curSites;
380  PU2X[tmpPU] = curSite->X();
381  PU2Y[tmpPU] = curSite->Y();
382  PULevelMatching.emplace_back(tmpPU, curSite);
383  tmpTotalDisplacement += std::fabs(tmpPU->X() - curSite->X()) + std::fabs(tmpPU->Y() - curSite->Y());
384  }
385  }
386 
387  return tmpTotalDisplacement;
388 }
389 
390 bool MacroLegalizer::macroCanBeFitIn(int colId, std::vector<std::vector<DeviceInfo::DeviceSite *>> &Column2Sites,
391  std::deque<PlacementInfo::PlacementUnit *> Column2PUs)
392 {
393  int c = colId;
394 
395  int numPUs = Column2PUs.size();
396  if (!numPUs)
397  return true;
398 
399  auto &curColSites = Column2Sites[c];
400  auto &curColPU = Column2PUs;
401 
402  sortSitesBySiteY(curColSites);
403  sortPUsByPU2Y(curColPU);
404 
405  // initialize
406 
407  std::vector<std::vector<float>> f(numPUs, std::vector<float>(curColSites.size(), 1000000000.0));
408  std::vector<std::vector<bool>> fChoice(
409  numPUs, std::vector<bool>(curColSites.size(), 0)); // used for tracing back macro-site mapping
410 
411  int minLastPUTop = -1;
412 
413  int totalMacroCellNum = 0;
414  int heightPURow = getMarcroCellNum(curColPU[0]);
415  totalMacroCellNum += heightPURow;
416  float minHPWLChange = 1100000000.0;
417  for (unsigned int j = totalMacroCellNum - 1; j < curColSites.size(); j++)
418  {
419  float curHPWLChange = 1;
420  if ((curColSites[j]->getSiteY() - curColSites[j - heightPURow + 1]->getSiteY() != heightPURow - 1))
421  {
422  // we need to ensure that there is no occpupied sites in this range
423  curHPWLChange = 1100000000.0;
424  }
425  if (auto curMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(curColPU[0]))
426  {
427  if (curMacro->getMacroType() != PlacementInfo::PlacementMacro::PlacementMacroType_CARRY &&
428  curColSites[j]->getClockRegionY() != curColSites[j - heightPURow + 1]->getClockRegionY())
429  {
430  // we need to ensure that there is no occpupied sites in this range
431  curHPWLChange = 1100000000.0;
432  }
433  if (curMacro->getMacroType() == PlacementInfo::PlacementMacro::PlacementMacroType_BRAM)
434  {
435  // we need to ensure BRAM macros starts from site with even siteY
436  if (curMacro->getCells().size() > 1 && curColSites[j - heightPURow + 1]->getSiteY() % 2 != 0)
437  {
438  curHPWLChange = 1100000000.0;
439  }
440  }
441  }
442  if (curHPWLChange < minHPWLChange)
443  {
444  minHPWLChange = curHPWLChange;
445  fChoice[0][j] = 1;
446  if (numPUs == 1)
447  {
448  minLastPUTop = j;
449  }
450  }
451  f[0][j] = minHPWLChange;
452  }
453 
454  // DP to minimize HPWL
455  for (int i = 1; i < numPUs; i++)
456  {
457  float minVal = 100000000.0;
458  int heightPURow = getMarcroCellNum(curColPU[i]);
459  totalMacroCellNum += heightPURow;
460  for (unsigned int j = totalMacroCellNum - 1; j < curColSites.size();
461  j++) // j start from heightPURow because PU0 must occupy 1+ site(s)
462  {
463  float curHPWLChange = 1;
464  if ((curColSites[j]->getSiteY() - curColSites[j - heightPURow + 1]->getSiteY() != heightPURow - 1))
465  {
466  // we need to ensure that there is no occpupied sites in this range
467  curHPWLChange = 1100000000.0;
468  }
469  if (auto curMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(curColPU[i]))
470  {
471  if (curMacro->getMacroType() != PlacementInfo::PlacementMacro::PlacementMacroType_CARRY &&
472  curColSites[j]->getClockRegionY() != curColSites[j - heightPURow + 1]->getClockRegionY())
473  {
474  // we need to ensure that there is no occpupied sites in this range
475  curHPWLChange = 1100000000.0;
476  }
477  if (curMacro->getMacroType() == PlacementInfo::PlacementMacro::PlacementMacroType_BRAM)
478  {
479  // we need to ensure BRAM macros starts from site with even siteY
480  if (curMacro->getCells().size() > 1 && curColSites[j - heightPURow + 1]->getSiteY() % 2 != 0)
481  {
482  curHPWLChange = 1100000000.0;
483  }
484  }
485  }
486  if (f[i][j - 1] > f[i - 1][j - heightPURow] + curHPWLChange)
487  {
488  fChoice[i][j] = 1;
489  if (i == numPUs - 1)
490  {
491  if (f[i - 1][j - heightPURow] + curHPWLChange < minVal)
492  {
493  minVal = f[i - 1][j - heightPURow] + curHPWLChange;
494  minLastPUTop = j;
495  }
496  }
497  }
498 
499  f[i][j] = std::min(f[i][j - 1], f[i - 1][j - heightPURow] + curHPWLChange);
500  }
501  }
502 
503  if (minLastPUTop < 0)
504  {
505  int PUCnt = 0;
506  for (int i = 0; i < numPUs; i++)
507  {
508  std::cout << curColPU[i] << "\n";
509  PUCnt += getMarcroCellNum(curColPU[i]);
510  }
511  std::cout << "total PU Cnt=" << PUCnt << "\n";
512  for (int i = 0; i < numPUs; i++)
513  for (int j = 0; j < curColSites.size(); j++)
514  {
515  if (fChoice[i][j])
516  {
517  std::cout << "PU#" << i << " (" << getMarcroCellNum(curColPU[i]) << "): " << j << "\n";
518  break;
519  }
520  }
521  std::cout.flush();
522  }
523 
524  return (minLastPUTop >= 0);
525 }
526 
528 {
529  macroCellsToLegalize.clear();
530  macroUnitsToLegalizeSet.clear();
531  BRAMPUs.clear();
532  DSPPUs.clear();
533  CARRYPUs.clear();
534  for (auto curCell : placementInfo->getCells())
535  {
536  for (auto curType : macroTypesToLegalize)
537  {
538  if (curCell->getCellType() == curType)
539  {
540  auto curPU = placementInfo->getPlacementUnitByCell(curCell);
541  if (!curPU->isLocked())
542  {
543  macroCellsToLegalize.push_back(curCell);
544  macroUnitsToLegalizeSet.insert(curPU);
545  if (curCell->isBRAM())
546  {
547  BRAMPUs.insert(curPU);
548  }
549  if (curCell->isDSP())
550  {
551  DSPPUs.insert(curPU);
552  }
553  if (curCell->isCarry())
554  {
555  CARRYPUs.insert(curPU);
556  }
557  }
558  }
559  }
560  }
562 }
563 
565 {
566  macroType2Sites.clear();
567  for (auto curCellType : macroTypesToLegalize)
568  {
569  macroType2Sites[curCellType] = std::vector<DeviceInfo::DeviceSite *>(0);
570  for (int SharedBELID : placementInfo->getPotentialBELTypeIDs(curCellType))
571  {
572  std::string targetSiteType =
575  std::vector<DeviceInfo::DeviceSite *> &sitesInType = deviceInfo->getSitesInType(targetSiteType);
576  for (auto curSite : sitesInType)
577  {
578  if (!curSite->isOccupied() && !curSite->isMapped())
579  {
580  // if (matchedSites.find(curSite) == matchedSites.end())
581  // {
582  macroType2Sites[curCellType].push_back(curSite);
583  // }
584  }
585  }
586  }
587  }
588 
589  for (auto curCellType : macroTypesToLegalize)
590  {
591  if (DesignInfo::isBRAM(curCellType))
592  {
593  enableBRAMLegalization = true;
594  for (auto curSite : macroType2Sites[curCellType])
595  {
596  if (curSite->getSiteY() + 1 > BRAMRowNum)
597  BRAMRowNum = curSite->getSiteY() + 1;
598  if (curSite->getSiteX() + 1 > BRAMColumnNum)
599  BRAMColumnNum = curSite->getSiteX() + 1;
600  }
601  }
602  if (DesignInfo::isDSP(curCellType))
603  {
604  enableDSPLegalization = true;
605  for (auto curSite : macroType2Sites[curCellType])
606  {
607  if (curSite->getSiteY() + 1 > DSPRowNum)
608  DSPRowNum = curSite->getSiteY() + 1;
609  if (curSite->getSiteX() + 1 > DSPColumnNum)
610  DSPColumnNum = curSite->getSiteX() + 1;
611  }
612  }
613  if (DesignInfo::isCarry(curCellType))
614  {
616  for (auto curSite : macroType2Sites[curCellType])
617  {
618  if (curSite->getSiteY() + 1 > CARRYRowNum)
619  CARRYRowNum = curSite->getSiteY() + 1;
620  if (curSite->getSiteX() + 1 > CARRYColumnNum)
621  CARRYColumnNum = curSite->getSiteX() + 1;
622  }
623  }
624  }
625 
626  BRAMColumnXs.clear();
628  {
629  BRAMColumnXs.resize(BRAMColumnNum, -1.0);
630  BRAMColumn2Sites.clear();
631  BRAMColumn2Sites.resize(BRAMColumnNum, std::vector<DeviceInfo::DeviceSite *>(0));
632  for (auto curCellType : macroTypesToLegalize)
633  {
634  if (DesignInfo::isBRAM(curCellType))
635  {
636  for (auto curSite : macroType2Sites[curCellType])
637  {
638  if (curSite->getSiteY() + 1 > BRAMRowNum)
639  BRAMRowNum = curSite->getSiteY() + 1;
640  if (curSite->getSiteX() + 1 > BRAMColumnNum)
641  BRAMColumnNum = curSite->getSiteX() + 1;
642  BRAMColumnXs[curSite->getSiteX()] = curSite->X();
643  BRAMColumn2Sites[curSite->getSiteX()].push_back(curSite);
644  }
645  break;
646  }
647  }
648  }
649 
650  DSPColumnXs.clear();
652  {
653  DSPColumnXs.resize(DSPColumnNum, -1.0);
654  DSPColumn2Sites.clear();
655  DSPColumn2Sites.resize(DSPColumnNum, std::vector<DeviceInfo::DeviceSite *>(0));
656  for (auto curCellType : macroTypesToLegalize)
657  {
658  if (DesignInfo::isDSP(curCellType))
659  {
660  for (auto curSite : macroType2Sites[curCellType])
661  {
662  if (curSite->getSiteY() + 1 > DSPRowNum)
663  DSPRowNum = curSite->getSiteY() + 1;
664  if (curSite->getSiteX() + 1 > DSPColumnNum)
665  DSPColumnNum = curSite->getSiteX() + 1;
666  DSPColumnXs[curSite->getSiteX()] = curSite->X();
667  DSPColumn2Sites[curSite->getSiteX()].push_back(curSite);
668  }
669  break;
670  }
671  }
672  }
673 
674  CARRYColumnXs.clear();
676  {
677  CARRYColumnXs.resize(CARRYColumnNum, -1.0);
678  CARRYColumn2Sites.clear();
679  CARRYColumn2Sites.resize(CARRYColumnNum, std::vector<DeviceInfo::DeviceSite *>(0));
680  for (auto curCellType : macroTypesToLegalize)
681  {
682  if (DesignInfo::isCarry(curCellType))
683  {
684  for (auto curSite : macroType2Sites[curCellType])
685  {
686  if (curSite->getSiteY() + 1 > CARRYRowNum)
687  CARRYRowNum = curSite->getSiteY() + 1;
688  if (curSite->getSiteX() + 1 > CARRYColumnNum)
689  CARRYColumnNum = curSite->getSiteX() + 1;
690  CARRYColumnXs[curSite->getSiteX()] = curSite->X();
691  CARRYColumn2Sites[curSite->getSiteX()].push_back(curSite);
692  }
693  break;
694  }
695  }
696  }
697 }
698 
700 {
701  macro2Sites.clear();
702 
703  for (auto curCell : macroCellsToLegalize)
704  {
705  macro2Sites[curCell] = std::vector<DeviceInfo::DeviceSite *>(0);
706  }
707 
708  int numMacroCells = macroCellsToLegalize.size();
709 
710  if (verbose)
711  {
712  print_status("searching sites for " + std::to_string(numMacroCells) + " macroCells with displacement<" +
713  std::to_string(displacementThreshold));
714  }
715 #pragma omp parallel for
716  for (int i = 0; i < numMacroCells; i++)
717  {
718  auto curCell = macroCellsToLegalize[i];
719  auto curCellType = curCell->getCellType();
720  int macroLength = -1;
721  int cellOffset = -1;
722 
723  if (DesignInfo::isDSP(curCellType) || DesignInfo::isBRAM(curCellType))
724  {
725  auto tmpPU = placementInfo->getPlacementUnitByCellId(curCell->getCellId());
726  if (dynamic_cast<PlacementInfo::PlacementUnpackedCell *>(tmpPU))
727  {
728  macroLength = cellOffset = 1;
729  }
730  else if (auto tmpMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(tmpPU))
731  {
732 
733  for (cellOffset = 0; cellOffset < (int)(tmpMacro->getCells().size()); cellOffset++)
734  {
735  if (tmpMacro->getCell(cellOffset) == curCell)
736  {
737  macroLength = tmpMacro->getCells().size();
738  break;
739  }
740  }
741  }
742  }
743 
744  assert(macroType2Sites.find(curCellType) != macroType2Sites.end());
745 
746  std::vector<DeviceInfo::DeviceSite *> *candidateSite = nullptr;
747  if (fixedColumn)
748  {
749  int targetSiteX = -1;
750  if (curCell->isDSP())
751  {
752  assert(DSPCell2Column.find(curCell) != DSPCell2Column.end());
753  targetSiteX = DSPCell2Column[curCell];
754  }
755  if (curCell->isCarry())
756  {
757  assert(CARRYCell2Column.find(curCell) != CARRYCell2Column.end());
758  targetSiteX = CARRYCell2Column[curCell];
759  }
760  if (curCell->isBRAM())
761  {
762  assert(BRAMCell2Column.find(curCell) != BRAMCell2Column.end());
763  targetSiteX = BRAMCell2Column[curCell];
764  }
765  assert(targetSiteX >= 0);
766 
767  std::vector<std::vector<DeviceInfo::DeviceSite *>> *column2Sites;
768  if (DesignInfo::isCarry(curCellType))
769  {
770  column2Sites = &CARRYColumn2Sites;
771  }
772  else if (DesignInfo::isDSP(curCellType))
773  {
774  column2Sites = &DSPColumn2Sites;
775  }
776  else if (DesignInfo::isBRAM(curCellType))
777  {
778  column2Sites = &BRAMColumn2Sites;
779  }
780  else
781  {
782  assert(false && "undefine type");
783  }
784  for (auto &tmpCol : *column2Sites)
785  {
786  if (tmpCol.size() == 0)
787  continue;
788  if (tmpCol[0]->getSiteX() == targetSiteX)
789  {
790  candidateSite = &tmpCol;
791  }
792  }
793  }
794  else
795  {
796  candidateSite = macro2SitesInDisplacementThreshold[curCell];
797  }
798 
799  assert(candidateSite);
800 
801  for (auto curSite : *candidateSite)
802  {
803  float curDisp = getDisplacement(cellLoc[curCell->getCellId()], curSite);
804  if ((!fixedColumn && curDisp < displacementThreshold) ||
805  (fixedColumn && curDisp < 2 * displacementThreshold))
806  {
807  // since the cell in a macro, we need to ensure the other parts of the macro can be legalized if the
808  // cell is placed to the site
809  if (placementInfo->isLegalLocation(curCell, curSite->X(), curSite->Y()) ||
811  {
812  if (matchedSites.find(curSite) != matchedSites.end())
813  continue;
814 
815  if ((curCellType == DesignInfo::CellType_RAMB36E2 ||
816  curCellType == DesignInfo::CellType_FIFO36E2) &&
817  curSite->getSiteY() % 2 != 0)
818  continue;
819  if ((curCellType == DesignInfo::CellType_RAMB18E2 ||
820  curCellType == DesignInfo::CellType_FIFO18E2) &&
821  curCell->isVirtualCell() && curSite->getSiteY() % 2 != 1)
822  continue;
823 
824  if (macroLength > 1 && cellOffset >= 0 && clockRegionCasLegalization && fixedColumn)
825  {
826  int headLocation = curSite->getSiteY() - cellOffset;
827  int tailLocation = headLocation + macroLength - 1;
828  if (headLocation / clockRegionHeightOfDSE_BRAM != tailLocation / clockRegionHeightOfDSE_BRAM)
829  {
830  continue;
831  }
832  }
833 
834  macro2Sites[curCell].push_back(curSite);
835  }
836  }
837  }
838  if (macro2Sites[curCell].size() > 1)
839  quick_sort_WLChange(curCell, macro2Sites[curCell], 0, macro2Sites[curCell].size() - 1,
840  cellLoc[curCell->getCellId()]);
841  if (macro2Sites[curCell].size() > (unsigned int)maxNumCandidate)
842  macro2Sites[curCell].resize(maxNumCandidate);
843  }
844 
845  // print_info("#total macro cell = " + std::to_string(macro2Sites.size()));
846  // print_info("#total macro candidate site (might be duplicated) = " + std::to_string(totalSiteNum));
847 }
848 
850 {
851  rightSiteIds.clear();
852  adjList.resize(macroCellsToLegalize.size());
853  siteList.clear();
854 
855  float minCost = 10000000;
856 
857  for (unsigned int leftCellId = 0; leftCellId < macroCellsToLegalize.size(); leftCellId++)
858  {
859  auto curCell = macroCellsToLegalize[leftCellId];
860  adjList[leftCellId].clear();
861  for (auto curSite : macro2Sites[curCell])
862  {
863  if (rightSiteIds.find(curSite) == rightSiteIds.end())
864  {
865  int curSiteCnt = rightSiteIds.size();
866  rightSiteIds[curSite] = curSiteCnt;
867  siteList.push_back(curSite);
868  }
869  float tmpCost = getHPWLChange(curCell, curSite);
870  adjList[leftCellId].emplace_back(rightSiteIds[curSite], tmpCost);
871  if (tmpCost < minCost)
872  {
873  minCost = tmpCost;
874  }
875  // adjList[leftCellId].emplace_back(rightSiteIds[curSite],
876  // getDisplacement(cellLoc[curCell->getCellId()], curSite));
877  }
878  }
879 
880  if (minCost < 0.0001)
881  {
882  float compensation = 10 - minCost;
883  for (unsigned int leftCellId = 0; leftCellId < macroCellsToLegalize.size(); leftCellId++)
884  {
885  for (unsigned int tmpId = 0; tmpId < adjList[leftCellId].size(); tmpId++)
886  {
887  adjList[leftCellId][tmpId].second += compensation;
888  }
889  }
890  }
891 }
892 
894 {
895 
896  for (unsigned int leftCellId = 0; leftCellId < macroCellsToLegalize.size(); leftCellId++)
897  {
898  int rightNode = minCostBipartiteMatcher->getMatchedRightNode(leftCellId);
899  auto curCell = macroCellsToLegalize[leftCellId];
900  if (rightNode >= 0)
901  {
902  assert(matchedMacroCells.find(curCell) == matchedMacroCells.end());
903  assert(matchedSites.find(siteList[rightNode]) == matchedSites.end());
904  matchedMacroCells.insert(curCell);
905  matchedSites.insert(siteList[rightNode]);
906  cellLevelMatching.emplace_back(curCell, siteList[rightNode]);
907  }
908  }
909  std::vector<DesignInfo::DesignCell *> newMacrosToLegalize;
910  newMacrosToLegalize.clear();
911  for (unsigned int leftCellId = 0; leftCellId < macroCellsToLegalize.size(); leftCellId++)
912  {
913  auto curCell = macroCellsToLegalize[leftCellId];
914  if (matchedMacroCells.find(curCell) == matchedMacroCells.end())
915  {
916  newMacrosToLegalize.push_back(curCell);
917  }
918  }
919  macroCellsToLegalize = newMacrosToLegalize;
920 }
921 
922 void MacroLegalizer::dumpMatching(bool fixedColumn, bool enforce)
923 {
924  if (JSONCfg.find("DumpMacroLegalization") != JSONCfg.end() || enforce)
925  {
926  std::string dumpFile = "";
927  if (enforce)
928  dumpFile = JSONCfg["dumpDirectory"] + legalizerName + "DumpMacroLegalization-" +
929  std::to_string(DumpMacroLegalizationCnt) + ".gz";
930  else
931  dumpFile = JSONCfg["DumpMacroLegalization"] + "-" + legalizerName +
932  std::to_string(DumpMacroLegalizationCnt) + ".gz";
933 
934  print_status("MacroLegalizer: dumping MacroLegalization archieve to: " + dumpFile);
936  if (dumpFile != "")
937  {
938  std::stringstream outfile0;
939  if (cellLevelMatching.size() != 0)
940  {
941  for (auto matchedPair : cellLevelMatching)
942  {
943  auto matchedSite = matchedPair.second;
944  auto curCell = matchedPair.first;
945  auto curPU = placementInfo->getPlacementUnitByCell(curCell);
946  outfile0 << "CellLevelMatching name: " << curCell->getName() << " CellId: " << curCell->getCellId()
947  << " PUID: " << curPU->getId() << "\n locX:" << cellLoc[curCell->getCellId()].X
948  << "\n locY:" << cellLoc[curCell->getCellId()].Y << "\n";
949  outfile0 << " macthed with: " << matchedSite->getName() << "\n locX:" << matchedSite->X()
950  << "\n locY:" << matchedSite->Y()
951  << "\n dis:" << getDisplacement(cellLoc[curCell->getCellId()], matchedSite)
952  << "\n HPWLIncrease:" << getHPWLChange(curCell, matchedSite) << "\n";
953  }
954  }
955 
956  if (PULevelMatching.size() != 0)
957  {
958  for (auto matchedPair : PULevelMatching)
959  {
960  auto matchedSite = matchedPair.second;
961  auto curPU = matchedPair.first;
962  outfile0 << "PULevelMatching name: " << curPU->getName() << " PUID: " << curPU->getId()
963  << "\n locX:" << curPU->X() << "\n locY:" << curPU->Y()
964  << "\n PU2X:" << PU2X[curPU] << "\n PU2Y:" << PU2Y[curPU] << "\n";
965  assert(std::fabs(matchedSite->X() - PU2X[curPU]) + std::fabs(matchedSite->Y() - PU2Y[curPU]) < 0.1);
966  assert(std::fabs(matchedSite->X() - placementInfo->getPULegalXY().first[curPU]) +
967  std::fabs(matchedSite->Y() - placementInfo->getPULegalXY().second[curPU]) <
968  0.1);
969  outfile0 << " macthed with: " << matchedSite->getName() << "\n locX:" << matchedSite->X()
970  << "\n locY:" << matchedSite->Y()
971  << "\n dis:" << getDisplacement(curPU, matchedSite)
972  << "\n HPWLIncrease:" << getHPWLChange(curPU, matchedSite) << "\n";
973  }
974  }
975 
976  if (fixedColumn)
977  {
978  for (int i = 0; i < BRAMColumnNum; i++)
979  {
980  int numPUs = BRAMColumn2PUs[i].size();
981  for (int j = 0; j < numPUs; j++)
982  {
983  auto PU = BRAMColumn2PUs[i][j];
984  outfile0 << "BRAM col#" << i << ": " << PU->getName() << " PUY:" << PU2Y[PU]
985  << " numPUs:" << getMarcroCellNum(PU) << " netNum:" << PU->getNetsSetPtr()->size()
986  << "\n";
987  }
988  }
989  for (int i = 0; i < DSPColumnNum; i++)
990  {
991  int numPUs = DSPColumn2PUs[i].size();
992  for (int j = 0; j < numPUs; j++)
993  {
994  auto PU = DSPColumn2PUs[i][j];
995  outfile0 << "DSP col#" << i << ": " << PU->getName() << " PUY:" << PU2Y[PU]
996  << " numPUs:" << getMarcroCellNum(PU) << " netNum:" << PU->getNetsSetPtr()->size()
997  << "\n";
998  }
999  }
1000  for (int i = 0; i < CARRYColumnNum; i++)
1001  {
1002  int numPUs = CARRYColumn2PUs[i].size();
1003  for (int j = 0; j < numPUs; j++)
1004  {
1005  auto PU = CARRYColumn2PUs[i][j];
1006  outfile0 << "CARRY col#" << i << ": " << PU->getName() << " PUY:" << PU2Y[PU]
1007  << " numPUs:" << getMarcroCellNum(PU) << " netNum:" << PU->getNetsSetPtr()->size()
1008  << "\n";
1009  }
1010  }
1011  }
1012 
1013  writeStrToGZip(dumpFile, outfile0);
1014  print_status("MacroLegalizer: dumped MacroLegalization archieve to: " + dumpFile);
1015  }
1016  }
1017 }
1018 
1020 {
1021  if (dynamic_cast<PlacementInfo::PlacementUnpackedCell *>(tmpMacroUnit))
1022  {
1023  return 1;
1024  }
1025  else if (auto macroPU = dynamic_cast<PlacementInfo::PlacementMacro *>(tmpMacroUnit))
1026  {
1027  if (macroPU->checkHasBRAM())
1028  return macroPU->getBRAMNum();
1029  else if (macroPU->checkHasDSP())
1030  return macroPU->getDSPNum();
1031  else if (macroPU->checkHasCARRY())
1032  return macroPU->getCARRYNum();
1033  else
1034  {
1035  assert(false && "undefined legaliation macro");
1036  return 1;
1037  }
1038  }
1039  assert(false);
1040  return 1;
1041 }
1042 
1043 void MacroLegalizer::sortPUsByPU2Y(std::deque<PlacementInfo::PlacementUnit *> &PUs)
1044 {
1045  int numPUs = PUs.size();
1046  for (int i = 0; i < numPUs; i++)
1047  for (int j = i + 1; j < numPUs; j++)
1048  if (PU2Y[PUs[i]] > PU2Y[PUs[j]])
1049  swapPU(&PUs[i], &PUs[j]);
1050 }
1051 
1052 void MacroLegalizer::sortSitesBySiteY(std::vector<DeviceInfo::DeviceSite *> &sites)
1053 {
1054  int numSites = sites.size();
1055  bool ordered = true;
1056  for (int i = 1; i < numSites; i++)
1057  {
1058  if (sites[i - 1]->getSiteY() > sites[i]->getSiteY())
1059  {
1060  ordered = false;
1061  break;
1062  }
1063  }
1064  if (ordered)
1065  return;
1066  for (int i = 0; i < numSites; i++)
1067  for (int j = i + 1; j < numSites; j++)
1068  if (sites[i]->getSiteY() > sites[j]->getSiteY())
1069  swapSitePtr(&sites[i], &sites[j]);
1070 }
1071 
1072 void MacroLegalizer::updatePUMatchingLocation(bool isRoughLegalization, bool updateDisplacement)
1073 {
1074  PU2X.clear();
1075  PU2Y.clear();
1076  PU2Columns.clear();
1077  PU2SiteX.clear();
1078  PU2LegalSites.clear();
1079 
1080  BRAMColumn2PUs.clear();
1081  if (BRAMColumnNum > 0)
1082  {
1083  BRAMColumn2PUs.resize(BRAMColumnNum, std::deque<PlacementInfo::PlacementUnit *>(0));
1084  }
1085  DSPColumn2PUs.clear();
1086  if (DSPColumnNum > 0)
1087  {
1088  DSPColumn2PUs.resize(DSPColumnNum, std::deque<PlacementInfo::PlacementUnit *>(0));
1089  }
1090  CARRYColumn2PUs.clear();
1091  if (CARRYColumnNum > 0)
1092  {
1093  CARRYColumn2PUs.resize(CARRYColumnNum, std::deque<PlacementInfo::PlacementUnit *>(0));
1094  }
1095 
1096  float tmpAverageDisplacement = 0.0;
1097 
1098  for (auto matchedPair : cellLevelMatching)
1099  {
1100  auto matchedSite = matchedPair.second;
1101  auto curCell = matchedPair.first;
1102 
1103  auto curPU = placementInfo->getPlacementUnitByCell(curCell);
1104 
1105  if (PU2Y.find(curPU) == PU2Y.end())
1106  {
1107  PU2SiteX[curPU] = -1;
1108  PU2Y[curPU] = 0.0;
1109  if (curCell->isBRAM())
1110  {
1111  BRAMColumn2PUs[matchedSite->getSiteX()].push_back(curPU);
1112  }
1113  if (curCell->isDSP())
1114  {
1115  DSPColumn2PUs[matchedSite->getSiteX()].push_back(curPU);
1116  }
1117  if (curCell->isCarry())
1118  {
1119  CARRYColumn2PUs[matchedSite->getSiteX()].push_back(curPU);
1120  }
1121  }
1122 
1123  float actualPUX = 0;
1124  float actualPUY = 0;
1125  // since the matched site is for a single DSP/BRAM/CARRY cell, we need to find its corresponding placement macro
1126  // (with multiple DSPs/BRAMs/CARRYs)
1127  placementInfo->getPULocationByCellLocation(curCell, matchedSite->X(), matchedSite->Y(), actualPUX, actualPUY);
1128 
1129  tmpAverageDisplacement += std::fabs(cellLoc[curCell->getCellId()].X - matchedSite->X()) +
1130  std::fabs(cellLoc[curCell->getCellId()].Y - matchedSite->Y());
1131  assert(isRoughLegalization || PU2SiteX[curPU] == -1 || PU2SiteX[curPU] == matchedSite->getSiteX());
1132  PU2SiteX[curPU] = matchedSite->getSiteX();
1133  PU2X[curPU] += actualPUX;
1134  PU2Y[curPU] += actualPUY;
1135  if (PU2Columns.find(curPU) == PU2Columns.end())
1136  {
1137  PU2Columns[curPU] = std::vector<int>(0);
1138  }
1139  PU2Columns[curPU].push_back(matchedSite->getSiteX());
1140  }
1141 
1142  tmpAverageDisplacement /= cellLevelMatching.size();
1143 
1144  if (verbose)
1145  print_info("MacroLegalizer[" + legalizerName +
1146  "] Macro Cell Average Displacement = " + std::to_string(tmpAverageDisplacement));
1147 
1148  if (updateDisplacement)
1149  {
1150  if (isRoughLegalization)
1151  roughAverageDisplacement = tmpAverageDisplacement;
1152  else
1153  fixedColumnAverageDisplacement = tmpAverageDisplacement;
1154  }
1155 
1156  for (auto pairPU2X : PU2X)
1157  {
1158  int numCells = getMarcroCellNum(pairPU2X.first);
1159  PU2X[pairPU2X.first] /= numCells;
1160  PU2Y[pairPU2X.first] /= numCells;
1161  }
1162 
1163 #pragma omp parallel for
1164  for (int i = 0; i < BRAMColumnNum; i++)
1166 
1167 #pragma omp parallel for
1168  for (int i = 0; i < DSPColumnNum; i++)
1170 
1171 #pragma omp parallel for
1172  for (int i = 0; i < CARRYColumnNum; i++)
1174 
1176 }
1177 
1178 void MacroLegalizer::spreadMacros(int columnNum, std::vector<int> &columnUntilization,
1179  std::vector<std::vector<DeviceInfo::DeviceSite *>> &column2Sites,
1180  std::vector<std::deque<PlacementInfo::PlacementUnit *>> &column2PUs,
1181  std::map<DesignInfo::DesignCell *, int> &cell2Column, float globalBudgeRatio)
1182 {
1183  std::vector<float> budgetRatios(columnNum, globalBudgeRatio);
1184  while (true)
1185  {
1186  int overflowColId = -1;
1187  std::vector<int> accumulationUtil(columnNum, 0), accumulationCapacity(columnNum, 0);
1188  accumulationUtil[0] = columnUntilization[0];
1189  accumulationCapacity[0] = column2Sites[0].size() * budgetRatios[0];
1190  for (int colId = 1; colId < columnNum; colId++)
1191  {
1192  accumulationUtil[colId] = accumulationUtil[colId - 1] + columnUntilization[colId];
1193  accumulationCapacity[colId] =
1194  accumulationCapacity[colId - 1] + column2Sites[colId].size() * budgetRatios[colId];
1195  }
1196 
1197  for (int colId = 0; colId < columnNum; colId++)
1198  {
1199  if (budgetRatios[colId] == 1)
1200  {
1201  if (column2Sites[colId].size() < (unsigned int)columnUntilization[colId])
1202  {
1203  overflowColId = colId;
1204  break;
1205  }
1206  }
1207  else
1208  {
1209  if (column2Sites[colId].size() * budgetRatios[colId] < (unsigned int)columnUntilization[colId])
1210  {
1211  overflowColId = colId;
1212  break;
1213  }
1214  }
1215 
1216  if (!macroCanBeFitIn(colId, column2Sites, column2PUs[colId]))
1217  {
1218  assert(budgetRatios[colId] - 0.05 > 0);
1219  budgetRatios[colId] -= 0.05;
1220  overflowColId = colId;
1221  break;
1222  }
1223  }
1224  if (overflowColId < 0)
1225  {
1226  break;
1227  }
1228  else
1229  {
1230  print_warning("column overflow resolving col:" + std::to_string(overflowColId));
1231  for (int colId = 0; colId < columnNum; colId++)
1232  {
1233  std::cout << " colId#" << colId << " columnUntilization:" << columnUntilization[colId] << " "
1234  << " siteCap:" << column2Sites[colId].size()
1235  << " actualSiteCap:" << column2Sites[colId].size() * budgetRatios[colId] << "\n";
1236  }
1237  int leftAvaliableCapacity = 0;
1238  int rightAvaliableCapacity = 0;
1239  int leftUtil = 0;
1240  int rightUtil = 0;
1241 
1242  if (overflowColId > 0)
1243  {
1244  leftAvaliableCapacity += accumulationCapacity[overflowColId - 1];
1245  leftUtil += accumulationUtil[overflowColId - 1];
1246  }
1247  if (overflowColId < columnNum - 1)
1248  {
1249  rightAvaliableCapacity += accumulationCapacity[columnNum - 1] - accumulationCapacity[overflowColId];
1250  rightUtil += accumulationUtil[columnNum - 1] - accumulationUtil[overflowColId];
1251  }
1252 
1253  int overflowNum =
1254  (unsigned int)columnUntilization[overflowColId] -
1255  column2Sites[overflowColId].size() * budgetRatios[overflowColId]; // spread more for redundant space
1256  int toLeft = 0;
1257 
1258  std::cout << " overflowNum=" << overflowNum << "\n";
1259 
1260  int totalAvailableCapacity = rightAvaliableCapacity + leftAvaliableCapacity - leftUtil - rightUtil;
1261  assert(totalAvailableCapacity > 0);
1262  float toLeftRatio = (float)(leftAvaliableCapacity - leftUtil) / totalAvailableCapacity;
1263  int toLeftNum = int((overflowNum * toLeftRatio) + 0.4999);
1264  int toRightNum = overflowNum - toLeft;
1265 
1266  if (leftAvaliableCapacity - leftUtil > 0)
1267  {
1268  while (toLeftNum > 0 && column2PUs[overflowColId].size() > 0)
1269  {
1270  column2PUs[overflowColId - 1].push_back(column2PUs[overflowColId][0]);
1271  int macroSize = getMarcroCellNum(column2PUs[overflowColId][0]);
1272  columnUntilization[overflowColId - 1] += macroSize;
1273  columnUntilization[overflowColId] -= macroSize;
1274  toLeftNum -= macroSize;
1275  column2PUs[overflowColId].pop_front();
1276  }
1277  }
1278  if (rightAvaliableCapacity - rightUtil > 0)
1279  {
1280  while (toRightNum > 0 && column2PUs[overflowColId].size() > 0)
1281  {
1282  column2PUs[overflowColId + 1].push_front(
1283  column2PUs[overflowColId][column2PUs[overflowColId].size() - 1]);
1284  int macroSize = getMarcroCellNum(column2PUs[overflowColId][column2PUs[overflowColId].size() - 1]);
1285  columnUntilization[overflowColId + 1] += macroSize;
1286  columnUntilization[overflowColId] -= macroSize;
1287  toRightNum -= macroSize;
1288  column2PUs[overflowColId].pop_back();
1289  }
1290  }
1291  }
1292  }
1293  cell2Column.clear();
1294  for (unsigned int colId = 0; colId < column2PUs.size(); colId++)
1295  {
1296  auto PUs = column2PUs[colId];
1297  for (auto curPU : PUs)
1298  {
1299  if (auto unpackedCell = dynamic_cast<PlacementInfo::PlacementUnpackedCell *>(curPU))
1300  {
1301  auto curCell = unpackedCell->getCell();
1302  cell2Column[curCell] = colId;
1303  }
1304  else if (auto macroPU = dynamic_cast<PlacementInfo::PlacementMacro *>(curPU))
1305  {
1306  for (auto curCell : macroPU->getCells())
1307  {
1308  cell2Column[curCell] = colId;
1309  }
1310  }
1311  }
1312  }
1313 }
1314 
1316 {
1318  {
1320  }
1322  {
1324  }
1326  {
1328  0.9);
1329  }
1330 }
1331 
1332 int MacroLegalizer::findIdMaxWithRecurence(int minId, int maxId, std::vector<int> &ids)
1333 {
1334  int resId = -1;
1335  int maxRecurence = 0;
1336  assert(ids.size() > 0);
1337  for (int i = minId; i <= maxId; i++)
1338  {
1339  int cnt = 0;
1340  for (auto id : ids)
1341  {
1342  if (id == i)
1343  cnt++;
1344  }
1345  if (cnt > maxRecurence)
1346  {
1347  resId = i;
1348  maxRecurence = cnt;
1349  }
1350  }
1351  assert(resId >= 0);
1352  return resId;
1353 }
1354 
1355 int MacroLegalizer::findCorrespondingColumn(float curX, std::vector<float> &Xs)
1356 {
1357  int resId = -1;
1358  float closeDiff = 100000000;
1359 
1360  for (unsigned int i = 0; i < Xs.size(); i++)
1361  {
1362  if (std::fabs(curX - Xs[i]) < closeDiff)
1363  {
1364  closeDiff = std::fabs(curX - Xs[i]);
1365  resId = i;
1366  }
1367  }
1368 
1369  assert(resId >= 0);
1370  return resId;
1371 }
1372 
1373 void MacroLegalizer::mapMacrosToColumns(bool directLegalization)
1374 {
1375  BRAMColumn2PUs.clear();
1376  BRAMColumnUntilization.clear();
1377  if (BRAMColumnNum > 0)
1378  {
1379  BRAMColumn2PUs.resize(BRAMColumnNum, std::deque<PlacementInfo::PlacementUnit *>(0));
1381 
1382  if (directLegalization)
1383  {
1384  for (auto &tmpMacroUnit : BRAMPUs)
1385  {
1386  if (BRAMPUs.find(tmpMacroUnit) != BRAMPUs.end())
1387  {
1388  int colId = findCorrespondingColumn(tmpMacroUnit->X(), BRAMColumnXs);
1389  BRAMColumn2PUs[colId].push_back(tmpMacroUnit);
1390  BRAMColumnUntilization[colId] += getMarcroCellNum(tmpMacroUnit);
1391  }
1392  }
1393  }
1394  else
1395  {
1396  for (auto &PUCol_pair : PU2Columns)
1397  {
1398  auto tmpMacroUnit = PUCol_pair.first;
1399  if (BRAMPUs.find(tmpMacroUnit) != BRAMPUs.end())
1400  {
1401  int colId = findIdMaxWithRecurence(0, BRAMColumnNum - 1, PUCol_pair.second);
1402 
1403  BRAMColumn2PUs[colId].push_back(tmpMacroUnit);
1404  BRAMColumnUntilization[colId] += getMarcroCellNum(tmpMacroUnit);
1405  }
1406  }
1407  }
1408  }
1409 
1410  DSPColumn2PUs.clear();
1411  DSPColumnUntilization.clear();
1412  if (DSPColumnNum > 0)
1413  {
1414  DSPColumn2PUs.resize(DSPColumnNum, std::deque<PlacementInfo::PlacementUnit *>(0));
1416 
1417  if (directLegalization)
1418  {
1419  for (auto tmpMacroUnit : DSPPUs)
1420  {
1421  if (DSPPUs.find(tmpMacroUnit) != DSPPUs.end())
1422  {
1423  int colId = findCorrespondingColumn(tmpMacroUnit->X(), DSPColumnXs);
1424 
1425  DSPColumn2PUs[colId].push_back(tmpMacroUnit);
1426  DSPColumnUntilization[colId] += getMarcroCellNum(tmpMacroUnit);
1427  }
1428  }
1429  }
1430  else
1431  {
1432  for (auto &PUCol_pair : PU2Columns)
1433  {
1434  auto tmpMacroUnit = PUCol_pair.first;
1435  if (DSPPUs.find(tmpMacroUnit) != DSPPUs.end())
1436  {
1437  int colId = findIdMaxWithRecurence(0, DSPColumnNum - 1, PUCol_pair.second);
1438 
1439  DSPColumn2PUs[colId].push_back(tmpMacroUnit);
1440  DSPColumnUntilization[colId] += getMarcroCellNum(tmpMacroUnit);
1441  }
1442  }
1443  }
1444  }
1445 
1446  CARRYColumn2PUs.clear();
1447  CARRYColumnUntilization.clear();
1448  if (CARRYColumnNum > 0)
1449  {
1450  CARRYColumn2PUs.resize(CARRYColumnNum, std::deque<PlacementInfo::PlacementUnit *>(0));
1452  if (directLegalization)
1453  {
1454  for (auto tmpMacroUnit : CARRYPUs)
1455  {
1456  if (CARRYPUs.find(tmpMacroUnit) != CARRYPUs.end())
1457  {
1458  int colId = findCorrespondingColumn(tmpMacroUnit->X(), CARRYColumnXs);
1459 
1460  CARRYColumn2PUs[colId].push_back(tmpMacroUnit);
1461  CARRYColumnUntilization[colId] += getMarcroCellNum(tmpMacroUnit);
1462  }
1463  }
1464  }
1465  else
1466  {
1467  for (auto &PUCol_pair : PU2Columns)
1468  {
1469  auto tmpMacroUnit = PUCol_pair.first;
1470  if (CARRYPUs.find(tmpMacroUnit) != CARRYPUs.end())
1471  {
1472  int colId = findIdMaxWithRecurence(0, CARRYColumnNum - 1, PUCol_pair.second);
1473 
1474  CARRYColumn2PUs[colId].push_back(tmpMacroUnit);
1475  CARRYColumnUntilization[colId] += getMarcroCellNum(tmpMacroUnit);
1476  }
1477  }
1478  }
1479  }
1480 }
1481 
1483 {
1484  if (PULevelMatching.size() == 0)
1485  {
1486  for (auto matchedPair : cellLevelMatching)
1487  {
1488  auto matchedSite = matchedPair.second;
1489  assert(!matchedSite->isMapped());
1490  matchedSite->setMapped();
1491  }
1492  }
1493  else
1494  {
1495  for (auto matchedPair : PULevelMatching)
1496  {
1497  auto targetPU = matchedPair.first;
1498  for (auto curSite : PU2LegalSites[targetPU])
1499  {
1500  assert(!curSite->isMapped());
1501  curSite->setMapped();
1502  }
1503  }
1504  }
1505 }
1506 
1508 {
1509  if (PULevelMatching.size() == 0)
1510  {
1511  for (auto matchedPair : cellLevelMatching)
1512  {
1513  auto matchedSite = matchedPair.second;
1514  assert(matchedSite->isMapped());
1515  matchedSite->resetMapped();
1516  }
1517  }
1518  else
1519  {
1520  for (auto matchedPair : PULevelMatching)
1521  {
1522  auto targetPU = matchedPair.first;
1523  for (auto curSite : PU2LegalSites[targetPU])
1524  {
1525  assert(curSite->isMapped());
1526  curSite->resetMapped();
1527  }
1528  }
1529  PULevelMatching.clear();
1530  }
1531 }
DesignInfo::isBRAM
static bool isBRAM(DesignCellType cellType)
Definition: DesignInfo.h:1341
MinCostBipartiteMatcher
Definition: MinCostBipartiteMatcher.h:44
MacroLegalizer::DSPColumnNum
int DSPColumnNum
the number of DSP columns on the target device
Definition: MacroLegalizer.h:300
MacroLegalizer::roughAverageDisplacement
float roughAverageDisplacement
the average displacement of rough legalization for the involved PlacementUnit
Definition: MacroLegalizer.h:494
paintPlacement.cnt
int cnt
Definition: paintPlacement.py:155
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
DesignInfo::CellType_RAMB36E2
@ CellType_RAMB36E2
Definition: DesignInfo.h:111
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
PlacementInfo::isLegalLocation
bool isLegalLocation(DesignInfo::DesignCell *curCell, float targetX, float targetY)
check whether the PlacementUnit is legalized in the device area when a cell in it is placed at target...
Definition: PlacementInfo.h:3452
PlacementInfo::getCells
std::vector< DesignInfo::DesignCell * > & getCells()
Definition: PlacementInfo.h:3898
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::resetSitesMapped
void resetSitesMapped()
reset the mapped flag of the involved sites.
Definition: MacroLegalizer.cc:1507
DesignInfo::CellType_FIFO18E2
@ CellType_FIFO18E2
Definition: DesignInfo.h:109
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
DeviceInfo::getSitesInType
std::vector< DeviceSite * > & getSitesInType(std::string &siteType)
Get sites of a specfic type.
Definition: DeviceInfo.h:1043
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
PlacementInfo::PlacementMacro::PlacementMacroType_CARRY
@ PlacementMacroType_CARRY
Definition: PlacementInfo.h:1537
MacroLegalizer::noTarget
bool noTarget
Definition: MacroLegalizer.h:496
MacroLegalizer::initialDisplacementThreshold
float initialDisplacementThreshold
displacement threshold to detect potential legal sites
Definition: MacroLegalizer.h:502
MacroLegalizer::adjList
std::vector< std::vector< std::pair< int, float > > > adjList
the adjacent list of the bipartite graph
Definition: MacroLegalizer.h:250
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::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
DesignInfo::isCarry
static bool isCarry(DesignCellType cellType)
Definition: DesignInfo.h:1331
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
PlacementInfo::getPULegalXY
std::pair< std::map< PlacementInfo::PlacementUnit *, float >, std::map< PlacementInfo::PlacementUnit *, float > > & getPULegalXY()
get the locations (pair of X,Y) of the legalized PlacementUnit objects
Definition: PlacementInfo.h:3693
MinCostBipartiteMatcher::solve
void solve()
Definition: MinCostBipartiteMatcher.cc:28
MacroLegalizer::clockRegionCasLegalization
bool clockRegionCasLegalization
Definition: MacroLegalizer.h:471
MacroLegalizer::JSONCfg
std::map< std::string, std::string > & JSONCfg
Definition: MacroLegalizer.h:188
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::DSPColumn2Sites
std::vector< std::vector< DeviceInfo::DeviceSite * > > DSPColumn2Sites
record the sites in each column of DSP
Definition: MacroLegalizer.h:354
DesignInfo::isDSP
static bool isDSP(DesignCellType cellType)
Definition: DesignInfo.h:1336
MacroLegalizer::getMarcroCellNum
int getMarcroCellNum(PlacementInfo::PlacementUnit *tmpMacroUnit)
check how many sites are required by the given PlacementUnit
Definition: MacroLegalizer.cc:1019
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
PlacementInfo::PlacementUnit::getName
std::string & getName()
Definition: PlacementInfo.h:1186
MacroLegalizer::CARRYColumn2Sites
std::vector< std::vector< DeviceInfo::DeviceSite * > > CARRYColumn2Sites
record the sites in each column of CARRY
Definition: MacroLegalizer.h:360
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
delayVisualization.c
c
Definition: delayVisualization.py:99
MacroLegalizer::compatiblePlacementTable
PlacementInfo::CompatiblePlacementTable * compatiblePlacementTable
compatiblePlacementTable describes the type mapping from design to device, where a cell can be placed...
Definition: MacroLegalizer.h:174
PlacementInfo::CompatiblePlacementTable::sharedCellBELTypes
std::vector< std::string > sharedCellBELTypes
some BEL types (design cells should be mapped to the BEL slot on FPGA device)
Definition: PlacementInfo.h:135
DesignInfo::CellType_RAMB18E2
@ CellType_RAMB18E2
Definition: DesignInfo.h:110
MacroLegalizer::cellLoc
std::vector< PlacementInfo::Location > & cellLoc
a reference of the locations of cells (in cellId order)
Definition: MacroLegalizer.h:186
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
DesignInfo::CellType_FIFO36E2
@ CellType_FIFO36E2
Definition: DesignInfo.h:108
print_status
void print_status(std::string tmp_string)
Definition: strPrint.cc:44
MacroLegalizer::BRAMColumn2PUs
std::vector< std::deque< PlacementInfo::PlacementUnit * > > BRAMColumn2PUs
record the PlacementUnits in each column of BRAM Sites
Definition: MacroLegalizer.h:366
MacroLegalizer::initialMacrosToLegalize
std::vector< DesignInfo::DesignCell * > initialMacrosToLegalize
a vector storing the cells in macros which SHOULD be legalized
Definition: MacroLegalizer.h:206
MacroLegalizer::clockRegionAware
bool clockRegionAware
Definition: MacroLegalizer.h:470
MacroLegalizer::sortPUsByPU2Y
void sortPUsByPU2Y(std::deque< PlacementInfo::PlacementUnit * > &PUs)
Definition: MacroLegalizer.cc:1043
print_warning
void print_warning(std::string tmp_string)
Definition: strPrint.cc:57
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
PlacementInfo::setPULegalSite
void setPULegalSite(std::map< PlacementInfo::PlacementUnit *, std::vector< DeviceInfo::DeviceSite * >> &PU2Sites)
set the sites occupied by the PlacementUnit objects
Definition: PlacementInfo.h:3668
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
PlacementInfo::getPlacementUnitByCellId
PlacementUnit * getPlacementUnitByCellId(int cellId)
Definition: PlacementInfo.h:3127
MacroLegalizer::BRAMColumnUntilization
std::vector< int > BRAMColumnUntilization
record the number of cells (Macro contains multiple cells) in each column for BRAM
Definition: MacroLegalizer.h:384
PlacementInfo::setPULegalXY
void setPULegalXY(std::map< PlacementInfo::PlacementUnit *, float > &PU2X, std::map< PlacementInfo::PlacementUnit *, float > &PU2Y)
set the legalization of some PlacementUnit objects
Definition: PlacementInfo.h:3648
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
MacroLegalizer::dumpMatching
void dumpMatching(bool fixedColumn=false, bool enforce=false)
Definition: MacroLegalizer.cc:922
writeStrToGZip
void writeStrToGZip(std::string fileName, std::stringstream &data)
Definition: dumpZip.cc:29
MacroLegalizer::CARRYPUs
std::set< PlacementInfo::PlacementUnit * > CARRYPUs
the PlacementUnits which shoudl be mapped to CARRY BEL
Definition: MacroLegalizer.h:463
MacroLegalizer.h
This header file contains the definitions of MacroLegalizer class and its internal modules and APIs w...
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
PlacementInfo::getPULocationByCellLocation
void getPULocationByCellLocation(DesignInfo::DesignCell *curCell, float targetX, float targetY, float &PUX, float &PUY)
Definition: PlacementInfo.h:3546
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::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::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
print_info
void print_info(std::string tmp_string)
Definition: strPrint.cc:39
MacroLegalizer::PU2LegalSites
std::map< PlacementInfo::PlacementUnit *, std::vector< DeviceInfo::DeviceSite * > > PU2LegalSites
Definition: MacroLegalizer.h:416
PlacementInfo::CompatiblePlacementTable::sharedCellType2SiteType
std::map< std::string, std::string > sharedCellType2SiteType
The mapping from shared cell types to device site types.
Definition: PlacementInfo.h:169
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
checkHalfColumn.i
int i
Definition: checkHalfColumn.py:5
MinCostBipartiteMatcher::getMatchedRightNode
int getMatchedRightNode(int x)
Definition: MinCostBipartiteMatcher.h:119
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
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
PlacementInfo::PlacementMacro::PlacementMacroType_BRAM
@ PlacementMacroType_BRAM
Definition: PlacementInfo.h:1539
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
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
PlacementInfo::getPotentialBELTypeIDs
std::vector< int > & getPotentialBELTypeIDs(DesignInfo::DesignCell *cell)
Definition: PlacementInfo.h:2932
MacroLegalizer::DSPColumnXs
std::vector< float > DSPColumnXs
the floating-point X location of the DSP columns on the device
Definition: MacroLegalizer.h:336
PlacementInfo
Information related to FPGA placement (wirelength optimization, cell spreading, legalization,...
Definition: PlacementInfo.h:59