Skip to content

Commit 8e7efe5

Browse files
authored
Merge pull request #1972 from verilog-to-routing/librrgraph
Now rr_graph -related source files are placed in a separated library ``librrgraph``
2 parents b176820 + 04f0a02 commit 8e7efe5

40 files changed

+347
-267
lines changed

doc/_doxygen/librrgraph.dox

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PROJECT_NAME = "Verilog to Routing - LIBRRGRAPH"
2+
OUTPUT_DIRECTORY = ../_build/doxygen/librrgraph
3+
FULL_PATH_NAMES = NO
4+
OPTIMIZE_OUTPUT_FOR_C = YES
5+
EXTRACT_ALL = YES
6+
EXTRACT_PRIVATE = YES
7+
EXTRACT_STATIC = YES
8+
WARN_IF_UNDOCUMENTED = NO
9+
INPUT = ../../libs/librrgraph
10+
RECURSIVE = YES
11+
GENERATE_HTML = NO
12+
GENERATE_LATEX = NO
13+
GENERATE_XML = YES

doc/src/api/vpr/rr_graph.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ RRGraphView
66
-----------
77

88
.. doxygenfile:: rr_graph_view.h
9-
:project: vpr
9+
:project: librrgraph
1010
:sections: detaileddescription
1111

1212
.. doxygenclass:: RRGraphView
13-
:project: vpr
13+
:project: librrgraph
1414
:members:
1515

1616
RRGraphBuilder
1717
--------------
1818

1919
.. doxygenfile:: rr_graph_builder.h
20-
:project: vpr
20+
:project: librrgraph
2121
:sections: detaileddescription
2222

2323
.. doxygenclass:: RRGraphBuilder
24-
:project: vpr
24+
:project: librrgraph
2525
:members:
2626

2727
RRSpatialLookup
2828
---------------
2929

3030
.. doxygenfile:: rr_spatial_lookup.h
31-
:project: vpr
31+
:project: librrgraph
3232
:sections: detaileddescription
3333

3434
.. doxygenclass:: RRSpatialLookup
35-
:project: vpr
35+
:project: librrgraph
3636
:members:
3737

doc/src/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358
"ace2": "../_build/doxygen/ace2/xml",
359359
"ODIN_II": "../_build/doxygen/ODIN_II/xml",
360360
"blifexplorer": "../_build/doxygen/blifexplorer/xml",
361+
"librrgraph": "../_build/doxygen/librrgraph/xml",
361362
}
362363
breathe_default_project = "vpr"
363364

libs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ endif()
1717
if(${VTR_ENABLE_CAPNPROTO})
1818
add_subdirectory(libvtrcapnproto)
1919
endif()
20+
add_subdirectory(librrgraph)

libs/librrgraph/CMakeLists.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
3+
project("librrgraph")
4+
5+
# Source file and library
6+
file(GLOB_RECURSE LIB_SOURCES src/*/*.cpp)
7+
file(GLOB_RECURSE LIB_HEADERS src/*/*.h)
8+
files_to_dirs(LIB_HEADERS LIB_INCLUDE_DIRS)
9+
10+
#Remove test executable from library
11+
list(REMOVE_ITEM LIB_SOURCES ${EXEC_SOURCES})
12+
13+
#Create the library
14+
add_library(librrgraph STATIC
15+
${LIB_HEADERS}
16+
${LIB_SOURCES}
17+
)
18+
19+
target_include_directories(librrgraph PUBLIC ${LIB_INCLUDE_DIRS})
20+
21+
set_target_properties(librrgraph PROPERTIES PREFIX "") #Avoid extra 'lib' prefix
22+
23+
#Specify link-time dependancies
24+
target_link_libraries(librrgraph
25+
libvtrutil
26+
libarchfpga
27+
)
28+
29+
target_compile_definitions(librrgraph PUBLIC ${INTERCHANGE_SCHEMA_HEADERS})
30+
31+
# Unit tests
32+
#file(GLOB_RECURSE TEST_SOURCES test/*.cpp)
33+
#add_executable(test_rr_graph ${TEST_SOURCES})
34+
#target_link_libraries(test_rr_graph
35+
# librrgraph)
36+
37+
# Run unit tests: comment out for now
38+
#add_test(NAME test_rr_graph COMMAND test_rr_graph --use-colour=yes)
File renamed without changes.

