Skip to content

Commit 5a89c86

Browse files
committed
grt: cleaning code, refactoring, adding comments
Signed-off-by: Jonas Gava <[email protected]>
1 parent 0cd6101 commit 5a89c86

File tree

5 files changed

+55
-44
lines changed

5 files changed

+55
-44
lines changed

src/grt/src/fastroute/src/FastRoute.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <algorithm>
77
#include <cmath>
8+
#include <cstdint>
89
#include <limits>
910
#include <memory>
1011
#include <unordered_set>
@@ -1101,6 +1102,8 @@ NetRouteMap FastRouteCore::run()
11011102
float logistic_coef = 0;
11021103
int slope;
11031104
int max_adj;
1105+
const int long_edge_len = 40;
1106+
const int short_edge_len = 12;
11041107

11051108
// call FLUTE to generate RSMT and break the nets into segments (2-pin nets)
11061109
via_cost_ = 0;
@@ -1501,8 +1504,8 @@ NetRouteMap FastRouteCore::run()
15011504
via_cost_ = 1;
15021505

15031506
if (past_cong == 0) {
1504-
mazeRouteMSMDOrder3D(enlarge_, 0, 40);
1505-
mazeRouteMSMDOrder3D(enlarge_, 0, 12);
1507+
mazeRouteMSMDOrder3D(enlarge_, 0, long_edge_len);
1508+
mazeRouteMSMDOrder3D(enlarge_, 0, short_edge_len);
15061509
}
15071510

15081511
if (logger_->debugCheck(GRT, "grtSteps", 1)) {

src/grt/src/fastroute/src/graph2d.cpp

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -349,24 +349,21 @@ void Graph2D::updateCongList(const std::string& net_name,
349349
}
350350
}
351351

352-
// Prints all congested nets.
352+
// Prints all congested nets (debug).
353353
void Graph2D::printAllElements()
354354
{
355355
if (congestion_nets_.empty()) {
356-
std::cout << "No congestion nets.\n";
356+
logger_->report("No congestion nets.");
357357
return;
358358
}
359359

360-
std::cout << "Congestion Nets: ";
361-
std::cout << congestion_nets_.size();
362-
std::cout << " { ";
360+
logger_->report("Congestion nets ({}):", congestion_nets_.size());
363361
for (auto it = congestion_nets_.begin(); it != congestion_nets_.end(); ++it) {
364362
if (it != congestion_nets_.begin()) {
365-
std::cout << ", ";
363+
logger_->reportLiteral(", ");
366364
}
367-
std::cout << "\"" << *it << "\"";
365+
logger_->reportLiteral(fmt::format("\"{}\"", *it));
368366
}
369-
std::cout << " }\n";
370367
}
371368

