From 44a1719526b6aa2542d1f040d899aba9b8afca7b Mon Sep 17 00:00:00 2001 From: Matt Liberty Date: Mon, 6 May 2024 06:18:48 +0000 Subject: [PATCH] drt: pre-compute isSkipInstTerm for performance Signed-off-by: Matt Liberty --- src/drt/src/pa/FlexPA.cpp | 1 + src/drt/src/pa/FlexPA.h | 4 ++++ src/drt/src/pa/FlexPA_init.cpp | 38 ++++++++++++++++++++++++++++++++++ src/drt/src/pa/FlexPA_prep.cpp | 36 +++++++++++++++----------------- src/drt/src/pa/FlexPA_unique.h | 10 ++++----- 5 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/drt/src/pa/FlexPA.cpp b/src/drt/src/pa/FlexPA.cpp index 11c6210696f..8afa97dbabf 100644 --- a/src/drt/src/pa/FlexPA.cpp +++ b/src/drt/src/pa/FlexPA.cpp @@ -92,6 +92,7 @@ void FlexPA::init() initTrackCoords(); unique_insts_.init(); + initSkipInstTerm(); } void FlexPA::applyPatternsFile(const char* file_path) diff --git a/src/drt/src/pa/FlexPA.h b/src/drt/src/pa/FlexPA.h index 97716b2b68a..010039b12f0 100644 --- a/src/drt/src/pa/FlexPA.h +++ b/src/drt/src/pa/FlexPA.h @@ -99,6 +99,8 @@ class FlexPA uniqueInstPatterns_; UniqueInsts unique_insts_; + using UniqueMTerm = std::pair; + std::map skip_unique_inst_term_; // helper structures std::vector> trackCoords_; @@ -121,6 +123,7 @@ 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(); } @@ -128,6 +131,7 @@ class FlexPA void init(); void initTrackCoords(); void initViaRawPriority(); + void initSkipInstTerm(); // prep void prep(); void prepPoint(); diff --git a/src/drt/src/pa/FlexPA_init.cpp b/src/drt/src/pa/FlexPA_init.cpp index 07a00827819..f139a04eb0f 100644 --- a/src/drt/src/pa/FlexPA_init.cpp +++ b/src/drt/src/pa/FlexPA_init.cpp @@ -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 diff --git a/src/drt/src/pa/FlexPA_prep.cpp b/src/drt/src/pa/FlexPA_prep.cpp index a7e8a8bee68..64f142e5d13 100644 --- a/src/drt/src/pa/FlexPA_prep.cpp +++ b/src/drt/src/pa/FlexPA_prep.cpp @@ -2226,34 +2226,32 @@ void FlexPA::getInsts(std::vector& 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 diff --git a/src/drt/src/pa/FlexPA_unique.h b/src/drt/src/pa/FlexPA_unique.h index fcbaddac5cb..dbed1c2d37e 100644 --- a/src/drt/src/pa/FlexPA_unique.h +++ b/src/drt/src/pa/FlexPA_unique.h @@ -44,6 +44,7 @@ namespace drt { class UniqueInsts { public: + using InstSet = std::set; // if target_insts is non-empty then analysis is limited to // those instances. UniqueInsts(frDesign* design, @@ -58,7 +59,7 @@ class UniqueInsts int getPAIndex(frInst* inst) const; // Gets the instances in the equivalence set of the given inst - std::set* getClass(frInst* inst) const; + InstSet* getClass(frInst* inst) const; const std::vector& getUnique() const; frInst* getUnique(int idx) const; @@ -97,17 +98,14 @@ class UniqueInsts // Mapp all instances to their representative unique instance std::map inst2unique_; // Maps all instances to the set of instances with the same unique inst - std::unordered_map*> - inst2Class_; + std::unordered_map inst2Class_; // Maps a unique instance to its pin access index std::map unique2paidx_; // Maps a unique instance to its index in unique_ std::map unique2Idx_; // master orient track-offset to instances std::map, - std::set>>, + std::map, InstSet>>, frBlockObjectComp> masterOT2Insts_; };