Skip to content

Commit a7d2d17

Browse files
committed
Centralize the setting of omp_num_threads
Use the value from -threads to set the number of threads once for the application instead of having it distributed throughout (e.g. ant, gpl, grt, drt). Signed-off-by: Matt Liberty <[email protected]>
1 parent 795facf commit a7d2d17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+119
-195
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ cc_library(
191191
"//src/sta:opensta_lib",
192192
"@boost.stacktrace",
193193
"@tk_tcl//:tcl",
194+
"@openmp",
194195
] + OPENROAD_LIBRARY_DEPS,
195196
)
196197

src/OpenRoad.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <thread>
1414
#include <vector>
1515

16+
#include "omp.h"
1617
#include "ord/Version.hh"
1718
#include "tcl.h"
1819
#ifdef ENABLE_PYTHON3
@@ -631,6 +632,17 @@ void OpenRoad::setThreadCount(int threads, bool print_info)
631632

632633
// place limits on tools with threads
633634
sta_->setThreadCount(threads_);
635+
636+
// Just to verify that OMP support is compiled in correctly.
637+
omp_set_num_threads(2);
638+
#pragma omp parallel
639+
{
640+
if (omp_get_num_threads() != 2) {
641+
logger_->error(ORD, 103, "OMP threading is not working.");
642+
}
643+
}
644+
645+
omp_set_num_threads(threads);
634646
}
635647

636648
void OpenRoad::setThreadCount(const char* threads, bool print_info)

src/ant/include/ant/AntennaChecker.hh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class AntennaChecker
3030
~AntennaChecker();
3131

3232
// net nullptr -> check all nets
33-
int checkAntennas(odb::dbNet* net = nullptr,
34-
int num_threads = 1,
35-
bool verbose = false);
33+
int checkAntennas(odb::dbNet* net = nullptr, bool verbose = false);
3634
int antennaViolationCount() const;
3735
Violations getAntennaViolations(odb::dbNet* net,
3836
odb::dbMTerm* diode_mterm,

src/ant/src/AntennaChecker.cc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ AntennaChecker::AntennaChecker(odb::dbDatabase* db, utl::Logger* logger)
6464

6565
AntennaChecker::~AntennaChecker() = default;
6666

67-
int AntennaChecker::checkAntennas(odb::dbNet* net,
68-
int num_threads,
69-
bool verbose)
67+
int AntennaChecker::checkAntennas(odb::dbNet* net, bool verbose)
7068
{
71-
return impl_->checkAntennas(net, num_threads, verbose);
69+
return impl_->checkAntennas(net, verbose);
7270
}
7371

7472
int AntennaChecker::antennaViolationCount() const
@@ -1153,9 +1151,7 @@ bool AntennaChecker::Impl::haveGuides()
11531151
return true;
11541152
}
11551153

1156-
int AntennaChecker::Impl::checkAntennas(odb::dbNet* net,
1157-
const int num_threads,
1158-
bool verbose)
1154+
int AntennaChecker::Impl::checkAntennas(odb::dbNet* net, bool verbose)
11591155
{
11601156
{
11611157
std::lock_guard<std::mutex> lock(map_mutex_);
@@ -1210,7 +1206,6 @@ int AntennaChecker::Impl::checkAntennas(odb::dbNet* net,
12101206
nets_.push_back(net);
12111207
}
12121208
}
1213-
omp_set_num_threads(num_threads);
12141209
#pragma omp parallel for schedule(dynamic)
12151210
for (int i = 0; i < nets_.size(); i++) {
12161211
odb::dbNet* net = nets_[i];

src/ant/src/AntennaChecker.i

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ check_antennas(const char *net_name, bool verbose)
3838
logger->error(utl::ANT, 12, "Net {} not found.", net_name);
3939
}
4040
}
41-
const int num_threads = ord::OpenRoad::openRoad()->getThreadCount();
42-
return getAntennaChecker()->checkAntennas(net, num_threads, verbose);
41+
return getAntennaChecker()->checkAntennas(net, verbose);
4342
}
4443

4544
int

src/ant/src/AntennaCheckerImpl.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class AntennaChecker::Impl
105105
Impl(odb::dbDatabase* db, utl::Logger* logger);
106106

107107
// net nullptr -> check all nets
108-
int checkAntennas(odb::dbNet* net, int num_threads, bool verbose);
108+
int checkAntennas(odb::dbNet* net, bool verbose);
109109
int antennaViolationCount() const;
110110
Violations getAntennaViolations(odb::dbNet* net,
111111
odb::dbMTerm* diode_mterm,

src/drt/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ cc_library(
279279
"@boost.polygon",
280280
"@boost.serialization",
281281
"@boost.stacktrace",
282+
"@openmp",
282283
"@tk_tcl//:tcl",
283284
],
284285
)

src/drt/include/drt/TritonRoute.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ struct ParamStruct
7777
int minAccessPoints = -1;
7878
bool saveGuideUpdates = false;
7979
std::string repairPDNLayerName;
80-
int num_threads;
8180
};
8281

