2121#include " GRNet.h"
2222#include " GRTree.h"
2323#include " geo.h"
24+ #include " odb/db.h"
2425#include " robin_hood.h"
2526#include " utl/Logger.h"
2627
@@ -36,6 +37,7 @@ GridGraph::GridGraph(const Design* design,
3637 num_layers_(design->getNumLayers ()),
3738 x_size_(gridlines_[0 ].size() - 1),
3839 y_size_(gridlines_[1 ].size() - 1),
40+ design_(design),
3941 constants_(constants)
4042{
4143 grid_centers_.resize (2 );
@@ -365,6 +367,72 @@ CostT GridGraph::getViaCost(const int layer_index, const PointT loc) const
365367 return cost;
366368}
367369
370+ void GridGraph::convertODBtoCUGR (AccessPointSet& selected_access_points,
371+ odb::dbAccessPoint* ap,
372+ int x,
373+ int y) const
374+ {
375+ const int amount_per_x = design_->getDieRegion ().hx () / x_size_;
376+ const int amount_per_y = design_->getDieRegion ().hy () / y_size_;
377+ auto point = ap->getPoint ();
378+ auto layer = ap->getLayer ();
379+ const int ap_x = ((point.getX () + x) / amount_per_x >= x_size_)
380+ ? x_size_ - 1
381+ : (point.getX () + x) / amount_per_x;
382+ const int ap_y = ((point.getY () + y) / amount_per_y >= y_size_)
383+ ? y_size_ - 1
384+ : (point.getY () + y) / amount_per_y;
385+ const PointT selected_point = PointT (ap_x, ap_y);
386+ const int num_layer = ((layer->getNumber () - 2 ) > (getNumLayers () - 1 ))
387+ ? getNumLayers () - 1
388+ : layer->getNumber () - 2 ;
389+ const IntervalT selected_layer = IntervalT (num_layer);
390+ const AccessPoint ap_new{.point = selected_point, .layers = selected_layer};
391+ selected_access_points.emplace (ap_new);
392+ }
393+
394+ bool GridGraph::findODBAccessPoints (
395+ const GRNet* net,
396+ AccessPointSet& selected_access_points) const
397+ {
398+ std::vector<odb::dbAccessPoint*> access_points;
399+ odb::dbNet* db_net = net->getDbNet ();
400+ if (db_net->getBTermCount () != 0 ) {
401+ for (odb::dbBTerm* bterms : db_net->getBTerms ()) {
402+ for (const odb::dbBPin* bpin : bterms->getBPins ()) {
403+ const std::vector<odb::dbAccessPoint*>& bpin_pas
404+ = bpin->getAccessPoints ();
405+ // Iterates per each AP and converts to CUGR structures
406+ access_points.insert (
407+ access_points.begin (), bpin_pas.begin (), bpin_pas.end ());
408+ for (auto ap : bpin_pas) {
409+ convertODBtoCUGR (selected_access_points, ap, 0 , 0 );
410+ }
411+ }
412+ }
413+ } else {
414+ for (auto iterms : db_net->getITerms ()) {
415+ auto pref_access_points = iterms->getPrefAccessPoints ();
416+ if (!pref_access_points.empty ()) {
417+ access_points.insert (access_points.end (),
418+ pref_access_points.begin (),
419+ pref_access_points.end ());
420+ // Iterates in ITerm prefered APs and convert to CUGR strucutres
421+ for (auto ap : pref_access_points) {
422+ int x, y;
423+ iterms->getInst ()->getLocation (x, y);
424+ convertODBtoCUGR (selected_access_points, ap, x, y);
425+ }
426+ }
427+ // Currently ignoring non preferred APs
428+ }
429+ }
430+ if (access_points.empty ()) {
431+ return false ;
432+ }
433+ return true ;
434+ }
435+
368436AccessPointSet GridGraph::selectAccessPoints (const GRNet* net) const
369437{
370438 AccessPointHash hasher (y_size_);
@@ -373,62 +441,60 @@ AccessPointSet GridGraph::selectAccessPoints(const GRNet* net) const
373441 selected_access_points.reserve (net->getNumPins ());
374442 const auto & boundingBox = net->getBoundingBox ();
375443 const PointT netCenter (boundingBox.cx (), boundingBox.cy ());
376- for (const std::vector<GRPoint>& accessPoints : net->getPinAccessPoints ()) {
377- std::pair<int , int > bestAccessDist = {0 , std::numeric_limits<int >::max ()};
378- int bestIndex = -1 ;
379- for (int index = 0 ; index < accessPoints.size (); index++) {
380- const GRPoint& point = accessPoints[index];
381- int accessibility = 0 ;
382- if (point.getLayerIdx () >= constants_.min_routing_layer ) {
383- const int direction = getLayerDirection (point.getLayerIdx ());
384- accessibility
385- += getEdge (point.getLayerIdx (), point.x (), point.y ()).capacity >= 1 ;
386- if (point[direction] > 0 ) {
387- auto lower = point;
388- lower[direction] -= 1 ;
444+ // Skips calculations if DRT already created APs in ODB
445+ if (!findODBAccessPoints (net, selected_access_points)) {
446+ for (const std::vector<GRPoint>& accessPoints : net->getPinAccessPoints ()) {
447+ std::pair<int , int > bestAccessDist = {0 , std::numeric_limits<int >::max ()};
448+ int bestIndex = -1 ;
449+ for (int index = 0 ; index < accessPoints.size (); index++) {
450+ const GRPoint& point = accessPoints[index];
451+ int accessibility = 0 ;
452+ if (point.getLayerIdx () >= constants_.min_routing_layer ) {
453+ const int direction = getLayerDirection (point.getLayerIdx ());
389454 accessibility
390- += getEdge (lower .getLayerIdx (), lower .x (), lower .y ()).capacity
455+ += getEdge (point .getLayerIdx (), point .x (), point .y ()).capacity
391456 >= 1 ;
457+ if (point[direction] > 0 ) {
458+ auto lower = point;
459+ lower[direction] -= 1 ;
460+ accessibility
461+ += getEdge (lower.getLayerIdx (), lower.x (), lower.y ()).capacity
462+ >= 1 ;
463+ }
464+ } else {
465+ accessibility = 1 ;
466+ }
467+ const int distance
468+ = abs (netCenter.x () - point.x ()) + abs (netCenter.y () - point.y ());
469+ if (accessibility > bestAccessDist.first
470+ || (accessibility == bestAccessDist.first
471+ && distance < bestAccessDist.second )) {
472+ bestIndex = index;
473+ bestAccessDist = {accessibility, distance};
392474 }
393- } else {
394- accessibility = 1 ;
395475 }
396- const int distance
397- = abs (netCenter.x () - point.x ()) + abs (netCenter.y () - point.y ());
398- if (accessibility > bestAccessDist.first
399- || (accessibility == bestAccessDist.first
400- && distance < bestAccessDist.second )) {
401- bestIndex = index;
402- bestAccessDist = {accessibility, distance};
476+ if (bestAccessDist.first == 0 ) {
477+ logger_->warn (utl::GRT, 274 , " pin is hard to access." );
403478 }
404- }
405- if (bestAccessDist.first == 0 ) {
406- logger_->warn (utl::GRT, 274 , " pin is hard to access." );
407- }
408479
409- if (bestIndex == -1 ) {
410- logger_->error (utl::GRT,
411- 283 ,
412- " No preferred access point found for pin on net {}." ,
413- net->getName ());
414- }
480+ if (bestIndex == -1 ) {
481+ logger_->error (utl::GRT,
482+ 283 ,
483+ " No preferred access point found for pin on net {}." ,
484+ net->getName ());
485+ }
415486
416- const PointT selectedPoint = accessPoints[bestIndex];
417- const AccessPoint ap{selectedPoint, {}};
418- auto it = selected_access_points.emplace (ap).first ;
419- IntervalT& fixedLayerInterval = it->layers ;
420- for (const auto & point : accessPoints) {
421- if (point.x () == selectedPoint.x () && point.y () == selectedPoint.y ()) {
422- fixedLayerInterval.Update (point.getLayerIdx ());
487+ const PointT selectedPoint = accessPoints[bestIndex];
488+ const AccessPoint ap{.point = selectedPoint, .layers = {}};
489+ auto it = selected_access_points.emplace (ap).first ;
490+ IntervalT& fixedLayerInterval = it->layers ;
491+ for (const auto & point : accessPoints) {
492+ if (point.x () == selectedPoint.x () && point.y () == selectedPoint.y ()) {
493+ fixedLayerInterval.Update (point.getLayerIdx ());
494+ }
423495 }
424496 }
425497 }
426- // Extend the fixed layers to 2 layers higher to facilitate track switching
427- for (auto & accessPoint : selected_access_points) {
428- IntervalT& fixedLayers = accessPoint.layers ;
429- fixedLayers.SetHigh (
430- std::min (fixedLayers.high () + 2 , (int ) getNumLayers () - 1 ));
431- }
432498 return selected_access_points;
433499}
434500
0 commit comments