Skip to content

Commit

Permalink
drt: pre-compute isSkipInstTerm for performance
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Liberty <[email protected]>
  • Loading branch information
maliberty committed May 6, 2024
1 parent 860e03a commit 44a1719
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/drt/src/pa/FlexPA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void FlexPA::init()
initTrackCoords();

unique_insts_.init();
initSkipInstTerm();
}

void FlexPA::applyPatternsFile(const char* file_path)
Expand Down
4 changes: 4 additions & 0 deletions src/drt/src/pa/FlexPA.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class FlexPA
uniqueInstPatterns_;

UniqueInsts unique_insts_;
using UniqueMTerm = std::pair<const UniqueInsts::InstSet*, frMTerm*>;
std::map<UniqueMTerm, bool> skip_unique_inst_term_;

// helper structures
std::vector<std::map<frCoord, frAccessPointEnum>> trackCoords_;
Expand All @@ -121,13 +123,15 @@ class FlexPA
}
void applyPatternsFile(const char* file_path);
void getViaRawPriority(frViaDef* viaDef, ViaRawPriorityTuple& priority);
bool isSkipInstTermLocal(frInstTerm* in);
bool isSkipInstTerm(frInstTerm* in);
bool isDistributed() const { return !remote_host_.empty(); }

// init
void init();
void initTrackCoords();
void initViaRawPriority();
void initSkipInstTerm();
// prep
void prep();
void prepPoint();
Expand Down
38 changes: 38 additions & 0 deletions src/drt/src/pa/FlexPA_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,42 @@ void FlexPA::initTrackCoords()
}
}

void FlexPA::initSkipInstTerm()
{
const auto& unique = unique_insts_.getUnique();

// Populate the map single-threaded so no further resizing is needed.
for (frInst* inst : unique) {
for (auto& instTerm : inst->getInstTerms()) {
auto term = instTerm->getTerm();
auto instClass = unique_insts_.getClass(inst);
skip_unique_inst_term_[{instClass, term}] = false;
}
}

const int unique_size = unique.size();
#pragma omp parallel for schedule(dynamic)
for (int uniqueInstIdx = 0; uniqueInstIdx < unique_size; uniqueInstIdx++) {
frInst* inst = unique[uniqueInstIdx];
for (auto& instTerm : inst->getInstTerms()) {
frMTerm* term = instTerm->getTerm();
const UniqueInsts::InstSet* instClass = unique_insts_.getClass(inst);

// We have to be careful that the skip conditions are true not only of
// the unique instance but also all the equivalent instances.
bool skip = isSkipInstTermLocal(instTerm.get());
if (skip) {
for (frInst* inst : *instClass) {
frInstTerm* it = inst->getInstTerm(instTerm->getIndexInOwner());
skip = isSkipInstTermLocal(it);
if (!skip) {
break;
}
}
}
skip_unique_inst_term_.at({instClass, term}) = skip;
}
}
}

} // namespace drt
36 changes: 17 additions & 19 deletions src/drt/src/pa/FlexPA_prep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2226,34 +2226,32 @@ void FlexPA::getInsts(std::vector<frInst*>& insts)
}

// Skip power pins, pins connected to special nets, and dangling pins
// (since we won't route these). We have to be careful that these
// conditions are true not only of the unique instance but also all
// the equivalent instances.
bool FlexPA::isSkipInstTerm(frInstTerm* in)
// (since we won't route these).
//
// Checks only this instTerm and not an equivalent ones. This
// is a helper to isSkipInstTerm and initSkipInstTerm.
bool FlexPA::isSkipInstTermLocal(frInstTerm* in)
{
if (in->getTerm()->getType().isSupply()) {
auto term = in->getTerm();
if (term->getType().isSupply()) {
return true;
}
auto in_net = in->getNet();
if (in_net && !in_net->isSpecial()) {
return false;
}
return true;
}

bool FlexPA::isSkipInstTerm(frInstTerm* in)
{
auto instClass = unique_insts_.getClass(in->getInst());
if (instClass != nullptr) {
for (auto& inst : *instClass) {
frInstTerm* it = inst->getInstTerm(in->getIndexInOwner());
if (!in_net) {
if (it->getNet()) {
return false;
}
} else if (in_net->isSpecial()) {
if (it->getNet() && !it->getNet()->isSpecial()) {
return false;
}
}
}
if (instClass == nullptr) {
return isSkipInstTermLocal(in);
}
return true;

// This should be already computed in initSkipInstTerm()
return skip_unique_inst_term_.at({instClass, in->getTerm()});
}

// the input inst must be unique instance
Expand Down
10 changes: 4 additions & 6 deletions src/drt/src/pa/FlexPA_unique.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace drt {
class UniqueInsts
{
public:
using InstSet = std::set<frInst*, frBlockObjectComp>;
// if target_insts is non-empty then analysis is limited to
// those instances.
UniqueInsts(frDesign* design,
Expand All @@ -58,7 +59,7 @@ class UniqueInsts
int getPAIndex(frInst* inst) const;

// Gets the instances in the equivalence set of the given inst
std::set<frInst*, frBlockObjectComp>* getClass(frInst* inst) const;
InstSet* getClass(frInst* inst) const;

const std::vector<frInst*>& getUnique() const;
frInst* getUnique(int idx) const;
Expand Down Expand Up @@ -97,17 +98,14 @@ class UniqueInsts
// Mapp all instances to their representative unique instance
std::map<frInst*, frInst*, frBlockObjectComp> inst2unique_;
// Maps all instances to the set of instances with the same unique inst
std::unordered_map<frInst*, std::set<frInst*, frBlockObjectComp>*>
inst2Class_;
std::unordered_map<frInst*, InstSet*> inst2Class_;
// Maps a unique instance to its pin access index
std::map<frInst*, int, frBlockObjectComp> unique2paidx_;
// Maps a unique instance to its index in unique_
std::map<frInst*, int, frBlockObjectComp> unique2Idx_;
// master orient track-offset to instances
std::map<frMaster*,
std::map<dbOrientType,
std::map<std::vector<frCoord>,
std::set<frInst*, frBlockObjectComp>>>,
std::map<dbOrientType, std::map<std::vector<frCoord>, InstSet>>,
frBlockObjectComp>
masterOT2Insts_;
};
Expand Down

0 comments on commit 44a1719

Please sign in to comment.