Skip to content

Commit c28a5d5

Browse files
Merge pull request The-OpenROAD-Project#6796 from bnmfw/drt_incremental_acc_pattern_2
drt: unique_inst_patterns_ structure structure refactor
2 parents f83fc1f + 07dc9a3 commit c28a5d5

File tree

7 files changed

+98
-87
lines changed

7 files changed

+98
-87
lines changed

src/drt/src/db/obj/frInst.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class frInst : public frRef
5050
: name_(name), master_(master), db_inst_(db_inst)
5151
{
5252
}
53+
// used for archive serialization
54+
frInst() : master_(nullptr), db_inst_(nullptr) {}
55+
5356
// getters
5457
const frString& getName() const { return name_; }
5558
frMaster* getMaster() const { return master_; }

src/drt/src/db/obj/frInstTerm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class frInstTerm : public frBlockObject
6363
void addAccessPoint(frAccessPoint* in) { ap_.push_back(in); }
6464
void setAccessPoints(const std::vector<frAccessPoint*>& in) { ap_ = in; }
6565
// others
66+
void clearAccessPoints() { ap_.clear(); }
6667
frBlockObjectEnum typeId() const override { return frcInstTerm; }
6768
frAccessPoint* getAccessPoint(frCoord x, frCoord y, frLayerNum lNum);
6869
bool hasAccessPoint(frCoord x, frCoord y, frLayerNum lNum);

src/drt/src/pa/FlexPA.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#pragma once
3030

3131
#include <boost/polygon/polygon.hpp>
32+
#include <boost/serialization/unordered_map.hpp>
3233
#include <cstdint>
3334
#include <vector>
3435

@@ -100,7 +101,8 @@ class FlexPA
100101
int macro_cell_pin_valid_planar_ap_cnt_ = 0;
101102
int macro_cell_pin_valid_via_ap_cnt_ = 0;
102103
int macro_cell_pin_no_ap_cnt_ = 0;
103-
std::vector<std::vector<std::unique_ptr<FlexPinAccessPattern>>>
104+
std::unordered_map<frInst*,
105+
std::vector<std::unique_ptr<FlexPinAccessPattern>>>
104106
unique_inst_patterns_;
105107

106108
UniqueInsts unique_insts_;
@@ -631,11 +633,11 @@ class FlexPA
631633
*/
632634
int prepPatternInstHelper(frInst* unique_inst, bool use_x);
633635

