1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2018-2020, The Regents of the University of California
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 // list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 // this list of conditions and the following disclaimer in the documentation
15 // and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE
25 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ///////////////////////////////////////////////////////////////////////////////
33
34 #ifndef __NESTEROV_BASE__
35 #define __NESTEROV_BASE__
36
37 #include <vector>
38 #include <memory>
39 #include <unordered_map>
40
41 #include "point.h"
42
43
44 namespace odb {
45 class dbInst;
46 class dbITerm;
47 class dbBTerm;
48 class dbNet;
49 }
50
51 namespace utl {
52 class Logger;
53 }
54
55 namespace gpl {
56
57 class Instance;
58 class Die;
59 class PlacerBase;
60
61 class Instance;
62 class Pin;
63 class Net;
64
65 class GPin;
66 class FFT;
67
68
69 class GCell {
70 public:
71 GCell();
72
73 // instance cells
74 GCell(Instance* inst);
75 GCell(const std::vector<Instance*>& insts);
76
77 // filler cells
78 GCell(int cx, int cy, int dx, int dy);
79 ~GCell();
80
81 Instance* instance() const;
insts()82 const std::vector<Instance*> & insts() const { return insts_; }
gPins()83 const std::vector<GPin*> & gPins() const { return gPins_; }
84
85 void addGPin(GPin* gPin);
86
87 void setClusteredInstance(const std::vector<Instance*>& insts);
88 void setInstance(Instance* inst);
89 void setFiller();
90 void setMacroInstance();
91 void setStdInstance();
92
93 // normal coordinates
94 int lx() const;
95 int ly() const;
96 int ux() const;
97 int uy() const;
98 int cx() const;
99 int cy() const;
100 int dx() const;
101 int dy() const;
102
103 // virtual density coordinates
104 int dLx() const;
105 int dLy() const;
106 int dUx() const;
107 int dUy() const;
108 int dCx() const;
109 int dCy() const;
110 int dDx() const;
111 int dDy() const;
112
113
114 void setLocation(int lx, int ly);
115 void setCenterLocation(int cx, int cy);
116 void setSize(int dx, int dy);
117
118 void setDensityLocation(int dLx, int dLy);
119 void setDensityCenterLocation(int dCx, int dCy);
120 void setDensitySize(int dDx, int dDy);
121
122 void setDensityScale(float densityScale);
123 void setGradientX(float gradX);
124 void setGradientY(float gradY);
125
gradientX()126 float gradientX() const { return gradientX_; }
gradientY()127 float gradientY() const { return gradientY_; }
densityScale()128 float densityScale() const { return densityScale_; }
129
130 bool isInstance() const;
131 bool isClusteredInstance() const;
132 bool isFiller() const;
133 bool isMacroInstance() const;
134 bool isStdInstance() const;
135
136
137 private:
138 std::vector<Instance*> insts_;
139 std::vector<GPin*> gPins_;
140 int lx_;
141 int ly_;
142 int ux_;
143 int uy_;
144
145 int dLx_;
146 int dLy_;
147 int dUx_;
148 int dUy_;
149
150 float densityScale_;
151 float gradientX_;
152 float gradientY_;
153
154 // need to be stored for
155 // MS replace
156 bool isMacroInstance_:1;
157 };
158
159 inline int
lx()160 GCell::lx() const {
161 return lx_;
162 }
163 inline int
ly()164 GCell::ly() const {
165 return ly_;
166 }
167
168 inline int
ux()169 GCell::ux() const {
170 return ux_;
171 }
172
173 inline int
uy()174 GCell::uy() const {
175 return uy_;
176 }
177
178 inline int
cx()179 GCell::cx() const {
180 return (lx_ + ux_)/2;
181 }
182
183 inline int
cy()184 GCell::cy() const {
185 return (ly_ + uy_)/2;
186 }
187
188 inline int
dx()189 GCell::dx() const {
190 return ux_ - lx_;
191 }
192
193 inline int
dy()194 GCell::dy() const {
195 return uy_ - ly_;
196 }
197
198 inline int
dLx()199 GCell::dLx() const {
200 return dLx_;
201 }
202
203 inline int
dLy()204 GCell::dLy() const {
205 return dLy_;
206 }
207
208 inline int
dUx()209 GCell::dUx() const {
210 return dUx_;
211 }
212
213 inline int
dUy()214 GCell::dUy() const {
215 return dUy_;
216 }
217
218 inline int
dCx()219 GCell::dCx() const {
220 return (dUx_ + dLx_)/2;
221 }
222
223 inline int
dCy()224 GCell::dCy() const {
225 return (dUy_ + dLy_)/2;
226 }
227
228 inline int
dDx()229 GCell::dDx() const {
230 return dUx_ - dLx_;
231 }
232
233 inline int
dDy()234 GCell::dDy() const {
235 return dUy_ - dLy_;
236 }
237
238 class GNet {
239 public:
240 GNet();
241 GNet(Net* net);
242 GNet(const std::vector<Net*>& nets);
243 ~GNet();
244
245 Net* net() const;
nets()246 const std::vector<Net*> & nets() const { return nets_; }
gPins()247 const std::vector<GPin*> & gPins() const { return gPins_; }
248
249 int lx() const;
250 int ly() const;
251 int ux() const;
252 int uy() const;
253
254 void setTimingWeight( float timingWeight );
255 void setCustomWeight( float customWeight );
256
totalWeight()257 float totalWeight() const { return timingWeight_ * customWeight_; }
timingWeight()258 float timingWeight() const { return timingWeight_; }
customWeight()259 float customWeight() const { return customWeight_; }
260
261 void addGPin(GPin* gPin);
262 void updateBox();
263 int64_t hpwl() const;
264
265 void setDontCare();
266 bool isDontCare() const;
267
268 // clear WA(Weighted Average) variables.
269 void clearWaVars();
270
271 void addWaExpMinSumX(float waExpMinSumX);
272 void addWaXExpMinSumX(float waExpXMinSumX);
273
274 void addWaExpMinSumY(float waExpMinSumY);
275 void addWaYExpMinSumY(float waExpXMinSumY);
276
277 void addWaExpMaxSumX(float waExpMaxSumX);
278 void addWaXExpMaxSumX(float waExpXMaxSumX);
279
280 void addWaExpMaxSumY(float waExpMaxSumY);
281 void addWaYExpMaxSumY(float waExpXMaxSumY);
282
283 float waExpMinSumX() const;
284 float waXExpMinSumX() const;
285
286 float waExpMinSumY() const;
287 float waYExpMinSumY() const;
288
289 float waExpMaxSumX() const;
290 float waXExpMaxSumX() const;
291
292 float waExpMaxSumY() const;
293 float waYExpMaxSumY() const;
294
295
296 private:
297 std::vector<GPin*> gPins_;
298 std::vector<Net*> nets_;
299 int lx_;
300 int ly_;
301 int ux_;
302 int uy_;
303
304 float timingWeight_;
305 float customWeight_;
306
307 //
308 // weighted average WL model stor for better indexing
309 // Please check the equation (4) in the ePlace-MS paper.
310 //
311 // WA: weighted Average
312 // saving four variable will be helpful for
313 // calculating the WA gradients/wirelengths.
314 //
315 // gamma: modeling accuracy.
316 //
317 // X forces.
318 //
319 // waExpMinSumX_: store sigma {exp(x_i/gamma)}
320 // waXExpMinSumX_: store signa {x_i*exp(e_i/gamma)}
321 // waExpMaxSumX_ : store sigma {exp(-x_i/gamma)}
322 // waXExpMaxSumX_: store sigma {x_i*exp(-x_i/gamma)}
323 //
324 float waExpMinSumX_;
325 float waXExpMinSumX_;
326
327 float waExpMaxSumX_;
328 float waXExpMaxSumX_;
329
330 //
331 // Y forces.
332 //
333 // waExpMinSumY_: store sigma {exp(y_i/gamma)}
334 // waYExpMinSumY_: store signa {y_i*exp(e_i/gamma)}
335 // waExpMaxSumY_ : store sigma {exp(-y_i/gamma)}
336 // waYExpMaxSumY_: store sigma {y_i*exp(-y_i/gamma)}
337 //
338 float waExpMinSumY_;
339 float waYExpMinSumY_;
340
341 float waExpMaxSumY_;
342 float waYExpMaxSumY_;
343
344 unsigned char isDontCare_:1;
345 };
346
347 inline int
lx()348 GNet::lx() const {
349 return lx_;
350 }
351
352 inline int
ly()353 GNet::ly() const {
354 return ly_;
355 }
356
357 inline int
ux()358 GNet::ux() const {
359 return ux_;
360 }
361
362 inline int
uy()363 GNet::uy() const {
364 return uy_;
365 }
366
367 // eight add functions
368 inline void
addWaExpMinSumX(float waExpMinSumX)369 GNet::addWaExpMinSumX(float waExpMinSumX) {
370 waExpMinSumX_ += waExpMinSumX;
371 }
372
373 inline void
addWaXExpMinSumX(float waXExpMinSumX)374 GNet::addWaXExpMinSumX(float waXExpMinSumX) {
375 waXExpMinSumX_ += waXExpMinSumX;
376 }
377
378 inline void
addWaExpMinSumY(float waExpMinSumY)379 GNet::addWaExpMinSumY(float waExpMinSumY) {
380 waExpMinSumY_ += waExpMinSumY;
381 }
382
383 inline void
addWaYExpMinSumY(float waYExpMinSumY)384 GNet::addWaYExpMinSumY(float waYExpMinSumY) {
385 waYExpMinSumY_ += waYExpMinSumY;
386 }
387
388 inline void
addWaExpMaxSumX(float waExpMaxSumX)389 GNet::addWaExpMaxSumX(float waExpMaxSumX) {
390 waExpMaxSumX_ += waExpMaxSumX;
391 }
392
393 inline void
addWaXExpMaxSumX(float waXExpMaxSumX)394 GNet::addWaXExpMaxSumX(float waXExpMaxSumX) {
395 waXExpMaxSumX_ += waXExpMaxSumX;
396 }
397
398 inline void
addWaExpMaxSumY(float waExpMaxSumY)399 GNet::addWaExpMaxSumY(float waExpMaxSumY) {
400 waExpMaxSumY_ += waExpMaxSumY;
401 }
402
403 inline void
addWaYExpMaxSumY(float waYExpMaxSumY)404 GNet::addWaYExpMaxSumY(float waYExpMaxSumY) {
405 waYExpMaxSumY_ += waYExpMaxSumY;
406 }
407
408 inline float
waExpMinSumX()409 GNet::waExpMinSumX() const {
410 return waExpMinSumX_;
411 }
412
413 inline float
waXExpMinSumX()414 GNet::waXExpMinSumX() const {
415 return waXExpMinSumX_;
416 }
417
418 inline float
waExpMinSumY()419 GNet::waExpMinSumY() const {
420 return waExpMinSumY_;
421 }
422
423 inline float
waYExpMinSumY()424 GNet::waYExpMinSumY() const {
425 return waYExpMinSumY_;
426 }
427
428 inline float
waExpMaxSumX()429 GNet::waExpMaxSumX() const {
430 return waExpMaxSumX_;
431 }
432
433 inline float
waXExpMaxSumX()434 GNet::waXExpMaxSumX() const {
435 return waXExpMaxSumX_;
436 }
437
438 inline float
waExpMaxSumY()439 GNet::waExpMaxSumY() const {
440 return waExpMaxSumY_;
441 }
442
443 inline float
waYExpMaxSumY()444 GNet::waYExpMaxSumY() const {
445 return waYExpMaxSumY_;
446 }
447
448
449 class GPin {
450 public:
451 GPin();
452 GPin(Pin* pin);
453 GPin(const std::vector<Pin*>& pins);
454 ~GPin();
455
456 Pin* pin() const;
pins()457 const std::vector<Pin*> & pins() const { return pins_; }
458
gCell()459 GCell* gCell() const { return gCell_; }
gNet()460 GNet* gNet() const { return gNet_; }
461
462 void setGCell(GCell* gCell);
463 void setGNet(GNet* gNet);
464
cx()465 int cx() const { return cx_; }
cy()466 int cy() const { return cy_; }
467
468 // clear WA(Weighted Average) variables.
469 void clearWaVars();
470
471 void setMaxExpSumX(float maxExpSumX);
472 void setMaxExpSumY(float maxExpSumY);
473 void setMinExpSumX(float minExpSumX);
474 void setMinExpSumY(float minExpSumY);
475
maxExpSumX()476 float maxExpSumX() const { return maxExpSumX_; }
maxExpSumY()477 float maxExpSumY() const { return maxExpSumY_; }
minExpSumX()478 float minExpSumX() const { return minExpSumX_; }
minExpSumY()479 float minExpSumY() const { return minExpSumY_; }
480
hasMaxExpSumX()481 bool hasMaxExpSumX() const { return (hasMaxExpSumX_ == 1); }
hasMaxExpSumY()482 bool hasMaxExpSumY() const { return (hasMaxExpSumY_ == 1); }
hasMinExpSumX()483 bool hasMinExpSumX() const { return (hasMinExpSumX_ == 1); }
hasMinExpSumY()484 bool hasMinExpSumY() const { return (hasMinExpSumY_ == 1); }
485
486 void setCenterLocation(int cx, int cy);
487 void updateLocation(const GCell* gCell);
488 void updateDensityLocation(const GCell* gCell);
489
490 private:
491 GCell* gCell_;
492 GNet* gNet_;
493 std::vector<Pin*> pins_;
494
495 int offsetCx_;
496 int offsetCy_;
497 int cx_;
498 int cy_;
499
500 // weighted average WL vals stor for better indexing
501 // Please check the equation (4) in the ePlace-MS paper.
502 //
503 // maxExpSum_: holds exp(x_i/gamma)
504 // minExpSum_: holds exp(-x_i/gamma)
505 // the x_i is equal to cx_ variable.
506 //
507 float maxExpSumX_;
508 float maxExpSumY_;
509
510 float minExpSumX_;
511 float minExpSumY_;
512
513 // flag variables
514 //
515 // check whether
516 // this pin is considered in a WA models.
517 unsigned char hasMaxExpSumX_:1;
518 unsigned char hasMaxExpSumY_:1;
519
520 unsigned char hasMinExpSumX_:1;
521 unsigned char hasMinExpSumY_:1;
522 };
523
524 class Bin {
525 public:
526 Bin();
527 Bin(int x, int y, int lx, int ly, int ux, int uy,
528 float targetDensity);
529
530 ~Bin();
531
532 int x() const;
533 int y() const;
534
535 int lx() const;
536 int ly() const;
537 int ux() const;
538 int uy() const;
539 int cx() const;
540 int cy() const;
541 int dx() const;
542 int dy() const;
543
544 float electroPhi() const;
545 float electroForceX() const;
546 float electroForceY() const;
547 float targetDensity() const;
548 float density() const;
549
550 void setDensity(float density);
551 void setTargetDensity(float density);
552 void setElectroForce(float electroForceX, float electroForceY);
553 void setElectroPhi(float phi);
554
555 void setNonPlaceArea(int64_t area);
556 void setInstPlacedArea(int64_t area);
557 void setFillerArea(int64_t area);
558
559 void addNonPlaceArea(int64_t area);
560 void addInstPlacedArea(int64_t area);
561 void addFillerArea(int64_t area);
562
563 const int64_t binArea() const;
nonPlaceArea()564 const int64_t nonPlaceArea() const { return nonPlaceArea_; }
instPlacedArea()565 const int64_t instPlacedArea() const { return instPlacedArea_; }
fillerArea()566 const int64_t fillerArea() const { return fillerArea_; }
567
568 private:
569 // index
570 int x_;
571 int y_;
572
573 // coordinate
574 int lx_;
575 int ly_;
576 int ux_;
577 int uy_;
578
579 int64_t nonPlaceArea_;
580 int64_t instPlacedArea_;
581 int64_t fillerArea_;
582
583 float density_;
584 float targetDensity_; // will enable bin-wise density screening
585 float electroPhi_;
586 float electroForceX_;
587 float electroForceY_;
588 };
589
590 inline int
x()591 Bin::x() const {
592 return x_;
593 }
594
595 inline int
y()596 Bin::y() const {
597 return y_;
598 }
599
600 inline int
lx()601 Bin::lx() const {
602 return lx_;
603 }
604
605 inline int
ly()606 Bin::ly() const {
607 return ly_;
608 }
609
610 inline int
ux()611 Bin::ux() const {
612 return ux_;
613 }
614
615 inline int
uy()616 Bin::uy() const {
617 return uy_;
618 }
619
620 inline int
cx()621 Bin::cx() const {
622 return (ux_ + lx_)/2;
623 }
624
625 inline int
cy()626 Bin::cy() const {
627 return (uy_ + ly_)/2;
628 }
629
630 inline int
dx()631 Bin::dx() const {
632 return (ux_ - lx_);
633 }
634
635 inline int
dy()636 Bin::dy() const {
637 return (uy_ - ly_);
638 }
639
640 inline void
setNonPlaceArea(int64_t area)641 Bin::setNonPlaceArea(int64_t area) {
642 nonPlaceArea_ = area;
643 }
644
645 inline void
setInstPlacedArea(int64_t area)646 Bin::setInstPlacedArea(int64_t area) {
647 instPlacedArea_ = area;
648 }
649
650 inline void
setFillerArea(int64_t area)651 Bin::setFillerArea(int64_t area) {
652 fillerArea_ = area;
653 }
654
655 inline void
addNonPlaceArea(int64_t area)656 Bin::addNonPlaceArea(int64_t area) {
657 nonPlaceArea_ += area;
658 }
659
660 inline void
addInstPlacedArea(int64_t area)661 Bin::addInstPlacedArea(int64_t area) {
662 instPlacedArea_ += area;
663 }
664
665 inline void
addFillerArea(int64_t area)666 Bin::addFillerArea(int64_t area) {
667 fillerArea_ += area;
668 }
669
670 //
671 // The bin can be non-uniform because of
672 // "integer" coordinates
673 //
674 class BinGrid {
675 public:
676 BinGrid();
677 BinGrid(Die* die);
678 ~BinGrid();
679
680 void setPlacerBase(const std::shared_ptr<PlacerBase> pb);
681 void setLogger(utl::Logger* log);
682 void setCorePoints(const Die* die);
683 void setBinCnt(int binCntX, int binCntY);
684 void setBinCntX(int binCntX);
685 void setBinCntY(int binCntY);
686 void setTargetDensity(float density);
687 void updateBinsGCellDensityArea(const std::vector<GCell*>& cells);
688
689 void initBins();
690
691 // lx, ly, ux, uy will hold coreArea
692 int lx() const;
693 int ly() const;
694 int ux() const;
695 int uy() const;
696 int cx() const;
697 int cy() const;
698 int dx() const;
699 int dy() const;
700
701 int binCntX() const;
702 int binCntY() const;
703 int binSizeX() const;
704 int binSizeY() const;
705
706 int64_t overflowArea() const;
707
708 // return bins_ index with given gcell
709 std::pair<int, int> getDensityMinMaxIdxX(const GCell* gcell) const;
710 std::pair<int, int> getDensityMinMaxIdxY(const GCell* gcell) const ;
711
712 std::pair<int, int> getMinMaxIdxX(const Instance* inst) const;
713 std::pair<int, int> getMinMaxIdxY(const Instance* inst) const;
714
715 const std::vector<Bin*> & bins() const;
716
717 void updateBinsNonPlaceArea();
718
719 private:
720 std::vector<Bin> binStor_;
721 std::vector<Bin*> bins_;
722 std::shared_ptr<PlacerBase> pb_;
723 utl::Logger* log_;
724 int lx_;
725 int ly_;
726 int ux_;
727 int uy_;
728 int binCntX_;
729 int binCntY_;
730 int binSizeX_;
731 int binSizeY_;
732 float targetDensity_;
733 int64_t overflowArea_;
734 unsigned char isSetBinCntX_:1;
735 unsigned char isSetBinCntY_:1;
736 };
737
738 inline const std::vector<Bin*>&
bins()739 BinGrid::bins() const {
740 return bins_;
741 }
742
743 class NesterovBaseVars {
744 public:
745 float targetDensity;
746 int binCntX;
747 int binCntY;
748 float minWireLengthForceBar;
749 // temp variables
750 unsigned char isSetBinCntX:1;
751 unsigned char isSetBinCntY:1;
752 unsigned char useUniformTargetDensity:1;
753
754 NesterovBaseVars();
755 void reset();
756 };
757
758 class NesterovBase {
759 public:
760 NesterovBase();
761 NesterovBase(NesterovBaseVars nbVars,
762 std::shared_ptr<PlacerBase> pb,
763 utl::Logger* log);
764 ~NesterovBase();
765
gCells()766 const std::vector<GCell*> & gCells() const { return gCells_; }
gCellInsts()767 const std::vector<GCell*> & gCellInsts() const { return gCellInsts_; }
gCellFillers()768 const std::vector<GCell*> & gCellFillers() const { return gCellFillers_; }
769
gNets()770 const std::vector<GNet*> & gNets() const { return gNets_; }
gPins()771 const std::vector<GPin*> & gPins() const { return gPins_; }
772
773 //
774 // placerBase To NesterovBase functions
775 //
776 GCell* pbToNb(Instance* inst) const;
777 GPin* pbToNb(Pin* pin) const;
778 GNet* pbToNb(Net* net) const;
779
780 //
781 // OpenDB To NesterovBase functions
782 //
783 GCell* dbToNb(odb::dbInst* inst) const;
784 GPin* dbToNb(odb::dbITerm* pin) const;
785 GPin* dbToNb(odb::dbBTerm* pin) const;
786 GNet* dbToNb(odb::dbNet* net) const;
787
788 // update gCells with lx, ly
789 void updateGCellLocation(
790 const std::vector<FloatPoint>& points);
791
792 // update gCells with cx, cy
793 void updateGCellCenterLocation(
794 const std::vector<FloatPoint>& points);
795
796 void updateGCellDensityCenterLocation(
797 const std::vector<FloatPoint>& points);
798
799
800 int binCntX() const;
801 int binCntY() const;
802 int binSizeX() const;
803 int binSizeY() const;
804 int64_t overflowArea() const;
805
806 const std::vector<Bin*> & bins() const;
807
808 // filler cells / area control
809 // will be used in Routability-driven loop
810 int fillerDx() const;
811 int fillerDy() const;
812 int fillerCnt() const;
813 int64_t fillerCellArea() const;
814 int64_t whiteSpaceArea() const;
815 int64_t movableArea() const;
816 int64_t totalFillerArea() const;
817
818 // bloating cell will change the following areas.
819 int64_t stdInstsArea() const;
820 int64_t macroInstsArea() const;
821
822 // update
823 // fillerArea, whiteSpaceArea, movableArea
824 // and totalFillerArea after changing gCell's size
825 void updateAreas();
826
827 // update density sizes with changed dx and dy
828 void updateDensitySize();
829
830 // should be separately defined.
831 // This is mainly used for NesterovLoop
832 int64_t nesterovInstsArea() const;
833
834 // sum phi and target density
835 // used in NesterovPlace
836 float sumPhi() const;
837
838 //
839 // return uniform (lower bound) target density
840 // LB of target density is required for massive runs.
841 //
842 float uniformTargetDensity() const;
843
844 // initTargetDensity is set by users
845 // targetDensity is equal to initTargetDensity and
846 // would be changed dynamically in RD loop
847 //
848 float initTargetDensity() const;
849 float targetDensity() const;
850
851 void setTargetDensity(float targetDensity);
852
853 // RD can shrink the number of fillerCells.
854 void cutFillerCells(int64_t targetFillerArea);
855
856 void updateDensityCoordiLayoutInside(GCell* gcell);
857
858 float getDensityCoordiLayoutInsideX(const GCell* gCell, float cx) const;
859 float getDensityCoordiLayoutInsideY(const GCell* gCell, float cy) const;
860
861 // WL force update based on WeightedAverage model
862 // wlCoeffX : WireLengthCoefficient for X.
863 // equal to 1 / gamma_x
864 // wlCoeffY : WireLengthCoefficient for Y.
865 // equal to 1 / gamma_y
866 //
867 // Gamma is described in the ePlaceMS paper.
868 //
869 void updateWireLengthForceWA(
870 float wlCoeffX,
871 float wlCoeffY);
872
873 FloatPoint
874 getWireLengthGradientPinWA(const GPin* gPin,
875 float wlCoeffX, float wlCoeffY) const;
876
877 FloatPoint
878 getWireLengthGradientWA(const GCell* gCell,
879 float wlCoeffX, float wlCoeffY) const;
880
881 // for preconditioner
882 FloatPoint
883 getWireLengthPreconditioner(const GCell* gCell) const;
884
885 FloatPoint
886 getDensityPreconditioner(const GCell* gCell) const;
887
888 FloatPoint
889 getDensityGradient(const GCell* gCell) const;
890
891 int64_t getHpwl();
892
893 // update electrostatic forces within Bin
894 void updateDensityForceBin();
895
896 void updateDbGCells();
897
898 private:
899 NesterovBaseVars nbVars_;
900 std::shared_ptr<PlacerBase> pb_;
901 utl::Logger* log_;
902
903 BinGrid bg_;
904 std::unique_ptr<FFT> fft_;
905
906 int fillerDx_, fillerDy_;
907 int64_t whiteSpaceArea_;
908 int64_t movableArea_;
909 int64_t totalFillerArea_;
910
911 int64_t stdInstsArea_;
912 int64_t macroInstsArea_;
913
914 std::vector<GCell> gCellStor_;
915 std::vector<GNet> gNetStor_;
916 std::vector<GPin> gPinStor_;
917
918 std::vector<GCell*> gCells_;
919 std::vector<GCell*> gCellInsts_;
920 std::vector<GCell*> gCellFillers_;
921
922 std::vector<GNet*> gNets_;
923 std::vector<GPin*> gPins_;
924
925 std::unordered_map<Instance*, GCell*> gCellMap_;
926 std::unordered_map<Pin*, GPin*> gPinMap_;
927 std::unordered_map<Net*, GNet*> gNetMap_;
928
929 float sumPhi_;
930 float targetDensity_;
931 float uniformTargetDensity_;
932
933 void init();
934 void initFillerGCells();
935 void initBinGrid();
936
937 void reset();
938 };
939
bins()940 inline const std::vector<Bin*> & NesterovBase::bins() const {
941 return bg_.bins();
942 }
943
944 }
945
946 #endif
947