diff --git a/src/drt/CMakeLists.txt b/src/drt/CMakeLists.txt index e377ba29186..0ae04d5437c 100644 --- a/src/drt/CMakeLists.txt +++ b/src/drt/CMakeLists.txt @@ -143,12 +143,11 @@ target_include_directories(drt_lib target_link_libraries(drt_lib PUBLIC - odb - stt + stt_lib OpenSTA utl_lib dst - dbSta + dbSta_lib Threads::Threads OpenMP::OpenMP_CXX ${Boost_LIBRARIES} diff --git a/src/drt/include/triton_route/TritonRoute.h b/src/drt/include/triton_route/TritonRoute.h index 31330b6dd79..08bf7e6ec26 100644 --- a/src/drt/include/triton_route/TritonRoute.h +++ b/src/drt/include/triton_route/TritonRoute.h @@ -28,8 +28,6 @@ #pragma once -#include - #include #include #include @@ -52,10 +50,6 @@ namespace utl { class Logger; } -namespace gui { -class Gui; -} - namespace stt { class SteinerTreeBuilder; } @@ -102,6 +96,7 @@ struct ParamStruct int minAccessPoints = -1; bool saveGuideUpdates = false; std::string repairPDNLayerName; + int num_threads; }; class TritonRoute @@ -177,15 +172,15 @@ class TritonRoute void updateGlobals(const char* file_name); void resetDb(const char* file_name); void clearDesign(); - void updateDesign(const std::vector& updates); - void updateDesign(const std::string& path); + void updateDesign(const std::vector& updates, int num_threads); + void updateDesign(const std::string& path, int num_threads); void addWorkerResults( const std::vector>& results); bool getWorkerResults(std::vector>& results); int getWorkerResultsSize(); void sendDesignDist(); bool writeGlobals(const std::string& name); - void sendDesignUpdates(const std::string& router_cfg_path); + void sendDesignUpdates(const std::string& router_cfg_path, int num_threads); void sendGlobalsUpdates(const std::string& router_cfg_path, const std::string& serializedViaData); void reportDRC(const std::string& file_name, @@ -197,11 +192,12 @@ class TritonRoute int y1, int x2, int y2, - const std::string& marker_name); + const std::string& marker_name, + int num_threads); bool initGuide(); void prep(); odb::dbDatabase* getDb() const { return db_; } - void fixMaxSpacing(); + void fixMaxSpacing(int num_threads); private: std::unique_ptr design_; @@ -213,7 +209,6 @@ class TritonRoute std::unique_ptr dr_; // kept for single stepping stt::SteinerTreeBuilder* stt_builder_{nullptr}; int num_drvs_{-1}; - gui::Gui* gui_{nullptr}; dst::Distributed* dist_{nullptr}; bool distributed_{false}; std::string dist_ip_; diff --git a/src/drt/src/GraphicsFactory.h b/src/drt/src/GraphicsFactory.h index 5838684220d..1e1acddd696 100644 --- a/src/drt/src/GraphicsFactory.h +++ b/src/drt/src/GraphicsFactory.h @@ -48,7 +48,7 @@ class GraphicsFactory : public AbstractGraphicsFactory { public: GraphicsFactory(); - ~GraphicsFactory(); + ~GraphicsFactory() override; void reset(frDebugSettings* settings, frDesign* design, odb::dbDatabase* db, diff --git a/src/drt/src/TritonRoute.cpp b/src/drt/src/TritonRoute.cpp index d28f3eb40a7..252ce1f3d7e 100644 --- a/src/drt/src/TritonRoute.cpp +++ b/src/drt/src/TritonRoute.cpp @@ -48,11 +48,9 @@ #include "gc/FlexGC.h" #include "global.h" #include "gr/FlexGR.h" -#include "gui/gui.h" #include "io/GuideProcessor.h" #include "io/io.h" #include "odb/dbShape.h" -#include "ord/OpenRoad.hh" #include "pa/AbstractPAGraphics.h" #include "pa/FlexPA.h" #include "rp/FlexRP.h" @@ -61,14 +59,14 @@ #include "stt/SteinerTreeBuilder.h" #include "ta/AbstractTAGraphics.h" #include "ta/FlexTA.h" +#include "utl/ScopedTemporaryFile.h" namespace drt { TritonRoute::TritonRoute() : debug_(std::make_unique()), db_callback_(std::make_unique(this)), - router_cfg_(std::make_unique()), - gui_(gui::Gui::get()) + router_cfg_(std::make_unique()) { if (distributed_) { dist_pool_.emplace(1); @@ -306,8 +304,25 @@ void TritonRoute::updateGlobals(const char* file_name) void TritonRoute::resetDb(const char* file_name) { + std::ifstream stream; + stream.open(file_name, std::ios::binary); + try { + if (db_->getChip() && db_->getChip()->getBlock()) { + logger_->error( + DRT, + 9947, + "You can't load a new db file as the db is already populated"); + } + + stream.exceptions(std::ifstream::failbit | std::ifstream::badbit + | std::ios::eofbit); + + db_->read(stream); + } catch (const std::ios_base::failure& f) { + logger_->error( + DRT, 9954, "odb file {} is invalid: {}", file_name, f.what()); + } design_ = std::make_unique(logger_, router_cfg_.get()); - ord::OpenRoad::openRoad()->readDb(file_name); initDesign(); if (!db_->getChip()->getBlock()->getAccessPoints().empty()) { initGuide(); @@ -345,9 +360,10 @@ static void deserializeUpdates(frDesign* design, file.close(); } -void TritonRoute::updateDesign(const std::vector& updatesStrs) +void TritonRoute::updateDesign(const std::vector& updatesStrs, + int num_threads) { - omp_set_num_threads(ord::OpenRoad::openRoad()->getThreadCount()); + omp_set_num_threads(num_threads); std::vector> updates(updatesStrs.size()); #pragma omp parallel for schedule(dynamic) for (int i = 0; i < updatesStrs.size(); i++) { @@ -356,9 +372,9 @@ void TritonRoute::updateDesign(const std::vector& updatesStrs) applyUpdates(updates); } -void TritonRoute::updateDesign(const std::string& path) +void TritonRoute::updateDesign(const std::string& path, int num_threads) { - omp_set_num_threads(ord::OpenRoad::openRoad()->getThreadCount()); + omp_set_num_threads(num_threads); std::vector> updates; deserializeUpdates(design_.get(), path, updates); applyUpdates(updates); @@ -830,7 +846,8 @@ void TritonRoute::sendDesignDist() std::string design_path = fmt::format("{}DESIGN.db", shared_volume_); std::string router_cfg_path = fmt::format("{}DESIGN.router_cfg", shared_volume_); - ord::OpenRoad::openRoad()->writeDb(design_path.c_str()); + + db_->write(utl::StreamHandler(design_path.c_str(), true).getStream()); writeGlobals(router_cfg_path); dst::JobMessage msg(dst::JobMessage::UPDATE_DESIGN, dst::JobMessage::BROADCAST), @@ -884,7 +901,8 @@ void TritonRoute::sendGlobalsUpdates(const std::string& router_cfg_path, } } -void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path) +void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path, + int num_threads) { if (!distributed_) { return; @@ -899,7 +917,7 @@ void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path) serializeTask = std::make_unique("DIST: SERIALIZE_UPDATES"); } const auto& designUpdates = design_->getUpdates(); - omp_set_num_threads(router_cfg_->MAX_THREADS); + omp_set_num_threads(num_threads); std::vector updates(designUpdates.size()); #pragma omp parallel for schedule(dynamic) for (int i = 0; i < designUpdates.size(); i++) { @@ -947,7 +965,6 @@ int TritonRoute::main() = fmt::format("{}/init_router_cfg.bin", debug_->dumpDir); writeGlobals(router_cfg_path); } - router_cfg_->MAX_THREADS = ord::OpenRoad::openRoad()->getThreadCount(); if (distributed_) { if (router_cfg_->DO_PA) { asio::post(pa_pool, [this]() { @@ -1003,8 +1020,9 @@ int TritonRoute::main() } } if (debug_->debugDumpDR) { - ord::OpenRoad::openRoad()->writeDb( - fmt::format("{}/design.odb", debug_->dumpDir).c_str()); + db_->write(utl::StreamHandler( + fmt::format("{}/design.odb", debug_->dumpDir).c_str(), true) + .getStream()); } if (!initGuide()) { gr(); @@ -1018,7 +1036,7 @@ int TritonRoute::main() ta(); if (distributed_) { asio::post(*dist_pool_, - boost::bind(&TritonRoute::sendDesignUpdates, this, "")); + [this] { sendDesignUpdates("", router_cfg_->MAX_THREADS); }); } dr(); if (!router_cfg_->SINGLE_STEP_DR) { @@ -1042,7 +1060,6 @@ void TritonRoute::pinAccess(const std::vector& target_insts) }); } clearDesign(); - router_cfg_->MAX_THREADS = ord::OpenRoad::openRoad()->getThreadCount(); router_cfg_->ENABLE_VIA_GEN = true; initDesign(); FlexPA pa(getDesign(), logger_, dist_, router_cfg_.get()); @@ -1059,11 +1076,12 @@ void TritonRoute::pinAccess(const std::vector& target_insts) writer.updateDb(db_, router_cfg_.get(), true); } -void TritonRoute::fixMaxSpacing() +void TritonRoute::fixMaxSpacing(int num_threads) { initDesign(); initGuide(); prep(); + router_cfg_->MAX_THREADS = num_threads; dr_ = std::make_unique( this, getDesign(), logger_, db_, router_cfg_.get()); dr_->init(); @@ -1075,7 +1093,6 @@ void TritonRoute::fixMaxSpacing() void TritonRoute::getDRCMarkers(frList>& markers, const Rect& requiredDrcBox) { - router_cfg_->MAX_THREADS = ord::OpenRoad::openRoad()->getThreadCount(); std::vector>> workersBatches(1); auto size = 7; auto offset = 0; @@ -1143,10 +1160,12 @@ void TritonRoute::checkDRC(const char* filename, int y1, int x2, int y2, - const std::string& marker_name) + const std::string& marker_name, + int num_threads) { router_cfg_->GC_IGNORE_PDN_LAYER_NUM = -1; router_cfg_->REPAIR_PDN_LAYER_NUM = -1; + router_cfg_->MAX_THREADS = num_threads; initDesign(); auto gcellGrid = db_->getChip()->getBlock()->getGCellGrid(); if (gcellGrid != nullptr && gcellGrid->getNumGridPatternsX() == 1 @@ -1238,6 +1257,7 @@ void TritonRoute::setParams(const ParamStruct& params) } router_cfg_->SAVE_GUIDE_UPDATES = params.saveGuideUpdates; router_cfg_->REPAIR_PDN_LAYER_NAME = params.repairPDNLayerName; + router_cfg_->MAX_THREADS = params.num_threads; } void TritonRoute::addWorkerResults( diff --git a/src/drt/src/TritonRoute.i b/src/drt/src/TritonRoute.i index 6adab877379..e9436aa3e1c 100644 --- a/src/drt/src/TritonRoute.i +++ b/src/drt/src/TritonRoute.i @@ -100,6 +100,7 @@ void detailed_route_cmd(const char* outputMazeFile, int drcReportIterStep) { auto* router = ord::OpenRoad::openRoad()->getTritonRoute(); + const int num_threads = ord::OpenRoad::openRoad()->getThreadCount(); std::optional drcReportIterStepOpt; if (drcReportIterStep > 0) { drcReportIterStepOpt = drcReportIterStep; @@ -124,7 +125,8 @@ void detailed_route_cmd(const char* outputMazeFile, singleStepDR, minAccessPoints, saveGuideUpdates, - repairPDNLayerName}); + repairPDNLayerName, + num_threads}); router->main(); router->setDistributed(false); } @@ -142,6 +144,7 @@ void pin_access_cmd(const char* dbProcessNode, params.topRoutingLayer = topRoutingLayer; params.verbose = verbose; params.minAccessPoints = minAccessPoints; + params.num_threads = ord::OpenRoad::openRoad()->getThreadCount(); router->setParams(params); router->pinAccess(); router->setDistributed(false); @@ -207,7 +210,8 @@ run_worker_cmd(const char* dump_dir, const char* worker_dir, const char* drc_rpt auto* router = ord::OpenRoad::openRoad()->getTritonRoute(); router->updateGlobals(fmt::format("{}/init_router_cfg.bin", dump_dir).c_str()); router->resetDb(fmt::format("{}/design.odb", dump_dir).c_str()); - router->updateDesign(fmt::format("{}/{}/updates.bin", dump_dir, worker_dir).c_str()); + const int num_threads = ord::OpenRoad::openRoad()->getThreadCount(); + router->updateDesign(fmt::format("{}/{}/updates.bin", dump_dir, worker_dir).c_str(), num_threads); router->updateGlobals(fmt::format("{}/{}/worker_router_cfg.bin", dump_dir, worker_dir).c_str()); router->debugSingleWorker(fmt::format("{}/{}", dump_dir, worker_dir), drc_rpt); @@ -231,7 +235,8 @@ void detailed_route_step_drt(int size, void fix_max_spacing_cmd() { auto* router = ord::OpenRoad::openRoad()->getTritonRoute(); - router->fixMaxSpacing(); + const int num_threads = ord::OpenRoad::openRoad()->getThreadCount(); + router->fixMaxSpacing(num_threads); } void step_end() { @@ -242,6 +247,7 @@ void step_end() void check_drc_cmd(const char* drc_file, int x1, int y1, int x2, int y2, const char* marker_name) { auto* router = ord::OpenRoad::openRoad()->getTritonRoute(); - router->checkDRC(drc_file, x1, y1, x2, y2, marker_name); + const int num_threads = ord::OpenRoad::openRoad()->getThreadCount(); + router->checkDRC(drc_file, x1, y1, x2, y2, marker_name, num_threads); } %} // inline diff --git a/src/drt/src/distributed/RoutingCallBack.h b/src/drt/src/distributed/RoutingCallBack.h index 945949d4777..7b16f1baff0 100644 --- a/src/drt/src/distributed/RoutingCallBack.h +++ b/src/drt/src/distributed/RoutingCallBack.h @@ -46,7 +46,6 @@ #include "dst/JobCallBack.h" #include "dst/JobMessage.h" #include "global.h" -#include "ord/OpenRoad.hh" #include "pa/FlexPA.h" #include "triton_route/TritonRoute.h" #include "utl/Logger.h" @@ -82,7 +81,7 @@ class RoutingCallBack : public dst::JobCallBack = static_cast(msg.getJobDescription()); if (init_) { init_ = false; - omp_set_num_threads(ord::OpenRoad::openRoad()->getThreadCount()); + omp_set_num_threads(router_->getRouterConfiguration()->MAX_THREADS); } auto workers = desc->getWorkers(); int size = workers.size(); @@ -138,7 +137,8 @@ class RoutingCallBack : public dst::JobCallBack frTime t; logger_->report("Design Update"); if (desc->isDesignUpdate()) { - router_->updateDesign(desc->getUpdates()); + router_->updateDesign(desc->getUpdates(), + router_->getRouterConfiguration()->MAX_THREADS); } else { router_->resetDb(desc->getDesignPath().c_str()); } @@ -188,7 +188,7 @@ class RoutingCallBack : public dst::JobCallBack break; case PinAccessJobDescription::INST_ROWS: { auto instRows = deserializeInstRows(desc->getPath()); - omp_set_num_threads(ord::OpenRoad::openRoad()->getThreadCount()); + omp_set_num_threads(router_->getRouterConfiguration()->MAX_THREADS); #pragma omp parallel for schedule(dynamic) for (int i = 0; i < instRows.size(); i++) { // NOLINT pa_.genInstRowPattern(instRows.at(i)); diff --git a/src/drt/src/dr/FlexDR.cpp b/src/drt/src/dr/FlexDR.cpp index ffe9a884865..2f8eb3a6fe0 100644 --- a/src/drt/src/dr/FlexDR.cpp +++ b/src/drt/src/dr/FlexDR.cpp @@ -52,8 +52,8 @@ #include "frProfileTask.h" #include "gc/FlexGC.h" #include "io/io.h" -#include "ord/OpenRoad.hh" #include "serialization.h" +#include "utl/ScopedTemporaryFile.h" #include "utl/exception.h" BOOST_CLASS_EXPORT(drt::RoutingJobDescription) @@ -740,7 +740,7 @@ void FlexDR::processWorkersBatchDistributed( serializeViaData(via_data_, serializedViaData); router_->sendGlobalsUpdates(router_cfg_path_, serializedViaData); } else { - router_->sendDesignUpdates(router_cfg_path_); + router_->sendDesignUpdates(router_cfg_path_, router_cfg_->MAX_THREADS); } ProfileTask task("DIST: PROCESS_BATCH"); @@ -1782,7 +1782,7 @@ std::vector FlexDR::getLonelyVias(frLayer* layer, std::vector visited(via_positions.size()); std::fill(visited.begin(), visited.end(), false); std::set isolated_via_nodes; - omp_set_num_threads(ord::OpenRoad::openRoad()->getThreadCount()); + omp_set_num_threads(router_cfg_->MAX_THREADS); #pragma omp parallel for schedule(dynamic) for (int i = 0; i < via_positions.size(); i++) { if (visited[i].load()) { @@ -1875,8 +1875,10 @@ int FlexDR::main() if (logger_->debugCheck(DRT, "snapshot", 1)) { io::Writer writer(getDesign(), logger_); writer.updateDb(db_, router_cfg_, false, true); - ord::OpenRoad::openRoad()->writeDb( - fmt::format("drt_iter{}.odb", iter_).c_str()); + + db_->write( + utl::StreamHandler(fmt::format("drt_iter{}.odb", iter_).c_str(), true) + .getStream()); } ++iter_; } diff --git a/src/drt/src/dr/FlexDR_graphics.cpp b/src/drt/src/dr/FlexDR_graphics.cpp index 775e30e7be6..88b3d934ffb 100644 --- a/src/drt/src/dr/FlexDR_graphics.cpp +++ b/src/drt/src/dr/FlexDR_graphics.cpp @@ -35,7 +35,6 @@ #include "../gc/FlexGC.h" #include "FlexDR.h" -#include "ord/OpenRoad.hh" namespace drt { diff --git a/src/drt/test/drt_aux.py b/src/drt/test/drt_aux.py index e140654feb8..8d69dfd3590 100644 --- a/src/drt/test/drt_aux.py +++ b/src/drt/test/drt_aux.py @@ -54,6 +54,7 @@ def detailed_route( params.singleStepDR = single_step_dr params.minAccessPoints = min_access_points params.saveGuideUpdates = save_guide_updates + params.num_threads = 1 router.setParams(params) router.main() diff --git a/src/grt/CMakeLists.txt b/src/grt/CMakeLists.txt index bac726fef56..12aca84a1f2 100644 --- a/src/grt/CMakeLists.txt +++ b/src/grt/CMakeLists.txt @@ -96,6 +96,7 @@ target_include_directories(grt target_link_libraries(grt grt_lib utl_lib + drt_lib FastRoute4.1 ant_lib dpl_lib @@ -126,6 +127,7 @@ if (Python3_FOUND AND BUILD_PYTHON) PUBLIC utl_lib FastRoute4.1 + drt_lib ant_lib dpl_lib dbSta