Skip to content

Commit 811699e

Browse files
authored
Merge pull request #7211 from The-OpenROAD-Project-staging/ppl_hg_tie_break
ppl: add tie break technique during hungarian matching
2 parents f83968d + f463523 commit 811699e

5 files changed

Lines changed: 96 additions & 49 deletions

File tree

src/ppl/src/HungarianMatching.cpp

Lines changed: 75 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,42 @@ void HungarianMatching::findAssignment()
4747
void HungarianMatching::createMatrix()
4848
{
4949
hungarian_matrix_.resize(non_blocked_slots_);
50-
int slot_index = 0;
51-
for (int i = begin_slot_; i <= end_slot_; ++i) {
52-
int pinIndex = 0;
53-
const Point& slot_pos = slots_[i].pos;
54-
if (slots_[i].blocked) {
55-
continue;
56-
}
57-
hungarian_matrix_[slot_index].resize(num_io_pins_,
58-
std::numeric_limits<int>::max());
59-
for (int idx : pin_indices_) {
60-
IOPin& io_pin = netlist_->getIoPin(idx);
61-
if (!io_pin.isInGroup()) {
62-
int hpwl = netlist_->computeIONetHPWL(idx, slot_pos)
63-
+ getMirroredPinCost(io_pin, slot_pos);
64-
hungarian_matrix_[slot_index][pinIndex] = hpwl;
65-
pinIndex++;
50+
int pin_index = 0;
51+
52+
for (int idx : pin_indices_) {
53+
IOPin& io_pin = netlist_->getIoPin(idx);
54+
if (!io_pin.isInGroup()) {
55+
bool is_mirrored = false;
56+
std::vector<int> larger_costs;
57+
int slot_index = 0;
58+
for (int i = begin_slot_; i <= end_slot_; ++i) {
59+
const Point& slot_pos = slots_[i].pos;
60+
if (slots_[i].blocked) {
61+
continue;
62+
}
63+
hungarian_matrix_[slot_index].resize(num_io_pins_,
64+
std::numeric_limits<int>::max());
65+
const int io_net_hpwl = netlist_->computeIONetHPWL(idx, slot_pos);
66+
const int mirrored_cost = getMirroredPinCost(io_pin, slot_pos);
67+
const int hpwl = io_net_hpwl + mirrored_cost;
68+
larger_costs.push_back(std::max(io_net_hpwl, mirrored_cost));
69+
hungarian_matrix_[slot_index][pin_index] = hpwl;
70+
is_mirrored = is_mirrored || mirrored_cost != 0;
71+
slot_index++;
6672
}
73+
74+
if (is_mirrored) {
75+
std::vector<uint8_t> rank = getTieBreakRank(larger_costs);
76+
for (int idx = 0; idx < slot_index; idx++) {
77+
const int hpwl = hungarian_matrix_[idx][pin_index];
78+
if ((hpwl >> 24) != 0) {
79+
logger_->critical(utl::PPL, 210, "Cost for pin exceeds 24 bits.");
80+
}
81+
hungarian_matrix_[idx][pin_index] = (hpwl << 8) | rank[idx];
82+
}
83+
}
84+
pin_index++;
6785
}
68-
slot_index++;
6986
}
7087
}
7188

@@ -208,31 +225,47 @@ void HungarianMatching::createMatrixForGroups()
208225
}
209226

210227
hungarian_matrix_.resize(group_slots_);
211-
int slot_index = 0;
212-
for (int i : valid_starting_slots_) {
213-
int groupIndex = 0;
214-
const Point& slot_pos = slots_[i].pos;
215-
216-
hungarian_matrix_[slot_index].resize(num_pin_groups_,
217-
std::numeric_limits<int>::max());
218-
for (const auto& [pins, order] : pin_groups_) {
228+
int group_index = 0;
229+
for (const auto& [pins, order] : pin_groups_) {
230+
int slot_index = 0;
231+
bool is_mirrored = false;
232+
std::vector<int> larger_costs(valid_starting_slots_.size(), 0);
233+
for (int i : valid_starting_slots_) {
219234
int group_hpwl = 0;
220235
for (const int io_idx : pins) {
236+
const Point& slot_pos = slots_[i].pos;
237+
238+
hungarian_matrix_[slot_index].resize(num_pin_groups_,
239+
std::numeric_limits<int>::max());
221240
IOPin& io_pin = netlist_->getIoPin(io_idx);
222241
int pin_hpwl = netlist_->computeIONetHPWL(io_idx, slot_pos);
223242
if (pin_hpwl == hungarian_fail_) {
224243
group_hpwl = hungarian_fail_;
225244
break;
226245
}
227-
group_hpwl += pin_hpwl + getMirroredPinCost(io_pin, slot_pos);
246+
const int mirrored_cost = getMirroredPinCost(io_pin, slot_pos);
247+
group_hpwl += pin_hpwl + mirrored_cost;
248+
larger_costs[slot_index] += std::max(pin_hpwl, mirrored_cost);
249+
is_mirrored = is_mirrored || mirrored_cost != 0;
228250
}
229251
if (pins.size() > group_slot_capacity[slot_index]) {
230252
group_hpwl = std::numeric_limits<int>::max();
231253
}
232-
hungarian_matrix_[slot_index][groupIndex] = group_hpwl;
233-
groupIndex++;
254+
hungarian_matrix_[slot_index][group_index] = group_hpwl;
255+
slot_index++;
256+
}
257+
258+
if (is_mirrored) {
259+
std::vector<uint8_t> rank = getTieBreakRank(larger_costs);
260+
for (int idx = 0; idx < slot_index; idx++) {
261+
const int hpwl = hungarian_matrix_[idx][group_index];
262+
if ((hpwl >> 24) != 0) {
263+
logger_->critical(utl::PPL, 211, "Cost for pin exceeds 24 bits.");
264+
}
265+
hungarian_matrix_[idx][group_index] = (hpwl << 8) | rank[idx];
266+
}
234267
}
235-
slot_index++;
268+
group_index++;
236269
}
237270

238271
if (hungarian_matrix_.empty()) {
@@ -359,4 +392,17 @@ Edge HungarianMatching::getMirroredEdge(const Edge& edge)
359392
return mirrored_edge;
360393
}
361394

395+
std::vector<uint8_t> HungarianMatching::getTieBreakRank(
396+
const std::vector<int>& costs)
397+
{
398+
std::vector<uint8_t> rank(costs.size());
399+
uint8_t ranking = 1;
400+
for (int i : sortIndexes(costs, costs)) {
401+
rank[i] = ranking;
402+
ranking++;
403+
}
404+
405+
return rank;
406+
}
407+
362408
} // namespace ppl

src/ppl/src/HungarianMatching.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class HungarianMatching
7272
bool groupHasMirroredPin(const std::vector<int>& group);
7373
int getMirroredPinCost(IOPin& io_pin, const odb::Point& position);
7474
Edge getMirroredEdge(const Edge& edge);
75+
std::vector<uint8_t> getTieBreakRank(const std::vector<int>& costs);
7576
};
7677

7778
} // namespace ppl

src/ppl/test/add_constraint10.defok

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ PINS 54 ;
122122
- req_msg[0] + NET req_msg[0] + DIRECTION INPUT + USE SIGNAL
123123
+ PORT
124124
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
125-
+ PLACED ( 22610 201530 ) N ;
125+
+ PLACED ( 46930 201530 ) N ;
126126
- req_msg[10] + NET req_msg[10] + DIRECTION INPUT + USE SIGNAL
127127
+ PORT
128128
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -166,7 +166,7 @@ PINS 54 ;
166166
- req_msg[1] + NET req_msg[1] + DIRECTION INPUT + USE SIGNAL
167167
+ PORT
168168
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
169-
+ PLACED ( 22230 201530 ) N ;
169+
+ PLACED ( 62130 201530 ) N ;
170170
- req_msg[20] + NET req_msg[20] + DIRECTION INPUT + USE SIGNAL
171171
+ PORT
172172
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -210,7 +210,7 @@ PINS 54 ;
210210
- req_msg[2] + NET req_msg[2] + DIRECTION INPUT + USE SIGNAL
211211
+ PORT
212212
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
213-
+ PLACED ( 35530 70 ) N ;
213+
+ PLACED ( 35910 70 ) N ;
214214
- req_msg[30] + NET req_msg[30] + DIRECTION INPUT + USE SIGNAL
215215
+ PORT
216216
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -222,7 +222,7 @@ PINS 54 ;
222222
- req_msg[3] + NET req_msg[3] + DIRECTION INPUT + USE SIGNAL
223223
+ PORT
224224
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
225-
+ PLACED ( 35910 70 ) N ;
225+
+ PLACED ( 35530 70 ) N ;
226226
- req_msg[4] + NET req_msg[4] + DIRECTION INPUT + USE SIGNAL
227227
+ PORT
228228
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
@@ -250,7 +250,7 @@ PINS 54 ;
250250
- req_rdy + NET req_rdy + DIRECTION OUTPUT + USE SIGNAL
251251
+ PORT
252252
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
253-
+ PLACED ( 21850 201530 ) N ;
253+
+ PLACED ( 22230 201530 ) N ;
254254
- req_val + NET req_val + DIRECTION INPUT + USE SIGNAL
255255
+ PORT
256256
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -262,11 +262,11 @@ PINS 54 ;
262262
- resp_msg[0] + NET resp_msg[0] + DIRECTION OUTPUT + USE SIGNAL
263263
+ PORT
264264
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
265-
+ PLACED ( 22610 70 ) N ;
265+
+ PLACED ( 46930 70 ) N ;
266266
- resp_msg[10] + NET resp_msg[10] + DIRECTION OUTPUT + USE SIGNAL
267267
+ PORT
268268
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
269-
+ PLACED ( 21850 70 ) N ;
269+
+ PLACED ( 22230 70 ) N ;
270270
- resp_msg[11] + NET resp_msg[11] + DIRECTION OUTPUT + USE SIGNAL
271271
+ PORT
272272
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -290,15 +290,15 @@ PINS 54 ;
290290
- resp_msg[1] + NET resp_msg[1] + DIRECTION OUTPUT + USE SIGNAL
291291
+ PORT
292292
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
293-
+ PLACED ( 22230 70 ) N ;
293+
+ PLACED ( 62130 70 ) N ;
294294
- resp_msg[2] + NET resp_msg[2] + DIRECTION OUTPUT + USE SIGNAL
295295
+ PORT
296296
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
297-
+ PLACED ( 35530 201530 ) N ;
297+
+ PLACED ( 35910 201530 ) N ;
298298
- resp_msg[3] + NET resp_msg[3] + DIRECTION OUTPUT + USE SIGNAL
299299
+ PORT
300300
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
301-
+ PLACED ( 35910 201530 ) N ;
301+
+ PLACED ( 35530 201530 ) N ;
302302
- resp_msg[4] + NET resp_msg[4] + DIRECTION OUTPUT + USE SIGNAL
303303
+ PORT
304304
+ LAYER metal3 ( -70 -70 ) ( 70 70 )

src/ppl/test/add_constraint10.ok

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Found 0 macro blocks.
1212
[INFO PPL-0004] Number of I/O w/o sink 0
1313
[INFO PPL-0005] Slots per section 200
1414
[INFO PPL-0008] Successfully assigned pins to sections.
15-
[INFO PPL-0012] I/O nets HPWL: 2264.48 um.
15+
[INFO PPL-0012] I/O nets HPWL: 2264.16 um.
1616
No differences found.

src/ppl/test/add_constraint9.defok

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ PINS 54 ;
118118
- clk + NET clk + DIRECTION INPUT + USE SIGNAL
119119
+ PORT
120120
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
121-
+ PLACED ( 76570 70 ) N ;
121+
+ PLACED ( 76190 70 ) N ;
122122
- req_msg[0] + NET req_msg[0] + DIRECTION INPUT + USE SIGNAL
123123
+ PORT
124124
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
125-
+ PLACED ( 200190 163660 ) N ;
125+
+ PLACED ( 200190 151340 ) N ;
126126
- req_msg[10] + NET req_msg[10] + DIRECTION INPUT + USE SIGNAL
127127
+ PORT
128128
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -166,7 +166,7 @@ PINS 54 ;
166166
- req_msg[1] + NET req_msg[1] + DIRECTION INPUT + USE SIGNAL
167167
+ PORT
168168
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
169-
+ PLACED ( 47690 70 ) N ;
169+
+ PLACED ( 34390 70 ) N ;
170170
- req_msg[20] + NET req_msg[20] + DIRECTION INPUT + USE SIGNAL
171171
+ PORT
172172
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -210,7 +210,7 @@ PINS 54 ;
210210
- req_msg[2] + NET req_msg[2] + DIRECTION INPUT + USE SIGNAL
211211
+ PORT
212212
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
213-
+ PLACED ( 200190 177380 ) N ;
213+
+ PLACED ( 200190 170100 ) N ;
214214
- req_msg[30] + NET req_msg[30] + DIRECTION INPUT + USE SIGNAL
215215
+ PORT
216216
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
@@ -222,7 +222,7 @@ PINS 54 ;
222222
- req_msg[3] + NET req_msg[3] + DIRECTION INPUT + USE SIGNAL
223223
+ PORT
224224
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
225-
+ PLACED ( 76190 201530 ) N ;
225+
+ PLACED ( 91770 201530 ) N ;
226226
- req_msg[4] + NET req_msg[4] + DIRECTION INPUT + USE SIGNAL
227227
+ PORT
228228
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
@@ -262,7 +262,7 @@ PINS 54 ;
262262
- resp_msg[0] + NET resp_msg[0] + DIRECTION OUTPUT + USE SIGNAL
263263
+ PORT
264264
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
265-
+ PLACED ( 70 163660 ) N ;
265+
+ PLACED ( 70 151340 ) N ;
266266
- resp_msg[10] + NET resp_msg[10] + DIRECTION OUTPUT + USE SIGNAL
267267
+ PORT
268268
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
@@ -290,15 +290,15 @@ PINS 54 ;
290290
- resp_msg[1] + NET resp_msg[1] + DIRECTION OUTPUT + USE SIGNAL
291291
+ PORT
292292
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
293-
+ PLACED ( 47690 201530 ) N ;
293+
+ PLACED ( 34390 201530 ) N ;
294294
- resp_msg[2] + NET resp_msg[2] + DIRECTION OUTPUT + USE SIGNAL
295295
+ PORT
296296
+ LAYER metal3 ( -70 -70 ) ( 70 70 )
297-
+ PLACED ( 70 177380 ) N ;
297+
+ PLACED ( 70 170100 ) N ;
298298
- resp_msg[3] + NET resp_msg[3] + DIRECTION OUTPUT + USE SIGNAL
299299
+ PORT
300300
+ LAYER metal2 ( -70 -70 ) ( 70 70 )
301-
+ PLACED ( 76190 70 ) N ;
301+
+ PLACED ( 91770 70 ) N ;
302302
- resp_msg[4] + NET resp_msg[4] + DIRECTION OUTPUT + USE SIGNAL
303303
+ PORT
304304
+ LAYER metal3 ( -70 -70 ) ( 70 70 )

0 commit comments

Comments
 (0)