634-
int genPatterns(frInst* inst,
636+
int genPatterns(frInst* unique_inst,
635637
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins);
636638

637639
int genPatternsHelper(
638-
frInst* inst,
640+
frInst* unique_inst,
639641
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
640642
std::set<std::vector<int>>& inst_access_patterns,
641643
std::set<std::pair<int, int>>& used_access_points,
@@ -665,7 +667,7 @@ class FlexPA
665667
* @brief Determines the value of all the paths of the DP problem
666668
*/
667669
void genPatternsPerform(
668-
frInst* inst,
670+
frInst* unique_inst,
669671
std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
670672
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
671673
std::vector<int>& vio_edges,
@@ -676,7 +678,7 @@ class FlexPA
676678
/**
677679
* @brief Determines the edge cost between two DP nodes
678680
*/
679-
int getEdgeCost(frInst* inst,
681+
int getEdgeCost(frInst* unique_inst,
680682
FlexDPNode* prev_node,
681683
FlexDPNode* curr_node,
682684
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
@@ -705,7 +707,7 @@ class FlexPA
705707
* @brief Commits to the best path (solution) on the DP graph
706708
*/
707709
bool genPatternsCommit(
708-
frInst* inst,
710+
frInst* unique_inst,
709711
const std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
710712
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
711713
bool& is_valid,

src/drt/src/pa/FlexPA_acc_pattern.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ namespace drt {
5151
using utl::ThreadException;
5252

5353
static inline void serializePatterns(
54-
const std::vector<std::vector<std::unique_ptr<FlexPinAccessPattern>>>&
55-
patterns,
54+
const std::unordered_map<
55+
frInst*,
56+
std::vector<std::unique_ptr<FlexPinAccessPattern>>>& patterns,
5657
const std::string& file_name)
5758
{
5859
std::ofstream file(file_name.c_str());
@@ -99,7 +100,7 @@ void FlexPA::prepPattern()
99100
const auto& unique = unique_insts_.getUnique();
100101

101102
// revert access points to origin
102-
unique_inst_patterns_.resize(unique.size());
103+
unique_inst_patterns_.reserve(unique.size());
103104

104105
int cnt = 0;
105106

@@ -192,6 +193,10 @@ void FlexPA::prepPattern()
192193

193194
void FlexPA::prepPatternInst(frInst* unique_inst)
194195
{
196+
#pragma omp critical
197+
unique_inst_patterns_[unique_inst]
198+
= std::vector<std::unique_ptr<FlexPinAccessPattern>>();
199+
195200
int num_valid_pattern = prepPatternInstHelper(unique_inst, true);
196201

197202
if (num_valid_pattern > 0) {
@@ -258,7 +263,7 @@ int FlexPA::prepPatternInstHelper(frInst* unique_inst, const bool use_x)
258263
}
259264

260265
int FlexPA::genPatterns(
261-
frInst* inst,
266+
frInst* unique_inst,
262267
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins)
263268
{
264269
if (pins.empty()) {
@@ -282,7 +287,7 @@ int FlexPA::genPatterns(
282287
std::set<std::pair<int, int>> viol_access_points;
283288
int num_valid_pattern = 0;
284289

285-
num_valid_pattern += FlexPA::genPatternsHelper(inst,
290+
num_valid_pattern += FlexPA::genPatternsHelper(unique_inst,
286291
pins,
287292
inst_access_patterns,
288293
used_access_points,
@@ -293,7 +298,7 @@ int FlexPA::genPatterns(
293298
auto reversed_pins = pins;
294299
reverse(reversed_pins.begin(), reversed_pins.end());
295300

296-
num_valid_pattern += FlexPA::genPatternsHelper(inst,
301+
num_valid_pattern += FlexPA::genPatternsHelper(unique_inst,
297302
reversed_pins,
298303
inst_access_patterns,
299304
used_access_points,
@@ -305,7 +310,7 @@ int FlexPA::genPatterns(
305310
}
306311

307312
int FlexPA::genPatternsHelper(
308-
frInst* inst,
313+
frInst* unique_inst,
309314
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
310315
std::set<std::vector<int>>& inst_access_patterns,
311316
std::set<std::pair<int, int>>& used_access_points,
@@ -327,15 +332,15 @@ int FlexPA::genPatternsHelper(
327332

328333
for (int i = 0; i < router_cfg_->ACCESS_PATTERN_END_ITERATION_NUM; i++) {
329334
genPatternsReset(nodes, pins);
330-
genPatternsPerform(inst,
335+
genPatternsPerform(unique_inst,
331336
nodes,
332337
pins,
333338
vio_edge,
334339
used_access_points,
335340
viol_access_points,
336341
max_access_point_size);
337342
bool is_valid = false;
338-
if (genPatternsCommit(inst,
343+
if (genPatternsCommit(unique_inst,
339344
nodes,
340345
pins,
341346
is_valid,
@@ -483,7 +488,7 @@ bool FlexPA::genPatternsGC(
483488
}
484489

485490
void FlexPA::genPatternsPerform(
486-
frInst* inst,
491+
frInst* unique_inst,
487492
std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
488493
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
489494
std::vector<int>& vio_edges,
@@ -510,7 +515,7 @@ void FlexPA::genPatternsPerform(
510515
continue;
511516
}
512517

513-
const int edge_cost = getEdgeCost(inst,
518+
const int edge_cost = getEdgeCost(unique_inst,
514519
prev_node,
515520
curr_node,
516521
pins,
@@ -530,7 +535,7 @@ void FlexPA::genPatternsPerform(
530535
}
531536

532537
int FlexPA::getEdgeCost(
533-
frInst* inst,
538+
frInst* unique_inst,
534539
FlexDPNode* prev_node,
535540
FlexDPNode* curr_node,
536541
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
@@ -556,7 +561,7 @@ int FlexPA::getEdgeCost(
556561
if (vio_edges[edge_idx] != -1) {
557562
has_vio = (vio_edges[edge_idx] == 1);
558563
} else {
559-
dbTransform xform = inst->getNoRotationTransform();
564+
dbTransform xform = unique_inst->getNoRotationTransform();
560565
// check DRC
561566
std::vector<std::pair<frConnFig*, frBlockObject*>> objs;
562567
const auto& [pin_1, inst_term_1] = pins[prev_pin_idx];
@@ -684,7 +689,7 @@ std::vector<int> FlexPA::extractAccessPatternFromNodes(
684689
}
685690

686691
bool FlexPA::genPatternsCommit(
687-
frInst* inst,
692+
frInst* unique_inst,
688693
const std::vector<std::vector<std::unique_ptr<FlexDPNode>>>& nodes,
689694
const std::vector<std::pair<frMPin*, frInstTerm*>>& pins,
690695
bool& is_valid,
@@ -711,8 +716,8 @@ bool FlexPA::genPatternsCommit(
711716
for (int pin_idx = 0; pin_idx < (int) pins.size(); pin_idx++) {
712717
auto acc_point_idx = access_pattern[pin_idx];
713718
auto& [pin, inst_term] = pins[pin_idx];
714-
target_obj = inst;
715-
const int pin_access_idx = unique_insts_.getPAIndex(inst);
719+
target_obj = unique_inst;
720+
const int pin_access_idx = unique_insts_.getPAIndex(unique_inst);
716721
const auto pa = pin->getPinAccess(pin_access_idx);
717722
const auto access_point = pa->getAccessPoint(acc_point_idx);
718723
pin_to_access_point[pin] = access_point;
@@ -724,7 +729,7 @@ bool FlexPA::genPatternsCommit(
724729
auto rvia = via.get();
725730
temp_vias.push_back(std::move(via));
726731

727-
dbTransform xform = inst->getNoRotationTransform();
732+
dbTransform xform = unique_inst->getNoRotationTransform();
728733
Point pt(access_point->getPoint());
729734
xform.apply(pt);
730735
rvia->setOrigin(pt);
@@ -741,7 +746,7 @@ bool FlexPA::genPatternsCommit(
741746
frCoord left_pt = std::numeric_limits<frCoord>::max();
742747
frCoord right_pt = std::numeric_limits<frCoord>::min();
743748

744-
for (auto& inst_term : inst->getInstTerms()) {
749+
for (auto& inst_term : unique_inst->getInstTerms()) {
745750
if (isSkipInstTerm(inst_term.get())) {
746751
continue;
747752
}
@@ -778,8 +783,7 @@ bool FlexPA::genPatternsCommit(
778783
if (target_obj != nullptr
779784
&& genPatternsGC({target_obj}, objs, Commit, &owners)) {
780785
pin_access_pattern->updateCost();
781-
const int inst_idx = unique_insts_.getIndex(inst);
782-
unique_inst_patterns_[inst_idx].push_back(std::move(pin_access_pattern));
786+
unique_inst_patterns_[unique_inst].push_back(std::move(pin_access_pattern));
783787
// genPatternsPrint(nodes, pins);
784788
is_valid = true;
785789
} else {
@@ -811,8 +815,8 @@ void FlexPA::genPatternsPrintDebug(
811815
dbTransform xform;
812816
auto& [pin, inst_term] = pins[0];
813817
if (inst_term) {
814-
frInst* inst = inst_term->getInst();
815-
xform = inst->getNoRotationTransform();
818+
frInst* unique_inst = inst_term->getInst();
819+
xform = unique_inst->getNoRotationTransform();
816820
}
817821

818822
std::cout << "failed pattern:";
@@ -822,9 +826,9 @@ void FlexPA::genPatternsPrintDebug(
822826
// non-virtual node
823827
if (pin_cnt != (int) pins.size()) {
824828
auto& [pin, inst_term] = pins[pin_cnt];
825-
auto inst = inst_term->getInst();
829+
auto unique_inst = inst_term->getInst();
826830
std::cout << " " << inst_term->getTerm()->getName();
827-
const int pin_access_idx = unique_insts_.getPAIndex(inst);
831+
const int pin_access_idx = unique_insts_.getPAIndex(unique_inst);
828832
auto pa = pin->getPinAccess(pin_access_idx);
829833
auto [curr_pin_idx, curr_acc_point_idx] = curr_node->getIdx();
830834
Point pt(pa->getAccessPoint(curr_acc_point_idx)->getPoint());
@@ -855,17 +859,17 @@ void FlexPA::genPatternsPrint(
855859
// non-virtual node
856860
if (pin_cnt != (int) pins.size()) {
857861
auto& [pin, inst_term] = pins[pin_cnt];
858-
auto inst = inst_term->getInst();
859-
const int pin_access_idx = unique_insts_.getPAIndex(inst);
862+
auto unique_inst = inst_term->getInst();
863+
const int pin_access_idx = unique_insts_.getPAIndex(unique_inst);
860864
auto pa = pin->getPinAccess(pin_access_idx);
861865
auto [curr_pin_idx, curr_acc_point_idx] = curr_node->getIdx();
862866
std::unique_ptr<frVia> via = std::make_unique<frVia>(
863867
pa->getAccessPoint(curr_acc_point_idx)->getViaDef());
864868
Point pt(pa->getAccessPoint(curr_acc_point_idx)->getPoint());
865-
std::cout << " gccleanvia " << inst->getMaster()->getName() << " "
869+
std::cout << " gccleanvia " << unique_inst->getMaster()->getName() << " "
866870
<< inst_term->getTerm()->getName() << " "
867871
<< via->getViaDef()->getName() << " " << pt.x() << " " << pt.y()
868-
<< " " << inst->getOrient().getString() << "\n";
872+
<< " " << unique_inst->getOrient().getString() << "\n";
869873
}
870874

871875
curr_node = curr_node->getPrevNode();

0 commit comments

Comments
 (0)