Skip to content

Commit 0a58008

Browse files
committed
Add comments requested in #1289
Signed-off-by: Dusty DeWeese <[email protected]>
1 parent e86c68f commit 0a58008

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

vpr/src/route/edge_groups.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bool EdgeGroups::add_non_config_edge(int from_node, int to_node) {
1313
// will form groups of nodes that are connected via non-configurable
1414
// edges.
1515
void EdgeGroups::create_sets() {
16-
rr_non_config_node_sets_map_.clear();
16+
rr_non_config_node_sets_.clear();
1717

1818
// https://en.wikipedia.org/wiki/Component_(graph_theory)#Algorithms
1919
std::vector<size_t> group_size;
@@ -34,20 +34,20 @@ void EdgeGroups::create_sets() {
3434
}
3535

3636
// Create compact set of sets.
37-
rr_non_config_node_sets_map_.resize(group_size.size());
37+
rr_non_config_node_sets_.resize(group_size.size());
3838
for (size_t i = 0; i < group_size.size(); i++) {
39-
rr_non_config_node_sets_map_[i].reserve(group_size[i]);
39+
rr_non_config_node_sets_[i].reserve(group_size[i]);
4040
}
4141
for (const auto& node : graph_) {
42-
rr_non_config_node_sets_map_[node.second.set].push_back(node.first);
42+
rr_non_config_node_sets_[node.second.set].push_back(node.first);
4343
}
4444
}
4545

4646
// Create t_non_configurable_rr_sets from set data.
4747
// NOTE: The stored graph is undirected, so this may generate reverse edges that don't exist.
4848
t_non_configurable_rr_sets EdgeGroups::output_sets() {
4949
t_non_configurable_rr_sets sets;
50-
for (const auto& nodes : rr_non_config_node_sets_map_) {
50+
for (const auto& nodes : rr_non_config_node_sets_) {
5151
std::set<t_node_edge> edge_set;
5252
std::set<int> node_set(nodes.begin(), nodes.end());
5353

@@ -67,7 +67,7 @@ t_non_configurable_rr_sets EdgeGroups::output_sets() {
6767
// Set device context structures for non-configurable node sets.
6868
void EdgeGroups::set_device_context(DeviceContext& device_ctx) {
6969
std::vector<std::vector<int>> rr_non_config_node_sets;
70-
for (const auto& item : rr_non_config_node_sets_map_) {
70+
for (const auto& item : rr_non_config_node_sets_) {
7171
rr_non_config_node_sets.emplace_back(std::move(item));
7272
}
7373

vpr/src/route/edge_groups.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@
99
#include "vpr_types.h"
1010
#include "vpr_context.h"
1111

12-
// Class for building a group of connected edges.
12+
// Class for identifying the components of a graph as sets of nodes.
13+
// Each node is reachable from any other node in the same set, and
14+
// unreachable from nodes in any other set.
15+
// Note that edges are undirected.
16+
//
17+
// This is used by the router to group nodes connected by
18+
// non-configurable edges, because a connection to one node
19+
// must connect them all.
20+
//
21+
// https://en.wikipedia.org/wiki/Component_(graph_theory)
1322
class EdgeGroups {
1423
public:
1524
EdgeGroups() {}
@@ -33,8 +42,8 @@ class EdgeGroups {
3342

3443
private:
3544
struct node_data {
36-
std::unordered_set<int> edges;
37-
int set = OPEN;
45+
std::unordered_set<int> edges; // Set of indices into graph_
46+
int set = OPEN; // Index into rr_non_config_node_sets_
3847
};
3948

4049
// Perform a DFS traversal marking everything reachable with the same set id
@@ -43,8 +52,9 @@ class EdgeGroups {
4352
// Set of non-configurable edges.
4453
std::unordered_map<int, node_data> graph_;
4554

46-
// Compact set of node sets. Map key is arbitrary.
47-
std::vector<std::vector<int>> rr_non_config_node_sets_map_;
55+
// Connected components, representing nodes connected by non-configurable edges.
56+
// Order is arbitrary.
57+
std::vector<std::vector<int>> rr_non_config_node_sets_;
4858
};
4959

5060
#endif

vpr/test/test_edge_groups.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ TEST_CASE("edge_groups_create_sets", "[vpr]") {
1515
// Construct a set of edges that result in these connected sets
1616
std::vector<std::set<int>> connected_sets{{{1, 2, 3, 4, 5, 6, 7, 8},
1717
{9, 0}}};
18+
19+
// Build chains from the given connected sets
1820
int max_node_id = 0;
1921
std::vector<std::pair<int, int>> edges;
2022
for (auto set : connected_sets) {
@@ -30,9 +32,14 @@ TEST_CASE("edge_groups_create_sets", "[vpr]") {
3032

3133
// Build the id map for node IDs
3234
std::vector<int> nodes(max_node_id + 1);
35+
36+
// Initialize nodes to [0, 1, ..., max_node_id]
3337
std::iota(nodes.begin(), nodes.end(), 0);
38+
39+
// Create a Mersenne Twister psuedo-random number generator with seed 1
3440
std::mt19937 g(1);
3541

42+
// Run the test many times, the PRNG will give differently shuffled inputs
3643
for (int i = 0; i < 1000; i++) {
3744
// Shuffle node IDs
3845
auto random_nodes = nodes;

0 commit comments

Comments
 (0)