Skip to content

Commit d29d915

Browse files
committed
update orientation calcualtion logic
Signed-off-by: Chaitanya Gambali <gschaitanya2003@gmail.com>
1 parent 617d142 commit d29d915

File tree

9 files changed

+1526
-57
lines changed

9 files changed

+1526
-57
lines changed

src/ppl/include/ppl/IOPlacer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum class Edge
6767
left,
6868
right,
6969
invalid,
70-
polygonEdge
70+
polygonEdge,
7171
};
7272

7373
enum class Direction
@@ -215,6 +215,8 @@ class IOPlacer
215215
void excludeInterval(Interval interval);
216216

217217
void updateOrientation(IOPin& pin);
218+
bool isPointInsidePolygon(const odb::Point point, const odb::Polygon polygon);
219+
void updateOrientationPolygon(IOPin& pin);
218220
void updatePinArea(IOPin& pin);
219221
void movePinToTrack(odb::Point& pos,
220222
int layer,

src/ppl/src/HungarianMatching.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ void HungarianMatching::getFinalAssignment(std::vector<IOPin>& assignment,
135135
io_pin.setLayer(slots_[slot_index].layer);
136136
io_pin.setPlaced();
137137
io_pin.setEdge(slots_[slot_index].edge);
138+
// Set line information only for polygon edges
139+
if (slots_[slot_index].edge == Edge::polygonEdge) {
140+
io_pin.setLine(slots_[slot_index].containing_line);
141+
}
138142
assignment.push_back(io_pin);
139143
slots_[slot_index].used = true;
140144

@@ -317,6 +321,10 @@ void HungarianMatching::getAssignmentForGroups(std::vector<IOPin>& assignment,
317321
io_pin.setPosition(slots_[slot_index + pin_cnt].pos);
318322
io_pin.setLayer(slots_[slot_index + pin_cnt].layer);
319323
io_pin.setEdge(slots_[slot_index + pin_cnt].edge);
324+
// Set line information only for polygon edges
325+
if (slots_[slot_index + pin_cnt].edge == Edge::polygonEdge) {
326+
io_pin.setLine(slots_[slot_index + pin_cnt].containing_line);
327+
}
320328
assignment.push_back(io_pin);
321329
slots_[slot_index + pin_cnt].used = true;
322330
slots_[slot_index + pin_cnt].blocked = true;

src/ppl/src/IOPlacer.cpp

Lines changed: 100 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ void IOPlacer::placeFallbackGroup(
402402
io_pin.setPosition(slot.pos);
403403
io_pin.setLayer(slot.layer);
404404
io_pin.setEdge(slot.edge);
405+
// Set line information only for polygon edges
406+
if (slot.edge == Edge::polygonEdge) {
407+
io_pin.setLine(slot.containing_line);
408+
}
405409
assignment_.push_back(io_pin);
406410
slot.used = true;
407411
slot.blocked = true;
@@ -737,7 +741,9 @@ void IOPlacer::findSlots(const std::set<int>& layers, Edge edge)
737741

738742
for (const Point& pos : slots) {
739743
bool blocked = checkBlocked(edge, pos, layer);
740-
slots_.push_back({blocked, false, pos, layer, edge});
744+
// For regular die boundary edges, use default-constructed line
745+
odb::Line empty_line; // Default constructor creates empty line
746+
slots_.push_back({blocked, false, pos, layer, edge, empty_line});
741747
}
742748
}
743749
}
@@ -747,15 +753,6 @@ void IOPlacer::findSlotsPolygon(const std::set<int>& layers, odb::Line line)
747753
for (int layer : layers) {
748754
std::vector<Point> slots = findLayerSlotsPolygon(layer, line);
749755

750-
if (!slots.empty()) {
751-
printf("Slots found for layer %d for polygon edge (%d, %d) to (%d, %d)\n",
752-
layer,
753-
line.pt0().getX(),
754-
line.pt0().getY(),
755-
line.pt1().getX(),
756-
line.pt1().getY());
757-
}
758-
759756
// Remove slots that violates the min distance before reversing the vector.
760757
// This ensures that mirrored positions will exists for every slot.
761758
int slot_count = 0;
@@ -790,12 +787,8 @@ void IOPlacer::findSlotsPolygon(const std::set<int>& layers, odb::Line line)
790787
}
791788

792789
for (const Point& pos : slots) {
793-
bool blocked = checkBlockedPolygon(line, pos, layer);
794-
slots_.push_back({blocked, false, pos, layer, Edge::polygonEdge});
795-
printf("slot added at coordinates (%d, %d) in layer %d\n",
796-
pos.getX(),
797-
pos.getY(),
798-
layer);
790+
bool blocked = checkBlockedPolygon(line, pos, layer);;
791+
slots_.push_back({blocked, false, pos, layer, Edge::polygonEdge, line});
799792
}
800793
}
801794
}
@@ -918,18 +911,10 @@ std::vector<Point> IOPlacer::findLayerSlotsPolygon(const int layer,
918911
: std::max(edge_start.getY(), edge_end.getY());
919912

920913
corner_avoidance_ = parms_->getCornerAvoidance();
921-
printf("corner_avoidance_ = %d\n", vertical_pin);
922-
printf("Core size X %d \n", core_->getMinDstPinsX().size());
923-
printf("Core size Y %d \n", core_->getMinDstPinsY().size());
924914

925-
printf("Layer %d", layer);
926-
for (auto [key, value] : core_->getMinDstPinsX()) {
927-
printf("Core X layer %d min distances: %d\n", key, value.size());
928-
}
929915
const std::vector<int>& layer_min_distances
930916
= vertical_pin ? core_->getMinDstPinsX().at(layer)
931917
: core_->getMinDstPinsY().at(layer);
932-
printf("Layer %d min distances: %d", layer, layer_min_distances[0]);
933918

934919
const std::vector<int>& layer_init_tracks
935920
= vertical_pin ? core_->getInitTracksX().at(layer)
@@ -1106,6 +1091,8 @@ void IOPlacer::defineSlotsPolygon()
11061091
findSlotsPolygon(hor_layers_, line);}
11071092
}
11081093

