35 std::string &sharedCellType,
int currentIteration,
float capacityShrinkRatio,
37 : placementInfo(placementInfo), JSONCfg(JSONCfg), sharedCellType(sharedCellType),
38 currentIteration(currentIteration), capacityShrinkRatio(capacityShrinkRatio), verbose(verbose),
39 binGrid(placementInfo->getBinGrid(placementInfo->getSharedBELTypeId(sharedCellType)))
53 unsigned int spreadRegionBinSizeLimit)
58 std::deque<int> overflowBinNumQ;
64 std::vector<int> historyTotalCellNum(0);
71 for (
auto curBin : row)
73 curBin->resetBinShrinkRatio();
74 curBin->resetNoOverflowCounter();
75 curBin->resetOverflowCounter();
82 if (
JSONCfg.find(
"DumpLUTFFCoordTrace-GeneralSpreader") !=
JSONCfg.end())
84 std::string dumpFile =
JSONCfg[
"DumpLUTFFCoordTrace-GeneralSpreader"];
88 print_status(
"GeneralSpreader: finding overflow regions");
94 totalCellNum += curBin->getCells().size();
99 print_info(
"found " + std::to_string(totalCellNum) +
" cells in them");
100 print_info(
"spread for " + std::to_string(loopCnt) +
" iterations");
104 std::set<PlacementInfo::PlacementUnit *> involvedPUs;
105 std::set<DesignInfo::DesignCell *> involvedCells;
106 std::vector<PlacementInfo::PlacementUnit *> involvedPUVec;
107 involvedPUVec.clear();
109 involvedCells.clear();
117 bool overlappedWithPreviousRegion =
false;
120 if (curRegion->isRegionOverlap(newRegion))
122 overlappedWithPreviousRegion =
true;
123 std::cout <<
"newRegion: "
124 <<
" left:" << newRegion->
left() <<
" right:" << newRegion->
right()
125 <<
" top:" << newRegion->
top() <<
" bottom:" << newRegion->
bottom() <<
"\n";
126 std::cout <<
"====================================================\n";
129 std::cout <<
"-----------------\n";
130 std::cout << curbin0 <<
" sharedBELStr:" << curbin0->getSharedCellType()
131 <<
" X: " << curbin0->X() <<
" Y: " << curbin0->Y() <<
" left:" << curbin0->left()
132 <<
" right:" << curbin0->right() <<
" top:" << curbin0->top()
133 <<
" bottom:" << curbin0->bottom() <<
"\n";
135 std::cout <<
"\n\n\nexistingRegion: "
136 <<
" left:" << curRegion->left() <<
" right:" << curRegion->right()
137 <<
" top:" << curRegion->top() <<
" bottom:" << curRegion->bottom() <<
"\n";
138 std::cout <<
"====================================================\n";
139 for (
auto curbin0 : curRegion->getBinsInRegion())
141 std::cout <<
"-----------------\n";
142 std::cout << curbin0 <<
" sharedBELStr:" << curbin0->getSharedCellType()
143 <<
" X: " << curbin0->X() <<
" Y: " << curbin0->Y() <<
" left:" << curbin0->left()
144 <<
" right:" << curbin0->right() <<
" top:" << curbin0->top()
145 <<
" bottom:" << curbin0->bottom() <<
"\n";
150 if (!overlappedWithPreviousRegion)
157 assert(
false &&
"should not overlap");
165 #pragma omp parallel sections
174 print_status(
"GeneralSpreader: spreading cells in the regions");
180 #pragma omp parallel for schedule(dynamic, 4)
181 for (
int regionId = 0; regionId < regionNum; regionId++)
185 assert(curRegion->
getCells().size() > 0);
194 for (
int regionId = 0; regionId < regionNum; regionId++)
198 assert(curRegion->
getCells().size() > 0);
209 print_status(
"GeneralSpreader: loading involved placement units");
214 assert(curRegion->getCells().size() > 0);
215 for (
auto curCell : curRegion->getCells())
217 if (involvedCells.find(curCell) == involvedCells.end())
220 if (involvedPUs.find(tmpPU) == involvedPUs.end())
222 involvedPUs.insert(tmpPU);
223 involvedPUVec.push_back(tmpPU);
225 involvedCells.insert(curCell);
232 omp_set_num_threads(
nJobs);
240 print_status(
"GeneralSpreader: updating Placement Units With Spreaded Cell Locations");
242 enableClockRegionAware, displacementLimit);
244 print_status(
"GeneralSpreader: updated Placement Units With Spreaded Cell Locations");
249 print_status(
"GeneralSpreader: processed all overflow regions");
273 for (
auto curBin : row)
275 if (curBin->isOverflow(overflowThreshold))
279 curBin->countOverflow();
280 if (curBin->getOverflowCounter() > 5)
282 if (curBin->getBinShrinkRatio() > 0.8)
284 curBin->shrinkBinBy(0.015);
288 curBin->resetBinShrinkRatio();
290 curBin->resetOverflowCounter();
295 curBin->countNoOverflow();
296 curBin->resetOverflowCounter();
297 if (curBin->getNoOverflowCounter() > 5)
299 curBin->resetBinShrinkRatio();
308 PlacementInfo *placementInfo, std::set<PlacementInfo::PlacementUnit *> &involvedPUs,
309 std::set<DesignInfo::DesignCell *> &involvedCells, std::vector<PlacementInfo::PlacementUnit *> &involvedPUVec,
310 float forgetRatio,
float displacementLimit,
int startId,
int endId)
312 bool displacementLimitEnable = displacementLimit > 0;
314 for (
int curPUID = startId; curPUID < endId; curPUID++)
316 assert((
unsigned int)curPUID < involvedPUVec.size());
317 auto curPU = involvedPUVec[curPUID];
320 float cellX = curUnpackedCell->X();
321 float cellY = curUnpackedCell->Y();
323 if (curPU->isFixed() || curPU->isLocked())
331 if (displacementLimitEnable)
332 curPU->setSpreadLocation_WithLimitDisplacement(cellLoc[curCell->
getCellId()].X,
333 cellLoc[curCell->
getCellId()].Y, forgetRatio,
336 curPU->setSpreadLocation(cellLoc[curCell->
getCellId()].X, cellLoc[curCell->
getCellId()].Y,
339 cellLoc[curCell->
getCellId()].X = curPU->X();
340 cellLoc[curCell->
getCellId()].Y = curPU->Y();
345 if (curPU->isFixed() || curPU->isLocked())
347 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
349 float offsetX_InMacro, offsetY_InMacro;
351 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
353 float cellX = curMacro->X() + offsetX_InMacro;
354 float cellY = curMacro->Y() + offsetY_InMacro;
364 double tmpTotalX = 0.0;
365 double tmpTotalY = 0.0;
367 int numCellsInvolvedInSpreading = 0;
368 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
371 if (involvedCells.find(curCell) != involvedCells.end())
373 float offsetX_InMacro, offsetY_InMacro;
375 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
378 tmpTotalX += cellLoc[curCell->
getCellId()].X - offsetX_InMacro;
379 tmpTotalY += cellLoc[curCell->
getCellId()].Y - offsetY_InMacro;
380 numCellsInvolvedInSpreading++;
383 tmpTotalX /= (double)numCellsInvolvedInSpreading;
384 tmpTotalY /= (double)numCellsInvolvedInSpreading;
386 float curNewPUX = tmpTotalX;
387 float curNewPUY = tmpTotalY;
389 if (displacementLimitEnable)
390 curPU->setSpreadLocation_WithLimitDisplacement(curNewPUX, curNewPUY, forgetRatio,
393 curPU->setSpreadLocation(curNewPUX, curNewPUY, forgetRatio);
395 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
397 float offsetX_InMacro, offsetY_InMacro;
399 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
401 float cellX = curMacro->X() + offsetX_InMacro;
402 float cellY = curMacro->Y() + offsetY_InMacro;
415 std::set<PlacementInfo::PlacementUnit *> &involvedPUs, std::set<DesignInfo::DesignCell *> &involvedCells,
416 std::vector<PlacementInfo::PlacementUnit *> &involvedPUVec,
float forgetRatio,
bool enableClockRegionAware,
417 float displacementLimit)
420 bool displacementLimitEnable = displacementLimit > 0;
442 if (enableClockRegionAware)
446 for (
auto curCell : involvedCells)
449 if (PU2ClockRegionColumn.find(PU) != PU2ClockRegionColumn.end())
451 int clockRegionX = PU2ClockRegionColumn[PU];
452 if (clockRegionX == 2)
454 float rLeft = clockRegions[0][clockRegionX]->getLeft();
455 float rRight = clockRegions[0][clockRegionX]->getRight();
456 if (cellLoc[curCell->getCellId()].X < rLeft)
457 cellLoc[curCell->getCellId()].
X = rLeft + 0.1;
458 if (cellLoc[curCell->getCellId()].X > rRight)
459 cellLoc[curCell->getCellId()].X = rRight - 0.1;
461 else if (clockRegionX < 2)
463 float rRight = clockRegions[0][1]->getRight();
464 if (cellLoc[curCell->getCellId()].X > rRight)
465 cellLoc[curCell->getCellId()].X = rRight - 0.1;
467 else if (clockRegionX > 2)
469 float rLeft = clockRegions[0][3]->getLeft();
470 if (cellLoc[curCell->getCellId()].X < rLeft)
471 cellLoc[curCell->getCellId()].X = rLeft + 0.1;
477 if (involvedPUs.size() > 100)
479 std::vector<std::thread *> threadsVec;
481 int eachThreadPUNum = involvedPUVec.size() /
nJobs;
482 std::vector<std::pair<int, int>> startEndPairs;
483 startEndPairs.clear();
485 for (
int threadId = 0, startId = 0, endId = eachThreadPUNum; threadId <
nJobs;
486 threadId++, startId += eachThreadPUNum, endId += eachThreadPUNum)
488 if (threadId ==
nJobs - 1)
490 endId = involvedPUVec.size();
492 startEndPairs.emplace_back(startId, endId);
494 for (
int threadId = 0; threadId <
nJobs; threadId++)
496 std::thread *newThread =
498 std::ref(involvedPUs), std::ref(involvedCells), std::ref(involvedPUVec),
499 std::ref(forgetRatio), std::ref(displacementLimit),
500 std::ref(startEndPairs[threadId].first), std::ref(startEndPairs[threadId].second));
501 threadsVec.push_back(newThread);
503 for (
int threadId = 0; threadId <
nJobs; threadId++)
505 threadsVec[threadId]->join();
506 delete threadsVec[threadId];
511 for (
auto curPU : involvedPUVec)
515 float cellX = curUnpackedCell->X();
516 float cellY = curUnpackedCell->Y();
518 if (curPU->isFixed() || curPU->isLocked())
528 if (displacementLimitEnable)
529 curPU->setSpreadLocation_WithLimitDisplacement(cellLoc[curCell->
getCellId()].X,
530 cellLoc[curCell->
getCellId()].Y, forgetRatio,
533 curPU->setSpreadLocation(cellLoc[curCell->
getCellId()].X, cellLoc[curCell->
getCellId()].Y,
536 cellLoc[curCell->
getCellId()].X = curPU->X();
537 cellLoc[curCell->
getCellId()].Y = curPU->Y();
542 if (curPU->isFixed() || curPU->isLocked())
544 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
546 float offsetX_InMacro, offsetY_InMacro;
548 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
550 float cellX = curMacro->X() + offsetX_InMacro;
551 float cellY = curMacro->Y() + offsetY_InMacro;
561 double tmpTotalX = 0.0;
562 double tmpTotalY = 0.0;
564 int numCellsInvolvedInSpreading = 0;
565 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
568 if (involvedCells.find(curCell) != involvedCells.end())
570 float offsetX_InMacro, offsetY_InMacro;
572 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
575 tmpTotalX += cellLoc[curCell->
getCellId()].X - offsetX_InMacro;
576 tmpTotalY += cellLoc[curCell->
getCellId()].Y - offsetY_InMacro;
577 numCellsInvolvedInSpreading++;
580 tmpTotalX /= (double)numCellsInvolvedInSpreading;
581 tmpTotalY /= (double)numCellsInvolvedInSpreading;
582 float curNewPUX = tmpTotalX;
583 float curNewPUY = tmpTotalY;
586 if (displacementLimitEnable)
587 curPU->setSpreadLocation_WithLimitDisplacement(curNewPUX, curNewPUY, forgetRatio,
590 curPU->setSpreadLocation(curNewPUX, curNewPUY, forgetRatio);
593 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
595 float offsetX_InMacro, offsetY_InMacro;
597 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
599 float cellX = curMacro->X() + offsetX_InMacro;
600 float cellY = curMacro->Y() + offsetY_InMacro;
614 float capacityShrinkRatio,
unsigned int numBinThr)
619 float binUnitSize = std::min(curBin->
right() - curBin->
left(), curBin->
top() - curBin->
bottom());
657 int newRegionRightBinX,
658 std::set<PlacementInfo::PlacementBinInfo *> &coveredBinSet)
660 assert(!
isRegionOverlap(newRegionTopBinY, newRegionBottomBinY, newRegionLeftBinX, newRegionRightBinX));
661 if (newRegionTopBinY >
topBinY)
670 assert(0 <= newRegionBottomBinY);
671 assert(0 <= newRegionTopBinY);
672 assert((
unsigned int)newRegionBottomBinY <
binGrid.size());
673 assert((
unsigned int)newRegionTopBinY <
binGrid.size());
674 assert(0 <= newRegionLeftBinX);
675 assert(0 <= newRegionRightBinX);
676 assert((
unsigned int)newRegionLeftBinX <
binGrid[0].size());
677 assert((
unsigned int)newRegionRightBinX <
binGrid[0].size());
678 for (
int i = newRegionBottomBinY;
i <= newRegionTopBinY;
i++)
679 for (
int j = newRegionLeftBinX; j <= newRegionRightBinX; j++)
702 tmpPU->recordSpreadLocatin();
710 if (topBinY - bottomBinY < minExpandSize - 1 && rightBinX - leftBinX < minExpandSize - 1)
715 SubBox *boxA =
nullptr, *boxB =
nullptr;
718 if (rightBinX - leftBinX >= minExpandSize - 1)
720 spreadCellsH(&boxA, &boxB);
722 if (!(boxA || boxB) && topBinY - bottomBinY >= minExpandSize - 1)
724 spreadCellsV(&boxA, &boxB);
729 if (topBinY - bottomBinY >= minExpandSize - 1)
731 spreadCellsV(&boxA, &boxB);
733 if (!(boxA || boxB) && rightBinX - leftBinX >= minExpandSize - 1)
735 spreadCellsH(&boxA, &boxB);
744 boxB->spreadAndPartition();
756 if (cellIds.size() == 0)
758 if (cellIds.size() > 1)
759 quick_sort(cellIds, 0, cellIds.size() - 1,
true);
761 std::vector<float> colCapacity(rightBinX - leftBinX + 1, 0.0);
762 float totalCapacity = 0;
764 assert(leftBinX >= 0);
765 assert(bottomBinY >= 0);
766 assert((
unsigned int)topBinY <
binGrid.size());
767 assert((
unsigned int)rightBinX <
binGrid[topBinY].size());
769 for (
int binX = leftBinX; binX <= rightBinX; binX++)
771 for (
int y = bottomBinY;
y <= topBinY;
y++)
774 colCapacity[binX - leftBinX] += binCapacity;
775 totalCapacity += binCapacity;
783 int boxALeft = leftBinX;
784 int boxBRight = rightBinX;
785 for (
int binX = leftBinX; binX <= rightBinX; binX++, boxALeft++)
787 if (colCapacity[binX - leftBinX] > 0)
790 for (
int binX = rightBinX; binX >= leftBinX; binX--, boxBRight--)
792 if (colCapacity[binX - leftBinX] > 0)
795 if (boxBRight <= boxALeft)
798 assert(
false &&
"should not happen");
804 int boxARight = boxALeft;
805 int boxBLeft = boxBRight;
806 float leftCapacity = colCapacity[boxARight - leftBinX];
807 float rightCapacity = colCapacity[boxBLeft - leftBinX];
808 while (boxARight < boxBLeft - 1)
810 if (leftCapacity <= rightCapacity)
813 leftCapacity += colCapacity[boxARight - leftBinX];
818 rightCapacity += colCapacity[boxBLeft - leftBinX];
823 float leftUtilRatio = leftCapacity / totalCapacity;
824 float totalUtilization = 0;
825 for (
auto cellId : cellIds)
829 float leftUtil = totalUtilization * leftUtilRatio;
834 for (
auto cellId : cellIds)
844 *boxA =
new SubBox(
this, topBinY, bottomBinY, boxALeft, boxARight, 0, cutLineIdX);
845 *boxB =
new SubBox(
this, topBinY, bottomBinY, boxBLeft, boxBRight, cutLineIdX + 1, cellIds.size() - 1);
848 float overallOverflowRatio = totalUtilization / totalCapacity;
849 if (overallOverflowRatio < 1)
850 overallOverflowRatio = 1;
852 std::vector<int> &boxACellIds = (*boxA)->cellIds;
853 if (boxACellIds.size() > 0)
855 int cellInBinHead = boxACellIds.size() - 1;
856 int cellInBinTail = boxACellIds.size() - 1;
860 for (
int binX = boxARight; binX >= boxALeft; binX--)
862 if (cellInBinTail < 0)
867 float oldLoX = cellLoc[boxACellIds[cellInBinTail]].X;
868 float oldHiX = oldLoX;
869 for (cellInBinHead = cellInBinTail;
870 cellInBinHead >= 0 &&
871 (binX == boxALeft || (cArea / overallOverflowRatio <= colCapacity[binX - leftBinX] + eps));
875 oldLoX = cellLoc[boxACellIds[cellInBinHead]].X;
882 assert((
unsigned int)binX <
binGrid[bottomBinY].size());
885 float rangeold = oldHiX - oldLoX;
886 float rangenew = newHiX - newLoX;
887 assert(rangeold > -1e-5);
888 assert(rangenew > -1e-5);
889 if (fabs(rangeold) < 1e-5)
891 float newLoc = (newLoX + newHiX) / 2;
892 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
894 cellLoc[boxACellIds[ci]].X = newLoc;
899 float scale = rangenew / rangeold;
900 assert(scale > -1e-5);
901 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
903 cellLoc[boxACellIds[ci]].X = newLoX + (cellLoc[boxACellIds[ci]].X - oldLoX) * scale;
907 cellInBinTail = cellInBinHead - 1;
916 std::vector<int> &boxBCellIds = (*boxB)->
cellIds;
918 if (boxBCellIds.size() > 0)
920 int cellInBinHead = 0;
921 int cellInBinTail = 0;
924 for (
int binX = boxBLeft; binX <= boxBRight; binX++)
926 if ((
unsigned int)cellInBinHead >= boxBCellIds.size())
931 float oldLoX = cellLoc[boxBCellIds[cellInBinHead]].X;
932 float oldHiX = oldLoX;
934 for (cellInBinTail = cellInBinHead;
935 (
unsigned int)cellInBinTail < boxBCellIds.size() &&
936 (binX == boxBRight || (cArea / overallOverflowRatio <= colCapacity[binX - leftBinX] + eps));
940 oldHiX = cellLoc[boxBCellIds[cellInBinTail]].X;
945 assert(cellLoc[boxBCellIds[cellInBinTail]].
X <= oldHiX + 1e-5);
949 assert((
unsigned int)binX <
binGrid[bottomBinY].size());
952 float rangeold = oldHiX - oldLoX;
953 float rangenew = newHiX - newLoX;
954 assert(rangeold > -1e-5);
955 assert(rangenew > -1e-5);
956 if (fabs(rangeold) < 1e-5)
958 float newLoc = (newLoX + newHiX) / 2;
959 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
961 cellLoc[boxBCellIds[ci]].X = newLoc;
966 float scale = rangenew / rangeold;
967 assert(scale > -1e-5);
968 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
970 cellLoc[boxBCellIds[ci]].X = newLoX + (cellLoc[boxBCellIds[ci]].X - oldLoX) * scale;
974 cellInBinHead = cellInBinTail + 1;
989 if (cellIds.size() == 0)
992 if (cellIds.size() > 1)
993 quick_sort(cellIds, 0, cellIds.size() - 1,
false);
995 std::vector<float> colCapacity(topBinY - bottomBinY + 1, 0.0);
996 float totalCapacity = 0;
998 assert(leftBinX >= 0);
999 assert(bottomBinY >= 0);
1000 assert((
unsigned int)topBinY <
binGrid.size());
1001 assert((
unsigned int)rightBinX <
binGrid[topBinY].size());
1003 for (
int binY = bottomBinY; binY <= topBinY; binY++)
1005 for (
int binX = leftBinX; binX <= rightBinX; binX++)
1008 colCapacity[binY - bottomBinY] += binCapacity;
1009 totalCapacity += binCapacity;
1024 int boxABottom = bottomBinY;
1025 int boxBTop = topBinY;
1026 for (
int binY = bottomBinY; binY <= topBinY; binY++, boxABottom++)
1028 if (colCapacity[binY - bottomBinY] > 0)
1031 for (
int binY = topBinY; binY >= bottomBinY; binY--, boxBTop--)
1033 if (colCapacity[binY - bottomBinY] > 0)
1036 if (boxBTop <= boxABottom)
1039 assert(
false &&
"should not happen");
1053 int boxATop = boxABottom;
1054 int boxBBottom = boxBTop;
1055 float bottomCapacity = colCapacity[boxATop - bottomBinY];
1056 float topCapacity = colCapacity[boxBBottom - bottomBinY];
1057 while (boxATop < boxBBottom - 1)
1059 if (bottomCapacity <= topCapacity)
1062 bottomCapacity += colCapacity[boxATop - bottomBinY];
1067 topCapacity += colCapacity[boxBBottom - bottomBinY];
1083 float bottomUtilRatio = bottomCapacity / totalCapacity;
1084 float totalUtilization = 0;
1085 for (
auto cellId : cellIds)
1089 float bottomUtil = totalUtilization * bottomUtilRatio;
1091 int cutLineIdX = -1;
1092 if (bottomUtil > eps)
1094 for (
auto cellId : cellIds)
1098 if (bottomUtil <= eps)
1104 *boxA =
new SubBox(
this, boxATop, boxABottom, leftBinX, rightBinX, 0, cutLineIdX);
1105 *boxB =
new SubBox(
this, boxBTop, boxBBottom, leftBinX, rightBinX, cutLineIdX + 1, cellIds.size() - 1);
1108 float overallOverflowRatio = totalUtilization / totalCapacity;
1109 if (overallOverflowRatio < 1)
1110 overallOverflowRatio = 1;
1111 std::vector<int> &boxACellIds = (*boxA)->cellIds;
1113 if (boxACellIds.size() > 0)
1115 int cellInBinHead = boxACellIds.size() - 1;
1116 int cellInBinTail = boxACellIds.size() - 1;
1119 for (
int binY = boxATop; binY >= boxABottom; binY--)
1121 if (cellInBinTail < 0)
1125 float oriBottomY = cellLoc[boxACellIds[cellInBinTail]].Y;
1126 float oriTopY = oriBottomY;
1127 for (cellInBinHead = cellInBinTail;
1128 cellInBinHead >= 0 &&
1129 (binY == boxABottom || (cArea / overallOverflowRatio <= colCapacity[binY - bottomBinY] + eps));
1133 oriBottomY = cellLoc[boxACellIds[cellInBinHead]].Y;
1140 assert((
unsigned int)binY <
binGrid.size());
1143 assert(newTopY >= newBottomY);
1144 float rangeold = oriTopY - oriBottomY;
1145 float rangenew = newTopY - newBottomY;
1146 assert(rangeold > -1e-5);
1147 assert(rangenew > -1e-5);
1148 if (fabs(rangeold) < 1e-5)
1150 float newBottomc = (newBottomY + newTopY) / 2;
1151 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
1153 cellLoc[boxACellIds[ci]].Y = newBottomc;
1158 float scale = rangenew / rangeold;
1159 assert(scale > -1e-5);
1160 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
1162 cellLoc[boxACellIds[ci]].Y = newBottomY + (cellLoc[boxACellIds[ci]].Y - oriBottomY) * scale;
1166 cellInBinTail = cellInBinHead - 1;
1175 std::vector<int> &boxBCellIds = (*boxB)->
cellIds;
1177 if (boxBCellIds.size() > 0)
1179 int cellInBinHead = 0;
1180 int cellInBinTail = 0;
1183 for (
int binY = boxBBottom; binY <= boxBTop; binY++)
1185 if ((
unsigned int)cellInBinHead >= boxBCellIds.size())
1190 float oriBottomY = cellLoc[boxBCellIds[cellInBinHead]].Y;
1191 float oriTopY = oriBottomY;
1193 for (cellInBinTail = cellInBinHead;
1194 (
unsigned int)cellInBinTail < boxBCellIds.size() &&
1195 (binY == boxBTop || (cArea / overallOverflowRatio <= colCapacity[binY - bottomBinY] + eps));
1199 oriTopY = cellLoc[boxBCellIds[cellInBinTail]].Y;
1206 assert((
unsigned int)binY <
binGrid.size());
1209 float rangeold = oriTopY - oriBottomY;
1210 float rangenew = newTopY - newBottomY;
1211 assert(rangeold > -1e-5);
1212 assert(rangenew > -1e-5);
1213 if (fabs(rangeold) < 1e-5)
1215 float newBottomc = (newBottomY + newTopY) / 2;
1216 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
1218 cellLoc[boxBCellIds[ci]].Y = newBottomc;
1223 float scale = rangenew / rangeold;
1224 assert(scale > -1e-5);
1225 for (
int ci = cellInBinHead; ci <= cellInBinTail; ++ci)
1227 cellLoc[boxBCellIds[ci]].Y = newBottomY + (cellLoc[boxBCellIds[ci]].Y - oriBottomY) * scale;
1231 cellInBinHead = cellInBinTail + 1;
1245 time_t now = time(0);
1248 tstruct = *localtime(&now);
1251 strftime(buf,
sizeof(buf),
"%Y-%m-%d.%X", &tstruct);
1260 print_status(
"GeneralSpreader: dumping density to: " + dumpFileName);
1261 std::vector<std::vector<PlacementInfo::PlacementBinInfo *>> &curBinGrid =
1264 std::ofstream outfile0(dumpFileName.c_str());
1265 assert(outfile0.is_open() && outfile0.good() &&
1266 "The path for site density dumping does not exist and please check your path settings");
1267 for (
auto &row : curBinGrid)
1269 for (
auto curBin : row)
1271 outfile0 << curBin->getRealUtilizationRate() <<
" ";
1281 if (
JSONCfg.find(
"DumpLUTFFCoordTrace-GeneralSpreader") !=
JSONCfg.end())
1283 std::string dumpFile =
JSONCfg[
"DumpLUTFFCoordTrace-GeneralSpreader"] +
"-" +
sharedCellType +
"-" +
1285 print_status(
"GeneralSpreader: dumping coordinate archieve to: " + dumpFile);
1289 std::stringstream outfile0;
1294 float cellX = curUnpackedCell->X();
1295 float cellY = curUnpackedCell->Y();
1297 if (curCell->
isFF() || curCell->
isLUT())
1299 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
1304 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
1306 float offsetX_InMacro, offsetY_InMacro;
1308 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
1309 float cellX = curMacro->X() + offsetX_InMacro;
1310 float cellY = curMacro->Y() + offsetY_InMacro;
1314 if (curMacro->getCell(vId))
1315 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
1317 outfile0 << cellX <<
" " << cellY <<
"\n";
1323 print_status(
"GeneralSpreader: dumped coordinate archieve to: " + dumpFile);
1330 os <<
"Box: Top:" << curBox->
top() <<
" Bottom:" << curBox->
bottom() <<
" Left:" << curBox->
left()
1331 <<
" Right:" << curBox->
right();
1337 if (dumpFileName !=
"")
1340 dumpFileName = dumpFileName +
"-" + std::to_string(
dumpCnt) +
".gz";
1342 std::stringstream outfile0;
1344 for (
auto tmpCell : curRegion->
getCells())
1346 outfile0 << cellLoc[tmpCell->getCellId()].X <<
" " << cellLoc[tmpCell->getCellId()].Y << tmpCell <<
"\n";
1354 std::vector<PlacementInfo::PlacementUnit *> &involvedPUVec)
1356 if (dumpFileName !=
"")
1359 dumpFileName = dumpFileName +
"-" + std::to_string(
dumpCnt) +
".gz";
1361 std::stringstream outfile0;
1362 for (
auto curPU : involvedPUVec)
1364 outfile0 << curPU->X() <<
" " << curPU->Y() <<
" " << curPU <<
"\n";