From 1e7b58a94bc6f38d21360ff626e40e58fc08041a Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Sat, 13 Sep 2025 03:18:17 +0000 Subject: [PATCH 01/19] add tcl --- src/interface/tcl/tcl_irt/CMakeLists.txt | 6 +- .../tcl/tcl_irt/include/tcl_register_irt.h | 8 +- src/interface/tcl/tcl_irt/include/tcl_rt.h | 44 ++-- ...tcl_clear_def.cpp => tcl_rt_clear_def.cpp} | 4 +- ...tput_db_json.cpp => tcl_rt_fix_fanout.cpp} | 17 +- src/operation/iRT/interface/RTInterface.cpp | 234 +----------------- src/operation/iRT/interface/RTInterface.hpp | 2 +- 7 files changed, 44 insertions(+), 271 deletions(-) rename src/interface/tcl/tcl_irt/src/{tcl_clear_def.cpp => tcl_rt_clear_def.cpp} (91%) rename src/interface/tcl/tcl_irt/src/{tcl_output_db_json.cpp => tcl_rt_fix_fanout.cpp} (69%) diff --git a/src/interface/tcl/tcl_irt/CMakeLists.txt b/src/interface/tcl/tcl_irt/CMakeLists.txt index 868f5b8a6..88b961bfd 100644 --- a/src/interface/tcl/tcl_irt/CMakeLists.txt +++ b/src/interface/tcl/tcl_irt/CMakeLists.txt @@ -1,10 +1,10 @@ add_library(tcl_irt - ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_clear_def.cpp - ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_destroy_rt.cpp ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_init_rt.cpp - ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_output_db_json.cpp ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_run_egr.cpp ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_run_rt.cpp + ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_destroy_rt.cpp + ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_rt_clear_def.cpp + ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_rt_fix_fanout.cpp ) target_link_libraries(tcl_irt diff --git a/src/interface/tcl/tcl_irt/include/tcl_register_irt.h b/src/interface/tcl/tcl_irt/include/tcl_register_irt.h index eba952afa..04d8573f9 100644 --- a/src/interface/tcl/tcl_irt/include/tcl_register_irt.h +++ b/src/interface/tcl/tcl_irt/include/tcl_register_irt.h @@ -24,12 +24,14 @@ namespace tcl { int registerCmdRT() { - registerTclCmd(TclClearDef, "clear_def"); - registerTclCmd(TclDestroyRT, "destroy_rt"); + // rt registerTclCmd(TclInitRT, "init_rt"); - registerTclCmd(TclOutputDBJson, "output_db_json"); registerTclCmd(TclRunEGR, "run_egr"); registerTclCmd(TclRunRT, "run_rt"); + registerTclCmd(TclDestroyRT, "destroy_rt"); + // aux + registerTclCmd(TclRTClearDef, "rt_clear_def"); + registerTclCmd(TclRTFixFanout, "rt_fix_fanout"); return EXIT_SUCCESS; } diff --git a/src/interface/tcl/tcl_irt/include/tcl_rt.h b/src/interface/tcl/tcl_irt/include/tcl_rt.h index 16d09ea86..2e2d34c97 100644 --- a/src/interface/tcl/tcl_irt/include/tcl_rt.h +++ b/src/interface/tcl/tcl_irt/include/tcl_rt.h @@ -20,11 +20,13 @@ namespace tcl { -class TclClearDef : public TclCmd +#if 1 // rt + +class TclInitRT : public TclCmd { public: - explicit TclClearDef(const char* cmd_name); - ~TclClearDef() override = default; + explicit TclInitRT(const char* cmd_name); + ~TclInitRT() override = default; unsigned check() override { return 1; }; @@ -34,11 +36,11 @@ class TclClearDef : public TclCmd std::vector> _config_list; }; -class TclDestroyRT : public TclCmd +class TclRunEGR : public TclCmd { public: - explicit TclDestroyRT(const char* cmd_name); - ~TclDestroyRT() override = default; + explicit TclRunEGR(const char* cmd_name); + ~TclRunEGR() override = default; unsigned check() override { return 1; }; @@ -48,11 +50,11 @@ class TclDestroyRT : public TclCmd std::vector> _config_list; }; -class TclInitRT : public TclCmd +class TclRunRT : public TclCmd { public: - explicit TclInitRT(const char* cmd_name); - ~TclInitRT() override = default; + explicit TclRunRT(const char* cmd_name); + ~TclRunRT() override = default; unsigned check() override { return 1; }; @@ -62,11 +64,11 @@ class TclInitRT : public TclCmd std::vector> _config_list; }; -class TclOutputDBJson : public TclCmd +class TclDestroyRT : public TclCmd { public: - explicit TclOutputDBJson(const char* cmd_name); - ~TclOutputDBJson() override = default; + explicit TclDestroyRT(const char* cmd_name); + ~TclDestroyRT() override = default; unsigned check() override { return 1; }; @@ -76,11 +78,15 @@ class TclOutputDBJson : public TclCmd std::vector> _config_list; }; -class TclRunEGR : public TclCmd +#endif + +#if 1 // aux + +class TclRTClearDef : public TclCmd { public: - explicit TclRunEGR(const char* cmd_name); - ~TclRunEGR() override = default; + explicit TclRTClearDef(const char* cmd_name); + ~TclRTClearDef() override = default; unsigned check() override { return 1; }; @@ -90,11 +96,11 @@ class TclRunEGR : public TclCmd std::vector> _config_list; }; -class TclRunRT : public TclCmd +class TclRTFixFanout : public TclCmd { public: - explicit TclRunRT(const char* cmd_name); - ~TclRunRT() override = default; + explicit TclRTFixFanout(const char* cmd_name); + ~TclRTFixFanout() override = default; unsigned check() override { return 1; }; @@ -104,4 +110,6 @@ class TclRunRT : public TclCmd std::vector> _config_list; }; +#endif + } // namespace tcl diff --git a/src/interface/tcl/tcl_irt/src/tcl_clear_def.cpp b/src/interface/tcl/tcl_irt/src/tcl_rt_clear_def.cpp similarity index 91% rename from src/interface/tcl/tcl_irt/src/tcl_clear_def.cpp rename to src/interface/tcl/tcl_irt/src/tcl_rt_clear_def.cpp index e3f9e5875..5a167cb24 100644 --- a/src/interface/tcl/tcl_irt/src/tcl_clear_def.cpp +++ b/src/interface/tcl/tcl_irt/src/tcl_rt_clear_def.cpp @@ -20,11 +20,11 @@ namespace tcl { -TclClearDef::TclClearDef(const char* cmd_name) : TclCmd(cmd_name) +TclRTClearDef::TclRTClearDef(const char* cmd_name) : TclCmd(cmd_name) { } -unsigned TclClearDef::exec() +unsigned TclRTClearDef::exec() { if (!check()) { return 0; diff --git a/src/interface/tcl/tcl_irt/src/tcl_output_db_json.cpp b/src/interface/tcl/tcl_irt/src/tcl_rt_fix_fanout.cpp similarity index 69% rename from src/interface/tcl/tcl_irt/src/tcl_output_db_json.cpp rename to src/interface/tcl/tcl_irt/src/tcl_rt_fix_fanout.cpp index 2e80b7426..c10417cdd 100644 --- a/src/interface/tcl/tcl_irt/src/tcl_output_db_json.cpp +++ b/src/interface/tcl/tcl_irt/src/tcl_rt_fix_fanout.cpp @@ -20,26 +20,19 @@ namespace tcl { -// public - -TclOutputDBJson::TclOutputDBJson(const char* cmd_name) : TclCmd(cmd_name) +TclRTFixFanout::TclRTFixFanout(const char* cmd_name) : TclCmd(cmd_name) { - _config_list.push_back(std::make_pair("-stage", ValueType::kString)); - _config_list.push_back(std::make_pair("-json_file_path", ValueType::kString)); - - TclUtil::addOption(this, _config_list); } -unsigned TclOutputDBJson::exec() +unsigned TclRTFixFanout::exec() { if (!check()) { return 0; } - std::map config_map = TclUtil::getConfigMap(this, _config_list); - RTI.outputDBJson(config_map); + + RTI.fixFanout(); + return 1; } -// private - } // namespace tcl diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index 52b6e3620..fa7395c69 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -278,239 +278,9 @@ void RTInterface::clearDef() ////////////////////////////////////////// } -void RTInterface::outputDBJson(std::map config_map) +void RTInterface::fixFanout() { - std::string stage = RTUTIL.getConfigValue(config_map, "-stage", "null"); - if (stage == "null") { - std::cout << "The stage is null!" << std::endl; - return; - } - if (stage == "fp") { - idb::IdbDie* idb_die = dmInst->get_idb_lef_service()->get_layout()->get_die(); - std::vector& idb_instance_list = dmInst->get_idb_def_service()->get_design()->get_instance_list()->get_instance_list(); - idb::IdbRows* idb_rows = dmInst->get_idb_def_service()->get_layout()->get_rows(); - std::vector& idb_layers = dmInst->get_idb_lef_service()->get_layout()->get_layers()->get_layers(); - - std::vector db_json_list; - { - nlohmann::json die_json; - die_json["die"] = {idb_die->get_llx(), idb_die->get_lly(), idb_die->get_urx(), idb_die->get_ury()}; - db_json_list.push_back(die_json); - } - { - for (idb::IdbInstance* idb_instance : idb_instance_list) { - if (!idb_instance->is_fixed()) { - continue; - } - nlohmann::json instance_json; - instance_json["name"] = idb_instance->get_name(); - instance_json["bbox"] = {idb_instance->get_bounding_box()->get_low_x(), idb_instance->get_bounding_box()->get_low_y(), - idb_instance->get_bounding_box()->get_high_x(), idb_instance->get_bounding_box()->get_high_y()}; - std::set layer_name_set; - for (idb::IdbObs* idb_obs : idb_instance->get_cell_master()->get_obs_list()) { - for (idb::IdbObsLayer* idb_layer : idb_obs->get_obs_layer_list()) { - layer_name_set.insert(idb_layer->get_shape()->get_layer()->get_name()); - } - } - for (idb::IdbLayerShape* obs_box : idb_instance->get_obs_box_list()) { - layer_name_set.insert(obs_box->get_layer()->get_name()); - } - for (idb::IdbPin* idb_pin : idb_instance->get_pin_list()->get_pin_list()) { - for (idb::IdbLayerShape* port_box : idb_pin->get_port_box_list()) { - layer_name_set.insert(port_box->get_layer()->get_name()); - } - for (idb::IdbVia* idb_via : idb_pin->get_via_list()) { - idb::IdbLayerShape idb_shape_top = idb_via->get_top_layer_shape(); - layer_name_set.insert(idb_shape_top.get_layer()->get_name()); - idb::IdbLayerShape idb_shape_bottom = idb_via->get_bottom_layer_shape(); - layer_name_set.insert(idb_shape_bottom.get_layer()->get_name()); - idb::IdbLayerShape idb_shape_cut = idb_via->get_cut_layer_shape(); - layer_name_set.insert(idb_shape_cut.get_layer()->get_name()); - } - } - instance_json["layer"] = layer_name_set; - instance_json["type"] = ((idb_instance->get_cell_master()->get_type() == idb::CellMasterType::kPad) ? "io_cell" : "core"); - db_json_list.push_back(instance_json); - } - } - { - std::string layer_name = "null"; - for (idb::IdbLayer* idb_layer : idb_layers) { - if (idb_layer->is_routing()) { - idb::IdbLayerRouting* idb_routing_layer = dynamic_cast(idb_layer); - layer_name = idb_routing_layer->get_name(); - break; - } - } - for (idb::IdbRow* idb_row : idb_rows->get_row_list()) { - idb::IdbCoordinate* idb_coord = idb_row->get_original_coordinate(); - nlohmann::json row_json; - row_json["name"] = idb_row->get_name(); - row_json["bbox"] - = {idb_coord->get_x(), idb_coord->get_y(), idb_coord->get_x() + (idb_row->get_row_num_x() * idb_row->get_step_x()), idb_coord->get_y()}; - row_json["layer"] = layer_name; - row_json["type"] = "row"; - db_json_list.push_back(row_json); - } - } - std::string db_json_file_path = RTUTIL.getString(RTUTIL.getConfigValue(config_map, "-json_file_path", "null")); - std::ofstream* db_json_file = RTUTIL.getOutputFileStream(db_json_file_path); - (*db_json_file) << db_json_list; - RTUTIL.closeFileStream(db_json_file); - } - - { - // std::vector db_json_list; - // { - // nlohmann::json die_json; - // die_json["die"] = {idb_die->get_llx(), idb_die->get_lly(), idb_die->get_urx(), idb_die->get_ury()}; - // db_json_list.push_back(die_json); - // } - // { - // nlohmann::json env_shape_json; - // // instance - // for (idb::IdbInstance* idb_instance : idb_instance_list) { - // if (idb_instance->is_unplaced()) { - // continue; - // } - // if (idb_instance->get_cell_master()->is_pad() || idb_instance->get_cell_master()->is_pad_filler()) { - // idb_instance->get_name(); - // idb_instance->get_bounding_box(); - - // } else { - // // instance obs - // for (idb::IdbLayerShape* obs_box : idb_instance->get_obs_box_list()) { - // for (idb::IdbRect* rect : obs_box->get_rect_list()) { - // env_shape_json["env_shape"]["obs"]["shape"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), obs_box->get_layer()->get_name()}); - // } - // } - // // instance pin without net - // for (idb::IdbPin* idb_pin : idb_instance->get_pin_list()->get_pin_list()) { - // std::string net_name; - // if (!isSkipping(idb_pin->get_net(), false)) { - // net_name = idb_pin->get_net()->get_net_name(); - // } else { - // net_name = "obs"; - // } - // for (idb::IdbLayerShape* port_box : idb_pin->get_port_box_list()) { - // for (idb::IdbRect* rect : port_box->get_rect_list()) { - // env_shape_json["env_shape"][net_name]["shape"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), port_box->get_layer()->get_name()}); - // } - // } - // for (idb::IdbVia* idb_via : idb_pin->get_via_list()) { - // { - // idb::IdbLayerShape idb_shape_top = idb_via->get_top_layer_shape(); - // idb::IdbRect idb_box_top = idb_shape_top.get_bounding_box(); - // env_shape_json["env_shape"][net_name]["shape"].push_back({idb_box_top.get_low_x(), idb_box_top.get_low_y(), idb_box_top.get_high_x(), - // idb_box_top.get_high_y(), idb_shape_top.get_layer()->get_name()}); - // } - // { - // idb::IdbLayerShape idb_shape_bottom = idb_via->get_bottom_layer_shape(); - // idb::IdbRect idb_box_bottom = idb_shape_bottom.get_bounding_box(); - // env_shape_json["env_shape"][net_name]["shape"].push_back({idb_box_bottom.get_low_x(), idb_box_bottom.get_low_y(), - // idb_box_bottom.get_high_x(), - // idb_box_bottom.get_high_y(), idb_shape_bottom.get_layer()->get_name()}); - // } - // idb::IdbLayerShape idb_shape_cut = idb_via->get_cut_layer_shape(); - // for (idb::IdbRect* idb_rect : idb_shape_cut.get_rect_list()) { - // env_shape_json["env_shape"][net_name]["shape"].push_back( - // {idb_rect->get_low_x(), idb_rect->get_low_y(), idb_rect->get_high_x(), idb_rect->get_high_y(), idb_shape_cut.get_layer()->get_name()}); - // } - // } - // } - // } - // } - // // special net - // for (idb::IdbSpecialNet* idb_net : idb_special_net_list) { - // for (idb::IdbSpecialWire* idb_wire : idb_net->get_wire_list()->get_wire_list()) { - // for (idb::IdbSpecialWireSegment* idb_segment : idb_wire->get_segment_list()) { - // if (idb_segment->is_via()) { - // for (idb::IdbLayerShape layer_shape : {idb_segment->get_via()->get_top_layer_shape(), idb_segment->get_via()->get_bottom_layer_shape()}) { - // for (idb::IdbRect* rect : layer_shape.get_rect_list()) { - // env_shape_json["env_shape"]["obs"]["shape"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), layer_shape.get_layer()->get_name()}); - // } - // } - // idb::IdbLayerShape cut_layer_shape = idb_segment->get_via()->get_cut_layer_shape(); - // for (idb::IdbRect* rect : cut_layer_shape.get_rect_list()) { - // env_shape_json["env_shape"]["obs"]["shape"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), cut_layer_shape.get_layer()->get_name()}); - // } - // } else { - // idb::IdbRect* idb_rect = idb_segment->get_bounding_box(); - // // wire - // env_shape_json["env_shape"]["obs"]["shape"].push_back( - // {idb_rect->get_low_x(), idb_rect->get_low_y(), idb_rect->get_high_x(), idb_rect->get_high_y(), idb_segment->get_layer()->get_name()}); - // } - // } - // } - // } - // // io pin - // for (idb::IdbPin* idb_io_pin : idb_io_pin_list) { - // std::string net_name; - // if (!isSkipping(idb_io_pin->get_net(), false)) { - // net_name = idb_io_pin->get_net()->get_net_name(); - // } else { - // net_name = "obs"; - // } - // for (idb::IdbLayerShape* port_box : idb_io_pin->get_port_box_list()) { - // for (idb::IdbRect* rect : port_box->get_rect_list()) { - // env_shape_json["env_shape"][net_name]["shape"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), port_box->get_layer()->get_name()}); - // } - // } - // } - // db_json_list.push_back(env_shape_json); - // } - // { - // nlohmann::json result_shape_json; - // // net - // for (idb::IdbNet* idb_net : idb_net_list) { - // for (idb::IdbRegularWire* idb_wire : idb_net->get_wire_list()->get_wire_list()) { - // for (idb::IdbRegularWireSegment* idb_segment : idb_wire->get_segment_list()) { - // if (idb_segment->get_point_number() >= 2) { - // PlanarCoord first_coord(idb_segment->get_point_start()->get_x(), idb_segment->get_point_start()->get_y()); - // PlanarCoord second_coord(idb_segment->get_point_second()->get_x(), idb_segment->get_point_second()->get_y()); - // int32_t half_width = dynamic_cast(idb_segment->get_layer())->get_width() / 2; - // PlanarRect rect = RTUTIL.getEnlargedRect(first_coord, second_coord, half_width); - // result_shape_json["result_shape"][idb_net->get_net_name()]["path"].push_back( - // {rect.get_ll_x(), rect.get_ll_y(), rect.get_ur_x(), rect.get_ur_y(), idb_segment->get_layer()->get_name()}); - // } - // if (idb_segment->is_via()) { - // for (idb::IdbVia* idb_via : idb_segment->get_via_list()) { - // for (idb::IdbLayerShape layer_shape : {idb_via->get_top_layer_shape(), idb_via->get_bottom_layer_shape()}) { - // for (idb::IdbRect* rect : layer_shape.get_rect_list()) { - // result_shape_json["result_shape"][idb_net->get_net_name()]["path"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), layer_shape.get_layer()->get_name()}); - // } - // } - // idb::IdbLayerShape cut_layer_shape = idb_via->get_cut_layer_shape(); - // for (idb::IdbRect* rect : cut_layer_shape.get_rect_list()) { - // result_shape_json["result_shape"][idb_net->get_net_name()]["path"].push_back( - // {rect->get_low_x(), rect->get_low_y(), rect->get_high_x(), rect->get_high_y(), cut_layer_shape.get_layer()->get_name()}); - // } - // } - // } - // if (idb_segment->is_rect()) { - // PlanarCoord offset_coord(idb_segment->get_point_start()->get_x(), idb_segment->get_point_start()->get_y()); - // PlanarRect delta_rect(idb_segment->get_delta_rect()->get_low_x(), idb_segment->get_delta_rect()->get_low_y(), - // idb_segment->get_delta_rect()->get_high_x(), idb_segment->get_delta_rect()->get_high_y()); - // PlanarRect rect = RTUTIL.getOffsetRect(delta_rect, offset_coord); - // result_shape_json["result_shape"][idb_net->get_net_name()]["patch"].push_back( - // {rect.get_ll_x(), rect.get_ll_y(), rect.get_ur_x(), rect.get_ur_y(), idb_segment->get_layer()->get_name()}); - // } - // } - // } - // } - // db_json_list.push_back(result_shape_json); - // } - // std::string db_json_file_path = RTUTIL.getString(RTUTIL.getConfigValue(config_map, "-json_file_path", "null")); - // std::ofstream* db_json_file = RTUTIL.getOutputFileStream(db_json_file_path); - // (*db_json_file) << db_json_list; - // RTUTIL.closeFileStream(db_json_file); - } + std::cout << "fix fanout" << std::endl; } #endif diff --git a/src/operation/iRT/interface/RTInterface.hpp b/src/operation/iRT/interface/RTInterface.hpp index b7bbacf0c..e38f17229 100644 --- a/src/operation/iRT/interface/RTInterface.hpp +++ b/src/operation/iRT/interface/RTInterface.hpp @@ -80,7 +80,7 @@ class RTInterface void runRT(); void destroyRT(); void clearDef(); - void outputDBJson(std::map config_map); + void fixFanout(); #endif #endif -- Gitee From 8ef1ffa400a7456f324e1827c0327efbbcf3d479 Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Mon, 15 Sep 2025 10:08:53 +0000 Subject: [PATCH 02/19] update --- src/database/data/design/db_design/IdbNet.cpp | 7 ++ .../src/module/density/density_eval.cpp | 1 + src/operation/iRT/interface/RTInterface.cpp | 68 ++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/database/data/design/db_design/IdbNet.cpp b/src/database/data/design/db_design/IdbNet.cpp index 4d087bf82..9e8626055 100644 --- a/src/database/data/design/db_design/IdbNet.cpp +++ b/src/database/data/design/db_design/IdbNet.cpp @@ -140,6 +140,13 @@ IdbPin* IdbNet::get_driving_pin() // } // } + if (!_io_pin_list->get_pin_list().empty()) { + return _io_pin_list->get_pin_list().front(); + } + if (!_instance_pin_list->get_pin_list().empty()) { + return _instance_pin_list->get_pin_list().front(); + } + std::cout << "Error : No driver pin exist..." << std::endl; return nullptr; } diff --git a/src/evaluation/src/module/density/density_eval.cpp b/src/evaluation/src/module/density/density_eval.cpp index d41dcf8f4..f907a94f8 100644 --- a/src/evaluation/src/module/density/density_eval.cpp +++ b/src/evaluation/src/module/density/density_eval.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index fa7395c69..0da4b2149 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -280,7 +280,73 @@ void RTInterface::clearDef() void RTInterface::fixFanout() { - std::cout << "fix fanout" << std::endl; + idb::IdbNetList* idb_net_list = dmInst->get_idb_def_service()->get_design()->get_net_list(); + idb::IdbInstanceList* idb_instance_list = dmInst->get_idb_def_service()->get_design()->get_instance_list(); + idb::IdbCellMasterList* idb_cell_master_list = dmInst->get_idb_def_service()->get_layout()->get_cell_master_list(); + + size_t max_fanout = 16; + while (true) { + std::set origin_net_set; + for (idb::IdbNet* idb_net : idb_net_list->get_net_list()) { + if (idb_net->get_load_pins().size() > max_fanout) { + origin_net_set.insert(idb_net); + } + } + if (origin_net_set.empty()) { + break; + } + size_t begin_net_num = idb_net_list->get_num(); + for (idb::IdbNet* origin_net : origin_net_set) { + // 解开所有的pin + std::vector load_pin_list = origin_net->get_load_pins(); + for (idb::IdbPin* load_pin : load_pin_list) { + origin_net->remove_pin(load_pin); + } + std::vector> load_pin_list_list; + for (size_t i = 0; i < load_pin_list.size(); i += max_fanout) { + size_t end = std::min(i + max_fanout, load_pin_list.size()); + load_pin_list_list.emplace_back(load_pin_list.begin() + i, load_pin_list.begin() + end); + } + for (std::vector& load_pin_list : load_pin_list_list) { + static size_t new_idx = 0; + // 生成net + idb::IdbNet* new_net = new IdbNet(); + new_net->set_net_name(RTUTIL.getString("rt_fanout_net_", new_idx++)); + idb_net_list->add_net(new_net); + // 生成buf + idb::IdbInstance* new_buf = new IdbInstance(); + new_buf->set_name(RTUTIL.getString("rt_fanout_buf_", new_idx++)); + new_buf->set_cell_master(idb_cell_master_list->find_cell_master(RTUTIL.getString("BUFFD8BWP30P140LVT"))); + idb_instance_list->add_instance(new_buf); + // 连接buf + for (idb::IdbPin* buf_pin : new_buf->get_pin_list()->get_pin_list()) { + if (buf_pin->get_term()->get_type() == idb::IdbConnectType::kPower || buf_pin->get_term()->get_type() == idb::IdbConnectType::kGround) { + continue; + } + if (buf_pin->get_term()->get_direction() == idb::IdbConnectDirection::kInput) { + origin_net->add_instance_pin(buf_pin); + buf_pin->set_net(origin_net); + buf_pin->set_net_name(origin_net->get_net_name()); + } else if (buf_pin->get_term()->get_direction() == idb::IdbConnectDirection::kOutput) { + new_net->add_instance_pin(buf_pin); + buf_pin->set_net(new_net); + buf_pin->set_net_name(new_net->get_net_name()); + } + } + // 连接pin + for (idb::IdbPin* load_pin : load_pin_list) { + if (load_pin->is_io_pin()) { + new_net->add_io_pin(load_pin); + } else { + new_net->add_instance_pin(load_pin); + } + load_pin->set_net(new_net); + load_pin->set_net_name(new_net->get_net_name()); + } + } + } + RTLOG.info(Loc::current(), "Fixed ", origin_net_set.size(), " nets!( +", idb_net_list->get_num() - begin_net_num, " nets )"); + } } #endif -- Gitee From 45daf1251268cac2b1181f7f707a760eb0930c2e Mon Sep 17 00:00:00 2001 From: jixiao <2655432410@qq.com> Date: Tue, 16 Sep 2025 14:57:57 +0800 Subject: [PATCH 03/19] update ns_metal --- .../NonsufficientMetalOverlap.cpp | 130 ++++++++++-------- 1 file changed, 71 insertions(+), 59 deletions(-) diff --git a/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp b/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp index a52ae7e36..9bcf0d08a 100644 --- a/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp +++ b/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp @@ -24,7 +24,7 @@ void RuleValidator::verifyNonsufficientMetalOverlap(RVBox& rv_box) std::map>> routing_net_rect_map; for (DRCShape* drc_shape : rv_box.get_drc_env_shape_list()) { - if (!drc_shape->get_is_routing() || drc_shape->get_net_idx() == -1) { + if (!drc_shape->get_is_routing()) { continue; } routing_net_rect_map[drc_shape->get_layer_idx()][drc_shape->get_net_idx()].push_back(drc_shape->get_rect()); @@ -36,79 +36,91 @@ void RuleValidator::verifyNonsufficientMetalOverlap(RVBox& rv_box) routing_net_rect_map[drc_shape->get_layer_idx()][drc_shape->get_net_idx()].push_back(drc_shape->get_rect()); } for (auto& [routing_layer_idx, net_rect_map] : routing_net_rect_map) { - RoutingLayer& routing_layer = routing_layer_list[routing_layer_idx]; - int32_t min_width = routing_layer.get_nonsufficient_metal_overlap_rule().min_width; - int32_t half_width = min_width / 2; for (auto& [net_idx, rect_list] : net_rect_map) { - std::map scale_gtl_poly_set_map; + GTLPolySetInt gtl_poly_set; for (PlanarRect& rect : rect_list) { - PlanarCoord mid_coord = rect.getMidPoint(); - if (routing_layer.isPreferH()) { - scale_gtl_poly_set_map[mid_coord.get_y()] += DRCUTIL.convertToGTLRectInt(rect); - } else { - scale_gtl_poly_set_map[mid_coord.get_x()] += DRCUTIL.convertToGTLRectInt(rect); - } + gtl_poly_set += DRCUTIL.convertToGTLRectInt(rect); } rect_list.clear(); - for (auto& [scale, gtl_poly_set] : scale_gtl_poly_set_map) { - std::vector gtl_rect_list; - gtl::get_max_rectangles(gtl_rect_list, gtl_poly_set); - for (GTLRectInt& gtl_rect : gtl_rect_list) { - rect_list.push_back(DRCUTIL.convertToPlanarRect(gtl_rect)); - } + std::vector gtl_rect_list; + gtl::get_max_rectangles(gtl_rect_list, gtl_poly_set); + for (GTLRectInt& gtl_rect : gtl_rect_list) { + rect_list.push_back(DRCUTIL.convertToPlanarRect(gtl_rect)); } - std::map rect_overlap_gtl_poly_set_map; - for (size_t i = 0; i < rect_list.size(); i++) { - for (size_t j = i + 1; j < rect_list.size(); j++) { - if (!DRCUTIL.isClosedOverlap(rect_list[i], rect_list[j])) { - continue; - } - GTLRectInt gtl_rect = DRCUTIL.convertToGTLRectInt(DRCUTIL.getEnlargedRect(DRCUTIL.getOverlap(rect_list[i], rect_list[j]), 1)); - rect_overlap_gtl_poly_set_map[static_cast(i)] += gtl_rect; - rect_overlap_gtl_poly_set_map[static_cast(j)] += gtl_rect; - } + } + } + std::map>>> routing_net_bg_rtree_map; + for (auto& [routing_layer_idx, net_rect_map] : routing_net_rect_map) { + for (auto& [net_idx, rect_list] : net_rect_map) { + for (PlanarRect& rect : rect_list) { + routing_net_bg_rtree_map[routing_layer_idx][net_idx].insert(DRCUTIL.convertToBGRectInt(rect)); } - std::vector overlap_rect_list; - for (auto& [rect_idx, overlap_gtl_poly_set] : rect_overlap_gtl_poly_set_map) { - std::vector gtl_poly_list; - overlap_gtl_poly_set.get_polygons(gtl_poly_list); - for (GTLPolyInt& gtl_poly : gtl_poly_list) { - GTLRectInt gtl_rect; - gtl::extents(gtl_rect, gtl_poly); - PlanarRect overlap_rect = DRCUTIL.convertToPlanarRect(gtl_rect); - if (!DRCUTIL.hasShrinkedRect(overlap_rect, 1)) { + } + } + for (auto& [routing_layer_idx, net_rect_map] : routing_net_rect_map) { + RoutingLayer& routing_layer = routing_layer_list[routing_layer_idx]; + int32_t min_width = routing_layer.get_minimum_width_rule().min_width; + int32_t half_width = min_width / 2; + for (auto& [net_idx, rect_list] : net_rect_map) { + for (PlanarRect& rect : rect_list) { + std::vector bg_rect_list; + { + PlanarRect check_rect = rect; + routing_net_bg_rtree_map[routing_layer_idx][net_idx].query(bgi::intersects(DRCUTIL.convertToBGRectInt(check_rect)), std::back_inserter(bg_rect_list)); + } + for (auto& bg_env_rect : bg_rect_list) { + PlanarRect env_rect = DRCUTIL.convertToPlanarRect(bg_env_rect); + if (!DRCUTIL.isClosedOverlap(rect, env_rect)) { continue; } - overlap_rect = DRCUTIL.getShrinkedRect(overlap_rect, 1); - if (rect_list[rect_idx].getArea() <= overlap_rect.getArea()) { + if (env_rect == rect) { continue; } + PlanarRect overlap_rect = DRCUTIL.getOverlap(rect, env_rect); double diag_length = std::hypot(overlap_rect.getXSpan(), overlap_rect.getYSpan()); if (diag_length >= min_width) { continue; } - overlap_rect_list.push_back(overlap_rect); - } - } - for (PlanarRect& overlap_rect : overlap_rect_list) { - int32_t x_enlarge_size = 0; - if (overlap_rect.getXSpan() < half_width) { - x_enlarge_size = half_width - overlap_rect.getXSpan(); - } - int32_t y_enlarge_size = 0; - if (overlap_rect.getYSpan() < half_width) { - y_enlarge_size = half_width - overlap_rect.getYSpan(); - } - PlanarRect violation_rect = DRCUTIL.getEnlargedRect(overlap_rect, x_enlarge_size, y_enlarge_size, x_enlarge_size, y_enlarge_size); + if (overlap_rect.get_ll() == overlap_rect.get_ur()) { + continue; + } + std::vector overlap_rect_env_list; + { + PlanarRect check_rect = overlap_rect; + routing_net_bg_rtree_map[routing_layer_idx][net_idx].query(bgi::intersects(DRCUTIL.convertToBGRectInt(check_rect)), + std::back_inserter(overlap_rect_env_list)); + } + bool is_inside = false; + for (auto& overlap_rect_env : overlap_rect_env_list) { + PlanarRect thirdrect = DRCUTIL.convertToPlanarRect(overlap_rect_env); + if ((DRCUTIL.isInside(thirdrect, overlap_rect) && DRCUTIL.isOpenOverlap(thirdrect, overlap_rect)) && thirdrect != rect && thirdrect != env_rect + && thirdrect.getWidth() >= min_width && DRCUTIL.getOverlap(thirdrect, rect) != overlap_rect && DRCUTIL.getOverlap(thirdrect, env_rect) != overlap_rect) { + is_inside = true; + break; + } + } + if (is_inside) { + continue; + } + int32_t x_enlarge_size = 0; + if (overlap_rect.getXSpan() < half_width) { + x_enlarge_size = half_width - overlap_rect.getXSpan(); + } + int32_t y_enlarge_size = 0; + if (overlap_rect.getYSpan() < half_width) { + y_enlarge_size = half_width - overlap_rect.getYSpan(); + } + PlanarRect violation_rect = DRCUTIL.getEnlargedRect(overlap_rect, x_enlarge_size, y_enlarge_size, x_enlarge_size, y_enlarge_size); - Violation violation; - violation.set_violation_type(ViolationType::kNonsufficientMetalOverlap); - violation.set_is_routing(true); - violation.set_violation_net_set({net_idx}); - violation.set_required_size(0); - violation.set_layer_idx(routing_layer_idx); - violation.set_rect(violation_rect); - rv_box.get_violation_list().push_back(violation); + Violation violation; + violation.set_violation_type(ViolationType::kNonsufficientMetalOverlap); + violation.set_is_routing(true); + violation.set_violation_net_set({net_idx}); + violation.set_required_size(0); + violation.set_layer_idx(routing_layer_idx); + violation.set_rect(violation_rect); + rv_box.get_violation_list().push_back(violation); + } } } } -- Gitee From 679ccacd3f09f3436a43edf4ddf7e01204847169 Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Fri, 19 Sep 2025 08:22:05 +0000 Subject: [PATCH 04/19] add mem --- src/operation/iRT/interface/RTInterface.cpp | 2 + .../iRT/source/data_manager/advance/Pin.hpp | 3 + .../module/detailed_router/DetailedRouter.cpp | 77 +++++++++--- .../module/detailed_router/DetailedRouter.hpp | 2 +- .../module/pin_accessor/PinAccessor.cpp | 117 ++++++++++++++---- .../module/pin_accessor/PinAccessor.hpp | 2 +- .../module/track_assigner/TrackAssigner.cpp | 13 +- 7 files changed, 171 insertions(+), 45 deletions(-) diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index 0da4b2149..a6b09c8b3 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -990,6 +990,7 @@ void RTInterface::wrapPinList(Net& net, idb::IdbNet* idb_net) } Pin pin; pin.set_pin_name(RTUTIL.getString(idb_pin->get_instance()->get_name(), ":", idb_pin->get_pin_name())); + pin.set_is_core(idb_pin->get_instance()->get_cell_master()->is_core()); wrapPinShapeList(pin, idb_pin); pin_list.push_back(std::move(pin)); } @@ -999,6 +1000,7 @@ void RTInterface::wrapPinList(Net& net, idb::IdbNet* idb_net) } Pin pin; pin.set_pin_name(idb_pin->get_pin_name()); + pin.set_is_core(false); wrapPinShapeList(pin, idb_pin); pin_list.push_back(std::move(pin)); } diff --git a/src/operation/iRT/source/data_manager/advance/Pin.hpp b/src/operation/iRT/source/data_manager/advance/Pin.hpp index fed6c352d..89d032ec8 100644 --- a/src/operation/iRT/source/data_manager/advance/Pin.hpp +++ b/src/operation/iRT/source/data_manager/advance/Pin.hpp @@ -31,6 +31,7 @@ class Pin // getter int32_t get_pin_idx() const { return _pin_idx; } std::string& get_pin_name() { return _pin_name; } + bool get_is_core() const { return _is_core; } std::vector& get_routing_shape_list() { return _routing_shape_list; } std::vector& get_cut_shape_list() { return _cut_shape_list; } bool get_is_driven() const { return _is_driven; } @@ -38,6 +39,7 @@ class Pin // setter void set_pin_idx(const int32_t pin_idx) { _pin_idx = pin_idx; } void set_pin_name(const std::string& pin_name) { _pin_name = pin_name; } + void set_is_core(const bool is_core) { _is_core = is_core; } void set_routing_shape_list(const std::vector& routing_shape_list) { _routing_shape_list = routing_shape_list; } void set_cut_shape_list(const std::vector& cut_shape_list) { _cut_shape_list = cut_shape_list; } void set_is_driven(const bool is_driven) { _is_driven = is_driven; } @@ -47,6 +49,7 @@ class Pin private: int32_t _pin_idx = -1; std::string _pin_name; + bool _is_core = false; std::vector _routing_shape_list; std::vector _cut_shape_list; bool _is_driven = false; diff --git a/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp b/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp index 99558478a..83dbf5f26 100644 --- a/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp +++ b/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp @@ -382,7 +382,7 @@ void DetailedRouter::routeDRBoxMap(DRModel& dr_model) buildDRNodeNeighbor(dr_box); buildOrientNetMap(dr_box); buildNetShadowMap(dr_box); - exemptPinShape(dr_box); + exemptPinShape(dr_model, dr_box); // debugCheckDRBox(dr_box); // debugPlotDRBox(dr_box, "before"); routeDRBox(dr_box); @@ -837,28 +837,71 @@ void DetailedRouter::buildNetShadowMap(DRBox& dr_box) } } -void DetailedRouter::exemptPinShape(DRBox& dr_box) +void DetailedRouter::exemptPinShape(DRModel& dr_model, DRBox& dr_box) { + int32_t detection_distance = RTDM.getDatabase().get_detection_distance(); + std::vector& dr_net_list = dr_model.get_dr_net_list(); ScaleAxis& box_track_axis = dr_box.get_box_track_axis(); std::vector>& layer_node_map = dr_box.get_layer_node_map(); - for (auto& [net_idx, access_point_set] : dr_box.get_net_access_point_map()) { - for (AccessPoint* access_point : access_point_set) { - if (!RTUTIL.existTrackGrid(access_point->get_real_coord(), box_track_axis)) { - continue; + for (auto& [dr_net_idx, access_point_set] : dr_box.get_net_access_point_map()) { + std::map> routing_obs_rect_map; + for (auto& [routing_layer_idx, net_fixed_rect_map] : dr_box.get_type_layer_net_fixed_rect_map()[true]) { + for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { + if (dr_net_idx == net_idx) { + continue; + } + for (auto& fixed_rect : fixed_rect_set) { + routing_obs_rect_map[routing_layer_idx].push_back(fixed_rect); + } } - PlanarCoord grid_coord = RTUTIL.getTrackGrid(access_point->get_real_coord(), box_track_axis); - DRNode& dr_node = layer_node_map[access_point->get_layer_idx()][grid_coord.get_x()][grid_coord.get_y()]; - for (auto& [orient, net_set] : dr_node.get_orient_fixed_rect_map()) { - if (orient == Orientation::kAbove || orient == Orientation::kBelow) { - net_set.erase(-1); - DRNode* neighbor_node = dr_node.getNeighborNode(orient); - if (neighbor_node == nullptr) { - continue; + } + std::vector& dr_pin_list = dr_net_list[dr_net_idx].get_dr_pin_list(); + for (AccessPoint* access_point : access_point_set) { + if (dr_pin_list[access_point->get_pin_idx()].get_is_core()) { + if (!RTUTIL.existTrackGrid(access_point->get_real_coord(), box_track_axis)) { + continue; + } + PlanarCoord grid_coord = RTUTIL.getTrackGrid(access_point->get_real_coord(), box_track_axis); + DRNode& dr_node = layer_node_map[access_point->get_layer_idx()][grid_coord.get_x()][grid_coord.get_y()]; + for (auto& [orient, net_set] : dr_node.get_orient_fixed_rect_map()) { + if (orient == Orientation::kAbove || orient == Orientation::kBelow) { + net_set.erase(-1); + DRNode* neighbor_node = dr_node.getNeighborNode(orient); + if (neighbor_node == nullptr) { + continue; + } + Orientation oppo_orientation = RTUTIL.getOppositeOrientation(orient); + if (RTUTIL.exist(neighbor_node->get_orient_fixed_rect_map(), oppo_orientation)) { + neighbor_node->get_orient_fixed_rect_map()[oppo_orientation].erase(-1); + } } - Orientation oppo_orientation = RTUTIL.getOppositeOrientation(orient); - if (RTUTIL.exist(neighbor_node->get_orient_fixed_rect_map(), oppo_orientation)) { - neighbor_node->get_orient_fixed_rect_map()[oppo_orientation].erase(-1); + } + } else { + PlanarRect real_rect = RTUTIL.getEnlargedRect(access_point->get_real_coord(), detection_distance); + if (!RTUTIL.existTrackGrid(real_rect, box_track_axis)) { + continue; + } + PlanarRect grid_rect = RTUTIL.getTrackGrid(real_rect, box_track_axis); + for (int32_t x = grid_rect.get_ll_x(); x <= grid_rect.get_ur_x(); x++) { + for (int32_t y = grid_rect.get_ll_y(); y <= grid_rect.get_ur_y(); y++) { + DRNode& dr_node = layer_node_map[access_point->get_layer_idx()][x][y]; + + bool within_shape = false; + for (EXTLayerRect* obs_rect : routing_obs_rect_map[dr_node.get_layer_idx()]) { + if (RTUTIL.isInside(obs_rect->get_real_rect(), dr_node.get_planar_coord())) { + within_shape = true; + break; + } + } + if (within_shape) { + continue; + } + for (auto& [orient, net_set] : dr_node.get_orient_fixed_rect_map()) { + if (orient == Orientation::kEast || orient == Orientation::kWest || orient == Orientation::kSouth || orient == Orientation::kNorth) { + net_set.erase(-1); + } + } } } } diff --git a/src/operation/iRT/source/module/detailed_router/DetailedRouter.hpp b/src/operation/iRT/source/module/detailed_router/DetailedRouter.hpp index 5b4c218e8..d1fc35f8a 100644 --- a/src/operation/iRT/source/module/detailed_router/DetailedRouter.hpp +++ b/src/operation/iRT/source/module/detailed_router/DetailedRouter.hpp @@ -77,7 +77,7 @@ class DetailedRouter void buildDRNodeNeighbor(DRBox& dr_box); void buildOrientNetMap(DRBox& dr_box); void buildNetShadowMap(DRBox& dr_box); - void exemptPinShape(DRBox& dr_box); + void exemptPinShape(DRModel& dr_model, DRBox& dr_box); void routeDRBox(DRBox& dr_box); std::vector initTaskSchedule(DRBox& dr_box); void updateGraph(DRBox& dr_box, DRTask* dr_task); diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp index 6038a7954..c6e2e1f05 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp @@ -159,14 +159,26 @@ void PinAccessor::initAccessPointList(PAModel& pa_model) int32_t curr_layer_idx = access_point.get_layer_idx(); // 构建目标层 std::vector point_layer_idx_list; - if (curr_layer_idx < bottom_routing_layer_idx) { - point_layer_idx_list.push_back(bottom_routing_layer_idx + 1); - } else if (top_routing_layer_idx < curr_layer_idx) { - point_layer_idx_list.push_back(top_routing_layer_idx - 1); - } else if (curr_layer_idx < top_routing_layer_idx) { - point_layer_idx_list.push_back(curr_layer_idx + 1); + if (pa_pin->get_is_core()) { + if (curr_layer_idx < bottom_routing_layer_idx) { + point_layer_idx_list.push_back(bottom_routing_layer_idx + 1); + } else if (top_routing_layer_idx < curr_layer_idx) { + point_layer_idx_list.push_back(top_routing_layer_idx - 1); + } else if (curr_layer_idx < top_routing_layer_idx) { + point_layer_idx_list.push_back(curr_layer_idx + 1); + } else { + point_layer_idx_list.push_back(curr_layer_idx - 1); + } } else { - point_layer_idx_list.push_back(curr_layer_idx - 1); + if (curr_layer_idx < bottom_routing_layer_idx) { + point_layer_idx_list.push_back(bottom_routing_layer_idx); + } else if (top_routing_layer_idx < curr_layer_idx) { + point_layer_idx_list.push_back(top_routing_layer_idx); + } else if (curr_layer_idx < top_routing_layer_idx) { + point_layer_idx_list.push_back(curr_layer_idx); + } else { + point_layer_idx_list.push_back(curr_layer_idx); + } } // 构建搜索形状 PlanarRect real_rect = RTUTIL.getEnlargedRect(access_point.get_real_coord(), detection_distance); @@ -710,7 +722,7 @@ void PinAccessor::routePABoxMap(PAModel& pa_model) buildPANodeNeighbor(pa_box); buildOrientNetMap(pa_box); buildNetShadowMap(pa_box); - exemptPinShape(pa_box); + exemptPinShape(pa_model, pa_box); // debugCheckPABox(pa_box); // debugPlotPABox(pa_box, "before"); routePABox(pa_box); @@ -1235,28 +1247,72 @@ void PinAccessor::buildNetShadowMap(PABox& pa_box) } } -void PinAccessor::exemptPinShape(PABox& pa_box) +void PinAccessor::exemptPinShape(PAModel& pa_model, PABox& pa_box) { + int32_t detection_distance = RTDM.getDatabase().get_detection_distance(); + std::vector& pa_net_list = pa_model.get_pa_net_list(); ScaleAxis& box_track_axis = pa_box.get_box_track_axis(); std::vector>& layer_node_map = pa_box.get_layer_node_map(); - for (auto& [net_idx, access_point_set] : pa_box.get_net_access_point_map()) { - for (AccessPoint* access_point : access_point_set) { - if (!RTUTIL.existTrackGrid(access_point->get_real_coord(), box_track_axis)) { - continue; + for (auto& [pa_net_idx, access_point_set] : pa_box.get_net_access_point_map()) { + std::map> routing_obs_rect_map; + for (auto& [routing_layer_idx, net_fixed_rect_map] : pa_box.get_type_layer_net_fixed_rect_map()[true]) { + + for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { + if (pa_net_idx == net_idx) { + continue; + } + for (auto& fixed_rect : fixed_rect_set) { + routing_obs_rect_map[routing_layer_idx].push_back(fixed_rect); + } } - PlanarCoord grid_coord = RTUTIL.getTrackGrid(access_point->get_real_coord(), box_track_axis); - PANode& pa_node = layer_node_map[access_point->get_layer_idx()][grid_coord.get_x()][grid_coord.get_y()]; - for (auto& [orient, net_set] : pa_node.get_orient_fixed_rect_map()) { - if (orient == Orientation::kAbove || orient == Orientation::kBelow) { - net_set.erase(-1); - PANode* neighbor_node = pa_node.getNeighborNode(orient); - if (neighbor_node == nullptr) { - continue; + } + std::vector& pa_pin_list = pa_net_list[pa_net_idx].get_pa_pin_list(); + for (AccessPoint* access_point : access_point_set) { + if (pa_pin_list[access_point->get_pin_idx()].get_is_core()) { + if (!RTUTIL.existTrackGrid(access_point->get_real_coord(), box_track_axis)) { + continue; + } + PlanarCoord grid_coord = RTUTIL.getTrackGrid(access_point->get_real_coord(), box_track_axis); + PANode& pa_node = layer_node_map[access_point->get_layer_idx()][grid_coord.get_x()][grid_coord.get_y()]; + for (auto& [orient, net_set] : pa_node.get_orient_fixed_rect_map()) { + if (orient == Orientation::kAbove || orient == Orientation::kBelow) { + net_set.erase(-1); + PANode* neighbor_node = pa_node.getNeighborNode(orient); + if (neighbor_node == nullptr) { + continue; + } + Orientation oppo_orientation = RTUTIL.getOppositeOrientation(orient); + if (RTUTIL.exist(neighbor_node->get_orient_fixed_rect_map(), oppo_orientation)) { + neighbor_node->get_orient_fixed_rect_map()[oppo_orientation].erase(-1); + } } - Orientation oppo_orientation = RTUTIL.getOppositeOrientation(orient); - if (RTUTIL.exist(neighbor_node->get_orient_fixed_rect_map(), oppo_orientation)) { - neighbor_node->get_orient_fixed_rect_map()[oppo_orientation].erase(-1); + } + } else { + PlanarRect real_rect = RTUTIL.getEnlargedRect(access_point->get_real_coord(), detection_distance); + if (!RTUTIL.existTrackGrid(real_rect, box_track_axis)) { + continue; + } + PlanarRect grid_rect = RTUTIL.getTrackGrid(real_rect, box_track_axis); + for (int32_t x = grid_rect.get_ll_x(); x <= grid_rect.get_ur_x(); x++) { + for (int32_t y = grid_rect.get_ll_y(); y <= grid_rect.get_ur_y(); y++) { + PANode& pa_node = layer_node_map[access_point->get_layer_idx()][x][y]; + + bool within_shape = false; + for (EXTLayerRect* obs_rect : routing_obs_rect_map[pa_node.get_layer_idx()]) { + if (RTUTIL.isInside(obs_rect->get_real_rect(), pa_node.get_planar_coord())) { + within_shape = true; + break; + } + } + if (within_shape) { + continue; + } + for (auto& [orient, net_set] : pa_node.get_orient_fixed_rect_map()) { + if (orient == Orientation::kEast || orient == Orientation::kWest || orient == Orientation::kSouth || orient == Orientation::kNorth) { + net_set.erase(-1); + } + } } } } @@ -2348,7 +2404,18 @@ void PinAccessor::updateTaskSchedule(PABox& pa_box, std::vector& routin if (!RTUTIL.exist(violation.get_violation_net_set(), pa_task->get_net_idx())) { continue; } - bool result_overlap = RTUTIL.isClosedOverlap(violation_shape.get_real_rect(), pa_task->get_bounding_box()); + bool result_overlap = false; + for (Segment& segment : pa_box.get_net_task_access_result_map()[pa_task->get_net_idx()][pa_task->get_task_idx()]) { + for (NetShape& net_shape : RTDM.getNetDetailedShapeList(pa_task->get_net_idx(), segment)) { + if (violation_shape.get_layer_idx() == net_shape.get_layer_idx() && RTUTIL.isClosedOverlap(violation_shape.get_real_rect(), net_shape.get_rect())) { + result_overlap = true; + break; + } + } + if (result_overlap) { + break; + } + } bool patch_overlap = false; for (EXTLayerRect& patch : pa_box.get_net_task_access_patch_map()[pa_task->get_net_idx()][pa_task->get_task_idx()]) { if (violation_shape.get_layer_idx() == patch.get_layer_idx() && RTUTIL.isClosedOverlap(violation_shape.get_real_rect(), patch.get_real_rect())) { diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.hpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.hpp index 70835aaee..ffa7807d0 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.hpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.hpp @@ -83,7 +83,7 @@ class PinAccessor void buildPANodeNeighbor(PABox& pa_box); void buildOrientNetMap(PABox& pa_box); void buildNetShadowMap(PABox& pa_box); - void exemptPinShape(PABox& pa_box); + void exemptPinShape(PAModel& pa_model, PABox& pa_box); void routePABox(PABox& pa_box); std::vector initTaskSchedule(PABox& pa_box); void updateGraph(PABox& pa_box, PATask* pa_task); diff --git a/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp b/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp index b1da516f2..9274a3fac 100644 --- a/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp +++ b/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp @@ -1077,7 +1077,18 @@ void TrackAssigner::updateTaskSchedule(TAPanel& ta_panel, std::vector& if (!RTUTIL.exist(violation.get_violation_net_set(), ta_task->get_net_idx())) { continue; } - bool result_overlap = RTUTIL.isClosedOverlap(violation_shape.get_real_rect(), ta_task->get_bounding_box()); + bool result_overlap = false; + for (Segment& segment : ta_panel.get_net_task_detailed_result_map()[ta_task->get_net_idx()][ta_task->get_task_idx()]) { + for (NetShape& net_shape : RTDM.getNetDetailedShapeList(ta_task->get_net_idx(), segment)) { + if (violation_shape.get_layer_idx() == net_shape.get_layer_idx() && RTUTIL.isClosedOverlap(violation_shape.get_real_rect(), net_shape.get_rect())) { + result_overlap = true; + break; + } + } + if (result_overlap) { + break; + } + } if (!result_overlap) { continue; } -- Gitee From 85b2a0db59b6ff784ac2b61c697e38bf7e57831f Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Fri, 19 Sep 2025 09:05:41 +0000 Subject: [PATCH 05/19] opt fix rect map --- .../iRT/source/data_manager/DataManager.cpp | 41 +++++++++++++++---- .../iRT/source/data_manager/DataManager.hpp | 1 + .../source/data_manager/advance/Database.hpp | 6 ++- .../data_manager/basic/EXTPlanarRect.hpp | 2 + 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/operation/iRT/source/data_manager/DataManager.cpp b/src/operation/iRT/source/data_manager/DataManager.cpp index 24b635292..0009669e0 100644 --- a/src/operation/iRT/source/data_manager/DataManager.cpp +++ b/src/operation/iRT/source/data_manager/DataManager.cpp @@ -344,21 +344,26 @@ void DataManager::updateViolationToGCellMap(ChangeType change_type, Violation* v std::map>>> DataManager::getTypeLayerNetFixedRectMap(EXTPlanarRect& region) { + Die& die = _database.get_die(); GridMap& gcell_map = _database.get_gcell_map(); - std::map>>> type_layer_net_fixed_rect_map; - for (int32_t x = region.get_grid_ll_x(); x <= region.get_grid_ur_x(); x++) { - for (int32_t y = region.get_grid_ll_y(); y <= region.get_grid_ur_y(); y++) { - for (auto& [is_routing, layer_net_fixed_rect_map] : gcell_map[x][y].get_type_layer_net_fixed_rect_map()) { - for (auto& [layer_idx, net_fixed_rect_map] : layer_net_fixed_rect_map) { - for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { - type_layer_net_fixed_rect_map[is_routing][layer_idx][net_idx].insert(fixed_rect_set.begin(), fixed_rect_set.end()); + if (region == die) { + return _database.get_type_layer_net_fixed_rect_map(); + } else { + std::map>>> type_layer_net_fixed_rect_map; + for (int32_t x = region.get_grid_ll_x(); x <= region.get_grid_ur_x(); x++) { + for (int32_t y = region.get_grid_ll_y(); y <= region.get_grid_ur_y(); y++) { + for (auto& [is_routing, layer_net_fixed_rect_map] : gcell_map[x][y].get_type_layer_net_fixed_rect_map()) { + for (auto& [layer_idx, net_fixed_rect_map] : layer_net_fixed_rect_map) { + for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { + type_layer_net_fixed_rect_map[is_routing][layer_idx][net_idx].insert(fixed_rect_set.begin(), fixed_rect_set.end()); + } } } } } + return type_layer_net_fixed_rect_map; } - return type_layer_net_fixed_rect_map; } std::map> DataManager::getNetAccessPointMap(EXTPlanarRect& region) @@ -738,6 +743,7 @@ void DataManager::buildDatabase() buildNetList(); buildDetectionDistance(); buildGCellMap(); + buildFixRectMap(); } void DataManager::buildLayerList() @@ -1522,6 +1528,25 @@ int32_t DataManager::getBucketIdx(int32_t scale_start, int32_t scale_end, int32_ return start_idx; } +void DataManager::buildFixRectMap() +{ + Die& die = _database.get_die(); + GridMap& gcell_map = _database.get_gcell_map(); + std::map>>>& type_layer_net_fixed_rect_map = _database.get_type_layer_net_fixed_rect_map(); + + for (int32_t x = die.get_grid_ll_x(); x <= die.get_grid_ur_x(); x++) { + for (int32_t y = die.get_grid_ll_y(); y <= die.get_grid_ur_y(); y++) { + for (auto& [is_routing, layer_net_fixed_rect_map] : gcell_map[x][y].get_type_layer_net_fixed_rect_map()) { + for (auto& [layer_idx, net_fixed_rect_map] : layer_net_fixed_rect_map) { + for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { + type_layer_net_fixed_rect_map[is_routing][layer_idx][net_idx].insert(fixed_rect_set.begin(), fixed_rect_set.end()); + } + } + } + } + } +} + void DataManager::printConfig() { ///////////////////////////////////////////// diff --git a/src/operation/iRT/source/data_manager/DataManager.hpp b/src/operation/iRT/source/data_manager/DataManager.hpp index 3c2850ca6..4107e48b7 100644 --- a/src/operation/iRT/source/data_manager/DataManager.hpp +++ b/src/operation/iRT/source/data_manager/DataManager.hpp @@ -124,6 +124,7 @@ class DataManager void initGCellMap(); void updateGCellMap(); int32_t getBucketIdx(int32_t scale_start, int32_t scale_end, int32_t bucket_start, int32_t bucket_end, int32_t bucket_length); + void buildFixRectMap(); void printConfig(); void printDatabase(); void outputScript(); diff --git a/src/operation/iRT/source/data_manager/advance/Database.hpp b/src/operation/iRT/source/data_manager/advance/Database.hpp index b08a95f8a..03dae680f 100644 --- a/src/operation/iRT/source/data_manager/advance/Database.hpp +++ b/src/operation/iRT/source/data_manager/advance/Database.hpp @@ -59,8 +59,9 @@ class Database std::vector& get_routing_obstacle_list() { return _routing_obstacle_list; } std::vector& get_cut_obstacle_list() { return _cut_obstacle_list; } std::vector& get_net_list() { return _net_list; } - GridMap& get_gcell_map() { return _gcell_map; } int32_t get_detection_distance() const { return _detection_distance; } + GridMap& get_gcell_map() { return _gcell_map; } + std::map>>>& get_type_layer_net_fixed_rect_map() { return _type_layer_net_fixed_rect_map; } Summary& get_summary() { return _summary; } // setter void set_design_name(const std::string& design_name) { _design_name = design_name; } @@ -94,8 +95,9 @@ class Database std::vector _routing_obstacle_list; std::vector _cut_obstacle_list; std::vector _net_list; - GridMap _gcell_map; int32_t _detection_distance = -1; + GridMap _gcell_map; + std::map>>> _type_layer_net_fixed_rect_map; Summary _summary; }; diff --git a/src/operation/iRT/source/data_manager/basic/EXTPlanarRect.hpp b/src/operation/iRT/source/data_manager/basic/EXTPlanarRect.hpp index bb710a8a9..7f764e8a6 100644 --- a/src/operation/iRT/source/data_manager/basic/EXTPlanarRect.hpp +++ b/src/operation/iRT/source/data_manager/basic/EXTPlanarRect.hpp @@ -25,6 +25,8 @@ class EXTPlanarRect public: EXTPlanarRect() = default; ~EXTPlanarRect() = default; + bool operator==(const EXTPlanarRect& other) const { return (_grid_rect == other._grid_rect && _real_rect == other._real_rect); } + bool operator!=(const EXTPlanarRect& other) const { return !((*this) == other); } // getter PlanarRect& get_grid_rect() { return _grid_rect; } PlanarCoord& get_grid_ll() { return _grid_rect.get_ll(); } -- Gitee From 5f794332d1f31e7e3f116d66bf3bfe1511605c0d Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Fri, 19 Sep 2025 09:52:10 +0000 Subject: [PATCH 06/19] format --- .../source/module/rule_validator/rv_data_manager/RVBox.hpp | 2 +- .../source/module/rule_validator/rv_data_manager/RVModel.hpp | 1 + .../module/rule_validator/rv_design_rule/MaxViaStack.cpp | 4 ++-- .../rv_design_rule/NonsufficientMetalOverlap.cpp | 3 ++- src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp | 1 - 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVBox.hpp b/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVBox.hpp index ecf60da26..492a7a201 100644 --- a/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVBox.hpp +++ b/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVBox.hpp @@ -19,10 +19,10 @@ #include "DRCShape.hpp" #include "LayerRect.hpp" #include "PlanarRect.hpp" +#include "RVComParam.hpp" #include "RVSummary.hpp" #include "Segment.hpp" #include "Violation.hpp" -#include "RVComParam.hpp" namespace idrc { diff --git a/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVModel.hpp b/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVModel.hpp index 5afe490dd..819db7bb6 100644 --- a/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVModel.hpp +++ b/src/operation/iDRC/source/module/rule_validator/rv_data_manager/RVModel.hpp @@ -45,6 +45,7 @@ class RVModel void set_rv_box_list(const std::vector& rv_box_list) { _rv_box_list = rv_box_list; } void set_violation_list(const std::vector& violation_list) { _violation_list = violation_list; } void set_rv_summary(const RVSummary& rv_summary) { _rv_summary = rv_summary; } + private: std::vector _drc_env_shape_list; std::vector _drc_result_shape_list; diff --git a/src/operation/iDRC/source/module/rule_validator/rv_design_rule/MaxViaStack.cpp b/src/operation/iDRC/source/module/rule_validator/rv_design_rule/MaxViaStack.cpp index 5c68deff9..4776fc80f 100644 --- a/src/operation/iDRC/source/module/rule_validator/rv_design_rule/MaxViaStack.cpp +++ b/src/operation/iDRC/source/module/rule_validator/rv_design_rule/MaxViaStack.cpp @@ -65,7 +65,7 @@ void RuleValidator::verifyMaxViaStack(RVBox& rv_box) std::map>> layer_net_stack_rect_map; layer_net_stack_rect_map[cut_layer_idx].push_back(net_stack_rect_pair); for (int32_t curr_cut_layer_idx = cut_layer_idx; curr_cut_layer_idx < top_cut_layer_idx; curr_cut_layer_idx++) { - std::map> net_used_rect_set; + std::map> net_used_rect_set; for (auto& [net_idx, stack_rect] : layer_net_stack_rect_map[curr_cut_layer_idx]) { std::vector> bg_rect_net_pair_list; PlanarRect check_rect = stack_rect; @@ -75,7 +75,7 @@ void RuleValidator::verifyMaxViaStack(RVBox& rv_box) if (!DRCUTIL.isOpenOverlap(stack_rect, env_rect)) { continue; } - if(DRCUTIL.exist(net_used_rect_set[env_net_idx], env_rect)) { + if (DRCUTIL.exist(net_used_rect_set[env_net_idx], env_rect)) { continue; } layer_net_stack_rect_map[curr_cut_layer_idx + 1].push_back({env_net_idx, env_rect}); diff --git a/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp b/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp index 9bcf0d08a..32b139205 100644 --- a/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp +++ b/src/operation/iDRC/source/module/rule_validator/rv_design_rule/NonsufficientMetalOverlap.cpp @@ -94,7 +94,8 @@ void RuleValidator::verifyNonsufficientMetalOverlap(RVBox& rv_box) for (auto& overlap_rect_env : overlap_rect_env_list) { PlanarRect thirdrect = DRCUTIL.convertToPlanarRect(overlap_rect_env); if ((DRCUTIL.isInside(thirdrect, overlap_rect) && DRCUTIL.isOpenOverlap(thirdrect, overlap_rect)) && thirdrect != rect && thirdrect != env_rect - && thirdrect.getWidth() >= min_width && DRCUTIL.getOverlap(thirdrect, rect) != overlap_rect && DRCUTIL.getOverlap(thirdrect, env_rect) != overlap_rect) { + && thirdrect.getWidth() >= min_width && DRCUTIL.getOverlap(thirdrect, rect) != overlap_rect + && DRCUTIL.getOverlap(thirdrect, env_rect) != overlap_rect) { is_inside = true; break; } diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp index c6e2e1f05..5dfab0e73 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp @@ -1257,7 +1257,6 @@ void PinAccessor::exemptPinShape(PAModel& pa_model, PABox& pa_box) for (auto& [pa_net_idx, access_point_set] : pa_box.get_net_access_point_map()) { std::map> routing_obs_rect_map; for (auto& [routing_layer_idx, net_fixed_rect_map] : pa_box.get_type_layer_net_fixed_rect_map()[true]) { - for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { if (pa_net_idx == net_idx) { continue; -- Gitee From 41f6323325c98f607a6c826fb47d20d8313e9d0a Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Thu, 25 Sep 2025 10:12:37 +0000 Subject: [PATCH 07/19] add mem support --- src/operation/iRT/interface/RTInterface.cpp | 2 +- .../module/pin_accessor/PinAccessor.cpp | 41 ++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index a6b09c8b3..22ad42c0b 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -316,7 +316,7 @@ void RTInterface::fixFanout() // 生成buf idb::IdbInstance* new_buf = new IdbInstance(); new_buf->set_name(RTUTIL.getString("rt_fanout_buf_", new_idx++)); - new_buf->set_cell_master(idb_cell_master_list->find_cell_master(RTUTIL.getString("BUFFD8BWP30P140LVT"))); + new_buf->set_cell_master(idb_cell_master_list->find_cell_master(RTUTIL.getString("BUFFD3BWP35P140LVT"))); idb_instance_list->add_instance(new_buf); // 连接buf for (idb::IdbPin* buf_pin : new_buf->get_pin_list()->get_pin_list()) { diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp index 5dfab0e73..70f1a7879 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp @@ -202,12 +202,27 @@ void PinAccessor::initAccessPointList(PAModel& pa_model) std::vector PinAccessor::getLegalShapeList(PAModel& pa_model, int32_t net_idx, PAPin* pa_pin) { - std::map, std::greater> routing_pin_shape_map; - for (EXTLayerRect& routing_shape : pa_pin->get_routing_shape_list()) { - routing_pin_shape_map[routing_shape.get_layer_idx()].emplace_back(routing_shape); + std::vector>> routing_pin_shape_list; + { + std::map> routing_pin_shape_map; + for (EXTLayerRect& routing_shape : pa_pin->get_routing_shape_list()) { + routing_pin_shape_map[routing_shape.get_layer_idx()].emplace_back(routing_shape); + } + for (auto& [routing_layer_idx, pin_shape_list] : routing_pin_shape_map) { + routing_pin_shape_list.emplace_back(routing_layer_idx, pin_shape_list); + } + } + if (pa_pin->get_is_core()) { + std::sort(routing_pin_shape_list.begin(), routing_pin_shape_list.end(), + [](const std::pair>& a, const std::pair>& b) { return a.first > b.first; }); + } else { + std::sort(routing_pin_shape_list.begin(), routing_pin_shape_list.end(), + [](const std::pair>& a, const std::pair>& b) { + return (a.first % 2 != 0 && b.first % 2 == 0) || (a.first % 2 == b.first % 2 && a.first > b.first); + }); } std::vector legal_rect_list; - for (auto& [routing_layer_idx, pin_shape_list] : routing_pin_shape_map) { + for (auto& [routing_layer_idx, pin_shape_list] : routing_pin_shape_list) { std::vector planar_legal_rect_list = getPlanarLegalRectList(pa_model, net_idx, pa_pin, pin_shape_list); for (PlanarRect planar_legal_rect : RTUTIL.mergeRectListByBoost(planar_legal_rect_list, Direction::kVertical)) { legal_rect_list.emplace_back(planar_legal_rect, routing_layer_idx); @@ -785,14 +800,14 @@ void PinAccessor::initPATaskList(PAModel& pa_model, PABox& pa_box) } } for (auto& [pa_net, pin_access_point_map] : net_pin_access_point_map) { - std::map> routing_obs_rect_map; + std::map> routing_obs_rect_map; for (auto& [routing_layer_idx, net_fixed_rect_map] : pa_box.get_type_layer_net_fixed_rect_map()[true]) { for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { if (pa_net->get_net_idx() == net_idx) { continue; } - for (auto& fixed_rect : fixed_rect_set) { - routing_obs_rect_map[routing_layer_idx].push_back(fixed_rect); + for (EXTLayerRect* fixed_rect : fixed_rect_set) { + routing_obs_rect_map[routing_layer_idx].push_back(RTUTIL.getEnlargedRect(fixed_rect->get_real_rect(), RTDM.getOnlyPitch())); } } } @@ -812,6 +827,10 @@ void PinAccessor::initPATaskList(PAModel& pa_model, PABox& pa_box) continue; } } + std::map> routing_pin_rect_map; + for (EXTLayerRect& routing_shape : pa_pin->get_routing_shape_list()) { + routing_pin_rect_map[routing_shape.get_layer_idx()].push_back(RTUTIL.getEnlargedRect(routing_shape.get_real_rect(), RTDM.getOnlyPitch())); + } std::vector pa_group_list(2); { pa_group_list.front().set_is_target(false); @@ -825,16 +844,16 @@ void PinAccessor::initPATaskList(PAModel& pa_model, PABox& pa_box) } bool within_shape = false; if (!within_shape) { - for (EXTLayerRect* obs_rect : routing_obs_rect_map[coord.get_layer_idx()]) { - if (RTUTIL.isInside(obs_rect->get_real_rect(), coord)) { + for (PlanarRect& obs_rect : routing_obs_rect_map[coord.get_layer_idx()]) { + if (RTUTIL.isInside(obs_rect, coord)) { within_shape = true; break; } } } if (!within_shape) { - for (EXTLayerRect& routing_shape : pa_pin->get_routing_shape_list()) { - if (routing_shape.get_layer_idx() == coord.get_layer_idx() && RTUTIL.isInside(routing_shape.get_real_rect(), coord)) { + for (PlanarRect& pin_rect : routing_pin_rect_map[coord.get_layer_idx()]) { + if (RTUTIL.isInside(pin_rect, coord)) { within_shape = true; break; } -- Gitee From eaa9160eee7f1884b30129345fc2d989b0044153 Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Sat, 27 Sep 2025 16:52:26 +0800 Subject: [PATCH 08/19] del format --- src/operation/iRT/interface/RTInterface.cpp | 4 ---- .../iRT/source/module/layer_assigner/LayerAssigner.cpp | 2 -- src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp | 2 -- .../iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp | 2 -- .../source/module/topology_generator/TopologyGenerator.cpp | 2 -- .../iRT/source/module/track_assigner/TrackAssigner.cpp | 2 -- 6 files changed, 14 deletions(-) diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index 22ad42c0b..c366f3b3b 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -100,10 +100,6 @@ void RTInterface::runEGR() initFlute(); RTGP.init(); - SupplyAnalyzer::initInst(); - RTSA.analyze(); - SupplyAnalyzer::destroyInst(); - EarlyRouter::initInst(); RTER.route(); EarlyRouter::destroyInst(); diff --git a/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp b/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp index acca34d53..c16c2f9ee 100644 --- a/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp +++ b/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp @@ -119,9 +119,7 @@ void LayerAssigner::setLAComParam(LAModel& la_model) /** * topo_spilt_length, via_unit, overflow_unit */ - // clang-format off LAComParam la_com_param(topo_spilt_length, via_unit, overflow_unit); - // clang-format on RTLOG.info(Loc::current(), "topo_spilt_length: ", la_com_param.get_topo_spilt_length()); RTLOG.info(Loc::current(), "via_unit: ", la_com_param.get_via_unit()); RTLOG.info(Loc::current(), "overflow_unit: ", la_com_param.get_overflow_unit()); diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp index 70f1a7879..395fb5d8b 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp @@ -114,9 +114,7 @@ void PinAccessor::setPAComParam(PAModel& pa_model) /** * max_candidate_point_num */ - // clang-format off PAComParam pa_com_param(10); - // clang-format on RTLOG.info(Loc::current(), "max_candidate_point_num: ", pa_com_param.get_max_candidate_point_num()); pa_model.set_pa_com_param(pa_com_param); } diff --git a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp index c695c3074..1b39ac614 100644 --- a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp +++ b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp @@ -87,9 +87,7 @@ void SupplyAnalyzer::setSAComParam(SAModel& sa_model) /** * supply_reduction, boundary_wire_unit, internal_wire_unit, internal_via_unit */ - // clang-format off SAComParam sa_com_param(supply_reduction, boundary_wire_unit, internal_wire_unit, internal_via_unit); - // clang-format on RTLOG.info(Loc::current(), "supply_reduction: ", sa_com_param.get_supply_reduction()); RTLOG.info(Loc::current(), "boundary_wire_unit: ", sa_com_param.get_boundary_wire_unit()); RTLOG.info(Loc::current(), "internal_wire_unit: ", sa_com_param.get_internal_wire_unit()); diff --git a/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp b/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp index e5bbc0a94..fc8952e28 100644 --- a/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp +++ b/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp @@ -119,9 +119,7 @@ void TopologyGenerator::setTGComParam(TGModel& tg_model) /** * topo_spilt_length, expand_step_num, expand_step_length, overflow_unit */ - // clang-format off TGComParam tg_com_param(topo_spilt_length, expand_step_num, expand_step_length, overflow_unit); - // clang-format on RTLOG.info(Loc::current(), "topo_spilt_length: ", tg_com_param.get_topo_spilt_length()); RTLOG.info(Loc::current(), "expand_step_num: ", tg_com_param.get_expand_step_num()); RTLOG.info(Loc::current(), "expand_step_length: ", tg_com_param.get_expand_step_length()); diff --git a/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp b/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp index 9274a3fac..56639da0c 100644 --- a/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp +++ b/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp @@ -118,9 +118,7 @@ void TrackAssigner::setTAComParam(TAModel& ta_model) /** * prefer_wire_unit, schedule_interval, fixed_rect_unit, routed_rect_unit, violation_unit, max_routed_times */ - // clang-format off TAComParam ta_com_param(prefer_wire_unit, 3, fixed_rect_unit, routed_rect_unit, violation_unit, 3); - // clang-format on RTLOG.info(Loc::current(), "prefer_wire_unit: ", ta_com_param.get_prefer_wire_unit()); RTLOG.info(Loc::current(), "schedule_interval: ", ta_com_param.get_schedule_interval()); RTLOG.info(Loc::current(), "fixed_rect_unit: ", ta_com_param.get_fixed_rect_unit()); -- Gitee From 943802593bd0f0226307de55795a2e11dd109395 Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Sun, 28 Sep 2025 14:23:32 +0800 Subject: [PATCH 09/19] add gcell info --- src/operation/iRT/interface/RTInterface.cpp | 4 +++ .../module/early_router/EarlyRouter.cpp | 34 ++++++++++++------- .../module/early_router/EarlyRouter.hpp | 1 + .../module/supply_analyzer/SupplyAnalyzer.cpp | 18 ++++------ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index c366f3b3b..22ad42c0b 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -100,6 +100,10 @@ void RTInterface::runEGR() initFlute(); RTGP.init(); + SupplyAnalyzer::initInst(); + RTSA.analyze(); + SupplyAnalyzer::destroyInst(); + EarlyRouter::initInst(); RTER.route(); EarlyRouter::destroyInst(); diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp index 544a75934..8e3f9ba21 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp @@ -70,6 +70,7 @@ void EarlyRouter::route() generateGlobalTree(er_model); updateSummary(er_model); printSummary(er_model); + outputGCellCSV(er_model); outputGuide(er_model); outputDemandCSV(er_model); outputOverflowCSV(er_model); @@ -1438,6 +1439,24 @@ void EarlyRouter::printSummary(ERModel& er_model) RTUTIL.printTableList({timing_table, power_table}); } +void EarlyRouter::outputGCellCSV(ERModel& er_model) +{ + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; + + std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "gcell.csv")); + if (guide_file_stream == nullptr) { + return; + } + for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { + for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { + GCell& gcell = gcell_map[x][y]; + RTUTIL.pushStream(guide_file_stream, x, ",", y, ",", gcell.get_ll_x(), ",", gcell.get_ll_y(), ",", gcell.get_ur_x(), ",", gcell.get_ur_y(), "\n"); + } + } + RTUTIL.closeFileStream(guide_file_stream); +} + void EarlyRouter::outputGuide(ERModel& er_model) { int32_t micron_dbu = RTDM.getDatabase().get_micron_dbu(); @@ -1445,10 +1464,7 @@ void EarlyRouter::outputGuide(ERModel& er_model) Die& die = RTDM.getDatabase().get_die(); std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - int32_t output_inter_result = RTDM.getConfig().output_inter_result; - if (!output_inter_result) { - return; - } + std::vector& er_net_list = er_model.get_er_net_list(); std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "route.guide")); @@ -1517,10 +1533,7 @@ void EarlyRouter::outputDemandCSV(ERModel& er_model) { std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - int32_t output_inter_result = RTDM.getConfig().output_inter_result; - if (!output_inter_result) { - return; - } + std::vector>& layer_node_map = er_model.get_layer_node_map(); for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* demand_csv_file @@ -1548,10 +1561,7 @@ void EarlyRouter::outputOverflowCSV(ERModel& er_model) { std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - int32_t output_inter_result = RTDM.getConfig().output_inter_result; - if (!output_inter_result) { - return; - } + std::vector>& layer_node_map = er_model.get_layer_node_map(); for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* overflow_csv_file diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.hpp b/src/operation/iRT/source/module/early_router/EarlyRouter.hpp index 60d9d8b4e..3dc20c92c 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.hpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.hpp @@ -106,6 +106,7 @@ class EarlyRouter #if 1 // exhibit void updateSummary(ERModel& er_model); void printSummary(ERModel& er_model); + void outputGCellCSV(ERModel& er_model); void outputGuide(ERModel& er_model); void outputDemandCSV(ERModel& er_model); void outputOverflowCSV(ERModel& er_model); diff --git a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp index 1b39ac614..97deaf21d 100644 --- a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp +++ b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp @@ -435,12 +435,9 @@ void SupplyAnalyzer::outputPlanarSupplyCSV(SAModel& sa_model) { std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::string& sa_temp_directory_path = RTDM.getConfig().sa_temp_directory_path; - int32_t output_inter_result = RTDM.getConfig().output_inter_result; - if (!output_inter_result) { - return; - } - std::ofstream* supply_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(sa_temp_directory_path, "supply_map_planar.csv")); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; + + std::ofstream* supply_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "supply_map_planar.csv")); for (int32_t y = gcell_map.get_y_size() - 1; y >= 0; y--) { for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { int32_t total_supply = 0; @@ -461,14 +458,11 @@ void SupplyAnalyzer::outputLayerSupplyCSV(SAModel& sa_model) { std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::string& sa_temp_directory_path = RTDM.getConfig().sa_temp_directory_path; - int32_t output_inter_result = RTDM.getConfig().output_inter_result; - if (!output_inter_result) { - return; - } + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; + for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* supply_csv_file - = RTUTIL.getOutputFileStream(RTUTIL.getString(sa_temp_directory_path, "supply_map_", routing_layer.get_layer_name(), ".csv")); + = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "supply_map_", routing_layer.get_layer_name(), ".csv")); for (int32_t y = gcell_map.get_y_size() - 1; y >= 0; y--) { for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { int32_t total_supply = 0; -- Gitee From 7a97f38db6baf9614209ff1e0a654b6e66469bc1 Mon Sep 17 00:00:00 2001 From: simintao Date: Sun, 28 Sep 2025 16:58:47 +0800 Subject: [PATCH 10/19] fix:invalid file name in third party BST-DME --- src/third_party/BST-DME/BENCHMARKS/s1423_a0 | 513 ++++++++++++++++++++ 1 file changed, 513 insertions(+) create mode 100755 src/third_party/BST-DME/BENCHMARKS/s1423_a0 diff --git a/src/third_party/BST-DME/BENCHMARKS/s1423_a0 b/src/third_party/BST-DME/BENCHMARKS/s1423_a0 new file mode 100755 index 000000000..f677f8b58 --- /dev/null +++ b/src/third_party/BST-DME/BENCHMARKS/s1423_a0 @@ -0,0 +1,513 @@ + + +"mr +"node[147]0:1 +"mr +move 8855.45493286 2622.48611074 (JS_type=2)(n_mr=2)(cap=0.1) + 6893.39798211 4584.54306148 skew:0.00, max:742.44, min:742.44 + 8855.45493286 2622.48611074 skew:0.00, max:742.44, min:742.44 +"node[145]0:1 +"mr +move 547.08971512 1706.02528844 (JS_type=2)(n_mr=2)(cap=1.4) + 624.49094012 1783.42651344 skew:0.00, max:2.48, min:2.48 + 547.08971512 1706.02528844 skew:0.00, max:2.48, min:2.48 +"node[121]0:1 +"mr +move 461.50000000 3745.36761978 (JS_type=2)(n_mr=2)(cap=0.2) + 312.86761978 3894.00000000 skew:0.00, max:0.18, min:0.18 + 461.50000000 3745.36761978 skew:0.00, max:0.18, min:0.18 +"node[104]0:1 +"mr +move 718.86761978 3488.00000000 (JS_type=2)(n_mr=2)(cap=0.2) + 312.86761978 3894.00000000 skew:0.00, max:0.18, min:0.18 + 718.86761978 3488.00000000 skew:0.00, max:0.18, min:0.18 +"node[89]0:1 +"mr +move 468.00000000 3488.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 186.00000000 3770.00000000 skew:0.00, max:0.07, min:0.07 + 468.00000000 3488.00000000 skew:0.00, max:0.07, min:0.07 +"node[143]0:1 +"mr +move 942.48287776 1388.03335081 (JS_type=2)(n_mr=2)(cap=1.1) + 624.49094012 1706.02528844 skew:0.00, max:2.12, min:2.12 + 942.48287776 1388.03335081 skew:0.00, max:2.12, min:2.12 +"node[127]0:1 +"mr +move 1299.22335116 1889.50000000 (JS_type=2)(n_mr=2)(cap=0.4) + 1852.30650371 2442.58315254 skew:0.00, max:0.61, min:0.61 + 1299.22335116 1889.50000000 skew:0.00, max:0.61, min:0.61 +"node[107]0:1 +"mr +move 1033.50000000 2442.58315254 (JS_type=2)(n_mr=2)(cap=0.2) + 884.00000000 2592.08315254 skew:0.00, max:0.06, min:0.06 + 1033.50000000 2442.58315254 skew:0.00, max:0.06, min:0.06 +"node[78]0:1 +"mr +move 1033.50000000 2520.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 933.50000000 2620.00000000 skew:0.00, max:0.02, min:0.02 + 1033.50000000 2520.00000000 skew:0.00, max:0.02, min:0.02 +"node[117]0:1 +"mr +move 1477.14550233 1889.50000000 (JS_type=2)(n_mr=2)(cap=0.3) + 2281.00000000 2693.35449767 skew:0.00, max:0.43, min:0.43 + 1477.14550233 1889.50000000 skew:0.00, max:0.43, min:0.43 +"node[84]0:1 +"mr +move 2361.00000000 1809.50000000 (JS_type=2)(n_mr=2)(cap=0.1) + 2281.00000000 1889.50000000 skew:0.00, max:0.05, min:0.05 + 2361.00000000 1809.50000000 skew:0.00, max:0.05, min:0.05 +"node[82]0:1 +"mr +move 1298.00000000 2534.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 1463.00000000 2699.00000000 skew:0.00, max:0.05, min:0.05 + 1298.00000000 2534.00000000 skew:0.00, max:0.05, min:0.05 +"node[139]0:1 +"mr +move 55.00000000 818.54241069 (JS_type=2)(n_mr=2)(cap=0.7) + 624.49094012 1388.03335081 skew:0.00, max:1.25, min:1.25 + 55.00000000 818.54241069 skew:0.00, max:1.25, min:1.25 +"node[126]0:1 +"mr +move 585.49094012 303.00000000 (JS_type=2)(n_mr=2)(cap=0.2) + 624.49094012 342.00000000 skew:0.00, max:0.21, min:0.21 + 585.49094012 303.00000000 skew:0.00, max:0.21, min:0.21 +"node[79]0:1 +"mr +move 200.00000000 342.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 120.00000000 422.00000000 skew:0.00, max:0.02, min:0.02 + 200.00000000 342.00000000 skew:0.00, max:0.02, min:0.02 +"node[108]0:1 +"mr +move 789.50000000 303.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 1228.50000000 742.00000000 skew:0.00, max:0.11, min:0.11 + 789.50000000 303.00000000 skew:0.00, max:0.11, min:0.11 +"node[133]0:1 +"mr +move 55.00000000 1137.46532750 (JS_type=2)(n_mr=2)(cap=0.4) + 897.56725398 1980.03258148 skew:0.00, max:0.70, min:0.70 + 55.00000000 1137.46532750 skew:0.00, max:0.70, min:0.70 +"node[110]0:1 +"mr +move 55.00000000 2092.87632410 (JS_type=2)(n_mr=1)(cap=0.2) + 55.00000000 2092.87632410 skew:0.00, max:0.05, min:0.05 +"node[80]0:1 +"mr +move 192.00000000 1910.50000000 (JS_type=2)(n_mr=2)(cap=0.1) + 55.00000000 2047.50000000 skew:0.00, max:0.03, min:0.03 + 192.00000000 1910.50000000 skew:0.00, max:0.03, min:0.03 +"node[122]0:1 +"mr +move 437.56725398 1040.00000000 (JS_type=2)(n_mr=2)(cap=0.2) + 897.56725398 1500.00000000 skew:0.00, max:0.25, min:0.25 + 437.56725398 1040.00000000 skew:0.00, max:0.25, min:0.25 +"node[85]0:1 +"mr +move 350.50000000 1372.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 478.50000000 1500.00000000 skew:0.00, max:0.05, min:0.05 + 350.50000000 1372.00000000 skew:0.00, max:0.05, min:0.05 +"node[75]0:1 +"mr +move 965.50000000 1040.00000000 (JS_type=2)(n_mr=1)(cap=0.1) + 965.50000000 1040.00000000 skew:0.00, max:0.02, min:0.02 +"node[146]0:1 +"mr +move 8855.45493286 4584.54306148 (JS_type=2)(n_mr=2)(cap=4.2) + 9026.65427482 4755.74240344 skew:0.00, max:24.86, min:24.86 + 8855.45493286 4584.54306148 skew:0.00, max:24.86, min:24.86 +"node[142]0:1 +"mr +move 8855.45493286 6349.93164841 (JS_type=2)(n_mr=2)(cap=1.7) + 10319.47824577 7813.95496132 skew:0.00, max:12.85, min:12.85 + 8855.45493286 6349.93164841 skew:0.00, max:12.85, min:12.85 +"node[137]0:1 +"mr +move 12434.00000000 6349.93164841 (JS_type=2)(n_mr=2)(cap=0.7) + 12481.88989170 6397.82154011 skew:0.00, max:2.59, min:2.59 + 12434.00000000 6349.93164841 skew:0.00, max:2.59, min:2.59 +"node[118]0:1 +"mr +move 12434.00000000 7659.60260034 (JS_type=2)(n_mr=2)(cap=0.3) + 13367.00000000 8592.60260034 skew:0.00, max:0.86, min:0.86 + 12434.00000000 7659.60260034 skew:0.00, max:0.86, min:0.86 +"node[99]0:1 +"mr +move 12949.00000000 7072.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 13367.00000000 7490.00000000 skew:0.00, max:0.21, min:0.21 + 12949.00000000 7072.00000000 skew:0.00, max:0.21, min:0.21 +"node[101]0:1 +"mr +move 12434.00000000 8672.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 13110.00000000 9348.00000000 skew:0.00, max:0.24, min:0.24 + 12434.00000000 8672.00000000 skew:0.00, max:0.24, min:0.24 +"node[130]0:1 +"mr +move 11635.50000000 4118.61010830 (JS_type=2)(n_mr=2)(cap=0.3) + 12481.88989170 4965.00000000 skew:0.00, max:0.75, min:0.75 + 11635.50000000 4118.61010830 skew:0.00, max:0.75, min:0.75 +"node[98]0:1 +"mr +move 12333.00000000 3780.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 13057.00000000 4504.00000000 skew:0.00, max:0.17, min:0.17 + 12333.00000000 3780.00000000 skew:0.00, max:0.17, min:0.17 +"node[106]0:1 +"mr +move 11635.50000000 4965.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 10753.50000000 5847.00000000 skew:0.00, max:0.24, min:0.24 + 11635.50000000 4965.00000000 skew:0.00, max:0.24, min:0.24 +"node[140]0:1 +"mr +move 7231.26591173 7813.95496132 (JS_type=2)(n_mr=2)(cap=0.9) + 6894.00000000 8151.22087306 skew:0.00, max:1.74, min:1.74 + 7231.26591173 7813.95496132 skew:0.00, max:1.74, min:1.74 +"node[124]0:1 +"mr +move 7868.50000000 8435.99358950 (JS_type=2)(n_mr=2)(cap=0.3) + 8159.00000000 8726.49358950 skew:0.00, max:0.36, min:0.36 + 7868.50000000 8435.99358950 skew:0.00, max:0.36, min:0.36 +"node[88]0:1 +"mr +move 8181.00000000 8076.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 8159.00000000 8098.00000000 skew:0.00, max:0.06, min:0.06 + 8181.00000000 8076.00000000 skew:0.00, max:0.06, min:0.06 +"node[105]0:1 +"mr +move 7868.50000000 8810.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 8548.50000000 9490.00000000 skew:0.00, max:0.16, min:0.16 + 7868.50000000 8810.00000000 skew:0.00, max:0.16, min:0.16 +"node[134]0:1 +"mr +move 6921.99215379 7813.95496132 (JS_type=2)(n_mr=2)(cap=0.6) + 6894.00000000 7841.94711511 skew:0.00, max:1.02, min:1.02 + 6921.99215379 7813.95496132 skew:0.00, max:1.02, min:1.02 +"node[115]0:1 +"mr +move 6943.00000000 6699.90594710 (JS_type=2)(n_mr=2)(cap=0.2) + 6894.00000000 6748.90594710 skew:0.00, max:0.17, min:0.17 + 6943.00000000 6699.90594710 skew:0.00, max:0.17, min:0.17 +"node[90]0:1 +"mr +move 6943.00000000 6922.50000000 (JS_type=2)(n_mr=2)(cap=0.1) + 7219.00000000 7198.50000000 skew:0.00, max:0.07, min:0.07 + 6943.00000000 6922.50000000 skew:0.00, max:0.07, min:0.07 +"node[125]0:1 +"mr +move 6921.99215379 8268.18475221 (JS_type=2)(n_mr=2)(cap=0.4) + 6776.75434786 8413.42255814 skew:0.00, max:0.35, min:0.35 + 6921.99215379 8268.18475221 skew:0.00, max:0.35, min:0.35 +"node[112]0:1 +"mr +move 7130.00000000 8413.42255814 (JS_type=2)(n_mr=2)(cap=0.2) + 7236.57744186 8520.00000000 skew:0.00, max:0.10, min:0.10 + 7130.00000000 8413.42255814 skew:0.00, max:0.10, min:0.10 +"node[86]0:1 +"mr +move 7130.00000000 8520.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 6978.00000000 8672.00000000 skew:0.00, max:0.06, min:0.06 + 7130.00000000 8520.00000000 skew:0.00, max:0.06, min:0.06 +"node[114]0:1 +"mr +move 6653.00000000 8268.18475221 (JS_type=2)(n_mr=2)(cap=0.2) + 6496.00000000 8425.18475221 skew:0.00, max:0.16, min:0.16 + 6653.00000000 8268.18475221 skew:0.00, max:0.16, min:0.16 +"node[87]0:1 +"mr +move 6397.00000000 8107.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 6496.00000000 8206.00000000 skew:0.00, max:0.06, min:0.06 + 6397.00000000 8107.00000000 skew:0.00, max:0.06, min:0.06 +"node[144]0:1 +"mr +move 7752.54287797 2543.59865695 (JS_type=2)(n_mr=2)(cap=2.5) + 9026.65427482 3817.71005380 skew:0.00, max:15.62, min:15.62 + 7752.54287797 2543.59865695 skew:0.00, max:15.62, min:15.62 +"node[138]0:1 +"mr +move 11001.98794897 938.09594156 (JS_type=2)(n_mr=2)(cap=0.7) + 10745.08389053 1195.00000000 skew:0.00, max:2.59, min:2.59 + 11001.98794897 938.09594156 skew:0.00, max:2.59, min:2.59 +"node[123]0:1 +"mr +move 12968.84747969 910.83190429 (JS_type=2)(n_mr=2)(cap=0.3) + 12684.67938398 1195.00000000 skew:0.00, max:0.30, min:0.30 + 12968.84747969 910.83190429 skew:0.00, max:0.30, min:0.30 +"node[102]0:1 +"mr +move 12951.00000000 910.83190429 (JS_type=2)(n_mr=2)(cap=0.2) + 12481.83190429 1380.00000000 skew:0.00, max:0.29, min:0.29 + 12951.00000000 910.83190429 skew:0.00, max:0.29, min:0.29 +"node[94]0:1 +"mr +move 12951.00000000 1274.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 12845.00000000 1380.00000000 skew:0.00, max:0.11, min:0.11 + 12951.00000000 1274.00000000 skew:0.00, max:0.11, min:0.11 +"node[132]0:1 +"mr +move 9996.75039308 938.09594156 (JS_type=2)(n_mr=2)(cap=0.4) + 9349.84633464 1585.00000000 skew:0.00, max:1.05, min:1.05 + 9996.75039308 938.09594156 skew:0.00, max:1.05, min:1.05 +"node[103]0:1 +"mr +move 8898.00000000 938.09594156 (JS_type=2)(n_mr=2)(cap=0.2) + 8558.00000000 1278.09594156 skew:0.00, max:0.19, min:0.19 + 8898.00000000 938.09594156 skew:0.00, max:0.19, min:0.19 +"node[91]0:1 +"mr +move 8898.00000000 1195.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 8721.00000000 1372.00000000 skew:0.00, max:0.07, min:0.07 + 8898.00000000 1195.00000000 skew:0.00, max:0.07, min:0.07 +"node[100]0:1 +"mr +move 11052.00000000 1218.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 10685.00000000 1585.00000000 skew:0.00, max:0.24, min:0.24 + 11052.00000000 1218.00000000 skew:0.00, max:0.24, min:0.24 +"node[141]0:1 +"mr +move 7752.54287797 3817.71005380 (JS_type=2)(n_mr=2)(cap=1.6) + 6510.14128223 5060.11164954 skew:0.00, max:7.24, min:7.24 + 7752.54287797 3817.71005380 skew:0.00, max:7.24, min:7.24 +"node[135]0:1 +"mr +move 8296.16391169 5121.13861057 (JS_type=2)(n_mr=2)(cap=0.7) + 8802.99985065 5627.97454953 skew:0.00, max:1.65, min:1.65 + 8296.16391169 5121.13861057 skew:0.00, max:1.65, min:1.65 +"node[120]0:1 +"mr +move 9370.99985065 4049.00000000 (JS_type=2)(n_mr=2)(cap=0.3) + 8802.99985065 4617.00000000 skew:0.00, max:0.53, min:0.53 + 9370.99985065 4049.00000000 skew:0.00, max:0.53, min:0.53 +"node[77]0:1 +"mr +move 9973.00000000 4547.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 9903.00000000 4617.00000000 skew:0.00, max:0.02, min:0.02 + 9973.00000000 4547.00000000 skew:0.00, max:0.02, min:0.02 +"node[97]0:1 +"mr +move 8270.00000000 3629.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 8690.00000000 4049.00000000 skew:0.00, max:0.16, min:0.16 + 8270.00000000 3629.00000000 skew:0.00, max:0.16, min:0.16 +"node[128]0:1 +"mr +move 8296.16391169 5653.31136103 (JS_type=2)(n_mr=2)(cap=0.4) + 7909.25841535 6040.21685737 skew:0.00, max:0.71, min:0.71 + 8296.16391169 5653.31136103 skew:0.00, max:0.71, min:0.71 +"node[113]0:1 +"mr +move 8296.16391169 6459.00000000 (JS_type=2)(n_mr=2)(cap=0.2) + 8228.16391169 6527.00000000 skew:0.00, max:0.12, min:0.12 + 8296.16391169 6459.00000000 skew:0.00, max:0.12, min:0.12 +"node[81]0:1 +"mr +move 8416.00000000 6517.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 8406.00000000 6527.00000000 skew:0.00, max:0.04, min:0.04 + 8416.00000000 6517.00000000 skew:0.00, max:0.04, min:0.04 +"node[116]0:1 +"mr +move 8318.25841535 5236.00000000 (JS_type=2)(n_mr=2)(cap=0.2) + 7909.25841535 5645.00000000 skew:0.00, max:0.32, min:0.32 + 8318.25841535 5236.00000000 skew:0.00, max:0.32, min:0.32 +"node[92]0:1 +"mr +move 7682.00000000 5102.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 7816.00000000 5236.00000000 skew:0.00, max:0.08, min:0.08 + 7682.00000000 5102.00000000 skew:0.00, max:0.08, min:0.08 +"node[76]0:1 +"mr +move 8623.00000000 5604.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 8582.00000000 5645.00000000 skew:0.00, max:0.02, min:0.02 + 8623.00000000 5604.00000000 skew:0.00, max:0.02, min:0.02 +"node[136]0:1 +"mr +move 5828.74929154 3136.31806311 (JS_type=2)(n_mr=2)(cap=0.8) + 6510.14128223 3817.71005380 skew:0.00, max:3.04, min:3.04 + 5828.74929154 3136.31806311 skew:0.00, max:3.04, min:3.04 +"node[129]0:1 +"mr +move 5818.00000000 1348.49464010 (JS_type=2)(n_mr=2)(cap=0.3) + 6510.14128223 2040.63592233 skew:0.00, max:0.59, min:0.59 + 5818.00000000 1348.49464010 skew:0.00, max:0.59, min:0.59 +"node[96]0:1 +"mr +move 6463.00000000 1195.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 6640.00000000 1372.00000000 skew:0.00, max:0.15, min:0.15 + 6463.00000000 1195.00000000 skew:0.00, max:0.15, min:0.15 +"node[111]0:1 +"mr +move 5818.00000000 2040.63592233 (JS_type=2)(n_mr=2)(cap=0.2) + 5752.00000000 2106.63592233 skew:0.00, max:0.10, min:0.10 + 5818.00000000 2040.63592233 skew:0.00, max:0.10, min:0.10 +"node[83]0:1 +"mr +move 5591.00000000 1833.50000000 (JS_type=2)(n_mr=2)(cap=0.1) + 5752.00000000 1994.50000000 skew:0.00, max:0.05, min:0.05 + 5591.00000000 1833.50000000 skew:0.00, max:0.05, min:0.05 +"node[131]0:1 +"mr +move 5828.74929154 4075.08744972 (JS_type=2)(n_mr=2)(cap=0.5) + 4946.50000000 4957.33674126 skew:0.00, max:1.30, min:1.30 + 5828.74929154 4075.08744972 skew:0.00, max:1.30, min:1.30 +"node[119]0:1 +"mr +move 4203.41255028 3332.00000000 (JS_type=2)(n_mr=2)(cap=0.2) + 4946.50000000 4075.08744972 skew:0.00, max:0.49, min:0.49 + 4203.41255028 3332.00000000 skew:0.00, max:0.49, min:0.49 +"node[95]0:1 +"mr +move 5226.50000000 3052.00000000 (JS_type=2)(n_mr=2)(cap=0.1) + 4946.50000000 3332.00000000 skew:0.00, max:0.11, min:0.11 + 5226.50000000 3052.00000000 skew:0.00, max:0.11, min:0.11 +"node[109]0:1 +"mr +move 6206.00000000 5121.64139333 (JS_type=2)(n_mr=2)(cap=0.2) + 6022.14139333 5305.50000000 skew:0.00, max:0.17, min:0.17 + 6206.00000000 5121.64139333 skew:0.00, max:0.17, min:0.17 +"node[93]0:1 +"mr +move 6206.00000000 5305.50000000 (JS_type=2)(n_mr=2)(cap=0.1) + 6398.00000000 5497.50000000 skew:0.00, max:0.09, min:0.09 + 6206.00000000 5305.50000000 skew:0.00, max:0.09, min:0.09 + + +"JS +move 547.1 1706.0 + 624.5 1783.4 +move 8855.5 4584.5 + 9026.7 4755.7 +move 461.5 3745.4 + 312.9 3894.0 +move 942.5 1388.0 + 624.5 1706.0 +move 718.9 3488.0 + 312.9 3894.0 +move 468.0 3488.0 + 186.0 3770.0 +move 1299.2 1889.5 + 1852.3 2442.6 +move 55.0 818.5 + 624.5 1388.0 +move 1033.5 2442.6 + 884.0 2592.1 +move 1477.1 1889.5 + 2281.0 2693.4 +move 1033.5 2520.0 + 933.5 2620.0 +move 2361.0 1809.5 + 2281.0 1889.5 +move 1298.0 2534.0 + 1463.0 2699.0 +move 585.5 303.0 + 624.5 342.0 +move 55.0 1137.5 + 897.6 1980.0 +move 200.0 342.0 + 120.0 422.0 +move 789.5 303.0 + 1228.5 742.0 +move 55.0 2092.9 + 55.0 2092.9 +move 437.6 1040.0 + 897.6 1500.0 +move 192.0 1910.5 + 55.0 2047.5 +move 350.5 1372.0 + 478.5 1500.0 +move 965.5 1040.0 + 965.5 1040.0 +move 8855.5 6349.9 + 10319.5 7814.0 +move 7752.5 2543.6 + 9026.7 3817.7 +move 12434.0 6349.9 + 12481.9 6397.8 +move 7231.3 7814.0 + 6894.0 8151.2 +move 12434.0 7659.6 + 13367.0 8592.6 +move 11635.5 4118.6 + 12481.9 4965.0 +move 12949.0 7072.0 + 13367.0 7490.0 +move 12434.0 8672.0 + 13110.0 9348.0 +move 12333.0 3780.0 + 13057.0 4504.0 +move 11635.5 4965.0 + 10753.5 5847.0 +move 7868.5 8436.0 + 8159.0 8726.5 +move 6922.0 7814.0 + 6894.0 7841.9 +move 8181.0 8076.0 + 8159.0 8098.0 +move 7868.5 8810.0 + 8548.5 9490.0 +move 6943.0 6699.9 + 6894.0 6748.9 +move 6922.0 8268.2 + 6776.8 8413.4 +move 6943.0 6922.5 + 7219.0 7198.5 +move 7130.0 8413.4 + 7236.6 8520.0 +move 6653.0 8268.2 + 6496.0 8425.2 +move 7130.0 8520.0 + 6978.0 8672.0 +move 6397.0 8107.0 + 6496.0 8206.0 +move 11002.0 938.1 + 10745.1 1195.0 +move 7752.5 3817.7 + 6510.1 5060.1 +move 12968.8 910.8 + 12684.7 1195.0 +move 9996.8 938.1 + 9349.8 1585.0 +move 12951.0 910.8 + 12481.8 1380.0 +move 12951.0 1274.0 + 12845.0 1380.0 +move 8898.0 938.1 + 8558.0 1278.1 +move 11052.0 1218.0 + 10685.0 1585.0 +move 8898.0 1195.0 + 8721.0 1372.0 +move 8296.2 5121.1 + 8803.0 5628.0 +move 5828.7 3136.3 + 6510.1 3817.7 +move 9371.0 4049.0 + 8803.0 4617.0 +move 8296.2 5653.3 + 7909.3 6040.2 +move 9973.0 4547.0 + 9903.0 4617.0 +move 8270.0 3629.0 + 8690.0 4049.0 +move 8296.2 6459.0 + 8228.2 6527.0 +move 8318.3 5236.0 + 7909.3 5645.0 +move 8416.0 6517.0 + 8406.0 6527.0 +move 7682.0 5102.0 + 7816.0 5236.0 +move 8623.0 5604.0 + 8582.0 5645.0 +move 5818.0 1348.5 + 6510.1 2040.6 +move 5828.7 4075.1 + 4946.5 4957.3 +move 6463.0 1195.0 + 6640.0 1372.0 +move 5818.0 2040.6 + 5752.0 2106.6 +move 5591.0 1833.5 + 5752.0 1994.5 +move 4203.4 3332.0 + 4946.5 4075.1 +move 6206.0 5121.6 + 6022.1 5305.5 +move 5226.5 3052.0 + 4946.5 3332.0 +move 6206.0 5305.5 + 6398.0 5497.5 -- Gitee From 28ed8145c8544ebd9703ece0e41dda937757af9b Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Sun, 28 Sep 2025 22:30:19 +0800 Subject: [PATCH 11/19] update early router --- src/feature/database/feature_irt.h | 8 +- src/operation/iRT/interface/RTInterface.cpp | 4 - .../source/data_manager/advance/Summary.hpp | 8 +- .../module/early_router/EarlyRouter.cpp | 1984 ++++++++++------- .../module/early_router/EarlyRouter.hpp | 106 +- .../{ERTopo.hpp => ERCandidate.hpp} | 40 +- .../er_data_manager/ERComParam.hpp | 33 +- .../{ERGroup.hpp => ERLayerCost.hpp} | 20 +- .../early_router/er_data_manager/ERModel.hpp | 60 +- .../early_router/er_data_manager/ERNet.hpp | 13 +- .../early_router/er_data_manager/ERNode.hpp | 265 ++- .../er_data_manager/ERPackage.hpp | 36 + .../{ERIterParam.hpp => ERPillar.hpp} | 23 +- .../module/supply_analyzer/SupplyAnalyzer.cpp | 18 +- 14 files changed, 1617 insertions(+), 1001 deletions(-) rename src/operation/iRT/source/module/early_router/er_data_manager/{ERTopo.hpp => ERCandidate.hpp} (47%) rename src/operation/iRT/source/module/early_router/er_data_manager/{ERGroup.hpp => ERLayerCost.hpp} (60%) create mode 100644 src/operation/iRT/source/module/early_router/er_data_manager/ERPackage.hpp rename src/operation/iRT/source/module/early_router/er_data_manager/{ERIterParam.hpp => ERPillar.hpp} (50%) diff --git a/src/feature/database/feature_irt.h b/src/feature/database/feature_irt.h index 8717d4f63..38584ac44 100644 --- a/src/feature/database/feature_irt.h +++ b/src/feature/database/feature_irt.h @@ -125,10 +125,10 @@ struct VRSummary struct ERSummary { - std::map routing_demand_map; - int32_t total_demand = 0; - std::map routing_overflow_map; - int32_t total_overflow = 0; + std::map routing_demand_map; + double total_demand = 0; + std::map routing_overflow_map; + double total_overflow = 0; std::map routing_wire_length_map; double total_wire_length = 0; std::map cut_via_num_map; diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index 22ad42c0b..c366f3b3b 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -100,10 +100,6 @@ void RTInterface::runEGR() initFlute(); RTGP.init(); - SupplyAnalyzer::initInst(); - RTSA.analyze(); - SupplyAnalyzer::destroyInst(); - EarlyRouter::initInst(); RTER.route(); EarlyRouter::destroyInst(); diff --git a/src/operation/iRT/source/data_manager/advance/Summary.hpp b/src/operation/iRT/source/data_manager/advance/Summary.hpp index b71b17763..cf2b61f52 100644 --- a/src/operation/iRT/source/data_manager/advance/Summary.hpp +++ b/src/operation/iRT/source/data_manager/advance/Summary.hpp @@ -146,10 +146,10 @@ class ERSummary public: ERSummary() = default; ~ERSummary() = default; - std::map routing_demand_map; - int32_t total_demand = 0; - std::map routing_overflow_map; - int32_t total_overflow = 0; + std::map routing_demand_map; + double total_demand = 0; + std::map routing_overflow_map; + double total_overflow = 0; std::map routing_wire_length_map; double total_wire_length = 0; std::map cut_via_num_map; diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp index 8e3f9ba21..0d2c93ff0 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp @@ -57,23 +57,23 @@ void EarlyRouter::route() ERModel er_model = initERModel(); setERComParam(er_model); generateAccessPoint(er_model); + // generateAccessResult(er_model); + buildSupplySchedule(er_model); + analyzeSupply(er_model); + buildIgnoreNet(er_model); + analyzeDemandUnit(er_model); initERTaskList(er_model); buildPlanarNodeMap(er_model); buildPlanarNodeNeighbor(er_model); buildPlanarOrientSupply(er_model); - // debugCheckPlanarNodeMap(er_model); - generateTopoTree(er_model); + generateTopology(er_model); buildLayerNodeMap(er_model); buildLayerNodeNeighbor(er_model); buildLayerOrientSupply(er_model); - // debugCheckLayerNodeMap(er_model); - generateGlobalTree(er_model); + assignLayer(er_model); + outputResult(er_model); updateSummary(er_model); printSummary(er_model); - outputGCellCSV(er_model); - outputGuide(er_model); - outputDemandCSV(er_model); - outputOverflowCSV(er_model); RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } @@ -115,21 +115,34 @@ ERNet EarlyRouter::convertToERNet(Net& net) void EarlyRouter::setERComParam(ERModel& er_model) { + int32_t supply_reduction = 0; + double boundary_wire_unit = 1; + double internal_wire_unit = 1; + double internal_via_unit = 1; int32_t topo_spilt_length = 10; + int32_t expand_step_num = 5; + int32_t expand_step_length = 2; double prefer_wire_unit = 1; double non_prefer_wire_unit = 2.5 * prefer_wire_unit; - double via_unit = 1; + double via_unit = 2 * non_prefer_wire_unit; double overflow_unit = 4 * non_prefer_wire_unit; + /** - * topo_spilt_length, prefer_wire_unit, via_unit, overflow_unit + * supply_reduction, boundary_wire_unit, internal_wire_unit, internal_via_unit, topo_spilt_length, expand_step_num, expand_step_length, via_unit, + * overflow_unit */ - // clang-format off - ERComParam er_com_param(topo_spilt_length, prefer_wire_unit, via_unit, overflow_unit); - // clang-format on + ERComParam er_com_param(supply_reduction, boundary_wire_unit, internal_wire_unit, internal_via_unit, topo_spilt_length, expand_step_num, expand_step_length, + via_unit, overflow_unit); + RTLOG.info(Loc::current(), "supply_reduction: ", er_com_param.get_supply_reduction()); + RTLOG.info(Loc::current(), "boundary_wire_unit: ", er_com_param.get_boundary_wire_unit()); + RTLOG.info(Loc::current(), "internal_wire_unit: ", er_com_param.get_internal_wire_unit()); + RTLOG.info(Loc::current(), "internal_via_unit: ", er_com_param.get_internal_via_unit()); RTLOG.info(Loc::current(), "topo_spilt_length: ", er_com_param.get_topo_spilt_length()); - RTLOG.info(Loc::current(), "prefer_wire_unit: ", er_com_param.get_prefer_wire_unit()); + RTLOG.info(Loc::current(), "expand_step_num: ", er_com_param.get_expand_step_num()); + RTLOG.info(Loc::current(), "expand_step_length: ", er_com_param.get_expand_step_length()); RTLOG.info(Loc::current(), "via_unit: ", er_com_param.get_via_unit()); RTLOG.info(Loc::current(), "overflow_unit: ", er_com_param.get_overflow_unit()); + er_model.set_er_com_param(er_com_param); } @@ -179,6 +192,294 @@ void EarlyRouter::generateAccessPoint(ERModel& er_model) RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } +void EarlyRouter::buildSupplySchedule(ERModel& er_model) +{ + Die& die = RTDM.getDatabase().get_die(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + int32_t bottom_routing_layer_idx = RTDM.getConfig().bottom_routing_layer_idx; + int32_t top_routing_layer_idx = RTDM.getConfig().top_routing_layer_idx; + + for (RoutingLayer& routing_layer : routing_layer_list) { + if (routing_layer.get_layer_idx() < bottom_routing_layer_idx || top_routing_layer_idx < routing_layer.get_layer_idx()) { + continue; + } + if (routing_layer.isPreferH()) { + for (int32_t begin_x = 1; begin_x <= 2; begin_x++) { + std::vector> grid_pair_list; + for (int32_t y = 0; y < die.getYSize(); y++) { + for (int32_t x = begin_x; x < die.getXSize(); x += 2) { + grid_pair_list.emplace_back(LayerCoord(x - 1, y, routing_layer.get_layer_idx()), LayerCoord(x, y, routing_layer.get_layer_idx())); + } + } + er_model.get_grid_pair_list_list().push_back(grid_pair_list); + } + } else { + for (int32_t begin_y = 1; begin_y <= 2; begin_y++) { + std::vector> grid_pair_list; + for (int32_t x = 0; x < die.getXSize(); x++) { + for (int32_t y = begin_y; y < die.getYSize(); y += 2) { + grid_pair_list.emplace_back(LayerCoord(x, y - 1, routing_layer.get_layer_idx()), LayerCoord(x, y, routing_layer.get_layer_idx())); + } + } + er_model.get_grid_pair_list_list().push_back(grid_pair_list); + } + } + } +} + +void EarlyRouter::analyzeSupply(ERModel& er_model) +{ + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + int32_t supply_reduction = er_model.get_er_com_param().get_supply_reduction(); + + size_t total_pair_num = 0; + for (std::vector>& grid_pair_list : er_model.get_grid_pair_list_list()) { + total_pair_num += grid_pair_list.size(); + } + + size_t analyzed_pair_num = 0; + for (std::vector>& grid_pair_list : er_model.get_grid_pair_list_list()) { + Monitor stage_monitor; +#pragma omp parallel for + for (std::pair& grid_pair : grid_pair_list) { + LayerCoord first_coord = grid_pair.first; + LayerCoord second_coord = grid_pair.second; + EXTLayerRect search_rect = getSearchRect(first_coord, second_coord); + + std::map& first_orient_supply_map + = gcell_map[first_coord.get_x()][first_coord.get_y()].get_routing_orient_supply_map()[search_rect.get_layer_idx()]; + std::map& second_orient_supply_map + = gcell_map[second_coord.get_x()][second_coord.get_y()].get_routing_orient_supply_map()[search_rect.get_layer_idx()]; + + Orientation first_orientation = RTUTIL.getOrientation(first_coord, second_coord); + Orientation second_orientation = RTUTIL.getOppositeOrientation(first_orientation); + + std::vector obs_rect_list; + { + for (auto& [is_routing, layer_net_fixed_rect_map] : RTDM.getTypeLayerNetFixedRectMap(search_rect)) { + if (!is_routing) { + continue; + } + for (auto& [layer_idx, net_fixed_rect_map] : layer_net_fixed_rect_map) { + if (search_rect.get_layer_idx() != layer_idx) { + continue; + } + for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { + for (EXTLayerRect* fixed_rect : fixed_rect_set) { + obs_rect_list.push_back(fixed_rect->get_real_rect()); + } + } + } + } + for (auto& [net_idx, segment_set] : RTDM.getNetDetailedResultMap(search_rect)) { + for (Segment* segment : segment_set) { + for (NetShape& net_shape : RTDM.getNetDetailedShapeList(net_idx, *segment)) { + if (!net_shape.get_is_routing()) { + continue; + } + if (search_rect.get_layer_idx() != net_shape.get_layer_idx()) { + continue; + } + obs_rect_list.push_back(net_shape); + } + } + } + for (auto& [net_idx, patch_set] : RTDM.getNetDetailedPatchMap(search_rect)) { + for (EXTLayerRect* patch : patch_set) { + if (search_rect.get_layer_idx() != patch->get_layer_idx()) { + continue; + } + obs_rect_list.push_back(patch->get_real_rect()); + } + } + } + std::vector wire_list = getCrossingWireList(search_rect); + int32_t max_supply = std::max(0, static_cast(wire_list.size()) - supply_reduction); + + int32_t supply = 0; + for (LayerRect& wire : wire_list) { + if (isAccess(wire, obs_rect_list)) { + supply++; + } + } + if (supply > 0) { + first_orient_supply_map[first_orientation] = std::min(supply, max_supply); + second_orient_supply_map[second_orientation] = std::min(supply, max_supply); + } + } + analyzed_pair_num += grid_pair_list.size(); + RTLOG.info(Loc::current(), "Analyzed ", analyzed_pair_num, "/", total_pair_num, "(", RTUTIL.getPercentage(analyzed_pair_num, total_pair_num), + ") grid pairs", stage_monitor.getStatsInfo()); + } + + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); +} + +EXTLayerRect EarlyRouter::getSearchRect(LayerCoord& first_coord, LayerCoord& second_coord) +{ + ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); + + if (first_coord.get_layer_idx() != second_coord.get_layer_idx()) { + RTLOG.error(Loc::current(), "The grid_pair layer_idx is not equal!"); + } + PlanarRect search_real_rect; + { + PlanarRect first_real_rect = RTUTIL.getRealRectByGCell(first_coord, gcell_axis); + PlanarCoord first_mid_coord = first_real_rect.getMidPoint(); + PlanarRect second_real_rect = RTUTIL.getRealRectByGCell(second_coord, gcell_axis); + PlanarCoord second_mid_coord = second_real_rect.getMidPoint(); + if (RTUTIL.isHorizontal(first_coord, second_coord)) { + std::vector coord_list; + coord_list.emplace_back(first_mid_coord.get_x(), first_real_rect.get_ll_y()); + coord_list.emplace_back(first_mid_coord.get_x(), first_real_rect.get_ur_y()); + coord_list.emplace_back(second_mid_coord.get_x(), second_real_rect.get_ll_y()); + coord_list.emplace_back(second_mid_coord.get_x(), second_real_rect.get_ur_y()); + search_real_rect = RTUTIL.getBoundingBox(coord_list); + } else if (RTUTIL.isVertical(first_coord, second_coord)) { + std::vector coord_list; + coord_list.emplace_back(first_real_rect.get_ll_x(), first_mid_coord.get_y()); + coord_list.emplace_back(first_real_rect.get_ur_x(), first_mid_coord.get_y()); + coord_list.emplace_back(second_real_rect.get_ll_x(), second_mid_coord.get_y()); + coord_list.emplace_back(second_real_rect.get_ur_x(), second_mid_coord.get_y()); + search_real_rect = RTUTIL.getBoundingBox(coord_list); + } + } + EXTLayerRect search_rect; + search_rect.set_real_rect(search_real_rect); + search_rect.set_grid_rect(RTUTIL.getClosedGCellGridRect(search_rect.get_real_rect(), gcell_axis)); + search_rect.set_layer_idx(first_coord.get_layer_idx()); + return search_rect; +} + +std::vector EarlyRouter::getCrossingWireList(EXTLayerRect& search_rect) +{ + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + + RoutingLayer& routing_layer = routing_layer_list[search_rect.get_layer_idx()]; + int32_t half_wire_width = routing_layer.get_min_width() / 2; + + int32_t real_ll_x = search_rect.get_real_ll_x(); + int32_t real_ll_y = search_rect.get_real_ll_y(); + int32_t real_ur_x = search_rect.get_real_ur_x(); + int32_t real_ur_y = search_rect.get_real_ur_y(); + + std::vector wire_list; + if (routing_layer.isPreferH()) { + for (int32_t y : RTUTIL.getScaleList(real_ll_y, real_ur_y, routing_layer.getYTrackGridList())) { + wire_list.emplace_back(real_ll_x, y - half_wire_width, real_ur_x, y + half_wire_width, search_rect.get_layer_idx()); + } + } else { + for (int32_t x : RTUTIL.getScaleList(real_ll_x, real_ur_x, routing_layer.getXTrackGridList())) { + wire_list.emplace_back(x - half_wire_width, real_ll_y, x + half_wire_width, real_ur_y, search_rect.get_layer_idx()); + } + } + return wire_list; +} + +bool EarlyRouter::isAccess(LayerRect& wire, std::vector& obs_rect_list) +{ + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + RoutingLayer& routing_layer = routing_layer_list[wire.get_layer_idx()]; + + for (PlanarRect& obs_rect : obs_rect_list) { + int32_t enlarged_size = routing_layer.getPRLSpacing(obs_rect); + PlanarRect enlarged_rect = RTUTIL.getEnlargedRect(obs_rect, enlarged_size); + if (RTUTIL.isOpenOverlap(enlarged_rect, wire)) { + // 阻塞 + return false; + } + } + return true; +} + +void EarlyRouter::buildIgnoreNet(ERModel& er_model) +{ + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + int32_t bottom_routing_layer_idx = RTDM.getConfig().bottom_routing_layer_idx; + int32_t top_routing_layer_idx = RTDM.getConfig().top_routing_layer_idx; + + for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { + for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { + std::map>> routing_ignore_net_orient_map; + for (auto& [is_routing, layer_net_fixed_rect_map] : gcell_map[x][y].get_type_layer_net_fixed_rect_map()) { + if (!is_routing) { + continue; + } + for (auto& [layer_idx, net_fixed_rect_map] : layer_net_fixed_rect_map) { + for (auto& [net_idx, fixed_rect_set] : net_fixed_rect_map) { + if (net_idx == -1) { + continue; + } + for (EXTLayerRect* fixed_rect : fixed_rect_set) { + if (RTUTIL.isClosedOverlap(gcell_map[x][y], fixed_rect->get_real_rect())) { + routing_ignore_net_orient_map[layer_idx][net_idx] = {}; + } + } + } + } + } + for (auto& [net_idx, segment_set] : gcell_map[x][y].get_net_detailed_result_map()) { + for (Segment* segment : segment_set) { + for (NetShape& net_shape : RTDM.getNetDetailedShapeList(net_idx, *segment)) { + if (!net_shape.get_is_routing()) { + continue; + } + if (RTUTIL.isClosedOverlap(gcell_map[x][y], net_shape.get_rect())) { + routing_ignore_net_orient_map[net_shape.get_layer_idx()][net_idx] = {}; + } + } + } + } + for (auto& [net_idx, patch_set] : gcell_map[x][y].get_net_detailed_patch_map()) { + for (EXTLayerRect* patch : patch_set) { + if (RTUTIL.isClosedOverlap(gcell_map[x][y], patch->get_real_rect())) { + routing_ignore_net_orient_map[patch->get_layer_idx()][net_idx] = {}; + } + } + } + for (auto& [routing_layer_idx, ignore_net_orient_map] : routing_ignore_net_orient_map) { + std::set ignore_orient_set; + ignore_orient_set.insert(Orientation::kAbove); + ignore_orient_set.insert(Orientation::kBelow); + if (bottom_routing_layer_idx <= routing_layer_idx && routing_layer_idx <= top_routing_layer_idx) { + if (routing_layer_list[routing_layer_idx].isPreferH()) { + ignore_orient_set.insert(Orientation::kWest); + ignore_orient_set.insert(Orientation::kEast); + } else { + ignore_orient_set.insert(Orientation::kSouth); + ignore_orient_set.insert(Orientation::kNorth); + } + } + for (auto& [net_idx, orient_set] : ignore_net_orient_map) { + orient_set = ignore_orient_set; + } + } + gcell_map[x][y].set_routing_ignore_net_orient_map(routing_ignore_net_orient_map); + } + } +} + +void EarlyRouter::analyzeDemandUnit(ERModel& er_model) +{ + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + double boundary_wire_unit = er_model.get_er_com_param().get_boundary_wire_unit(); + double internal_wire_unit = er_model.get_er_com_param().get_internal_wire_unit(); + double internal_via_unit = er_model.get_er_com_param().get_internal_via_unit(); + + for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { + for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { + GCell& gcell = gcell_map[x][y]; + gcell.set_boundary_wire_unit(boundary_wire_unit); + gcell.set_internal_wire_unit(internal_wire_unit); + gcell.set_internal_via_unit(internal_via_unit); + } + } +} + void EarlyRouter::initERTaskList(ERModel& er_model) { std::vector& er_net_list = er_model.get_er_net_list(); @@ -203,6 +504,14 @@ void EarlyRouter::buildPlanarNodeMap(ERModel& er_model) for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { ERNode& er_node = planar_node_map[x][y]; er_node.set_coord(x, y); + er_node.set_boundary_wire_unit(gcell_map[x][y].get_boundary_wire_unit()); + er_node.set_internal_wire_unit(gcell_map[x][y].get_internal_wire_unit()); + er_node.set_internal_via_unit(gcell_map[x][y].get_internal_via_unit()); + for (auto& [routing_layer_idx, ignore_net_orient_map] : gcell_map[x][y].get_routing_ignore_net_orient_map()) { + for (auto& [net_idx, orient_set] : ignore_net_orient_map) { + er_node.get_ignore_net_orient_map()[net_idx].insert(orient_set.begin(), orient_set.end()); + } + } } } RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); @@ -261,7 +570,7 @@ void EarlyRouter::buildPlanarOrientSupply(ERModel& er_model) RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } -void EarlyRouter::generateTopoTree(ERModel& er_model) +void EarlyRouter::generateTopology(ERModel& er_model) { Monitor monitor; RTLOG.info(Loc::current(), "Starting..."); @@ -272,7 +581,7 @@ void EarlyRouter::generateTopoTree(ERModel& er_model) Monitor stage_monitor; for (size_t i = 0; i < er_task_list.size(); i++) { - routePlanarNet(er_model, er_task_list[i]); + generateERTask(er_model, er_task_list[i]); if ((i + 1) % batch_size == 0 || (i + 1) == er_task_list.size()) { RTLOG.info(Loc::current(), "Routed ", (i + 1), "/", er_task_list.size(), "(", RTUTIL.getPercentage(i + 1, er_task_list.size()), ") nets", stage_monitor.getStatsInfo()); @@ -282,28 +591,61 @@ void EarlyRouter::generateTopoTree(ERModel& er_model) RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } -void EarlyRouter::routePlanarNet(ERModel& er_model, ERNet* er_net) +void EarlyRouter::generateERTask(ERModel& er_model, ERNet* er_task) +{ + initSinglePlanarTask(er_model, er_task); + std::vector> routing_segment_list = getPlanarRoutingSegmentList(er_model); + MTree coord_tree = getCoordTree(er_model, routing_segment_list); + updateDemandToGraph(er_model, ChangeType::kAdd, coord_tree); + er_task->set_planar_tree(coord_tree); + resetSinglePlanarTask(er_model); +} + +void EarlyRouter::initSinglePlanarTask(ERModel& er_model, ERNet* er_task) { + er_model.set_curr_er_task(er_task); +} + +std::vector> EarlyRouter::getPlanarRoutingSegmentList(ERModel& er_model) +{ + std::vector> planar_topo_list = getPlanarTopoList(er_model); + + std::vector er_candidate_list; + for (size_t i = 0; i < planar_topo_list.size(); i++) { + for (std::vector> routing_segment_list : getRoutingSegmentListList(er_model, planar_topo_list[i])) { + er_candidate_list.emplace_back(i, routing_segment_list, 0); + } + } +#pragma omp parallel for + for (ERCandidate& er_candidate : er_candidate_list) { + er_candidate.set_cost(getNodeCost(er_model, er_candidate.get_routing_segment_list())); + } + std::map topo_candidate_map; + for (ERCandidate& er_candidate : er_candidate_list) { + int32_t topo_idx = er_candidate.get_topo_idx(); + if (!RTUTIL.exist(topo_candidate_map, topo_idx)) { + topo_candidate_map[topo_idx] = &er_candidate; + } + if (er_candidate.get_cost() < topo_candidate_map[topo_idx]->get_cost()) { + topo_candidate_map[topo_idx] = &er_candidate; + } + } std::vector> routing_segment_list; - for (Segment& planar_topo : getPlanarTopoList(er_model, er_net)) { - for (Segment& routing_segment : getRoutingSegmentList(er_model, planar_topo)) { + for (auto& [topo_idx, min_candidate] : topo_candidate_map) { + for (Segment& routing_segment : min_candidate->get_routing_segment_list()) { routing_segment_list.push_back(routing_segment); } } - MTree coord_tree = getPlanarCoordTree(er_net, routing_segment_list); - updatePlanarDemandToGraph(er_model, ChangeType::kAdd, coord_tree); - if (!RTUTIL.getSegListByTree(coord_tree).empty()) { - er_net->set_topo_tree(coord_tree); - } + return routing_segment_list; } -std::vector> EarlyRouter::getPlanarTopoList(ERModel& er_model, ERNet* er_net) +std::vector> EarlyRouter::getPlanarTopoList(ERModel& er_model) { int32_t topo_spilt_length = er_model.get_er_com_param().get_topo_spilt_length(); std::vector planar_coord_list; { - for (ERPin& er_pin : er_net->get_er_pin_list()) { + for (ERPin& er_pin : er_model.get_curr_er_task()->get_er_pin_list()) { planar_coord_list.push_back(er_pin.get_access_point().get_grid_coord()); } std::sort(planar_coord_list.begin(), planar_coord_list.end(), CmpPlanarCoordByXASC()); @@ -348,34 +690,39 @@ std::vector> EarlyRouter::getPlanarTopoList(ERModel& er_mod return planar_topo_list; } -std::vector> EarlyRouter::getRoutingSegmentList(ERModel& er_model, Segment& planar_topo) +std::vector>> EarlyRouter::getRoutingSegmentListList(ERModel& er_model, Segment& planar_topo) { - std::vector> routing_segment_list; + std::vector>> routing_segment_list_list; for (auto getRoutingSegmentList : {std::bind(&EarlyRouter::getRoutingSegmentListByStraight, this, std::placeholders::_1, std::placeholders::_2), - std::bind(&EarlyRouter::getRoutingSegmentListByLPattern, this, std::placeholders::_1, std::placeholders::_2)}) { - if (routing_segment_list.empty()) { - routing_segment_list = getRoutingSegmentList(er_model, planar_topo); + std::bind(&EarlyRouter::getRoutingSegmentListByLPattern, this, std::placeholders::_1, std::placeholders::_2), + std::bind(&EarlyRouter::getRoutingSegmentListByZPattern, this, std::placeholders::_1, std::placeholders::_2), + std::bind(&EarlyRouter::getRoutingSegmentListByUPattern, this, std::placeholders::_1, std::placeholders::_2), + std::bind(&EarlyRouter::getRoutingSegmentListByInner3Bends, this, std::placeholders::_1, std::placeholders::_2), + std::bind(&EarlyRouter::getRoutingSegmentListByOuter3Bends, this, std::placeholders::_1, std::placeholders::_2)}) { + for (std::vector> routing_segment_list : getRoutingSegmentList(er_model, planar_topo)) { + routing_segment_list_list.push_back(routing_segment_list); } } - if (routing_segment_list.empty()) { - RTLOG.error(Loc::current(), "The routing_segment_list is empty"); - } - return routing_segment_list; + return routing_segment_list_list; } -std::vector> EarlyRouter::getRoutingSegmentListByStraight(ERModel& er_model, Segment& planar_topo) +std::vector>> EarlyRouter::getRoutingSegmentListByStraight(ERModel& er_model, Segment& planar_topo) { PlanarCoord& first_coord = planar_topo.get_first(); PlanarCoord& second_coord = planar_topo.get_second(); if (RTUTIL.isOblique(first_coord, second_coord)) { return {}; } - std::vector> routing_segment_list; - routing_segment_list.emplace_back(first_coord, second_coord); - return routing_segment_list; + std::vector>> routing_segment_list_list; + { + std::vector> routing_segment_list; + routing_segment_list.emplace_back(first_coord, second_coord); + routing_segment_list_list.push_back(routing_segment_list); + } + return routing_segment_list_list; } -std::vector> EarlyRouter::getRoutingSegmentListByLPattern(ERModel& er_model, Segment& planar_topo) +std::vector>> EarlyRouter::getRoutingSegmentListByLPattern(ERModel& er_model, Segment& planar_topo) { PlanarCoord& first_coord = planar_topo.get_first(); PlanarCoord& second_coord = planar_topo.get_second(); @@ -391,108 +738,377 @@ std::vector> EarlyRouter::getRoutingSegmentListByLPattern(E std::vector>> routing_segment_list_list; for (std::vector& inflection_list : inflection_list_list) { std::vector> routing_segment_list; - if (inflection_list.empty()) { - routing_segment_list.emplace_back(planar_topo.get_first(), planar_topo.get_second()); - } else { - routing_segment_list.emplace_back(planar_topo.get_first(), inflection_list.front()); - for (size_t i = 1; i < inflection_list.size(); i++) { - routing_segment_list.emplace_back(inflection_list[i - 1], inflection_list[i]); - } - routing_segment_list.emplace_back(inflection_list.back(), planar_topo.get_second()); + routing_segment_list.emplace_back(planar_topo.get_first(), inflection_list.front()); + for (size_t i = 1; i < inflection_list.size(); i++) { + routing_segment_list.emplace_back(inflection_list[i - 1], inflection_list[i]); } + routing_segment_list.emplace_back(inflection_list.back(), planar_topo.get_second()); routing_segment_list_list.push_back(routing_segment_list); } + return routing_segment_list_list; +} - double min_cost = DBL_MAX; - size_t min_i = 0; - for (size_t i = 0; i < routing_segment_list_list.size(); i++) { - double cost = getPlanarNodeCost(er_model, routing_segment_list_list[i]); - if (cost < min_cost) { - min_cost = cost; - min_i = i; +std::vector>> EarlyRouter::getRoutingSegmentListByZPattern(ERModel& er_model, Segment& planar_topo) +{ + PlanarCoord& first_coord = planar_topo.get_first(); + PlanarCoord& second_coord = planar_topo.get_second(); + if (RTUTIL.isRightAngled(first_coord, second_coord)) { + return {}; + } + std::vector x_mid_index_list = getMidIndexList(first_coord.get_x(), second_coord.get_x()); + std::vector y_mid_index_list = getMidIndexList(first_coord.get_y(), second_coord.get_y()); + if (x_mid_index_list.empty() && y_mid_index_list.empty()) { + return {}; + } + std::vector> inflection_list_list; + for (size_t i = 0; i < x_mid_index_list.size(); i++) { + PlanarCoord inflection_coord1(x_mid_index_list[i], first_coord.get_y()); + PlanarCoord inflection_coord2(x_mid_index_list[i], second_coord.get_y()); + inflection_list_list.push_back({inflection_coord1, inflection_coord2}); + } + for (size_t i = 0; i < y_mid_index_list.size(); i++) { + PlanarCoord inflection_coord1(first_coord.get_x(), y_mid_index_list[i]); + PlanarCoord inflection_coord2(second_coord.get_x(), y_mid_index_list[i]); + inflection_list_list.push_back({inflection_coord1, inflection_coord2}); + } + std::vector>> routing_segment_list_list; + for (std::vector& inflection_list : inflection_list_list) { + std::vector> routing_segment_list; + routing_segment_list.emplace_back(planar_topo.get_first(), inflection_list.front()); + for (size_t i = 1; i < inflection_list.size(); i++) { + routing_segment_list.emplace_back(inflection_list[i - 1], inflection_list[i]); } + routing_segment_list.emplace_back(inflection_list.back(), planar_topo.get_second()); + routing_segment_list_list.push_back(routing_segment_list); } - return routing_segment_list_list[min_i]; + return routing_segment_list_list; } -double EarlyRouter::getPlanarNodeCost(ERModel& er_model, std::vector>& routing_segment_list) +std::vector EarlyRouter::getMidIndexList(int32_t first_idx, int32_t second_idx) { - double overflow_unit = er_model.get_er_com_param().get_overflow_unit(); - GridMap& planar_node_map = er_model.get_planar_node_map(); - - double node_cost = 0; - for (Segment& coord_segment : routing_segment_list) { - PlanarCoord& first_coord = coord_segment.get_first(); - PlanarCoord& second_coord = coord_segment.get_second(); + std::vector mid_index_list; + RTUTIL.swapByASC(first_idx, second_idx); + mid_index_list.reserve(second_idx - first_idx - 1); + for (int32_t i = (first_idx + 1); i <= (second_idx - 1); i++) { + mid_index_list.push_back(i); + } + return mid_index_list; +} - Orientation orientation = RTUTIL.getOrientation(first_coord, second_coord); - if (orientation == Orientation::kNone || orientation == Orientation::kOblique) { - RTLOG.error(Loc::current(), "The orientation is error!"); - } - Orientation opposite_orientation = RTUTIL.getOppositeOrientation(orientation); +std::vector>> EarlyRouter::getRoutingSegmentListByUPattern(ERModel& er_model, Segment& planar_topo) +{ + Die& die = RTDM.getDatabase().get_die(); + int32_t expand_step_num = er_model.get_er_com_param().get_expand_step_num(); + int32_t expand_step_length = er_model.get_er_com_param().get_expand_step_length(); - node_cost += planar_node_map[first_coord.get_x()][first_coord.get_y()].getOverflowCost(orientation, overflow_unit); - node_cost += planar_node_map[second_coord.get_x()][second_coord.get_y()].getOverflowCost(opposite_orientation, overflow_unit); + PlanarCoord& first_coord = planar_topo.get_first(); + PlanarCoord& second_coord = planar_topo.get_second(); + if (RTUTIL.getManhattanDistance(first_coord, second_coord) <= 1) { + return {}; + } + int32_t first_x = first_coord.get_x(); + int32_t second_x = second_coord.get_x(); + int32_t first_y = first_coord.get_y(); + int32_t second_y = second_coord.get_y(); + RTUTIL.swapByASC(first_x, second_x); + RTUTIL.swapByASC(first_y, second_y); - if (RTUTIL.isHorizontal(first_coord, second_coord)) { - int32_t first_x = first_coord.get_x(); - int32_t second_x = second_coord.get_x(); - int32_t y = first_coord.get_y(); - RTUTIL.swapByASC(first_x, second_x); - for (int32_t x = (first_x + 1); x <= (second_x - 1); x++) { - node_cost += planar_node_map[x][y].getOverflowCost(orientation, overflow_unit); - node_cost += planar_node_map[x][y].getOverflowCost(opposite_orientation, overflow_unit); + std::vector> inflection_list_list; + if (!RTUTIL.isHorizontal(first_coord, second_coord)) { + for (int32_t i = 0; i < expand_step_num; i++) { + first_x -= expand_step_length; + if (first_x >= die.get_grid_ll_x()) { + PlanarCoord inflection_coord1(first_x, first_coord.get_y()); + PlanarCoord inflection_coord2(first_x, second_coord.get_y()); + inflection_list_list.push_back({inflection_coord1, inflection_coord2}); } - } else if (RTUTIL.isVertical(first_coord, second_coord)) { - int32_t x = first_coord.get_x(); - int32_t first_y = first_coord.get_y(); - int32_t second_y = second_coord.get_y(); - RTUTIL.swapByASC(first_y, second_y); - for (int32_t y = (first_y + 1); y <= (second_y - 1); y++) { - node_cost += planar_node_map[x][y].getOverflowCost(orientation, overflow_unit); - node_cost += planar_node_map[x][y].getOverflowCost(opposite_orientation, overflow_unit); + second_x += expand_step_length; + if (second_x <= die.get_grid_ur_x()) { + PlanarCoord inflection_coord1(second_x, first_coord.get_y()); + PlanarCoord inflection_coord2(second_x, second_coord.get_y()); + inflection_list_list.push_back({inflection_coord1, inflection_coord2}); } } } - return node_cost; + if (!RTUTIL.isVertical(first_coord, second_coord)) { + for (int32_t i = 0; i < expand_step_num; i++) { + first_y -= expand_step_length; + if (first_y >= die.get_grid_ll_y()) { + PlanarCoord inflection_coord1(first_coord.get_x(), first_y); + PlanarCoord inflection_coord2(second_coord.get_x(), first_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2}); + } + second_y += expand_step_length; + if (second_y <= die.get_grid_ur_y()) { + PlanarCoord inflection_coord1(first_coord.get_x(), second_y); + PlanarCoord inflection_coord2(second_coord.get_x(), second_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2}); + } + } + } + std::vector>> routing_segment_list_list; + for (std::vector& inflection_list : inflection_list_list) { + std::vector> routing_segment_list; + routing_segment_list.emplace_back(planar_topo.get_first(), inflection_list.front()); + for (size_t i = 1; i < inflection_list.size(); i++) { + routing_segment_list.emplace_back(inflection_list[i - 1], inflection_list[i]); + } + routing_segment_list.emplace_back(inflection_list.back(), planar_topo.get_second()); + routing_segment_list_list.push_back(routing_segment_list); + } + return routing_segment_list_list; } -MTree EarlyRouter::getPlanarCoordTree(ERNet* er_net, std::vector>& planar_routing_segment_list) +std::vector>> EarlyRouter::getRoutingSegmentListByInner3Bends(ERModel& er_model, Segment& planar_topo) { - std::vector> routing_segment_list; - for (Segment& planar_routing_segment : planar_routing_segment_list) { - routing_segment_list.emplace_back(LayerCoord(planar_routing_segment.get_first(), 0), LayerCoord(planar_routing_segment.get_second(), 0)); + PlanarCoord& first_coord = planar_topo.get_first(); + PlanarCoord& second_coord = planar_topo.get_second(); + if (RTUTIL.isRightAngled(first_coord, second_coord)) { + return {}; } - std::vector candidate_root_coord_list; - std::map, CmpLayerCoordByXASC> key_coord_pin_map; - std::vector& er_pin_list = er_net->get_er_pin_list(); - for (size_t i = 0; i < er_pin_list.size(); i++) { - LayerCoord coord(er_pin_list[i].get_access_point().get_grid_coord(), 0); - candidate_root_coord_list.push_back(coord); - key_coord_pin_map[coord].insert(static_cast(i)); + std::vector x_mid_index_list = getMidIndexList(first_coord.get_x(), second_coord.get_x()); + std::vector y_mid_index_list = getMidIndexList(first_coord.get_y(), second_coord.get_y()); + if (x_mid_index_list.empty() || y_mid_index_list.empty()) { + return {}; } - return RTUTIL.getTreeByFullFlow(candidate_root_coord_list, routing_segment_list, key_coord_pin_map); + std::vector> inflection_list_list; + for (size_t i = 0; i < x_mid_index_list.size(); i++) { + for (size_t j = 0; j < y_mid_index_list.size(); j++) { + PlanarCoord inflection_coord1(x_mid_index_list[i], first_coord.get_y()); + PlanarCoord inflection_coord2(x_mid_index_list[i], y_mid_index_list[j]); + PlanarCoord inflection_coord3(second_coord.get_x(), y_mid_index_list[j]); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + } + + for (size_t i = 0; i < x_mid_index_list.size(); i++) { + for (size_t j = 0; j < y_mid_index_list.size(); j++) { + PlanarCoord inflection_coord1(first_coord.get_x(), y_mid_index_list[j]); + PlanarCoord inflection_coord2(x_mid_index_list[i], y_mid_index_list[j]); + PlanarCoord inflection_coord3(x_mid_index_list[i], second_coord.get_y()); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + } + std::vector>> routing_segment_list_list; + for (std::vector& inflection_list : inflection_list_list) { + std::vector> routing_segment_list; + routing_segment_list.emplace_back(planar_topo.get_first(), inflection_list.front()); + for (size_t i = 1; i < inflection_list.size(); i++) { + routing_segment_list.emplace_back(inflection_list[i - 1], inflection_list[i]); + } + routing_segment_list.emplace_back(inflection_list.back(), planar_topo.get_second()); + routing_segment_list_list.push_back(routing_segment_list); + } + return routing_segment_list_list; } -void EarlyRouter::buildLayerNodeMap(ERModel& er_model) +std::vector>> EarlyRouter::getRoutingSegmentListByOuter3Bends(ERModel& er_model, Segment& planar_topo) { - Monitor monitor; - RTLOG.info(Loc::current(), "Starting..."); + Die& die = RTDM.getDatabase().get_die(); + int32_t expand_step_num = er_model.get_er_com_param().get_expand_step_num(); + int32_t expand_step_length = er_model.get_er_com_param().get_expand_step_length(); - GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + PlanarCoord& first_coord = planar_topo.get_first(); + PlanarCoord& second_coord = planar_topo.get_second(); + if (RTUTIL.isRightAngled(first_coord, second_coord)) { + return {}; + } + int32_t start_x = first_coord.get_x(); + int32_t end_x = second_coord.get_x(); + int32_t start_y = first_coord.get_y(); + int32_t end_y = second_coord.get_y(); - std::vector>& layer_node_map = er_model.get_layer_node_map(); - layer_node_map.resize(routing_layer_list.size()); -#pragma omp parallel for - for (int32_t layer_idx = 0; layer_idx < static_cast(layer_node_map.size()); layer_idx++) { - GridMap& er_node_map = layer_node_map[layer_idx]; - er_node_map.init(gcell_map.get_x_size(), gcell_map.get_y_size()); + int32_t box_lb_x = std::min(start_x, end_x); + int32_t box_rt_x = std::max(start_x, end_x); + int32_t box_lb_y = std::min(start_y, end_y); + int32_t box_rt_y = std::max(start_y, end_y); + + std::vector> inflection_list_list; + for (int32_t i = 0; i < expand_step_num; i++) { + box_lb_x -= expand_step_length; + box_rt_x += expand_step_length; + box_lb_y -= expand_step_length; + box_rt_y += expand_step_length; + if (start_x < end_x) { + if (start_y < end_y) { + /** + * line style + * + * x(e) + * x + * x + * x(s) + * + */ + if (die.get_grid_ll_y() <= box_lb_y && box_rt_x <= die.get_grid_ur_x()) { + PlanarCoord inflection_coord1(start_x, box_lb_y); + PlanarCoord inflection_coord2(box_rt_x, box_lb_y); + PlanarCoord inflection_coord3(box_rt_x, end_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + if (die.get_grid_ll_x() <= box_lb_x && box_rt_y <= die.get_grid_ur_y()) { + PlanarCoord inflection_coord1(box_lb_x, start_y); + PlanarCoord inflection_coord2(box_lb_x, box_rt_y); + PlanarCoord inflection_coord3(end_x, box_rt_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + } else { + /** + * line style + * + * x(s) + * x + * x + * x(e) + * + */ + if (box_rt_x <= die.get_grid_ur_x() && box_rt_y <= die.get_grid_ur_y()) { + PlanarCoord inflection_coord1(start_x, box_rt_y); + PlanarCoord inflection_coord2(box_rt_x, box_rt_y); + PlanarCoord inflection_coord3(box_rt_x, end_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + if (die.get_grid_ll_x() <= box_lb_x && die.get_grid_ll_y() <= box_lb_y) { + PlanarCoord inflection_coord1(box_lb_x, start_y); + PlanarCoord inflection_coord2(box_lb_x, box_lb_y); + PlanarCoord inflection_coord3(end_x, box_lb_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + } + + } else { + if (start_y < end_y) { + /** + * line style + * + * x(e) + * x + * x + * x(s) + * + */ + if (box_rt_x <= die.get_grid_ur_x() && box_rt_y <= die.get_grid_ur_y()) { + PlanarCoord inflection_coord1(box_rt_x, start_y); + PlanarCoord inflection_coord2(box_rt_x, box_rt_y); + PlanarCoord inflection_coord3(end_x, box_rt_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + if (die.get_grid_ll_x() <= box_lb_x && die.get_grid_ll_y() <= box_lb_y) { + PlanarCoord inflection_coord1(start_x, box_lb_y); + PlanarCoord inflection_coord2(box_lb_x, box_lb_y); + PlanarCoord inflection_coord3(box_lb_x, end_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + } else { + /** + * line style + * + * x(s) + * x + * x + * x(e) + * + */ + if (die.get_grid_ll_y() <= box_lb_y && box_rt_x <= die.get_grid_ur_x()) { + PlanarCoord inflection_coord1(box_rt_x, start_y); + PlanarCoord inflection_coord2(box_rt_x, box_lb_y); + PlanarCoord inflection_coord3(end_x, box_lb_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + if (die.get_grid_ll_x() <= box_lb_x && box_rt_y <= die.get_grid_ur_y()) { + PlanarCoord inflection_coord1(start_x, box_rt_y); + PlanarCoord inflection_coord2(box_lb_x, box_rt_y); + PlanarCoord inflection_coord3(box_lb_x, end_y); + inflection_list_list.push_back({inflection_coord1, inflection_coord2, inflection_coord3}); + } + } + } + } + std::vector>> routing_segment_list_list; + for (std::vector& inflection_list : inflection_list_list) { + std::vector> routing_segment_list; + routing_segment_list.emplace_back(planar_topo.get_first(), inflection_list.front()); + for (size_t i = 1; i < inflection_list.size(); i++) { + routing_segment_list.emplace_back(inflection_list[i - 1], inflection_list[i]); + } + routing_segment_list.emplace_back(inflection_list.back(), planar_topo.get_second()); + routing_segment_list_list.push_back(routing_segment_list); + } + return routing_segment_list_list; +} + +double EarlyRouter::getNodeCost(ERModel& er_model, std::vector>& routing_segment_list) +{ + double overflow_unit = er_model.get_er_com_param().get_overflow_unit(); + GridMap& planar_node_map = er_model.get_planar_node_map(); + int32_t curr_net_idx = er_model.get_curr_er_task()->get_net_idx(); + + double node_cost = 0; + for (Segment& coord_segment : routing_segment_list) { + PlanarCoord& first_coord = coord_segment.get_first(); + PlanarCoord& second_coord = coord_segment.get_second(); + if (!RTUTIL.isRightAngled(first_coord, second_coord)) { + RTLOG.error(Loc::current(), "The direction is error!"); + } + int32_t first_x = first_coord.get_x(); + int32_t second_x = second_coord.get_x(); + int32_t first_y = first_coord.get_y(); + int32_t second_y = second_coord.get_y(); + RTUTIL.swapByASC(first_x, second_x); + RTUTIL.swapByASC(first_y, second_y); + Direction direction = RTUTIL.getDirection(first_coord, second_coord); + for (int32_t x = first_x; x <= second_x; x++) { + for (int32_t y = first_y; y <= second_y; y++) { + node_cost += planar_node_map[x][y].getOverflowCost(curr_net_idx, direction, overflow_unit); + } + } + } + return node_cost; +} + +MTree EarlyRouter::getCoordTree(ERModel& er_model, std::vector>& routing_segment_list) +{ + std::vector candidate_root_coord_list; + std::map, CmpPlanarCoordByXASC> key_coord_pin_map; + std::vector& er_pin_list = er_model.get_curr_er_task()->get_er_pin_list(); + for (size_t i = 0; i < er_pin_list.size(); i++) { + PlanarCoord coord = er_pin_list[i].get_access_point().get_grid_coord(); + candidate_root_coord_list.push_back(coord); + key_coord_pin_map[coord].insert(static_cast(i)); + } + return RTUTIL.getTreeByFullFlow(candidate_root_coord_list, routing_segment_list, key_coord_pin_map); +} + +void EarlyRouter::resetSinglePlanarTask(ERModel& er_model) +{ + er_model.set_curr_er_task(nullptr); +} + +void EarlyRouter::buildLayerNodeMap(ERModel& er_model) +{ + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + + std::vector>& layer_node_map = er_model.get_layer_node_map(); + layer_node_map.resize(routing_layer_list.size()); +#pragma omp parallel for + for (int32_t layer_idx = 0; layer_idx < static_cast(layer_node_map.size()); layer_idx++) { + GridMap& er_node_map = layer_node_map[layer_idx]; + er_node_map.init(gcell_map.get_x_size(), gcell_map.get_y_size()); for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { ERNode& er_node = er_node_map[x][y]; er_node.set_coord(x, y); er_node.set_layer_idx(layer_idx); + er_node.set_boundary_wire_unit(gcell_map[x][y].get_boundary_wire_unit()); + er_node.set_internal_wire_unit(gcell_map[x][y].get_internal_wire_unit()); + er_node.set_internal_via_unit(gcell_map[x][y].get_internal_via_unit()); + if (RTUTIL.exist(gcell_map[x][y].get_routing_ignore_net_orient_map(), layer_idx)) { + er_node.set_ignore_net_orient_map(gcell_map[x][y].get_routing_ignore_net_orient_map()[layer_idx]); + } } } } @@ -574,7 +1190,7 @@ void EarlyRouter::buildLayerOrientSupply(ERModel& er_model) RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } -void EarlyRouter::generateGlobalTree(ERModel& er_model) +void EarlyRouter::assignLayer(ERModel& er_model) { Monitor monitor; RTLOG.info(Loc::current(), "Starting..."); @@ -585,7 +1201,7 @@ void EarlyRouter::generateGlobalTree(ERModel& er_model) Monitor stage_monitor; for (size_t i = 0; i < er_task_list.size(); i++) { - routeLayerNet(er_model, er_task_list[i]); + assignERTask(er_model, er_task_list[i]); if ((i + 1) % batch_size == 0 || (i + 1) == er_task_list.size()) { RTLOG.info(Loc::current(), "Routed ", (i + 1), "/", er_task_list.size(), "(", RTUTIL.getPercentage(i + 1, er_task_list.size()), ") nets", stage_monitor.getStatsInfo()); @@ -595,559 +1211,578 @@ void EarlyRouter::generateGlobalTree(ERModel& er_model) RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } -void EarlyRouter::routeLayerNet(ERModel& er_model, ERNet* er_net) +void EarlyRouter::assignERTask(ERModel& er_model, ERNet* er_task) { - // 构建er_topo_list,并将通孔线段加入routing_segment_list - std::vector er_topo_list; - std::vector> routing_segment_list; - makeERTopoList(er_model, er_net, er_topo_list, routing_segment_list); - for (ERTopo& er_topo : er_topo_list) { - routeERTopo(er_model, &er_topo); - for (Segment& routing_segment : er_topo.get_routing_segment_list()) { - routing_segment_list.push_back(routing_segment); - } + initSingleTask(er_model, er_task); + if (needRouting(er_model)) { + spiltPlaneTree(er_model); + buildPillarTree(er_model); + assignPillarTree(er_model); + buildLayerTree(er_model, er_task); } - MTree coord_tree = getLayerCoordTree(er_net, routing_segment_list); - updateLayerDemandToGraph(er_model, ChangeType::kAdd, coord_tree); - uploadNetResult(er_net, coord_tree); + resetSingleLayerTask(er_model); } -void EarlyRouter::makeERTopoList(ERModel& er_model, ERNet* er_net, std::vector& er_topo_list, std::vector>& routing_segment_list) +void EarlyRouter::initSingleTask(ERModel& er_model, ERNet* er_task) +{ + er_model.set_curr_er_task(er_task); +} + +bool EarlyRouter::needRouting(ERModel& er_model) +{ + return (er_model.get_curr_er_task()->get_planar_tree().get_root() != nullptr); +} + +void EarlyRouter::spiltPlaneTree(ERModel& er_model) { - int32_t bottom_routing_layer_idx = RTDM.getConfig().bottom_routing_layer_idx; - int32_t top_routing_layer_idx = RTDM.getConfig().top_routing_layer_idx; int32_t topo_spilt_length = er_model.get_er_com_param().get_topo_spilt_length(); - if (er_net->get_topo_tree().get_root() == nullptr) { - ERTopo er_topo; - for (ERPin& er_pin : er_net->get_er_pin_list()) { - ERGroup er_group; - er_group.get_coord_list().push_back(er_pin.get_access_point().getGridLayerCoord()); - er_topo.get_er_group_list().push_back(er_group); - } - er_topo_list.push_back(er_topo); - { - std::set coord_set; - for (ERTopo& er_topo : er_topo_list) { - for (ERGroup& er_group : er_topo.get_er_group_list()) { - for (LayerCoord& coord : er_group.get_coord_list()) { - coord_set.insert(coord); - } - } - } - if (coord_set.size() > 1) { - RTLOG.error(Loc::current(), "The topo_tree should not be empty!"); - } - } - } else { - // planar_topo_list - std::vector> planar_topo_list; - { - for (Segment*>& coord_segment : RTUTIL.getSegListByTree(er_net->get_topo_tree())) { - PlanarCoord& first_coord = coord_segment.get_first()->value(); - PlanarCoord& second_coord = coord_segment.get_second()->value(); - int32_t first_x = first_coord.get_x(); - int32_t first_y = first_coord.get_y(); - int32_t second_x = second_coord.get_x(); - int32_t second_y = second_coord.get_y(); - - if (first_x == second_x) { - int32_t y_diff = std::abs(second_y - first_y); - int32_t segment_num = std::max(1, static_cast(std::ceil(y_diff / topo_spilt_length))); - int32_t step = (second_y - first_y) / segment_num; - for (int32_t i = 0; i < segment_num; ++i) { - PlanarCoord start(first_x, first_y + i * step); - PlanarCoord end(first_x, first_y + (i + 1) * step); - planar_topo_list.emplace_back(start, end); - } - // Add the last segment to reach the exact second_coord - if (planar_topo_list.back().get_second().get_y() != second_y) { - planar_topo_list.emplace_back(planar_topo_list.back().get_second(), second_coord); - } - } else if (first_y == second_y) { - int32_t x_diff = std::abs(second_x - first_x); - int32_t segment_num = std::max(1, static_cast(std::ceil(x_diff / topo_spilt_length))); - int32_t step = (second_x - first_x) / segment_num; - for (int32_t i = 0; i < segment_num; ++i) { - PlanarCoord start(first_x + i * step, first_y); - PlanarCoord end(first_x + (i + 1) * step, first_y); - planar_topo_list.emplace_back(start, end); - } - if (planar_topo_list.back().get_second().get_x() != second_x) { - planar_topo_list.emplace_back(planar_topo_list.back().get_second(), second_coord); - } - } else { - RTLOG.error(Loc::current(), "The segment is not horizontal or vertical!"); - } + TNode* planar_tree_root = er_model.get_curr_er_task()->get_planar_tree().get_root(); + std::queue*> planar_queue = RTUTIL.initQueue(planar_tree_root); + while (!planar_queue.empty()) { + TNode* planar_node = RTUTIL.getFrontAndPop(planar_queue); + std::vector*> child_list = planar_node->get_child_list(); + for (size_t i = 0; i < child_list.size(); i++) { + int32_t length = RTUTIL.getManhattanDistance(planar_node->value(), child_list[i]->value()); + if (length <= topo_spilt_length) { + continue; } + insertMidPoint(er_model, planar_node, child_list[i]); } - // planar_pin_group_map - std::map, CmpPlanarCoordByXASC> planar_pin_group_map; - { - for (ERPin& er_pin : er_net->get_er_pin_list()) { - LayerCoord grid_coord = er_pin.get_access_point().getGridLayerCoord(); + RTUTIL.addListToQueue(planar_queue, child_list); + } +} - ERGroup er_group; - er_group.get_coord_list().push_back(grid_coord); - planar_pin_group_map[grid_coord.get_planar_coord()].push_back(er_group); +void EarlyRouter::insertMidPoint(ERModel& er_model, TNode* planar_node, TNode* child_node) +{ + int32_t topo_spilt_length = er_model.get_er_com_param().get_topo_spilt_length(); + + PlanarCoord& parent_coord = planar_node->value(); + PlanarCoord& child_coord = child_node->value(); + if (RTUTIL.isProximal(parent_coord, child_coord)) { + return; + } + std::vector mid_coord_list; + int32_t x1 = parent_coord.get_x(); + int32_t x2 = child_coord.get_x(); + int32_t y1 = parent_coord.get_y(); + int32_t y2 = child_coord.get_y(); + if (RTUTIL.isHorizontal(parent_coord, child_coord)) { + RTUTIL.swapByASC(x1, x2); + for (int32_t x = x1 + topo_spilt_length; x < x2; x += topo_spilt_length) { + mid_coord_list.emplace_back(x, y1); + } + if (parent_coord.get_x() > child_coord.get_x()) { + for (size_t i = 0, j = mid_coord_list.size() - 1; i < j; i++, j--) { + std::swap(mid_coord_list[i], mid_coord_list[j]); } } - // planar_steiner_group_map - std::map planar_steiner_group_map; - { - for (Segment& planar_topo : planar_topo_list) { - for (PlanarCoord coord : {planar_topo.get_first(), planar_topo.get_second()}) { - if (!RTUTIL.exist(planar_pin_group_map, coord) && !RTUTIL.exist(planar_steiner_group_map, coord)) { - // 补充steiner point的垂直线段 - routing_segment_list.emplace_back(LayerCoord(coord, bottom_routing_layer_idx), LayerCoord(coord, top_routing_layer_idx)); - for (int32_t layer_idx = bottom_routing_layer_idx; layer_idx <= top_routing_layer_idx; layer_idx++) { - planar_steiner_group_map[coord].get_coord_list().push_back(LayerCoord(coord, layer_idx)); - } - } - } - } + } else if (RTUTIL.isVertical(parent_coord, child_coord)) { + RTUTIL.swapByASC(y1, y2); + for (int32_t y = y1 + topo_spilt_length; y < y2; y += topo_spilt_length) { + mid_coord_list.emplace_back(x1, y); } - // 生成topo group - { - for (Segment& planar_topo : planar_topo_list) { - ERTopo er_topo; - for (PlanarCoord coord : {planar_topo.get_first(), planar_topo.get_second()}) { - if (RTUTIL.exist(planar_pin_group_map, coord)) { - for (ERGroup& er_group : planar_pin_group_map[coord]) { - er_topo.get_er_group_list().push_back(er_group); - } - } else if (RTUTIL.exist(planar_steiner_group_map, coord)) { - er_topo.get_er_group_list().push_back(planar_steiner_group_map[coord]); - } - } - er_topo_list.push_back(er_topo); + if (parent_coord.get_y() > child_coord.get_y()) { + for (size_t i = 0, j = mid_coord_list.size() - 1; i < j; i++, j--) { + std::swap(mid_coord_list[i], mid_coord_list[j]); } } + } else { + RTLOG.error(Loc::current(), "The segment is oblique!"); } - // 构建topo的其他内容 - { - for (ERTopo& er_topo : er_topo_list) { - er_topo.set_net_idx(er_net->get_net_idx()); - std::vector coord_list; - for (ERGroup& er_group : er_topo.get_er_group_list()) { - for (LayerCoord& coord : er_group.get_coord_list()) { - coord_list.push_back(coord); - } - } - er_topo.set_bounding_box(RTUTIL.getBoundingBox(coord_list)); - } + planar_node->delChild(child_node); + TNode* curr_node = planar_node; + for (size_t i = 0; i < mid_coord_list.size(); i++) { + TNode* mid_node = new TNode(mid_coord_list[i]); + curr_node->addChild(mid_node); + curr_node = mid_node; } + curr_node->addChild(child_node); } -void EarlyRouter::routeERTopo(ERModel& er_model, ERTopo* er_topo) +void EarlyRouter::buildPillarTree(ERModel& er_model) { - initSingleTask(er_model, er_topo); - while (!isConnectedAllEnd(er_model)) { - routeSinglePath(er_model); - updatePathResult(er_model); - resetStartAndEnd(er_model); - resetSinglePath(er_model); + ERNet* curr_er_task = er_model.get_curr_er_task(); + + std::map, CmpPlanarCoordByXASC> coord_pin_layer_map; + for (ERPin& er_pin : curr_er_task->get_er_pin_list()) { + AccessPoint& access_point = er_pin.get_access_point(); + coord_pin_layer_map[access_point.get_grid_coord()].insert(access_point.get_layer_idx()); } - updateTaskResult(er_model); - resetSingleTask(er_model); + std::function, CmpPlanarCoordByXASC>&)> convert; + convert = std::bind(&EarlyRouter::convertERPillar, this, std::placeholders::_1, std::placeholders::_2); + curr_er_task->set_pillar_tree(RTUTIL.convertTree(curr_er_task->get_planar_tree(), convert, coord_pin_layer_map)); } -void EarlyRouter::initSingleTask(ERModel& er_model, ERTopo* er_topo) +ERPillar EarlyRouter::convertERPillar(PlanarCoord& planar_coord, std::map, CmpPlanarCoordByXASC>& coord_pin_layer_map) { - std::vector>& layer_node_map = er_model.get_layer_node_map(); - - // single topo - er_model.set_curr_er_topo(er_topo); - { - std::vector> node_list_list; - std::vector& er_group_list = er_topo->get_er_group_list(); - for (ERGroup& er_group : er_group_list) { - std::vector node_list; - for (LayerCoord& coord : er_group.get_coord_list()) { - ERNode& er_node = layer_node_map[coord.get_layer_idx()][coord.get_x()][coord.get_y()]; - node_list.push_back(&er_node); - } - node_list_list.push_back(node_list); - } - for (size_t i = 0; i < node_list_list.size(); i++) { - if (i == 0) { - er_model.get_start_node_list_list().push_back(node_list_list[i]); - } else { - er_model.get_end_node_list_list().push_back(node_list_list[i]); - } - } - } - er_model.get_path_node_list().clear(); - er_model.get_single_topo_visited_node_list().clear(); - er_model.get_routing_segment_list().clear(); + ERPillar er_pillar; + er_pillar.set_planar_coord(planar_coord); + er_pillar.set_pin_layer_idx_set(coord_pin_layer_map[planar_coord]); + return er_pillar; } -bool EarlyRouter::isConnectedAllEnd(ERModel& er_model) +void EarlyRouter::assignPillarTree(ERModel& er_model) { - return er_model.get_end_node_list_list().empty(); + assignForward(er_model); + assignBackward(er_model); } -void EarlyRouter::routeSinglePath(ERModel& er_model) +void EarlyRouter::assignForward(ERModel& er_model) { - initPathHead(er_model); - while (!searchEnded(er_model)) { - expandSearching(er_model); - resetPathHead(er_model); + TNode* pillar_tree_root = er_model.get_curr_er_task()->get_pillar_tree().get_root(); + + ERPackage er_package(pillar_tree_root, pillar_tree_root); + for (int32_t candidate_layer_idx : getCandidateLayerList(er_model, er_package)) { + std::set& pin_layer_idx_set = pillar_tree_root->value().get_pin_layer_idx_set(); + LALayerCost layer_cost; + layer_cost.set_parent_layer_idx(candidate_layer_idx); + layer_cost.set_layer_idx(candidate_layer_idx); + layer_cost.set_history_cost(getFullViaCost(er_model, pin_layer_idx_set, candidate_layer_idx)); + pillar_tree_root->value().get_layer_cost_list().push_back(std::move(layer_cost)); + } + std::queue*> pillar_node_queue = RTUTIL.initQueue(pillar_tree_root); + while (!pillar_node_queue.empty()) { + TNode* parent_pillar_node = RTUTIL.getFrontAndPop(pillar_node_queue); + std::vector*>& child_list = parent_pillar_node->get_child_list(); + for (size_t i = 0; i < child_list.size(); i++) { + ERPackage er_package(parent_pillar_node, child_list[i]); + buildLayerCost(er_model, er_package); + } + RTUTIL.addListToQueue(pillar_node_queue, child_list); } } -void EarlyRouter::initPathHead(ERModel& er_model) +std::vector EarlyRouter::getCandidateLayerList(ERModel& er_model, ERPackage& er_package) { - std::vector>& start_node_list_list = er_model.get_start_node_list_list(); - std::vector& path_node_list = er_model.get_path_node_list(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + int32_t bottom_routing_layer_idx = RTDM.getConfig().bottom_routing_layer_idx; + int32_t top_routing_layer_idx = RTDM.getConfig().top_routing_layer_idx; + + Direction direction = RTUTIL.getDirection(er_package.getParentPillar().get_planar_coord(), er_package.getChildPillar().get_planar_coord()); - for (std::vector& start_node_list : start_node_list_list) { - for (ERNode* start_node : start_node_list) { - start_node->set_estimated_cost(getEstimateCostToEnd(er_model, start_node)); - pushToOpenList(er_model, start_node); + std::vector candidate_layer_idx_list; + for (RoutingLayer& routing_layer : routing_layer_list) { + if (routing_layer.get_layer_idx() < bottom_routing_layer_idx || top_routing_layer_idx < routing_layer.get_layer_idx()) { + continue; + } + if (direction == Direction::kProximal) { + candidate_layer_idx_list.push_back(routing_layer.get_layer_idx()); + } else if (direction == routing_layer.get_prefer_direction()) { + candidate_layer_idx_list.push_back(routing_layer.get_layer_idx()); } } - for (ERNode* path_node : path_node_list) { - path_node->set_estimated_cost(getEstimateCostToEnd(er_model, path_node)); - pushToOpenList(er_model, path_node); - } - resetPathHead(er_model); + return candidate_layer_idx_list; } -bool EarlyRouter::searchEnded(ERModel& er_model) +double EarlyRouter::getFullViaCost(ERModel& er_model, std::set& layer_idx_set, int32_t candidate_layer_idx) { - std::vector>& end_node_list_list = er_model.get_end_node_list_list(); - ERNode* path_head_node = er_model.get_path_head_node(); + double via_unit = er_model.get_er_com_param().get_via_unit(); - if (path_head_node == nullptr) { - er_model.set_end_node_list_idx(-1); - return true; - } - for (size_t i = 0; i < end_node_list_list.size(); i++) { - for (ERNode* end_node : end_node_list_list[i]) { - if (path_head_node == end_node) { - er_model.set_end_node_list_idx(static_cast(i)); - return true; - } - } + int32_t via_num = 0; + if (layer_idx_set.size() > 0) { + std::set layer_idx_set_temp = layer_idx_set; + layer_idx_set_temp.insert(candidate_layer_idx); + via_num = std::abs(*layer_idx_set_temp.begin() - *layer_idx_set_temp.rbegin()); } - return false; + return (via_unit * via_num); } -void EarlyRouter::expandSearching(ERModel& er_model) +void EarlyRouter::buildLayerCost(ERModel& er_model, ERPackage& er_package) { - PriorityQueue, CmpERNodeCost>& open_queue = er_model.get_open_queue(); - ERNode* path_head_node = er_model.get_path_head_node(); + std::vector& layer_cost_list = er_package.getChildPillar().get_layer_cost_list(); - for (auto& [orientation, neighbor_node] : path_head_node->get_neighbor_node_map()) { - if (neighbor_node == nullptr) { - continue; - } - if (!RTUTIL.isInside(er_model.get_curr_er_topo()->get_bounding_box(), *neighbor_node)) { - continue; - } - if (neighbor_node->isClose()) { - continue; - } - double known_cost = getKnownCost(er_model, path_head_node, neighbor_node); - if (neighbor_node->isOpen() && known_cost < neighbor_node->get_known_cost()) { - neighbor_node->set_known_cost(known_cost); - neighbor_node->set_parent_node(path_head_node); - // 对优先队列中的值修改了,需要重新建堆 - std::make_heap(open_queue.begin(), open_queue.end(), CmpERNodeCost()); - } else if (neighbor_node->isNone()) { - neighbor_node->set_known_cost(known_cost); - neighbor_node->set_parent_node(path_head_node); - neighbor_node->set_estimated_cost(getEstimateCostToEnd(er_model, neighbor_node)); - pushToOpenList(er_model, neighbor_node); - } + for (int32_t candidate_layer_idx : getCandidateLayerList(er_model, er_package)) { + std::pair parent_pillar_cost_pair = getParentPillarCost(er_model, er_package, candidate_layer_idx); + double segment_cost = getSegmentCost(er_model, er_package, candidate_layer_idx); + double child_pillar_cost = getChildPillarCost(er_model, er_package, candidate_layer_idx); + + LALayerCost layer_cost; + layer_cost.set_parent_layer_idx(parent_pillar_cost_pair.first); + layer_cost.set_layer_idx(candidate_layer_idx); + layer_cost.set_history_cost(parent_pillar_cost_pair.second + segment_cost + child_pillar_cost); + layer_cost_list.push_back(std::move(layer_cost)); } } -void EarlyRouter::resetPathHead(ERModel& er_model) +std::pair EarlyRouter::getParentPillarCost(ERModel& er_model, ERPackage& er_package, int32_t candidate_layer_idx) { - er_model.set_path_head_node(popFromOpenList(er_model)); + ERPillar& parent_pillar = er_package.getParentPillar(); + + std::pair layer_cost_pair; + double min_cost = DBL_MAX; + for (LALayerCost& layer_cost : parent_pillar.get_layer_cost_list()) { + std::set layer_idx_set_temp = parent_pillar.get_pin_layer_idx_set(); + layer_idx_set_temp.insert(layer_cost.get_layer_idx()); + double curr_cost = layer_cost.get_history_cost() + getExtraViaCost(er_model, layer_idx_set_temp, candidate_layer_idx); + + if (curr_cost < min_cost) { + min_cost = curr_cost; + layer_cost_pair.first = layer_cost.get_layer_idx(); + layer_cost_pair.second = curr_cost; + } else if (curr_cost == min_cost) { + layer_cost_pair.first = std::min(layer_cost_pair.first, layer_cost.get_layer_idx()); + } + } + if (min_cost == DBL_MAX) { + RTLOG.error(Loc::current(), "The min cost is wrong!"); + } + return layer_cost_pair; } -void EarlyRouter::updatePathResult(ERModel& er_model) +double EarlyRouter::getExtraViaCost(ERModel& er_model, std::set& layer_idx_set, int32_t candidate_layer_idx) { - for (Segment& routing_segment : getRoutingSegmentListByNode(er_model.get_path_head_node())) { - er_model.get_routing_segment_list().push_back(routing_segment); + double via_unit = er_model.get_er_com_param().get_via_unit(); + + int32_t via_num = 0; + if (layer_idx_set.size() > 0) { + int32_t begin_layer_idx = *layer_idx_set.begin(); + int32_t end_layer_idx = *layer_idx_set.rbegin(); + if (candidate_layer_idx < begin_layer_idx) { + via_num = std::abs(candidate_layer_idx - begin_layer_idx); + } else if (end_layer_idx < candidate_layer_idx) { + via_num = std::abs(candidate_layer_idx - end_layer_idx); + } else { + via_num = 0; + } } + return (via_unit * via_num); } -std::vector> EarlyRouter::getRoutingSegmentListByNode(ERNode* node) +double EarlyRouter::getSegmentCost(ERModel& er_model, ERPackage& er_package, int32_t candidate_layer_idx) { - std::vector> routing_segment_list; + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + std::vector>& layer_node_map = er_model.get_layer_node_map(); + double overflow_unit = er_model.get_er_com_param().get_overflow_unit(); - ERNode* curr_node = node; - ERNode* pre_node = curr_node->get_parent_node(); + Direction prefer_direction = routing_layer_list[candidate_layer_idx].get_prefer_direction(); - if (pre_node == nullptr) { - // 起点和终点重合 - return routing_segment_list; - } - Orientation curr_orientation = RTUTIL.getOrientation(*curr_node, *pre_node); - while (pre_node->get_parent_node() != nullptr) { - Orientation pre_orientation = RTUTIL.getOrientation(*pre_node, *pre_node->get_parent_node()); - if (curr_orientation != pre_orientation) { - routing_segment_list.emplace_back(*curr_node, *pre_node); - curr_orientation = pre_orientation; - curr_node = pre_node; + PlanarCoord first_coord = er_package.getParentPillar().get_planar_coord(); + PlanarCoord second_coord = er_package.getChildPillar().get_planar_coord(); + int32_t first_x = first_coord.get_x(); + int32_t first_y = first_coord.get_y(); + int32_t second_x = second_coord.get_x(); + int32_t second_y = second_coord.get_y(); + RTUTIL.swapByASC(first_x, second_x); + RTUTIL.swapByASC(first_y, second_y); + + double node_cost = 0; + for (int32_t x = first_x; x <= second_x; x++) { + for (int32_t y = first_y; y <= second_y; y++) { + node_cost += layer_node_map[candidate_layer_idx][x][y].getOverflowCost(er_model.get_curr_er_task()->get_net_idx(), prefer_direction, overflow_unit); } - pre_node = pre_node->get_parent_node(); } - routing_segment_list.emplace_back(*curr_node, *pre_node); + return node_cost; +} - return routing_segment_list; +double EarlyRouter::getChildPillarCost(ERModel& er_model, ERPackage& er_package, int32_t candidate_layer_idx) +{ + ERPillar& child_pillar = er_package.getChildPillar(); + return getFullViaCost(er_model, child_pillar.get_pin_layer_idx_set(), candidate_layer_idx); } -void EarlyRouter::resetStartAndEnd(ERModel& er_model) +void EarlyRouter::assignBackward(ERModel& er_model) { - std::vector>& start_node_list_list = er_model.get_start_node_list_list(); - std::vector>& end_node_list_list = er_model.get_end_node_list_list(); - std::vector& path_node_list = er_model.get_path_node_list(); - ERNode* path_head_node = er_model.get_path_head_node(); - int32_t end_node_list_idx = er_model.get_end_node_list_idx(); + std::vector*>> level_list = RTUTIL.getLevelOrder(er_model.get_curr_er_task()->get_pillar_tree()); + if (level_list.empty()) { + return; + } + for (int32_t i = static_cast(level_list.size() - 1); i >= 0; i--) { + for (size_t j = 0; j < level_list[i].size(); j++) { + int32_t best_layer_idx; + if (level_list[i][j]->isLeafNode()) { + best_layer_idx = getBestLayerBySelf(level_list[i][j]); + } else { + best_layer_idx = getBestLayerByChild(level_list[i][j]); + } + level_list[i][j]->value().set_layer_idx(best_layer_idx); + } + } +} - // 对于抵达的终点pin,只保留到达的node - end_node_list_list[end_node_list_idx].clear(); - end_node_list_list[end_node_list_idx].push_back(path_head_node); +int32_t EarlyRouter::getBestLayerBySelf(TNode* pillar_node) +{ + std::vector& layer_cost_list = pillar_node->value().get_layer_cost_list(); - ERNode* path_node = path_head_node->get_parent_node(); - if (path_node == nullptr) { - // 起点和终点重合 - path_node = path_head_node; - } else { - // 起点和终点不重合 - while (path_node->get_parent_node() != nullptr) { - path_node_list.push_back(path_node); - path_node = path_node->get_parent_node(); + double min_cost = DBL_MAX; + int32_t best_layer_idx = layer_cost_list.front().get_layer_idx(); + for (LALayerCost& layer_cost : layer_cost_list) { + double cost = layer_cost.get_history_cost(); + if (cost < min_cost) { + min_cost = cost; + best_layer_idx = layer_cost.get_layer_idx(); + } else if (cost == min_cost) { + best_layer_idx = std::min(best_layer_idx, layer_cost.get_layer_idx()); } } - if (start_node_list_list.size() == 1) { - start_node_list_list.front().clear(); - start_node_list_list.front().push_back(path_node); + if (min_cost == DBL_MAX) { + RTLOG.error(Loc::current(), "The min cost is wrong!"); } - start_node_list_list.push_back(end_node_list_list[end_node_list_idx]); - end_node_list_list.erase(end_node_list_list.begin() + end_node_list_idx); + return best_layer_idx; } -void EarlyRouter::resetSinglePath(ERModel& er_model) +int32_t EarlyRouter::getBestLayerByChild(TNode* parent_pillar_node) { - PriorityQueue, CmpERNodeCost> empty_queue; - er_model.set_open_queue(empty_queue); - - std::vector& single_path_visited_node_list = er_model.get_single_path_visited_node_list(); - for (ERNode* visited_node : single_path_visited_node_list) { - visited_node->set_state(ERNodeState::kNone); - visited_node->set_parent_node(nullptr); - visited_node->set_known_cost(0); - visited_node->set_estimated_cost(0); + std::set candidate_layer_idx_set; + for (TNode* child_node : parent_pillar_node->get_child_list()) { + for (LALayerCost& layer_cost : child_node->value().get_layer_cost_list()) { + if (layer_cost.get_layer_idx() == child_node->value().get_layer_idx()) { + candidate_layer_idx_set.insert(layer_cost.get_parent_layer_idx()); + } + } } - single_path_visited_node_list.clear(); - - er_model.set_path_head_node(nullptr); - er_model.set_end_node_list_idx(-1); + double min_cost = DBL_MAX; + int32_t best_layer_idx = INT_MAX; + for (int32_t candidate_layer_idx : candidate_layer_idx_set) { + for (LALayerCost& layer_cost : parent_pillar_node->value().get_layer_cost_list()) { + if (layer_cost.get_layer_idx() != candidate_layer_idx) { + continue; + } + double curr_cost = layer_cost.get_history_cost(); + if (curr_cost < min_cost) { + min_cost = curr_cost; + best_layer_idx = candidate_layer_idx; + } else if (curr_cost == min_cost) { + best_layer_idx = std::min(best_layer_idx, candidate_layer_idx); + } + break; + } + } + if (min_cost == DBL_MAX) { + RTLOG.error(Loc::current(), "The min cost is wrong!"); + } + return best_layer_idx; } -void EarlyRouter::updateTaskResult(ERModel& er_model) +void EarlyRouter::buildLayerTree(ERModel& er_model, ERNet* er_task) { - er_model.get_curr_er_topo()->set_routing_segment_list(getRoutingSegmentList(er_model)); + std::vector> routing_segment_list = getLayerRoutingSegmentList(er_model); + MTree coord_tree = getCoordTree(er_model, routing_segment_list); + updateDemandToGraph(er_model, ChangeType::kAdd, coord_tree); + er_task->set_layer_tree(coord_tree); } -std::vector> EarlyRouter::getRoutingSegmentList(ERModel& er_model) +std::vector> EarlyRouter::getLayerRoutingSegmentList(ERModel& er_model) { - ERTopo* curr_er_topo = er_model.get_curr_er_topo(); + std::vector> routing_segment_list; - std::vector candidate_root_coord_list; - std::map, CmpLayerCoordByXASC> key_coord_pin_map; - std::vector& er_group_list = curr_er_topo->get_er_group_list(); - for (size_t i = 0; i < er_group_list.size(); i++) { - for (LayerCoord& coord : er_group_list[i].get_coord_list()) { - candidate_root_coord_list.push_back(coord); - key_coord_pin_map[coord].insert(static_cast(i)); + std::queue*> pillar_node_queue = RTUTIL.initQueue(er_model.get_curr_er_task()->get_pillar_tree().get_root()); + while (!pillar_node_queue.empty()) { + TNode* parent_pillar_node = RTUTIL.getFrontAndPop(pillar_node_queue); + std::vector*>& child_list = parent_pillar_node->get_child_list(); + { + std::set layer_idx_set = parent_pillar_node->value().get_pin_layer_idx_set(); + layer_idx_set.insert(parent_pillar_node->value().get_layer_idx()); + for (TNode* child_node : child_list) { + layer_idx_set.insert(child_node->value().get_layer_idx()); + } + routing_segment_list.emplace_back(LayerCoord(parent_pillar_node->value().get_planar_coord(), *layer_idx_set.begin()), + LayerCoord(parent_pillar_node->value().get_planar_coord(), *layer_idx_set.rbegin())); } - } - MTree coord_tree = RTUTIL.getTreeByFullFlow(candidate_root_coord_list, er_model.get_routing_segment_list(), key_coord_pin_map); - - std::vector> routing_segment_list; - for (Segment*>& coord_segment : RTUTIL.getSegListByTree(coord_tree)) { - routing_segment_list.emplace_back(coord_segment.get_first()->value(), coord_segment.get_second()->value()); + for (TNode* child_node : child_list) { + routing_segment_list.emplace_back(LayerCoord(parent_pillar_node->value().get_planar_coord(), child_node->value().get_layer_idx()), + LayerCoord(child_node->value().get_planar_coord(), child_node->value().get_layer_idx())); + } + RTUTIL.addListToQueue(pillar_node_queue, child_list); } return routing_segment_list; } -void EarlyRouter::resetSingleTask(ERModel& er_model) +MTree EarlyRouter::getCoordTree(ERModel& er_model, std::vector>& routing_segment_list) { - er_model.set_curr_er_topo(nullptr); - er_model.get_start_node_list_list().clear(); - er_model.get_end_node_list_list().clear(); - er_model.get_path_node_list().clear(); - er_model.get_single_topo_visited_node_list().clear(); - er_model.get_routing_segment_list().clear(); + std::vector candidate_root_coord_list; + std::map, CmpLayerCoordByXASC> key_coord_pin_map; + std::vector& er_pin_list = er_model.get_curr_er_task()->get_er_pin_list(); + for (size_t i = 0; i < er_pin_list.size(); i++) { + LayerCoord coord = er_pin_list[i].get_access_point().getGridLayerCoord(); + candidate_root_coord_list.push_back(coord); + key_coord_pin_map[coord].insert(static_cast(i)); + } + return RTUTIL.getTreeByFullFlow(candidate_root_coord_list, routing_segment_list, key_coord_pin_map); } -// manager open list - -void EarlyRouter::pushToOpenList(ERModel& er_model, ERNode* curr_node) +void EarlyRouter::resetSingleLayerTask(ERModel& er_model) { - PriorityQueue, CmpERNodeCost>& open_queue = er_model.get_open_queue(); - std::vector& single_topo_visited_node_list = er_model.get_single_topo_visited_node_list(); - std::vector& single_path_visited_node_list = er_model.get_single_path_visited_node_list(); + er_model.set_curr_er_task(nullptr); +} - open_queue.push(curr_node); - curr_node->set_state(ERNodeState::kOpen); - single_topo_visited_node_list.push_back(curr_node); - single_path_visited_node_list.push_back(curr_node); +void EarlyRouter::outputResult(ERModel& er_model) +{ + outputGCellCSV(er_model); + outputLayerSupplyCSV(er_model); + outputLayerGuide(er_model); + outputLayerNetCSV(er_model); + outputLayerOverflowCSV(er_model); } -ERNode* EarlyRouter::popFromOpenList(ERModel& er_model) +void EarlyRouter::outputGCellCSV(ERModel& er_model) { - PriorityQueue, CmpERNodeCost>& open_queue = er_model.get_open_queue(); + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - ERNode* node = nullptr; - if (!open_queue.empty()) { - node = open_queue.top(); - open_queue.pop(); - node->set_state(ERNodeState::kClose); + std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "gcell.info")); + if (guide_file_stream == nullptr) { + return; } - return node; + for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { + for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { + GCell& gcell = gcell_map[x][y]; + RTUTIL.pushStream(guide_file_stream, x, ",", y, ",", gcell.get_ll_x(), ",", gcell.get_ll_y(), ",", gcell.get_ur_x(), ",", gcell.get_ur_y(), "\n"); + } + } + RTUTIL.closeFileStream(guide_file_stream); } -// calculate known - -double EarlyRouter::getKnownCost(ERModel& er_model, ERNode* start_node, ERNode* end_node) +void EarlyRouter::outputLayerSupplyCSV(ERModel& er_model) { - bool exist_neighbor = false; - for (auto& [orientation, neighbor_ptr] : start_node->get_neighbor_node_map()) { - if (neighbor_ptr == end_node) { - exist_neighbor = true; - break; + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; + + for (RoutingLayer& routing_layer : routing_layer_list) { + std::ofstream* supply_csv_file + = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "supply_map_", routing_layer.get_layer_name(), ".csv")); + for (int32_t y = gcell_map.get_y_size() - 1; y >= 0; y--) { + for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { + int32_t total_supply = 0; + for (auto& [orient, supply] : gcell_map[x][y].get_routing_orient_supply_map()[routing_layer.get_layer_idx()]) { + total_supply += supply; + } + RTUTIL.pushStream(supply_csv_file, total_supply, ","); + } + RTUTIL.pushStream(supply_csv_file, "\n"); } + RTUTIL.closeFileStream(supply_csv_file); } - if (!exist_neighbor) { - RTLOG.error(Loc::current(), "The neighbor not exist!"); + RTLOG.info(Loc::current(), "The csv file has been saved"); +} + +void EarlyRouter::outputLayerGuide(ERModel& er_model) +{ + int32_t micron_dbu = RTDM.getDatabase().get_micron_dbu(); + ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; + + std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "route.guide")); + if (guide_file_stream == nullptr) { + return; } + RTUTIL.pushStream(guide_file_stream, "guide net_name\n"); + RTUTIL.pushStream(guide_file_stream, "pin grid_x grid_y real_x real_y layer energy name\n"); + RTUTIL.pushStream(guide_file_stream, "wire grid1_x grid1_y grid2_x grid2_y real1_x real1_y real2_x real2_y layer\n"); + RTUTIL.pushStream(guide_file_stream, "via grid_x grid_y real_x real_y layer1 layer2\n"); - double cost = 0; - cost += start_node->get_known_cost(); - cost += getNodeCost(er_model, start_node, RTUTIL.getOrientation(*start_node, *end_node)); - cost += getNodeCost(er_model, end_node, RTUTIL.getOrientation(*end_node, *start_node)); - cost += getKnownWireCost(er_model, start_node, end_node); - cost += getKnownViaCost(er_model, start_node, end_node); - return cost; -} + for (ERNet& er_net : er_model.get_er_net_list()) { + RTUTIL.pushStream(guide_file_stream, "guide ", er_net.get_origin_net()->get_net_name(), "\n"); + + for (ERPin& er_pin : er_net.get_er_pin_list()) { + AccessPoint& access_point = er_pin.get_access_point(); + double grid_x = access_point.get_grid_x(); + double grid_y = access_point.get_grid_y(); + double real_x = access_point.get_real_x() / 1.0 / micron_dbu; + double real_y = access_point.get_real_y() / 1.0 / micron_dbu; + std::string layer = routing_layer_list[access_point.get_layer_idx()].get_layer_name(); + std::string connnect; + if (er_pin.get_is_driven()) { + connnect = "driven"; + } else { + connnect = "load"; + } + RTUTIL.pushStream(guide_file_stream, "pin ", grid_x, " ", grid_y, " ", real_x, " ", real_y, " ", layer, " ", connnect, " ", er_pin.get_pin_name(), "\n"); + } -double EarlyRouter::getNodeCost(ERModel& er_model, ERNode* curr_node, Orientation orientation) -{ - double overflow_unit = er_model.get_er_com_param().get_overflow_unit(); + for (Segment*>& segment : RTUTIL.getSegListByTree(er_net.get_layer_tree())) { + LayerCoord first_layer_coord = segment.get_first()->value(); + double grid1_x = first_layer_coord.get_x(); + double grid1_y = first_layer_coord.get_y(); + int32_t first_layer_idx = first_layer_coord.get_layer_idx(); - double node_cost = 0; - node_cost += curr_node->getOverflowCost(orientation, overflow_unit); - return node_cost; -} + PlanarCoord first_mid_coord = RTUTIL.getRealRectByGCell(first_layer_coord, gcell_axis).getMidPoint(); + double real1_x = first_mid_coord.get_x() / 1.0 / micron_dbu; + double real1_y = first_mid_coord.get_y() / 1.0 / micron_dbu; -double EarlyRouter::getKnownWireCost(ERModel& er_model, ERNode* start_node, ERNode* end_node) -{ - std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); - double prefer_wire_unit = er_model.get_er_com_param().get_prefer_wire_unit(); + LayerCoord second_layer_coord = segment.get_second()->value(); + double grid2_x = second_layer_coord.get_x(); + double grid2_y = second_layer_coord.get_y(); + int32_t second_layer_idx = second_layer_coord.get_layer_idx(); - double wire_cost = 0; - if (start_node->get_layer_idx() == end_node->get_layer_idx()) { - wire_cost += RTUTIL.getManhattanDistance(start_node->get_planar_coord(), end_node->get_planar_coord()); + PlanarCoord second_mid_coord = RTUTIL.getRealRectByGCell(second_layer_coord, gcell_axis).getMidPoint(); + double real2_x = second_mid_coord.get_x() / 1.0 / micron_dbu; + double real2_y = second_mid_coord.get_y() / 1.0 / micron_dbu; - RoutingLayer& routing_layer = routing_layer_list[start_node->get_layer_idx()]; - if (routing_layer.get_prefer_direction() == RTUTIL.getDirection(*start_node, *end_node)) { - wire_cost *= prefer_wire_unit; + if (first_layer_idx != second_layer_idx) { + RTUTIL.swapByASC(first_layer_idx, second_layer_idx); + std::string layer1 = routing_layer_list[first_layer_idx].get_layer_name(); + std::string layer2 = routing_layer_list[second_layer_idx].get_layer_name(); + RTUTIL.pushStream(guide_file_stream, "via ", grid1_x, " ", grid1_y, " ", real1_x, " ", real1_y, " ", layer1, " ", layer2, "\n"); + } else { + std::string layer = routing_layer_list[first_layer_idx].get_layer_name(); + RTUTIL.pushStream(guide_file_stream, "wire ", grid1_x, " ", grid1_y, " ", grid2_x, " ", grid2_y, " ", real1_x, " ", real1_y, " ", real2_x, " ", real2_y, + " ", layer, "\n"); + } } } - return wire_cost; -} - -double EarlyRouter::getKnownViaCost(ERModel& er_model, ERNode* start_node, ERNode* end_node) -{ - double via_unit = er_model.get_er_com_param().get_via_unit(); - double via_cost = (via_unit * std::abs(start_node->get_layer_idx() - end_node->get_layer_idx())); - return via_cost; + RTUTIL.closeFileStream(guide_file_stream); + RTLOG.info(Loc::current(), "The csv file has been saved"); } -// calculate estimate - -double EarlyRouter::getEstimateCostToEnd(ERModel& er_model, ERNode* curr_node) +void EarlyRouter::outputLayerNetCSV(ERModel& er_model) { - std::vector>& end_node_list_list = er_model.get_end_node_list_list(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - double estimate_cost = DBL_MAX; - for (std::vector& end_node_list : end_node_list_list) { - for (ERNode* end_node : end_node_list) { - if (end_node->isClose()) { - continue; + std::vector>& layer_node_map = er_model.get_layer_node_map(); + for (RoutingLayer& routing_layer : routing_layer_list) { + std::ofstream* net_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "net_map_", routing_layer.get_layer_name(), ".csv")); + GridMap& er_node_map = layer_node_map[routing_layer.get_layer_idx()]; + for (int32_t y = er_node_map.get_y_size() - 1; y >= 0; y--) { + for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { + RTUTIL.pushStream(net_csv_file, er_node_map[x][y].getDemand(), ","); } - estimate_cost = std::min(estimate_cost, getEstimateCost(er_model, curr_node, end_node)); + RTUTIL.pushStream(net_csv_file, "\n"); } + RTUTIL.closeFileStream(net_csv_file); } - return estimate_cost; -} - -double EarlyRouter::getEstimateCost(ERModel& er_model, ERNode* start_node, ERNode* end_node) -{ - double estimate_cost = 0; - estimate_cost += getEstimateWireCost(er_model, start_node, end_node); - estimate_cost += getEstimateViaCost(er_model, start_node, end_node); - return estimate_cost; -} - -double EarlyRouter::getEstimateWireCost(ERModel& er_model, ERNode* start_node, ERNode* end_node) -{ - double prefer_wire_unit = er_model.get_er_com_param().get_prefer_wire_unit(); - - double wire_cost = 0; - wire_cost += RTUTIL.getManhattanDistance(start_node->get_planar_coord(), end_node->get_planar_coord()); - wire_cost *= prefer_wire_unit; - return wire_cost; + RTLOG.info(Loc::current(), "The csv file has been saved"); } -double EarlyRouter::getEstimateViaCost(ERModel& er_model, ERNode* start_node, ERNode* end_node) +void EarlyRouter::outputLayerOverflowCSV(ERModel& er_model) { - double via_unit = er_model.get_er_com_param().get_via_unit(); - double via_cost = (via_unit * std::abs(start_node->get_layer_idx() - end_node->get_layer_idx())); - return via_cost; -} + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; -MTree EarlyRouter::getLayerCoordTree(ERNet* er_net, std::vector>& routing_segment_list) -{ - std::vector candidate_root_coord_list; - std::map, CmpLayerCoordByXASC> key_coord_pin_map; - std::vector& er_pin_list = er_net->get_er_pin_list(); - for (size_t i = 0; i < er_pin_list.size(); i++) { - LayerCoord coord = er_pin_list[i].get_access_point().getGridLayerCoord(); - candidate_root_coord_list.push_back(coord); - key_coord_pin_map[coord].insert(static_cast(i)); - } - return RTUTIL.getTreeByFullFlow(candidate_root_coord_list, routing_segment_list, key_coord_pin_map); -} + std::vector>& layer_node_map = er_model.get_layer_node_map(); + for (RoutingLayer& routing_layer : routing_layer_list) { + std::ofstream* overflow_csv_file + = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "overflow_map_", routing_layer.get_layer_name(), ".csv")); -void EarlyRouter::uploadNetResult(ERNet* er_net, MTree& coord_tree) -{ - for (Segment*>& coord_segment : RTUTIL.getSegListByTree(coord_tree)) { - Segment* segment = new Segment(coord_segment.get_first()->value(), coord_segment.get_second()->value()); - RTDM.updateNetGlobalResultToGCellMap(ChangeType::kAdd, er_net->get_net_idx(), segment); + GridMap& er_node_map = layer_node_map[routing_layer.get_layer_idx()]; + for (int32_t y = er_node_map.get_y_size() - 1; y >= 0; y--) { + for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { + RTUTIL.pushStream(overflow_csv_file, er_node_map[x][y].getOverflow(), ","); + } + RTUTIL.pushStream(overflow_csv_file, "\n"); + } + RTUTIL.closeFileStream(overflow_csv_file); } + RTLOG.info(Loc::current(), "The csv file has been saved"); } #if 1 // update env -void EarlyRouter::updatePlanarDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree) +void EarlyRouter::updateDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree) { - std::vector> routing_segment_list; - for (Segment*>& coord_segment : RTUTIL.getSegListByTree(coord_tree)) { + int32_t curr_net_idx = er_model.get_curr_er_task()->get_net_idx(); + + std::vector> routing_segment_list; + for (Segment*>& coord_segment : RTUTIL.getSegListByTree(coord_tree)) { routing_segment_list.emplace_back(coord_segment.get_first()->value(), coord_segment.get_second()->value()); } - std::map, CmpLayerCoordByXASC> usage_map; - for (Segment& coord_segment : routing_segment_list) { - LayerCoord& first_coord = coord_segment.get_first(); - LayerCoord& second_coord = coord_segment.get_second(); + std::map, CmpPlanarCoordByXASC> usage_map; + for (Segment& coord_segment : routing_segment_list) { + PlanarCoord& first_coord = coord_segment.get_first(); + PlanarCoord& second_coord = coord_segment.get_second(); Orientation orientation = RTUTIL.getOrientation(first_coord, second_coord); if (orientation == Orientation::kNone || orientation == Orientation::kOblique) { @@ -1157,24 +1792,19 @@ void EarlyRouter::updatePlanarDemandToGraph(ERModel& er_model, ChangeType change int32_t first_x = first_coord.get_x(); int32_t first_y = first_coord.get_y(); - int32_t first_layer_idx = first_coord.get_layer_idx(); int32_t second_x = second_coord.get_x(); int32_t second_y = second_coord.get_y(); - int32_t second_layer_idx = second_coord.get_layer_idx(); RTUTIL.swapByASC(first_x, second_x); RTUTIL.swapByASC(first_y, second_y); - RTUTIL.swapByASC(first_layer_idx, second_layer_idx); for (int32_t x = first_x; x <= second_x; x++) { for (int32_t y = first_y; y <= second_y; y++) { - for (int32_t layer_idx = first_layer_idx; layer_idx <= second_layer_idx; layer_idx++) { - LayerCoord coord(x, y, layer_idx); - if (coord != first_coord) { - usage_map[coord].insert(opposite_orientation); - } - if (coord != second_coord) { - usage_map[coord].insert(orientation); - } + PlanarCoord coord(x, y); + if (coord != first_coord) { + usage_map[coord].insert(opposite_orientation); + } + if (coord != second_coord) { + usage_map[coord].insert(orientation); } } } @@ -1182,12 +1812,14 @@ void EarlyRouter::updatePlanarDemandToGraph(ERModel& er_model, ChangeType change GridMap& planar_node_map = er_model.get_planar_node_map(); for (auto& [usage_coord, orientation_list] : usage_map) { ERNode& er_node = planar_node_map[usage_coord.get_x()][usage_coord.get_y()]; - er_node.updateDemand(orientation_list, ChangeType::kAdd); + er_node.updateDemand(curr_net_idx, orientation_list, change_type); } } -void EarlyRouter::updateLayerDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree) +void EarlyRouter::updateDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree) { + int32_t curr_net_idx = er_model.get_curr_er_task()->get_net_idx(); + std::vector> routing_segment_list; for (Segment*>& coord_segment : RTUTIL.getSegListByTree(coord_tree)) { routing_segment_list.emplace_back(coord_segment.get_first()->value(), coord_segment.get_second()->value()); @@ -1230,7 +1862,7 @@ void EarlyRouter::updateLayerDemandToGraph(ERModel& er_model, ChangeType change_ std::vector>& layer_node_map = er_model.get_layer_node_map(); for (auto& [usage_coord, orientation_list] : usage_map) { ERNode& er_node = layer_node_map[usage_coord.get_layer_idx()][usage_coord.get_x()][usage_coord.get_y()]; - er_node.updateDemand(orientation_list, ChangeType::kAdd); + er_node.updateDemand(curr_net_idx, orientation_list, change_type); } } @@ -1242,17 +1874,15 @@ void EarlyRouter::updateSummary(ERModel& er_model) { int32_t micron_dbu = RTDM.getDatabase().get_micron_dbu(); ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); - Die& die = RTDM.getDatabase().get_die(); GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::vector>& layer_via_master_list = RTDM.getDatabase().get_layer_via_master_list(); Summary& summary = RTDM.getDatabase().get_summary(); int32_t enable_timing = RTDM.getConfig().enable_timing; - std::map& routing_demand_map = summary.er_summary.routing_demand_map; - int32_t& total_demand = summary.er_summary.total_demand; - std::map& routing_overflow_map = summary.er_summary.routing_overflow_map; - int32_t& total_overflow = summary.er_summary.total_overflow; + std::map& routing_demand_map = summary.er_summary.routing_demand_map; + double& total_demand = summary.er_summary.total_demand; + std::map& routing_overflow_map = summary.er_summary.routing_overflow_map; + double& total_overflow = summary.er_summary.total_overflow; std::map& routing_wire_length_map = summary.er_summary.routing_wire_length_map; double& total_wire_length = summary.er_summary.total_wire_length; std::map& cut_via_num_map = summary.er_summary.cut_via_num_map; @@ -1278,19 +1908,8 @@ void EarlyRouter::updateSummary(ERModel& er_model) GridMap& er_node_map = layer_node_map[layer_idx]; for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { for (int32_t y = 0; y < er_node_map.get_y_size(); y++) { - std::map& orient_supply_map = er_node_map[x][y].get_orient_supply_map(); - std::map& orient_demand_map = er_node_map[x][y].get_orient_demand_map(); - int32_t node_demand = 0; - int32_t node_overflow = 0; - if (routing_layer_list[layer_idx].isPreferH()) { - node_demand = (orient_demand_map[Orientation::kEast] + orient_demand_map[Orientation::kWest]); - node_overflow = std::max(0, orient_demand_map[Orientation::kEast] - orient_supply_map[Orientation::kEast]) - + std::max(0, orient_demand_map[Orientation::kWest] - orient_supply_map[Orientation::kWest]); - } else { - node_demand = (orient_demand_map[Orientation::kSouth] + orient_demand_map[Orientation::kNorth]); - node_overflow = std::max(0, orient_demand_map[Orientation::kSouth] - orient_supply_map[Orientation::kSouth]) - + std::max(0, orient_demand_map[Orientation::kNorth] - orient_supply_map[Orientation::kNorth]); - } + double node_demand = er_node_map[x][y].getDemand(); + double node_overflow = er_node_map[x][y].getOverflow(); routing_demand_map[layer_idx] += node_demand; total_demand += node_demand; routing_overflow_map[layer_idx] += node_overflow; @@ -1298,11 +1917,11 @@ void EarlyRouter::updateSummary(ERModel& er_model) } } } - for (auto& [net_idx, segment_set] : RTDM.getNetGlobalResultMap(die)) { - for (Segment* segment : segment_set) { - LayerCoord& first_coord = segment->get_first(); + for (ERNet& er_net : er_net_list) { + for (Segment*>& segment : RTUTIL.getSegListByTree(er_net.get_layer_tree())) { + LayerCoord& first_coord = segment.get_first()->value(); int32_t first_layer_idx = first_coord.get_layer_idx(); - LayerCoord& second_coord = segment->get_second(); + LayerCoord& second_coord = segment.get_second()->value(); int32_t second_layer_idx = second_coord.get_layer_idx(); if (first_layer_idx == second_layer_idx) { @@ -1332,14 +1951,14 @@ void EarlyRouter::updateSummary(ERModel& er_model) layer_coord.get_layer_idx()); } } - for (auto& [net_idx, segment_set] : RTDM.getNetGlobalResultMap(die)) { - for (Segment* segment : segment_set) { - LayerCoord first_layer_coord = segment->get_first(); + for (ERNet& er_net : er_net_list) { + for (Segment*>& segment : RTUTIL.getSegListByTree(er_net.get_layer_tree())) { + LayerCoord first_layer_coord = segment.get_first()->value(); LayerCoord first_real_coord(RTUTIL.getRealRectByGCell(first_layer_coord, gcell_axis).getMidPoint(), first_layer_coord.get_layer_idx()); - LayerCoord second_layer_coord = segment->get_second(); + LayerCoord second_layer_coord = segment.get_second()->value(); LayerCoord second_real_coord(RTUTIL.getRealRectByGCell(second_layer_coord, gcell_axis).getMidPoint(), second_layer_coord.get_layer_idx()); - routing_segment_list_list[net_idx].emplace_back(first_real_coord, second_real_coord); + routing_segment_list_list[er_net.get_net_idx()].emplace_back(first_real_coord, second_real_coord); } } RTI.updateTimingAndPower(real_pin_coord_map_list, routing_segment_list_list, clock_timing_map, type_power_map); @@ -1353,10 +1972,10 @@ void EarlyRouter::printSummary(ERModel& er_model) Summary& summary = RTDM.getDatabase().get_summary(); int32_t enable_timing = RTDM.getConfig().enable_timing; - std::map& routing_demand_map = summary.er_summary.routing_demand_map; - int32_t& total_demand = summary.er_summary.total_demand; - std::map& routing_overflow_map = summary.er_summary.routing_overflow_map; - int32_t& total_overflow = summary.er_summary.total_overflow; + std::map& routing_demand_map = summary.er_summary.routing_demand_map; + double& total_demand = summary.er_summary.total_demand; + std::map& routing_overflow_map = summary.er_summary.routing_overflow_map; + double& total_overflow = summary.er_summary.total_overflow; std::map& routing_wire_length_map = summary.er_summary.routing_wire_length_map; double& total_wire_length = summary.er_summary.total_wire_length; std::map& cut_via_num_map = summary.er_summary.cut_via_num_map; @@ -1439,207 +2058,6 @@ void EarlyRouter::printSummary(ERModel& er_model) RTUTIL.printTableList({timing_table, power_table}); } -void EarlyRouter::outputGCellCSV(ERModel& er_model) -{ - GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - - std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "gcell.csv")); - if (guide_file_stream == nullptr) { - return; - } - for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { - for (int32_t y = 0; y < gcell_map.get_y_size(); y++) { - GCell& gcell = gcell_map[x][y]; - RTUTIL.pushStream(guide_file_stream, x, ",", y, ",", gcell.get_ll_x(), ",", gcell.get_ll_y(), ",", gcell.get_ur_x(), ",", gcell.get_ur_y(), "\n"); - } - } - RTUTIL.closeFileStream(guide_file_stream); -} - -void EarlyRouter::outputGuide(ERModel& er_model) -{ - int32_t micron_dbu = RTDM.getDatabase().get_micron_dbu(); - ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); - Die& die = RTDM.getDatabase().get_die(); - std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); - std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - - std::vector& er_net_list = er_model.get_er_net_list(); - - std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "route.guide")); - if (guide_file_stream == nullptr) { - return; - } - RTUTIL.pushStream(guide_file_stream, "guide net_name\n"); - RTUTIL.pushStream(guide_file_stream, "pin grid_x grid_y real_x real_y layer energy name\n"); - RTUTIL.pushStream(guide_file_stream, "wire grid1_x grid1_y grid2_x grid2_y real1_x real1_y real2_x real2_y layer\n"); - RTUTIL.pushStream(guide_file_stream, "via grid_x grid_y real_x real_y layer1 layer2\n"); - - for (auto& [net_idx, segment_set] : RTDM.getNetGlobalResultMap(die)) { - ERNet& er_net = er_net_list[net_idx]; - RTUTIL.pushStream(guide_file_stream, "guide ", er_net.get_origin_net()->get_net_name(), "\n"); - - for (ERPin& er_pin : er_net.get_er_pin_list()) { - AccessPoint& access_point = er_pin.get_access_point(); - double grid_x = access_point.get_grid_x(); - double grid_y = access_point.get_grid_y(); - double real_x = access_point.get_real_x() / 1.0 / micron_dbu; - double real_y = access_point.get_real_y() / 1.0 / micron_dbu; - std::string layer = routing_layer_list[access_point.get_layer_idx()].get_layer_name(); - std::string connnect; - if (er_pin.get_is_driven()) { - connnect = "driven"; - } else { - connnect = "load"; - } - RTUTIL.pushStream(guide_file_stream, "pin ", grid_x, " ", grid_y, " ", real_x, " ", real_y, " ", layer, " ", connnect, " ", er_pin.get_pin_name(), "\n"); - } - for (Segment* segment : segment_set) { - LayerCoord first_layer_coord = segment->get_first(); - double grid1_x = first_layer_coord.get_x(); - double grid1_y = first_layer_coord.get_y(); - int32_t first_layer_idx = first_layer_coord.get_layer_idx(); - - PlanarCoord first_mid_coord = RTUTIL.getRealRectByGCell(first_layer_coord, gcell_axis).getMidPoint(); - double real1_x = first_mid_coord.get_x() / 1.0 / micron_dbu; - double real1_y = first_mid_coord.get_y() / 1.0 / micron_dbu; - - LayerCoord second_layer_coord = segment->get_second(); - double grid2_x = second_layer_coord.get_x(); - double grid2_y = second_layer_coord.get_y(); - int32_t second_layer_idx = second_layer_coord.get_layer_idx(); - - PlanarCoord second_mid_coord = RTUTIL.getRealRectByGCell(second_layer_coord, gcell_axis).getMidPoint(); - double real2_x = second_mid_coord.get_x() / 1.0 / micron_dbu; - double real2_y = second_mid_coord.get_y() / 1.0 / micron_dbu; - - if (first_layer_idx != second_layer_idx) { - RTUTIL.swapByASC(first_layer_idx, second_layer_idx); - std::string layer1 = routing_layer_list[first_layer_idx].get_layer_name(); - std::string layer2 = routing_layer_list[second_layer_idx].get_layer_name(); - RTUTIL.pushStream(guide_file_stream, "via ", grid1_x, " ", grid1_y, " ", real1_x, " ", real1_y, " ", layer1, " ", layer2, "\n"); - } else { - std::string layer = routing_layer_list[first_layer_idx].get_layer_name(); - RTUTIL.pushStream(guide_file_stream, "wire ", grid1_x, " ", grid1_y, " ", grid2_x, " ", grid2_y, " ", real1_x, " ", real1_y, " ", real2_x, " ", real2_y, - " ", layer, "\n"); - } - } - } - RTUTIL.closeFileStream(guide_file_stream); -} - -void EarlyRouter::outputDemandCSV(ERModel& er_model) -{ - std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); - std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - - std::vector>& layer_node_map = er_model.get_layer_node_map(); - for (RoutingLayer& routing_layer : routing_layer_list) { - std::ofstream* demand_csv_file - = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "demand_map_", routing_layer.get_layer_name(), ".csv")); - - GridMap& er_node_map = layer_node_map[routing_layer.get_layer_idx()]; - for (int32_t y = er_node_map.get_y_size() - 1; y >= 0; y--) { - for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { - std::map& orient_demand_map = er_node_map[x][y].get_orient_demand_map(); - int32_t total_demand = 0; - if (routing_layer.isPreferH()) { - total_demand = (orient_demand_map[Orientation::kEast] + orient_demand_map[Orientation::kWest]); - } else { - total_demand = (orient_demand_map[Orientation::kSouth] + orient_demand_map[Orientation::kNorth]); - } - RTUTIL.pushStream(demand_csv_file, total_demand, ","); - } - RTUTIL.pushStream(demand_csv_file, "\n"); - } - RTUTIL.closeFileStream(demand_csv_file); - } -} - -void EarlyRouter::outputOverflowCSV(ERModel& er_model) -{ - std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); - std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - - std::vector>& layer_node_map = er_model.get_layer_node_map(); - for (RoutingLayer& routing_layer : routing_layer_list) { - std::ofstream* overflow_csv_file - = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "overflow_map_", routing_layer.get_layer_name(), ".csv")); - - GridMap& er_node_map = layer_node_map[routing_layer.get_layer_idx()]; - for (int32_t y = er_node_map.get_y_size() - 1; y >= 0; y--) { - for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { - std::map& orient_supply_map = er_node_map[x][y].get_orient_supply_map(); - std::map& orient_demand_map = er_node_map[x][y].get_orient_demand_map(); - int32_t total_overflow = 0; - if (routing_layer.isPreferH()) { - total_overflow = std::max(0, orient_demand_map[Orientation::kEast] - orient_supply_map[Orientation::kEast]) - + std::max(0, orient_demand_map[Orientation::kWest] - orient_supply_map[Orientation::kWest]); - } else { - total_overflow = std::max(0, orient_demand_map[Orientation::kSouth] - orient_supply_map[Orientation::kSouth]) - + std::max(0, orient_demand_map[Orientation::kNorth] - orient_supply_map[Orientation::kNorth]); - } - RTUTIL.pushStream(overflow_csv_file, total_overflow, ","); - } - RTUTIL.pushStream(overflow_csv_file, "\n"); - } - RTUTIL.closeFileStream(overflow_csv_file); - } -} - -#endif - -#if 1 // debug - -void EarlyRouter::debugCheckPlanarNodeMap(ERModel& er_model) -{ - GridMap& er_node_map = er_model.get_planar_node_map(); - for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { - for (int32_t y = 0; y < er_node_map.get_y_size(); y++) { - ERNode& er_node = er_node_map[x][y]; - for (auto& [orient, neighbor] : er_node.get_neighbor_node_map()) { - Orientation opposite_orient = RTUTIL.getOppositeOrientation(orient); - if (!RTUTIL.exist(neighbor->get_neighbor_node_map(), opposite_orient)) { - RTLOG.error(Loc::current(), "The er_node neighbor is not bidirectional!"); - } - if (neighbor->get_neighbor_node_map()[opposite_orient] != &er_node) { - RTLOG.error(Loc::current(), "The er_node neighbor is not bidirectional!"); - } - if (RTUTIL.getOrientation(PlanarCoord(er_node), PlanarCoord(*neighbor)) == orient) { - continue; - } - RTLOG.error(Loc::current(), "The neighbor orient is different with real region!"); - } - } - } -} - -void EarlyRouter::debugCheckLayerNodeMap(ERModel& er_model) -{ - std::vector>& layer_node_map = er_model.get_layer_node_map(); - for (GridMap& er_node_map : layer_node_map) { - for (int32_t x = 0; x < er_node_map.get_x_size(); x++) { - for (int32_t y = 0; y < er_node_map.get_y_size(); y++) { - ERNode& er_node = er_node_map[x][y]; - for (auto& [orient, neighbor] : er_node.get_neighbor_node_map()) { - Orientation opposite_orient = RTUTIL.getOppositeOrientation(orient); - if (!RTUTIL.exist(neighbor->get_neighbor_node_map(), opposite_orient)) { - RTLOG.error(Loc::current(), "The er_node neighbor is not bidirectional!"); - } - if (neighbor->get_neighbor_node_map()[opposite_orient] != &er_node) { - RTLOG.error(Loc::current(), "The er_node neighbor is not bidirectional!"); - } - if (RTUTIL.getOrientation(LayerCoord(er_node), LayerCoord(*neighbor)) == orient) { - continue; - } - RTLOG.error(Loc::current(), "The neighbor orient is different with real region!"); - } - } - } - } -} - #endif } // namespace irt diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.hpp b/src/operation/iRT/source/module/early_router/EarlyRouter.hpp index 3dc20c92c..51aaaed41 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.hpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.hpp @@ -20,7 +20,9 @@ #include "Config.hpp" #include "DataManager.hpp" #include "Database.hpp" +#include "ERCandidate.hpp" #include "ERModel.hpp" +#include "ERPackage.hpp" #include "RTHeader.hpp" namespace irt { @@ -52,69 +54,75 @@ class EarlyRouter ERNet convertToERNet(Net& net); void setERComParam(ERModel& er_model); void generateAccessPoint(ERModel& er_model); + void buildSupplySchedule(ERModel& er_model); + void analyzeSupply(ERModel& er_model); + EXTLayerRect getSearchRect(LayerCoord& first_coord, LayerCoord& second_coord); + std::vector getCrossingWireList(EXTLayerRect& search_rect); + bool isAccess(LayerRect& wire, std::vector& obs_rect_list); + void buildIgnoreNet(ERModel& er_model); + void analyzeDemandUnit(ERModel& er_model); void initERTaskList(ERModel& er_model); void buildPlanarNodeMap(ERModel& er_model); void buildPlanarNodeNeighbor(ERModel& er_model); void buildPlanarOrientSupply(ERModel& er_model); - void generateTopoTree(ERModel& er_model); - void routePlanarNet(ERModel& er_model, ERNet* er_net); - std::vector> getPlanarTopoList(ERModel& er_model, ERNet* er_net); - std::vector> getRoutingSegmentList(ERModel& er_model, Segment& planar_topo); - std::vector> getRoutingSegmentListByStraight(ERModel& er_model, Segment& planar_topo); - std::vector> getRoutingSegmentListByLPattern(ERModel& er_model, Segment& planar_topo); - double getPlanarNodeCost(ERModel& er_model, std::vector>& routing_segment_list); - MTree getPlanarCoordTree(ERNet* er_net, std::vector>& planar_routing_segment_list); + void generateTopology(ERModel& er_model); + void generateERTask(ERModel& er_model, ERNet* er_task); + void initSinglePlanarTask(ERModel& er_model, ERNet* er_task); + std::vector> getPlanarRoutingSegmentList(ERModel& er_model); + std::vector> getPlanarTopoList(ERModel& er_model); + std::vector>> getRoutingSegmentListList(ERModel& er_model, Segment& planar_topo); + std::vector>> getRoutingSegmentListByStraight(ERModel& er_model, Segment& planar_topo); + std::vector>> getRoutingSegmentListByLPattern(ERModel& er_model, Segment& planar_topo); + std::vector>> getRoutingSegmentListByZPattern(ERModel& er_model, Segment& planar_topo); + std::vector getMidIndexList(int32_t first_idx, int32_t second_idx); + std::vector>> getRoutingSegmentListByUPattern(ERModel& er_model, Segment& planar_topo); + std::vector>> getRoutingSegmentListByInner3Bends(ERModel& er_model, Segment& planar_topo); + std::vector>> getRoutingSegmentListByOuter3Bends(ERModel& er_model, Segment& planar_topo); + double getNodeCost(ERModel& er_model, std::vector>& routing_segment_list); + MTree getCoordTree(ERModel& er_model, std::vector>& routing_segment_list); + void resetSinglePlanarTask(ERModel& er_model); void buildLayerNodeMap(ERModel& er_model); void buildLayerNodeNeighbor(ERModel& er_model); void buildLayerOrientSupply(ERModel& er_model); - void generateGlobalTree(ERModel& er_model); - void routeLayerNet(ERModel& er_model, ERNet* er_net); - void makeERTopoList(ERModel& er_model, ERNet* er_net, std::vector& er_topo_list, std::vector>& routing_segment_list); - void routeERTopo(ERModel& er_model, ERTopo* er_topo); - void initSingleTask(ERModel& er_model, ERTopo* er_topo); - bool isConnectedAllEnd(ERModel& er_model); - void routeSinglePath(ERModel& er_model); - void initPathHead(ERModel& er_model); - bool searchEnded(ERModel& er_model); - void expandSearching(ERModel& er_model); - void resetPathHead(ERModel& er_model); - void updatePathResult(ERModel& er_model); - std::vector> getRoutingSegmentListByNode(ERNode* node); - void resetStartAndEnd(ERModel& er_model); - void resetSinglePath(ERModel& er_model); - void updateTaskResult(ERModel& er_model); - std::vector> getRoutingSegmentList(ERModel& er_model); - void resetSingleTask(ERModel& er_model); - void pushToOpenList(ERModel& er_model, ERNode* curr_node); - ERNode* popFromOpenList(ERModel& er_model); - double getKnownCost(ERModel& er_model, ERNode* start_node, ERNode* end_node); - double getNodeCost(ERModel& er_model, ERNode* curr_node, Orientation orientation); - double getKnownWireCost(ERModel& er_model, ERNode* start_node, ERNode* end_node); - double getKnownViaCost(ERModel& er_model, ERNode* start_node, ERNode* end_node); - double getEstimateCostToEnd(ERModel& er_model, ERNode* curr_node); - double getEstimateCost(ERModel& er_model, ERNode* start_node, ERNode* end_node); - double getEstimateWireCost(ERModel& er_model, ERNode* start_node, ERNode* end_node); - double getEstimateViaCost(ERModel& er_model, ERNode* start_node, ERNode* end_node); - MTree getLayerCoordTree(ERNet* er_net, std::vector>& routing_segment_list); - void uploadNetResult(ERNet* er_net, MTree& coord_tree); + void assignLayer(ERModel& er_model); + void assignERTask(ERModel& er_model, ERNet* er_task); + void initSingleTask(ERModel& er_model, ERNet* er_task); + bool needRouting(ERModel& er_model); + void spiltPlaneTree(ERModel& er_model); + void insertMidPoint(ERModel& er_model, TNode* planar_node, TNode* child_node); + void buildPillarTree(ERModel& er_model); + ERPillar convertERPillar(PlanarCoord& planar_coord, std::map, CmpPlanarCoordByXASC>& coord_pin_layer_map); + void assignPillarTree(ERModel& er_model); + void assignForward(ERModel& er_model); + std::vector getCandidateLayerList(ERModel& er_model, ERPackage& er_package); + double getFullViaCost(ERModel& er_model, std::set& layer_idx_set, int32_t candidate_layer_idx); + void buildLayerCost(ERModel& er_model, ERPackage& er_package); + std::pair getParentPillarCost(ERModel& er_model, ERPackage& er_package, int32_t candidate_layer_idx); + double getExtraViaCost(ERModel& er_model, std::set& layer_idx_set, int32_t candidate_layer_idx); + double getSegmentCost(ERModel& er_model, ERPackage& er_package, int32_t candidate_layer_idx); + double getChildPillarCost(ERModel& er_model, ERPackage& er_package, int32_t candidate_layer_idx); + void assignBackward(ERModel& er_model); + int32_t getBestLayerBySelf(TNode* pillar_node); + int32_t getBestLayerByChild(TNode* parent_pillar_node); + void buildLayerTree(ERModel& er_model, ERNet* er_task); + std::vector> getLayerRoutingSegmentList(ERModel& er_model); + MTree getCoordTree(ERModel& er_model, std::vector>& routing_segment_list); + void resetSingleLayerTask(ERModel& er_model); + void outputResult(ERModel& er_model); + void outputGCellCSV(ERModel& er_model); + void outputLayerSupplyCSV(ERModel& er_model); + void outputLayerGuide(ERModel& er_model); + void outputLayerNetCSV(ERModel& er_model); + void outputLayerOverflowCSV(ERModel& er_model); #if 1 // update env - void updatePlanarDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree); - void updateLayerDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree); + void updateDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree); + void updateDemandToGraph(ERModel& er_model, ChangeType change_type, MTree& coord_tree); #endif #if 1 // exhibit void updateSummary(ERModel& er_model); void printSummary(ERModel& er_model); - void outputGCellCSV(ERModel& er_model); - void outputGuide(ERModel& er_model); - void outputDemandCSV(ERModel& er_model); - void outputOverflowCSV(ERModel& er_model); -#endif - -#if 1 // debug - void debugCheckPlanarNodeMap(ERModel& er_model); - void debugCheckLayerNodeMap(ERModel& er_model); #endif }; diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERTopo.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERCandidate.hpp similarity index 47% rename from src/operation/iRT/source/module/early_router/er_data_manager/ERTopo.hpp rename to src/operation/iRT/source/module/early_router/er_data_manager/ERCandidate.hpp index a1865fbe0..e1f1c6a52 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERTopo.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERCandidate.hpp @@ -16,35 +16,37 @@ // *************************************************************************************** #pragma once -#include "ERGroup.hpp" +#include "PlanarCoord.hpp" +#include "RTHeader.hpp" +#include "Segment.hpp" namespace irt { -class ERTopo +class ERCandidate { public: - ERTopo() = default; - ~ERTopo() = default; + ERCandidate() = default; + ERCandidate(int32_t topo_idx, const std::vector>& routing_segment_list, double cost) + { + _topo_idx = topo_idx; + _routing_segment_list = routing_segment_list; + _cost = cost; + } + ~ERCandidate() = default; // getter - int32_t get_net_idx() { return _net_idx; } - std::vector& get_er_group_list() { return _er_group_list; } - PlanarRect& get_bounding_box() { return _bounding_box; } - std::vector>& get_routing_segment_list() { return _routing_segment_list; } - // const getter - const std::vector& get_er_group_list() const { return _er_group_list; } - const PlanarRect& get_bounding_box() const { return _bounding_box; } + int32_t get_topo_idx() const { return _topo_idx; } + std::vector>& get_routing_segment_list() { return _routing_segment_list; } + double get_cost() const { return _cost; } // setter - void set_net_idx(const int32_t net_idx) { _net_idx = net_idx; } - void set_er_group_list(const std::vector& er_group_list) { _er_group_list = er_group_list; } - void set_bounding_box(const PlanarRect& bounding_box) { _bounding_box = bounding_box; } - void set_routing_segment_list(const std::vector>& routing_segment_list) { _routing_segment_list = routing_segment_list; } + void set_topo_idx(const int32_t topo_idx) { _topo_idx = topo_idx; } + void set_routing_segment_list(const std::vector>& routing_segment_list) { _routing_segment_list = routing_segment_list; } + void set_cost(const double cost) { _cost = cost; } // function private: - int32_t _net_idx = -1; - std::vector _er_group_list; - PlanarRect _bounding_box; - std::vector> _routing_segment_list; + int32_t _topo_idx = -1; + std::vector> _routing_segment_list; + double _cost = 0.0; }; } // namespace irt diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERComParam.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERComParam.hpp index dddd966ac..b762e44ee 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERComParam.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERComParam.hpp @@ -16,34 +16,57 @@ // *************************************************************************************** #pragma once +#include "RTHeader.hpp" + namespace irt { class ERComParam { public: ERComParam() = default; - ERComParam(int32_t topo_spilt_length, double prefer_wire_unit, double via_unit, double overflow_unit) + ERComParam(int32_t supply_reduction, double boundary_wire_unit, double internal_wire_unit, double internal_via_unit, int32_t topo_spilt_length, + int32_t expand_step_num, int32_t expand_step_length, double via_unit, double overflow_unit) { + _supply_reduction = supply_reduction; + _boundary_wire_unit = boundary_wire_unit; + _internal_wire_unit = internal_wire_unit; + _internal_via_unit = internal_via_unit; _topo_spilt_length = topo_spilt_length; - _prefer_wire_unit = prefer_wire_unit; + _expand_step_num = expand_step_num; + _expand_step_length = expand_step_length; _via_unit = via_unit; _overflow_unit = overflow_unit; } ~ERComParam() = default; // getter + int32_t get_supply_reduction() const { return _supply_reduction; } + double get_boundary_wire_unit() const { return _boundary_wire_unit; } + double get_internal_wire_unit() const { return _internal_wire_unit; } + double get_internal_via_unit() const { return _internal_via_unit; } int32_t get_topo_spilt_length() const { return _topo_spilt_length; } - double get_prefer_wire_unit() const { return _prefer_wire_unit; } + int32_t get_expand_step_num() const { return _expand_step_num; } + int32_t get_expand_step_length() const { return _expand_step_length; } double get_via_unit() const { return _via_unit; } double get_overflow_unit() const { return _overflow_unit; } // setter + void set_supply_reduction(const int32_t supply_reduction) { _supply_reduction = supply_reduction; } + void set_boundary_wire_unit(const double boundary_wire_unit) { _boundary_wire_unit = boundary_wire_unit; } + void set_internal_wire_unit(const double internal_wire_unit) { _internal_wire_unit = internal_wire_unit; } + void set_internal_via_unit(const double internal_via_unit) { _internal_via_unit = internal_via_unit; } void set_topo_spilt_length(const int32_t topo_spilt_length) { _topo_spilt_length = topo_spilt_length; } - void set_prefer_wire_unit(const double prefer_wire_unit) { _prefer_wire_unit = prefer_wire_unit; } + void set_expand_step_num(const int32_t expand_step_num) { _expand_step_num = expand_step_num; } + void set_expand_step_length(const int32_t expand_step_length) { _expand_step_length = expand_step_length; } void set_via_unit(const double via_unit) { _via_unit = via_unit; } void set_overflow_unit(const double overflow_unit) { _overflow_unit = overflow_unit; } private: + int32_t _supply_reduction = -1; + double _boundary_wire_unit = -1; + double _internal_wire_unit = -1; + double _internal_via_unit = -1; int32_t _topo_spilt_length = 0; - double _prefer_wire_unit = 0; + int32_t _expand_step_num = 0; + int32_t _expand_step_length = 0; double _via_unit = 0; double _overflow_unit = 0; }; diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERGroup.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERLayerCost.hpp similarity index 60% rename from src/operation/iRT/source/module/early_router/er_data_manager/ERGroup.hpp rename to src/operation/iRT/source/module/early_router/er_data_manager/ERLayerCost.hpp index 496a51c2b..e31aec7a6 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERGroup.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERLayerCost.hpp @@ -16,23 +16,29 @@ // *************************************************************************************** #pragma once -#include "LayerCoord.hpp" +#include "RTHeader.hpp" namespace irt { -class ERGroup +class ERLayerCost { public: - ERGroup() = default; - ~ERGroup() = default; + ERLayerCost() = default; + ~ERLayerCost() = default; // getter - std::vector& get_coord_list() { return _coord_list; } + int32_t get_parent_layer_idx() const { return _parent_layer_idx; } + int32_t get_layer_idx() const { return _layer_idx; } + double get_history_cost() const { return _history_cost; } // setter - void set_coord_list(const std::vector& coord_list) { _coord_list = coord_list; } + void set_parent_layer_idx(const int32_t parent_layer_idx) { _parent_layer_idx = parent_layer_idx; } + void set_layer_idx(const int32_t layer_idx) { _layer_idx = layer_idx; } + void set_history_cost(const double history_cost) { _history_cost = history_cost; } // function private: - std::vector _coord_list; + int32_t _parent_layer_idx = -1; + int32_t _layer_idx = -1; + double _history_cost = 0; }; } // namespace irt diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERModel.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERModel.hpp index 8e760d0a0..45e82a84b 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERModel.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERModel.hpp @@ -19,8 +19,7 @@ #include "ERComParam.hpp" #include "ERNet.hpp" #include "ERNode.hpp" -#include "ERTopo.hpp" -#include "PriorityQueue.hpp" +#include "RTHeader.hpp" namespace irt { @@ -32,66 +31,37 @@ class ERModel // getter std::vector& get_er_net_list() { return _er_net_list; } ERComParam& get_er_com_param() { return _er_com_param; } + std::vector>>& get_grid_pair_list_list() { return _grid_pair_list_list; } std::vector& get_er_task_list() { return _er_task_list; } GridMap& get_planar_node_map() { return _planar_node_map; } std::vector>& get_layer_node_map() { return _layer_node_map; } // setter void set_er_net_list(const std::vector& er_net_list) { _er_net_list = er_net_list; } void set_er_com_param(const ERComParam& er_com_param) { _er_com_param = er_com_param; } + void set_grid_pair_list_list(const std::vector>>& grid_pair_list_list) + { + _grid_pair_list_list = grid_pair_list_list; + } void set_er_task_list(const std::vector& er_task_list) { _er_task_list = er_task_list; } void set_planar_node_map(const GridMap& planar_node_map) { _planar_node_map = planar_node_map; } void set_layer_node_map(const std::vector>& layer_node_map) { _layer_node_map = layer_node_map; } - // function -#if 1 // astar - // single topo - ERTopo* get_curr_er_topo() { return _curr_er_topo; } - std::vector>& get_start_node_list_list() { return _start_node_list_list; } - std::vector>& get_end_node_list_list() { return _end_node_list_list; } - std::vector& get_path_node_list() { return _path_node_list; } - std::vector& get_single_topo_visited_node_list() { return _single_topo_visited_node_list; } - std::vector>& get_routing_segment_list() { return _routing_segment_list; } - void set_curr_er_topo(ERTopo* curr_er_topo) { _curr_er_topo = curr_er_topo; } - void set_start_node_list_list(const std::vector>& start_node_list_list) { _start_node_list_list = start_node_list_list; } - void set_end_node_list_list(const std::vector>& end_node_list_list) { _end_node_list_list = end_node_list_list; } - void set_path_node_list(const std::vector& path_node_list) { _path_node_list = path_node_list; } - void set_single_topo_visited_node_list(const std::vector& single_topo_visited_node_list) - { - _single_topo_visited_node_list = single_topo_visited_node_list; - } - void set_routing_segment_list(const std::vector>& routing_segment_list) { _routing_segment_list = routing_segment_list; } - // single path - PriorityQueue, CmpERNodeCost>& get_open_queue() { return _open_queue; } - std::vector& get_single_path_visited_node_list() { return _single_path_visited_node_list; } - ERNode* get_path_head_node() { return _path_head_node; } - int32_t get_end_node_list_idx() const { return _end_node_list_idx; } - void set_open_queue(const PriorityQueue, CmpERNodeCost>& open_queue) { _open_queue = open_queue; } - void set_single_path_visited_node_list(const std::vector& single_path_visited_node_list) - { - _single_path_visited_node_list = single_path_visited_node_list; - } - void set_path_head_node(ERNode* path_head_node) { _path_head_node = path_head_node; } - void set_end_node_list_idx(const int32_t end_node_list_idx) { _end_node_list_idx = end_node_list_idx; } + +#if 1 + // single task + ERNet* get_curr_er_task() { return _curr_er_task; } + void set_curr_er_task(ERNet* curr_er_task) { _curr_er_task = curr_er_task; } #endif private: std::vector _er_net_list; ERComParam _er_com_param; + std::vector>> _grid_pair_list_list; std::vector _er_task_list; GridMap _planar_node_map; std::vector> _layer_node_map; -#if 1 // astar - // single topo - ERTopo* _curr_er_topo = nullptr; - std::vector> _start_node_list_list; - std::vector> _end_node_list_list; - std::vector _path_node_list; - std::vector _single_topo_visited_node_list; - std::vector> _routing_segment_list; - // single path - PriorityQueue, CmpERNodeCost> _open_queue; - std::vector _single_path_visited_node_list; - ERNode* _path_head_node = nullptr; - int32_t _end_node_list_idx = -1; +#if 1 + // single task + ERNet* _curr_er_task = nullptr; #endif }; diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERNet.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERNet.hpp index 4f3def82e..6c3335eba 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERNet.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERNet.hpp @@ -16,6 +16,7 @@ // *************************************************************************************** #pragma once +#include "ERPillar.hpp" #include "ERPin.hpp" #include "Net.hpp" @@ -32,7 +33,9 @@ class ERNet ConnectType& get_connect_type() { return _connect_type; } std::vector& get_er_pin_list() { return _er_pin_list; } BoundingBox& get_bounding_box() { return _bounding_box; } - MTree& get_topo_tree() { return _topo_tree; } + MTree& get_planar_tree() { return _planar_tree; } + MTree& get_pillar_tree() { return _pillar_tree; } + MTree& get_layer_tree() { return _layer_tree; } // const getter const ConnectType& get_connect_type() const { return _connect_type; } const std::vector& get_er_pin_list() const { return _er_pin_list; } @@ -43,7 +46,9 @@ class ERNet void set_connect_type(const ConnectType& connect_type) { _connect_type = connect_type; } void set_er_pin_list(const std::vector& er_pin_list) { _er_pin_list = er_pin_list; } void set_bounding_box(const BoundingBox& bounding_box) { _bounding_box = bounding_box; } - void set_topo_tree(const MTree& topo_tree) { _topo_tree = topo_tree; } + void set_planar_tree(const MTree& planar_tree) { _planar_tree = planar_tree; } + void set_pillar_tree(const MTree& pillar_tree) { _pillar_tree = pillar_tree; } + void set_layer_tree(const MTree& layer_tree) { _layer_tree = layer_tree; } // function private: @@ -52,7 +57,9 @@ class ERNet ConnectType _connect_type = ConnectType::kNone; std::vector _er_pin_list; BoundingBox _bounding_box; - MTree _topo_tree; + MTree _planar_tree; + MTree _pillar_tree; + MTree _layer_tree; }; struct CmpERNet diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERNode.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERNode.hpp index 49d7d2cbe..d31269900 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERNode.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERNode.hpp @@ -24,28 +24,29 @@ namespace irt { -#if 1 // astar -enum class ERNodeState -{ - kNone = 0, - kOpen = 1, - kClose = 2 -}; -#endif - class ERNode : public LayerCoord { public: ERNode() = default; ~ERNode() = default; // getter + double get_boundary_wire_unit() const { return _boundary_wire_unit; } + double get_internal_wire_unit() const { return _internal_wire_unit; } + double get_internal_via_unit() const { return _internal_via_unit; } std::map& get_neighbor_node_map() { return _neighbor_node_map; } std::map& get_orient_supply_map() { return _orient_supply_map; } - std::map& get_orient_demand_map() { return _orient_demand_map; } + std::map>& get_ignore_net_orient_map() { return _ignore_net_orient_map; } + std::map>& get_orient_net_map() { return _orient_net_map; } + std::map>& get_net_orient_map() { return _net_orient_map; } // setter + void set_boundary_wire_unit(const double boundary_wire_unit) { _boundary_wire_unit = boundary_wire_unit; } + void set_internal_wire_unit(const double internal_wire_unit) { _internal_wire_unit = internal_wire_unit; } + void set_internal_via_unit(const double internal_via_unit) { _internal_via_unit = internal_via_unit; } void set_neighbor_node_map(const std::map& neighbor_node_map) { _neighbor_node_map = neighbor_node_map; } void set_orient_supply_map(const std::map& orient_supply_map) { _orient_supply_map = orient_supply_map; } - void set_orient_demand_map(const std::map& orient_demand_map) { _orient_demand_map = orient_demand_map; } + void set_ignore_net_orient_map(const std::map>& ignore_net_orient_map) { _ignore_net_orient_map = ignore_net_orient_map; } + void set_orient_net_map(const std::map>& orient_net_map) { _orient_net_map = orient_net_map; } + void set_net_orient_map(const std::map>& net_orient_map) { _net_orient_map = net_orient_map; } // function ERNode* getNeighborNode(Orientation orientation) { @@ -55,88 +56,216 @@ class ERNode : public LayerCoord } return neighbor_node; } - double getOverflowCost(Orientation orientation, double overflow_cost) + double getOverflowCost(int32_t net_idx, Direction direction, double overflow_unit) { - double cost = 0; - if (orientation != Orientation::kAbove && orientation != Orientation::kBelow) { - int32_t node_demand = 0; - if (RTUTIL.exist(_orient_demand_map, orientation)) { - node_demand = _orient_demand_map[orientation]; + if (!validDemandUnit()) { + RTLOG.error(Loc::current(), "The demand unit is error!"); + } + std::map> orient_net_map = _orient_net_map; + std::map> net_orient_map = _net_orient_map; + if (direction == Direction::kHorizontal) { + for (Orientation orient : {Orientation::kEast, Orientation::kWest}) { + orient_net_map[orient].insert(net_idx); + net_orient_map[net_idx].insert(orient); + } + } else if (direction == Direction::kVertical) { + for (Orientation orient : {Orientation::kSouth, Orientation::kNorth}) { + orient_net_map[orient].insert(net_idx); + net_orient_map[net_idx].insert(orient); + } + } else { + RTLOG.error(Loc::current(), "The direction is error!"); + } + double boundary_overflow = 0; + for (Orientation orient : {Orientation::kEast, Orientation::kWest, Orientation::kSouth, Orientation::kNorth}) { + double boundary_demand = 0; + if (RTUTIL.exist(orient_net_map, orient)) { + for (int32_t demand_net_idx : orient_net_map[orient]) { + if (RTUTIL.exist(_ignore_net_orient_map, demand_net_idx) && RTUTIL.exist(_ignore_net_orient_map[demand_net_idx], orient)) { + continue; + } + boundary_demand += _boundary_wire_unit; + } + } + double boundary_supply = 0; + if (RTUTIL.exist(_orient_supply_map, orient)) { + boundary_supply = (_orient_supply_map[orient] * _boundary_wire_unit); + } + boundary_overflow += calcCost(boundary_demand, boundary_supply); + } + double internal_overflow = 0; + { + double internal_demand = 0; + for (Orientation orient : {Orientation::kEast, Orientation::kWest, Orientation::kSouth, Orientation::kNorth}) { + if (RTUTIL.exist(orient_net_map, orient)) { + for (int32_t demand_net_idx : orient_net_map[orient]) { + if (RTUTIL.exist(_ignore_net_orient_map, demand_net_idx) && RTUTIL.exist(_ignore_net_orient_map[demand_net_idx], orient)) { + continue; + } + internal_demand += _internal_wire_unit; + } + } + } + for (auto& [net_idx, orient_set] : net_orient_map) { + if (RTUTIL.exist(_ignore_net_orient_map, net_idx) + && (RTUTIL.exist(_ignore_net_orient_map[net_idx], Orientation::kAbove) || RTUTIL.exist(_ignore_net_orient_map[net_idx], Orientation::kBelow))) { + continue; + } + if (RTUTIL.exist(orient_set, Orientation::kEast) || RTUTIL.exist(orient_set, Orientation::kWest) || RTUTIL.exist(orient_set, Orientation::kSouth) + || RTUTIL.exist(orient_set, Orientation::kNorth)) { + continue; + } + if (RTUTIL.exist(orient_set, Orientation::kAbove) || RTUTIL.exist(orient_set, Orientation::kBelow)) { + internal_demand += _internal_via_unit; + } } - int32_t node_supply = 0; - if (RTUTIL.exist(_orient_supply_map, orientation)) { - node_supply = _orient_supply_map[orientation]; + double internal_supply = 0; + for (auto& [orient, supply] : _orient_supply_map) { + internal_supply += (supply * _internal_wire_unit); } - cost += (calcCost(node_demand + 1, node_supply) * overflow_cost); + internal_overflow += calcCost(internal_demand, internal_supply); } + double cost = 0; + cost += (overflow_unit * (boundary_overflow + internal_overflow)); return cost; } + bool validDemandUnit() + { + if (_boundary_wire_unit <= 0) { + return false; + } + if (_internal_wire_unit <= 0) { + return false; + } + if (_internal_via_unit <= 0) { + return false; + } + return true; + } double calcCost(double demand, double supply) { double cost = 0; if (demand == supply) { cost = 1; } else if (demand > supply) { - cost = std::pow(demand - supply + 1, 2); + cost = std::pow(demand - supply + 1, 4); } else if (demand < supply) { - cost = std::pow(demand / supply, 2); + cost = std::pow(demand / supply, 4); } return cost; } - void updateDemand(std::set orient_set, ChangeType change_type) + double getDemand() { - for (const Orientation& orient : orient_set) { - if (orient == Orientation::kEast || orient == Orientation::kWest || orient == Orientation::kSouth || orient == Orientation::kNorth) { - _orient_demand_map[orient] += (change_type == ChangeType::kAdd ? 1 : -1); + if (!validDemandUnit()) { + RTLOG.error(Loc::current(), "The demand unit is error!"); + } + double boundary_demand = 0; + for (Orientation orient : {Orientation::kEast, Orientation::kWest, Orientation::kSouth, Orientation::kNorth}) { + if (RTUTIL.exist(_orient_net_map, orient)) { + boundary_demand += (static_cast(_orient_net_map[orient].size()) * _boundary_wire_unit); + } + } + double internal_demand = 0; + for (Orientation orient : {Orientation::kEast, Orientation::kWest, Orientation::kSouth, Orientation::kNorth}) { + if (RTUTIL.exist(_orient_net_map, orient)) { + internal_demand += (static_cast(_orient_net_map[orient].size()) * _internal_wire_unit); + } + } + for (auto& [net_idx, orient_set] : _net_orient_map) { + if (RTUTIL.exist(orient_set, Orientation::kEast) || RTUTIL.exist(orient_set, Orientation::kWest) || RTUTIL.exist(orient_set, Orientation::kSouth) + || RTUTIL.exist(orient_set, Orientation::kNorth)) { + continue; + } + if (RTUTIL.exist(orient_set, Orientation::kAbove) || RTUTIL.exist(orient_set, Orientation::kBelow)) { + internal_demand += _internal_via_unit; } } + return (boundary_demand + internal_demand); } -#if 1 // astar - // single path - ERNodeState& get_state() { return _state; } - ERNode* get_parent_node() const { return _parent_node; } - double get_known_cost() const { return _known_cost; } - double get_estimated_cost() const { return _estimated_cost; } - void set_state(ERNodeState state) { _state = state; } - void set_parent_node(ERNode* parent_node) { _parent_node = parent_node; } - void set_known_cost(const double known_cost) { _known_cost = known_cost; } - void set_estimated_cost(const double estimated_cost) { _estimated_cost = estimated_cost; } - // function - bool isNone() { return _state == ERNodeState::kNone; } - bool isOpen() { return _state == ERNodeState::kOpen; } - bool isClose() { return _state == ERNodeState::kClose; } - double getTotalCost() { return (_known_cost + _estimated_cost); } -#endif - - private: - std::map _neighbor_node_map; - std::map _orient_supply_map; - std::map _orient_demand_map; -#if 1 // astar - // single path - ERNodeState _state = ERNodeState::kNone; - ERNode* _parent_node = nullptr; - double _known_cost = 0.0; // include curr - double _estimated_cost = 0.0; -#endif -}; - -#if 1 // astar -struct CmpERNodeCost -{ - bool operator()(ERNode* a, ERNode* b) + double getOverflow() { - if (RTUTIL.equalDoubleByError(a->getTotalCost(), b->getTotalCost(), RT_ERROR)) { - if (RTUTIL.equalDoubleByError(a->get_estimated_cost(), b->get_estimated_cost(), RT_ERROR)) { - return a->get_neighbor_node_map().size() < b->get_neighbor_node_map().size(); + if (!validDemandUnit()) { + RTLOG.error(Loc::current(), "The demand unit is error!"); + } + double boundary_overflow = 0; + for (Orientation orient : {Orientation::kEast, Orientation::kWest, Orientation::kSouth, Orientation::kNorth}) { + double boundary_demand = 0; + if (RTUTIL.exist(_orient_net_map, orient)) { + for (int32_t demand_net_idx : _orient_net_map[orient]) { + if (RTUTIL.exist(_ignore_net_orient_map, demand_net_idx) && RTUTIL.exist(_ignore_net_orient_map[demand_net_idx], orient)) { + continue; + } + boundary_demand += _boundary_wire_unit; + } + } + double boundary_supply = 0; + if (RTUTIL.exist(_orient_supply_map, orient)) { + boundary_supply = (_orient_supply_map[orient] * _boundary_wire_unit); + } + boundary_overflow += std::max(0.0, boundary_demand - boundary_supply); + } + double internal_overflow = 0; + { + double internal_demand = 0; + for (Orientation orient : {Orientation::kEast, Orientation::kWest, Orientation::kSouth, Orientation::kNorth}) { + if (RTUTIL.exist(_orient_net_map, orient)) { + for (int32_t demand_net_idx : _orient_net_map[orient]) { + if (RTUTIL.exist(_ignore_net_orient_map, demand_net_idx) && RTUTIL.exist(_ignore_net_orient_map[demand_net_idx], orient)) { + continue; + } + internal_demand += _internal_wire_unit; + } + } + } + for (auto& [net_idx, orient_set] : _net_orient_map) { + if (RTUTIL.exist(_ignore_net_orient_map, net_idx) + && (RTUTIL.exist(_ignore_net_orient_map[net_idx], Orientation::kAbove) || RTUTIL.exist(_ignore_net_orient_map[net_idx], Orientation::kBelow))) { + continue; + } + if (RTUTIL.exist(orient_set, Orientation::kEast) || RTUTIL.exist(orient_set, Orientation::kWest) || RTUTIL.exist(orient_set, Orientation::kSouth) + || RTUTIL.exist(orient_set, Orientation::kNorth)) { + continue; + } + if (RTUTIL.exist(orient_set, Orientation::kAbove) || RTUTIL.exist(orient_set, Orientation::kBelow)) { + internal_demand += _internal_via_unit; + } + } + double internal_supply = 0; + for (auto& [orient, supply] : _orient_supply_map) { + internal_supply += (supply * _internal_wire_unit); + } + internal_overflow += std::max(0.0, internal_demand - internal_supply); + } + return (boundary_overflow + internal_overflow); + } + void updateDemand(int32_t net_idx, std::set orient_set, ChangeType change_type) + { + for (const Orientation& orient : orient_set) { + if (change_type == ChangeType::kAdd) { + _orient_net_map[orient].insert(net_idx); + _net_orient_map[net_idx].insert(orient); } else { - return a->get_estimated_cost() > b->get_estimated_cost(); + _orient_net_map[orient].erase(net_idx); + if (_orient_net_map[orient].empty()) { + _orient_net_map.erase(orient); + } + _net_orient_map[net_idx].erase(orient); + if (_net_orient_map[net_idx].empty()) { + _net_orient_map.erase(net_idx); + } } - } else { - return a->getTotalCost() > b->getTotalCost(); } } + + private: + double _boundary_wire_unit = -1; + double _internal_wire_unit = -1; + double _internal_via_unit = -1; + std::map _neighbor_node_map; + std::map _orient_supply_map; + std::map> _ignore_net_orient_map; + std::map> _orient_net_map; + std::map> _net_orient_map; }; -#endif } // namespace irt diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERPackage.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERPackage.hpp new file mode 100644 index 000000000..daccd953b --- /dev/null +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERPackage.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "ERPillar.hpp" +#include "TNode.hpp" + +namespace irt { + +class ERPackage +{ + public: + ERPackage() = default; + explicit ERPackage(TNode* parent_pillar_node, TNode* child_pillar_node) + { + _parent_pillar_node = parent_pillar_node; + _child_pillar_node = child_pillar_node; + } + ~ERPackage() = default; + // getter + TNode* get_parent_pillar_node() { return _parent_pillar_node; } + TNode* get_child_pillar_node() { return _child_pillar_node; } + // const getter + const TNode* get_parent_pillar_node() const { return _parent_pillar_node; } + const TNode* get_child_pillar_node() const { return _child_pillar_node; } + // setter + void set_parent_pillar_node(TNode* parent_pillar_node) { _parent_pillar_node = parent_pillar_node; } + void set_child_pillar_node(TNode* child_pillar_node) { _child_pillar_node = child_pillar_node; } + // function + ERPillar& getParentPillar() { return _parent_pillar_node->value(); } + ERPillar& getChildPillar() { return _child_pillar_node->value(); } + + private: + TNode* _parent_pillar_node = nullptr; + TNode* _child_pillar_node = nullptr; +}; + +} // namespace irt diff --git a/src/operation/iRT/source/module/early_router/er_data_manager/ERIterParam.hpp b/src/operation/iRT/source/module/early_router/er_data_manager/ERPillar.hpp similarity index 50% rename from src/operation/iRT/source/module/early_router/er_data_manager/ERIterParam.hpp rename to src/operation/iRT/source/module/early_router/er_data_manager/ERPillar.hpp index 0e338f6cf..b1909a046 100644 --- a/src/operation/iRT/source/module/early_router/er_data_manager/ERIterParam.hpp +++ b/src/operation/iRT/source/module/early_router/er_data_manager/ERPillar.hpp @@ -16,17 +16,32 @@ // *************************************************************************************** #pragma once +#include "LALayerCost.hpp" +#include "PlanarCoord.hpp" + namespace irt { -class ERIterParam +class ERPillar { public: - ERIterParam() = default; - ~ERIterParam() = default; + ERPillar() = default; + ~ERPillar() = default; // getter + PlanarCoord& get_planar_coord() { return _planar_coord; } + std::set& get_pin_layer_idx_set() { return _pin_layer_idx_set; } + std::vector& get_layer_cost_list() { return _layer_cost_list; } + int32_t get_layer_idx() const { return _layer_idx; } // setter + void set_planar_coord(const PlanarCoord& planar_coord) { _planar_coord = planar_coord; } + void set_pin_layer_idx_set(const std::set& pin_layer_idx_set) { _pin_layer_idx_set = pin_layer_idx_set; } + void set_layer_cost_list(const std::vector& layer_cost_list) { _layer_cost_list = layer_cost_list; } + void set_layer_idx(const int32_t layer_idx) { _layer_idx = layer_idx; } + // function private: + PlanarCoord _planar_coord; + std::set _pin_layer_idx_set; + std::vector _layer_cost_list; + int32_t _layer_idx = -1; }; - } // namespace irt diff --git a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp index 97deaf21d..1b39ac614 100644 --- a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp +++ b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp @@ -435,9 +435,12 @@ void SupplyAnalyzer::outputPlanarSupplyCSV(SAModel& sa_model) { std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - - std::ofstream* supply_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "supply_map_planar.csv")); + std::string& sa_temp_directory_path = RTDM.getConfig().sa_temp_directory_path; + int32_t output_inter_result = RTDM.getConfig().output_inter_result; + if (!output_inter_result) { + return; + } + std::ofstream* supply_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(sa_temp_directory_path, "supply_map_planar.csv")); for (int32_t y = gcell_map.get_y_size() - 1; y >= 0; y--) { for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { int32_t total_supply = 0; @@ -458,11 +461,14 @@ void SupplyAnalyzer::outputLayerSupplyCSV(SAModel& sa_model) { std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); - std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; - + std::string& sa_temp_directory_path = RTDM.getConfig().sa_temp_directory_path; + int32_t output_inter_result = RTDM.getConfig().output_inter_result; + if (!output_inter_result) { + return; + } for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* supply_csv_file - = RTUTIL.getOutputFileStream(RTUTIL.getString(er_temp_directory_path, "supply_map_", routing_layer.get_layer_name(), ".csv")); + = RTUTIL.getOutputFileStream(RTUTIL.getString(sa_temp_directory_path, "supply_map_", routing_layer.get_layer_name(), ".csv")); for (int32_t y = gcell_map.get_y_size() - 1; y >= 0; y--) { for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { int32_t total_supply = 0; -- Gitee From d10238a63d1ca1abdcdc4d2b7015f3d02988745a Mon Sep 17 00:00:00 2001 From: simintao Date: Mon, 29 Sep 2025 11:19:16 +0800 Subject: [PATCH 12/19] refactore:add warning --- .../builder/verilog_builder/verilog_read.cpp | 22 ++++++++++------- .../verilog-parser/src/verilog_parser/mod.rs | 24 +++++++++---------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/database/manager/builder/verilog_builder/verilog_read.cpp b/src/database/manager/builder/verilog_builder/verilog_read.cpp index d52821608..5ce38b94a 100644 --- a/src/database/manager/builder/verilog_builder/verilog_read.cpp +++ b/src/database/manager/builder/verilog_builder/verilog_read.cpp @@ -78,6 +78,7 @@ void testMakeSingleModule(idb::NetlistReader* nr, string topModuleName) { #include #include "IdbDesign.h" +#include "log/Log.hh" namespace idb { @@ -482,7 +483,12 @@ int32_t RustVerilogRead::build_assign() the_right_io_pin->set_net(the_left_idb_net); the_right_io_pin->set_net_name(the_left_idb_net->get_net_name()); } else { - std::cout << "assign " << left_net_name << " = " << right_net_name << " is not processed." << "\n"; + LOG_WARNING << "assign " << left_net_name << " = " << right_net_name << " is not processed."; + bool has_b0 = (right_net_name.find("1'b0") != std::string::npos); + bool has_b1 = (right_net_name.find("1'b1") != std::string::npos); + if (has_b0 || has_b1) { + LOG_ERROR << "constant net should connect to tie logic cell."; + } } } else if (the_right_idb_net && !the_right_io_pin) { if (the_left_io_pin->is_io_pin()) { @@ -491,7 +497,7 @@ int32_t RustVerilogRead::build_assign() the_left_io_pin->set_net(the_right_idb_net); the_left_io_pin->set_net_name(the_right_idb_net->get_net_name()); } else { - std::cout << "assign " << left_net_name << " = " << right_net_name << " is not processed." << "\n"; + LOG_WARNING << "assign " << left_net_name << " = " << right_net_name << " is not processed."; } } else if (!the_left_idb_net && !the_right_idb_net && the_right_io_pin) { // assign output_port = input_port; @@ -519,10 +525,10 @@ int32_t RustVerilogRead::build_assign() the_left_io_pin->set_net(idb_net); the_left_io_pin->set_net_name(idb_net->get_net_name()); } else { - std::cout << "assign " << left_net_name << " = " << right_net_name << " is not processed." << "\n"; + LOG_WARNING << "assign " << left_net_name << " = " << right_net_name << " is not processed."; } } else { - std::cout << "assign " << left_net_name << " = " << right_net_name << " is not processed." << "\n"; + LOG_WARNING << "assign " << left_net_name << " = " << right_net_name << " is not processed."; } }; @@ -572,8 +578,7 @@ int32_t RustVerilogRead::build_assign() id_net_name = slice_net_id->base_id; base_id_index = slice_net_id->range_base; } else { - std::cout << "left net id should be id or bus slice id"; - assert(false); + LOG_FATAL << "left net id should be id or bus slice id"; } auto verilog_id_concat = rust_convert_verilog_net_concat_expr(concat_net_expr)->verilog_id_concat; @@ -690,8 +695,7 @@ int32_t RustVerilogRead::build_assign() } } else { - std::cout << "assign declaration's lhs/rhs is not VerilogNetIDExpr class." << std::endl; - assert(false); + LOG_FATAL << "assign declaration's lhs/rhs is not VerilogNetIDExpr class."; } } } @@ -849,7 +853,7 @@ int32_t RustVerilogRead::build_components() auto* cell_master = idb_master_list->find_cell_master(cell_master_name); if (cell_master == nullptr) { - std::cout << "Error : can not find cell master = " << cell_master_name << std::endl; + LOG_ERROR << "Error : can not find cell master = " << cell_master_name; continue; } idb_instance->set_cell_master(cell_master); diff --git a/src/database/manager/parser/verilog/verilog-rust/verilog-parser/src/verilog_parser/mod.rs b/src/database/manager/parser/verilog/verilog-rust/verilog-parser/src/verilog_parser/mod.rs index ce863a3f7..a0142cff4 100644 --- a/src/database/manager/parser/verilog/verilog-rust/verilog-parser/src/verilog_parser/mod.rs +++ b/src/database/manager/parser/verilog/verilog-rust/verilog-parser/src/verilog_parser/mod.rs @@ -781,8 +781,8 @@ fn flatten_the_module( port_connect_net_opt.unwrap() } }; - - // get assign left parent connect net. + + // get assign left parent connect net. let left_net_expr_id = left_net_expr.get_verilog_id(); let left_port_name = left_net_expr_id.get_name(); let left_net_base_name = left_net_expr_id.get_base_name(); @@ -797,7 +797,6 @@ fn flatten_the_module( let left_port_connect_net = get_or_create_port_connect_net(left_port_connect_net_opt, left_net_expr); - // get assign right parent connect net. if right_net_expr.is_id_expr() { @@ -812,7 +811,7 @@ fn flatten_the_module( right_net_base_name, right_port_name, ); - + let right_port_connect_net = get_or_create_port_connect_net(right_port_connect_net_opt, right_net_expr); // for debug @@ -837,9 +836,9 @@ fn flatten_the_module( // should be concat expr, so we need to process each net expr in the concat expr. let right_net_expr_concat = right_net_expr.as_any().downcast_ref::().unwrap(); - + let mut new_right_net_expr_concat: Vec> = Vec::new(); - right_net_expr_concat.get_verilog_id_concat().iter().for_each(|net_expr| { + right_net_expr_concat.get_verilog_id_concat().iter().for_each(|net_expr| { let right_net_expr_id = net_expr.get_verilog_id(); let right_port_name = right_net_expr_id.get_name(); let right_net_base_name = right_net_expr_id.get_base_name(); @@ -862,12 +861,12 @@ fn flatten_the_module( Box::new(new_right_net_expr); let new_assignment_stmt: verilog_data::VerilogAssign = verilog_data::VerilogAssign::new( - module_assign_stmt.get_line_no(), - left_port_connect_net, - new_dyn_right_net_expr, - ); + module_assign_stmt.get_line_no(), + left_port_connect_net, + new_dyn_right_net_expr, + ); let new_dyn_assign_stmt: Box = Box::new(new_assignment_stmt); - verilog_data::VerilogModule::add_stmt(&mut parent_module.borrow_mut(), new_dyn_assign_stmt); + verilog_data::VerilogModule::add_stmt(&mut parent_module.borrow_mut(), new_dyn_assign_stmt); } } } @@ -959,7 +958,8 @@ pub fn flatten_module(verilog_file: &mut verilog_data::VerilogFile, top_module_n let module_map = verilog_file.get_module_map(); if module_map.len() > 1 { println!("flatten module {} start", top_module_name); - let the_module = module_map.get(top_module_name).unwrap(); + let the_module = + module_map.get(top_module_name).unwrap_or_else(|| panic!("can't find top module {}", top_module_name)); let mut have_sub_module; loop { have_sub_module = false; -- Gitee From 28c1e2740627f9af2ade57c72bf4957090ed95f8 Mon Sep 17 00:00:00 2001 From: simintao Date: Mon, 29 Sep 2025 11:20:27 +0800 Subject: [PATCH 13/19] refactor:warning log --- src/database/manager/builder/verilog_builder/verilog_read.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/database/manager/builder/verilog_builder/verilog_read.cpp b/src/database/manager/builder/verilog_builder/verilog_read.cpp index 5ce38b94a..157f23751 100644 --- a/src/database/manager/builder/verilog_builder/verilog_read.cpp +++ b/src/database/manager/builder/verilog_builder/verilog_read.cpp @@ -487,7 +487,7 @@ int32_t RustVerilogRead::build_assign() bool has_b0 = (right_net_name.find("1'b0") != std::string::npos); bool has_b1 = (right_net_name.find("1'b1") != std::string::npos); if (has_b0 || has_b1) { - LOG_ERROR << "constant net should connect to tie logic cell."; + LOG_ERROR << "constant net should connect to tie cell."; } } } else if (the_right_idb_net && !the_right_io_pin) { -- Gitee From 1eb20b55430992d5126e4b45dd9110badea4755a Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Wed, 1 Oct 2025 14:42:08 +0800 Subject: [PATCH 14/19] update early router --- .../module/early_router/EarlyRouter.cpp | 556 +++++++++++++++++- .../module/early_router/EarlyRouter.hpp | 6 + .../module/layer_assigner/LayerAssigner.cpp | 25 + .../module/pin_accessor/PinAccessor.cpp | 19 +- .../module/space_router/SpaceRouter.cpp | 25 + .../topology_generator/TopologyGenerator.cpp | 25 + 6 files changed, 633 insertions(+), 23 deletions(-) diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp index 0d2c93ff0..34e750543 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp @@ -57,7 +57,7 @@ void EarlyRouter::route() ERModel er_model = initERModel(); setERComParam(er_model); generateAccessPoint(er_model); - // generateAccessResult(er_model); + generateAccessPatch(er_model); buildSupplySchedule(er_model); analyzeSupply(er_model); buildIgnoreNet(er_model); @@ -72,6 +72,7 @@ void EarlyRouter::route() buildLayerOrientSupply(er_model); assignLayer(er_model); outputResult(er_model); + // debugPlotERModel(er_model, "best"); updateSummary(er_model); printSummary(er_model); RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); @@ -157,23 +158,30 @@ void EarlyRouter::generateAccessPoint(ERModel& er_model) for (ERNet& er_net : er_net_list) { for (ERPin& er_pin : er_net.get_er_pin_list()) { - std::vector& routing_shape_list = er_pin.get_routing_shape_list(); - - LayerCoord layer_coord; + std::vector>> routing_pin_shape_list; { - int32_t max_area = INT32_MIN; - LayerRect max_area_shape = routing_shape_list.front().getRealLayerRect(); + std::map> routing_pin_shape_map; for (EXTLayerRect& routing_shape : er_pin.get_routing_shape_list()) { - PlanarRect& real_shape = routing_shape.get_real_rect(); - if (max_area < real_shape.getArea()) { - max_area = static_cast(real_shape.getArea()); - max_area_shape.set_rect(real_shape); - } + routing_pin_shape_map[routing_shape.get_layer_idx()].emplace_back(routing_shape); + } + for (auto& [routing_layer_idx, pin_shape_list] : routing_pin_shape_map) { + routing_pin_shape_list.emplace_back(routing_layer_idx, pin_shape_list); } - layer_coord.set_coord(max_area_shape.getMidPoint()); - layer_coord.set_layer_idx(max_area_shape.get_layer_idx()); + if (er_pin.get_is_core()) { + std::sort( + routing_pin_shape_list.begin(), routing_pin_shape_list.end(), + [](const std::pair>& a, const std::pair>& b) { return a.first > b.first; }); + } else { + std::sort(routing_pin_shape_list.begin(), routing_pin_shape_list.end(), + [](const std::pair>& a, const std::pair>& b) { + return (a.first % 2 != 0 && b.first % 2 == 0) || (a.first % 2 == b.first % 2 && a.first > b.first); + }); + } + } + if (routing_pin_shape_list.empty()) { + RTLOG.error(Loc::current(), "The routing_pin_shape_list is empty!"); } - er_pin.set_access_point(AccessPoint(er_pin.get_pin_idx(), layer_coord)); + er_pin.set_access_point(AccessPoint(er_pin.get_pin_idx(), getAccessCoord(routing_pin_shape_list.front().second))); } std::vector coord_list; @@ -192,6 +200,183 @@ void EarlyRouter::generateAccessPoint(ERModel& er_model) RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } +LayerCoord EarlyRouter::getAccessCoord(std::vector& shape_list) +{ + Die& die = RTDM.getDatabase().get_die(); + int32_t manufacture_grid = RTDM.getDatabase().get_manufacture_grid(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + + std::vector layer_coord_list; + for (EXTLayerRect& legal_shape : shape_list) { + int32_t ll_x = legal_shape.get_real_rect().get_ll_x(); + int32_t ll_y = legal_shape.get_real_rect().get_ll_y(); + int32_t ur_x = legal_shape.get_real_rect().get_ur_x(); + int32_t ur_y = legal_shape.get_real_rect().get_ur_y(); + int32_t curr_layer_idx = legal_shape.get_layer_idx(); + // 避免 off_grid + while (ll_x % manufacture_grid != 0) { + ll_x++; + } + while (ll_y % manufacture_grid != 0) { + ll_y++; + } + while (ur_x % manufacture_grid != 0) { + ur_x--; + } + while (ur_y % manufacture_grid != 0) { + ur_y--; + } + RoutingLayer curr_routing_layer = routing_layer_list[curr_layer_idx]; + std::vector x_track_list = RTUTIL.getScaleList(ll_x, ur_x, curr_routing_layer.getXTrackGridList()); + std::vector y_track_list = RTUTIL.getScaleList(ll_y, ur_y, curr_routing_layer.getYTrackGridList()); + std::vector x_shape_list; + { + x_shape_list.emplace_back(ll_x); + if ((ur_x - ll_x) / manufacture_grid % 2 == 0) { + x_shape_list.emplace_back((ll_x + ur_x) / 2); + } else { + x_shape_list.emplace_back((ll_x + ur_x - manufacture_grid) / 2); + x_shape_list.emplace_back((ll_x + ur_x + manufacture_grid) / 2); + } + x_shape_list.emplace_back(ur_x); + } + std::vector y_shape_list; + { + y_shape_list.emplace_back(ll_y); + if ((ur_y - ll_y) / manufacture_grid % 2 == 0) { + y_shape_list.emplace_back((ll_y + ur_y) / 2); + } else { + y_shape_list.emplace_back((ll_y + ur_y - manufacture_grid) / 2); + y_shape_list.emplace_back((ll_y + ur_y + manufacture_grid) / 2); + } + y_shape_list.emplace_back(ur_y); + } + // track grid + if (layer_coord_list.empty()) { + for (int32_t x : x_track_list) { + for (int32_t y : y_track_list) { + layer_coord_list.emplace_back(x, y, curr_layer_idx); + } + } + } + // on track + if (layer_coord_list.empty()) { + for (int32_t x : x_shape_list) { + for (int32_t y : y_track_list) { + layer_coord_list.emplace_back(x, y, curr_layer_idx); + } + } + for (int32_t x : x_track_list) { + for (int32_t y : y_shape_list) { + layer_coord_list.emplace_back(x, y, curr_layer_idx); + } + } + } + // on shape + if (layer_coord_list.empty()) { + for (int32_t x : x_shape_list) { + for (int32_t y : y_shape_list) { + layer_coord_list.emplace_back(x, y, curr_layer_idx); + } + } + } + } + { + PlanarRect die_valid_rect = die.get_real_rect(); + int32_t shrinked_size = RTDM.getOnlyPitch(); + if (RTUTIL.hasShrinkedRect(die_valid_rect, shrinked_size)) { + die_valid_rect = RTUTIL.getShrinkedRect(die_valid_rect, shrinked_size); + } + std::vector new_layer_coord_list; + for (LayerCoord& layer_coord : layer_coord_list) { + if (RTUTIL.isInside(die_valid_rect, layer_coord)) { + new_layer_coord_list.push_back(layer_coord); + } + } + layer_coord_list = new_layer_coord_list; + } + { + for (LayerCoord& layer_coord : layer_coord_list) { + if (layer_coord.get_x() % manufacture_grid != 0) { + RTLOG.error(Loc::current(), "The coord is off_grid!"); + } + if (layer_coord.get_y() % manufacture_grid != 0) { + RTLOG.error(Loc::current(), "The coord is off_grid!"); + } + } + } + std::sort(layer_coord_list.begin(), layer_coord_list.end(), CmpLayerCoordByXASC()); + layer_coord_list.erase(std::unique(layer_coord_list.begin(), layer_coord_list.end()), layer_coord_list.end()); + if (layer_coord_list.empty()) { + RTLOG.error(Loc::current(), "The layer_coord_list is empty!"); + } + return layer_coord_list.front(); +} + +void EarlyRouter::generateAccessPatch(ERModel& er_model) +{ + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + + ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + int32_t bottom_routing_layer_idx = RTDM.getConfig().bottom_routing_layer_idx; + int32_t top_routing_layer_idx = RTDM.getConfig().top_routing_layer_idx; + + std::vector& er_net_list = er_model.get_er_net_list(); + + for (ERNet& er_net : er_net_list) { + for (ERPin& er_pin : er_net.get_er_pin_list()) { + AccessPoint& access_point = er_pin.get_access_point(); + int32_t curr_layer_idx = access_point.get_layer_idx(); + + int32_t min_layer_idx = curr_layer_idx; + int32_t max_layer_idx = curr_layer_idx; + if (er_pin.get_is_core()) { + if (curr_layer_idx < bottom_routing_layer_idx) { + max_layer_idx = bottom_routing_layer_idx + 1; + } else if (top_routing_layer_idx < curr_layer_idx) { + max_layer_idx = top_routing_layer_idx - 1; + } else if (curr_layer_idx < top_routing_layer_idx) { + max_layer_idx = curr_layer_idx + 1; + } else { + max_layer_idx = curr_layer_idx - 1; + } + } else { + if (curr_layer_idx < bottom_routing_layer_idx) { + max_layer_idx = bottom_routing_layer_idx; + } else if (top_routing_layer_idx < curr_layer_idx) { + max_layer_idx = top_routing_layer_idx; + } else if (curr_layer_idx < top_routing_layer_idx) { + max_layer_idx = curr_layer_idx; + } else { + max_layer_idx = curr_layer_idx; + } + } + RTUTIL.swapByASC(min_layer_idx, max_layer_idx); + for (int32_t layer_idx = min_layer_idx; layer_idx <= max_layer_idx; layer_idx++) { + if (layer_idx == curr_layer_idx) { + continue; + } + RoutingLayer& routing_layer = routing_layer_list[layer_idx]; + int32_t half_width = routing_layer.get_min_width() / 2; + int32_t half_length = routing_layer.get_min_area() / routing_layer.get_min_width() / 2; + + EXTLayerRect patch; + if (routing_layer.isPreferH()) { + patch.set_real_rect(RTUTIL.getEnlargedRect(access_point.get_real_coord(), half_length, half_width, half_length, half_width)); + } else { + patch.set_real_rect(RTUTIL.getEnlargedRect(access_point.get_real_coord(), half_width, half_length, half_width, half_length)); + } + patch.set_grid_rect(RTUTIL.getClosedGCellGridRect(patch.get_real_rect(), gcell_axis)); + patch.set_layer_idx(layer_idx); + RTDM.updateNetDetailedPatchToGCellMap(ChangeType::kAdd, er_net.get_net_idx(), new EXTLayerRect(patch)); + } + } + } + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); +} + void EarlyRouter::buildSupplySchedule(ERModel& er_model) { Die& die = RTDM.getDatabase().get_die(); @@ -2060,4 +2245,347 @@ void EarlyRouter::printSummary(ERModel& er_model) #endif +#if 1 // debug + +void EarlyRouter::debugPlotERModel(ERModel& er_model, std::string flag) +{ + ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); + Die& die = RTDM.getDatabase().get_die(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); + std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; + + int32_t point_size = 5; + + GPGDS gp_gds; + + // base_region + { + GPStruct base_region_struct("base_region"); + GPBoundary gp_boundary; + gp_boundary.set_layer_idx(0); + gp_boundary.set_data_type(0); + gp_boundary.set_rect(die.get_real_rect()); + base_region_struct.push(gp_boundary); + gp_gds.addStruct(base_region_struct); + } + + // gcell_axis + { + GPStruct gcell_axis_struct("gcell_axis"); + std::vector gcell_x_list = RTUTIL.getScaleList(die.get_real_ll_x(), die.get_real_ur_x(), gcell_axis.get_x_grid_list()); + std::vector gcell_y_list = RTUTIL.getScaleList(die.get_real_ll_y(), die.get_real_ur_y(), gcell_axis.get_y_grid_list()); + for (int32_t x : gcell_x_list) { + GPPath gp_path; + gp_path.set_layer_idx(0); + gp_path.set_data_type(1); + gp_path.set_segment(x, die.get_real_ll_y(), x, die.get_real_ur_y()); + gcell_axis_struct.push(gp_path); + } + for (int32_t y : gcell_y_list) { + GPPath gp_path; + gp_path.set_layer_idx(0); + gp_path.set_data_type(1); + gp_path.set_segment(die.get_real_ll_x(), y, die.get_real_ur_x(), y); + gcell_axis_struct.push(gp_path); + } + gp_gds.addStruct(gcell_axis_struct); + } + + // track_axis_struct + { + GPStruct track_axis_struct("track_axis_struct"); + for (RoutingLayer& routing_layer : routing_layer_list) { + std::vector x_list = RTUTIL.getScaleList(die.get_real_ll_x(), die.get_real_ur_x(), routing_layer.getXTrackGridList()); + std::vector y_list = RTUTIL.getScaleList(die.get_real_ll_y(), die.get_real_ur_y(), routing_layer.getYTrackGridList()); + for (int32_t x : x_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(x, die.get_real_ll_y(), x, die.get_real_ur_y()); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + for (int32_t y : y_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(die.get_real_ll_x(), y, die.get_real_ur_x(), y); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + } + gp_gds.addStruct(track_axis_struct); + } + + // fixed_rect + for (auto& [is_routing, layer_net_rect_map] : RTDM.getTypeLayerNetFixedRectMap(die)) { + for (auto& [layer_idx, net_rect_map] : layer_net_rect_map) { + for (auto& [net_idx, rect_set] : net_rect_map) { + GPStruct fixed_rect_struct(RTUTIL.getString("fixed_rect(net_", net_idx, ")")); + for (EXTLayerRect* rect : rect_set) { + GPBoundary gp_boundary; + gp_boundary.set_data_type(static_cast(GPDataType::kShape)); + gp_boundary.set_rect(rect->get_real_rect()); + if (is_routing) { + gp_boundary.set_layer_idx(RTGP.getGDSIdxByRouting(layer_idx)); + } else { + gp_boundary.set_layer_idx(RTGP.getGDSIdxByCut(layer_idx)); + } + fixed_rect_struct.push(gp_boundary); + } + gp_gds.addStruct(fixed_rect_struct); + } + } + } + + // access_point + for (ERNet& er_net : er_model.get_er_net_list()) { + GPStruct access_point_struct(RTUTIL.getString("access_point(net_", er_net.get_net_idx(), ")")); + for (ERPin& er_pin : er_net.get_er_pin_list()) { + AccessPoint& access_point = er_pin.get_access_point(); + + int32_t x = access_point.get_real_x(); + int32_t y = access_point.get_real_y(); + + GPBoundary access_point_boundary; + access_point_boundary.set_layer_idx(RTGP.getGDSIdxByRouting(access_point.get_layer_idx())); + access_point_boundary.set_data_type(static_cast(GPDataType::kAccessPoint)); + access_point_boundary.set_rect(x - point_size, y - point_size, x + point_size, y + point_size); + access_point_struct.push(access_point_boundary); + } + gp_gds.addStruct(access_point_struct); + } + + // routing result + for (ERNet& er_net : er_model.get_er_net_list()) { + GPStruct global_result_struct(RTUTIL.getString("global_result(net_", er_net.get_net_idx(), ")")); + for (Segment*>& segment : RTUTIL.getSegListByTree(er_net.get_layer_tree())) { + for (NetShape& net_shape : RTDM.getNetGlobalShapeList(er_net.get_net_idx(), segment.get_first()->value(), segment.get_second()->value())) { + GPBoundary gp_boundary; + gp_boundary.set_data_type(static_cast(GPDataType::kGlobalPath)); + gp_boundary.set_rect(net_shape.get_rect()); + if (net_shape.get_is_routing()) { + gp_boundary.set_layer_idx(RTGP.getGDSIdxByRouting(net_shape.get_layer_idx())); + } else { + gp_boundary.set_layer_idx(RTGP.getGDSIdxByCut(net_shape.get_layer_idx())); + } + global_result_struct.push(gp_boundary); + } + } + gp_gds.addStruct(global_result_struct); + } + + // routing result + for (auto& [net_idx, segment_set] : RTDM.getNetDetailedResultMap(die)) { + GPStruct detailed_result_struct(RTUTIL.getString("detailed_result(net_", net_idx, ")")); + for (Segment* segment : segment_set) { + for (NetShape& net_shape : RTDM.getNetDetailedShapeList(net_idx, *segment)) { + GPBoundary gp_boundary; + gp_boundary.set_data_type(static_cast(GPDataType::kShape)); + gp_boundary.set_rect(net_shape.get_rect()); + if (net_shape.get_is_routing()) { + gp_boundary.set_layer_idx(RTGP.getGDSIdxByRouting(net_shape.get_layer_idx())); + } else { + gp_boundary.set_layer_idx(RTGP.getGDSIdxByCut(net_shape.get_layer_idx())); + } + detailed_result_struct.push(gp_boundary); + } + } + gp_gds.addStruct(detailed_result_struct); + } + + // routing patch + for (auto& [net_idx, patch_set] : RTDM.getNetDetailedPatchMap(die)) { + GPStruct detailed_patch_struct(RTUTIL.getString("detailed_patch(net_", net_idx, ")")); + for (EXTLayerRect* patch : patch_set) { + GPBoundary gp_boundary; + gp_boundary.set_data_type(static_cast(GPDataType::kPatch)); + gp_boundary.set_rect(patch->get_real_rect()); + gp_boundary.set_layer_idx(RTGP.getGDSIdxByRouting(patch->get_layer_idx())); + detailed_patch_struct.push(gp_boundary); + } + gp_gds.addStruct(detailed_patch_struct); + } + + // layer_node_map + { + std::vector>& layer_node_map = er_model.get_layer_node_map(); + // er_node_map + { + GPStruct er_node_map_struct("er_node_map"); + for (GridMap& er_node_map : layer_node_map) { + for (int32_t grid_x = 0; grid_x < er_node_map.get_x_size(); grid_x++) { + for (int32_t grid_y = 0; grid_y < er_node_map.get_y_size(); grid_y++) { + ERNode& er_node = er_node_map[grid_x][grid_y]; + PlanarRect real_rect = RTUTIL.getRealRectByGCell(er_node.get_planar_coord(), gcell_axis); + int32_t y_reduced_span = std::max(1, real_rect.getYSpan() / 12); + int32_t y = real_rect.get_ur_y(); + + y -= y_reduced_span; + GPText gp_text_node_real_coord; + gp_text_node_real_coord.set_coord(real_rect.get_ll_x(), y); + gp_text_node_real_coord.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_node_real_coord.set_message(RTUTIL.getString("(", er_node.get_x(), " , ", er_node.get_y(), " , ", er_node.get_layer_idx(), ")")); + gp_text_node_real_coord.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_node_real_coord.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_node_real_coord); + + y -= y_reduced_span; + GPText gp_text_node_grid_coord; + gp_text_node_grid_coord.set_coord(real_rect.get_ll_x(), y); + gp_text_node_grid_coord.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_node_grid_coord.set_message(RTUTIL.getString("(", grid_x, " , ", grid_y, " , ", er_node.get_layer_idx(), ")")); + gp_text_node_grid_coord.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_node_grid_coord.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_node_grid_coord); + + y -= y_reduced_span; + GPText gp_text_orient_supply_map; + gp_text_orient_supply_map.set_coord(real_rect.get_ll_x(), y); + gp_text_orient_supply_map.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_orient_supply_map.set_message("orient_supply_map: "); + gp_text_orient_supply_map.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_orient_supply_map.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_orient_supply_map); + + if (!er_node.get_orient_supply_map().empty()) { + y -= y_reduced_span; + GPText gp_text_orient_supply_map_info; + gp_text_orient_supply_map_info.set_coord(real_rect.get_ll_x(), y); + gp_text_orient_supply_map_info.set_text_type(static_cast(GPDataType::kInfo)); + std::string orient_supply_map_info_message = "--"; + for (auto& [orient, supply] : er_node.get_orient_supply_map()) { + orient_supply_map_info_message += RTUTIL.getString("(", GetOrientationName()(orient), ",", supply, ")"); + } + gp_text_orient_supply_map_info.set_message(orient_supply_map_info_message); + gp_text_orient_supply_map_info.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_orient_supply_map_info.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_orient_supply_map_info); + } + + y -= y_reduced_span; + GPText gp_text_ignore_net_orient_map; + gp_text_ignore_net_orient_map.set_coord(real_rect.get_ll_x(), y); + gp_text_ignore_net_orient_map.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_ignore_net_orient_map.set_message("ignore_net_orient_map: "); + gp_text_ignore_net_orient_map.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_ignore_net_orient_map.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_ignore_net_orient_map); + + if (!er_node.get_ignore_net_orient_map().empty()) { + y -= y_reduced_span; + GPText gp_text_ignore_net_orient_map_info; + gp_text_ignore_net_orient_map_info.set_coord(real_rect.get_ll_x(), y); + gp_text_ignore_net_orient_map_info.set_text_type(static_cast(GPDataType::kInfo)); + std::string ignore_net_orient_map_info_message = "--"; + for (auto& [net_idx, orient_set] : er_node.get_ignore_net_orient_map()) { + ignore_net_orient_map_info_message += RTUTIL.getString("(", net_idx); + for (Orientation orient : orient_set) { + ignore_net_orient_map_info_message += RTUTIL.getString(",", GetOrientationName()(orient)); + } + ignore_net_orient_map_info_message += RTUTIL.getString(")"); + } + gp_text_ignore_net_orient_map_info.set_message(ignore_net_orient_map_info_message); + gp_text_ignore_net_orient_map_info.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_ignore_net_orient_map_info.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_ignore_net_orient_map_info); + } + + y -= y_reduced_span; + GPText gp_text_orient_net_map; + gp_text_orient_net_map.set_coord(real_rect.get_ll_x(), y); + gp_text_orient_net_map.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_orient_net_map.set_message("orient_net_map: "); + gp_text_orient_net_map.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_orient_net_map.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_orient_net_map); + + if (!er_node.get_orient_net_map().empty()) { + y -= y_reduced_span; + GPText gp_text_orient_net_map_info; + gp_text_orient_net_map_info.set_coord(real_rect.get_ll_x(), y); + gp_text_orient_net_map_info.set_text_type(static_cast(GPDataType::kInfo)); + std::string orient_net_map_info_message = "--"; + for (auto& [orient, net_set] : er_node.get_orient_net_map()) { + orient_net_map_info_message += RTUTIL.getString("(", GetOrientationName()(orient)); + for (int32_t net_idx : net_set) { + orient_net_map_info_message += RTUTIL.getString(",", net_idx); + } + orient_net_map_info_message += RTUTIL.getString(")"); + } + gp_text_orient_net_map_info.set_message(orient_net_map_info_message); + gp_text_orient_net_map_info.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_orient_net_map_info.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_orient_net_map_info); + } + + y -= y_reduced_span; + GPText gp_text_net_orient_map; + gp_text_net_orient_map.set_coord(real_rect.get_ll_x(), y); + gp_text_net_orient_map.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_net_orient_map.set_message("net_orient_map: "); + gp_text_net_orient_map.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_net_orient_map.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_net_orient_map); + + if (!er_node.get_net_orient_map().empty()) { + y -= y_reduced_span; + GPText gp_text_net_orient_map_info; + gp_text_net_orient_map_info.set_coord(real_rect.get_ll_x(), y); + gp_text_net_orient_map_info.set_text_type(static_cast(GPDataType::kInfo)); + std::string net_orient_map_info_message = "--"; + for (auto& [net_idx, orient_set] : er_node.get_net_orient_map()) { + net_orient_map_info_message += RTUTIL.getString("(", net_idx); + for (Orientation orient : orient_set) { + net_orient_map_info_message += RTUTIL.getString(",", GetOrientationName()(orient)); + } + net_orient_map_info_message += RTUTIL.getString(")"); + } + gp_text_net_orient_map_info.set_message(net_orient_map_info_message); + gp_text_net_orient_map_info.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_net_orient_map_info.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_net_orient_map_info); + } + + y -= y_reduced_span; + GPText gp_text_overflow; + gp_text_overflow.set_coord(real_rect.get_ll_x(), y); + gp_text_overflow.set_text_type(static_cast(GPDataType::kInfo)); + gp_text_overflow.set_message(RTUTIL.getString("overflow: ", er_node.getOverflow())); + gp_text_overflow.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + gp_text_overflow.set_presentation(GPTextPresentation::kLeftMiddle); + er_node_map_struct.push(gp_text_overflow); + } + } + } + gp_gds.addStruct(er_node_map_struct); + } + // overflow + { + GPStruct overflow_struct("overflow"); + for (GridMap& er_node_map : layer_node_map) { + for (int32_t grid_x = 0; grid_x < er_node_map.get_x_size(); grid_x++) { + for (int32_t grid_y = 0; grid_y < er_node_map.get_y_size(); grid_y++) { + ERNode& er_node = er_node_map[grid_x][grid_y]; + if (er_node.getOverflow() <= 0) { + continue; + } + PlanarRect real_rect = RTUTIL.getRealRectByGCell(er_node.get_planar_coord(), gcell_axis); + + GPBoundary gp_boundary; + gp_boundary.set_data_type(static_cast(GPDataType::kOverflow)); + gp_boundary.set_rect(real_rect); + gp_boundary.set_layer_idx(RTGP.getGDSIdxByRouting(er_node.get_layer_idx())); + overflow_struct.push(gp_boundary); + } + } + } + gp_gds.addStruct(overflow_struct); + } + } + + std::string gds_file_path = RTUTIL.getString(er_temp_directory_path, flag, "_er_model.gds"); + RTGP.plot(gp_gds, gds_file_path); +} + +#endif + } // namespace irt diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.hpp b/src/operation/iRT/source/module/early_router/EarlyRouter.hpp index 51aaaed41..e95d0f086 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.hpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.hpp @@ -54,6 +54,8 @@ class EarlyRouter ERNet convertToERNet(Net& net); void setERComParam(ERModel& er_model); void generateAccessPoint(ERModel& er_model); + LayerCoord getAccessCoord(std::vector& shape_list); + void generateAccessPatch(ERModel& er_model); void buildSupplySchedule(ERModel& er_model); void analyzeSupply(ERModel& er_model); EXTLayerRect getSearchRect(LayerCoord& first_coord, LayerCoord& second_coord); @@ -124,6 +126,10 @@ class EarlyRouter void updateSummary(ERModel& er_model); void printSummary(ERModel& er_model); #endif + +#if 1 // debug + void debugPlotERModel(ERModel& er_model, std::string flag); +#endif }; } // namespace irt diff --git a/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp b/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp index c16c2f9ee..4aff50eb1 100644 --- a/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp +++ b/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp @@ -1206,6 +1206,7 @@ void LayerAssigner::debugPlotLAModel(LAModel& la_model, std::string flag) { ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); Die& die = RTDM.getDatabase().get_die(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& la_temp_directory_path = RTDM.getConfig().la_temp_directory_path; int32_t point_size = 5; @@ -1245,6 +1246,30 @@ void LayerAssigner::debugPlotLAModel(LAModel& la_model, std::string flag) gp_gds.addStruct(gcell_axis_struct); } + // track_axis_struct + { + GPStruct track_axis_struct("track_axis_struct"); + for (RoutingLayer& routing_layer : routing_layer_list) { + std::vector x_list = RTUTIL.getScaleList(die.get_real_ll_x(), die.get_real_ur_x(), routing_layer.getXTrackGridList()); + std::vector y_list = RTUTIL.getScaleList(die.get_real_ll_y(), die.get_real_ur_y(), routing_layer.getYTrackGridList()); + for (int32_t x : x_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(x, die.get_real_ll_y(), x, die.get_real_ur_y()); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + for (int32_t y : y_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(die.get_real_ll_x(), y, die.get_real_ur_x(), y); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + } + gp_gds.addStruct(track_axis_struct); + } + // fixed_rect for (auto& [is_routing, layer_net_rect_map] : RTDM.getTypeLayerNetFixedRectMap(die)) { for (auto& [layer_idx, net_rect_map] : layer_net_rect_map) { diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp index 395fb5d8b..10ef538d8 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp @@ -209,15 +209,16 @@ std::vector PinAccessor::getLegalShapeList(PAModel& pa_model, int32_t for (auto& [routing_layer_idx, pin_shape_list] : routing_pin_shape_map) { routing_pin_shape_list.emplace_back(routing_layer_idx, pin_shape_list); } - } - if (pa_pin->get_is_core()) { - std::sort(routing_pin_shape_list.begin(), routing_pin_shape_list.end(), - [](const std::pair>& a, const std::pair>& b) { return a.first > b.first; }); - } else { - std::sort(routing_pin_shape_list.begin(), routing_pin_shape_list.end(), - [](const std::pair>& a, const std::pair>& b) { - return (a.first % 2 != 0 && b.first % 2 == 0) || (a.first % 2 == b.first % 2 && a.first > b.first); - }); + if (pa_pin->get_is_core()) { + std::sort( + routing_pin_shape_list.begin(), routing_pin_shape_list.end(), + [](const std::pair>& a, const std::pair>& b) { return a.first > b.first; }); + } else { + std::sort(routing_pin_shape_list.begin(), routing_pin_shape_list.end(), + [](const std::pair>& a, const std::pair>& b) { + return (a.first % 2 != 0 && b.first % 2 == 0) || (a.first % 2 == b.first % 2 && a.first > b.first); + }); + } } std::vector legal_rect_list; for (auto& [routing_layer_idx, pin_shape_list] : routing_pin_shape_list) { diff --git a/src/operation/iRT/source/module/space_router/SpaceRouter.cpp b/src/operation/iRT/source/module/space_router/SpaceRouter.cpp index d91073225..454ed2e45 100644 --- a/src/operation/iRT/source/module/space_router/SpaceRouter.cpp +++ b/src/operation/iRT/source/module/space_router/SpaceRouter.cpp @@ -1953,6 +1953,7 @@ void SpaceRouter::debugPlotSRModel(SRModel& sr_model, std::string flag) { ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); Die& die = RTDM.getDatabase().get_die(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& sr_temp_directory_path = RTDM.getConfig().sr_temp_directory_path; int32_t point_size = 5; @@ -1992,6 +1993,30 @@ void SpaceRouter::debugPlotSRModel(SRModel& sr_model, std::string flag) gp_gds.addStruct(gcell_axis_struct); } + // track_axis_struct + { + GPStruct track_axis_struct("track_axis_struct"); + for (RoutingLayer& routing_layer : routing_layer_list) { + std::vector x_list = RTUTIL.getScaleList(die.get_real_ll_x(), die.get_real_ur_x(), routing_layer.getXTrackGridList()); + std::vector y_list = RTUTIL.getScaleList(die.get_real_ll_y(), die.get_real_ur_y(), routing_layer.getYTrackGridList()); + for (int32_t x : x_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(x, die.get_real_ll_y(), x, die.get_real_ur_y()); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + for (int32_t y : y_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(die.get_real_ll_x(), y, die.get_real_ur_x(), y); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + } + gp_gds.addStruct(track_axis_struct); + } + // fixed_rect for (auto& [is_routing, layer_net_rect_map] : RTDM.getTypeLayerNetFixedRectMap(die)) { for (auto& [layer_idx, net_rect_map] : layer_net_rect_map) { diff --git a/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp b/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp index fc8952e28..4fa2b29b1 100644 --- a/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp +++ b/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp @@ -1135,6 +1135,7 @@ void TopologyGenerator::debugPlotTGModel(TGModel& tg_model, std::string flag) { ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); Die& die = RTDM.getDatabase().get_die(); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& tg_temp_directory_path = RTDM.getConfig().tg_temp_directory_path; int32_t point_size = 5; @@ -1174,6 +1175,30 @@ void TopologyGenerator::debugPlotTGModel(TGModel& tg_model, std::string flag) gp_gds.addStruct(gcell_axis_struct); } + // track_axis_struct + { + GPStruct track_axis_struct("track_axis_struct"); + for (RoutingLayer& routing_layer : routing_layer_list) { + std::vector x_list = RTUTIL.getScaleList(die.get_real_ll_x(), die.get_real_ur_x(), routing_layer.getXTrackGridList()); + std::vector y_list = RTUTIL.getScaleList(die.get_real_ll_y(), die.get_real_ur_y(), routing_layer.getYTrackGridList()); + for (int32_t x : x_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(x, die.get_real_ll_y(), x, die.get_real_ur_y()); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + for (int32_t y : y_list) { + GPPath gp_path; + gp_path.set_data_type(static_cast(GPDataType::kAxis)); + gp_path.set_segment(die.get_real_ll_x(), y, die.get_real_ur_x(), y); + gp_path.set_layer_idx(RTGP.getGDSIdxByRouting(routing_layer.get_layer_idx())); + track_axis_struct.push(gp_path); + } + } + gp_gds.addStruct(track_axis_struct); + } + // fixed_rect for (auto& [is_routing, layer_net_rect_map] : RTDM.getTypeLayerNetFixedRectMap(die)) { for (auto& [layer_idx, net_rect_map] : layer_net_rect_map) { -- Gitee From 40e91362ec17b4c34a216d79a23be7f02235ab7b Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Fri, 10 Oct 2025 10:58:26 +0800 Subject: [PATCH 15/19] update clean def --- src/interface/tcl/tcl_irt/CMakeLists.txt | 2 +- .../tcl/tcl_irt/include/tcl_register_irt.h | 2 +- src/interface/tcl/tcl_irt/include/tcl_rt.h | 6 +-- ..._rt_clear_def.cpp => tcl_rt_clean_def.cpp} | 6 +-- src/operation/iRT/interface/RTInterface.cpp | 39 ++++++++++--------- src/operation/iRT/interface/RTInterface.hpp | 2 +- 6 files changed, 30 insertions(+), 27 deletions(-) rename src/interface/tcl/tcl_irt/src/{tcl_rt_clear_def.cpp => tcl_rt_clean_def.cpp} (90%) diff --git a/src/interface/tcl/tcl_irt/CMakeLists.txt b/src/interface/tcl/tcl_irt/CMakeLists.txt index 88b961bfd..fde136195 100644 --- a/src/interface/tcl/tcl_irt/CMakeLists.txt +++ b/src/interface/tcl/tcl_irt/CMakeLists.txt @@ -3,7 +3,7 @@ add_library(tcl_irt ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_run_egr.cpp ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_run_rt.cpp ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_destroy_rt.cpp - ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_rt_clear_def.cpp + ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_rt_clean_def.cpp ${HOME_INTERFACE}/tcl/tcl_irt/src/tcl_rt_fix_fanout.cpp ) diff --git a/src/interface/tcl/tcl_irt/include/tcl_register_irt.h b/src/interface/tcl/tcl_irt/include/tcl_register_irt.h index 04d8573f9..fbc919f9b 100644 --- a/src/interface/tcl/tcl_irt/include/tcl_register_irt.h +++ b/src/interface/tcl/tcl_irt/include/tcl_register_irt.h @@ -30,7 +30,7 @@ int registerCmdRT() registerTclCmd(TclRunRT, "run_rt"); registerTclCmd(TclDestroyRT, "destroy_rt"); // aux - registerTclCmd(TclRTClearDef, "rt_clear_def"); + registerTclCmd(TclRTCleanDef, "rt_clean_def"); registerTclCmd(TclRTFixFanout, "rt_fix_fanout"); return EXIT_SUCCESS; } diff --git a/src/interface/tcl/tcl_irt/include/tcl_rt.h b/src/interface/tcl/tcl_irt/include/tcl_rt.h index 2e2d34c97..6524c6d49 100644 --- a/src/interface/tcl/tcl_irt/include/tcl_rt.h +++ b/src/interface/tcl/tcl_irt/include/tcl_rt.h @@ -82,11 +82,11 @@ class TclDestroyRT : public TclCmd #if 1 // aux -class TclRTClearDef : public TclCmd +class TclRTCleanDef : public TclCmd { public: - explicit TclRTClearDef(const char* cmd_name); - ~TclRTClearDef() override = default; + explicit TclRTCleanDef(const char* cmd_name); + ~TclRTCleanDef() override = default; unsigned check() override { return 1; }; diff --git a/src/interface/tcl/tcl_irt/src/tcl_rt_clear_def.cpp b/src/interface/tcl/tcl_irt/src/tcl_rt_clean_def.cpp similarity index 90% rename from src/interface/tcl/tcl_irt/src/tcl_rt_clear_def.cpp rename to src/interface/tcl/tcl_irt/src/tcl_rt_clean_def.cpp index 5a167cb24..34c15aead 100644 --- a/src/interface/tcl/tcl_irt/src/tcl_rt_clear_def.cpp +++ b/src/interface/tcl/tcl_irt/src/tcl_rt_clean_def.cpp @@ -20,17 +20,17 @@ namespace tcl { -TclRTClearDef::TclRTClearDef(const char* cmd_name) : TclCmd(cmd_name) +TclRTCleanDef::TclRTCleanDef(const char* cmd_name) : TclCmd(cmd_name) { } -unsigned TclRTClearDef::exec() +unsigned TclRTCleanDef::exec() { if (!check()) { return 0; } - RTI.clearDef(); + RTI.cleanDef(); return 1; } diff --git a/src/operation/iRT/interface/RTInterface.cpp b/src/operation/iRT/interface/RTInterface.cpp index c366f3b3b..e570d5ef2 100644 --- a/src/operation/iRT/interface/RTInterface.cpp +++ b/src/operation/iRT/interface/RTInterface.cpp @@ -183,19 +183,35 @@ void RTInterface::destroyRT() Logger::destroyInst(); } -void RTInterface::clearDef() +void RTInterface::cleanDef() { - idb::IdbPins* idb_pin_list = dmInst->get_idb_def_service()->get_design()->get_io_pin_list(); - IdbNetList* idb_net_list = dmInst->get_idb_def_service()->get_design()->get_net_list(); - ////////////////////////////////////////// // 删除net内所有的wire + IdbNetList* idb_net_list = dmInst->get_idb_def_service()->get_design()->get_net_list(); for (idb::IdbNet* idb_net : idb_net_list->get_net_list()) { idb_net->clear_wire_list(); } // 删除net内所有的wire ////////////////////////////////////////// + ////////////////////////////////////////// + // 删除虚空的io_pin + idb::IdbPins* idb_pin_list = dmInst->get_idb_def_service()->get_design()->get_io_pin_list(); + std::vector remove_pin_list; + for (idb::IdbPin* io_pin : idb_pin_list->get_pin_list()) { + if (io_pin->get_port_box_list().empty()) { + RTLOG.info(Loc::current(), "del io_pin: ", io_pin->get_pin_name()); + remove_pin_list.push_back(io_pin); + } + } + for (idb::IdbPin* io_pin : remove_pin_list) { + idb_pin_list->remove_pin(io_pin); + } + // 删除虚空的io_pin + ////////////////////////////////////////// + +#if 0 + ////////////////////////////////////////// // 删除net内所有的virtual for (idb::IdbNet* idb_net : idb_net_list->get_net_list()) { @@ -258,20 +274,7 @@ void RTInterface::clearDef() // 删除net: 虚拟的io_pin与io_cell连接的PAD ////////////////////////////////////////// - ////////////////////////////////////////// - // 删除虚空的io_pin - std::vector remove_pin_list; - for (idb::IdbPin* io_pin : idb_pin_list->get_pin_list()) { - if (io_pin->get_port_box_list().empty()) { - RTLOG.info(Loc::current(), "del io_pin: ", io_pin->get_pin_name()); - remove_pin_list.push_back(io_pin); - } - } - for (idb::IdbPin* io_pin : remove_pin_list) { - idb_pin_list->remove_pin(io_pin); - } - // 删除虚空的io_pin - ////////////////////////////////////////// +#endif } void RTInterface::fixFanout() diff --git a/src/operation/iRT/interface/RTInterface.hpp b/src/operation/iRT/interface/RTInterface.hpp index e38f17229..2b600188c 100644 --- a/src/operation/iRT/interface/RTInterface.hpp +++ b/src/operation/iRT/interface/RTInterface.hpp @@ -79,7 +79,7 @@ class RTInterface void runEGR(); void runRT(); void destroyRT(); - void clearDef(); + void cleanDef(); void fixFanout(); #endif -- Gitee From 31ce76c255e4cc5756e8102b6383d0129405323f Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Fri, 10 Oct 2025 14:55:00 +0800 Subject: [PATCH 16/19] update log --- .../module/detailed_router/DetailedRouter.cpp | 10 ++++++-- .../module/early_router/EarlyRouter.cpp | 25 ++++++++++++++++--- .../module/layer_assigner/LayerAssigner.cpp | 15 ++++++++--- .../module/pin_accessor/PinAccessor.cpp | 10 ++++++-- .../module/space_router/SpaceRouter.cpp | 15 ++++++++--- .../module/supply_analyzer/SupplyAnalyzer.cpp | 10 ++++++-- .../topology_generator/TopologyGenerator.cpp | 15 ++++++++--- .../module/track_assigner/TrackAssigner.cpp | 10 ++++++-- .../violation_reporter/ViolationReporter.cpp | 10 ++++++-- 9 files changed, 97 insertions(+), 23 deletions(-) diff --git a/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp b/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp index 83dbf5f26..9683a6396 100644 --- a/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp +++ b/src/operation/iRT/source/module/detailed_router/DetailedRouter.cpp @@ -3044,6 +3044,9 @@ void DetailedRouter::outputNetCSV(DRModel& dr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_net_map; layer_net_map.resize(routing_layer_list.size()); for (GridMap& net_map : layer_net_map) { @@ -3086,7 +3089,7 @@ void DetailedRouter::outputNetCSV(DRModel& dr_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void DetailedRouter::outputViolationCSV(DRModel& dr_model) @@ -3098,6 +3101,9 @@ void DetailedRouter::outputViolationCSV(DRModel& dr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_violation_map; layer_violation_map.resize(routing_layer_list.size()); for (GridMap& violation_map : layer_violation_map) { @@ -3122,7 +3128,7 @@ void DetailedRouter::outputViolationCSV(DRModel& dr_model) } RTUTIL.closeFileStream(violation_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void DetailedRouter::outputJson(DRModel& dr_model) diff --git a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp index 34e750543..54a4521d0 100644 --- a/src/operation/iRT/source/module/early_router/EarlyRouter.cpp +++ b/src/operation/iRT/source/module/early_router/EarlyRouter.cpp @@ -1802,6 +1802,9 @@ void EarlyRouter::outputResult(ERModel& er_model) void EarlyRouter::outputGCellCSV(ERModel& er_model) { + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; @@ -1816,10 +1819,15 @@ void EarlyRouter::outputGCellCSV(ERModel& er_model) } } RTUTIL.closeFileStream(guide_file_stream); + + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void EarlyRouter::outputLayerSupplyCSV(ERModel& er_model) { + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); GridMap& gcell_map = RTDM.getDatabase().get_gcell_map(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; @@ -1839,11 +1847,14 @@ void EarlyRouter::outputLayerSupplyCSV(ERModel& er_model) } RTUTIL.closeFileStream(supply_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void EarlyRouter::outputLayerGuide(ERModel& er_model) { + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + int32_t micron_dbu = RTDM.getDatabase().get_micron_dbu(); ScaleAxis& gcell_axis = RTDM.getDatabase().get_gcell_axis(); std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); @@ -1909,11 +1920,14 @@ void EarlyRouter::outputLayerGuide(ERModel& er_model) } } RTUTIL.closeFileStream(guide_file_stream); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void EarlyRouter::outputLayerNetCSV(ERModel& er_model) { + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; @@ -1929,11 +1943,14 @@ void EarlyRouter::outputLayerNetCSV(ERModel& er_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void EarlyRouter::outputLayerOverflowCSV(ERModel& er_model) { + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector& routing_layer_list = RTDM.getDatabase().get_routing_layer_list(); std::string& er_temp_directory_path = RTDM.getConfig().er_temp_directory_path; @@ -1951,7 +1968,7 @@ void EarlyRouter::outputLayerOverflowCSV(ERModel& er_model) } RTUTIL.closeFileStream(overflow_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } #if 1 // update env diff --git a/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp b/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp index 4aff50eb1..03b1db199 100644 --- a/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp +++ b/src/operation/iRT/source/module/layer_assigner/LayerAssigner.cpp @@ -958,6 +958,9 @@ void LayerAssigner::outputGuide(LAModel& la_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector& la_net_list = la_model.get_la_net_list(); std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(la_temp_directory_path, "route.guide")); @@ -1020,7 +1023,7 @@ void LayerAssigner::outputGuide(LAModel& la_model) } } RTUTIL.closeFileStream(guide_file_stream); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void LayerAssigner::outputNetCSV(LAModel& la_model) @@ -1031,6 +1034,9 @@ void LayerAssigner::outputNetCSV(LAModel& la_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector>& layer_node_map = la_model.get_layer_node_map(); for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* net_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(la_temp_directory_path, "net_map_", routing_layer.get_layer_name(), ".csv")); @@ -1043,7 +1049,7 @@ void LayerAssigner::outputNetCSV(LAModel& la_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void LayerAssigner::outputOverflowCSV(LAModel& la_model) @@ -1054,6 +1060,9 @@ void LayerAssigner::outputOverflowCSV(LAModel& la_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector>& layer_node_map = la_model.get_layer_node_map(); for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* overflow_csv_file @@ -1068,7 +1077,7 @@ void LayerAssigner::outputOverflowCSV(LAModel& la_model) } RTUTIL.closeFileStream(overflow_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void LayerAssigner::outputJson(LAModel& la_model) diff --git a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp index 10ef538d8..f4da51f50 100644 --- a/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp +++ b/src/operation/iRT/source/module/pin_accessor/PinAccessor.cpp @@ -3500,6 +3500,9 @@ void PinAccessor::outputNetCSV(PAModel& pa_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_net_map; layer_net_map.resize(routing_layer_list.size()); for (GridMap& net_map : layer_net_map) { @@ -3546,7 +3549,7 @@ void PinAccessor::outputNetCSV(PAModel& pa_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void PinAccessor::outputViolationCSV(PAModel& pa_model) @@ -3558,6 +3561,9 @@ void PinAccessor::outputViolationCSV(PAModel& pa_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_violation_map; layer_violation_map.resize(routing_layer_list.size()); for (GridMap& violation_map : layer_violation_map) { @@ -3582,7 +3588,7 @@ void PinAccessor::outputViolationCSV(PAModel& pa_model) } RTUTIL.closeFileStream(violation_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void PinAccessor::outputJson(PAModel& pa_model) diff --git a/src/operation/iRT/source/module/space_router/SpaceRouter.cpp b/src/operation/iRT/source/module/space_router/SpaceRouter.cpp index 454ed2e45..7e1db4701 100644 --- a/src/operation/iRT/source/module/space_router/SpaceRouter.cpp +++ b/src/operation/iRT/source/module/space_router/SpaceRouter.cpp @@ -1702,6 +1702,9 @@ void SpaceRouter::outputGuide(SRModel& sr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector& sr_net_list = sr_model.get_sr_net_list(); std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(sr_temp_directory_path, "route_", sr_model.get_iter(), ".guide")); @@ -1764,7 +1767,7 @@ void SpaceRouter::outputGuide(SRModel& sr_model) } } RTUTIL.closeFileStream(guide_file_stream); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void SpaceRouter::outputNetCSV(SRModel& sr_model) @@ -1775,6 +1778,9 @@ void SpaceRouter::outputNetCSV(SRModel& sr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector>& layer_node_map = sr_model.get_layer_node_map(); for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* net_csv_file @@ -1788,7 +1794,7 @@ void SpaceRouter::outputNetCSV(SRModel& sr_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void SpaceRouter::outputOverflowCSV(SRModel& sr_model) @@ -1799,6 +1805,9 @@ void SpaceRouter::outputOverflowCSV(SRModel& sr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector>& layer_node_map = sr_model.get_layer_node_map(); for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* overflow_csv_file = RTUTIL.getOutputFileStream( @@ -1813,7 +1822,7 @@ void SpaceRouter::outputOverflowCSV(SRModel& sr_model) } RTUTIL.closeFileStream(overflow_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void SpaceRouter::outputJson(SRModel& sr_model) diff --git a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp index 1b39ac614..666005e61 100644 --- a/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp +++ b/src/operation/iRT/source/module/supply_analyzer/SupplyAnalyzer.cpp @@ -440,6 +440,9 @@ void SupplyAnalyzer::outputPlanarSupplyCSV(SAModel& sa_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::ofstream* supply_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(sa_temp_directory_path, "supply_map_planar.csv")); for (int32_t y = gcell_map.get_y_size() - 1; y >= 0; y--) { for (int32_t x = 0; x < gcell_map.get_x_size(); x++) { @@ -454,7 +457,7 @@ void SupplyAnalyzer::outputPlanarSupplyCSV(SAModel& sa_model) RTUTIL.pushStream(supply_csv_file, "\n"); } RTUTIL.closeFileStream(supply_csv_file); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void SupplyAnalyzer::outputLayerSupplyCSV(SAModel& sa_model) @@ -466,6 +469,9 @@ void SupplyAnalyzer::outputLayerSupplyCSV(SAModel& sa_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + for (RoutingLayer& routing_layer : routing_layer_list) { std::ofstream* supply_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(sa_temp_directory_path, "supply_map_", routing_layer.get_layer_name(), ".csv")); @@ -481,7 +487,7 @@ void SupplyAnalyzer::outputLayerSupplyCSV(SAModel& sa_model) } RTUTIL.closeFileStream(supply_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } #endif diff --git a/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp b/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp index 4fa2b29b1..629f11c2b 100644 --- a/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp +++ b/src/operation/iRT/source/module/topology_generator/TopologyGenerator.cpp @@ -920,6 +920,9 @@ void TopologyGenerator::outputGuide(TGModel& tg_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector& tg_net_list = tg_model.get_tg_net_list(); std::ofstream* guide_file_stream = RTUTIL.getOutputFileStream(RTUTIL.getString(tg_temp_directory_path, "route.guide")); @@ -982,7 +985,7 @@ void TopologyGenerator::outputGuide(TGModel& tg_model) } } RTUTIL.closeFileStream(guide_file_stream); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void TopologyGenerator::outputNetCSV(TGModel& tg_model) @@ -992,6 +995,9 @@ void TopologyGenerator::outputNetCSV(TGModel& tg_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::ofstream* net_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(tg_temp_directory_path, "net_map.csv")); GridMap& tg_node_map = tg_model.get_tg_node_map(); for (int32_t y = tg_node_map.get_y_size() - 1; y >= 0; y--) { @@ -1001,7 +1007,7 @@ void TopologyGenerator::outputNetCSV(TGModel& tg_model) RTUTIL.pushStream(net_csv_file, "\n"); } RTUTIL.closeFileStream(net_csv_file); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void TopologyGenerator::outputOverflowCSV(TGModel& tg_model) @@ -1011,6 +1017,9 @@ void TopologyGenerator::outputOverflowCSV(TGModel& tg_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::ofstream* overflow_csv_file = RTUTIL.getOutputFileStream(RTUTIL.getString(tg_temp_directory_path, "overflow_map.csv")); GridMap& tg_node_map = tg_model.get_tg_node_map(); for (int32_t y = tg_node_map.get_y_size() - 1; y >= 0; y--) { @@ -1020,7 +1029,7 @@ void TopologyGenerator::outputOverflowCSV(TGModel& tg_model) RTUTIL.pushStream(overflow_csv_file, "\n"); } RTUTIL.closeFileStream(overflow_csv_file); - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void TopologyGenerator::outputJson(TGModel& tg_model) diff --git a/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp b/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp index 56639da0c..dd63e3e51 100644 --- a/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp +++ b/src/operation/iRT/source/module/track_assigner/TrackAssigner.cpp @@ -1456,6 +1456,9 @@ void TrackAssigner::outputNetCSV(TAModel& ta_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_net_map; layer_net_map.resize(routing_layer_list.size()); for (GridMap& net_map : layer_net_map) { @@ -1492,7 +1495,7 @@ void TrackAssigner::outputNetCSV(TAModel& ta_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void TrackAssigner::outputViolationCSV(TAModel& ta_model) @@ -1504,6 +1507,9 @@ void TrackAssigner::outputViolationCSV(TAModel& ta_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_violation_map; layer_violation_map.resize(routing_layer_list.size()); for (GridMap& violation_map : layer_violation_map) { @@ -1528,7 +1534,7 @@ void TrackAssigner::outputViolationCSV(TAModel& ta_model) } RTUTIL.closeFileStream(violation_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void TrackAssigner::outputJson(TAModel& ta_model) diff --git a/src/operation/iRT/source/module/violation_reporter/ViolationReporter.cpp b/src/operation/iRT/source/module/violation_reporter/ViolationReporter.cpp index 67d7e09c7..c01ab76b2 100644 --- a/src/operation/iRT/source/module/violation_reporter/ViolationReporter.cpp +++ b/src/operation/iRT/source/module/violation_reporter/ViolationReporter.cpp @@ -429,6 +429,9 @@ void ViolationReporter::outputNetCSV(VRModel& vr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_net_map; layer_net_map.resize(routing_layer_list.size()); for (GridMap& net_map : layer_net_map) { @@ -470,7 +473,7 @@ void ViolationReporter::outputNetCSV(VRModel& vr_model) } RTUTIL.closeFileStream(net_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void ViolationReporter::outputViolationCSV(VRModel& vr_model) @@ -482,6 +485,9 @@ void ViolationReporter::outputViolationCSV(VRModel& vr_model) if (!output_inter_result) { return; } + Monitor monitor; + RTLOG.info(Loc::current(), "Starting..."); + std::vector> layer_violation_map; layer_violation_map.resize(routing_layer_list.size()); for (GridMap& violation_map : layer_violation_map) { @@ -506,7 +512,7 @@ void ViolationReporter::outputViolationCSV(VRModel& vr_model) } RTUTIL.closeFileStream(violation_csv_file); } - RTLOG.info(Loc::current(), "The csv file has been saved"); + RTLOG.info(Loc::current(), "Completed", monitor.getStatsInfo()); } void ViolationReporter::outputJson(VRModel& vr_model) -- Gitee From a3badcac5401afb239944b423158c10bb0ae29bb Mon Sep 17 00:00:00 2001 From: YihangQiu Date: Fri, 10 Oct 2025 16:08:53 +0800 Subject: [PATCH 17/19] fix: paths from early router for evaluating egr_congestion. --- src/evaluation/apps/congestion_app.cpp | 11 +- .../src/module/congestion/congestion_eval.cpp | 113 +++++++++--------- .../src/module/congestion/congestion_eval.h | 4 +- .../src/module/density/density_eval.cpp | 58 +++++---- src/evaluation/src/util/init_egr.cpp | 1 - src/evaluation/src/util/init_idb.cpp | 2 +- src/evaluation/src/util/init_sta.cc | 24 ++-- 7 files changed, 104 insertions(+), 109 deletions(-) diff --git a/src/evaluation/apps/congestion_app.cpp b/src/evaluation/apps/congestion_app.cpp index d2fef3e63..85bf4fa2b 100644 --- a/src/evaluation/apps/congestion_app.cpp +++ b/src/evaluation/apps/congestion_app.cpp @@ -54,7 +54,8 @@ int main(const int argc, const char* argv[]) void TestEgrDataStructure() { - std::string congestion_dir = "/home/yhqiu/net_level_collect/benchmark/large_model_test/rt/rt_temp_directory/early_router"; + // specify the path to the early router output directory + std::string congestion_dir = "./rt/rt_temp_directory/early_router"; ieval::CongestionAPI api; std::map>> egr_map = api.getEGRMap(); @@ -77,6 +78,7 @@ void TestEgrMap() { ieval::CongestionAPI congestion_api; + // specify the path to the early router output directory std::string map_path = "./rt_temp_directory"; std::string stage = "place"; @@ -138,7 +140,8 @@ void TestEgrOverflow() { ieval::CongestionAPI congestion_api; - std::string map_path = "/home/yhqiu/benchmark/AiEDA/application/test/iEDA/rt_temp_directory"; + // specify the path to the early router output directory + std::string map_path = "./rt/rt_temp_directory"; std::string stage = "place"; ieval::OverflowSummary overflow_summary; @@ -159,7 +162,9 @@ void TestRudyUtilization() ieval::CongestionAPI congestion_api; std::string stage = "place"; - std::string map_path = "/home/yhqiu/benchmark/AiEDA/third_party/iEDA/bin"; + // specify the path to the rudy map directory + std::string map_path = "./map/"; + ieval::UtilizationSummary utilization_summary; utilization_summary = congestion_api.rudyUtilization(stage, map_path, false); std::cout << "max utilization horizontal: " << utilization_summary.max_utilization_horizontal << std::endl; diff --git a/src/evaluation/src/module/congestion/congestion_eval.cpp b/src/evaluation/src/module/congestion/congestion_eval.cpp index e7fe8e189..47c36c461 100644 --- a/src/evaluation/src/module/congestion/congestion_eval.cpp +++ b/src/evaluation/src/module/congestion/congestion_eval.cpp @@ -306,7 +306,7 @@ string CongestionEval::evalRUDY(CongestionNets nets, CongestionRegion region, in int32_t overlap_area = 0; if (overlap_lx == overlap_ux) { - overlap_area = overlap_uy - overlap_ly; // 假设线宽为1 + overlap_area = overlap_uy - overlap_ly; // assume wire width is 1 } else if (overlap_ly == overlap_uy) { overlap_area = overlap_ux - overlap_lx; } else { @@ -376,7 +376,7 @@ string CongestionEval::evalLUTRUDY(CongestionNets nets, CongestionRegion region, net_ux = std::max(net_ux, pin.lx); net_uy = std::max(net_uy, pin.ly); } - // 计算引脚数目、纵横比、L-ness + // compute pin count, aspect ratio, L-ness int pin_num = net.pins.size(); int aspect_ratio = 1; if (net_ux - net_lx >= net_uy - net_ly && net_uy - net_ly != 0) { @@ -425,7 +425,7 @@ string CongestionEval::evalLUTRUDY(CongestionNets nets, CongestionRegion region, int32_t overlap_area = 0; if (overlap_lx == overlap_ux) { - overlap_area = overlap_uy - overlap_ly; // 假设线宽为1 + overlap_area = overlap_uy - overlap_ly; // assume wire width is 1 } else if (overlap_ly == overlap_uy) { overlap_area = overlap_ux - overlap_lx; } else { @@ -815,10 +815,6 @@ float CongestionEval::evalAvgUtilization(string stage, string rudy_dir_path, str size_t idx_1_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.01))); size_t idx_2_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.02))); size_t idx_5_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.05))); - // size_t idx_0_5_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.1))); - // size_t idx_1_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.2))); - // size_t idx_2_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.3))); - // size_t idx_5_percent = std::max(size_t(1), static_cast(std::ceil(size * 0.4))); float sum_05 = 0.0f; float sum_1 = 0.0f; @@ -1590,7 +1586,6 @@ std::map>> CongestionEval::getEGRMap(b std::map>> CongestionEval::getDemandSupplyDiffMap(bool is_run_egr) { - // 如果未指定目录,使用默认路径 std::string congestion_dir = dmInst->get_config().get_output_path() + "/rt/rt_temp_directory"; if (is_run_egr == true) { @@ -1599,27 +1594,27 @@ std::map>> CongestionEval::getDemandSu destroyEGR(); } - // 构造early_router和supply_analyzer的完整路径 + // construct demand and supply directory paths std::string demand_dir = congestion_dir + "/early_router"; - std::string supply_dir = congestion_dir + "/supply_analyzer"; + std::string supply_dir = congestion_dir + "/early_router"; printf("demand_dir: %s\nsupply_dir: %s\n", demand_dir.c_str(), supply_dir.c_str()); - // 用于存储最终的差值矩阵 + // store the final diff matrices std::map>> diff_map; - // 临时存储demand和supply矩阵 + // store the read demand and supply matrices std::map>> demand_matrices; std::map>> supply_matrices; - // 读取demand矩阵 + // read demand matrices std::filesystem::path demand_path(demand_dir); for (const auto& entry : std::filesystem::directory_iterator(demand_path)) { std::string filename = entry.path().filename().string(); - if (filename.find("demand_map_") == 0) { - // 提取层名 (AP, M1, M2等) - std::string layer_name = filename.substr(11, filename.length() - 15); + if (filename.find("net_map_") == 0) { + // extract layer name (net_map_ = 8 chars, .csv = 4 chars) + std::string layer_name = filename.substr(8, filename.length() - 8 - 4); - // 读取文件内容 + // read file content std::ifstream file(entry.path()); std::string line; std::vector> matrix; @@ -1632,21 +1627,21 @@ std::map>> CongestionEval::getDemandSu } matrix.push_back(row); } - // 反转行顺序(转换为左下角原点) + // reverse row order (to convert to bottom-left origin) std::reverse(matrix.begin(), matrix.end()); demand_matrices[layer_name] = matrix; } } - // 读取supply矩阵 + // read supply matrices std::filesystem::path supply_path(supply_dir); for (const auto& entry : std::filesystem::directory_iterator(supply_path)) { std::string filename = entry.path().filename().string(); if (filename.find("supply_map_") == 0) { - // 提取层名 (AP, M1, M2等) - std::string layer_name = filename.substr(11, filename.length() - 15); + // extract layer name (supply_map_ = 11 chars, .csv = 4 chars) + std::string layer_name = filename.substr(11, filename.length() - 11 - 4); - // 读取文件内容 + // read file content std::ifstream file(entry.path()); std::string line; std::vector> matrix; @@ -1659,25 +1654,25 @@ std::map>> CongestionEval::getDemandSu } matrix.push_back(row); } - // 反转行顺序(转换为左下角原点) + // reverse row order (to convert to bottom-left origin) std::reverse(matrix.begin(), matrix.end()); supply_matrices[layer_name] = matrix; } } - // 计算差值矩阵 + // calculate demand - supply for each layer for (const auto& [layer_name, demand_matrix] : demand_matrices) { - // 检查该层是否同时存在supply数据 + // check if corresponding supply matrix exists if (supply_matrices.find(layer_name) != supply_matrices.end()) { const auto& supply_matrix = supply_matrices[layer_name]; - // 确保矩阵尺寸相同 + // make sure matrices are of the same size if (demand_matrix.size() == supply_matrix.size() && demand_matrix[0].size() == supply_matrix[0].size()) { std::vector> diff_matrix; for (size_t i = 0; i < demand_matrix.size(); ++i) { std::vector diff_row; for (size_t j = 0; j < demand_matrix[i].size(); ++j) { - // 计算差值 + // calculate demand - supply diff_row.push_back(demand_matrix[i][j] - supply_matrix[i][j]); } diff_matrix.push_back(diff_row); @@ -1696,17 +1691,17 @@ std::map>> CongestionEval::getDemandSu std::map CongestionEval::patchRUDYCongestion(CongestionNets nets, std::map, std::pair>> patch_coords) { - // 预计算线网数据 + // precompute net data for efficiency auto net_metadata = precomputeNetData(nets); - // 预处理:按x坐标排序线网数据 + // presort nets by their lx coordinate for binary search std::sort(net_metadata.begin(), net_metadata.end(), [](const NetMetadata& a, const NetMetadata& b) { return a.lx < b.lx; }); std::map patch_rudy_map; - // 处理每个patch + // process each patch for (const auto& [patch_id, coord] : patch_coords) { const auto& [l_range, u_range] = coord; const int patch_lx = l_range.first, patch_ly = l_range.second; @@ -1715,7 +1710,7 @@ std::map CongestionEval::patchRUDYCongestion(CongestionNets nets, double rudy = 0.0; - // 使用二分查找确定x坐标范围 + // use binary search to find candidate nets that may overlap with the patch auto start_it = std::lower_bound(net_metadata.begin(), net_metadata.end(), patch_lx, [](const NetMetadata& net, int x) { return net.ux < x; @@ -1726,13 +1721,13 @@ std::map CongestionEval::patchRUDYCongestion(CongestionNets nets, return x < net.lx; }); - // 遍历可能重叠的线网 + // tranverse candidate nets and check for overlap for (auto it = start_it; it != end_it; ++it) { const auto& net = *it; - // 检查y坐标是否重叠 + // check vertical overlap if (net.ly <= patch_uy && net.uy >= patch_ly) { - // 计算重叠区域 + // compute overlap area const int overlap_lx = std::max(net.lx, patch_lx); const int overlap_ly = std::max(net.ly, patch_ly); const int overlap_ux = std::min(net.ux, patch_ux); @@ -1741,7 +1736,7 @@ std::map CongestionEval::patchRUDYCongestion(CongestionNets nets, const int overlap_width = overlap_ux - overlap_lx; const int overlap_height = overlap_uy - overlap_ly; if (overlap_width > 0 && overlap_height > 0) { - // 累加RUDY值(使用预计算结果) + // accumulate RUDY contribution rudy += (overlap_width * overlap_height) * (net.hor_rudy + net.ver_rudy) / patch_area; } } @@ -1755,13 +1750,13 @@ std::map CongestionEval::patchEGRCongestion(std::map patch_egr_congestion; - // 获取各层拥塞数据 + // get congestion data for all layers auto congestion_layer_map = getDemandSupplyDiffMap(); if (congestion_layer_map.empty()) { return patch_egr_congestion; } - // 动态获取矩阵尺寸(取第一个有效层的尺寸) + // get matrix dimensions dynamically (take the first valid layer's dimensions) const auto& first_matrix = congestion_layer_map.begin()->second; const size_t matrix_rows = first_matrix.size(); const size_t matrix_cols = matrix_rows > 0 ? first_matrix[0].size() : 0; @@ -1771,7 +1766,7 @@ std::map CongestionEval::patchEGRCongestion(std::map> total_congestion(matrix_rows, std::vector(matrix_cols, 0)); for (const auto& [layer, matrix] : congestion_layer_map) { for (size_t row = 0; row < matrix_rows; ++row) { @@ -1781,31 +1776,31 @@ std::map CongestionEval::patchEGRCongestion(std::map((center_phy_y / max_phy_y) * (matrix_rows - 1)), 0, static_cast(matrix_rows - 1)); const int matrix_col = std::clamp(static_cast((center_phy_x / max_phy_x) * (matrix_cols - 1)), 0, static_cast(matrix_cols - 1)); - // 存储结果 + // store congestion value patch_egr_congestion[patch_id] = total_congestion[matrix_row][matrix_col]; } @@ -1815,16 +1810,16 @@ std::map CongestionEval::patchEGRCongestion(std::map> CongestionEval::patchLayerEGRCongestion( std::map, std::pair>> patch_coords) { - // 返回结构: patch_id -> {layer_name -> congestion_value} + // return : patch_id -> {layer_name -> congestion_value} std::map> patch_layer_congestion; - // 获取各层拥塞数据 + // get congestion data for all layers auto congestion_layer_map = getDemandSupplyDiffMap(false); if (congestion_layer_map.empty()) { return patch_layer_congestion; } - // 动态获取矩阵尺寸(取第一个有效层的尺寸) + // get matrix dimensions dynamically (take the first valid layer's dimensions) const auto& first_matrix = congestion_layer_map.begin()->second; const size_t matrix_rows = first_matrix.size(); const size_t matrix_cols = matrix_rows > 0 ? first_matrix[0].size() : 0; @@ -1834,31 +1829,31 @@ std::map> CongestionEval::patchLayerEGRConges return patch_layer_congestion; } - // 获取物理坐标范围 + // get physical coordinate range int max_phy_x = 0, max_phy_y = 0; for (const auto& [id, coords] : patch_coords) { - max_phy_x = std::max(max_phy_x, coords.second.first); // 物理坐标最大值X - max_phy_y = std::max(max_phy_y, coords.second.second); // 物理坐标最大值Y + max_phy_x = std::max(max_phy_x, coords.second.first); + max_phy_y = std::max(max_phy_y, coords.second.second); } - // 为每个patch的每一层建立映射关系 + // establish mapping for each patch for (const auto& [patch_id, coords] : patch_coords) { const auto& [left_bottom, right_top] = coords; const auto& [phy_x1, phy_y1] = left_bottom; const auto& [phy_x2, phy_y2] = right_top; - // 计算中心点坐标(物理坐标) + // compute center point (physical coordinates) const double center_phy_x = (phy_x1 + phy_x2) / 2.0; const double center_phy_y = (phy_y1 + phy_y2) / 2.0; - // 映射到矩阵行列索引 + // map to matrix row/col indices const int matrix_row = std::clamp(static_cast((center_phy_y / max_phy_y) * (matrix_rows - 1)), 0, static_cast(matrix_rows - 1)); const int matrix_col = std::clamp(static_cast((center_phy_x / max_phy_x) * (matrix_cols - 1)), 0, static_cast(matrix_cols - 1)); - // 为每一层存储拥塞值 + // store congestion values for all layers std::map layer_congestion; for (const auto& [layer_name, congestion_matrix] : congestion_layer_map) { layer_congestion[layer_name] = congestion_matrix[matrix_row][matrix_col]; @@ -1877,7 +1872,7 @@ std::vector CongestionEval::precomputeNetData(const CongestionNets& for (const auto& net : nets) { NetMetadata md; - // 计算边界框 + // compute bounding box md.lx = INT32_MAX; md.ly = INT32_MAX; md.ux = INT32_MIN; @@ -1889,12 +1884,12 @@ std::vector CongestionEval::precomputeNetData(const CongestionNets& md.uy = std::max(md.uy, pin.ly); } - // 安全检查:跳过无效的net坐标 + // skip nets without valid pins if (md.lx == INT32_MAX || md.ly == INT32_MAX || md.ux == INT32_MIN || md.uy == INT32_MIN) { - continue; // 跳过没有有效pin的net + continue; } - // 预计算RUDY因子 + // precompute RUDY factors md.hor_rudy = (md.uy == md.ly) ? 1.0 : 1.0 / (md.uy - md.ly); md.ver_rudy = (md.ux == md.lx) ? 1.0 : 1.0 / (md.ux - md.lx); diff --git a/src/evaluation/src/module/congestion/congestion_eval.h b/src/evaluation/src/module/congestion/congestion_eval.h index e7eeeb6ef..9fcd5b1ec 100644 --- a/src/evaluation/src/module/congestion/congestion_eval.h +++ b/src/evaluation/src/module/congestion/congestion_eval.h @@ -19,8 +19,8 @@ using namespace ::std; struct NetMetadata { - int32_t lx, ly, ux, uy; // 预计算的net边界框 - double hor_rudy, ver_rudy; // 预计算的RUDY因子 + int32_t lx, ly, ux, uy; // precomputed bounding box + double hor_rudy, ver_rudy; // precomputed RUDY factors }; diff --git a/src/evaluation/src/module/density/density_eval.cpp b/src/evaluation/src/module/density/density_eval.cpp index caa2e3c92..652d7a7f6 100644 --- a/src/evaluation/src/module/density/density_eval.cpp +++ b/src/evaluation/src/module/density/density_eval.cpp @@ -551,7 +551,7 @@ std::map DensityEval::patchCellDensity(DensityCells cells, std::map { std::map patch_cell_density; - // 预处理:将单元格按x坐标排序,提升查找性能 + // preprocess: sort cells by x coordinate to improve search efficiency std::vector sorted_cells = cells; std::sort(sorted_cells.begin(), sorted_cells.end(), [](const DensityCell& a, const DensityCell& b) { return a.lx < b.lx; @@ -561,18 +561,18 @@ std::map DensityEval::patchCellDensity(DensityCells cells, std::map double density = 0.0; auto [l_range, u_range] = coord; - // 提取当前 patch 的物理边界 + // extract physical boundaries of the current patch const int patch_lx = l_range.first; const int patch_ly = l_range.second; const int patch_ux = u_range.first; const int patch_uy = u_range.second; - // 计算 patch 面积 + // compute patch area const int patch_width = patch_ux - patch_lx; const int patch_height = patch_uy - patch_ly; const int patch_area = patch_width * patch_height; - // 使用二分查找确定x坐标范围,减少需要检查的单元格数量 + // use binary search to find candidate cells that may overlap with the patch auto lower_it = std::lower_bound(sorted_cells.begin(), sorted_cells.end(), patch_lx, [](const DensityCell& cell, int x) { return cell.lx + cell.width <= x; @@ -582,24 +582,22 @@ std::map DensityEval::patchCellDensity(DensityCells cells, std::map return x < cell.lx; }); - // 只检查x坐标范围内可能重叠的单元格 + // only check cells that may overlap in the x-coordinate range for (auto it = lower_it; it != upper_it; ++it) { const auto& cell = *it; - // 检查y坐标是否重叠 + // check if y-coordinates overlap if (cell.ly + cell.height > patch_ly && cell.ly < patch_uy) { - // 计算重叠面积 + // compute overlap area const int overlap_lx = std::max(cell.lx, patch_lx); const int overlap_ly = std::max(cell.ly, patch_ly); const int overlap_ux = std::min(cell.lx + cell.width, patch_ux); const int overlap_uy = std::min(cell.ly + cell.height, patch_uy); - // 有效重叠面积计算 const int overlap_width = std::max(0, overlap_ux - overlap_lx); const int overlap_height = std::max(0, overlap_uy - overlap_ly); const int overlap_area = overlap_width * overlap_height; - // 累加密度贡献(当且仅当有重叠时) if (overlap_area > 0) { density += static_cast(overlap_area) / patch_area; } @@ -617,7 +615,7 @@ std::map DensityEval::patchPinDensity(DensityPins pins, std::map patch_pin_density; - // 预处理:将引脚按x坐标排序,提升查找性能 + // preprocess: sort pins by x coordinate to improve search efficiency std::vector sorted_pins = pins; std::sort(sorted_pins.begin(), sorted_pins.end(), [](const DensityPin& a, const DensityPin& b) { return a.lx < b.lx; @@ -632,7 +630,7 @@ std::map DensityEval::patchPinDensity(DensityPins pins, std::map DensityEval::patchPinDensity(DensityPins pins, std::map= patch_ly && pin.ly <= patch_uy) { ++pin_count; } @@ -667,7 +665,7 @@ std::map DensityEval::patchNetDensity(DensityNets nets, std::map sorted_nets = nets; std::sort(sorted_nets.begin(), sorted_nets.end(), [](const DensityNet& a, const DensityNet& b) { return a.lx < b.lx; @@ -677,13 +675,13 @@ std::map DensityEval::patchNetDensity(DensityNets nets, std::map DensityEval::patchNetDensity(DensityNets nets, std::map DensityEval::patchNetDensity(DensityNets nets, std::map DensityEval::patchNetDensity(DensityNets nets, std::map patch_ly && net.ly < patch_uy) { - // 计算重叠面积 + // compute overlap area const int overlap_lx = std::max(net.lx, patch_lx); const int overlap_ly = std::max(net.ly, patch_ly); const int overlap_ux = std::min(net.ux, patch_ux); const int overlap_uy = std::min(net.uy, patch_uy); - // 有效重叠面积计算 const int overlap_width = std::max(0, overlap_ux - overlap_lx); const int overlap_height = std::max(0, overlap_uy - overlap_ly); const int overlap_area = overlap_width * overlap_height; - // 累加密度贡献(当且仅当有重叠时) if (overlap_area > 0) { density += static_cast(overlap_area) / patch_area; } @@ -748,7 +744,7 @@ std::map DensityEval::patchMacroMargin(DensityCells cells, DensityRegi } } - // 预处理:将宏按x坐标排序,提升查找性能 + // preprocess: sort macros by x coordinate to improve search efficiency std::sort(macros.begin(), macros.end(), [](const DensityCell& a, const DensityCell& b) { return a.lx < b.lx; }); @@ -756,19 +752,19 @@ std::map DensityEval::patchMacroMargin(DensityCells cells, DensityRegi for (const auto& [patch_id, coord] : patch_coords) { auto [l_range, u_range] = coord; - // 提取当前 patch 的物理边界 + // extract physical boundaries of the current patch const int patch_lx = l_range.first; const int patch_ly = l_range.second; const int patch_ux = u_range.first; const int patch_uy = u_range.second; - // 计算核心区域的边界 + // compute core area boundaries int32_t h_right = core.ux; int32_t h_left = core.lx; int32_t v_up = core.uy; int32_t v_down = core.ly; if (patch_ux <= h_left || patch_lx >= h_right || patch_uy <= v_down || patch_ly >= v_up) { - patch_macro_margin[patch_id] = 0; // 确保所有情况都有赋值 + patch_macro_margin[patch_id] = 0; // make sure margin is zero if patch is outside core continue; } @@ -780,7 +776,7 @@ std::map DensityEval::patchMacroMargin(DensityCells cells, DensityRegi int overlap_area = 0; int margin = 0; - // 使用二分查找确定x坐标范围,减少需要检查的宏数量 + // use binary search to find candidate macros that may overlap with the patch auto lower_it = std::lower_bound(macros.begin(), macros.end(), patch_lx, [](const DensityCell& macro, int x) { return macro.lx + macro.width <= x; @@ -790,11 +786,11 @@ std::map DensityEval::patchMacroMargin(DensityCells cells, DensityRegi return x < macro.lx; }); - // 只检查x坐标范围内可能重叠的宏 + // only check macros that may overlap in the x-coordinate range for (auto it = lower_it; it != upper_it; ++it) { const auto& macro = *it; - // 检查y坐标是否重叠 + // check if y-coordinates overlap if (macro.ly + macro.height > patch_ly && macro.ly < patch_uy) { int32_t rect_lx = std::max(patch_lx, macro.lx); int32_t rect_ly = std::max(patch_ly, macro.ly); @@ -812,11 +808,11 @@ std::map DensityEval::patchMacroMargin(DensityCells cells, DensityRegi } if (!overlap) { - // 再次使用相同的范围进行margin计算 + // use the same range again for margin calculation for (auto it = lower_it; it != upper_it; ++it) { const auto& macro = *it; - // 检查y坐标是否重叠 + // check if y-coordinates overlap if (macro.ly + macro.height > patch_ly && macro.ly < patch_uy) { int32_t macro_middle_x = macro.lx + macro.width * 0.5; int32_t macro_middle_y = macro.ly + macro.height * 0.5; diff --git a/src/evaluation/src/util/init_egr.cpp b/src/evaluation/src/util/init_egr.cpp index b1dfa6ece..2a3c3d4c7 100644 --- a/src/evaluation/src/util/init_egr.cpp +++ b/src/evaluation/src/util/init_egr.cpp @@ -57,7 +57,6 @@ void InitEGR::runEGR(bool enable_timing) auto clock_layer_name = routing_layers.size() >= 4 ? routing_layers[routing_layers.size() - 4]->get_name() : logic_layer_name; std::map config_map; config_map.insert({"-temp_directory_path", _egr_dir_path}); - config_map.insert({"-output_inter_result", 1}); config_map.insert({"-bottom_routing_layer", logic_layer_name}); // only for 28nm config_map.insert({"-top_routing_layer", clock_layer_name}); // only for 28nm if (enable_timing == true) { diff --git a/src/evaluation/src/util/init_idb.cpp b/src/evaluation/src/util/init_idb.cpp index 77360afc8..98515e7a4 100644 --- a/src/evaluation/src/util/init_idb.cpp +++ b/src/evaluation/src/util/init_idb.cpp @@ -231,7 +231,7 @@ void InitIDB::initDensityDBNets() max_uy = std::max(max_uy, idb_load_pin->get_average_coordinate()->get_y()); } - // 安全检查:如果net没有任何pin或坐标无效,跳过此net + // if net has no pins or invalid coordinates, skip this net if (min_lx == INT32_MAX || min_ly == INT32_MAX || max_ux == INT32_MIN || max_uy == INT32_MIN || min_lx > max_ux || min_ly > max_uy) { diff --git a/src/evaluation/src/util/init_sta.cc b/src/evaluation/src/util/init_sta.cc index 71d5add4c..b0156697f 100644 --- a/src/evaluation/src/util/init_sta.cc +++ b/src/evaluation/src/util/init_sta.cc @@ -1766,7 +1766,7 @@ std::map InitSTA::patchTimingMap(std::mapgetIDBAdapter(); auto dbu = idb_adapter->get_dbu(); - // 预处理:将实例坐标转换并按x坐标排序,提升查找性能 + // preprocess: convert instance coordinates and sort by x coordinate to improve search performance std::vector> sorted_instances; sorted_instances.reserve(inst_timing_map.size()); @@ -1776,7 +1776,7 @@ std::map InitSTA::patchTimingMap(std::map InitSTA::patchTimingMap(std::map::max(); bool found_instance = false; - // 使用二分查找确定x坐标范围,减少需要检查的实例数量 + // use binary search to determine the x coordinate range, reducing the number of instances to check auto lower_it = std::lower_bound(sorted_instances.begin(), sorted_instances.end(), std::make_tuple(patch_lx, INT64_MIN, 0.0)); auto upper_it = std::upper_bound(sorted_instances.begin(), sorted_instances.end(), std::make_tuple(patch_ux, INT64_MAX, 0.0)); - // 只检查x坐标在范围内的实例 + // only check instances with x coordinates within the range for (auto it = lower_it; it != upper_it; ++it) { int64_t inst_y = std::get<1>(*it); double slack = std::get<2>(*it); @@ -1832,7 +1832,7 @@ std::map InitSTA::patchPowerMap(std::mapgetIDBAdapter(); auto dbu = idb_adapter->get_dbu(); - // 预处理:将实例坐标转换并按x坐标排序,提升查找性能 + // preprocess: convert instance coordinates and sort by x coordinate to improve search performance std::vector> sorted_instances; sorted_instances.reserve(inst_power_map.size()); @@ -1842,7 +1842,7 @@ std::map InitSTA::patchPowerMap(std::map InitSTA::patchPowerMap(std::map(*it); double power = std::get<2>(*it); @@ -1900,7 +1900,7 @@ std::map InitSTA::patchIRDropMap(std::mapgetIDBAdapter(); auto dbu = idb_adapter->get_dbu(); - // 预处理:将实例坐标转换并按x坐标排序,提升查找性能 + // preprocess: convert instance coordinates and sort by x coordinate to improve search performance std::vector> sorted_instances; sorted_instances.reserve(instance_to_ir_drop.size()); @@ -1911,7 +1911,7 @@ std::map InitSTA::patchIRDropMap(std::map InitSTA::patchIRDropMap(std::map(*it); double ir_drop = std::get<2>(*it); -- Gitee From a92b1ca7369f2baaee192f2200f3394dceabb8f5 Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Fri, 10 Oct 2025 17:32:49 +0800 Subject: [PATCH 18/19] fix bug --- src/operation/iNO/source/iNO.cpp | 1 + .../source/module/fix_fanout/FixFanout.cpp | 65 ++++++++++++++++++- .../iNO/source/module/fix_fanout/FixFanout.h | 1 + 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/operation/iNO/source/iNO.cpp b/src/operation/iNO/source/iNO.cpp index 990780bf2..cbeb60e9d 100644 --- a/src/operation/iNO/source/iNO.cpp +++ b/src/operation/iNO/source/iNO.cpp @@ -55,6 +55,7 @@ void iNO::fixFanout() { cout << R"( )" << endl; cout << "\033[0m" << endl; ino::FixFanout *fix_fanout = new FixFanout(_db_interface); + fix_fanout->fixIO(); fix_fanout->fixFanout(); delete fix_fanout; } diff --git a/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp b/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp index f10478556..397828d5f 100644 --- a/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp +++ b/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp @@ -29,6 +29,65 @@ FixFanout::FixFanout(ino::DbInterface *db_interface) : _db_interface(db_interfac _max_fanout = _db_interface->get_max_fanout(); } +/** + * 临时修复io问题,此函数有问题可联系zzs + */ +void FixFanout::fixIO() { + idb::IdbNetList *idb_net_list = _idb->get_def_service()->get_design()->get_net_list(); + idb::IdbInstanceList *idb_instance_list = + _idb->get_def_service()->get_design()->get_instance_list(); + idb::IdbCellMasterList *idb_cell_master_list = + _idb->get_def_service()->get_layout()->get_cell_master_list(); + idb::IdbPins *idb_io_pin_list = + _idb->get_def_service()->get_design()->get_io_pin_list(); + std::string buffer_name = _db_interface->get_insert_buffer(); + size_t new_idx = 0; + + for (idb::IdbPin *idb_io_pin : idb_io_pin_list->get_pin_list()) { + if (idb_io_pin->get_net() == nullptr) { + continue; + } + if (idb_io_pin->get_pin_name() == idb_io_pin->get_net()->get_net_name()) { + continue; + } + // 在当前net中解开io pin + idb::IdbNet *origin_net = idb_io_pin->get_net(); + if (origin_net == nullptr) { + std::cout << "curr_net is empty !!!" << std::endl; + } + origin_net->remove_pin(idb_io_pin); + // 加入原来的io net + idb::IdbNet *io_net = idb_net_list->find_net(idb_io_pin->get_pin_name()); + if (io_net == nullptr) { + std::cout << "io_net is empty !!!" << std::endl; + } + idb_io_pin->set_net(io_net); + idb_io_pin->set_net_name(io_net->get_net_name()); + // 生成buf + idb::IdbInstance *new_buf = new IdbInstance(); + new_buf->set_name("zzs_buf_" + std::to_string(new_idx++)); + new_buf->set_cell_master(idb_cell_master_list->find_cell_master(buffer_name)); + idb_instance_list->add_instance(new_buf); + // 插入buf + for (idb::IdbPin *buf_pin : new_buf->get_pin_list()->get_pin_list()) { + if (buf_pin->get_term()->get_type() == idb::IdbConnectType::kPower || + buf_pin->get_term()->get_type() == idb::IdbConnectType::kGround) { + continue; + } + if (buf_pin->get_term()->get_direction() == idb::IdbConnectDirection::kInput) { + origin_net->add_instance_pin(buf_pin); + buf_pin->set_net(origin_net); + buf_pin->set_net_name(origin_net->get_net_name()); + } else if (buf_pin->get_term()->get_direction() == + idb::IdbConnectDirection::kOutput) { + io_net->add_instance_pin(buf_pin); + buf_pin->set_net(io_net); + buf_pin->set_net_name(io_net->get_net_name()); + } + } + } +} + void FixFanout::fixFanout() { _db_interface->set_eval_data(); _idb_layout = _idb->get_lef_service()->get_layout(); @@ -64,11 +123,11 @@ void FixFanout::fixFanout() { } void FixFanout::fixFanout(IdbNet *net) { - int fanout = net->get_load_pins().size(); + int fanout = net->get_load_pins().size(); bool have_switch_name = false; while (fanout > _max_fanout) { auto load_pins = net->get_load_pins(); - bool connect_to_port = false; // if net connect to a port need rename for the net + bool connect_to_port = false; // if net connect to a port need rename for the net for (auto pin : load_pins) { if (pin->is_io_pin()) { connect_to_port = true; @@ -155,7 +214,7 @@ void FixFanout::disconnectPin(IdbPin *dpin, IdbNet *dnet) { } void FixFanout::connect(IdbInstance *dinst, IdbPin *dpin, IdbNet *dnet) { - if(dinst) { + if (dinst) { auto &dpin_list = dinst->get_pin_list()->get_pin_list(); string port_name = dpin->get_pin_name(); for (auto dpin : dpin_list) { diff --git a/src/operation/iNO/source/module/fix_fanout/FixFanout.h b/src/operation/iNO/source/module/fix_fanout/FixFanout.h index 5d8ce9a48..cf008e1a9 100644 --- a/src/operation/iNO/source/module/fix_fanout/FixFanout.h +++ b/src/operation/iNO/source/module/fix_fanout/FixFanout.h @@ -35,6 +35,7 @@ class FixFanout { FixFanout(ino::DbInterface *db_interface); ~FixFanout() = default; + void fixIO(); void fixFanout(); private: -- Gitee From 02eead36c336c3035a4da889387de22e79e4c8a7 Mon Sep 17 00:00:00 2001 From: ZhishengZeng Date: Sat, 11 Oct 2025 11:49:55 +0800 Subject: [PATCH 19/19] fix bug --- src/operation/iNO/source/module/fix_fanout/FixFanout.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp b/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp index 397828d5f..7e0b072ab 100644 --- a/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp +++ b/src/operation/iNO/source/module/fix_fanout/FixFanout.cpp @@ -59,7 +59,9 @@ void FixFanout::fixIO() { // 加入原来的io net idb::IdbNet *io_net = idb_net_list->find_net(idb_io_pin->get_pin_name()); if (io_net == nullptr) { - std::cout << "io_net is empty !!!" << std::endl; + io_net = new IdbNet(); + io_net->set_net_name(idb_io_pin->get_pin_name()); + idb_net_list->add_net(io_net); } idb_io_pin->set_net(io_net); idb_io_pin->set_net_name(io_net->get_net_name()); -- Gitee