Skip to content

Commit

Permalink
Merge pull request #5835 from LucasYuki/odb_store_routing_layer_range
Browse files Browse the repository at this point in the history
Odb store routing layer range
  • Loading branch information
maliberty authored Oct 1, 2024
2 parents b5ec51a + da88bb2 commit 42fad34
Show file tree
Hide file tree
Showing 11 changed files with 427 additions and 149 deletions.
2 changes: 0 additions & 2 deletions src/grt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ If you are a developer, you might find these useful. More details can be found i
| `parse_layer_name` | Get routing layer number from layer name |
| `parse_layer_range` | Parses a range from `layer_range` argument of format (%s-%s). `cmd` argument is not used. |
| `check_region` | Checks the defined region if its within the die area. |
| `define_layer_range` | Provide a Tcl list of layers and automatically generate the min and max layers for signal routing. |
| `define_clock_layer_range` | Provide a Tcl list of layers and automatically generate the min and max layers for clock routing. |
| `have_detailed_route` | Checks if block has detailed route already. |

## Regression tests
Expand Down
10 changes: 4 additions & 6 deletions src/grt/include/grt/GlobalRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ class GlobalRouter : public ant::GlobalRouteSource
void setAdjustment(const float adjustment);
void setMinRoutingLayer(const int min_layer);
void setMaxRoutingLayer(const int max_layer);
int getMinRoutingLayer() const { return min_routing_layer_; }
int getMaxRoutingLayer() const { return max_routing_layer_; }
int getMinRoutingLayer();
int getMaxRoutingLayer();
void setMinLayerForClock(const int min_layer);
void setMaxLayerForClock(const int max_layer);
int getMinLayerForClock();
int getMaxLayerForClock();
void setCriticalNetsPercentage(float critical_nets_percentage);
void addLayerAdjustment(int layer, float reduction_percentage);
void addRegionAdjustment(int min_x,
Expand Down Expand Up @@ -473,8 +475,6 @@ class GlobalRouter : public ant::GlobalRouteSource

// Flow variables
float adjustment_;
int min_routing_layer_;
int max_routing_layer_;
int layer_for_guide_dimension_;
int overflow_iterations_;
int congestion_report_iter_step_;
Expand All @@ -489,8 +489,6 @@ class GlobalRouter : public ant::GlobalRouteSource
std::vector<RegionAdjustment> region_adjustments_;

bool verbose_;
int min_layer_for_clock_;
int max_layer_for_clock_;

// variables for random grt
int seed_;
Expand Down
146 changes: 93 additions & 53 deletions src/grt/src/GlobalRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ GlobalRouter::GlobalRouter()
groute_renderer_(nullptr),
grid_(new Grid),
adjustment_(0.0),
min_routing_layer_(1),
max_routing_layer_(-1),
layer_for_guide_dimension_(3),
overflow_iterations_(50),
congestion_report_iter_step_(0),
Expand All @@ -101,8 +99,6 @@ GlobalRouter::GlobalRouter()
initialized_(false),
total_diodes_count_(0),
verbose_(false),
min_layer_for_clock_(-1),
max_layer_for_clock_(-2),
seed_(0),
caps_perturbation_percentage_(0),
perturbation_amount_(1),
Expand Down Expand Up @@ -387,7 +383,7 @@ void GlobalRouter::repairAntennas(odb::dbMTerm* diode_mterm,
}
violations = repair_antennas_->checkAntennaViolations(routes_,
nets_to_repair,
max_routing_layer_,
getMaxRoutingLayer(),
diode_mterm,
ratio_margin,
num_threads);
Expand Down Expand Up @@ -420,7 +416,7 @@ void GlobalRouter::makeNetWires()
repair_antennas_
= new RepairAntennas(this, antenna_checker_, opendp_, db_, logger_);
}
repair_antennas_->makeNetWires(routes_, nets_to_repair, max_routing_layer_);
repair_antennas_->makeNetWires(routes_, nets_to_repair, getMaxRoutingLayer());
}

void GlobalRouter::destroyNetWires()
Expand Down Expand Up @@ -958,9 +954,9 @@ void GlobalRouter::findPins(Net* net)
int GlobalRouter::getNetMaxRoutingLayer(const Net* net)
{
return net->getSignalType() == odb::dbSigType::CLOCK
&& max_layer_for_clock_ > 0
? max_layer_for_clock_
: max_routing_layer_;
&& getMaxLayerForClock() > 0
? getMaxLayerForClock()
: getMaxRoutingLayer();
}

