@@ -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) .
353353void 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()
552549bool 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 }
0 commit comments