Skip to content

Now rr_graph -related source files are placed in a separated library librrgraph #1972

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

Merged
merged 21 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
70e01cc
[Lib] Moving rr_graph data structure to a library
tangxifan Feb 10, 2022
4a547e1
[Lib] Add Cmakelist for librrgraph
tangxifan Feb 10, 2022
2e55317
[Lib] Add librrgraph to higher level CMakelist
tangxifan Feb 10, 2022
eddcc08
[VPR] Add librrgraph to the dependency of VPR
tangxifan Feb 10, 2022
f98a93e
[lib] Disable unit tests for now; Focus on compilation errors
tangxifan Feb 10, 2022
cd5f9ee
[Lib] Debugging compilation errors
tangxifan Feb 10, 2022
c7a979d
[Lib] Adapt sources for dependencies on data structures
tangxifan Feb 10, 2022
0f1c3cd
[Lib] Detecting some low-level APIs require global variables; Need sl…
tangxifan Feb 10, 2022
b6840e5
[Lib] Now move edge_is_configurable() and validate() API from rr_node…
tangxifan Feb 10, 2022
56165c6
[Lib] Move validate() function and partition_edges() function from rr…
tangxifan Feb 10, 2022
6631527
[Lib] Resolving dependency problem for rr_node_impl files
tangxifan Feb 10, 2022
6e431d7
[Lib] Now RC data is referenced in the RRGraphView
tangxifan Feb 10, 2022
6a61e7a
[Lib] Fixed all the errors in the librrgraph
tangxifan Feb 11, 2022
dac9b10
[Lib] Fixing type bugs
tangxifan Feb 11, 2022
4d62124
[Lib] Fix compiler warnings
tangxifan Feb 11, 2022
8b830b5
[Lib] Add missing files
tangxifan Feb 11, 2022
f91b728
[VPR] Code format
tangxifan Feb 11, 2022
c583013
[Doc] Fix the broken links in API doc
tangxifan Feb 19, 2022
a4baac7
[Lib] Add code comments
tangxifan Feb 19, 2022
f30c62f
[Doc] Fixing the broken links in API doc
tangxifan Feb 19, 2022
04f0a02
[Doc] Typo
tangxifan Feb 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ endif()
if(${VTR_ENABLE_CAPNPROTO})
add_subdirectory(libvtrcapnproto)
endif()
add_subdirectory(librrgraph)
38 changes: 38 additions & 0 deletions libs/librrgraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.9)

project("librrgraph")

# Source file and library
file(GLOB_RECURSE LIB_SOURCES src/*/*.cpp)
file(GLOB_RECURSE LIB_HEADERS src/*/*.h)
files_to_dirs(LIB_HEADERS LIB_INCLUDE_DIRS)

#Remove test executable from library
list(REMOVE_ITEM LIB_SOURCES ${EXEC_SOURCES})

#Create the library
add_library(librrgraph STATIC
${LIB_HEADERS}
${LIB_SOURCES}
)

target_include_directories(librrgraph PUBLIC ${LIB_INCLUDE_DIRS})

set_target_properties(librrgraph PROPERTIES PREFIX "") #Avoid extra 'lib' prefix

#Specify link-time dependancies
target_link_libraries(librrgraph
libvtrutil
libarchfpga
)

target_compile_definitions(librrgraph PUBLIC ${INTERCHANGE_SCHEMA_HEADERS})

# Unit tests
#file(GLOB_RECURSE TEST_SOURCES test/*.cpp)
#add_executable(test_rr_graph ${TEST_SOURCES})
#target_link_libraries(test_rr_graph
# librrgraph)

# Run unit tests: comment out for now
#add_test(NAME test_rr_graph COMMAND test_rr_graph --use-colour=yes)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ void RRGraphBuilder::reorder_nodes(e_rr_node_reorder_algorithm reorder_rr_graph_
for (auto u : src_order)
dest_order[u] = RRNodeId(cur_idx++);

VTR_ASSERT_SAFE(node_storage_.validate(rr_switch_inf_));
node_storage_.reorder(dest_order, src_order);
VTR_ASSERT_SAFE(node_storage_.validate(rr_switch_inf_));

node_lookup().reorder(dest_order);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,19 @@ class RRGraphBuilder {
rr_switch_inf_.resize(size);
}

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

/** @brief Sorts edge data such that configurable edges appears before
* non-configurable edges. */
inline void partition_edges() {
node_storage_.partition_edges();
return node_storage_.partition_edges(rr_switch_inf_);
}

