AMF-Placer  2.0
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
ClusterPlacer.h
Go to the documentation of this file.
1 
27 #ifndef _CLUSTERPLACER
28 #define _CLUSTERPLACER
29 
30 #include "DesignInfo.h"
31 #include "DeviceInfo.h"
32 #include "GraphPartitioner.h"
33 #include "PlacementInfo.h"
34 #include "SAPlacer.h"
35 #include "sysInfo.h"
36 #include <assert.h>
37 #include <fstream>
38 #include <iostream>
39 #include <map>
40 #include <mutex>
41 #include <semaphore.h>
42 #include <set>
43 #include <sstream>
44 #include <string>
45 #include <thread>
46 #include <vector>
47 
54 {
55  public:
63  ClusterPlacer(PlacementInfo *placementInfo, std::map<std::string, std::string> &JSONCfg,
64  float connectionToFixedFactor = 5.0);
66  {
67  if (saPlacer)
68  delete saPlacer;
70  delete basicGraphPartitioner;
73  for (auto tmpClusterUnit : clusterUnits)
74  {
75  delete tmpClusterUnit;
76  }
77  for (auto tmpClusterNet : clusterNets)
78  {
79  delete tmpClusterNet;
80  }
81  }
82 
88  void ClusterPlacement();
89 
90  private:
96 
103  std::vector<std::set<int>> clusters;
104  std::map<std::string, std::string> &JSONCfg;
105 
111 
116  float y2xRatio = 1.0;
117  bool verbose;
118 
120 
126 
131  double maxMinCutRate = 0.0333;
132 
137  std::vector<std::pair<int, int>> cluster2XY;
138 
143  std::vector<std::pair<float, float>> cluster2FP_XY;
144 
145  // the cluster-level netlist information
146 
147  std::vector<std::vector<float>> clusterAdjMat;
148  std::vector<float> clusterCLBCellWeights;
149  std::vector<float> clusterDSPCellWeights;
150  std::vector<float> clusterBRAMCellWeights;
151 
152  std::vector<std::vector<float>> cluster2FixedUnitMat;
153  std::vector<float> fixedX;
154  std::vector<float> fixedY;
155 
156  std::vector<int> placementUnit2ClusterId;
157 
159  std::vector<PlacementInfo::ClusterUnit *> clusterUnits;
160  std::vector<PlacementInfo::ClusterNet *> clusterNets;
161 
163 
168  int jobs;
169 
177  SAPlacer *saPlacer = nullptr;
178 
184  GraphPartitioner<std::vector<PlacementInfo::PlacementUnit *>, std::vector<PlacementInfo::PlacementNet *>>
186 
192  GraphPartitioner<std::vector<PlacementInfo::ClusterUnit *>, std::vector<PlacementInfo::ClusterNet *>>
194 
200  GraphPartitioner<std::vector<PlacementInfo::ClusterUnit *>, std::vector<PlacementInfo::ClusterNet *>>
202 
203  inline bool isDensePlacement()
204  {
205  return ((float)clusters.size() / (float)placementInfo->getDeviceInfo()->getClockRegionNumX() /
206  (float)placementInfo->getDeviceInfo()->getClockRegionNumY()) > 0.6;
207  }
208 
215  {
216  placementUnitId2ClusterUnitId = std::vector<int>(placementInfo->getPlacementUnits().size(), -1);
217  clusterUnits.clear();
218  clusterNets.clear();
219  }
220 
226  {
227  // create the nets between the cluster units
228  for (auto tmpNet : placementInfo->getPlacementNets())
229  {
231  clusterNets.push_back(curClusterNet);
232  for (auto tmpPU : tmpNet->getUnits())
233  {
234  curClusterNet->addClusterUnit(clusterUnits[placementUnitId2ClusterUnitId[tmpPU->getId()]]);
235  }
236  }
237 
238  print_info("ClusterPlacer: #clusterNet=" + std::to_string(clusterNets.size()));
239  }
240 
245  void setClusterNetsAdjMat();
246 
251  void hypergraphPartitioning();
252 
260  void basicPartitioning(int minClusterCellNum, int eachClusterDSPNum, int eachClusterBRAMNum);
261 
269  void clockBasedPartitioning(int minClusterCellNum, int eachClusterDSPNum, int eachClusterBRAMNum);
270 
279  void userDefinedClusterBasedPartitioning(int minClusterCellNum, int eachClusterDSPNum, int eachClusterBRAMNum);
280 
286 
292 
298 
304 
312 
317  void clusterPlacementUnits();
318 
323  void placeClusters();
324 
330  void placeUnitBaseOnClusterPlacement(const std::vector<std::pair<int, int>> &cluster2XY);
331 
338  bool isClustersToLarges();
339 
341  {
342 
343  auto &timingNodes = placementInfo->getTimingInfo()->getSimplePlacementTimingInfo();
344  if (auto unpacked = dynamic_cast<PlacementInfo::PlacementUnpackedCell *>(curPU))
345  {
346  if (unpacked->getCell()->isVirtualCell())
347  return 0;
348  return timingNodes[unpacked->getCell()->getCellId()]->getLongestPathLength();
349  }
350  else if (auto tmpMacro = dynamic_cast<PlacementInfo::PlacementMacro *>(curPU))
351  {
352  int maxLen = 0;
353  for (auto tmpCell : tmpMacro->getCells())
354  {
355  if (tmpCell->isVirtualCell())
356  continue;
357  int len = timingNodes[tmpCell->getCellId()]->getLongestPathLength();
358  if (len > maxLen)
359  maxLen = len;
360  }
361  return maxLen;
362  }
363  return 0;
364  }
365 
366  inline float random_float(float min, float max)
367  {
368  return ((float)random() / RAND_MAX) * (max - min) + min;
369  }
370 
371  void dumpClusters();
372 
373  void drawClusters();
374 };
375 
376 #endif
ClusterPlacer::placementUnitId2ClusterUnitId
std::vector< int > placementUnitId2ClusterUnitId
Definition: ClusterPlacer.h:158
ClusterPlacer
ClusterPlacer will cluster nodes in the given netlist and place the clusters on the device based on s...
Definition: ClusterPlacer.h:54
ClusterPlacer::connectionToFixedFactor
float connectionToFixedFactor
the enhancement ratio of the net between elements and I/Os
Definition: ClusterPlacer.h:110
PlacementInfo::getPlacementUnits
std::vector< PlacementUnit * > & getPlacementUnits()
Definition: PlacementInfo.h:2810
ClusterPlacer::creaeClusterNets
void creaeClusterNets()
construct the netlist of the generated clusters based on the PlacementNet in PlacementInfo
Definition: ClusterPlacer.h:225
ClusterPlacer::createUserDefinedClusterBasedClusterUnits
void createUserDefinedClusterBasedClusterUnits()
initially cluster cells based on user-defined clusters
Definition: ClusterPlacer.cc:269
PlacementInfo::PlacementMacro
a fixed group of multiple standard cells with constraints of their relative locations
Definition: PlacementInfo.h:1525
ClusterPlacer::resetClusterInfo
void resetClusterInfo()
clean all information of the clusters (including PlacementUnit-Cluster mapping and the cluster-level ...
Definition: ClusterPlacer.h:214
ClusterPlacer::userDefinedClusterBasedGraphPartitioner
GraphPartitioner< std::vector< PlacementInfo::ClusterUnit * >, std::vector< PlacementInfo::ClusterNet * > > * userDefinedClusterBasedGraphPartitioner
userDefinedClusterBasedGraphPartitioner will conduct partitioning at the Cluster level considering co...
Definition: ClusterPlacer.h:193
GraphPartitioner.h
ClusterPlacer::clusterBRAMCellWeights
std::vector< float > clusterBRAMCellWeights
Definition: ClusterPlacer.h:150
PlacementInfo::ClusterNet
The net between the objects of ClusterUnit class.
Definition: PlacementInfo.h:2541
ClusterPlacer::basicGraphPartitioner
GraphPartitioner< std::vector< PlacementInfo::PlacementUnit * >, std::vector< PlacementInfo::PlacementNet * > > * basicGraphPartitioner
basicGraphPartitioner will conduct partitioning at the PlacementUnit level considering connectivity a...
Definition: ClusterPlacer.h:185
ClusterPlacer::placementInfo
PlacementInfo * placementInfo
the PlacementInfo for this placer to handle
Definition: ClusterPlacer.h:95
ClusterPlacer::clusterDSPCellWeights
std::vector< float > clusterDSPCellWeights
Definition: ClusterPlacer.h:149
PlacementInfo::ClusterNet::addClusterUnit
void addClusterUnit(ClusterUnit *tmpCU)
Definition: PlacementInfo.h:2558
ClusterPlacer::dumpClusters
void dumpClusters()
Definition: ClusterPlacer.cc:777
SAPlacer.h
ClusterPlacer::basicPartitioning
void basicPartitioning(int minClusterCellNum, int eachClusterDSPNum, int eachClusterBRAMNum)
pure connectivity-based partitioning based on PaToH
Definition: ClusterPlacer.cc:338
ClusterPlacer::clusterNets
std::vector< PlacementInfo::ClusterNet * > clusterNets
Definition: ClusterPlacer.h:160
ClusterPlacer::userDefinedClusterBasedPartitioning
void userDefinedClusterBasedPartitioning(int minClusterCellNum, int eachClusterDSPNum, int eachClusterBRAMNum)
initially cluster cells based on user-defined clusters and conduct connectivity-based partitioning ba...
Definition: ClusterPlacer.cc:361
ClusterPlacer::y2xRatio
float y2xRatio
the Y/X coordinate calibration factor
Definition: ClusterPlacer.h:116
DeviceInfo::getClockRegionNumY
int getClockRegionNumY()
Get the number of rows of the clock region array.
Definition: DeviceInfo.h:1227
ClusterPlacer::cluster2XY
std::vector< std::pair< int, int > > cluster2XY
mapping cluster id to X/Y location in the cluster bin
Definition: ClusterPlacer.h:137
ClusterPlacer::createLongPathClusterUnits
void createLongPathClusterUnits()
initially cluster cells based on user-defined clusters
Definition: ClusterPlacer.cc:144
ClusterPlacer::jobs
int jobs
the parallel (multi-threading) worker number
Definition: ClusterPlacer.h:168
DesignInfo.h
This header file contains the classes of data for a standalone design netlist.
ClusterPlacer::clusterCLBCellWeights
std::vector< float > clusterCLBCellWeights
Definition: ClusterPlacer.h:148
PlacementInfo::getDeviceInfo
DeviceInfo * getDeviceInfo()
Definition: PlacementInfo.h:3308
ClusterPlacer::clockRegionXNum
int clockRegionXNum
Definition: ClusterPlacer.h:162
ClusterPlacer::refineClustersWithPredefinedClusters
void refineClustersWithPredefinedClusters()
refine the elements in obtained clusters to ensure the cells in user-defined clusters in the same clu...
Definition: ClusterPlacer.cc:457
ClusterPlacer::createSinglePUClusterUnits
void createSinglePUClusterUnits()
wrap single PlacementUnits into ClusterUnit for later uniform processing
Definition: ClusterPlacer.cc:324
ClusterPlacer::isClustersToLarges
bool isClustersToLarges()
check whether the average size of clusters is greater than the given threshold
Definition: ClusterPlacer.cc:527
DeviceInfo.h
This header file contains the classes of data for a standalone device.
ClusterPlacer::getPlacementUnitMaxPathLen
int getPlacementUnitMaxPathLen(PlacementInfo::PlacementUnit *curPU)
Definition: ClusterPlacer.h:340
ClusterPlacer::clockBasedPartitioning
void clockBasedPartitioning(int minClusterCellNum, int eachClusterDSPNum, int eachClusterBRAMNum)
initially cluster cells based on clock domains and conduct connectivity-based partitioning based on P...
Definition: ClusterPlacer.cc:399
ClusterPlacer::avgClusterSizeRequirement
int avgClusterSizeRequirement
the requirement of the average size of clusters (the number of cells)
Definition: ClusterPlacer.h:125
GraphPartitioner
GraphPartitioner will recursively bi-partition the netlist (which could be netlist of clusters) based...
Definition: GraphPartitioner.h:52
ClusterPlacer::randomInitialPlacement
bool randomInitialPlacement
Definition: ClusterPlacer.h:119
ClusterPlacer::clockRegionYNum
int clockRegionYNum
Definition: ClusterPlacer.h:162
sysInfo.h
ClusterPlacer::placeClusters
void placeClusters()
conduct the ClusterUnit level SA placement and then map PlacementUnit to cluster location
Definition: ClusterPlacer.cc:709
ClusterPlacer::setClusterNetsAdjMat
void setClusterNetsAdjMat()
construct the cluster nets adjacent matrix for simulated-annealing cluster placement
Definition: ClusterPlacer.cc:593
ClusterPlacer::~ClusterPlacer
~ClusterPlacer()
Definition: ClusterPlacer.h:65
ClusterPlacer::placementUnit2ClusterId
std::vector< int > placementUnit2ClusterId
Definition: ClusterPlacer.h:156
ClusterPlacer::hypergraphPartitioning
void hypergraphPartitioning()
call specific partitioners to partition the design netlist into clusters for initial placement
Definition: ClusterPlacer.cc:113
ClusterPlacer::random_float
float random_float(float min, float max)
Definition: ClusterPlacer.h:366
PlacementInfo::PlacementUnit
a movement unit in placement with information of location and resource demand
Definition: PlacementInfo.h:1010
SAPlacer
Definition: SAPlacer.h:41
PlacementInfo::getTimingInfo
PlacementTimingInfo * getTimingInfo()
Definition: PlacementInfo.h:3313
ClusterPlacer::clusterUnits
std::vector< PlacementInfo::ClusterUnit * > clusterUnits
Definition: ClusterPlacer.h:159
ClusterPlacer::JSONCfg
std::map< std::string, std::string > & JSONCfg
Definition: ClusterPlacer.h:104
ClusterPlacer::maxMinCutRate
double maxMinCutRate
the maximum cut rate for netlist min-cut partitioning
Definition: ClusterPlacer.h:131
ClusterPlacer::cluster2FP_XY
std::vector< std::pair< float, float > > cluster2FP_XY
mapping cluster id to floating-point X/Y location on device
Definition: ClusterPlacer.h:143
ClusterPlacer::clusters
std::vector< std::set< int > > clusters
the resultant clusters of PlacementUnit (id)
Definition: ClusterPlacer.h:103
DeviceInfo::getClockRegionNumX
int getClockRegionNumX()
Get the number of columns of the clock region array.
Definition: DeviceInfo.h:1217
PlacementTimingInfo::getSimplePlacementTimingInfo
std::vector< TimingGraph< DesignInfo::DesignCell >::TimingNode * > & getSimplePlacementTimingInfo()
Get the Simple Timing Info object which regard design cells as timing nodes.
Definition: PlacementTimingInfo.h:835
PlacementInfo::getPlacementNets
std::vector< PlacementNet * > & getPlacementNets()
Definition: PlacementInfo.h:2822
ClusterPlacer::saPlacer
SAPlacer * saPlacer
simulated-annealing placer for the cluster placement.
Definition: ClusterPlacer.h:177
ClusterPlacer::ClusterPlacement
void ClusterPlacement()
conduct cluster placement, cluster nodes in the given netlist and place the clusters on the device as...
Definition: ClusterPlacer.cc:60
PlacementInfo::PlacementUnpackedCell
the smallest, indivisible, representable component. It will include only one standard cell
Definition: PlacementInfo.h:1447
ClusterPlacer::clusterAdjMat
std::vector< std::vector< float > > clusterAdjMat
Definition: ClusterPlacer.h:147
ClusterPlacer::clockBasedGraphPartitioner
GraphPartitioner< std::vector< PlacementInfo::ClusterUnit * >, std::vector< PlacementInfo::ClusterNet * > > * clockBasedGraphPartitioner
clockBasedGraphPartitioner will conduct partitioning at the Cluster level considering connectivity an...
Definition: ClusterPlacer.h:201
print_info
void print_info(std::string tmp_string)
Definition: strPrint.cc:39
ClusterPlacer::cluster2FixedUnitMat
std::vector< std::vector< float > > cluster2FixedUnitMat
Definition: ClusterPlacer.h:152
ClusterPlacer::ClusterPlacer
ClusterPlacer(PlacementInfo *placementInfo, std::map< std::string, std::string > &JSONCfg, float connectionToFixedFactor=5.0)
Construct a new Cluster Placer object.
Definition: ClusterPlacer.cc:33
PlacementInfo.h
This header file mainly contains the definition of class PlacementInfo, including information related...
ClusterPlacer::drawClusters
void drawClusters()
Definition: ClusterPlacer.cc:843
ClusterPlacer::isDensePlacement
bool isDensePlacement()
Definition: ClusterPlacer.h:203
ClusterPlacer::fixedX
std::vector< float > fixedX
Definition: ClusterPlacer.h:153
ClusterPlacer::createClockBasedClusterUnits
void createClockBasedClusterUnits()
initially cluster cells based on clock domains
Definition: ClusterPlacer.cc:235
ClusterPlacer::verbose
bool verbose
Definition: ClusterPlacer.h:117
PlacementInfo
Information related to FPGA placement (wirelength optimization, cell spreading, legalization,...
Definition: PlacementInfo.h:59
ClusterPlacer::placeUnitBaseOnClusterPlacement
void placeUnitBaseOnClusterPlacement(const std::vector< std::pair< int, int >> &cluster2XY)
map PlacementUnit to cluster location
Definition: ClusterPlacer.cc:740
ClusterPlacer::fixedY
std::vector< float > fixedY
Definition: ClusterPlacer.h:154
ClusterPlacer::clusterPlacementUnits
void clusterPlacementUnits()
cluster the netlist and create ClusterUnit level netlist for SA placement
Definition: ClusterPlacer.cc:100