Skip to content

Commit f112df8

Browse files
Address PR comments
1 parent 3a0ad03 commit f112df8

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
lines changed

libs/librrgraph/src/base/rr_graph_builder.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,14 @@ class RRGraphBuilder {
351351
inline void alloc_and_load_edges(const t_rr_edge_info_set* rr_edges_to_create) {
352352
node_storage_.alloc_and_load_edges(rr_edges_to_create);
353353
}
354-
354+
355+
/** @brief Removes a given list of RREdgeIds for the RR Graph.
356+
* This method does not preserve the order of edges. If you're
357+
* calling it after partition_edges has been called, you need
358+
* to call it again.
359+
*
360+
* @param rr_edges_to_remove list of RREdgeIds to be removed
361+
*/
355362
inline void remove_edges(std::vector<RREdgeId>& rr_edges_to_remove) {
356363
node_storage_.remove_edges(rr_edges_to_remove);
357364
}

libs/librrgraph/src/base/rr_graph_storage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,32 @@ void t_rr_graph_storage::alloc_and_load_edges(const t_rr_edge_info_set* rr_edges
6262
void t_rr_graph_storage::remove_edges(std::vector<RREdgeId>& rr_edges_to_remove) {
6363
size_t starting_edge_count = edge_dest_node_.size();
6464

65+
// Sort and make sure all edge indices are unique
6566
vtr::uniquify(rr_edges_to_remove);
67+
VTR_ASSERT_SAFE(std::is_sorted(rr_edges_to_remove.begin(), rr_edges_to_remove.end()));
6668

69+
// Index of the last edge
6770
size_t edge_list_end = edge_dest_node_.size() - 1;
71+
72+
// Iterate backwards through the list of indices we want to remove.
6873
for (auto it = rr_edges_to_remove.rbegin(); it != rr_edges_to_remove.rend(); ++it) {
6974
RREdgeId erase_idx = *it;
7075

76+
// Copy what's at the end of the list to the index we wanted to remove
7177
edge_dest_node_[erase_idx] = edge_dest_node_[RREdgeId(edge_list_end)];
7278
edge_src_node_[erase_idx] = edge_src_node_[RREdgeId(edge_list_end)];
7379
edge_switch_[erase_idx] = edge_switch_[RREdgeId(edge_list_end)];
7480
edge_remapped_[erase_idx] = edge_remapped_[RREdgeId(edge_list_end)];
7581

82+
// At this point we have no copies of what was at erase_idx and two copies of
83+
// what was at the end of the list. If we make the list one element shorter,
84+
// we end up with a list that has removed the element at erase_idx.
7685
edge_list_end--;
7786

7887
}
7988

89+
// We have a new index to the end of the list, call erase on the elements past that index
90+
// to update the std::vector and shrink the actual data structures.
8091
edge_dest_node_.erase(edge_dest_node_.begin() + edge_list_end + 1, edge_dest_node_.end());
8192
edge_src_node_.erase(edge_src_node_.begin() + edge_list_end + 1, edge_src_node_.end());
8293
edge_switch_.erase(edge_switch_.begin() + edge_list_end + 1, edge_switch_.end());

libs/librrgraph/src/base/rr_graph_storage.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,10 @@ class t_rr_graph_storage {
400400
return vtr::StrongIdRange<RREdgeId>(first_edge(id), last_edge(id));
401401
}
402402

403-
403+
/** @brief Returns a range of all edges in the RR Graph.
404+
* This method does not depend on the edges begin correctly
405+
* sorted and can be used before partition_edges is called.
406+
*/
404407
inline vtr::StrongIdRange<RREdgeId> all_edges() const {
405408
return vtr::StrongIdRange<RREdgeId>(RREdgeId(0), RREdgeId(edge_src_node_.size()));
406409
}
@@ -781,6 +784,13 @@ class t_rr_graph_storage {
781784
/** @brief Adds a batch of edges.*/
782785
void alloc_and_load_edges(const t_rr_edge_info_set* rr_edges_to_create);
783786

787+
/** @brief Removes a given list of RREdgeIds for the RR Graph.
788+
* This method does not preserve the order of edges. If you're
789+
* calling it after partition_edges has been called, you need
790+
* to call it again.
791+
*
792+
* @param rr_edges_to_remove list of RREdgeIds to be removed
793+
*/
784794
void remove_edges(std::vector<RREdgeId>& rr_edges_to_remove);
785795

786796
/* Edge finalization methods */

libs/librrgraph/src/base/rr_graph_view.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ class RRGraphView {
594594
return vtr::make_range(edge_idx_iterator(0), edge_idx_iterator(num_edges(id)));
595595
}
596596

597+
/** @brief Returns a range of all edges in the RR Graph.
598+
* This method does not depend on the edges begin correctly
599+
* sorted and can be used before partition_edges is called.
600+
*/
597601
inline vtr::StrongIdRange<RREdgeId> all_edges() const {
598602
return node_storage_.all_edges();
599603
}

vpr/src/route/rr_graph_generation/interposer_cut.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "rr_graph_view.h"
1111
#include "rr_node_types.h"
1212
#include "rr_spatial_lookup.h"
13+
#include "vpr_error.h"
1314
#include "vtr_assert.h"
14-
#include "vtr_log.h"
1515

1616
#include "interposer_cut.h"
1717

@@ -43,23 +43,20 @@ static short node_xstart(const RRGraphView& rr_graph, RRNodeId node) {
4343
switch (rr_graph.node_direction(node)) {
4444
case Direction::DEC:
4545
return rr_graph.node_xhigh(node);
46-
break;
4746

4847
case Direction::INC:
4948
return rr_graph.node_xlow(node);
50-
break;
5149

5250
case Direction::NONE:
5351
VTR_ASSERT(rr_graph.node_xlow(node) == rr_graph.node_xhigh(node));
5452
return (rr_graph.node_xlow(node));
55-
break;
5653

5754
case Direction::BIDIR:
58-
VTR_ASSERT_MSG(false, "Bidir node has no starting point");
55+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Bidir node has no starting point.");
5956
break;
6057

6158
default:
62-
VTR_ASSERT(false);
59+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Invalid RR node direction.");
6360
break;
6461
}
6562
}
@@ -76,23 +73,20 @@ static short node_ystart(const RRGraphView& rr_graph, RRNodeId node) {
7673
switch (rr_graph.node_direction(node)) {
7774
case Direction::DEC:
7875
return rr_graph.node_yhigh(node);
79-
break;
8076

8177
case Direction::INC:
8278
return rr_graph.node_ylow(node);
83-
break;
8479

8580
case Direction::NONE:
8681
VTR_ASSERT(rr_graph.node_ylow(node) == rr_graph.node_yhigh(node));
8782
return (rr_graph.node_ylow(node));
88-
break;
8983

9084
case Direction::BIDIR:
91-
VTR_ASSERT_MSG(false, "Bidir node has no starting point");
85+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Bidir node has no starting point.");
9286
break;
9387

9488
default:
95-
VTR_ASSERT(false);
89+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Invalid RR node direction.");
9690
break;
9791
}
9892
}
@@ -106,10 +100,6 @@ std::vector<RREdgeId> mark_interposer_cut_edges_for_removal(const RRGraphView& r
106100
RRNodeId src_node = rr_graph.edge_src_node(edge_id);
107101
RRNodeId sink_node = rr_graph.edge_sink_node(edge_id);
108102

109-
if (src_node == RRNodeId(5866) && sink_node == RRNodeId(5604)) {
110-
VTR_LOG("HI\n");
111-
}
112-
113103
// TODO: ignoring ChanZ nodes for now
114104
if (rr_graph.node_type(src_node) == e_rr_type::CHANZ || rr_graph.node_type(sink_node) == e_rr_type::CHANZ) {
115105
continue;
@@ -147,7 +137,10 @@ std::vector<RREdgeId> mark_interposer_cut_edges_for_removal(const RRGraphView& r
147137
}
148138

149139
/**
150-
* @brief Update a CHANY node's bounding box in RRGraph and SpatialLookup entries. This function assumes that the channel node actually crosses the cut location and might not function correctly otherwise.
140+
* @brief Update a CHANY node's bounding box in RRGraph and SpatialLookup entries.
141+
* This function assumes that the channel node actually crosses the cut location and
142+
* might not function correctly otherwise.
143+
*
151144
* This is a low level function, you should use cut_channel_node that wraps this up in a nicer API.
152145
*/
153146
static void cut_chan_y_node(RRNodeId node, int x_low, int y_low, int x_high, int y_high, int layer, int ptc_num, int cut_loc_y, Direction node_direction, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup) {
@@ -173,7 +166,10 @@ static void cut_chan_y_node(RRNodeId node, int x_low, int y_low, int x_high, int
173166
}
174167

175168
/**
176-
* @brief Update a CHANX node's bounding box in RRGraph and SpatialLookup entries. This function assumes that the channel node actually crosses the cut location and might not function correctly otherwise.
169+
* @brief Update a CHANX node's bounding box in RRGraph and SpatialLookup entries.
170+
* This function assumes that the channel node actually crosses the cut location and
171+
* might not function correctly otherwise.
172+
*
177173
* This is a low level function, you should use cut_channel_node that wraps this up in a nicer API.
178174
*/
179175
static void cut_chan_x_node(RRNodeId node, int x_low, int y_low, int x_high, int y_high, int layer, int ptc_num, int cut_loc_x, Direction node_direction, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup) {
@@ -205,7 +201,6 @@ static void cut_chan_x_node(RRNodeId node, int x_low, int y_low, int x_high, int
205201
* @param cut_loc location of vertical interposer cut line
206202
* @param interposer_cut_type Type of the interposer cut line (Horizontal or vertical)
207203
* @param sg_node_indices Sorted list of scatter-gather node IDs. We do not want to cut these nodes as they're allowed to cross an interposer cut line.
208-
* @note This function is very similar to cut_chan_y_node. If you're modifying this you probably also want to modify that function too.
209204
*/
210205
static void cut_channel_node(RRNodeId node, int cut_loc, e_interposer_cut_type interposer_cut_type, const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder, RRSpatialLookup& spatial_lookup, const std::vector<std::pair<RRNodeId, int>>& sg_node_indices) {
211206
constexpr auto node_indice_compare = [](RRNodeId l, RRNodeId r) noexcept { return size_t(l) < size_t(r); };

vpr/src/route/rr_graph_generation/rr_node_indices.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void load_block_rr_indices(RRGraphBuilder& rr_graph_builder,
8686
const DeviceGrid& grid,
8787
int* index) {
8888
// Walk through the grid assigning indices to SOURCE/SINK IPIN/OPIN
89-
for (const t_physical_tile_loc grid_loc : grid.all_locations()) {
89+
for (const t_physical_tile_loc& grid_loc : grid.all_locations()) {
9090
//Process each block from its root location
9191
if (grid.is_root_location(grid_loc)) {
9292
t_physical_tile_type_ptr physical_type = grid.get_physical_type(grid_loc);
@@ -458,7 +458,7 @@ void alloc_and_load_intra_cluster_rr_node_indices(RRGraphBuilder& rr_graph_build
458458
const vtr::vector<ClusterBlockId, std::unordered_set<int>>& pin_chains_num,
459459
int* index) {
460460

461-
for (const t_physical_tile_loc grid_loc : grid.all_locations()) {
461+
for (const t_physical_tile_loc& grid_loc : grid.all_locations()) {
462462

463463
// Process each block from its root location
464464
if (grid.is_root_location(grid_loc)) {
@@ -498,7 +498,7 @@ bool verify_rr_node_indices(const DeviceGrid& grid,
498498
const t_rr_graph_storage& rr_nodes,
499499
bool is_flat) {
500500
std::unordered_map<RRNodeId, int> rr_node_counts;
501-
for (t_physical_tile_loc tile_loc : grid.all_locations()) {
501+
for (const t_physical_tile_loc& tile_loc : grid.all_locations()) {
502502
for (e_rr_type rr_type : RR_TYPES) {
503503
// Get the list of nodes at a specific location (x, y)
504504
std::vector<RRNodeId> nodes_from_lookup;

0 commit comments

Comments
 (0)