8382
class TritonRoute
@@ -155,15 +154,15 @@ class TritonRoute
155154
void updateGlobals(const char* file_name);
156155
void resetDb(const char* file_name);
157156
void clearDesign();
158-
void updateDesign(const std::vector<std::string>& updates, int num_threads);
159-
void updateDesign(const std::string& path, int num_threads);
157+
void updateDesign(const std::vector<std::string>& updates);
158+
void updateDesign(const std::string& path);
160159
void addWorkerResults(
161160
const std::vector<std::pair<int, std::string>>& results);
162161
bool getWorkerResults(std::vector<std::pair<int, std::string>>& results);
163162
int getWorkerResultsSize();
164163
void sendDesignDist();
165164
bool writeGlobals(const std::string& name);
166-
void sendDesignUpdates(const std::string& router_cfg_path, int num_threads);
165+
void sendDesignUpdates(const std::string& router_cfg_path);
167166
void sendGlobalsUpdates(const std::string& router_cfg_path,
168167
const std::string& serializedViaData);
169168
void reportDRC(const std::string& file_name,
@@ -176,12 +175,11 @@ class TritonRoute
176175
int y1,
177176
int x2,
178177
int y2,
179-
const std::string& marker_name,
180-
int num_threads);
178+
const std::string& marker_name);
181179
bool initGuide();
182180
void prep();
183181
odb::dbDatabase* getDb() const { return db_; }
184-
void fixMaxSpacing(int num_threads);
182+
void fixMaxSpacing();
185183
void deleteInstancePAData(frInst* inst);
186184
void addInstancePAData(frInst* inst);
187185

src/drt/src/TritonRoute.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,8 @@ static void deserializeUpdates(frDesign* design,
380380
file.close();
381381
}
382382