void GlobalRouter::findFastRoutePins(Net* net,
Expand Down Expand Up @@ -1177,13 +1173,13 @@ void GlobalRouter::getNetLayerRange(odb::dbNet* db_net,
}

bool is_non_leaf_clock = isNonLeafClock(db_net);
min_layer = (is_non_leaf_clock && min_layer_for_clock_ > 0)
? min_layer_for_clock_
: min_routing_layer_;
min_layer = (is_non_leaf_clock && getMinLayerForClock() > 0)
? getMinLayerForClock()
: getMinRoutingLayer();
min_layer = std::max(min_layer, pin_min_layer);
max_layer = (is_non_leaf_clock && max_layer_for_clock_ > 0)
? max_layer_for_clock_
: max_routing_layer_;
max_layer = (is_non_leaf_clock && getMaxLayerForClock() > 0)
? getMaxLayerForClock()
: getMaxRoutingLayer();
}

void GlobalRouter::getGridSize(int& x_grids, int& y_grids)
Expand Down Expand Up @@ -1245,7 +1241,7 @@ void GlobalRouter::computeTrackConsumption(
std::vector<LayerId> GlobalRouter::findTransitionLayers()
{
odb::dbTech* tech = db_->getTech();
const int max_layer = std::max(max_routing_layer_, max_layer_for_clock_);
const int max_layer = std::max(getMaxRoutingLayer(), getMaxLayerForClock());
std::map<int, odb::dbTechVia*> default_vias = getDefaultVias(max_layer);
std::vector<LayerId> transition_layers;
for (const auto [layer, via] : default_vias) {
Expand Down Expand Up @@ -1654,24 +1650,68 @@ void GlobalRouter::setAdjustment(const float adjustment)
adjustment_ = adjustment;
}

int GlobalRouter::getMinRoutingLayer()
{
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
return block_->getMinRoutingLayer();
}

int GlobalRouter::getMaxRoutingLayer()
{
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
return block_->getMaxRoutingLayer();
}

int GlobalRouter::getMinLayerForClock()
{
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
return block_->getMinLayerForClock();
}

int GlobalRouter::getMaxLayerForClock()
{
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
return block_->getMaxLayerForClock();
}

void GlobalRouter::setMinRoutingLayer(const int min_layer)
{
min_routing_layer_ = min_layer;
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
block_->setMinRoutingLayer(min_layer);
}

void GlobalRouter::setMaxRoutingLayer(const int max_layer)
{
max_routing_layer_ = max_layer;
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
block_->setMaxRoutingLayer(max_layer);
}

void GlobalRouter::setMinLayerForClock(const int min_layer)
{
min_layer_for_clock_ = min_layer;
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
block_->setMinLayerForClock(min_layer);
}

void GlobalRouter::setMaxLayerForClock(const int max_layer)
{
max_layer_for_clock_ = max_layer;
if (block_ == nullptr) {
block_ = db_->getChip()->getBlock();
}
block_->setMaxLayerForClock(max_layer);
}

void GlobalRouter::setCriticalNetsPercentage(float critical_nets_percentage)
Expand All @@ -1690,10 +1730,10 @@ void GlobalRouter::addLayerAdjustment(int layer, float reduction_percentage)
{
odb::dbTech* tech = db_->getTech();
odb::dbTechLayer* tech_layer = tech->findRoutingLayer(layer);
if (layer > max_routing_layer_ && max_routing_layer_ > 0) {
if (layer > getMaxRoutingLayer() && getMaxRoutingLayer() > 0) {
if (verbose_) {
odb::dbTechLayer* max_tech_layer
= tech->findRoutingLayer(max_routing_layer_);
= tech->findRoutingLayer(getMaxRoutingLayer());
logger_->warn(GRT,
30,
"Specified layer {} for adjustment is greater than max "
Expand Down Expand Up @@ -1768,7 +1808,7 @@ void GlobalRouter::perturbCapacities()
std::mt19937 g;
g.seed(seed_);

for (int layer = 1; layer <= max_routing_layer_; layer++) {
for (int layer = 1; layer <= getMaxRoutingLayer(); layer++) {
std::uniform_int_distribution<int> uni_x(1, std::max(x_grids - 1, 1));
std::uniform_int_distribution<int> uni_y(1, std::max(y_grids - 1, 1));
std::bernoulli_distribution add_or_subtract;
Expand Down Expand Up @@ -1810,8 +1850,8 @@ void GlobalRouter::initGridAndNets()
{
block_ = db_->getChip()->getBlock();
routes_.clear();
if (max_routing_layer_ == -1) {
max_routing_layer_ = computeMaxRoutingLayer();
if (getMaxRoutingLayer() == -1) {
setMaxRoutingLayer(computeMaxRoutingLayer());
}
if (routing_layers_.empty()) {
int min_layer, max_layer;
Expand Down Expand Up @@ -1856,13 +1896,13 @@ void GlobalRouter::configFastRoute()

void GlobalRouter::getMinMaxLayer(int& min_layer, int& max_layer)
{
if (max_routing_layer_ == -1) {
max_routing_layer_ = computeMaxRoutingLayer();
if (getMaxRoutingLayer() == -1) {
setMaxRoutingLayer(computeMaxRoutingLayer());
}
min_layer = min_layer_for_clock_ > 0
? std::min(min_routing_layer_, min_layer_for_clock_)
: min_routing_layer_;
max_layer = std::max(max_routing_layer_, max_layer_for_clock_);
min_layer = getMinLayerForClock() > 0
? std::min(getMinRoutingLayer(), getMinLayerForClock())
: getMinRoutingLayer();
max_layer = std::max(getMaxRoutingLayer(), getMaxLayerForClock());
}

void GlobalRouter::checkOverflow()
Expand Down Expand Up @@ -2251,7 +2291,7 @@ void GlobalRouter::saveGuides()
odb::dbGuide::create(db_net, layer, via_layer, box);
}
} else if (segment.init_layer == segment.final_layer) {
if (segment.init_layer < min_routing_layer_
if (segment.init_layer < getMinRoutingLayer()
&& segment.init_x != segment.final_x
&& segment.init_y != segment.final_y) {
logger_->error(GRT,
Expand Down Expand Up @@ -2597,9 +2637,9 @@ void GlobalRouter::connectTopLevelPins(odb::dbNet* db_net, GRoute& route)
{
std::vector<Pin>& pins = db_net_map_[db_net]->getPins();
for (Pin& pin : pins) {
if (pin.getConnectionLayer() > max_routing_layer_) {
if (pin.getConnectionLayer() > getMaxRoutingLayer()) {
odb::Point pin_pos = pin.getOnGridPosition();
for (int l = max_routing_layer_; l < pin.getConnectionLayer(); l++) {
for (int l = getMaxRoutingLayer(); l < pin.getConnectionLayer(); l++) {
GSegment segment = GSegment(
pin_pos.x(), pin_pos.y(), l, pin_pos.x(), pin_pos.y(), l + 1);
route.push_back(segment);
Expand Down Expand Up @@ -3089,11 +3129,11 @@ std::vector<std::pair<int, int>> GlobalRouter::calcLayerPitches(int max_layer)
}
if (min_spc_valid) {
if (up_via_valid)
L2V_up = (level != max_routing_layer_)
L2V_up = (level != getMaxRoutingLayer())
? (layer_width / 2) + (width_up / 2) + min_spc_up
: -1;
if (down_via_valid)
L2V_down = (level != min_routing_layer_)
L2V_down = (level != getMinRoutingLayer())
? (layer_width / 2) + (width_down / 2) + min_spc_down
: -1;
debugPrint(logger_,
Expand Down Expand Up @@ -3354,9 +3394,9 @@ void GlobalRouter::makeItermPins(Net* net,
const odb::Rect& die_area)
{
bool is_clock = (net->getSignalType() == odb::dbSigType::CLOCK);
int max_routing_layer = (is_clock && max_layer_for_clock_ > 0)
? max_layer_for_clock_
: max_routing_layer_;
int max_routing_layer = (is_clock && getMaxLayerForClock() > 0)
? getMaxLayerForClock()
: getMaxRoutingLayer();
for (odb::dbITerm* iterm : db_net->getITerms()) {
odb::dbMTerm* mterm = iterm->getMTerm();
odb::dbMaster* master = mterm->getMaster();
Expand Down Expand Up @@ -3586,7 +3626,7 @@ int GlobalRouter::findObstructions(odb::Rect& die_area)
odb::dbBox* obstruction_box = obstruction->getBBox();

int layer = obstruction_box->getTechLayer()->getRoutingLevel();
if (min_routing_layer_ <= layer && layer <= max_routing_layer_) {
if (getMinRoutingLayer() <= layer && layer <= getMaxRoutingLayer()) {
odb::Point lower_bound
= odb::Point(obstruction_box->xMin(), obstruction_box->yMin());
odb::Point upper_bound
Expand All @@ -3611,11 +3651,11 @@ bool GlobalRouter::layerIsBlocked(
std::vector<odb::Rect>& extended_obs)
{
// if layer is max or min, then all obs the nearest layer are added
if (layer == max_routing_layer_
if (layer == getMaxRoutingLayer()
&& macro_obs_per_layer.find(layer - 1) != macro_obs_per_layer.end()) {
extended_obs = macro_obs_per_layer.at(layer - 1);
}
if (layer == min_routing_layer_
if (layer == getMinRoutingLayer()
&& macro_obs_per_layer.find(layer + 1) != macro_obs_per_layer.end()) {
extended_obs = macro_obs_per_layer.at(layer + 1);
}
Expand Down Expand Up @@ -3661,11 +3701,11 @@ void GlobalRouter::extendObstructions(
int top_layer)
{
// if it has obs on min_layer + 1, then the min_layer needs to be block
if (bottom_layer - 1 == min_routing_layer_) {
if (bottom_layer - 1 == getMinRoutingLayer()) {
bottom_layer--;
}
// if it has obs on max_layer - 1, then the max_layer needs to be block
if (top_layer + 1 == max_routing_layer_) {
if (top_layer + 1 == getMaxRoutingLayer()) {
top_layer++;
}

Expand Down Expand Up @@ -3707,7 +3747,7 @@ int GlobalRouter::findInstancesObstructions(

for (odb::dbBox* box : master->getObstructions()) {
int layer = box->getTechLayer()->getRoutingLevel();
if (min_routing_layer_ <= layer && layer <= max_routing_layer_) {
if (getMinRoutingLayer() <= layer && layer <= getMaxRoutingLayer()) {
odb::Rect rect = box->getBox();
transform.apply(rect);

Expand Down Expand Up @@ -3742,7 +3782,7 @@ int GlobalRouter::findInstancesObstructions(
} else {
for (odb::dbBox* box : master->getObstructions()) {
int layer = box->getTechLayer()->getRoutingLevel();
if (min_routing_layer_ <= layer && layer <= max_routing_layer_) {
if (getMinRoutingLayer() <= layer && layer <= getMaxRoutingLayer()) {
odb::Rect rect = box->getBox();
transform.apply(rect);

Expand Down Expand Up @@ -3781,8 +3821,8 @@ int GlobalRouter::findInstancesObstructions(
}

pin_layer = tech_layer->getRoutingLevel();
if (min_routing_layer_ <= pin_layer
&& pin_layer <= max_routing_layer_) {
if (getMinRoutingLayer() <= pin_layer
&& pin_layer <= getMaxRoutingLayer()) {
lower_bound = odb::Point(rect.xMin(), rect.yMin());
upper_bound = odb::Point(rect.xMax(), rect.yMax());
pin_box = odb::Rect(lower_bound, upper_bound);
Expand Down Expand Up @@ -3887,7 +3927,7 @@ void GlobalRouter::applyNetObstruction(const odb::Rect& rect,
{
int l = tech_layer->getRoutingLevel();

if (min_routing_layer_ <= l && l <= max_routing_layer_) {
if (getMinRoutingLayer() <= l && l <= getMaxRoutingLayer()) {
odb::Point lower_bound = odb::Point(rect.xMin(), rect.yMin());
odb::Point upper_bound = odb::Point(rect.xMax(), rect.yMax());
odb::Rect obstruction_rect = odb::Rect(lower_bound, upper_bound);
Expand Down Expand Up @@ -4073,7 +4113,7 @@ void GlobalRouter::getBlockage(odb::dbTechLayer* layer,
uint8_t& blockage_h,
uint8_t& blockage_v)
{
int max_layer = std::max(max_routing_layer_, max_layer_for_clock_);
int max_layer = std::max(getMaxRoutingLayer(), getMaxLayerForClock());
if (layer->getRoutingLevel() <= max_layer) {
fastroute_->getBlockage(layer, x, y, blockage_h, blockage_v);
}
Expand Down Expand Up @@ -4618,7 +4658,7 @@ std::vector<Net*> GlobalRouter::updateDirtyRoutes(bool save_guides)
initFastRouteIncr(dirty_nets);

NetRouteMap new_route
= findRouting(dirty_nets, min_routing_layer_, max_routing_layer_);
= findRouting(dirty_nets, getMinRoutingLayer(), getMaxRoutingLayer());
mergeResults(new_route);

bool reroutingOverflow = true;
Expand Down Expand Up @@ -4652,8 +4692,8 @@ std::vector<Net*> GlobalRouter::updateDirtyRoutes(bool save_guides)
}
// The dirty nets are initialized and then routed
initFastRouteIncr(dirty_nets);
NetRouteMap new_route
= findRouting(dirty_nets, min_routing_layer_, max_routing_layer_);
NetRouteMap new_route = findRouting(
dirty_nets, getMinRoutingLayer(), getMaxRoutingLayer());
mergeResults(new_route);
add_max--;
}
Expand Down
Loading

0 comments on commit 42fad34

Please sign in to comment.