Skip to content

Commit 1138027

Browse files
Merge pull request #6916 from bnmfw/drt_computeInstRows
drt: computeInstRows
2 parents 363b51f + 0b2d875 commit 1138027

4 files changed

Lines changed: 141 additions & 114 deletions

File tree

src/drt/src/pa/FlexPA.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "FlexPA.h"
55

6+
#include <omp.h>
7+
68
#include <boost/archive/text_iarchive.hpp>
79
#include <boost/archive/text_oarchive.hpp>
810
#include <boost/io/ios_state.hpp>
@@ -24,11 +26,27 @@
2426
#include "frProfileTask.h"
2527
#include "gc/FlexGC.h"
2628
#include "serialization.h"
29+
#include "utl/exception.h"
2730

2831
BOOST_CLASS_EXPORT(drt::PinAccessJobDescription)
2932

3033
namespace drt {
3134

35+
using utl::ThreadException;
36+
37+
static inline void serializePatterns(
38+
const std::unordered_map<
39+
frInst*,
40+
std::vector<std::unique_ptr<FlexPinAccessPattern>>>& patterns,
41+
const std::string& file_name)
42+
{
43+
std::ofstream file(file_name.c_str());
44+
frOArchive ar(file);
45+
registerTypes(ar);
46+
ar << patterns;
47+
file.close();
48+
}
49+
3250
FlexPA::FlexPA(frDesign* in,
3351
Logger* logger,
3452
dst::Distributed* dist,
@@ -153,6 +171,69 @@ void FlexPA::prep()
153171
prepPattern();
154172
}
155173

174+
void FlexPA::prepPattern()
175+
{
176+
ProfileTask profile("PA:pattern");
177+
178+
const auto& unique = unique_insts_.getUnique();
179+
180+
// revert access points to origin
181+
unique_inst_patterns_.reserve(unique.size());
182+
183+
int cnt = 0;
184+
185+
omp_set_num_threads(router_cfg_->MAX_THREADS);
186+
ThreadException exception;
187+
#pragma omp parallel for schedule(dynamic)
188+
for (frInst* unique_inst : unique) {
189+
try {
190+
// only do for core and block cells
191+
// TODO the above comment says "block cells" but that's not what the code
192+
// does?
193+
if (!isStdCell(unique_inst)) {
194+
continue;
195+
}
196+
prepPatternInst(unique_inst);
197+
#pragma omp critical
198+
{
199+
cnt++;
200+
if (router_cfg_->VERBOSE > 0) {
201+
if (cnt % (cnt > 1000 ? 1000 : 100) == 0) {
202+
logger_->info(DRT, 79, " Complete {} unique inst patterns.", cnt);
203+
}
204+
}
205+
}
206+
} catch (...) {
207+
exception.capture();
208+
}
209+
}
210+
exception.rethrow();
211+
if (router_cfg_->VERBOSE > 0) {
212+
logger_->info(DRT, 81, " Complete {} unique inst patterns.", cnt);
213+
}
214+
if (isDistributed()) {
215+
dst::JobMessage msg(dst::JobMessage::PIN_ACCESS,
216+
dst::JobMessage::BROADCAST),
217+
result;
218+
std::unique_ptr<PinAccessJobDescription> uDesc
219+
= std::make_unique<PinAccessJobDescription>();
220+
std::string patterns_file = fmt::format("{}/patterns.bin", shared_vol_);
221+
serializePatterns(unique_inst_patterns_, patterns_file);
222+
uDesc->setPath(patterns_file);
223+
uDesc->setType(PinAccessJobDescription::UPDATE_PATTERNS);
224+
msg.setJobDescription(std::move(uDesc));
225+
const bool ok
226+
= dist_->sendJob(msg, remote_host_.c_str(), remote_port_, result);
227+
if (!ok) {
228+
logger_->error(
229+
utl::DRT, 330, "Error sending UPDATE_PATTERNS Job to cloud");
230+
}
231+
}
232+
233+
std::vector<std::vector<frInst*>> inst_rows = computeInstRows();
234+
prepPatternInstRows(inst_rows);
235+
}
236+
156237
void FlexPA::setTargetInstances(const frCollection<odb::dbInst*>& insts)
157238
{
158239
target_insts_ = insts;

src/drt/src/pa/FlexPA.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ namespace drt {
3232
using ViaRawPriorityTuple
3333
= std::tuple<bool, frCoord, frCoord, bool, frCoord, frCoord, bool>;
3434

35+
struct frInstLocationComp
36+
{
37+
bool operator()(const frInst* lhs, const frInst* rhs) const
38+
{
39+
Point lp = lhs->getOrigin(), rp = rhs->getOrigin();
40+
if (lp.getY() != rp.getY()) {
41+
return lp.getY() < rp.getY();
42+
}
43+
return lp.getX() < rp.getX();
44+
}
45+
};
46+
47+
using frInstLocationSet = std::set<frInst*, frInstLocationComp>;
48+
3549
class FlexPinAccessPattern;
3650
class FlexDPNode;
3751
class AbstractPAGraphics;
@@ -92,6 +106,7 @@ class FlexPA
92106
std::map<int, std::map<ViaRawPriorityTuple, const frViaDef*>>>
93107
layer_num_to_via_defs_;
94108
frCollection<odb::dbInst*> target_insts_;
109+
frInstLocationSet insts_set_;
95110

96111
std::string remote_host_;
97112
uint16_t remote_port_ = -1;
@@ -730,7 +745,18 @@ class FlexPA
730745
PatternType pattern_type,
731746
std::set<frBlockObject*>* owners = nullptr);
732747

733-
void getInsts(std::vector<frInst*>& insts);
748+
/**
749+
* @brief populates the insts_set_ data structure
750+
*/
751+
void buildInstsSet();
752+
753+
/**
754+
* @brief organizes all the insts in a vector of clusters, each cluster being
755+
* a vector of insts a adjacent insts
756+
*
757+
* @returns the vector of vectors of insts
758+
*/
759+
std::vector<std::vector<frInst*>> computeInstRows();
734760

735761
void prepPatternInstRows(std::vector<std::vector<frInst*>> inst_rows);
736762

src/drt/src/pa/FlexPA_acc_pattern.cpp

Lines changed: 3 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,9 @@ namespace drt {
2525

2626
using utl::ThreadException;
2727

28-
static inline void serializePatterns(
29-
const std::unordered_map<
30-
frInst*,
31-
std::vector<std::unique_ptr<FlexPinAccessPattern>>>& patterns,
32-
const std::string& file_name)
33-
{
34-
std::ofstream file(file_name.c_str());
35-
frOArchive ar(file);
36-
registerTypes(ar);
37-
ar << patterns;
38-
file.close();
39-
}
40-
41-
void FlexPA::getInsts(std::vector<frInst*>& insts)
28+
void FlexPA::buildInstsSet()
4229
{
30+
insts_set_.clear();
4331
std::set<frInst*> target_frinsts;
4432
for (auto inst : target_insts_) {
4533
target_frinsts.insert(design_->getTopBlock()->findInst(inst));
@@ -63,107 +51,9 @@ void FlexPA::getInsts(std::vector<frInst*>& insts)
6351
}
6452
}
6553
if (!is_skip) {
66-
insts.push_back(inst.get());
67-
}
68-
}
69-
}
70-
71-
void FlexPA::prepPattern()
72-
{
73-
ProfileTask profile("PA:pattern");
74-
75-
const auto& unique = unique_insts_.getUnique();
76-
77-
// revert access points to origin
78-
unique_inst_patterns_.reserve(unique.size());
79-
80-
int cnt = 0;
81-
82-
omp_set_num_threads(router_cfg_->MAX_THREADS);
83-
ThreadException exception;
84-
#pragma omp parallel for schedule(dynamic)
85-
for (frInst* unique_inst : unique) {
86-
try {
87-
// only do for core and block cells
88-
// TODO the above comment says "block cells" but that's not what the code
89-
// does?
90-
if (!isStdCell(unique_inst)) {
91-
continue;
92-
}
93-
prepPatternInst(unique_inst);
94-
#pragma omp critical
95-
{
96-
cnt++;
97-
if (router_cfg_->VERBOSE > 0) {
98-
if (cnt % (cnt > 1000 ? 1000 : 100) == 0) {
99-
logger_->info(DRT, 79, " Complete {} unique inst patterns.", cnt);
100-
}
101-
}
102-
}
103-
} catch (...) {
104-
exception.capture();
105-
}
106-
}
107-
exception.rethrow();
108-
if (router_cfg_->VERBOSE > 0) {
109-
logger_->info(DRT, 81, " Complete {} unique inst patterns.", cnt);
110-
}
111-
if (isDistributed()) {
112-
dst::JobMessage msg(dst::JobMessage::PIN_ACCESS,
113-
dst::JobMessage::BROADCAST),
114-
result;
115-
std::unique_ptr<PinAccessJobDescription> uDesc
116-
= std::make_unique<PinAccessJobDescription>();
117-
std::string patterns_file = fmt::format("{}/patterns.bin", shared_vol_);
118-
serializePatterns(unique_inst_patterns_, patterns_file);
119-
uDesc->setPath(patterns_file);
120-
uDesc->setType(PinAccessJobDescription::UPDATE_PATTERNS);
121-
msg.setJobDescription(std::move(uDesc));
122-
const bool ok
123-
= dist_->sendJob(msg, remote_host_.c_str(), remote_port_, result);
124-
if (!ok) {
125-
logger_->error(
126-
utl::DRT, 330, "Error sending UPDATE_PATTERNS Job to cloud");
54+
insts_set_.insert(inst.get());
12755
}
12856
}
129-
130-
// prep pattern for each row
131-
std::vector<frInst*> insts;
132-
std::vector<std::vector<frInst*>> inst_rows;
133-
std::vector<frInst*> row_insts;
134-
135-
auto instLocComp = [](frInst* const& a, frInst* const& b) {
136-
const Point originA = a->getOrigin();
137-
const Point originB = b->getOrigin();
138-
if (originA.y() == originB.y()) {
139-
return (originA.x() < originB.x());
140-
}
141-
return (originA.y() < originB.y());
142-
};
143-
144-
getInsts(insts);
145-
std::sort(insts.begin(), insts.end(), instLocComp);
146-
147-
// gen rows of insts
148-
int prev_y_coord = INT_MIN;
149-
int prev_x_end_coord = INT_MIN;
150-
for (auto inst : insts) {
151-
Point origin = inst->getOrigin();
152-
if (origin.y() != prev_y_coord || origin.x() > prev_x_end_coord) {
153-
if (!row_insts.empty()) {
154-
inst_rows.push_back(row_insts);
155-
row_insts.clear();
156-
}
157-
}
158-
row_insts.push_back(inst);
159-
prev_y_coord = origin.y();
160-
Rect inst_boundary_box = inst->getBoundaryBBox();
161-
prev_x_end_coord = inst_boundary_box.xMax();
162-
}
163-
if (!row_insts.empty()) {
164-
inst_rows.push_back(row_insts);
165-
}
166-
prepPatternInstRows(std::move(inst_rows));
16757
}
16858

16959
void FlexPA::prepPatternInst(frInst* unique_inst)

src/drt/src/pa/FlexPA_row_pattern.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@ static inline void serializeInstRows(
3333
paUpdate::serialize(update, file_name);
3434
}
3535

36+
std::vector<std::vector<frInst*>> FlexPA::computeInstRows()
37+
{
38+
// prep pattern for each row
39+
std::vector<std::vector<frInst*>> inst_rows;
40+
std::vector<frInst*> row_insts;
41+
42+
buildInstsSet();
43+
44+
// gen rows of insts
45+
int prev_y_coord = INT_MIN;
46+
int prev_x_end_coord = INT_MIN;
47+
for (auto inst : insts_set_) {
48+
Point origin = inst->getOrigin();
49+
if (origin.y() != prev_y_coord || origin.x() > prev_x_end_coord) {
50+
if (!row_insts.empty()) {
51+
inst_rows.push_back(row_insts);
52+
row_insts.clear();
53+
}
54+
}
55+
row_insts.push_back(inst);
56+
prev_y_coord = origin.y();
57+
Rect inst_boundary_box = inst->getBoundaryBBox();
58+
prev_x_end_coord = inst_boundary_box.xMax();
59+
}
60+
if (!row_insts.empty()) {
61+
inst_rows.push_back(row_insts);
62+
}
63+
return inst_rows;
64+
}
65+
3666
void FlexPA::prepPatternInstRows(std::vector<std::vector<frInst*>> inst_rows)
3767
{
3868
ThreadException exception;

0 commit comments

Comments
 (0)