Skip to content

Commit 4e04b79

Browse files
Merge pull request #3268 from verilog-to-routing/check_rr_graph_arch
RR Graph / Architecture Pin Side Consistency Check
2 parents 3ee4a62 + 9790180 commit 4e04b79

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

libs/libarchfpga/src/switchblock_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ enum e_directionality {
1818
/**
1919
* @brief At the intersection of routing channels, left, right, top and bottom specify the x- and y-directed channels
2020
* while above and under specify the switch block wires one a layer above or below the current one. above and below
21-
* are only used for multi-layer FPGAs.
21+
* are only used for multi-layer FPGAs. Note that the order of 2D sides is important, as it corresponds to the bit
22+
* order in t_rr_node_data::dir_side_.sides.
2223
*/
2324
enum e_side : unsigned char {
2425
TOP = 0,

libs/librrgraph/src/base/check_rr_graph.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ void check_rr_node(const RRGraphView& rr_graph,
473473

474474
e_pin_type class_type = e_pin_type::OPEN;
475475
int class_num_pins = -1;
476+
std::vector<e_side> rr_graph_sides;
477+
std::vector<e_side> arch_side_vec;
476478
switch (rr_type) {
477479
case e_rr_type::SOURCE:
478480
case e_rr_type::SINK:
@@ -511,6 +513,19 @@ void check_rr_node(const RRGraphView& rr_graph,
511513
VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
512514
"in check_rr_node: inode %d (type %d) has a capacity of %d.\n", inode, rr_type, capacity);
513515
}
516+
rr_graph_sides = rr_graph.node_sides(rr_node);
517+
std::tie(std::ignore, std::ignore, arch_side_vec) = get_pin_coordinates(type, ptc_num, std::vector<e_side>(TOTAL_2D_SIDES.begin(), TOTAL_2D_SIDES.end()));
518+
// sides in the architecture are a superset of the sides for a pin in RR Graph. We iterate over the sides stored
519+
// in the RR Graph to ensure that all of them also exist in the architecture.
520+
for (size_t i = 0; i < rr_graph_sides.size(); i++) {
521+
if (std::find(arch_side_vec.begin(), arch_side_vec.end(), rr_graph_sides[i]) == arch_side_vec.end()) {
522+
VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
523+
"in check_rr_node: inode %d (type %d) has a different side '%s' in the RR graph and the architecture.\n",
524+
inode,
525+
rr_type,
526+
TOTAL_2D_SIDE_STRINGS[rr_graph_sides[i]]);
527+
}
528+
}
514529
break;
515530

516531
case e_rr_type::CHANX:

libs/librrgraph/src/base/rr_graph_storage.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ const std::string& t_rr_graph_storage::node_direction_string(RRNodeId id) const
631631
return CONST_DIRECTION_STRING[int_direction];
632632
}
633633

634+
635+
const std::vector<e_side> t_rr_graph_storage::node_sides(RRNodeId id) const {
636+
std::vector<e_side> sides;
637+
for (const e_side& side : TOTAL_2D_SIDES) {
638+
if (is_node_on_specific_side(id, side)) {
639+
sides.push_back(side);
640+
}
641+
}
642+
return sides;
643+
}
644+
634645
const char* t_rr_graph_storage::node_side_string(RRNodeId id) const {
635646
for (const e_side& side : TOTAL_2D_SIDES) {
636647
if (is_node_on_specific_side(id, side)) {
@@ -807,7 +818,7 @@ void t_rr_graph_storage::set_node_direction(RRNodeId id, Direction new_direction
807818

808819
void t_rr_graph_storage::add_node_side(RRNodeId id, e_side new_side) {
809820
if (node_type(id) != e_rr_type::IPIN && node_type(id) != e_rr_type::OPIN) {
810-
VTR_LOG_ERROR("Attempted to set RR node 'side' for non-channel type '%s'", node_type_string(id));
821+
VTR_LOG_ERROR("Attempted to set RR node 'side' for non-pin type '%s'", node_type_string(id));
811822
}
812823
std::bitset<NUM_2D_SIDES> side_bits = node_storage_[id].dir_side_.sides;
813824
side_bits[size_t(new_side)] = true;

libs/librrgraph/src/base/rr_graph_storage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ class t_rr_graph_storage {
220220
id, side);
221221
}
222222

223+
/** @brief Get the sides where the node locates on. */
224+
const std::vector<e_side> node_sides(RRNodeId id) const;
225+
223226
/* FIXME: This function should be DEPRECATED!
224227
* Developers can easily use the following codes with more flexibility
225228
*

libs/librrgraph/src/base/rr_graph_view.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ class RRGraphView {
432432
return node_storage_.is_node_on_specific_side(node, side);
433433
}
434434

435+
/** @brief Get the sides where the node locates on. */
436+
inline const std::vector<e_side> node_sides(RRNodeId node) const {
437+
return node_storage_.node_sides(node);
438+
}
439+
435440
/** @brief Return a string representing the side of a routing resource node.
436441
*/
437442
inline const char* node_side_string(RRNodeId node) const {

vpr/src/util/vpr_utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,9 @@ RRNodeId get_pin_rr_node_id(const RRSpatialLookup& rr_spatial_lookup,
16791679
std::tie(x_offset, y_offset, pin_sides) = get_pin_coordinates(physical_tile, pin_physical_num, std::vector<e_side>(TOTAL_2D_SIDES.begin(), TOTAL_2D_SIDES.end()));
16801680
VTR_ASSERT(!x_offset.empty());
16811681
RRNodeId node_id = RRNodeId::INVALID();
1682+
// Pin sides from get_pin_coordinates are those specified in the architecture. However, when
1683+
// adding pins to the RR Graph, not all sides may be included (depending on the block’s location).
1684+
// Therefore, we iterate over all sides to find a valid node id.
16821685
for (int coord_idx = 0; coord_idx < (int)pin_sides.size(); coord_idx++) {
16831686
node_id = rr_spatial_lookup.find_node(root_loc.layer_num,
16841687
root_loc.x + x_offset[coord_idx],

0 commit comments

Comments
 (0)