Skip to content

Commit

Permalink
drt: used access pattern guard
Browse files Browse the repository at this point in the history
Signed-off-by: bernardo <[email protected]>
  • Loading branch information
bnmfw committed Oct 4, 2024
1 parent 6814845 commit 91a9156
Showing 1 changed file with 92 additions and 98 deletions.
190 changes: 92 additions & 98 deletions src/drt/src/pa/FlexPA_prep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2640,19 +2640,14 @@ bool FlexPA::genPatterns_commit(
const int curr_unique_inst_idx,
const int max_access_point_size)
{
bool has_new_pattern = false;

const int source_node_idx = getFlatIdx(-1, 0, max_access_point_size);
const int drain_node_idx = getFlatIdx(pins.size(), 0, max_access_point_size);
auto drain_node = &(nodes[drain_node_idx]);
int curr_node_idx = drain_node->getPrevNodeIdx();

std::vector<int> access_pattern(pins.size(), -1);

while (curr_node_idx != source_node_idx) {
if (curr_node_idx == -1) {
// Some node has no previous node
// This means there is no path from source to drain
logger_->error(DRT, 90, "Valid access pattern not found.");
}

Expand All @@ -2666,112 +2661,111 @@ bool FlexPA::genPatterns_commit(
curr_node_idx = curr_node->getPrevNodeIdx();
}

// add to pattern set if unique
if (inst_access_patterns.find(access_pattern) == inst_access_patterns.end()) {
inst_access_patterns.insert(access_pattern);
// create new access pattern and push to uniqueInstances
auto pin_access_pattern = std::make_unique<FlexPinAccessPattern>();
std::map<frMPin*, frAccessPoint*> pin_to_access_point;
// check DRC for the whole pattern
std::vector<std::pair<frConnFig*, frBlockObject*>> objs;
std::vector<std::unique_ptr<frVia>> temp_vias;
frInst* target_obj = nullptr;
for (int pin_idx = 0; pin_idx < (int) pins.size(); pin_idx++) {
auto acc_point_idx = access_pattern[pin_idx];
auto& [pin, inst_term] = pins[pin_idx];
auto inst = inst_term->getInst();
target_obj = inst;
const int pin_access_idx = unique_insts_.getPAIndex(inst);
const auto pa = pin->getPinAccess(pin_access_idx);
const auto access_point = pa->getAccessPoint(acc_point_idx);
pin_to_access_point[pin] = access_point;

// add objs
std::unique_ptr<frVia> via;
if (access_point->hasAccess(frDirEnum::U)) {
via = std::make_unique<frVia>(access_point->getViaDef());
auto rvia = via.get();
temp_vias.push_back(std::move(via));
// not a new access pattern
if (inst_access_patterns.find(access_pattern) != inst_access_patterns.end()) {
return false;
}

dbTransform xform = inst->getUpdatedXform(true);
Point pt(access_point->getPoint());
xform.apply(pt);
rvia->setOrigin(pt);
if (inst_term->hasNet()) {
objs.emplace_back(rvia, inst_term->getNet());
} else {
objs.emplace_back(rvia, inst_term);
}
inst_access_patterns.insert(access_pattern);
// create new access pattern and push to uniqueInstances
auto pin_access_pattern = std::make_unique<FlexPinAccessPattern>();
std::map<frMPin*, frAccessPoint*> pin_to_access_point;
// check DRC for the whole pattern
std::vector<std::pair<frConnFig*, frBlockObject*>> objs;
std::vector<std::unique_ptr<frVia>> temp_vias;
frInst* target_obj = nullptr;
for (int pin_idx = 0; pin_idx < (int) pins.size(); pin_idx++) {
auto acc_point_idx = access_pattern[pin_idx];
auto& [pin, inst_term] = pins[pin_idx];
auto inst = inst_term->getInst();
target_obj = inst;
const int pin_access_idx = unique_insts_.getPAIndex(inst);
const auto pa = pin->getPinAccess(pin_access_idx);
const auto access_point = pa->getAccessPoint(acc_point_idx);
pin_to_access_point[pin] = access_point;

// add objs
std::unique_ptr<frVia> via;
if (access_point->hasAccess(frDirEnum::U)) {
via = std::make_unique<frVia>(access_point->getViaDef());
auto rvia = via.get();
temp_vias.push_back(std::move(via));

dbTransform xform = inst->getUpdatedXform(true);
Point pt(access_point->getPoint());
xform.apply(pt);
rvia->setOrigin(pt);
if (inst_term->hasNet()) {
objs.emplace_back(rvia, inst_term->getNet());
} else {
objs.emplace_back(rvia, inst_term);
}
}
}

frAccessPoint* leftAP = nullptr;
frAccessPoint* rightAP = nullptr;
frCoord leftPt = std::numeric_limits<frCoord>::max();
frCoord rightPt = std::numeric_limits<frCoord>::min();
frAccessPoint* leftAP = nullptr;
frAccessPoint* rightAP = nullptr;
frCoord leftPt = std::numeric_limits<frCoord>::max();
frCoord rightPt = std::numeric_limits<frCoord>::min();

const auto& [pin, inst_term] = pins[0];
const auto inst = inst_term->getInst();
for (auto& inst_term : inst->getInstTerms()) {
if (isSkipInstTerm(inst_term.get())) {
continue;
}
uint64_t n_no_ap_pins = 0;
for (auto& pin : inst_term->getTerm()->getPins()) {
if (pin_to_access_point.find(pin.get()) == pin_to_access_point.end()) {
n_no_ap_pins++;
pin_access_pattern->addAccessPoint(nullptr);
} else {
const auto& ap = pin_to_access_point[pin.get()];
const Point tmpPt = ap->getPoint();
if (tmpPt.x() < leftPt) {
leftAP = ap;
leftPt = tmpPt.x();
}
if (tmpPt.x() > rightPt) {
rightAP = ap;
rightPt = tmpPt.x();
}
pin_access_pattern->addAccessPoint(ap);
}
}
if (n_no_ap_pins == inst_term->getTerm()->getPins().size()) {
logger_->error(DRT, 91, "Pin does not have valid ap.");
}
const auto& [pin, inst_term] = pins[0];
const auto inst = inst_term->getInst();
for (auto& inst_term : inst->getInstTerms()) {
if (isSkipInstTerm(inst_term.get())) {
continue;
}
pin_access_pattern->setBoundaryAP(true, leftAP);
pin_access_pattern->setBoundaryAP(false, rightAP);

std::set<frBlockObject*> owners;
if (target_obj != nullptr
&& genPatterns_gc({target_obj}, objs, Commit, &owners)) {
pin_access_pattern->updateCost();
unique_inst_patterns_[curr_unique_inst_idx].push_back(
std::move(pin_access_pattern));
// genPatterns_print(nodes, pins, max_access_point_size);
is_valid = true;
} else {
for (int idx_1 = 0; idx_1 < (int) pins.size(); idx_1++) {
auto idx_2 = access_pattern[idx_1];
auto& [pin, inst_term] = pins[idx_1];
if (inst_term->hasNet()) {
if (owners.find(inst_term->getNet()) != owners.end()) {
viol_access_points.insert(std::make_pair(idx_1, idx_2)); // idx ;
}
} else {
if (owners.find(inst_term) != owners.end()) {
viol_access_points.insert(std::make_pair(idx_1, idx_2)); // idx ;
}
uint64_t n_no_ap_pins = 0;
for (auto& pin : inst_term->getTerm()->getPins()) {
if (pin_to_access_point.find(pin.get()) == pin_to_access_point.end()) {
n_no_ap_pins++;
pin_access_pattern->addAccessPoint(nullptr);
} else {
const auto& ap = pin_to_access_point[pin.get()];
const Point tmpPt = ap->getPoint();
if (tmpPt.x() < leftPt) {
leftAP = ap;
leftPt = tmpPt.x();
}
if (tmpPt.x() > rightPt) {
rightAP = ap;
rightPt = tmpPt.x();
}
pin_access_pattern->addAccessPoint(ap);
}
}
if (n_no_ap_pins == inst_term->getTerm()->getPins().size()) {
logger_->error(DRT, 91, "Pin does not have valid ap.");
}
}
pin_access_pattern->setBoundaryAP(true, leftAP);
pin_access_pattern->setBoundaryAP(false, rightAP);

has_new_pattern = true;
std::set<frBlockObject*> owners;
if (target_obj != nullptr
&& genPatterns_gc({target_obj}, objs, Commit, &owners)) {
pin_access_pattern->updateCost();
unique_inst_patterns_[curr_unique_inst_idx].push_back(
std::move(pin_access_pattern));
// genPatterns_print(nodes, pins, max_access_point_size);
is_valid = true;
} else {
has_new_pattern = false;
for (int idx_1 = 0; idx_1 < (int) pins.size(); idx_1++) {
auto idx_2 = access_pattern[idx_1];
auto& [pin, inst_term] = pins[idx_1];
if (inst_term->hasNet()) {
if (owners.find(inst_term->getNet()) != owners.end()) {
viol_access_points.insert(std::make_pair(idx_1, idx_2)); // idx ;
}
} else {
if (owners.find(inst_term) != owners.end()) {
viol_access_points.insert(std::make_pair(idx_1, idx_2)); // idx ;
}
}
}
}

return has_new_pattern;
// new access pattern
return true;
}

void FlexPA::genPatternsPrintDebug(
Expand Down

0 comments on commit 91a9156

Please sign in to comment.