1094+
findSlotsForTopLayer(); // Add top layer support for polygon flow too
1095+
11091096
int regular_pin_count
11101097
= static_cast<int>(netlist_->getIOPins().size()) - top_layer_pins_count_;
11111098
int available_slots = 0;
@@ -1652,11 +1639,9 @@ bool IOPlacer::assignPinsToSectionsPolygon(int assigned_pins_count)
16521639
std::vector<Section>& sections = sections_;
16531640

16541641
createSectionsPolygon();
1655-
printf("DEBUG: Created %zu sections for polygon\n", sections_.size());
16561642

16571643
int mirrored_pins_cnt = 0;
16581644
int total_pins_assigned = assignGroupsToSections(mirrored_pins_cnt);
1659-
printf("DEBUG: After assignGroupsToSections: total_pins_assigned = %d\n", total_pins_assigned);
16601645

16611646
// Mirrored pins first
16621647
int idx = 0;
@@ -1670,23 +1655,17 @@ bool IOPlacer::assignPinsToSectionsPolygon(int assigned_pins_count)
16701655
}
16711656
idx++;
16721657
}
1673-
printf("DEBUG: Mirrored pins assigned: %d\n", mirrored_pins_assigned);
16741658

16751659
// Remaining pins
16761660
idx = 0;
1677-
int remaining_pins_assigned = 0;//DEBUG VARIABLE _ REMOVE LATER
16781661
for (IOPin& io_pin : net->getIOPins()) {
16791662
if (assignPinToSection(io_pin, idx, sections)) {
16801663
total_pins_assigned++;
1681-
remaining_pins_assigned++;//DEBUG VARIABLE _ REMOVE LATER
16821664
}
16831665
idx++;
16841666
}
1685-
printf("DEBUG: Remaining pins assigned: %d\n", remaining_pins_assigned);
16861667

16871668
total_pins_assigned += assigned_pins_count + mirrored_pins_cnt;
1688-
printf("DEBUG: Final total_pins_assigned = %d (out of %d total pins)\n",
1689-
total_pins_assigned, net->numIOPins());
16901669

16911670
if (total_pins_assigned > net->numIOPins()) {
16921671
logger_->error(
@@ -1834,6 +1813,90 @@ void IOPlacer::updateOrientation(IOPin& pin)
18341813
}
18351814
}
18361815