372369
// Updates usage for a horizontal edge, considering NDRs.
@@ -552,29 +549,28 @@ void Graph2D::printEdgeCapPerLayer()
552549
bool Graph2D::hasNDRCapacity(FrNet* net, int x, int y, EdgeDirection direction)
553550
{
554551
const int8_t edgeCost = net->getEdgeCost();
555-
double max_single_layer_cap = 0;
556-
557-
if (edgeCost > 1) {
558-
// For nets with high cost, we need at least one layer with sufficient
559-
// capacity
560-
for (int l = net->getMinLayer(); l <= net->getMaxLayer(); l++) {
561-
double layer_cap = 0;
562-
if (direction == EdgeDirection::Horizontal) {
563-
layer_cap = h_cap_3D_[l][x][y].cap_ndr;
564-
} else {
565-
layer_cap = v_cap_3D_[l][x][y].cap_ndr;
566-
}
567-
max_single_layer_cap = std::max(max_single_layer_cap, layer_cap);
568-
if (layer_cap >= edgeCost) {
569-
return true;
570-
}
552+
553+
if (edgeCost == 1) {
554+
return true;
555+
}
556+
557+
// For nets with high cost, we need at least one layer with sufficient
558+
// capacity
559+
for (int l = net->getMinLayer(); l <= net->getMaxLayer(); l++) {
560+
double layer_cap = 0;
561+
if (direction == EdgeDirection::Horizontal) {
562+
layer_cap = h_cap_3D_[l][x][y].cap_ndr;
563+
} else {
564+
layer_cap = v_cap_3D_[l][x][y].cap_ndr;
571565
}
572566

573-
// No single layer can accommodate this NDR net
574-
return false;
567+
if (layer_cap >= edgeCost) {
568+
return true;
569+
}
575570
}
576571

577-
return true;
572+
// No single layer can accommodate this NDR net
573+
return false;
578574
}
579575

580576
// Calculates the cost of an edge, considering NDRs.
@@ -603,9 +599,15 @@ double Graph2D::getCostNDRAware(FrNet* net,
603599
bool is_net_present = ndr_nets.find(net_name) != ndr_nets.end();
604600
double final_edge_cost = 0;
605601

606-
if (edge_cost < 0) { // Rip-up: remove resource
607-
if (is_net_present) { // Remove only one time for L route
602+
if (edge_cost < 0) { // Rip-up: remove resource
603+
// If the net is in the list, remove it and compute the edge cost.
604+
// If the net is not in the list, it probably means that we are removing
605+
// half the edge cost a second time in the initial routing steps. But we
606+
// only need to count once to avoid problems when managing 3D capacity
607+
if (is_net_present) {
608608
ndr_nets.erase(net_name);
609+
// If the edge already has an overflow caused by NDR net we need to remove
610+
// the big edge cost value
609611
if (edge.ndr_overflow > 0) {
610612
edge.ndr_overflow--;
611613
final_edge_cost = -OVERFLOW_COST_MULTIPLIER * edgeCost;
@@ -615,7 +617,14 @@ double Graph2D::getCostNDRAware(FrNet* net,
615617
updateNDRCapLayer(x, y, net, direction, edge_cost);
616618
}
617619
} else { // Routing: add resource
620+
// If the net is not in the list, add it and compute the edge cost.
621+
// If the net is in the list, it probably means that we are in the
622+
// initial routing steps adding two times half the edge cost. But we
623+
// only need to count once to avoid problems when managing 3D capacity
618624
if (!is_net_present) {
625+
// If the edge already has an overflow caused by NDR net or it will have
626+
// an overflow due to lack of capacity in a single layer, we need to add
627+
// the big edge cost value
619628
if (edge.ndr_overflow > 0 || !hasNDRCapacity(net, x, y, direction)) {
620629
edge.ndr_overflow++;
621630
final_edge_cost = OVERFLOW_COST_MULTIPLIER * edgeCost;
@@ -661,19 +670,24 @@ void Graph2D::updateNDRCapLayer(const int x,
661670
for (int l = net->getMinLayer(); l <= net->getMaxLayer(); l++) {
662671
auto& layer_cap = cap_3D[l][x][y];
663672
if (edge_cost < 0) { // Reducing edge usage
673+
// If we already have a NDR net in this layer, increase the NDR capacity
674+
// available again
664675
if (layer_cap.cap - layer_cap.cap_ndr >= edgeCost) {
665676
layer_cap.cap_ndr += edgeCost;
666677
return;
667678
}
668679
} else { // Increasing edge usage
680+
// If there is NDR capacity available, reduce the capacity value
669681
if (layer_cap.cap_ndr >= edgeCost) {
670682
layer_cap.cap_ndr -= edgeCost;
671683
return;
672684
}
673685
}
674686
}
675687

676-
// Overflow (need to update cap_ndr even with congestion)
688+
// If the edge is already with congestion and there is no capacity available
689+
// in any layer, reduce the capacity available of the first layer.
690+
// When rippin-up, it will be the first to be released
677691
if (edge_cost > 0) {
678692
cap_3D[net->getMinLayer()][x][y].cap_ndr -= edgeCost;
679693
}

src/grt/src/fastroute/src/maze.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ int FastRouteCore::getOverflow2Dmaze(int* maxOverflow, int* tUsage)
19551955
total_overflow_ = H_overflow + V_overflow;
19561956
*maxOverflow = max_overflow;
19571957

1958-
if (logger_->debugCheck(GRT, "congestion", 1)) {
1958+
if (logger_->debugCheck(GRT, "congestion2D", 1)) {
19591959
logger_->report("Overflow report:");
19601960
logger_->report("Total usage : {}", total_usage);
19611961
logger_->report("Max H overflow : {}", max_H_overflow);
@@ -2038,7 +2038,7 @@ int FastRouteCore::getOverflow2D(int* maxOverflow)
20382038
ahth_ = 20;
20392039
}
20402040

2041-
if (logger_->debugCheck(GRT, "congestion", 1)) {
2041+
if (logger_->debugCheck(GRT, "congestion2D", 1)) {
20422042
logger_->report("Overflow report.");
20432043
logger_->report("Total hCap : {}", hCap);
20442044
logger_->report("Total vCap : {}", vCap);

src/grt/src/fastroute/src/maze3D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ void FastRouteCore::mazeRouteMSMDOrder3D(int expand,
14321432
graph2d_.updateUsageV(grids[i].x, min_y, net, net->getEdgeCost());
14331433
v_edges_3D_[grids[i].layer][min_y][grids[i].x].usage
14341434
+= net->getLayerEdgeCost(grids[i].layer);
1435-
} else /// if(grids[i].y==grids[i+1].y)// a horizontal edge
1435+
} else // a horizontal edge
14361436
{
14371437
const int min_x = std::min(grids[i].x, grids[i + 1].x);
14381438
graph2d_.updateUsageH(min_x, grids[i].y, net, net->getEdgeCost());

src/grt/src/fastroute/src/utility.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,9 @@ void FastRouteCore::ConvertToFull3DType2()
9696

9797
static bool compareNetPins(const OrderNetPin& a, const OrderNetPin& b)
9898
{
99-
// First priority: NDR nets (lower is better, so NDR nets with priority 0 come
100-
// first)
101-
if (a.ndr_priority != b.ndr_priority) {
102-
return a.ndr_priority < b.ndr_priority;
103-
}
104-
105-
// Second priority: original sorting by length_per_pin, minX, and treeIndex
106-
return std::tie(a.length_per_pin, a.minX, a.treeIndex)
107-
< std::tie(b.length_per_pin, b.minX, b.treeIndex);
99+
// Sorting by ndr_priority, length_per_pin, minX, and treeIndex
100+
return std::tie(a.ndr_priority, a.length_per_pin, a.minX, a.treeIndex)
101+
< std::tie(b.ndr_priority, b.length_per_pin, b.minX, b.treeIndex);
108102
}
109103

110104
void FastRouteCore::netpinOrderInc()

0 commit comments

Comments
 (0)