383-
void TritonRoute::updateDesign(const std::vector<std::string>& updatesStrs,
384-
int num_threads)
383+
void TritonRoute::updateDesign(const std::vector<std::string>& updatesStrs)
385384
{
386-
omp_set_num_threads(num_threads);
387385
std::vector<std::vector<drUpdate>> updates(updatesStrs.size());
388386
#pragma omp parallel for schedule(dynamic)
389387
for (int i = 0; i < updatesStrs.size(); i++) {
@@ -392,9 +390,8 @@ void TritonRoute::updateDesign(const std::vector<std::string>& updatesStrs,
392390
applyUpdates(updates);
393391
}
394392

395-
void TritonRoute::updateDesign(const std::string& path, int num_threads)
393+
void TritonRoute::updateDesign(const std::string& path)
396394
{
397-
omp_set_num_threads(num_threads);
398395
std::vector<std::vector<drUpdate>> updates;
399396
deserializeUpdates(design_.get(), path, updates);
400397
applyUpdates(updates);
@@ -918,8 +915,7 @@ void TritonRoute::sendGlobalsUpdates(const std::string& router_cfg_path,
918915
}
919916
}
920917

921-
void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path,
922-
int num_threads)
918+
void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path)
923919
{
924920
if (!distributed_) {
925921
return;
@@ -934,7 +930,6 @@ void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path,
934930
serializeTask = std::make_unique<ProfileTask>("DIST: SERIALIZE_UPDATES");
935931
}
936932
const auto& designUpdates = design_->getUpdates();
937-
omp_set_num_threads(num_threads);
938933
std::vector<std::string> updates(designUpdates.size());
939934
#pragma omp parallel for schedule(dynamic)
940935
for (int i = 0; i < designUpdates.size(); i++) {
@@ -970,15 +965,6 @@ void TritonRoute::sendDesignUpdates(const std::string& router_cfg_path,
970965

971966
int TritonRoute::main()
972967
{
973-
// Just to verify that OMP support is compiled in correctly.
974-
omp_set_num_threads(2);
975-
#pragma omp parallel
976-
{
977-
if (omp_get_num_threads() != 2) {
978-
logger_->error(DRT, 623, "OMP threading is not working.");
979-
}
980-
}
981-
982968
if (router_cfg_->DBPROCESSNODE == "GF14_13M_3Mx_2Cx_4Kx_2Hx_2Gx_LB") {
983969
router_cfg_->USENONPREFTRACKS = false;
984970
}
@@ -1061,8 +1047,7 @@ int TritonRoute::main()
10611047
prep();
10621048
ta();
10631049
if (distributed_) {
1064-
asio::post(*dist_pool_,
1065-
[this] { sendDesignUpdates("", router_cfg_->MAX_THREADS); });
1050+
asio::post(*dist_pool_, [this] { sendDesignUpdates(""); });
10661051
}
10671052
dr();
10681053
if (!router_cfg_->SINGLE_STEP_DR) {
@@ -1120,12 +1105,11 @@ void TritonRoute::addInstancePAData(frInst* inst)
11201105
}
11211106
}
11221107

1123-
void TritonRoute::fixMaxSpacing(int num_threads)
1108+
void TritonRoute::fixMaxSpacing()
11241109
{
11251110
initDesign();
11261111
initGuide();
11271112
prep();
1128-
router_cfg_->MAX_THREADS = num_threads;
11291113
dr_ = std::make_unique<FlexDR>(
11301114
this, getDesign(), logger_, db_, router_cfg_.get());
11311115
dr_->init();
@@ -1173,7 +1157,6 @@ void TritonRoute::getDRCMarkers(frList<std::unique_ptr<frMarker>>& markers,
11731157
}
11741158
}
11751159
std::map<MarkerId, frMarker*> mapMarkers;
1176-
omp_set_num_threads(router_cfg_->MAX_THREADS);
11771160
for (auto& workers : workersBatches) {
11781161
#pragma omp parallel for schedule(dynamic)
11791162
for (int i = 0; i < workers.size(); i++) { // NOLINT
@@ -1206,12 +1189,10 @@ void TritonRoute::checkDRC(const char* filename,
12061189
int y1,
12071190
int x2,
12081191
int y2,
1209-
const std::string& marker_name,
1210-
int num_threads)
1192+
const std::string& marker_name)
12111193
{
12121194
router_cfg_->GC_IGNORE_PDN_LAYER_NUM = -1;
12131195
router_cfg_->REPAIR_PDN_LAYER_NUM = -1;
1214-
router_cfg_->MAX_THREADS = num_threads;
12151196
initDesign();
12161197
auto gcellGrid = db_->getChip()->getBlock()->getGCellGrid();
12171198
if (gcellGrid != nullptr && gcellGrid->getNumGridPatternsX() == 1
@@ -1300,7 +1281,6 @@ void TritonRoute::setParams(const ParamStruct& params)
13001281
}
13011282
router_cfg_->SAVE_GUIDE_UPDATES = params.saveGuideUpdates;
13021283
router_cfg_->REPAIR_PDN_LAYER_NAME = params.repairPDNLayerName;
1303-
router_cfg_->MAX_THREADS = params.num_threads;
13041284
}
13051285

13061286
void TritonRoute::addWorkerResults(

src/drt/src/TritonRoute.i

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ void detailed_route_cmd(const char* outputMazeFile,
7070
int drcReportIterStep)
7171
{
7272
auto* router = ord::OpenRoad::openRoad()->getTritonRoute();
73-
const int num_threads = ord::OpenRoad::openRoad()->getThreadCount();
7473
std::optional<int> drcReportIterStepOpt;
7574
if (drcReportIterStep > 0) {
7675
drcReportIterStepOpt = drcReportIterStep;
@@ -94,8 +93,7 @@ void detailed_route_cmd(const char* outputMazeFile,
9493
singleStepDR,
9594
minAccessPoints,
9695
saveGuideUpdates,
97-
repairPDNLayerName,
98-
num_threads});
96+
repairPDNLayerName});
9997
router->main();
10098
router->setDistributed(false);
10199
}
@@ -115,7 +113,6 @@ void pin_access_cmd(const char* dbProcessNode,
115113
params.minAccessPoints = minAccessPoints;
116114
params.viaInPinBottomLayer = viaInPinBottomLayer;
117115
params.viaInPinTopLayer = viaInPinTopLayer;
118-
params.num_threads = ord::OpenRoad::openRoad()->getThreadCount();
119116
router->setParams(params);
120117
router->pinAccess();
121118
router->setDistributed(false);
@@ -183,8 +180,7 @@ run_worker_cmd(const char* dump_dir, const char* worker_dir, const char* drc_rpt
183180
auto* router = ord::OpenRoad::openRoad()->getTritonRoute();
184181
router->updateGlobals(fmt::format("{}/init_router_cfg.bin", dump_dir).c_str());
185182
router->resetDb(fmt::format("{}/design.odb", dump_dir).c_str());
186-
const int num_threads = ord::OpenRoad::openRoad()->getThreadCount();
187-
router->updateDesign(fmt::format("{}/{}/updates.bin", dump_dir, worker_dir).c_str(), num_threads);
183+
router->updateDesign(fmt::format("{}/{}/updates.bin", dump_dir, worker_dir).c_str());
188184
router->updateGlobals(fmt::format("{}/{}/worker_router_cfg.bin", dump_dir, worker_dir).c_str());
189185

190186
router->debugSingleWorker(fmt::format("{}/{}", dump_dir, worker_dir), drc_rpt);
@@ -208,8 +204,7 @@ void detailed_route_step_drt(int size,
208204
void fix_max_spacing_cmd()
209205
{
210206
auto* router = ord::OpenRoad::openRoad()->getTritonRoute();
211-
const int num_threads = ord::OpenRoad::openRoad()->getThreadCount();
212-
router->fixMaxSpacing(num_threads);
207+
router->fixMaxSpacing();
213208
}
214209
void step_end()
215210
{
@@ -220,8 +215,7 @@ void step_end()
220215
void check_drc_cmd(const char* drc_file, int x1, int y1, int x2, int y2, const char* marker_name)
221216
{
222217
auto* router = ord::OpenRoad::openRoad()->getTritonRoute();
223-
const int num_threads = ord::OpenRoad::openRoad()->getThreadCount();
224-
router->checkDRC(drc_file, x1, y1, x2, y2, marker_name, num_threads);
218+
router->checkDRC(drc_file, x1, y1, x2, y2, marker_name);
225219
}
226220

227221
std::vector<int>

0 commit comments

Comments
 (0)