1816+
bool IOPlacer::isPointInsidePolygon(const odb::Point point, const odb::Polygon die_polygon) {
1817+
const std::vector<odb::Point>& vertices = die_polygon.getPoints();
1818+
if (vertices.size() < 3) {
1819+
return false; // Not a valid polygon
1820+
}
1821+
1822+
int x = point.getX();
1823+
int y = point.getY();
1824+
bool inside = false;
1825+
1826+
size_t j = vertices.size() - 1; // Start with last vertex
1827+
1828+
for (size_t i = 0; i < vertices.size(); i++) {
1829+
int xi = vertices[i].getX();
1830+
int yi = vertices[i].getY();
1831+
int xj = vertices[j].getX();
1832+
int yj = vertices[j].getY();
1833+
1834+
// Check if point is on different sides of the edge
1835+
if (((yi > y) != (yj > y)) &&
1836+
(x < (xj - xi) * (y - yi) / (yj - yi) + xi)) {
1837+
inside = !inside;
1838+
}
1839+
j = i; // j follows i
1840+
}
1841+
1842+
return inside;
1843+
}
1844+
1845+
void IOPlacer::updateOrientationPolygon(IOPin& pin)
1846+
{
1847+
const int x = pin.getX();
1848+
const int y = pin.getY();
1849+
printf("Setting orientation for pin at position: (%d, %d) to : ", x, y);
1850+
odb::Line pin_line = pin.getLine();
1851+
1852+
odb::Polygon die_polygon = getBlock()->getDieAreaPolygon();
1853+
1854+
const int offset = 50;
1855+
1856+
bool is_vertical = (pin_line.pt0().getX() == pin_line.pt1().getX());
1857+
1858+
if (is_vertical)
1859+
{
1860+
1861+
odb::Point delta_right = pin.getPosition();
1862+
odb::Point delta_left = pin.getPosition();
1863+
delta_right.setX(delta_right.getX() + offset);
1864+
delta_left.setX(delta_left.getX() - offset);
1865+
if (isPointInsidePolygon(delta_right, die_polygon)) {
1866+
pin.setOrientation(Orientation::east);
1867+
printf("east\n");
1868+
return;
1869+
}
1870+
if (isPointInsidePolygon(delta_left, die_polygon)) {
1871+
pin.setOrientation(Orientation::west);
1872+
printf("west\n");
1873+
return;
1874+
}
1875+
}
1876+
else
1877+
{
1878+
odb::Point delta_top = pin.getPosition();
1879+
odb::Point delta_bottom = pin.getPosition();
1880+
delta_top.setY(delta_top.getY() + offset);
1881+
delta_bottom.setY(delta_bottom.getY() - offset);
1882+
if (isPointInsidePolygon(delta_top, die_polygon)) {
1883+
pin.setOrientation(Orientation::north);
1884+
printf("north\n");
1885+
return;
1886+
}
1887+
if (isPointInsidePolygon(delta_bottom, die_polygon)) {
1888+
pin.setOrientation(Orientation::south);
1889+
printf("south\n");
1890+
return;
1891+
}
1892+
}
1893+
1894+
logger_->warn(PPL, 9999, "Could not determine orientation for pin {} at ({:.2f}um, {:.2f}um)\n",
1895+
pin.getName(),
1896+
getBlock()->dbuToMicrons(x),
1897+
getBlock()->dbuToMicrons(y));
1898+
}
1899+
18371900
void IOPlacer::updatePinArea(IOPin& pin)
18381901
{
18391902
const int mfg_grid = getTech()->getManufacturingGrid();
@@ -2396,12 +2459,10 @@ std::string IOPlacer::getPinSetOrListString(const PinSetOrList& group)
23962459
void IOPlacer::findPinAssignment(std::vector<Section>& sections,
23972460
bool mirrored_groups_only)
23982461
{
2399-
printf("DEBUG: findPinAssignment called with %zu sections\n", sections.size());
24002462
int total_pin_indices = 0;
24012463
for (const auto& section : sections) {
24022464
total_pin_indices += section.pin_indices.size();
24032465
}
2404-
printf("DEBUG: Total pin indices in sections: %d\n", total_pin_indices);
24052466

24062467
std::vector<HungarianMatching> hg_vec;
24072468
for (const auto& section : sections) {
@@ -2446,7 +2507,6 @@ void IOPlacer::findPinAssignment(std::vector<Section>& sections,
24462507
}
24472508
}
24482509

2449-
printf("DEBUG: findPinAssignment completed, assignment_ size = %zu\n", assignment_.size());
24502510
}
24512511

24522512
void IOPlacer::updateSlots()
@@ -2557,24 +2617,18 @@ void IOPlacer::runHungarianMatching()
25572617
void IOPlacer::runHungarianMatchingPolygon()
25582618
{
25592619
slots_per_section_ = parms_->getSlotsPerSection();
2560-
printf("Slots per section: %d\n", slots_per_section_);
25612620
initExcludedIntervals();
2562-
printf("Excluded intervals initialized.\n");
25632621
initNetlistAndCore(hor_layers_, ver_layers_);
2564-
printf("Netlist and core initialized.\n");
25652622
getBlockedRegionsFromMacros();
2566-
printf("Blocked regions from macros retrieved.\n");
2623+
25672624
defineSlotsPolygon();
2568-
printf("Slots defined.\n");
2625+
25692626
initMirroredPins();
2570-
printf("mirrored pins initialized.\n");
25712627
initConstraints();
2572-
printf("Constraints initialized.\n");
25732628

25742629
int constrained_pins_cnt = 0;
25752630
int mirrored_pins_cnt = 0;
25762631
printConfig();
2577-
printf("config printed.\n");
25782632

25792633
// add groups to fallback
25802634
for (const auto& io_group : netlist_->getIOGroups()) {
@@ -2587,11 +2641,9 @@ void IOPlacer::runHungarianMatchingPolygon()
25872641
"to fallback mode.",
25882642
io_group.pin_indices.size());
25892643
addGroupToFallback(io_group.pin_indices, io_group.order);
2590-
printf("Group of size %zu added to fallback mode.\n", io_group.pin_indices.size());
25912644
}
25922645
}
25932646
constrained_pins_cnt += placeFallbackPins();
2594-
printf("Fallback pins placed: %d\n", constrained_pins_cnt);
25952647