vpr/src/device/rr_graph_builder.cpp renamed to libs/librrgraph/src/base/rr_graph_builder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ void RRGraphBuilder::reorder_nodes(e_rr_node_reorder_algorithm reorder_rr_graph_
124124
for (auto u : src_order)
125125
dest_order[u] = RRNodeId(cur_idx++);
126126

127+
VTR_ASSERT_SAFE(node_storage_.validate(rr_switch_inf_));
127128
node_storage_.reorder(dest_order, src_order);
129+
VTR_ASSERT_SAFE(node_storage_.validate(rr_switch_inf_));
128130

129131
node_lookup().reorder(dest_order);
130132

vpr/src/device/rr_graph_builder.h renamed to libs/librrgraph/src/base/rr_graph_builder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,19 @@ class RRGraphBuilder {
285285
rr_switch_inf_.resize(size);
286286
}
287287

288-
/** brief Validate that edge data is partitioned correctly
288+
/** @brief Validate that edge data is partitioned correctly
289289
* @note This function is used to validate the correctness of the routing resource graph in terms
290290
* of graph attributes. Strongly recommend to call it when you finish the building a routing resource
291291
* graph. If you need more advance checks, which are related to architecture features, you should
292292
* consider to use the check_rr_graph() function or build your own check_rr_graph() function. */
293293
inline bool validate() const {
294-
return node_storage_.validate();
294+
return node_storage_.validate(rr_switch_inf_);
295295
}
296296

297297
/** @brief Sorts edge data such that configurable edges appears before
298298
* non-configurable edges. */
299299
inline void partition_edges() {
300-
node_storage_.partition_edges();
300+
return node_storage_.partition_edges(rr_switch_inf_);
301301
}
302302

303303
/** @brief Init per node fan-in data. Should only be called after all edges have

vpr/src/device/rr_graph_obj.h renamed to libs/librrgraph/src/base/rr_graph_obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
#include "arch_types.h"
207207

208208
/* VPR header files go third */
209-
#include "vpr_types.h"
209+
#include "rr_node_types.h"
210210
#include "rr_graph_fwd.h"
211211

212212
class RRGraph {

vpr/src/route/rr_graph_storage.cpp renamed to libs/librrgraph/src/base/rr_graph_storage.cpp

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
#include <climits>
2+
#include "arch_types.h"
13
#include "rr_graph_storage.h"
24

35
#include <algorithm>
46

5-
#include "globals.h"
6-
77
void t_rr_graph_storage::reserve_edges(size_t num_edges) {
88
edge_src_node_.reserve(num_edges);
99
edge_dest_node_.reserve(num_edges);
@@ -488,8 +488,7 @@ void t_rr_graph_storage::mark_edges_as_rr_switch_ids() {
488488
remapped_edges_ = true;
489489
}
490490

491-
/* TODO: This API should be moved to RRGraphBuilder */
492-
void t_rr_graph_storage::partition_edges() {
491+
void t_rr_graph_storage::partition_edges(const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) {
493492
if (partitioned_) {
494493
return;
495494
}
@@ -504,40 +503,65 @@ void t_rr_graph_storage::partition_edges() {
504503
std::sort(
505504
edge_sort_iterator(this, 0),
506505
edge_sort_iterator(this, edge_src_node_.size()),
507-
edge_compare_src_node_and_configurable_first(g_vpr_ctx.mutable_device().rr_graph_builder.rr_switch()));
506+
edge_compare_src_node_and_configurable_first(rr_switches));
508507

509508
partitioned_ = true;
510509

511510
assign_first_edges();
512511

513-
VTR_ASSERT_SAFE(validate());
512+
VTR_ASSERT_SAFE(validate(rr_switches));
514513
}
515514

516-
t_edge_size t_rr_graph_storage::num_configurable_edges(const RRNodeId& id) const {
515+
t_edge_size t_rr_graph_storage::num_configurable_edges(RRNodeId id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
517516
VTR_ASSERT(!node_first_edge_.empty() && remapped_edges_);
518517

519-
const auto& device_ctx = g_vpr_ctx.device();
520-
const auto& rr_graph = device_ctx.rr_graph;
521518
auto first_id = size_t(node_first_edge_[id]);
522519
auto last_id = size_t((&node_first_edge_[id])[1]);
523520
for (size_t idx = first_id; idx < last_id; ++idx) {
524521
auto switch_idx = edge_switch_[RREdgeId(idx)];
525-
if (!rr_graph.rr_switch_inf(RRSwitchId(switch_idx)).configurable()) {
522+
if (!rr_switches[RRSwitchId(switch_idx)].configurable()) {
526523
return idx - first_id;
527524
}
528525
}
529526

530527
return last_id - first_id;
531528
}
532529

533-
t_edge_size t_rr_graph_storage::num_non_configurable_edges(const RRNodeId& id) const {
534-
return num_edges(id) - num_configurable_edges(id);
530+
t_edge_size t_rr_graph_storage::num_non_configurable_edges(RRNodeId node, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
531+
return num_edges(node) - num_configurable_edges(node, rr_switches);
532+
}
533+
534+
bool t_rr_graph_storage::edge_is_configurable(RRNodeId id, t_edge_size iedge, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
535+
auto iswitch = edge_switch(id, iedge);
536+
return rr_switches[RRSwitchId(iswitch)].configurable();
537+
}
538+
539+
bool t_rr_graph_storage::validate_node(RRNodeId node_id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
540+
t_edge_size iedge = 0;
541+
for (auto edge : edges(node_id)) {
542+
if (edge < num_configurable_edges(node_id, rr_switches)) {
543+
if (!edge_is_configurable(node_id, edge, rr_switches)) {
544+
VTR_LOG_ERROR("RR Node non-configurable edge found in configurable edge list");
545+
}
546+
} else {
547+
if (edge_is_configurable(node_id, edge, rr_switches)) {
548+
VTR_LOG_ERROR("RR Node configurable edge found in non-configurable edge list");
549+
}
550+
}
551+
++iedge;
552+
}
553+
554+
if (iedge != num_edges(node_id)) {
555+
VTR_LOG_ERROR("RR Node Edge iteration does not match edge size");
556+
}
557+
558+
return true;
535559
}
536560

537-
bool t_rr_graph_storage::validate() const {
561+
bool t_rr_graph_storage::validate(const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
538562
bool all_valid = verify_first_edges();
539563
for (size_t inode = 0; inode < size(); ++inode) {
540-
all_valid = (*this)[inode].validate() || all_valid;
564+
all_valid = validate_node(RRNodeId(inode), rr_switches) || all_valid;
541565
}
542566
return all_valid;
543567
}
@@ -567,37 +591,26 @@ const char* t_rr_graph_storage::node_side_string(RRNodeId id) const {
567591
return SIDE_STRING[NUM_SIDES];
568592
}
569593

570-
float t_rr_graph_storage::node_R(RRNodeId id) const {
571-
auto& device_ctx = g_vpr_ctx.device();
572-
return device_ctx.rr_rc_data[node_rc_index(id)].R;
573-
}
574-
575-
float t_rr_graph_storage::node_C(RRNodeId id) const {
576-
auto& device_ctx = g_vpr_ctx.device();
577-
VTR_ASSERT(node_rc_index(id) < (short)device_ctx.rr_rc_data.size());
578-
return device_ctx.rr_rc_data[node_rc_index(id)].C;
579-
}
580-
581594
void t_rr_graph_storage::set_node_ptc_num(RRNodeId id, short new_ptc_num) {
582595
node_ptc_[id].ptc_.pin_num = new_ptc_num; //TODO: eventually remove
583596
}
584597
void t_rr_graph_storage::set_node_pin_num(RRNodeId id, short new_pin_num) {
585598
if (node_type(id) != IPIN && node_type(id) != OPIN) {
586-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'pin_num' for non-IPIN/OPIN type '%s'", node_type_string(id));
599+
VTR_LOG_ERROR("Attempted to set RR node 'pin_num' for non-IPIN/OPIN type '%s'", node_type_string(id));
587600
}
588601
node_ptc_[id].ptc_.pin_num = new_pin_num;
589602
}
590603

591604
void t_rr_graph_storage::set_node_track_num(RRNodeId id, short new_track_num) {
592605
if (node_type(id) != CHANX && node_type(id) != CHANY) {
593-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'track_num' for non-CHANX/CHANY type '%s'", node_type_string(id));
606+
VTR_LOG_ERROR("Attempted to set RR node 'track_num' for non-CHANX/CHANY type '%s'", node_type_string(id));
594607
}
595608
node_ptc_[id].ptc_.track_num = new_track_num;
596609
}
597610

598611
void t_rr_graph_storage::set_node_class_num(RRNodeId id, short new_class_num) {
599612
if (node_type(id) != SOURCE && node_type(id) != SINK) {
600-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'class_num' for non-SOURCE/SINK type '%s'", node_type_string(id));
613+
VTR_LOG_ERROR("Attempted to set RR node 'class_num' for non-SOURCE/SINK type '%s'", node_type_string(id));
601614
}
602615
node_ptc_[id].ptc_.class_num = new_class_num;
603616
}
@@ -612,7 +625,7 @@ static short get_node_pin_num(
612625
RRNodeId id) {
613626
auto node_type = node_storage[id].type_;
614627
if (node_type != IPIN && node_type != OPIN) {
615-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to access RR node 'pin_num' for non-IPIN/OPIN type '%s'", rr_node_typename[node_type]);
628+
VTR_LOG_ERROR("Attempted to access RR node 'pin_num' for non-IPIN/OPIN type '%s'", rr_node_typename[node_type]);
616629
}
617630
return node_ptc[id].ptc_.pin_num;
618631
}
@@ -623,7 +636,7 @@ static short get_node_track_num(
623636
RRNodeId id) {
624637
auto node_type = node_storage[id].type_;
625638
if (node_type != CHANX && node_type != CHANY) {
626-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to access RR node 'track_num' for non-CHANX/CHANY type '%s'", rr_node_typename[node_type]);
639+
VTR_LOG_ERROR("Attempted to access RR node 'track_num' for non-CHANX/CHANY type '%s'", rr_node_typename[node_type]);
627640
}
628641
return node_ptc[id].ptc_.track_num;
629642
}
@@ -634,7 +647,7 @@ static short get_node_class_num(
634647
RRNodeId id) {
635648
auto node_type = node_storage[id].type_;
636649
if (node_type != SOURCE && node_type != SINK) {
637-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to access RR node 'class_num' for non-SOURCE/SINK type '%s'", rr_node_typename[node_type]);
650+
VTR_LOG_ERROR("Attempted to access RR node 'class_num' for non-SOURCE/SINK type '%s'", rr_node_typename[node_type]);
638651
}
639652
return node_ptc[id].ptc_.class_num;
640653
}
@@ -684,8 +697,8 @@ void t_rr_graph_storage::set_node_coordinates(RRNodeId id, short x1, short y1, s
684697
void t_rr_graph_storage::set_node_cost_index(RRNodeId id, RRIndexedDataId new_cost_index) {
685698
auto& node = node_storage_[id];
686699
if ((size_t)new_cost_index >= std::numeric_limits<decltype(node.cost_index_)>::max()) {
687-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set cost_index_ %zu above cost_index storage max value.",
688-
new_cost_index);
700+
VTR_LOG_ERROR("Attempted to set cost_index_ %zu above cost_index storage max value.",
701+
new_cost_index);
689702
}
690703
node.cost_index_ = (size_t)new_cost_index;
691704
}
@@ -701,19 +714,19 @@ void t_rr_graph_storage::set_node_capacity(RRNodeId id, short new_capacity) {
701714

702715
void t_rr_graph_storage::set_node_direction(RRNodeId id, Direction new_direction) {
703716
if (node_type(id) != CHANX && node_type(id) != CHANY) {
704-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'direction' for non-channel type '%s'", node_type_string(id));
717+
VTR_LOG_ERROR("Attempted to set RR node 'direction' for non-channel type '%s'", node_type_string(id));
705718
}
706719
node_storage_[id].dir_side_.direction = new_direction;
707720
}
708721

709722
void t_rr_graph_storage::add_node_side(RRNodeId id, e_side new_side) {
710723
if (node_type(id) != IPIN && node_type(id) != OPIN) {
711-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'side' for non-channel type '%s'", node_type_string(id));
724+
VTR_LOG_ERROR("Attempted to set RR node 'side' for non-channel type '%s'", node_type_string(id));
712725
}
713726
std::bitset<NUM_SIDES> side_bits = node_storage_[id].dir_side_.sides;
714727
side_bits[size_t(new_side)] = true;
715728
if (side_bits.to_ulong() > CHAR_MAX) {
716-
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Invalid side '%s' to be added to rr node %u", SIDE_STRING[new_side], size_t(id));
729+
VTR_LOG_ERROR("Invalid side '%s' to be added to rr node %u", SIDE_STRING[new_side], size_t(id));
717730
}
718731
node_storage_[id].dir_side_.sides = static_cast<unsigned char>(side_bits.to_ulong());
719732
}
@@ -760,7 +773,6 @@ t_rr_graph_view t_rr_graph_storage::view() const {
760773
// should generally be called before creating such references.
761774
void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
762775
const vtr::vector<RRNodeId, RRNodeId>& inverse_order) {
763-
VTR_ASSERT_SAFE(validate());
764776
VTR_ASSERT(order.size() == inverse_order.size());
765777
{
766778
auto old_node_storage = node_storage_;
@@ -805,6 +817,4 @@ void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
805817
node_fan_in_[order[RRNodeId(i)]] = old_node_fan_in[RRNodeId(i)];
806818
}
807819
}
808-
809-
VTR_ASSERT_SAFE(validate());
810820
}

0 commit comments

Comments
 (0)