/** @brief Init per node fan-in data. Should only be called after all edges have
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
#include "arch_types.h"

/* VPR header files go third */
#include "vpr_types.h"
#include "rr_node_types.h"
#include "rr_graph_fwd.h"

class RRGraph {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <climits>
#include "arch_types.h"
#include "rr_graph_storage.h"

#include <algorithm>

#include "globals.h"

void t_rr_graph_storage::reserve_edges(size_t num_edges) {
edge_src_node_.reserve(num_edges);
edge_dest_node_.reserve(num_edges);
Expand Down Expand Up @@ -488,8 +488,7 @@ void t_rr_graph_storage::mark_edges_as_rr_switch_ids() {
remapped_edges_ = true;
}

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

partitioned_ = true;

assign_first_edges();

VTR_ASSERT_SAFE(validate());
VTR_ASSERT_SAFE(validate(rr_switches));
}

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

const auto& device_ctx = g_vpr_ctx.device();
const auto& rr_graph = device_ctx.rr_graph;
auto first_id = size_t(node_first_edge_[id]);
auto last_id = size_t((&node_first_edge_[id])[1]);
for (size_t idx = first_id; idx < last_id; ++idx) {
auto switch_idx = edge_switch_[RREdgeId(idx)];
if (!rr_graph.rr_switch_inf(RRSwitchId(switch_idx)).configurable()) {
if (!rr_switches[RRSwitchId(switch_idx)].configurable()) {
return idx - first_id;
}
}

return last_id - first_id;
}

t_edge_size t_rr_graph_storage::num_non_configurable_edges(const RRNodeId& id) const {
return num_edges(id) - num_configurable_edges(id);
t_edge_size t_rr_graph_storage::num_non_configurable_edges(RRNodeId node, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
return num_edges(node) - num_configurable_edges(node, rr_switches);
}

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 {
auto iswitch = edge_switch(id, iedge);
return rr_switches[RRSwitchId(iswitch)].configurable();
}

bool t_rr_graph_storage::validate_node(RRNodeId node_id, const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
t_edge_size iedge = 0;
for (auto edge : edges(node_id)) {
if (edge < num_configurable_edges(node_id, rr_switches)) {
if (!edge_is_configurable(node_id, edge, rr_switches)) {
VTR_LOG_ERROR("RR Node non-configurable edge found in configurable edge list");
}
} else {
if (edge_is_configurable(node_id, edge, rr_switches)) {
VTR_LOG_ERROR("RR Node configurable edge found in non-configurable edge list");
}
}
++iedge;
}

if (iedge != num_edges(node_id)) {
VTR_LOG_ERROR("RR Node Edge iteration does not match edge size");
}

return true;
}

bool t_rr_graph_storage::validate() const {
bool t_rr_graph_storage::validate(const vtr::vector<RRSwitchId, t_rr_switch_inf>& rr_switches) const {
bool all_valid = verify_first_edges();
for (size_t inode = 0; inode < size(); ++inode) {
all_valid = (*this)[inode].validate() || all_valid;
all_valid = validate_node(RRNodeId(inode), rr_switches) || all_valid;
}
return all_valid;
}
Expand Down Expand Up @@ -567,37 +591,26 @@ const char* t_rr_graph_storage::node_side_string(RRNodeId id) const {
return SIDE_STRING[NUM_SIDES];
}

float t_rr_graph_storage::node_R(RRNodeId id) const {
auto& device_ctx = g_vpr_ctx.device();
return device_ctx.rr_rc_data[node_rc_index(id)].R;
}

float t_rr_graph_storage::node_C(RRNodeId id) const {
auto& device_ctx = g_vpr_ctx.device();
VTR_ASSERT(node_rc_index(id) < (short)device_ctx.rr_rc_data.size());
return device_ctx.rr_rc_data[node_rc_index(id)].C;
}

void t_rr_graph_storage::set_node_ptc_num(RRNodeId id, short new_ptc_num) {
node_ptc_[id].ptc_.pin_num = new_ptc_num; //TODO: eventually remove
}
void t_rr_graph_storage::set_node_pin_num(RRNodeId id, short new_pin_num) {
if (node_type(id) != IPIN && node_type(id) != OPIN) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'pin_num' for non-IPIN/OPIN type '%s'", node_type_string(id));
VTR_LOG_ERROR("Attempted to set RR node 'pin_num' for non-IPIN/OPIN type '%s'", node_type_string(id));
}
node_ptc_[id].ptc_.pin_num = new_pin_num;
}

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

void t_rr_graph_storage::set_node_class_num(RRNodeId id, short new_class_num) {
if (node_type(id) != SOURCE && node_type(id) != SINK) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'class_num' for non-SOURCE/SINK type '%s'", node_type_string(id));
VTR_LOG_ERROR("Attempted to set RR node 'class_num' for non-SOURCE/SINK type '%s'", node_type_string(id));
}
node_ptc_[id].ptc_.class_num = new_class_num;
}
Expand All @@ -612,7 +625,7 @@ static short get_node_pin_num(
RRNodeId id) {
auto node_type = node_storage[id].type_;
if (node_type != IPIN && node_type != OPIN) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to access RR node 'pin_num' for non-IPIN/OPIN type '%s'", rr_node_typename[node_type]);
VTR_LOG_ERROR("Attempted to access RR node 'pin_num' for non-IPIN/OPIN type '%s'", rr_node_typename[node_type]);
}
return node_ptc[id].ptc_.pin_num;
}
Expand All @@ -623,7 +636,7 @@ static short get_node_track_num(
RRNodeId id) {
auto node_type = node_storage[id].type_;
if (node_type != CHANX && node_type != CHANY) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to access RR node 'track_num' for non-CHANX/CHANY type '%s'", rr_node_typename[node_type]);
VTR_LOG_ERROR("Attempted to access RR node 'track_num' for non-CHANX/CHANY type '%s'", rr_node_typename[node_type]);
}
return node_ptc[id].ptc_.track_num;
}
Expand All @@ -634,7 +647,7 @@ static short get_node_class_num(
RRNodeId id) {
auto node_type = node_storage[id].type_;
if (node_type != SOURCE && node_type != SINK) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to access RR node 'class_num' for non-SOURCE/SINK type '%s'", rr_node_typename[node_type]);
VTR_LOG_ERROR("Attempted to access RR node 'class_num' for non-SOURCE/SINK type '%s'", rr_node_typename[node_type]);
}
return node_ptc[id].ptc_.class_num;
}
Expand Down Expand Up @@ -684,8 +697,8 @@ void t_rr_graph_storage::set_node_coordinates(RRNodeId id, short x1, short y1, s
void t_rr_graph_storage::set_node_cost_index(RRNodeId id, RRIndexedDataId new_cost_index) {
auto& node = node_storage_[id];
if ((size_t)new_cost_index >= std::numeric_limits<decltype(node.cost_index_)>::max()) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set cost_index_ %zu above cost_index storage max value.",
new_cost_index);
VTR_LOG_ERROR("Attempted to set cost_index_ %zu above cost_index storage max value.",
new_cost_index);
}
node.cost_index_ = (size_t)new_cost_index;
}
Expand All @@ -701,19 +714,19 @@ void t_rr_graph_storage::set_node_capacity(RRNodeId id, short new_capacity) {

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

void t_rr_graph_storage::add_node_side(RRNodeId id, e_side new_side) {
if (node_type(id) != IPIN && node_type(id) != OPIN) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Attempted to set RR node 'side' for non-channel type '%s'", node_type_string(id));
VTR_LOG_ERROR("Attempted to set RR node 'side' for non-channel type '%s'", node_type_string(id));
}
std::bitset<NUM_SIDES> side_bits = node_storage_[id].dir_side_.sides;
side_bits[size_t(new_side)] = true;
if (side_bits.to_ulong() > CHAR_MAX) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE, "Invalid side '%s' to be added to rr node %u", SIDE_STRING[new_side], size_t(id));
VTR_LOG_ERROR("Invalid side '%s' to be added to rr node %u", SIDE_STRING[new_side], size_t(id));
}
node_storage_[id].dir_side_.sides = static_cast<unsigned char>(side_bits.to_ulong());
}
Expand Down Expand Up @@ -760,7 +773,6 @@ t_rr_graph_view t_rr_graph_storage::view() const {
// should generally be called before creating such references.
void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
const vtr::vector<RRNodeId, RRNodeId>& inverse_order) {
VTR_ASSERT_SAFE(validate());
VTR_ASSERT(order.size() == inverse_order.size());
{
auto old_node_storage = node_storage_;
Expand Down Expand Up @@ -805,6 +817,4 @@ void t_rr_graph_storage::reorder(const vtr::vector<RRNodeId, RRNodeId>& order,
node_fan_in_[order[RRNodeId(i)]] = old_node_fan_in[RRNodeId(i)];
}
}

VTR_ASSERT_SAFE(validate());
}
Loading