25962648
for (bool mirrored_only : {true, false}) {
25972649
for (Constraint& constraint : constraints_) {
@@ -2632,16 +2684,12 @@ void IOPlacer::runHungarianMatchingPolygon()
26322684
}
26332685
}
26342686
constrained_pins_cnt += placeFallbackPins();
2635-
printf("Fallback pins placed (constraint version): %d\n", constrained_pins_cnt);
26362687

26372688
assignPinsToSectionsPolygon(constrained_pins_cnt);
2638-
printf("Assigned pins to sections: %d\n", constrained_pins_cnt);
26392689
findPinAssignment(sections_, false);
2640-
printf("DEBUG: assignment_ vector size = %zu\n", assignment_.size());
2641-
printf("DEBUG: Total netlist pins = %d\n", netlist_->numIOPins());
26422690

26432691
for (auto& pin : assignment_) {
2644-
updateOrientation(pin);
2692+
updateOrientationPolygon(pin);
26452693
updatePinArea(pin);
26462694
}
26472695

@@ -3232,7 +3280,8 @@ void IOPlacer::findSlotsForTopLayer()
32323280
false,
32333281
Point(x, y),
32343282
top_grid_->layer->getRoutingLevel(),
3235-
Edge::invalid});
3283+
Edge::invalid,
3284+
odb::Line()}); // Default-constructed line for top layer
32363285
}
32373286
}
32383287
}
@@ -3500,11 +3549,9 @@ void IOPlacer::findConstraintRegion(const Interval& interval,
35003549

35013550
void IOPlacer::commitIOPlacementToDB(std::vector<IOPin>& assignment)
35023551
{
3503-
printf("DEBUG: Committing %zu pins to database\n", assignment.size());
35043552
for (const IOPin& pin : assignment) {
35053553
commitIOPinToDB(pin);
35063554
}
3507-
printf("DEBUG: Finished committing pins to database\n");
35083555
}
35093556

35103557
void IOPlacer::commitIOPinToDB(const IOPin& pin)

src/ppl/src/Netlist.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class IOPin
9595
odb::dbBTerm* getBTerm() const { return bterm_; }
9696
int getLayer() const { return layer_; }
9797
void setLayer(const int layer) { layer_ = layer; }
98+
odb::Line getLine() const { return line_; }
99+
void setLine(const odb::Line line) { line_ = line; }
98100
int getGroupIdx() const { return group_idx_; }
99101
void setGroupIdx(const int group_idx) { group_idx_ = group_idx; }
100102
int getConstraintIdx() const { return constraint_idx_; }
@@ -130,6 +132,7 @@ class IOPin
130132
odb::Point lower_bound_;
131133
odb::Point upper_bound_;
132134
odb::dbPlacementStatus placement_status_;
135+
odb::Line line_;
133136
int layer_{-1};
134137
int group_idx_{-1};
135138
int constraint_idx_{-1};

src/ppl/src/Slots.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct Slot
5858
odb::Point pos;
5959
int layer;
6060
Edge edge;
61+
odb::Line containing_line;
6162

6263
bool isAvailable() const { return (!blocked && !used); }
6364
};

src/ppl/test/polygon_flow_test.tcl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# gcd flow pipe cleaner
2+
source "helpers.tcl"
3+
source "flow_helpers.tcl"
4+
source "Nangate45/Nangate45.vars"
5+
6+
set design "gcd"
7+
set top_module "gcd"
8+
set synth_verilog "gcd_nangate45.v"
9+
set sdc_file "gcd_nangate45.sdc"
10+
# set die_area {0 0 100.13 100.8}
11+
# set core_area {10.07 11.2 90.25 91}
12+
13+
set die_area {0 0 400 300 400 150 300 150 300}
14+
set core_area {20 20 380 280 380 180 280 180 280 20}
15+
16+
include -echo "flow.tcl"

0 commit comments

Comments
 (0)