AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
AMFPlacer.h
Go to the documentation of this file.
1 
13 #include "3rdParty/Rendering/paintDB.h"
14 #include "DesignInfo.h"
15 #include "DeviceInfo.h"
16 #include "GlobalPlacer.h"
17 #include "IncrementalBELPacker.h"
18 #include "InitialPacker.h"
19 #include "ParallelCLBPacker.h"
20 #include "PlacementInfo.h"
22 #include "utils/simpleJSON.h"
23 #include <boost/filesystem.hpp>
24 #include <iostream>
25 #include <omp.h>
26 
49 class AMFPlacer
50 {
51  public:
57  AMFPlacer(std::string JSONFileName, bool guiEnable)
58  {
59  JSON = parseJSONFile(JSONFileName);
60 
61  assert(JSON.find("vivado extracted device information file") != JSON.end());
62  assert(JSON.find("special pin offset info file") != JSON.end());
63  assert(JSON.find("vivado extracted design information file") != JSON.end());
64  assert(JSON.find("cellType2fixedAmo file") != JSON.end());
65  assert(JSON.find("cellType2sharedCellType file") != JSON.end());
66  assert(JSON.find("sharedCellType2BELtype file") != JSON.end());
67  assert(JSON.find("GlobalPlacementIteration") != JSON.end());
68  if (JSON.find("dumpDirectory") != JSON.end())
69  {
70  if (!fileExists(JSON["dumpDirectory"]))
71  assert(boost::filesystem::create_directories(JSON["dumpDirectory"]) &&
72  "the specified dump directory should be created successfully.");
73  }
74 
75  oriTime = std::chrono::steady_clock::now();
76 
77  omp_set_num_threads(std::stoi(JSON["jobs"]));
78  if (JSON.find("jobs") != JSON.end())
79  {
80  omp_set_num_threads(std::stoi(JSON["jobs"]));
81  }
82  else
83  {
84  omp_set_num_threads(1);
85  }
86 
87  // load device information
88  deviceinfo = new DeviceInfo(JSON, "VCU108");
90 
91  // load design information
94  paintData = new PaintDataBase();
95 
96  if (guiEnable)
97  JSON["guiEnable"] = "true";
98  };
99 
101  {
102  delete placementInfo;
103  delete designInfo;
104  delete deviceinfo;
106  delete incrementalBELPacker;
107  if (globalPlacer)
108  delete globalPlacer;
109  if (initialPacker)
110  delete initialPacker;
111  }
112 
114  {
115  for (auto PU : placementInfo->getPlacementUnits())
116  {
117  if (PU->isPacked())
118  PU->resetPacked();
119  }
120  for (auto pair : placementInfo->getPULegalXY().first)
121  {
122  if (pair.first->isFixed() && !pair.first->isLocked())
123  {
124  pair.first->setUnfixed();
125  }
126  }
127  }
128 
133  void run()
134  {
135  // initialize placement information, including how to map cells to BELs
138 
139  // we have to pack cells in design info into placement units in placement info with packer
141  initialPacker->pack();
143 
145  placementInfo->createGridBins(5.0, 5.0);
147 
150  int longPathThr = placementInfo->getLongPathThresholdLevel();
151  // int mediumPathThr = placementInfo->getMediumPathThresholdLevel();
152 
153  // go through several glable placement iterations to get initial placement
155 
156  // enable the timing optimization, start initial placement and global placement.
157 
159  timingOptimizer->clusterLongPathInOneClockRegion(longPathThr, 0.5);
161 
163 
164  globalPlacer->GlobalPlacement_CLBElements(std::stoi(JSON["GlobalPlacementIteration"]) / 3, false, 5, true, true,
165  200, timingOptimizer);
166  timingOptimizer->clusterLongPathInOneClockRegion(longPathThr, 0.5);
170  placementInfo->createGridBins(2.5, 2.5);
172  // globalPlacer->spreading(-1);
173  globalPlacer->GlobalPlacement_CLBElements(std::stoi(JSON["GlobalPlacementIteration"]) * 2 / 9, true, 5, true,
174  true, 200, timingOptimizer);
176  print_info("Current Total HPWL = " + std::to_string(placementInfo->updateB2BAndGetTotalHPWL()));
177 
178  // pack simple LUT-FF pairs and go through several global placement iterations
183  print_info("Current Total HPWL = " + std::to_string(placementInfo->updateB2BAndGetTotalHPWL()));
184 
185  timingOptimizer->clusterLongPathInOneClockRegion(longPathThr, 0.5);
186 
191 
192  globalPlacer->GlobalPlacement_CLBElements(std::stoi(JSON["GlobalPlacementIteration"]) * 2 / 9, true, 5, true,
193  true, 25, timingOptimizer);
194  // placementInfo->getPU2ClockRegionCenters().clear();
195 
201  // placementInfo->getDesignInfo()->resetNetEnhanceRatio();
202  // timingOptimizer->enhanceNetWeight_LevelBased(mediumPathThr);
204 
205  // timingOptimizer->moveDriverIntoBetterClockRegion(longPathThr, 0.75);
206  globalPlacer->GlobalPlacement_CLBElements(std::stoi(JSON["GlobalPlacementIteration"]) * 2 / 9, true, 5, true,
207  true, 25, timingOptimizer);
208  JSON["SpreaderSimpleExpland"] = "true";
209  // placementInfo->getPU2ClockRegionCenters().clear();
210  globalPlacer->GlobalPlacement_CLBElements(std::stoi(JSON["GlobalPlacementIteration"]) / 2, true, 5, true, false,
211  25, timingOptimizer);
212 
213  // // currently, some fixed/packed flag cannot be stored in the check-point (TODO)
214  // clearSomeAttributesCannotRecord();
215 
216  // // test the check-point mechanism
217  // placementInfo->dumpPlacementUnitInformation(JSON["dumpDirectory"] + "/PUInfoBeforeFinalPacking");
218  // placementInfo->loadPlacementUnitInformation(JSON["dumpDirectory"] + "/PUInfoBeforeFinalPacking.gz");
219  // print_info("Current Total HPWL = " + std::to_string(placementInfo->updateB2BAndGetTotalHPWL()));
220 
221  timingOptimizer->conductStaticTimingAnalysis();
222  // finally pack the elements into sites on the FPGA device
224  new ParallelCLBPacker(designInfo, deviceinfo, placementInfo, JSON, 3, 10, 0.25, 0.5, 6, 10, 0.02, "first",
225  timingOptimizer, globalPlacer->getWirelengthOptimizer());
226  parallelCLBPacker->packCLBs(30, true);
228  timingOptimizer->conductStaticTimingAnalysis();
230  print_info("Current Total HPWL = " + std::to_string(placementInfo->updateB2BAndGetTotalHPWL()));
235  placementInfo->dumpCongestion(JSON["dumpDirectory"] + "/congestionInfo");
236 
237  if (parallelCLBPacker)
238  delete parallelCLBPacker;
239 
240  // currently, some fixed/packed flag cannot be stored in the check-point (TODO)
242  placementInfo->dumpPlacementUnitInformation(JSON["dumpDirectory"] + "/PUInfoFinal");
244 
245  print_status("Placement Done");
246  print_info("Current Total HPWL = " + std::to_string(placementInfo->updateB2BAndGetTotalHPWL()));
247 
248  // auto nowTime = std::chrono::steady_clock::now();
249  // auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(nowTime - oriTime).count();
250 
251  return;
252  }
253 
254  PaintDataBase *paintData = nullptr;
255 
256  private:
261  DeviceInfo *deviceinfo = nullptr;
262 
267  DesignInfo *designInfo = nullptr;
268 
274 
280 
286 
292 
298 
303  std::map<std::string, std::string> JSON;
304 };
PlacementInfo::buildSimpleTimingGraph
void buildSimpleTimingGraph()
call timing info to build simple timing graph
Definition: PlacementInfo.h:4331
DesignInfo::printStat
void printStat(bool verbose=false)
Definition: DesignInfo.cc:635
GlobalPlacer::getWirelengthOptimizer
WirelengthOptimizer * getWirelengthOptimizer()
Definition: GlobalPlacer.h:207
InitialPacker
InitialPacker will identify macros from the design netlist based on pattern matching.
Definition: InitialPacker.h:51
AMFPlacer::deviceinfo
DeviceInfo * deviceinfo
information related to the device (BELs, Sites, Tiles, Clock Regions)
Definition: AMFPlacer.h:261
PlacementInfo::getPlacementUnits
std::vector< PlacementUnit * > & getPlacementUnits()
Definition: PlacementInfo.h:2810
AMFPlacer::globalPlacer
GlobalPlacer * globalPlacer
global placer acconting for initial placement, quadratic placement, cell spreading and macro legaliza...
Definition: AMFPlacer.h:291
PlacementTimingOptimizer.h
PlacementTimingOptimizer::clusterLongPathInOneClockRegion
void clusterLongPathInOneClockRegion(int pathLenThr, float clusterThrRatio)
Definition: PlacementTimingOptimizer.cc:526
PlacementInfo::dumpCongestion
void dumpCongestion(std::string dumpFileName)
dump the congestion mesh grid for evaluation
Definition: PlacementInfo.cc:1562
IncrementalBELPacker::LUTFFPairing
void LUTFFPairing(float disThreshold)
try to pair LUTs/FFs in the design netlist which are neighbors according to a given threshold and con...
Definition: IncrementalBELPacker.cc:44
PlacementInfo::setPaintDataBase
void setPaintDataBase(PaintDataBase *_paintData)
Definition: PlacementInfo.h:4423
GlobalPlacer::setPseudoNetWeight
void setPseudoNetWeight(float weight)
Set the initial pseudo net weight for the global placer.
Definition: GlobalPlacer.h:127
PlacementInfo::getLongPathThresholdLevel
int getLongPathThresholdLevel()
Definition: PlacementInfo.h:4358
ParallelCLBPacker.h
This header file contains the definitions of ParallelCLBPacker class and its internal modules and API...
AMFPlacer
AMFPlacer is an analytical mixed-size FPGA placer.
Definition: AMFPlacer.h:50
AMFPlacer::placementInfo
PlacementInfo * placementInfo
inforamtion related to placement (locations, interconnections, status, constraints,...
Definition: AMFPlacer.h:273
fileExists
bool fileExists(const std::string &filename)
Definition: dumpZip.cc:45
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
GlobalPlacer.h
This header file contains the definitions of GlobalPlacer class and its internal modules and APIs whi...
PlacementInfo::printStat
void printStat(bool verbose=false)
Definition: PlacementInfo.cc:294
PlacementInfo::updateB2BAndGetTotalHPWL
double updateB2BAndGetTotalHPWL()
update the B2B net model for the placement and get the total HPWL of all the nets in the design
Definition: PlacementInfo.h:3913
AMFPlacer::JSON
std::map< std::string, std::string > JSON
the user-defined settings of placement
Definition: AMFPlacer.h:303
PlacementTimingOptimizer
Definition: PlacementTimingOptimizer.h:46
DesignInfo.h
This header file contains the classes of data for a standalone design netlist.
IncrementalBELPacker
IncrementalBELPacker incrementally packs some LUTs/FFs during global placement based on their distanc...
Definition: IncrementalBELPacker.h:50
DeviceInfo.h
This header file contains the classes of data for a standalone device.
parseJSONFile
std::map< std::string, std::string > parseJSONFile(std::string JSONFileName)
Definition: simpleJSON.h:49
InitialPacker.h
This header file contains the definitions of InitialPacker class and its internal modules and APIs wh...
AMFPlacer::initialPacker
InitialPacker * initialPacker
initially packing for macro extraction based on pre-defined rules
Definition: AMFPlacer.h:279
GlobalPlacer::setNeighborDisplacementUpperbound
void setNeighborDisplacementUpperbound(float _threshold)
Set the distance upperbound of neighbor LUT/FF-like elements for area adjustion.
Definition: GlobalPlacer.h:191
DeviceInfo::printStat
void printStat(bool verbose=false)
Definition: DeviceInfo.cc:466
simpleJSON.h
AMFPlacer::clearSomeAttributesCannotRecord
void clearSomeAttributesCannotRecord()
Definition: AMFPlacer.h:113
AMFPlacer::paintData
PaintDataBase * paintData
Definition: AMFPlacer.h:254
GlobalPlacer::getMacroPseudoNetEnhanceCnt
int getMacroPseudoNetEnhanceCnt()
Get the number of macro pseudo net enhancements.
Definition: GlobalPlacer.h:151
print_status
void print_status(std::string tmp_string)
Definition: strPrint.cc:44
PlacementInfo::verifyDeviceForDesign
void verifyDeviceForDesign()
verify that each cells in the design can be mapped on the resource elements on the device.
Definition: PlacementInfo.cc:790
AMFPlacer::incrementalBELPacker
IncrementalBELPacker * incrementalBELPacker
incremental pairing of some FFs and LUTs into small macros
Definition: AMFPlacer.h:285
InitialPacker::pack
void pack()
extract the macros from the netlist to construction PlacmentMacro
Definition: InitialPacker.cc:28
AMFPlacer::AMFPlacer
AMFPlacer(std::string JSONFileName, bool guiEnable)
Construct a new AMFPlacer object according to a given placer configuration file.
Definition: AMFPlacer.h:57
ParallelCLBPacker::packCLBs
void packCLBs(int packIterNum, bool doExceptionHandling, bool debug=false)
packing the PlacementUnits (which are compatible to CLB sites) into CLB sites
Definition: ParallelCLBPacker.cc:288
ParallelCLBPacker::updatePackedMacro
void updatePackedMacro(bool setPUPseudoNetToCLBSite=false, bool setCLBFixed=false)
Update the macros in PlacementInfo by regarding those elements in one CLB site as a macro.
Definition: ParallelCLBPacker.cc:2562
PlacementInfo::resetLUTFFDeterminedOccupation
void resetLUTFFDeterminedOccupation()
reset the LUTFFDeterminedOccupation object
Definition: PlacementInfo.h:4087
PlacementInfo::getTimingInfo
PlacementTimingInfo * getTimingInfo()
Definition: PlacementInfo.h:3313
PlacementInfo::dumpOverflowClockUtilization
void dumpOverflowClockUtilization()
Definition: PlacementInfo.cc:2163
GlobalPlacer::GlobalPlacement_CLBElements
void GlobalPlacement_CLBElements(int iterNum, bool continuePreviousIteration=false, int lowerBoundIterNum=6, bool enableMacroPseudoNet2Site=false, bool stopStrictly=false, unsigned int spreadRegionBinNumLimit=10000000, PlacementTimingOptimizer *timingOptimizer=nullptr)
wirelength optimization + cell spreading + legalization + area adjustion
Definition: GlobalPlacer.cc:128
GlobalPlacer::GlobalPlacement_fixedCLB
void GlobalPlacement_fixedCLB(int iterNum, float pseudoNetWeight)
fix the locations of CLB and let macros move without low pseudo net at initial stages,...
Definition: GlobalPlacer.cc:334
IncrementalBELPacker.h
This header file contains the definitions of IncrementalBELPacker class and its internal modules and ...
PlacementInfo::checkClockUtilization
bool checkClockUtilization(bool dump)
check the utlization of the clock regions on the device
Definition: PlacementInfo.cc:2087
PlacementTimingOptimizer::conductStaticTimingAnalysis
float conductStaticTimingAnalysis(bool enforeOptimisticTiming=false)
Definition: PlacementTimingOptimizer.cc:218
DeviceInfo
Information class related to FPGA device, including the details of BEL/Site/Tile/ClockRegion.
Definition: DeviceInfo.h:43
PlacementInfo::dumpPlacementUnitInformation
void dumpPlacementUnitInformation(std::string dumpFile)
dump the PlacementUnit objects and some placement parameters as a checkpoint
Definition: PlacementInfo.cc:1723
GlobalPlacer
GlobalPlacer accounts for the general iterations in global placement.
Definition: GlobalPlacer.h:60
AMFPlacer::designInfo
DesignInfo * designInfo
information related to the design (cells, pins and nets)
Definition: AMFPlacer.h:267
GlobalPlacer::clusterPlacement
void clusterPlacement()
cluster elements and conduct initial placement at coarse-grained level
Definition: GlobalPlacer.cc:122
print_info
void print_info(std::string tmp_string)
Definition: strPrint.cc:39
GlobalPlacer::setMacroLegalizationParameters
void setMacroLegalizationParameters(int cnt, float macroLegalizationWeight)
Set the macro legalization parameters (including legalization counter and pseudo net weight)
Definition: GlobalPlacer.h:172
oriTime
std::chrono::time_point< std::chrono::steady_clock > oriTime
Definition: strPrint.cc:32
ParallelCLBPacker
ParallelCLBPacker will finally pack LUT/FF/MUX/CARRY elements into legal CLB sites in a parallel appr...
Definition: ParallelCLBPacker.h:94
AMFPlacer::run
void run()
launch the analytical mixed-size FPGA placement procedure
Definition: AMFPlacer.h:133
GlobalPlacer::getPseudoNetWeight
float getPseudoNetWeight()
Get the current pseudo net weight.
Definition: GlobalPlacer.h:139
GlobalPlacer::getMacroLegalizationWeight
float getMacroLegalizationWeight()
Get the current macro legalization weight object.
Definition: GlobalPlacer.h:161
AMFPlacer::parallelCLBPacker
ParallelCLBPacker * parallelCLBPacker
final packing of instances into CLB sites
Definition: AMFPlacer.h:297
PlacementInfo::adjustLUTFFUtilization
void adjustLUTFFUtilization(float neighborDisplacementUpperbound, bool enfore=false)
adjust the resource demand of LUTs/FFs according to packing feasibility and routing congestion
Definition: PlacementInfo.cc:1544
PlacementInfo::getPU2ClockRegionCenters
std::map< PlacementUnit *, std::pair< float, float > > & getPU2ClockRegionCenters()
get the PlacementUnit Mapping to clock region centers for timing optimzation
Definition: PlacementInfo.h:4343
PlacementInfo.h
This header file mainly contains the definition of class PlacementInfo, including information related...
PlacementTimingInfo::setDSPInnerDelay
void setDSPInnerDelay()
Definition: PlacementTimingInfo.cc:74
ParallelCLBPacker::setPULocationToPackedSite
void setPULocationToPackedSite()
update the location of PlacementUnits according to the packing result
Definition: ParallelCLBPacker.cc:2518
IncrementalBELPacker::FFPairing
void FFPairing(float disThreshold)
try to pair FFs in the design netlist which are neighbors according to a given threshold and the cont...
Definition: IncrementalBELPacker.cc:253
DesignInfo
Information related to FPGA designs, including design cells and their interconnections.
Definition: DesignInfo.h:51
AMFPlacer::~AMFPlacer
~AMFPlacer()
Definition: AMFPlacer.h:100
PlacementInfo::createGridBins
void createGridBins(float binWidth, float binHeight)
Create a grid of bins on the device.
Definition: PlacementInfo.cc:325
PlacementInfo
Information related to FPGA placement (wirelength optimization, cell spreading, legalization,...
Definition: PlacementInfo.h:59