From 0fe62b18a1af8db260ed6d504654e08f481034d8 Mon Sep 17 00:00:00 2001 From: mrg Date: Sun, 14 Jun 2026 07:23:17 -0700 Subject: [PATCH] drt: limit detailed-route grid graph to the routing-layer range FlexGridGraph::initTracks() added every routing layer in the tech to the grid, sizing nodes_, the per-node arrays (prevDirs_/srcs_/dsts_/guides_), and the maze search bounds across the full layer stack. Routing edges and access vias are already capped at TOP_ROUTING_LAYER, so layers above it were dead weight. Skip routing layers above TOP_ROUTING_LAYER so the grid graph spans only the routing range. Default TOP_ROUTING_LAYER is INT_MAX, so this is a no-op unless the top routing layer is explicitly lowered. Once the grid is trimmed it no longer spans the full layer stack, so maze-cost init must not assume every tech layer maps to a grid node. initMazeCost_fixedObj and initMazeCost_terms looped over the whole stack and called getMazeZIdx(layerNum) for routing layers above TOP_ROUTING_LAYER, returning an out-of-range z that the cost path dereferenced (getLayerNum -> zCoords_[z]), crashing on platforms with fixed shapes or instance pins above the top routing layer (e.g. ihp-sg13g2, with PDN and sg13g2_io pins on TopMetal above Metal5). Guard both so fixed-shape costing skips layers outside the grid's [getMinLayerNum, getMaxLayerNum] span. The skip is before any cost call, and is a no-op when the grid spans every routing layer. (The setBlocked/setGuide paths in initMazeCost_planarTerm, modBlockedEdgesForMacroPin and the guide helper are already bounds-checked, so they need no change.) Verified: - gt2n gcd: at the tech-top layer the routed DB is bit-identical to before (true no-op); with the top routing layer lowered to M5, detailed-route wall time dropped ~10% and peak memory ~14%, 0 DRC. - ihp-sg13g2 gcd (fixedObj) and i2c-gpio-expander (terms) crashed before the guard and route DRC-clean after it. Signed-off-by: mrg --- src/drt/src/dr/FlexDR_init.cpp | 32 ++++++++++++++++++++++++++++++++ src/drt/src/dr/FlexGridGraph.cpp | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/drt/src/dr/FlexDR_init.cpp b/src/drt/src/dr/FlexDR_init.cpp index 81a8a94843e..fc7e57d4e24 100644 --- a/src/drt/src/dr/FlexDR_init.cpp +++ b/src/drt/src/dr/FlexDR_init.cpp @@ -2722,6 +2722,14 @@ void FlexDRWorker::initMazeCost_fixedObj(const frDesign* design) result.clear(); if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::ROUTING) { isRoutingLayer = true; + // The grid graph need not span the full layer stack: TOP_ROUTING_LAYER + // can trim routing layers above it out of the grid. Skip fixed-shape + // costing on layers absent from the grid so getMazeZIdx / getLayerNum + // stay in range. No-op when the grid spans every routing layer. + if (layerNum < gridGraph_.getMinLayerNum() + || layerNum > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum); } else if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::CUT) { @@ -2729,6 +2737,10 @@ void FlexDRWorker::initMazeCost_fixedObj(const frDesign* design) if (getTech()->getBottomLayerNum() <= layerNum - 1 && getTech()->getLayer(layerNum - 1)->getType() == dbTechLayerType::ROUTING) { + if (layerNum - 1 < gridGraph_.getMinLayerNum() + || layerNum - 1 > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum - 1); } else { continue; @@ -2894,6 +2906,12 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::ROUTING) { isRoutingLayer = true; + // Grid may not span the full stack (TOP_ROUTING_LAYER trim); + // skip layers absent from the grid. No-op when fully spanned. + if (layerNum < gridGraph_.getMinLayerNum() + || layerNum > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum); } else if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::CUT) { @@ -2901,6 +2919,10 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getBottomLayerNum() <= layerNum - 1 && getTech()->getLayer(layerNum - 1)->getType() == dbTechLayerType::ROUTING) { + if (layerNum - 1 < gridGraph_.getMinLayerNum() + || layerNum - 1 > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum - 1); } else { continue; @@ -2971,6 +2993,12 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::ROUTING) { isRoutingLayer = true; + // Grid may not span the full stack (TOP_ROUTING_LAYER trim); + // skip layers absent from the grid. No-op when fully spanned. + if (layerNum < gridGraph_.getMinLayerNum() + || layerNum > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum); } else if (getTech()->getLayer(layerNum)->getType() == dbTechLayerType::CUT) { @@ -2978,6 +3006,10 @@ void FlexDRWorker::initMazeCost_terms( if (getTech()->getBottomLayerNum() <= layerNum - 1 && getTech()->getLayer(layerNum - 1)->getType() == dbTechLayerType::ROUTING) { + if (layerNum - 1 < gridGraph_.getMinLayerNum() + || layerNum - 1 > gridGraph_.getMaxLayerNum()) { + continue; + } zIdx = gridGraph_.getMazeZIdx(layerNum - 1); } else { continue; diff --git a/src/drt/src/dr/FlexGridGraph.cpp b/src/drt/src/dr/FlexGridGraph.cpp index 70dcfe0cf4a..8b778c03f28 100644 --- a/src/drt/src/dr/FlexGridGraph.cpp +++ b/src/drt/src/dr/FlexGridGraph.cpp @@ -471,6 +471,17 @@ void FlexGridGraph::initTracks( continue; } frLayerNum currLayerNum = layer->getLayerNum(); + // Layers above TOP_ROUTING_LAYER carry no routing edges or access vias + // (initEdges and the special-access via loop already cap work at + // TOP_ROUTING_LAYER), yet they were still added to the grid here, sizing + // nodes_, the per-node arrays, and the maze search bounds across the full + // layer stack. Skip them so the grid graph spans only the routing range, + // cutting detailed-route memory and runtime when the design's top routing + // layer is below the technology top. Default TOP_ROUTING_LAYER is INT_MAX, + // so this is a no-op unless the top routing layer is explicitly lowered. + if (currLayerNum > router_cfg_->TOP_ROUTING_LAYER) { + continue; + } dbTechLayerDir currPrefRouteDir = layer->getDir(); for (auto& tp : design->getTopBlock()->getTrackPatterns(currLayerNum)) { // allow wrongway if global variable and design rule allow