Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drt: genPatterns_commit refactoring #5872

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bnmfw
Copy link
Contributor

@bnmfw bnmfw commented Oct 4, 2024

Some refactoring on genPatterns_commit is being done to improve readability and reduce code.

Access Patterns Graph Backwards Path Function and Readability

The first part of genPatterns_commit is a loop that traces a path through access points of an instance that represent a chosen access pattern.

Right now the loop is a little over complicated for what it does, so I refactored it a bit to make more obvious.

Added the variables source_node_idx and drain_node_idx to make the start and end points of the path search more clear, instead decreasing pin_cnt.

This was transformed in a function called extractAccessPatternFromNodes as it has a pretty distinct role and function.

Used Pattern Guard

The later part of the had an if statement to check is the generated pattern was unused, if true it did more checks, later it essentially had an else with return false. This as transformed into a guard.

No further changes on this function will be done in this PR as the git diff shows everything past the guard as changed due to the indentation level change. Further changes will be at a separate PR.

Copy link
Contributor

github-actions bot commented Oct 4, 2024

clang-tidy review says "All clean, LGTM! 👍"

@bnmfw bnmfw force-pushed the drt_genPatterns_commit_refactoring branch from 2ebcfdb to 91a9156 Compare October 4, 2024 15:41
Copy link
Contributor

github-actions bot commented Oct 4, 2024

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/drt/src/pa/FlexPA.h Outdated Show resolved Hide resolved
@bnmfw bnmfw force-pushed the drt_genPatterns_commit_refactoring branch from b050b9b to 63dc4f8 Compare October 8, 2024 11:56
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/drt/src/pa/FlexPA.h Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Oct 8, 2024

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@bnmfw bnmfw force-pushed the drt_genPatterns_commit_refactoring branch from cc3f2a2 to f7b2789 Compare October 18, 2024 17:40
@bnmfw bnmfw marked this pull request as ready for review October 18, 2024 17:41
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

leftAP = ap;
leftPt = tmpPt.x();
}
if (tmpPt.x() > rightPt) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be else if?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. Consider the first iteration. we need to set both; leftPt and rightPt, to tmpPt

}
}
if (n_no_ap_pins == inst_term->getTerm()->getPins().size()) {
logger_->error(DRT, 91, "Pin does not have valid ap.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize AP. Also, can you add the term name to the print?

Comment on lines +2636 to +2638
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "drain" have a special meeting here? I the opposite of source is usually "sink" in these contexts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess sink is the correct word in this context.

@@ -568,6 +568,25 @@ class FlexPA
int curr_unique_inst_idx,
int max_access_point_size);

/**
* @brief Extracts the access patterns given the graph nodes composing the
* access points relatioship
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* access points relatioship
* access points relationship

* access points relatioship
*
* @param nodes {pin,access_point} nodes of the access pattern graph
* @param pins vector os pins of the unique instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector of pins?

Comment on lines +578 to +579
* @param max_access_point_size number of acc points the instance with most
* acc points has
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param max_access_point_size number of acc points the instance with most
* acc points has
* @param max_access_point_size the maximum number of access points across
* all instances

Comment on lines +2762 to +2766
if (owners.find(inst_term->getNet()) != owners.end()) {
viol_access_points.insert(std::make_pair(idx_1, idx_2)); // idx ;
}
}
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, left_access_point);
pin_access_pattern->setBoundaryAP(false, right_access_point);

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 ;
}
} else {
if (owners.find(inst_term) != owners.end()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a more efficient way to do this because this will traverse owners twice. It might not matter if the else is rarely exercised or if owners is small.


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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto drain_node = &(nodes[drain_node_idx]);
const auto& drain_node = nodes[drain_node_idx];

use const reference to the object instead of pointer.

Comment on lines +2636 to +2638
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess sink is the correct word in this context.

logger_->error(DRT, 90, "Valid access pattern not found.");
}

auto curr_node = &(nodes[curr_node_idx]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines +2712 to +2715
frAccessPoint* leftAP = nullptr;
frAccessPoint* rightAP = nullptr;
frCoord leftPt = std::numeric_limits<frCoord>::max();
frCoord rightPt = std::numeric_limits<frCoord>::min();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the renaming? this is not the followed style.

leftAP = ap;
leftPt = tmpPt.x();
}
if (tmpPt.x() > rightPt) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. Consider the first iteration. we need to set both; leftPt and rightPt, to tmpPt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants