32 bool resetLegalizationInfo)
33 : placementInfo(placementInfo), JSONCfg(JSONCfg)
44 if (
JSONCfg.find(
"disableSpreadingConvergeRatio") !=
JSONCfg.end())
53 print_warning(
"Direct Macro Legalization is enbaled. It might undermine the HPWL.");
73 std::vector<DesignInfo::DesignCellType> macroTypesToLegalize;
74 macroTypesToLegalize.clear();
82 macroTypesToLegalize.clear();
87 std::vector<std::string> lclbTypeList(1,
"SLICEL");
91 std::vector<std::string> mclbTypeList(1,
"SLICEM");
95 if (resetLegalizationInfo)
98 if (
JSONCfg.find(
"pseudoNetWeightConsiderNetNum") !=
JSONCfg.end())
109 print_warning(
"pseudoNetWeightConsiderNetNum option is turn on: " +
114 print_warning(
"pseudoNetWeightConsiderNetNum option is turn off: " +
129 bool enableMacroPseudoNet2Site,
bool stopStrictly,
130 unsigned int spreadRegionBinNumLimit,
133 print_status(
"GlobalPlacer GlobalPlacement_CLBElements started");
137 tmpNet->setOverallTimingNetEnhancement(1.0);
166 int iterCntAfterMacrosFixed = 0;
169 for (
int i = 0;
i < iterNum || (!stopStrictly);
i++)
172 float displacementLimit = -10;
176 displacementLimit = 10;
193 for (
int j = 0; j < lowerBoundIterNum; j++)
214 spreading(
i, spreadRegionBinNumLimit, displacementLimit);
225 if (enableMacroPseudoNet2Site)
227 bool timingDrivenLegalization =
false;
231 timingDrivenLegalization =
true;
257 if (minHPWL < placementInfo->getMinHPWL())
269 " and minHPWL is updated to be: " + std::to_string(
upperBoundHPWL));
286 print_info(
"clockLegal=" + std::to_string(clockLegal));
294 bool criteria2 = upperBoundHPWL < minHPWL * 2 && macroLegalizationFixed && i > 30;
300 iterCntAfterMacrosFixed++;
302 if (criteria3 || criteria4)
316 print_status(
"Global Placer: Should do packing now before further optimization");
336 print_status(
"GlobalPlacer GlobalPlacement_fixedCLB started");
340 int lowerBoundIterNum = 6;
343 if (!curCell->isLUT() && !curCell->isFF())
348 if (curPU->isLocked())
353 for (
int i = 0;
i < iterNum;
i++)
355 for (
int j = 0; j < lowerBoundIterNum; j++)
362 print_status(
"WLOptimizer Iteration#" + std::to_string(
i) +
" Done");
372 if (!curCell->isLUT() && !curCell->isFF())
377 if (curPU->isLocked())
403 if (curPU->isPlaced())
415 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
419 std::stringstream outfile0;
424 float cellX = curUnpackedCell->X();
425 float cellY = curUnpackedCell->Y();
427 if (curCell->
isLUT())
429 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
434 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
436 float offsetX_InMacro, offsetY_InMacro;
438 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
439 float cellX = curMacro->X() + offsetX_InMacro;
440 float cellY = curMacro->Y() + offsetY_InMacro;
444 if (curMacro->getCell(vId))
445 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
447 outfile0 << cellX <<
" " << cellY <<
"\n";
453 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
482 print_info(
"DSPBRAM Average Displacement Of Rough Legalization =" +
498 print_info(
"DSPBRAM Average Displacement Of Exact Legalization =" +
501 print_info(
"CARRY Average Displacement Of Exact Legalization =" +
517 print_warning(
"too many times of legalization. enforce the elements to be fixed!");
521 auto curPU = pair.first;
562 auto curPU = pair.first;
571 auto curPU = pair.first;
585 auto curPU = pair.first;
607 if (std::sqrt(err / 3) < 0.01)
625 std::string sharedCellType_SLICEL_CARRY8 =
"SLICEL_CARRY8";
632 std::string sharedCellType_SLICEL_MUXF8 =
"SLICEL_MUXF8";
638 std::string sharedCellType_SLICEL_MUXF7 =
"SLICEL_MUXF7";
647 std::string sharedCellType_SLICEL_LUT =
"SLICEL_LUT";
653 std::string sharedCellType_SLICEL_FF =
"SLICEL_FF";
692 print_warning(
"GlobalPlacer: clock region aware optimization is enabled.");
708 for (
int vecId = numRecorded - 5; vecId < numRecorded; vecId++)
725 "GlobalPlacer: The upperbound HPWL increases too much, pseudoNetWeight is reduced by 50% to recover.");
730 err = std::sqrt(err / 5);
731 print_info(
"GlobalPlacer: err=" + std::to_string(err) +
" minHPWL=" + std::to_string(
minHPWL) +
732 " err/minHPWL=" + std::to_string(err /
minHPWL) +
" progressRatio=" + std::to_string(
progressRatio));
737 if (err / minHPWL < 1.0 / 100.0 && progressRatio > 0.85 &&
751 "GlobalPlacer: The upperbound HPWL increases too much, pseudoNetWeight is reduced by 50% to recover.");
773 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
777 std::stringstream outfile0;
782 float cellX = curUnpackedCell->X();
783 float cellY = curUnpackedCell->Y();
787 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
792 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
794 float offsetX_InMacro, offsetY_InMacro;
796 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
797 float cellX = curMacro->X() + offsetX_InMacro;
798 float cellY = curMacro->Y() + offsetY_InMacro;
802 if (curMacro->getCell(vId))
803 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
805 outfile0 << cellX <<
" " << cellY <<
"\n";
811 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
821 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
825 std::stringstream outfile0;
830 float cellX = curUnpackedCell->X();
831 float cellY = curUnpackedCell->Y();
835 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
840 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
842 float offsetX_InMacro, offsetY_InMacro;
844 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
845 float cellX = curMacro->X() + offsetX_InMacro;
846 float cellY = curMacro->Y() + offsetY_InMacro;
850 if (curMacro->getCell(vId))
851 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
853 outfile0 << cellX <<
" " << cellY <<
"\n";
859 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
869 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
873 std::stringstream outfile0;
878 float cellX = curUnpackedCell->X();
879 float cellY = curUnpackedCell->Y();
881 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
885 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
887 float offsetX_InMacro, offsetY_InMacro;
889 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
890 float cellX = curMacro->X() + offsetX_InMacro;
891 float cellY = curMacro->Y() + offsetY_InMacro;
893 if (curMacro->getCell(vId))
894 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
896 outfile0 << cellX <<
" " << cellY <<
"\n";
901 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
912 std::string dumpFile =
914 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
918 std::stringstream outfile0;
923 float cellX = curUnpackedCell->X();
924 float cellY = curUnpackedCell->Y();
928 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
933 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
935 float offsetX_InMacro, offsetY_InMacro;
937 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
938 float cellX = curMacro->X() + offsetX_InMacro;
939 float cellY = curMacro->Y() + offsetY_InMacro;
943 if (curMacro->getCell(vId))
944 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName()
947 outfile0 << cellX <<
" " << cellY <<
"\n";
953 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
959 std::string dumpFile =
961 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
965 std::stringstream outfile0;
970 float cellX = curUnpackedCell->X();
971 float cellY = curUnpackedCell->Y();
975 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
980 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
982 float offsetX_InMacro, offsetY_InMacro;
984 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
985 float cellX = curMacro->X() + offsetX_InMacro;
986 float cellY = curMacro->Y() + offsetY_InMacro;
990 if (curMacro->getCell(vId))
991 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
993 outfile0 << cellX <<
" " << cellY <<
"\n";
999 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
1011 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
1015 std::stringstream outfile0;
1020 float cellX = curUnpackedCell->X();
1021 float cellY = curUnpackedCell->Y();
1023 if (curCell->
isDSP())
1025 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
1030 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
1032 float offsetX_InMacro, offsetY_InMacro;
1034 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
1035 float cellX = curMacro->X() + offsetX_InMacro;
1036 float cellY = curMacro->Y() + offsetY_InMacro;
1040 if (curMacro->getCell(vId))
1041 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName()
1044 outfile0 << cellX <<
" " << cellY <<
"\n";
1050 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
1057 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
1061 std::stringstream outfile0;
1066 float cellX = curUnpackedCell->X();
1067 float cellY = curUnpackedCell->Y();
1069 if (curCell->
isDSP())
1071 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
1076 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
1078 float offsetX_InMacro, offsetY_InMacro;
1080 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
1081 float cellX = curMacro->X() + offsetX_InMacro;
1082 float cellY = curMacro->Y() + offsetY_InMacro;
1086 if (curMacro->getCell(vId))
1087 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
1089 outfile0 << cellX <<
" " << cellY <<
"\n";
1095 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
1107 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
1111 std::stringstream outfile0;
1116 float cellX = curUnpackedCell->X();
1117 float cellY = curUnpackedCell->Y();
1121 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
1126 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
1128 float offsetX_InMacro, offsetY_InMacro;
1130 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
1131 float cellX = curMacro->X() + offsetX_InMacro;
1132 float cellY = curMacro->Y() + offsetY_InMacro;
1136 if (curMacro->getCell(vId))
1137 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName()
1140 outfile0 << cellX <<
" " << cellY <<
"\n";
1146 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
1153 print_status(
"GlobalPlacer: dumping coordinate archieve to: " + dumpFile);
1157 std::stringstream outfile0;
1162 float cellX = curUnpackedCell->X();
1163 float cellY = curUnpackedCell->Y();
1167 outfile0 << cellX <<
" " << cellY <<
" " << curCell->
getName() <<
"\n";
1172 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
1174 float offsetX_InMacro, offsetY_InMacro;
1176 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
1177 float cellX = curMacro->X() + offsetX_InMacro;
1178 float cellY = curMacro->Y() + offsetY_InMacro;
1182 if (curMacro->getCell(vId))
1183 outfile0 << cellX <<
" " << cellY <<
" " << curMacro->getCell(vId)->getName() <<
"\n";
1185 outfile0 << cellX <<
" " << cellY <<
"\n";
1191 print_status(
"GlobalPlacer: dumped coordinate archieve to: " + dumpFile);
1199 print_status(
"ParallelCLBPacker: conducting timing-driven detailed placement based on shortest path.");
1201 std::set<PlacementInfo::PlacementUnit *> PUsTouched;
1206 for (
auto oriCellIdsInCriticalPath : oriCellIdsInCriticalPaths)
1208 std::map<int, std::vector<PlacementInfo::Location>> cellId2CandidateLocation;
1209 cellId2CandidateLocation.clear();
1211 std::vector<int> cellIdsInCriticalPath;
1213 std::set<PlacementInfo::PlacementUnit *> PUsInCriticalPathSet;
1214 for (
auto cellId : oriCellIdsInCriticalPath)
1217 PUsInCriticalPathSet.end())
1220 cellIdsInCriticalPath.push_back(cellId);
1224 bool CellUnmapped =
false;
1225 for (
auto cellId : cellIdsInCriticalPath)
1229 cellId2CandidateLocation[cellId] = std::vector<PlacementInfo::Location>(1, cellLoc[cellId]);
1232 for (
int orderI = cellIdsInCriticalPath.size() - 1; orderI >= 0; orderI--)
1234 auto cellId = cellIdsInCriticalPath[orderI];
1237 if (PUsTouched.find(curPU) != PUsTouched.end())
1242 if (!curPU->isFixed() && !curPU->isLocked() && !curPU->checkHasLUTRAM() && !curPU->checkHasBRAM() &&
1243 !curPU->checkHasDSP())
1245 float tmpRange = range;
1246 if (curPU->checkHasCARRY())
1248 if (curPU->getCARRYNum() <= 2)
1253 auto curX = cellLoc[cellId].X;
1254 auto curY = cellLoc[cellId].Y;
1255 for (
float cX = curX - 1.0 * tmpRange; cX < curX + 1.1 * tmpRange; cX += 0.5 * tmpRange)
1257 for (
float cY = curY - 2.0 * tmpRange; cY < curY + 2.1 * tmpRange; cY += 1 * tmpRange)
1259 if (std::fabs(cX - curX) + std::fabs(cY - curY) < 0.1)
1264 cellId2CandidateLocation[cellId].push_back(newLoc);
1269 for (
int orderI = cellIdsInCriticalPath.size() - 1; orderI >= 0; orderI--)
1271 auto cellId = cellIdsInCriticalPath[orderI];
1273 PUsTouched.insert(curPU);
1276 std::vector<std::vector<float>> shortestPath_LayerSite;
1277 std::vector<std::vector<int>> shortestPath_LayerSite_backtrace;
1278 shortestPath_LayerSite.push_back(
1279 std::vector<float>(cellId2CandidateLocation[cellIdsInCriticalPath[0]].size(), 0.0));
1280 shortestPath_LayerSite_backtrace.push_back(
1281 std::vector<int>(cellId2CandidateLocation[cellIdsInCriticalPath[0]].size(), -1));
1283 int bestEndChoice = -1;
1284 float bestChoiceDelay = 100000;
1286 for (
int i = 1;
i < cellIdsInCriticalPath.size();
i++)
1288 auto predCell = cellIdsInCriticalPath[
i - 1];
1289 auto curCell = cellIdsInCriticalPath[
i];
1290 auto &predCandidates = cellId2CandidateLocation[predCell];
1291 auto &curCandidates = cellId2CandidateLocation[curCell];
1292 shortestPath_LayerSite.push_back(std::vector<float>(cellId2CandidateLocation[curCell].size(), 100000.0));
1293 shortestPath_LayerSite_backtrace.push_back(std::vector<int>(cellId2CandidateLocation[curCell].size(), -1));
1295 for (
int j = 0; j < predCandidates.size(); j++)
1297 for (
int k = 0; k < curCandidates.size(); k++)
1299 float predX = predCandidates[j].
X, predY = predCandidates[j].Y;
1300 float curX = curCandidates[k].X, curY = curCandidates[k].Y;
1304 if (shortestPath_LayerSite[
i][k] > shortestPath_LayerSite[
i - 1][j] +
delay)
1306 shortestPath_LayerSite[
i][k] = shortestPath_LayerSite[
i - 1][j] +
delay;
1307 shortestPath_LayerSite_backtrace[
i][k] = j;
1309 if (
i == cellIdsInCriticalPath.size() - 1)
1311 if (shortestPath_LayerSite[
i][k] < bestChoiceDelay)
1313 bestChoiceDelay = shortestPath_LayerSite[
i][k];
1322 for (
int i = shortestPath_LayerSite.size() - 1;
i >= 0;
i--)
1326 auto curCellId = cellIdsInCriticalPath[
i];
1330 auto &curCandidates = cellId2CandidateLocation[curCellId];
1331 if (!curPU->isFixed() && !curPU->isLocked() && !curPU->checkHasLUTRAM() && !curPU->checkHasBRAM() &&
1332 !curPU->checkHasDSP())
1336 float offsetX_InMacro = curMacro->getCellOffsetXInMacro(curCell),
1337 offsetY_InMacro = curMacro->getCellOffsetYInMacro(curCell);
1339 float resX = curCandidates[bestEndChoice].X - offsetX_InMacro;
1340 float resY = curCandidates[bestEndChoice].Y - offsetY_InMacro;
1343 curPU->setAnchorLocationAndForgetTheOriginalOne(resX, resY);
1344 for (
int vId = 0; vId < curMacro->getNumOfCells(); vId++)
1347 float offsetX_InMacro, offsetY_InMacro;
1348 curMacro->getVirtualCellInfo(vId, offsetX_InMacro, offsetY_InMacro, cellType);
1351 float cellX = curMacro->X() + offsetX_InMacro;
1352 float cellY = curMacro->Y() + offsetY_InMacro;
1354 cellLoc[curCellInMacro->
getCellId()].X = cellX;
1355 cellLoc[curCellInMacro->
getCellId()].Y = cellY;
1361 curCandidates[bestEndChoice].
Y);
1362 curPU->setAnchorLocationAndForgetTheOriginalOne(curCandidates[bestEndChoice].
X,
1363 curCandidates[bestEndChoice].
Y);
1364 cellLoc[unpacked->getCell()->getCellId()].X = curCandidates[bestEndChoice].X;
1365 cellLoc[unpacked->getCell()->getCellId()].Y = curCandidates[bestEndChoice].Y;
1370 bestEndChoice = shortestPath_LayerSite_backtrace[
i][bestEndChoice];
1375 print_status(
"ParallelCLBPacker: conducted timing-driven detailed placement (shortest path) and " +
1376 std::to_string(replaceCnt) +
" PlacementUnits are replaced.");