Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/grt/src/cugr/include/CUGR.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ class CUGR
// the default slack/bbox order.
void sortNetIndices(std::vector<int>& net_indices,
bool res_aware_order) const;
// Order for passes that reroute one net at a time against all others:
// non-critical nets largest first, then critical nets, worst slack last.
void sortRerouteIndices(std::vector<int>& net_indices) const;
// sortNetIndices for res-aware or incremental routing, else
// sortRerouteIndices.
void sortForReroute(std::vector<int>& net_indices) const;
void getGuides(const GRNet* net,
std::vector<std::pair<int, grt::BoxT>>& guides);
// Append net's routing tree to route as GRoute segments.
Expand Down
79 changes: 58 additions & 21 deletions src/grt/src/cugr/src/CUGR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ using utl::GRT;

namespace grt {

// Sentinel demoteNonCriticalNets writes so a net sorts last; not a slack.
// Sentinel demoteNonCriticalNets writes on non-critical nets; not a slack.
constexpr float kDemotedSlack = std::numeric_limits<float>::max();
// Overflow relief rounds; each grows the candidates and reruns the RRR loop.
constexpr int kReliefRounds = 5;
Expand All @@ -65,6 +65,23 @@ constexpr double kMaxReliefStretch = 1.25;

namespace {

// Stable-sorts net indices by less on their nets. Removed (null) nets sort
// last so the comparator stays a strict weak ordering.
template <typename Less>
void stableSortNets(std::vector<int>& net_indices,
const std::vector<std::unique_ptr<GRNet>>& nets,
Less less)
{
std::ranges::stable_sort(net_indices, [&](const int lhs, const int rhs) {
const GRNet* lhs_net = nets[lhs].get();
const GRNet* rhs_net = nets[rhs].get();
if (lhs_net == nullptr || rhs_net == nullptr) {
return rhs_net == nullptr && lhs_net != nullptr;
}
return less(lhs_net, rhs_net);
});
}

// Per-3D-edge key used by saveCongestion() to attribute wires and via
// stubs to specific edges.
using EdgeKey = std::tuple<int, int, int>; // (layer, x, y)
Expand Down Expand Up @@ -808,8 +825,7 @@ void CUGR::patternRouteWithDetours(std::vector<int>& net_indices)
// (2d) direction -> x -> y -> has overflow?
GridGraphView<bool> congestion_view;
grid_graph_->extractCongestionView(congestion_view);
sortNetIndices(net_indices,
resistance_aware_ && critical_nets_percentage_ != 0);
sortForReroute(net_indices);
for (const int net_index : net_indices) {
if (gr_nets_[net_index] == nullptr) {
continue;
Expand Down Expand Up @@ -855,8 +871,7 @@ double CUGR::mazeRoute(std::vector<int>& net_indices,
GridGraphView<CostT> full_view;
int view_mismatches = 0;
double view_max_drift = 0.0;
sortNetIndices(net_indices,
resistance_aware_ && critical_nets_percentage_ != 0);
sortForReroute(net_indices);
SparseGrid grid(10, 10, 0, 0);
// A reroute that adds overflow beyond float noise is rolled back and
// retried next pass.
Expand Down Expand Up @@ -1244,7 +1259,7 @@ void CUGR::reportDebugNetSlack(const GRNet* net,
sta_slack * 1e12);
} else if (cugr_slack >= kDemotedSlack) {
detail = fmt::format(
"slack = {:.2f} ps (cugr entered stage demoted, sorts last)",
"slack = {:.2f} ps (cugr entered stage demoted as non-critical)",
sta_slack * 1e12);
} else {
detail = fmt::format(
Expand Down Expand Up @@ -1743,26 +1758,48 @@ void CUGR::sortNetIndices(std::vector<int>& net_indices,
if (res_aware_order) {
// Multi-factor res-aware ordering (slack+resistance+fanout+length) so
// critical nets route first (FR's full tuple regressed asap7).
std::ranges::stable_sort(net_indices, [&](int lhs, int rhs) {
if (gr_nets_[lhs] == nullptr || gr_nets_[rhs] == nullptr) {
return false;
}
return getResAwareScore(gr_nets_[lhs].get())
< getResAwareScore(gr_nets_[rhs].get());
});
stableSortNets(
net_indices, gr_nets_, [&](const GRNet* lhs, const GRNet* rhs) {
return getResAwareScore(lhs) < getResAwareScore(rhs);
});
return;
}
std::ranges::stable_sort(net_indices, [&](int lhs, int rhs) {
if (gr_nets_[lhs] == nullptr || gr_nets_[rhs] == nullptr) {
return false;
}
return std::make_tuple(gr_nets_[lhs]->getSlack(),
gr_nets_[lhs]->getBoundingBox().hp())
< std::make_tuple(gr_nets_[rhs]->getSlack(),
gr_nets_[rhs]->getBoundingBox().hp());
stableSortNets(net_indices, gr_nets_, [](const GRNet* lhs, const GRNet* rhs) {
return std::make_tuple(lhs->getSlack(), lhs->getBoundingBox().hp())
< std::make_tuple(rhs->getSlack(), rhs->getBoundingBox().hp());
});
}

void CUGR::sortRerouteIndices(std::vector<int>& net_indices) const
{
// Each reroute sees every other net in place, so a net routed later finds
// the capacity that earlier nets vacated. Non-critical nets go first,
// largest bounding box first, since they have the most room to detour.
// Critical nets go last, worst slack last.
auto key = [](const GRNet* net) {
const float slack = net->getSlack();
return std::make_tuple(
slack < kDemotedSlack, -slack, -net->getBoundingBox().hp());
};
stableSortNets(
net_indices, gr_nets_, [&](const GRNet* lhs, const GRNet* rhs) {
return key(lhs) < key(rhs);
});
}

void CUGR::sortForReroute(std::vector<int>& net_indices) const
{
const bool res_aware_order
= resistance_aware_ && critical_nets_percentage_ != 0;
// Incremental reroutes follow netlist edits rather than congestion and
// skip demotion, so they keep the slack-then-size order.
if (res_aware_order || incremental_routing_) {
sortNetIndices(net_indices, res_aware_order);
} else {
sortRerouteIndices(net_indices);
}
}

void CUGR::getGuides(const GRNet* net,
std::vector<std::pair<int, BoxT>>& guides)
{
Expand Down
Loading
Loading