Intermediate change from vector of ints to RRNodeId
- should fail at compile time
- need some function to tell me if a RRNodeId is in range of the
keys()
diff --git a/vpr/src/base/read_route.cpp b/vpr/src/base/read_route.cpp
index b5cf1d0..0afa7b0 100644
--- a/vpr/src/base/read_route.cpp
+++ b/vpr/src/base/read_route.cpp
@@ -202,7 +202,7 @@
/*remember the position of the last line in order to go back*/
streampos oldpos = fp.tellg();
- int inode, x, y, x2, y2, ptc, switch_id, offset;
+ int x, y, x2, y2, ptc, switch_id, offset;
int node_count = 0;
string input;
std::vector<std::string> tokens;
@@ -231,7 +231,7 @@
return;
} else if (tokens[0] == "Node:") {
/*An actual line, go through each node and add it to the route tree*/
- inode = atoi(tokens[1].c_str());
+ RRNodeId inode (atoi(tokens[1].c_str()));
auto& node = device_ctx.rr_nodes[inode];
/*First node needs to be source. It is isolated to correctly set heap head.*/
diff --git a/vpr/src/base/stats.cpp b/vpr/src/base/stats.cpp
index a7df305..acd9daa 100644
--- a/vpr/src/base/stats.cpp
+++ b/vpr/src/base/stats.cpp
@@ -261,7 +261,7 @@
/* Loads the two arrays passed in with the total occupancy at each of the *
* channel segments in the FPGA. */
static void load_channel_occupancies(vtr::Matrix<int>& chanx_occ, vtr::Matrix<int>& chany_occ) {
- int i, j, inode;
+ int i, j;
t_trace *tptr;
t_rr_type rr_type;
@@ -281,7 +281,7 @@
tptr = route_ctx.trace_head[net_id];
while (tptr != nullptr) {
- inode = tptr->index;
+ auto inode = tptr->index;
rr_type = device_ctx.rr_nodes[inode].type();
if (rr_type == SINK) {
@@ -316,7 +316,6 @@
auto& device_ctx = g_vpr_ctx.device();
t_trace *tptr, *prevptr;
- int inode;
t_rr_type curr_type, prev_type;
int bends, length, segments;
@@ -329,7 +328,7 @@
vpr_throw(VPR_ERROR_OTHER, __FILE__, __LINE__,
"in get_num_bends_and_length: net #%lu has no traceback.\n", size_t(inet));
}
- inode = prevptr->index;
+ auto inode = prevptr->index;
prev_type = device_ctx.rr_nodes[inode].type();
tptr = prevptr->next;
diff --git a/vpr/src/base/vpr_context.h b/vpr/src/base/vpr_context.h
index df5743d..0b788d6 100644
--- a/vpr/src/base/vpr_context.h
+++ b/vpr/src/base/vpr_context.h
@@ -6,6 +6,7 @@
#include <csignal> //for sig_atomic_t
#include "vpr_types.h"
+#include "vtr_vector.h"
#include "vtr_matrix.h"
#include "vtr_ndmatrix.h"
#include "atom_netlist.h"
@@ -128,7 +129,7 @@
t_chan_width chan_width;
/* Structures to define the routing architecture of the FPGA. */
- std::vector<t_rr_node> rr_nodes; /* autogenerated in build_rr_graph */
+ vtr::vector<RRNodeId, t_rr_node> rr_nodes; /* autogenerated in build_rr_graph */
int num_rr_indexed_data;
t_rr_indexed_data *rr_indexed_data; /* [0 .. num_rr_indexed_data-1] */
@@ -228,11 +229,11 @@
vtr::vector_map<ClusterNetId, t_trace*> trace_head, trace_tail;
vtr::vector_map<ClusterNetId, std::unordered_set<int>> trace_nodes;
- vtr::vector_map<ClusterNetId, std::vector<int>> net_rr_terminals; /* [0..num_nets-1][0..num_pins-1] */
+ vtr::vector_map<ClusterNetId, std::vector<RRNodeId>> net_rr_terminals; /* [0..num_nets-1][0..num_pins-1] */
vtr::vector_map<ClusterBlockId, std::vector<int>> rr_blk_source; /* [0..num_blocks-1][0..num_class-1] */
- std::vector<t_rr_node_route_inf> rr_node_route_inf; /* [0..device_ctx.num_rr_nodes-1] */
+ vtr::vector<RRNodeId, t_rr_node_route_inf> rr_node_route_inf; /* [0..device_ctx.rr_nodes.size()-1] */
//Information about current routing status of each net
vtr::vector_map<ClusterNetId, t_net_routing_status> net_status; //[0..cluster_ctx.clb_nlist.nets().size()-1]
diff --git a/vpr/src/base/vpr_types.h b/vpr/src/base/vpr_types.h
index 71c45ab..664c37c 100644
--- a/vpr/src/base/vpr_types.h
+++ b/vpr/src/base/vpr_types.h
@@ -28,6 +28,7 @@
#include "arch_types.h"
#include "atom_netlist_fwd.h"
#include "clustered_netlist_fwd.h"
+#include "rr_node_fwd.h"
#include "constant_nets.h"
#include "clock_modeling.h"
@@ -1063,7 +1064,7 @@
* next: Pointer to the next traceback element in this route. */
struct t_trace {
t_trace *next;
- int index;
+ RRNodeId index;
short iswitch;
};
@@ -1087,7 +1088,7 @@
* Number of times this node must be reached to fully route. *
* occ: The current occupancy of the associated rr node */
struct t_rr_node_route_inf {
- int prev_node;
+ RRNodeId prev_node;
short prev_edge;
float pres_cost;
@@ -1195,6 +1196,6 @@
int chan_width_ = -1;
};
-typedef vtr::vector_map<ClusterBlockId, std::vector<std::vector<int>>> t_clb_opins_used; //[0..num_blocks-1][0..class-1][0..used_pins-1]
+typedef vtr::vector_map<ClusterBlockId, std::vector<std::vector<RRNodeId>>> t_clb_opins_used; //[0..num_blocks-1][0..class-1][0..used_pins-1]
#endif
diff --git a/vpr/src/draw/draw.cpp b/vpr/src/draw/draw.cpp
index c0dc5aa..df49d72 100644
--- a/vpr/src/draw/draw.cpp
+++ b/vpr/src/draw/draw.cpp
@@ -22,6 +22,7 @@
#include "vtr_assert.h"
#include "vtr_matrix.h"
+#include "vtr_vector.h"
#include "vtr_ndoffsetmatrix.h"
#include "vtr_memory.h"
#include "vtr_log.h"
@@ -286,31 +287,31 @@
static void deselect_all();
static void draw_routed_net(ClusterNetId net);
-void draw_partial_route(const std::vector<int>& rr_nodes_to_draw);
+void draw_partial_route(const std::vector<RRNodeId>& rr_nodes_to_draw);
static void draw_rr();
-static void draw_rr_edges(int from_node);
-static void draw_rr_pin(int inode, const t_color& color);
-static void draw_rr_chan(int inode, const t_color color);
-static t_bound_box draw_get_rr_chan_bbox(int inode);
-static void draw_pin_to_chan_edge(int pin_node, int chan_node);
+static void draw_rr_edges(RRNodeId from_node);
+static void draw_rr_pin(RRNodeId inode, const t_color& color);
+static void draw_rr_chan(RRNodeId inode, const t_color color);
+static t_bound_box draw_get_rr_chan_bbox(RRNodeId inode);
+static void draw_pin_to_chan_edge(RRNodeId pin_node, RRNodeId chan_node);
static void draw_x(float x, float y, float size);
-static void draw_pin_to_pin(int opin, int ipin);
+static void draw_pin_to_pin(RRNodeId opin, RRNodeId ipin);
static void draw_rr_switch(float from_x, float from_y, float to_x, float to_y,
bool buffered, bool switch_configurable);
-static void draw_chany_to_chany_edge(int from_node, int to_node,
+static void draw_chany_to_chany_edge(RRNodeId from_node, RRNodeId to_node,
int to_track, short switch_type);
-static void draw_chanx_to_chanx_edge(int from_node, int to_node,
+static void draw_chanx_to_chanx_edge(RRNodeId from_node, RRNodeId to_node,
int to_track, short switch_type);
-static void draw_chanx_to_chany_edge(int chanx_node, int chanx_track, int chany_node,
+static void draw_chanx_to_chany_edge(RRNodeId chanx_node, int chanx_track, RRNodeId chany_node,
int chany_track, enum e_edge_dir edge_dir,
short switch_type);
-static int get_track_num(int inode, const vtr::OffsetMatrix<int>& chanx_track, const vtr::OffsetMatrix<int>& chany_track);
+static int get_track_num(RRNodeId inode, const vtr::OffsetMatrix<int>& chanx_track, const vtr::OffsetMatrix<int>& chany_track);
static bool draw_if_net_highlighted (ClusterNetId inet);
-static void draw_highlight_fan_in_fan_out(const std::set<int>& nodes);
-static void highlight_nets(char *message, int hit_node);
-static int draw_check_rr_node_hit (float click_x, float click_y);
-static std::set<int> draw_expand_non_configurable_rr_nodes(int hit_node);
-static void draw_expand_non_configurable_rr_nodes_recurr(int from_node, std::set<int>& expanded_nodes);
+static void draw_highlight_fan_in_fan_out(const std::set<RRNodeId>& nodes);
+static void highlight_nets(char *message, RRNodeId hit_node);
+static RRNodeId draw_check_rr_node_hit (float click_x, float click_y);
+static std::set<RRNodeId> draw_expand_non_configurable_rr_nodes(RRNodeId hit_node);
+static void draw_expand_non_configurable_rr_nodes_recurr(RRNodeId from_node, std::set<RRNodeId>& expanded_nodes);
static bool highlight_rr_nodes(float x, float y);
static void draw_highlight_blocks_color(t_type_ptr type, ClusterBlockId blk_id);
static void draw_reset_blk_colors();
@@ -327,9 +328,9 @@
static void draw_flyline_timing_edge(t_point start, t_point end, float incr_delay);
static void draw_routed_timing_edge(tatum::NodeId start_tnode, tatum::NodeId end_tnode, float incr_delay, t_color color);
static void draw_routed_timing_edge_connection(tatum::NodeId src_tnode, tatum::NodeId sink_tnode, t_color color);
-static std::vector<int> trace_routed_connection_rr_nodes(const ClusterNetId net_id, const int driver_pin, const int sink_pin);
-static bool trace_routed_connection_rr_nodes_recurr(const t_rt_node* rt_node, int sink_rr_node, std::vector<int>& rr_nodes_on_path);
-static int find_edge(int prev_inode, int inode);
+static std::vector<RRNodeId> trace_routed_connection_rr_nodes(const ClusterNetId net_id, const int driver_pin, const int sink_pin);
+static bool trace_routed_connection_rr_nodes_recurr(const t_rt_node* rt_node, RRNodeId sink_rr_node, std::vector<RRNodeId>& rr_nodes_on_path);
+static int find_edge(RRNodeId prev_inode, RRNodeId inode);
t_color to_t_color(vtr::Color<float> color);
static void draw_color_map_legend(const vtr::ColorMap& cmap);
@@ -763,8 +764,7 @@
/* Space is allocated for draw_rr_node but not initialized because we do *
* not yet know information about the routing resources. */
- draw_state->draw_rr_node = (t_draw_rr_node *) vtr::malloc(
- device_ctx.rr_nodes.size() * sizeof(t_draw_rr_node));
+ draw_state->draw_rr_node.resize(device_ctx.rr_nodes.size());
draw_state->arch_info = arch;
@@ -788,10 +788,7 @@
draw_coords->tile_y = nullptr;
}
- if(draw_state != nullptr) {
- free(draw_state->draw_rr_node);
- draw_state->draw_rr_node = nullptr;
- }
+ draw_state->draw_rr_node.clear();
}
void init_draw_coords(float width_val) {
@@ -809,11 +806,10 @@
/* Each time routing is on screen, need to reallocate the color of each *
* rr_node, as the number of rr_nodes may change. */
if (device_ctx.rr_nodes.size() != 0) {
- draw_state->draw_rr_node = (t_draw_rr_node *) vtr::realloc(draw_state->draw_rr_node,
- (device_ctx.rr_nodes.size()) * sizeof(t_draw_rr_node));
- for (size_t i = 0; i < device_ctx.rr_nodes.size(); i++) {
- draw_state->draw_rr_node[i].color = DEFAULT_RR_NODE_COLOR;
- draw_state->draw_rr_node[i].node_highlighted = false;
+ draw_state->draw_rr_node.resize(device_ctx.rr_nodes.size());
+ for (auto inode : device_ctx.rr_nodes.keys()) {
+ draw_state->draw_rr_node[inode].color = DEFAULT_RR_NODE_COLOR;
+ draw_state->draw_rr_node[inode].node_highlighted = false;
}
}
@@ -982,8 +978,8 @@
//Record min/max congestion
float min_congestion_ratio = 1.;
float max_congestion_ratio = min_congestion_ratio;
- std::vector<int> congested_rr_nodes = collect_congested_rr_nodes();
- for (int inode : congested_rr_nodes) {
+ auto congested_rr_nodes = collect_congested_rr_nodes();
+ for (auto inode : congested_rr_nodes) {
short occ = route_ctx.rr_node_route_inf[inode].occ();
short capacity = device_ctx.rr_nodes[inode].capacity();
@@ -1005,7 +1001,7 @@
//Sort the nodes in ascending order of value for drawing, this ensures high
//valued nodes are not overdrawn by lower value ones (e.g. when zoomed-out far)
- auto cmp_ascending_acc_cost = [&](int lhs_node, int rhs_node) {
+ auto cmp_ascending_acc_cost = [&](RRNodeId lhs_node, RRNodeId rhs_node) {
short lhs_occ = route_ctx.rr_node_route_inf[lhs_node].occ();
short lhs_capacity = device_ctx.rr_nodes[lhs_node].capacity();
@@ -1023,7 +1019,7 @@
auto rr_node_nets = collect_rr_node_nets();
- for (int inode : congested_rr_nodes) {
+ for (auto inode : congested_rr_nodes) {
for (ClusterNetId net : rr_node_nets[inode]) {
t_color color = kelly_max_contrast_colors[size_t(net) % kelly_max_contrast_colors.size()];
draw_state->net_color[net] = color;
@@ -1033,7 +1029,7 @@
drawroute(HIGHLIGHTED);
//Reset colors
- for (int inode : congested_rr_nodes) {
+ for (auto inode : congested_rr_nodes) {
for (ClusterNetId net : rr_node_nets[inode]) {
draw_state->net_color[net] = DEFAULT_RR_NODE_COLOR;
}
@@ -1043,7 +1039,7 @@
}
//Draw each congested node
- for(int inode : congested_rr_nodes) {
+ for(auto inode : congested_rr_nodes) {
short occ = route_ctx.rr_node_route_inf[inode].occ();
short capacity = device_ctx.rr_nodes[inode].capacity();
@@ -1091,8 +1087,8 @@
float min_cost = std::numeric_limits<float>::infinity();
float max_cost = -min_cost;
- std::vector<float> rr_node_costs(device_ctx.rr_nodes.size(), 0.);
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
+ vtr::vector<RRNodeId, float> rr_node_costs(device_ctx.rr_nodes.size(), 0.);
+ for (auto inode : device_ctx.rr_nodes.keys()) {
float cost = 0.;
if ( draw_state->show_routing_costs == DRAW_TOTAL_ROUTING_COSTS
|| draw_state->show_routing_costs == DRAW_LOG_TOTAL_ROUTING_COSTS) {
@@ -1149,14 +1145,15 @@
//Draw the nodes in ascending order of value, this ensures high valued nodes
//are not overdrawn by lower value ones (e.g. when zoomed-out far)
- std::vector<int> nodes(device_ctx.rr_nodes.size());
- std::iota(nodes.begin(), nodes.end(), 0);
- auto cmp_ascending_cost = [&](int lhs_node, int rhs_node) {
+ std::vector<RRNodeId> nodes(device_ctx.rr_nodes.size());
+ auto rr_nodes_keys = device_ctx.rr_nodes.keys();
+ std::copy(rr_nodes_keys.begin(), rr_nodes_keys.end(), nodes.begin());
+ auto cmp_ascending_cost = [&](RRNodeId lhs_node, RRNodeId rhs_node) {
return rr_node_costs[lhs_node] < rr_node_costs[rhs_node];
};
std::sort(nodes.begin(), nodes.end(), cmp_ascending_cost);
- for (int inode : nodes) {
+ for (auto inode : nodes) {
float cost = rr_node_costs[inode];
if (cost == min_cost) continue; //Hide minimum cost resources
@@ -1253,7 +1250,7 @@
setlinestyle(SOLID);
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
if (!draw_state->draw_rr_node[inode].node_highlighted)
{
/* If not highlighted node, assign color based on type. */
@@ -1308,7 +1305,7 @@
drawroute(HIGHLIGHTED);
}
-static void draw_rr_chan(int inode, const t_color color) {
+static void draw_rr_chan(RRNodeId inode, const t_color color) {
auto& device_ctx = g_vpr_ctx.device();
t_rr_type type = device_ctx.rr_nodes[inode].type();
@@ -1453,7 +1450,7 @@
setcolor(color); //Ensure color is still set correctly if we drew any arrows/text
}
-static void draw_rr_edges(int inode) {
+static void draw_rr_edges(RRNodeId inode) {
/* Draws all the edges that the user wants shown between inode and what it *
* connects to. inode is assumed to be a CHANX, CHANY, or IPIN. */
@@ -1461,7 +1458,7 @@
auto& device_ctx = g_vpr_ctx.device();
t_rr_type from_type, to_type;
- int to_node, from_ptc_num, to_ptc_num;
+ int from_ptc_num, to_ptc_num;
short switch_type;
from_type = device_ctx.rr_nodes[inode].type();
@@ -1474,7 +1471,7 @@
from_ptc_num = device_ctx.rr_nodes[inode].ptc_num();
for (int iedge = 0, l = device_ctx.rr_nodes[inode].num_edges(); iedge < l; iedge++) {
- to_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
+ auto to_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
to_type = device_ctx.rr_nodes[to_node].type();
to_ptc_num = device_ctx.rr_nodes[to_node].ptc_num();
bool edge_configurable = device_ctx.rr_nodes[inode].edge_is_configurable(iedge);
@@ -1661,8 +1658,8 @@
}
-static void draw_chanx_to_chany_edge(int chanx_node, int chanx_track,
- int chany_node, int chany_track, enum e_edge_dir edge_dir,
+static void draw_chanx_to_chany_edge(RRNodeId chanx_node, int chanx_track,
+ RRNodeId chany_node, int chany_track, enum e_edge_dir edge_dir,
short switch_type) {
t_draw_state* draw_state = get_draw_state_vars();
@@ -1734,7 +1731,7 @@
}
-static void draw_chanx_to_chanx_edge(int from_node, int to_node,
+static void draw_chanx_to_chanx_edge(RRNodeId from_node, RRNodeId to_node,
int to_track, short switch_type) {
/* Draws a connection between two x-channel segments. Passing in the track *
@@ -1821,7 +1818,7 @@
}
-static void draw_chany_to_chany_edge(int from_node, int to_node,
+static void draw_chany_to_chany_edge(RRNodeId from_node, RRNodeId to_node,
int to_track, short switch_type) {
t_draw_state* draw_state = get_draw_state_vars();
@@ -1912,7 +1909,7 @@
* wire has been clicked on by the user.
* TODO: Fix this for global routing, currently for detailed only.
*/
-static t_bound_box draw_get_rr_chan_bbox (int inode) {
+static t_bound_box draw_get_rr_chan_bbox (RRNodeId inode) {
t_bound_box bound_box;
t_draw_coords* draw_coords = get_draw_coords_vars();
@@ -1978,7 +1975,7 @@
}
}
-static void draw_rr_pin(int inode, const t_color& color) {
+static void draw_rr_pin(RRNodeId inode, const t_color& color) {
/* Draws an IPIN or OPIN rr_node. Note that the pin can appear on more *
* than one side of a clb. Also note that this routine can change the *
@@ -2013,7 +2010,7 @@
/* Returns the coordinates at which the center of this pin should be drawn. *
* inode gives the node number, and iside gives the side of the clb or pad *
* the physical pin is on. */
-void draw_get_rr_pin_coords(int inode, float *xcen, float *ycen) {
+void draw_get_rr_pin_coords(RRNodeId inode, float *xcen, float *ycen) {
auto& device_ctx = g_vpr_ctx.device();
draw_get_rr_pin_coords(&device_ctx.rr_nodes[inode], xcen, ycen);
}
@@ -2109,9 +2106,9 @@
return; /* partially complete routes). */
t_trace* tptr = route_ctx.trace_head[net_id]; /* SOURCE to start */
- int inode = tptr->index;
+ auto inode = tptr->index;
- std::vector<int> rr_nodes_to_draw;
+ std::vector<RRNodeId> rr_nodes_to_draw;
rr_nodes_to_draw.push_back(inode);
for (;;) {
tptr = tptr->next;
@@ -2148,7 +2145,7 @@
}
//Draws the set of rr_nodes specified, using the colors set in draw_state
-void draw_partial_route(const std::vector<int>& rr_nodes_to_draw) {
+void draw_partial_route(const std::vector<RRNodeId>& rr_nodes_to_draw) {
t_draw_state* draw_state = get_draw_state_vars();
auto& device_ctx = g_vpr_ctx.device();
@@ -2178,10 +2175,10 @@
for(size_t i = 1; i < rr_nodes_to_draw.size(); ++i) {
- int inode = rr_nodes_to_draw[i];
+ auto inode = rr_nodes_to_draw[i];
auto rr_type = device_ctx.rr_nodes[inode].type();
- int prev_node = rr_nodes_to_draw[i-1];
+ auto prev_node = rr_nodes_to_draw[i-1];
auto prev_type = device_ctx.rr_nodes[prev_node].type();
int iedge = find_edge(prev_node, inode);
@@ -2279,7 +2276,7 @@
}
}
-static int get_track_num(int inode, const vtr::OffsetMatrix<int>& chanx_track, const vtr::OffsetMatrix<int>& chany_track) {
+static int get_track_num(RRNodeId inode, const vtr::OffsetMatrix<int>& chanx_track, const vtr::OffsetMatrix<int>& chany_track) {
/* Returns the track number of this routing resource node. */
@@ -2329,7 +2326,7 @@
/* If an rr_node has been clicked on, it will be highlighted in MAGENTA.
* If so, and toggle nets is selected, highlight the whole net in that colour.
*/
-static void highlight_nets(char *message, int hit_node) {
+static void highlight_nets(char *message, RRNodeId hit_node) {
t_trace *tptr;
auto& cluster_ctx = g_vpr_ctx.clustering();
auto& route_ctx = g_vpr_ctx.routing();
@@ -2361,7 +2358,7 @@
* fan_in into the node in blue and fan_out from the node in red. If de-highlighted,
* de-highlight its fan_in and fan_out.
*/
-static void draw_highlight_fan_in_fan_out(const std::set<int>& nodes) {
+static void draw_highlight_fan_in_fan_out(const std::set<RRNodeId>& nodes) {
t_draw_state* draw_state = get_draw_state_vars();
auto& device_ctx = g_vpr_ctx.device();
@@ -2369,7 +2366,7 @@
for (auto node : nodes) {
/* Highlight the fanout nodes in red. */
for (int iedge = 0, l = device_ctx.rr_nodes[node].num_edges(); iedge < l; iedge++) {
- int fanout_node = device_ctx.rr_nodes[node].edge_sink_node(iedge);
+ auto fanout_node = device_ctx.rr_nodes[node].edge_sink_node(iedge);
if (draw_state->draw_rr_node[node].color == MAGENTA && draw_state->draw_rr_node[fanout_node].color != MAGENTA) {
// If node is highlighted, highlight its fanout
@@ -2383,9 +2380,9 @@
}
/* Highlight the nodes that can fanin to this node in blue. */
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
for (int iedge = 0, l = device_ctx.rr_nodes[inode].num_edges(); iedge < l; iedge++) {
- int fanout_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
+ auto fanout_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
if (fanout_node == node) {
if (draw_state->draw_rr_node[node].color == MAGENTA && draw_state->draw_rr_node[inode].color != MAGENTA) {
// If node is highlighted, highlight its fanin
@@ -2410,14 +2407,14 @@
*
* It returns the hit RR node's ID (or OPEN if no hit)
*/
-static int draw_check_rr_node_hit (float click_x, float click_y) {
- int hit_node = OPEN;
+static RRNodeId draw_check_rr_node_hit (float click_x, float click_y) {
+ RRNodeId hit_node;
t_bound_box bound_box;
t_draw_coords* draw_coords = get_draw_coords_vars();
auto& device_ctx = g_vpr_ctx.device();
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
switch (device_ctx.rr_nodes[inode].type()) {
case IPIN:
case OPIN:
@@ -2469,23 +2466,23 @@
break;
}
}
- return hit_node;
+ return RRNodeId::INVALID();
}
-static std::set<int> draw_expand_non_configurable_rr_nodes(int from_node) {
- std::set<int> expanded_nodes;
+static std::set<RRNodeId> draw_expand_non_configurable_rr_nodes(RRNodeId from_node) {
+ std::set<RRNodeId> expanded_nodes;
draw_expand_non_configurable_rr_nodes_recurr(from_node, expanded_nodes);
return expanded_nodes;
}
-static void draw_expand_non_configurable_rr_nodes_recurr(int from_node, std::set<int>& expanded_nodes) {
+static void draw_expand_non_configurable_rr_nodes_recurr(RRNodeId from_node, std::set<RRNodeId>& expanded_nodes) {
auto& device_ctx = g_vpr_ctx.device();
expanded_nodes.insert(from_node);
for (int iedge = 0; iedge < device_ctx.rr_nodes[from_node].num_edges(); ++iedge) {
bool edge_configurable = device_ctx.rr_nodes[from_node].edge_is_configurable(iedge);
- int to_node = device_ctx.rr_nodes[from_node].edge_sink_node(iedge);
+ auto to_node = device_ctx.rr_nodes[from_node].edge_sink_node(iedge);
if (!edge_configurable && !expanded_nodes.count(to_node)) {
draw_expand_non_configurable_rr_nodes_recurr(to_node, expanded_nodes);
@@ -2512,9 +2509,9 @@
}
// Check which rr_node (if any) was clicked on.
- int hit_node = draw_check_rr_node_hit (x, y);
+ auto hit_node = draw_check_rr_node_hit (x, y);
- if (hit_node != OPEN) {
+ if (hit_node != RRNodeId::INVALID()) {
auto nodes = draw_expand_non_configurable_rr_nodes(hit_node);
for (auto node : nodes) {
@@ -2663,9 +2660,9 @@
if (draw_state->draw_rr_toggle != DRAW_NO_RR) {
- int hit_node = draw_check_rr_node_hit(mouse_x, mouse_y);
+ auto hit_node = draw_check_rr_node_hit(mouse_x, mouse_y);
- if(hit_node != OPEN) {
+ if(hit_node != RRNodeId::INVALID()) {
//Update message
std::string info = describe_rr_node(hit_node);
@@ -2760,9 +2757,9 @@
for (auto net_id : cluster_ctx.clb_nlist.nets())
draw_state->net_color[net_id] = BLACK;
- for (size_t i = 0; i < device_ctx.rr_nodes.size(); i++) {
- draw_state->draw_rr_node[i].color = DEFAULT_RR_NODE_COLOR;
- draw_state->draw_rr_node[i].node_highlighted = false;
+ for (auto node_id : device_ctx.rr_nodes.keys()) {
+ draw_state->draw_rr_node[node_id].color = DEFAULT_RR_NODE_COLOR;
+ draw_state->draw_rr_node[node_id].node_highlighted = false;
}
get_selected_sub_block_info().clear();
@@ -2867,7 +2864,7 @@
return LOD_screen_area_test_square(arrow_size*0.66, MIN_VISIBLE_AREA);
}
-static void draw_pin_to_chan_edge(int pin_node, int chan_node) {
+static void draw_pin_to_chan_edge(RRNodeId pin_node, RRNodeId chan_node) {
/* This routine draws an edge from the pin_node to the chan_node (CHANX or *
* CHANY). The connection is made to the nearest end of the track instead *
@@ -2951,7 +2948,7 @@
}
-static void draw_pin_to_pin(int opin_node, int ipin_node) {
+static void draw_pin_to_pin(RRNodeId opin_node, RRNodeId ipin_node) {
/* This routine draws an edge from the opin rr node to the ipin rr node */
auto& device_ctx = g_vpr_ctx.device();
@@ -3231,7 +3228,7 @@
//Mark all the nodes highlighted
t_draw_state* draw_state = get_draw_state_vars();
- for (int inode : routed_rr_nodes) {
+ for (auto inode : routed_rr_nodes) {
draw_state->draw_rr_node[inode].color = color;
}
@@ -3246,7 +3243,7 @@
}
//Returns the set of rr nodes which connect driver to sink
-static std::vector<int> trace_routed_connection_rr_nodes(const ClusterNetId net_id, const int driver_pin, const int sink_pin) {
+static std::vector<RRNodeId> trace_routed_connection_rr_nodes(const ClusterNetId net_id, const int driver_pin, const int sink_pin) {
auto& route_ctx = g_vpr_ctx.routing();
bool allocated_route_tree_structs = alloc_route_tree_timing_structs(true); //Needed for traceback_to_route_tree
@@ -3256,9 +3253,9 @@
VTR_ASSERT(rt_root->inode == route_ctx.net_rr_terminals[net_id][driver_pin]);
- int sink_rr_node = route_ctx.net_rr_terminals[net_id][sink_pin];
+ auto sink_rr_node = route_ctx.net_rr_terminals[net_id][sink_pin];
- std::vector<int> rr_nodes_on_path;
+ std::vector<RRNodeId> rr_nodes_on_path;
//Collect the rr nodes
trace_routed_connection_rr_nodes_recurr(rt_root, sink_rr_node, rr_nodes_on_path);
@@ -3275,7 +3272,7 @@
//Helper function for trace_routed_connection_rr_nodes
//Adds the rr nodes linking rt_node to sink_rr_node to rr_nodes_on_path
//Returns true if rt_node is on the path
-bool trace_routed_connection_rr_nodes_recurr(const t_rt_node* rt_node, int sink_rr_node, std::vector<int>& rr_nodes_on_path) {
+bool trace_routed_connection_rr_nodes_recurr(const t_rt_node* rt_node, RRNodeId sink_rr_node, std::vector<RRNodeId>& rr_nodes_on_path) {
//DFS from the current rt_node to the sink_rr_node, when the sink is found trace back the used rr nodes
if (rt_node->inode == sink_rr_node) {
@@ -3299,7 +3296,7 @@
}
//Find the edge between two rr nodes
-static int find_edge(int prev_inode, int inode) {
+static int find_edge(RRNodeId prev_inode, RRNodeId inode) {
auto& device_ctx = g_vpr_ctx.device();
for (int iedge = 0; iedge < device_ctx.rr_nodes[prev_inode].num_edges(); ++iedge) {
if (device_ctx.rr_nodes[prev_inode].edge_sink_node(iedge) == inode) {
@@ -3570,11 +3567,11 @@
vtr::Matrix<float> usage({{device_ctx.grid.width(), device_ctx.grid.height()}}, 0.);
//Collect all the in-use RR nodes
- std::set<int> rr_nodes;
+ std::set<RRNodeId> rr_nodes;
for (auto net : cluster_ctx.clb_nlist.nets()) {
t_trace* tptr = route_ctx.trace_head[net];
while (tptr != nullptr) {
- int inode = tptr->index;
+ auto inode = tptr->index;
if (device_ctx.rr_nodes[inode].type() == rr_type) {
rr_nodes.insert(inode);
@@ -3584,7 +3581,7 @@
}
//Record number of used resources in each x/y channel
- for (int inode : rr_nodes) {
+ for (auto inode : rr_nodes) {
auto& rr_node = device_ctx.rr_nodes[inode];
if (rr_type == CHANX) {
@@ -3616,7 +3613,7 @@
auto& device_ctx = g_vpr_ctx.device();
vtr::Matrix<float> avail({{device_ctx.grid.width(), device_ctx.grid.height()}}, 0.);
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); ++inode) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
auto& rr_node = device_ctx.rr_nodes[inode];
if (rr_node.type() == CHANX && rr_type == CHANX) {
diff --git a/vpr/src/draw/draw.h b/vpr/src/draw/draw.h
index 313ca41..e65351c 100644
--- a/vpr/src/draw/draw.h
+++ b/vpr/src/draw/draw.h
@@ -19,7 +19,7 @@
void free_draw_structs();
-void draw_get_rr_pin_coords(int inode, float *xcen, float *ycen);
+void draw_get_rr_pin_coords(RRNodeId inode, float *xcen, float *ycen);
void draw_get_rr_pin_coords(const t_rr_node* node, float *xcen, float *ycen);
void draw_triangle_along_line(t_point start, t_point end, float relative_position=1., float arrow_size=DEFAULT_ARROW_SIZE);
diff --git a/vpr/src/draw/draw_types.h b/vpr/src/draw/draw_types.h
index fa25161..893c59d 100644
--- a/vpr/src/draw/draw_types.h
+++ b/vpr/src/draw/draw_types.h
@@ -24,6 +24,7 @@
#include "graphics.h"
#include "vpr_types.h"
#include "vtr_color_map.h"
+#include "vtr_vector.h"
using namespace std;
enum e_draw_crit_path {
@@ -156,7 +157,7 @@
char default_message[vtr::bufsize];
vtr::vector_map<ClusterNetId, t_color> net_color;
vtr::vector_map<ClusterBlockId, t_color> block_color;
- t_draw_rr_node *draw_rr_node = nullptr;
+ vtr::vector<RRNodeId, t_draw_rr_node> draw_rr_node;
std::shared_ptr<const SetupTimingInfo> setup_timing_info;
const t_arch* arch_info = nullptr;
std::unique_ptr<const vtr::ColorMap> color_map = nullptr;
diff --git a/vpr/src/power/power.cpp b/vpr/src/power/power.cpp
index 8954dd3..4b95867 100644
--- a/vpr/src/power/power.cpp
+++ b/vpr/src/power/power.cpp
@@ -34,6 +34,7 @@
#include "vtr_log.h"
#include "vtr_assert.h"
#include "vtr_memory.h"
+#include "vtr_vector.h"
#include "power.h"
#include "power_components.h"
@@ -63,7 +64,7 @@
} e_power_breakdown_entry_type;
/************************* File Scope **********************************/
-static t_rr_node_power * rr_node_power;
+static vtr::vector<RRNodeId, t_rr_node_power> rr_node_power;
/************************* Function Declarations ********************/
/* Routing */
@@ -802,7 +803,7 @@
power_ctx.commonly_used->total_cb_buffer_size = 0.;
/* Reset rr graph net indices */
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
rr_node_power[rr_node_idx].net_num = ClusterNetId::INVALID();
rr_node_power[rr_node_idx].num_inputs = 0;
rr_node_power[rr_node_idx].selected_input = 0;
@@ -831,7 +832,7 @@
}
for (edge_idx = 0; edge_idx < node->num_edges(); edge_idx++) {
- if (node->edge_sink_node(edge_idx) != OPEN) {
+ if (node->edge_sink_node(edge_idx) != RRNodeId::INVALID()) {
auto next_node = &device_ctx.rr_nodes[node->edge_sink_node(edge_idx)];
t_rr_node_power * next_node_power = &rr_node_power[node->edge_sink_node(edge_idx)];
@@ -863,7 +864,7 @@
}
/* Calculate power of all routing entities */
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
t_power_usage sub_power_usage;
auto node = &device_ctx.rr_nodes[rr_node_idx];
t_rr_node_power * node_power = &rr_node_power[rr_node_idx];
@@ -1180,9 +1181,9 @@
}
/* Initialize RR Graph Structures */
- rr_node_power = (t_rr_node_power*) vtr::calloc(device_ctx.rr_nodes.size(),
- sizeof(t_rr_node_power));
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ rr_node_power.resize(device_ctx.rr_nodes.size()); // Each member is value-initialized
+ // except pointers
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
rr_node_power[rr_node_idx].driver_switch_type = OPEN;
}
@@ -1192,7 +1193,7 @@
max_IPIN_fanin = 0;
max_seg_to_seg_fanout = 0;
max_seg_to_IPIN_fanout = 0;
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
int switch_idx;
int fanout_to_IPIN = 0;
int fanout_to_seg = 0;
@@ -1245,12 +1246,12 @@
#endif
/* Populate driver switch type */
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
auto node = &device_ctx.rr_nodes[rr_node_idx];
int edge_idx;
for (edge_idx = 0; edge_idx < node->num_edges(); edge_idx++) {
- if (node->edge_sink_node(edge_idx) != OPEN) {
+ if (node->edge_sink_node(edge_idx) != RRNodeId::INVALID()) {
if (rr_node_power[node->edge_sink_node(edge_idx)].driver_switch_type == OPEN) {
rr_node_power[node->edge_sink_node(edge_idx)].driver_switch_type = node->edge_switch(edge_idx);
} else {
@@ -1262,7 +1263,7 @@
/* Find Max Fanout of Routing Buffer */
max_seg_fanout = 0;
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
auto node = &device_ctx.rr_nodes[rr_node_idx];
switch (node->type()) {
@@ -1349,7 +1350,7 @@
auto& power_ctx = g_vpr_ctx.power();
bool error = false;
- for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
+ for (auto rr_node_idx : device_ctx.rr_nodes.keys()) {
auto node = &device_ctx.rr_nodes[rr_node_idx];
t_rr_node_power * node_power = &rr_node_power[rr_node_idx];
@@ -1367,7 +1368,7 @@
break;
}
}
- free(rr_node_power);
+ rr_node_power.clear();
/* Free mux architectures */
for (std::map<float, t_power_mux_info*>::iterator it =
diff --git a/vpr/src/route/check_route.cpp b/vpr/src/route/check_route.cpp
index a534085..dc2c883 100755
--- a/vpr/src/route/check_route.cpp
+++ b/vpr/src/route/check_route.cpp
@@ -4,6 +4,7 @@
#include "vtr_assert.h"
#include "vtr_log.h"
#include "vtr_memory.h"
+#include "vtr_vector.h"
#include "vpr_types.h"
#include "vpr_error.h"
@@ -16,13 +17,13 @@
#include "read_xml_arch_file.h"
struct t_node_edge {
- t_node_edge(int fnode, int tnode) {
+ t_node_edge(RRNodeId fnode, RRNodeId tnode) {
from_node = fnode;
to_node = tnode;
}
- int from_node;
- int to_node;
+ RRNodeId from_node;
+ RRNodeId to_node;
//For std::set
friend bool operator<(const t_node_edge& lhs, const t_node_edge& rhs) {
@@ -37,18 +38,18 @@
};
/******************** Subroutines local to this module **********************/
-static void check_node_and_range(int inode, enum e_route_type route_type);
-static void check_source(int inode, ClusterNetId net_id);
-static void check_sink(int inode, ClusterNetId net_id, bool * pin_done);
+static void check_node_and_range(RRNodeId inode, enum e_route_type route_type);
+static void check_source(RRNodeId inode, ClusterNetId net_id);
+static void check_sink(RRNodeId inode, ClusterNetId net_id, bool * pin_done);
static void check_switch(t_trace *tptr, int num_switch);
-static bool check_adjacent(int from_node, int to_node);
-static int chanx_chany_adjacent(int chanx_node, int chany_node);
-static void reset_flags(ClusterNetId inet, bool * connected_to_route);
+static bool check_adjacent(RRNodeId from_node, RRNodeId to_node);
+static int chanx_chany_adjacent(RRNodeId chanx_node, RRNodeId chany_node);
+static void reset_flags(ClusterNetId inet, vtr::vector<RRNodeId, bool>& connected_to_route);
static void check_locally_used_clb_opins(const t_clb_opins_used& clb_opins_used_locally,
enum e_route_type route_type);
static t_non_configurable_rr_sets identify_non_configurable_rr_sets();
-static void expand_non_configurable(int inode, std::set<t_node_edge>& edge_set);
+static void expand_non_configurable(RRNodeId inode, std::set<t_node_edge>& edge_set);
static bool check_non_configurable_edges(ClusterNetId net, const t_non_configurable_rr_sets& non_configurable_rr_sets);
/************************ Subroutine definitions ****************************/
@@ -61,16 +62,16 @@
* oversubscribed (the occupancy of everything is recomputed from *
* scratch). */
- int max_pins, inode, prev_node;
- unsigned int ipin;
- bool valid, connects;
- bool * connected_to_route; /* [0 .. device_ctx.rr_nodes.size()-1] */
- t_trace *tptr;
- bool * pin_done;
-
auto& device_ctx = g_vpr_ctx.device();
auto& cluster_ctx = g_vpr_ctx.clustering();
auto& route_ctx = g_vpr_ctx.routing();
+
+ int max_pins;
+ unsigned int ipin;
+ bool valid, connects;
+ vtr::vector<RRNodeId, bool> connected_to_route(device_ctx.rr_nodes.size(), false);
+ t_trace *tptr;
+ bool * pin_done;
vtr::printf_info("\n");
vtr::printf_info("Checking to ensure routing is legal...\n");
@@ -90,8 +91,6 @@
auto non_configurable_rr_sets = identify_non_configurable_rr_sets();
- connected_to_route = (bool *) vtr::calloc(device_ctx.rr_nodes.size(), sizeof(bool));
-
max_pins = 0;
for (auto net_id : cluster_ctx.clb_nlist.nets())
max_pins = max(max_pins, (int)cluster_ctx.clb_nlist.net_pins(net_id).size());
@@ -113,7 +112,7 @@
"in check_route: net %d has no routing.\n", size_t(net_id));
}
- inode = tptr->index;
+ auto inode = tptr->index;
check_node_and_range(inode, route_type);
check_switch(tptr, num_switches);
connected_to_route[inode] = true; /* Mark as in path. */
@@ -121,7 +120,7 @@
check_source(inode, net_id);
pin_done[0] = true;
- prev_node = inode;
+ auto prev_node = inode;
int prev_switch = tptr->iswitch;
tptr = tptr->next;
@@ -183,7 +182,7 @@
} /* End for each net */
free(pin_done);
- free(connected_to_route);
+ connected_to_route.clear();
vtr::printf_info("Completed routing consistency check successfully.\n");
vtr::printf_info("\n");
}
@@ -191,7 +190,7 @@
/* Checks that this SINK node is one of the terminals of inet, and marks *
* the appropriate pin as being reached. */
-static void check_sink(int inode, ClusterNetId net_id, bool * pin_done) {
+static void check_sink(RRNodeId inode, ClusterNetId net_id, bool * pin_done) {
int i, j, ifound, ptc_num, iclass, iblk, pin_index;
ClusterBlockId bnum;
@@ -243,7 +242,7 @@
}
/* Checks that the node passed in is a valid source for this net. */
-static void check_source(int inode, ClusterNetId net_id) {
+static void check_source(RRNodeId inode, ClusterNetId net_id) {
t_rr_type rr_type;
t_type_ptr type;
ClusterBlockId blk_id;
@@ -286,12 +285,11 @@
/* Checks that the switch leading from this traceback element to the next *
* one is a legal switch type. */
- int inode;
short switch_type;
auto& device_ctx = g_vpr_ctx.device();
- inode = tptr->index;
+ auto inode = tptr->index;
switch_type = tptr->iswitch;
if (device_ctx.rr_nodes[inode].type() != SINK) {
@@ -314,7 +312,7 @@
}
}
-static void reset_flags(ClusterNetId inet, bool * connected_to_route) {
+static void reset_flags(ClusterNetId inet, vtr::vector<RRNodeId, bool>& connected_to_route) {
/* This routine resets the flags of all the channel segments contained *
* in the traceback of net inet to 0. This allows us to check the *
@@ -322,20 +320,19 @@
* should always be zero after they have been used). */
t_trace *tptr;
- int inode;
auto& route_ctx = g_vpr_ctx.routing();
tptr = route_ctx.trace_head[inet];
while (tptr != nullptr) {
- inode = tptr->index;
+ auto inode = tptr->index;
connected_to_route[inode] = false; /* Not in routed path now. */
tptr = tptr->next;
}
}
-static bool check_adjacent(int from_node, int to_node) {
+static bool check_adjacent(RRNodeId from_node, RRNodeId to_node) {
/* This routine checks if the rr_node to_node is reachable from from_node. *
* It returns true if is reachable and false if it is not. Check_node has *
@@ -519,7 +516,7 @@
return false; //Should not reach here once thrown
}
-static int chanx_chany_adjacent(int chanx_node, int chany_node) {
+static int chanx_chany_adjacent(RRNodeId chanx_node, RRNodeId chany_node) {
/* Returns 1 if the specified CHANX and CHANY nodes are adjacent, 0 *
* otherwise. */
@@ -554,7 +551,7 @@
* brute force recompute from scratch that is useful for sanity checking.
*/
- int inode, iclass, ipin, num_local_opins;
+ int iclass, ipin, num_local_opins;
t_trace *tptr;
auto& route_ctx = g_vpr_ctx.mutable_routing();
@@ -563,8 +560,9 @@
/* First set the occupancy of everything to zero. */
- for (size_t inode_idx = 0; inode_idx < device_ctx.rr_nodes.size(); inode_idx++)
+ for (auto inode_idx : device_ctx.rr_nodes.keys()) {
route_ctx.rr_node_route_inf[inode_idx].set_occ(0);
+ }
/* Now go through each net and count the tracks and pins used everywhere */
@@ -577,7 +575,7 @@
continue;
for (;;) {
- inode = tptr->index;
+ auto inode = tptr->index;
route_ctx.rr_node_route_inf[inode].set_occ(route_ctx.rr_node_route_inf[inode].occ() + 1);
if (tptr->iswitch == OPEN) {
@@ -598,7 +596,7 @@
num_local_opins = route_ctx.clb_opins_used_locally[blk_id][iclass].size();
/* Will always be 0 for pads or SINK classes. */
for (ipin = 0; ipin < num_local_opins; ipin++) {
- inode = route_ctx.clb_opins_used_locally[blk_id][iclass][ipin];
+ auto inode = route_ctx.clb_opins_used_locally[blk_id][iclass][ipin];
route_ctx.rr_node_route_inf[inode].set_occ(route_ctx.rr_node_route_inf[inode].occ() + 1);
}
}
@@ -611,7 +609,7 @@
/* Checks that enough OPINs on CLBs have been set aside (used up) to make a *
* legal routing if subblocks connect to OPINs directly. */
- int iclass, num_local_opins, inode, ipin;
+ int iclass, num_local_opins, ipin;
t_rr_type rr_type;
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -623,7 +621,7 @@
/* Always 0 for pads and for SINK classes */
for (ipin = 0; ipin < num_local_opins; ipin++) {
- inode = clb_opins_used_locally[blk_id][iclass][ipin];
+ auto inode = clb_opins_used_locally[blk_id][iclass][ipin];
check_node_and_range(inode, route_type); /* Node makes sense? */
/* Now check that node is an OPIN of the right type. */
@@ -648,14 +646,14 @@
}
}
-static void check_node_and_range(int inode, enum e_route_type route_type) {
+static void check_node_and_range(RRNodeId inode, enum e_route_type route_type) {
/* Checks that inode is within the legal range, then calls check_node to *
* check that everything else about the node is OK. */
auto& device_ctx = g_vpr_ctx.device();
- if (inode < 0 || inode >= (int) device_ctx.rr_nodes.size()) {
+ if (inode == RRNodeId::INVALID() || device_ctx.rr_nodes.keys().in_range(inode)) {
vpr_throw(VPR_ERROR_ROUTE, __FILE__, __LINE__,
"in check_node_and_range: rr_node #%d is out of legal, range (0 to %d).\n", inode, device_ctx.rr_nodes.size() - 1);
}
@@ -669,7 +667,7 @@
//Walk through the RR graph and recursively expand non-configurable edges
//to collect the sets of non-configurably connected nodes
auto& device_ctx = g_vpr_ctx.device();
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); ++inode) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
std::set<t_node_edge> edge_set;
expand_non_configurable(inode, edge_set);
@@ -701,14 +699,14 @@
}
//Builds a set of non-configurably connected RR graph edges
-static void expand_non_configurable(int inode, std::set<t_node_edge>& edge_set) {
+static void expand_non_configurable(RRNodeId inode, std::set<t_node_edge>& edge_set) {
auto& device_ctx = g_vpr_ctx.device();
for (int iedge = 0; iedge < device_ctx.rr_nodes[inode].num_edges(); ++iedge) {
bool edge_non_configurable = !device_ctx.rr_nodes[inode].edge_is_configurable(iedge);
if (edge_non_configurable) {
- int to_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
+ auto to_node = device_ctx.rr_nodes[inode].edge_sink_node(iedge);
t_node_edge edge = {inode, to_node};
diff --git a/vpr/src/route/check_rr_graph.cpp b/vpr/src/route/check_rr_graph.cpp
index fa34360..f0d4973 100755
--- a/vpr/src/route/check_rr_graph.cpp
+++ b/vpr/src/route/check_rr_graph.cpp
@@ -208,7 +208,7 @@
return type->is_global_pin[ipin];
}
-void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext& device_ctx) {
+void check_rr_node(RRNodeId inode, enum e_route_type route_type, const DeviceContext& device_ctx) {
/* This routine checks that the rr_node is inside the grid and has a valid
* pin number, etc.
diff --git a/vpr/src/route/check_rr_graph.h b/vpr/src/route/check_rr_graph.h
index 3885cdd..df45fda 100755
--- a/vpr/src/route/check_rr_graph.h
+++ b/vpr/src/route/check_rr_graph.h
@@ -6,7 +6,7 @@
const DeviceGrid& grid,
const int num_rr_switches, const t_type_ptr types);
-void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext& device_ctx);
+void check_rr_node(RRNodeId inode, enum e_route_type route_type, const DeviceContext& device_ctx);
#endif
diff --git a/vpr/src/route/route_breadth_first.cpp b/vpr/src/route/route_breadth_first.cpp
index e46c394..6cb3e14 100755
--- a/vpr/src/route/route_breadth_first.cpp
+++ b/vpr/src/route/route_breadth_first.cpp
@@ -20,17 +20,27 @@
int remaining_connections_to_sink,
std::vector<int>& modified_rr_node_inf);
-static void breadth_first_expand_neighbours(int inode, float pcost,
+static void breadth_first_expand_neighbours(RRNodeId inode, float pcost,
ClusterNetId net_id, float bend_cost);
-static void breadth_first_add_to_heap_expand_non_configurable(const float path_cost, const float bend_cost,
- const int from_node, const int to_node, const int iconn);
+static void breadth_first_add_to_heap_expand_non_configurable(
+ const float path_cost,
+ const float bend_cost,
+ const RRNodeId from_node,
+ const RRNodeId to_node,
+ const int iconn);
-static void breadth_first_expand_non_configurable_recurr(const float path_cost, const float bend_cost,
- t_heap* current, const int from_node, const int to_node, const int iconn, std::set<int>& visited);
+static void breadth_first_expand_non_configurable_recurr(
+ const float path_cost,
+ const float bend_cost,
+ t_heap* current,
+ const RRNodeId from_node,
+ const RRNodeId to_node,
+ const int iconn,
+ std::set<RRNodeId>& visited);
static float evaluate_node_cost(const float prev_path_cost, const float bend_cost,
- const int from_node, const int to_node);
+ const RRNodeId from_node, const RRNodeId to_node);
static void breadth_first_add_source_to_heap(ClusterNetId net_id);
@@ -152,7 +162,7 @@
* lack of potential paths, rather than congestion), it returns false, as *
* routing is impossible on this architecture. Otherwise it returns true. */
- int inode, remaining_connections_to_sink;
+ int remaining_connections_to_sink;
float pcost, new_pcost;
t_heap *current;
t_trace *tptr;
@@ -190,7 +200,7 @@
return (false);
}
- inode = current->index;
+ auto inode = current->index;
#ifdef ROUTER_DEBUG
vtr::printf(" Popped node %d\n", inode);
@@ -280,7 +290,6 @@
* this means two connections to the same SINK. */
t_trace *tptr, *next_ptr;
- int inode, sink_node, last_ipin_node;
auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.mutable_routing();
@@ -311,14 +320,14 @@
return; /* No route yet */
next_ptr = tptr->next;
- last_ipin_node = OPEN; /* Stops compiler from complaining. */
+ auto last_ipin_node = RRNodeId::INVALID(); /* Stops compiler from complaining. */
/* Can't put last SINK on heap with NO_PREVIOUS, etc, since that won't let *
* us reach it again. Instead, leave the last traceback element (SINK) off *
* the heap. */
while (next_ptr != nullptr) {
- inode = tptr->index;
+ auto inode = tptr->index;
#ifdef ROUTER_DEBUG
vtr::printf(" Adding previous routing node %d to heap*\n", tptr->index);
#endif
@@ -343,7 +352,7 @@
/* Also need to mark the SINK as having high cost, so another connection can *
* be made to it. */
- sink_node = tptr->index;
+ auto sink_node = tptr->index;
add_to_mod_list(sink_node, modified_rr_node_inf);
route_ctx.rr_node_route_inf[sink_node].path_cost = HUGE_POSITIVE_FLOAT;
@@ -355,21 +364,21 @@
}
}
-static void breadth_first_expand_neighbours(int inode, float pcost,
+static void breadth_first_expand_neighbours(RRNodeId inode, float pcost,
ClusterNetId net_id, float bend_cost) {
/* Puts all the rr_nodes adjacent to inode on the heap. rr_nodes outside *
* the expanded bounding box specified in route_bb are not added to the *
* heap. pcost is the path_cost to get to inode. */
- int iconn, to_node, num_edges;
+ int iconn, num_edges;
auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.routing();
num_edges = device_ctx.rr_nodes[inode].num_edges();
for (iconn = 0; iconn < num_edges; iconn++) {
- to_node = device_ctx.rr_nodes[inode].edge_sink_node(iconn);
+ auto to_node = device_ctx.rr_nodes[inode].edge_sink_node(iconn);
if (device_ctx.rr_nodes[to_node].xhigh() < route_ctx.route_bb[net_id].xmin
|| device_ctx.rr_nodes[to_node].xlow() > route_ctx.route_bb[net_id].xmax
@@ -382,8 +391,12 @@
}
//Add to_node to the heap, and also add any nodes which are connected by non-configurable edges
-static void breadth_first_add_to_heap_expand_non_configurable(const float path_cost, const float bend_cost,
- const int from_node, const int to_node, const int iconn) {
+static void breadth_first_add_to_heap_expand_non_configurable(
+ const float path_cost,
+ const float bend_cost,
+ const RRNodeId from_node,
+ const RRNodeId to_node,
+ const int iconn) {
//Create a heap element to represent this node (and any non-configurably connected nodes)
t_heap* next = alloc_heap_data();
@@ -394,15 +407,22 @@
//Calculate cost and collect nodes connected non-configurably
// This sets the heap element cost and connectivity to non-configurably connected nodes
- std::set<int> visited;
+ std::set<RRNodeId> visited;
breadth_first_expand_non_configurable_recurr(path_cost, bend_cost,
next, from_node, to_node, iconn, visited);
add_to_heap(next);
}
-static void breadth_first_expand_non_configurable_recurr(const float path_cost, const float bend_cost,
- t_heap* current, const int from_node, const int to_node, const int iconn, std::set<int>& visited) {
+static void breadth_first_expand_non_configurable_recurr(
+ const float path_cost,
+ const float bend_cost,
+ t_heap* current,
+ const RRNodeId from_node,
+ const RRNodeId to_node,
+ const int iconn,
+ std::set<RRNodeId>& visited) {
+
VTR_ASSERT(current);
if (!visited.count(to_node)) {
@@ -428,7 +448,7 @@
bool edge_configurable = device_ctx.rr_nodes[to_node].edge_is_configurable(iconn_next);
VTR_ASSERT(!edge_configurable); //Forced expansion
- int to_to_node = device_ctx.rr_nodes[to_node].edge_sink_node(iconn_next);
+ auto to_to_node = device_ctx.rr_nodes[to_node].edge_sink_node(iconn_next);
breadth_first_expand_non_configurable_recurr(new_path_cost, bend_cost,
current, to_node, to_to_node, iconn_next, visited);
@@ -437,7 +457,7 @@
}
static float evaluate_node_cost(const float prev_path_cost, const float bend_cost,
- const int from_node, const int to_node) {
+ const RRNodeId from_node, const RRNodeId to_node) {
auto& device_ctx = g_vpr_ctx.device();
float tot_cost = prev_path_cost + get_rr_cong_cost(to_node);
@@ -457,12 +477,11 @@
/* Adds the SOURCE of this net to the heap. Used to start a net's routing. */
- int inode;
float cost;
auto& route_ctx = g_vpr_ctx.routing();
- inode = route_ctx.net_rr_terminals[net_id][0]; /* SOURCE */
+ auto inode = route_ctx.net_rr_terminals[net_id][0]; /* SOURCE */
cost = get_rr_cong_cost(inode);
#ifdef ROUTER_DEBUG
diff --git a/vpr/src/route/route_common.cpp b/vpr/src/route/route_common.cpp
index c812c4d..e74523d 100644
--- a/vpr/src/route/route_common.cpp
+++ b/vpr/src/route/route_common.cpp
@@ -374,7 +374,7 @@
auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.routing();
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
if (route_ctx.rr_node_route_inf[inode].occ() > device_ctx.rr_nodes[inode].capacity()) {
return (false);
}
@@ -384,12 +384,12 @@
}
//Returns all RR nodes in the current routing which are congested
-std::vector<int> collect_congested_rr_nodes() {
+std::vector<RRNodeId> collect_congested_rr_nodes() {
auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.routing();
- std::vector<int> congested_rr_nodes;
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); inode++) {
+ std::vector<RRNodeId> congested_rr_nodes;
+ for (auto inode : device_ctx.rr_nodes.keys()) {
short occ = route_ctx.rr_node_route_inf[inode].occ();
short capacity = device_ctx.rr_nodes[inode].capacity();
@@ -402,7 +402,7 @@
/* Returns a vector from [0..device_ctx.rr_nodes.size()-1] containing the set
* of nets using each RR node */
-std::vector<std::set<ClusterNetId>> collect_rr_node_nets() {
+vtr::vector<RRNodeId, std::set<ClusterNetId>> collect_rr_node_nets() {
auto& device_ctx = g_vpr_ctx.device();
auto& route_ctx = g_vpr_ctx.routing();
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -411,7 +411,7 @@
for (ClusterNetId inet : cluster_ctx.clb_nlist.nets()) {
t_trace* trace_elem = route_ctx.trace_head[inet];
while (trace_elem) {
- int rr_node = trace_elem->index;
+ auto rr_node = trace_elem->index;
rr_node_nets[rr_node].insert(inet);
@@ -799,7 +799,7 @@
}
/* Returns the *congestion* cost of using this rr_node. */
-float get_rr_cong_cost(int inode) {
+float get_rr_cong_cost(RRNodeId inode) {
short cost_index;
float cost;
@@ -838,7 +838,7 @@
++route_ctx.rr_node_route_inf[sink_node].target_flag;
}
-void node_to_heap(int inode, float total_cost, int prev_node, int prev_edge,
+void node_to_heap(RRNodeId inode, float total_cost, int prev_node, int prev_edge,
float backward_path_cost, float R_upstream) {
/* Puts an rr_node on the heap, if the new cost given is lower than the *
@@ -1234,7 +1234,7 @@
return route_bb;
}
-void add_to_mod_list(int inode, std::vector<int>& modified_rr_node_inf) {
+void add_to_mod_list(RRNodeId inode, std::vector<int>& modified_rr_node_inf) {
auto& route_ctx = g_vpr_ctx.routing();
if (std::isinf(route_ctx.rr_node_route_inf[inode].path_cost)) {
@@ -1473,7 +1473,7 @@
num_heap_allocated--;
}
-void invalidate_heap_entries(int sink_node, int ipin_node) {
+void invalidate_heap_entries(RRNodeId sink_node, RRNodeId ipin_node) {
/* Marks all the heap entries consisting of sink_node, where it was reached *
* via ipin_node, as invalid (OPEN). Used only by the breadth_first router *
@@ -1483,7 +1483,7 @@
if (heap[i]->index == sink_node) {
for (t_heap_prev prev : heap[i]->previous) {
if (prev.from_node == ipin_node) {
- heap[i]->index = OPEN; /* Invalid. */
+ heap[i]->index = RRNodeId::INVALID();
break;
}
}
diff --git a/vpr/src/route/route_common.h b/vpr/src/route/route_common.h
index 50fe8fc..5e4438c 100755
--- a/vpr/src/route/route_common.h
+++ b/vpr/src/route/route_common.h
@@ -5,10 +5,10 @@
struct t_heap_prev {
- t_heap_prev(int to, int from, short edge)
+ t_heap_prev(RRNodeId to, RRNodeId from, short edge)
: to_node(to), from_node(from), from_edge(edge) {}
- int to_node = NO_PREVIOUS; //The target node
- int from_node = NO_PREVIOUS; //The previous node used to connect to 'to_node'
+ RRNodeId to_node = RRNodeId::INVALID(); //The target node
+ RRNodeId from_node = RRNodeId::INVALID(); //The previous node used to connect to 'to_node'
short from_edge = NO_PREVIOUS; //The edge used to connect from 'from_node' to 'to_node'
};
@@ -37,7 +37,7 @@
float cost = 0.;
float backward_path_cost = 0.;
float R_upstream = 0.;
- int index = OPEN;
+ RRNodeId index = RRNodeId::INVALID();
std::vector<t_heap_prev> previous;
};
@@ -57,21 +57,21 @@
void reset_path_costs(const std::vector<int>& visited_rr_nodes);
void reset_path_costs();
-float get_rr_cong_cost(int inode);
+float get_rr_cong_cost(RRNodeId inode);
void mark_ends(ClusterNetId net_id);
void mark_remaining_ends(const std::vector<int>& remaining_sinks);
void add_to_heap(t_heap *hptr);
t_heap *alloc_heap_data();
-void node_to_heap(int inode, float cost, int prev_node, int prev_edge,
+void node_to_heap(RRNodeId inode, float cost, int prev_node, int prev_edge,
float backward_path_cost, float R_upstream);
bool is_empty_heap();
void free_traceback(ClusterNetId net_id);
-void add_to_mod_list(int inode, std::vector<int>& modified_rr_node_inf);
+void add_to_mod_list(RRNodeId inode, std::vector<int>& modified_rr_node_inf);
void add_to_mod_list(float *fptr);
namespace heap_ {
@@ -93,7 +93,7 @@
void free_heap_data(t_heap *hptr);
-void invalidate_heap_entries(int sink_node, int ipin_node);
+void invalidate_heap_entries(RRNodeId sink_node, RRNodeId ipin_node);
void init_route_structs(int bb_factor);
diff --git a/vpr/src/route/route_export.h b/vpr/src/route/route_export.h
index 02db822..c8ef600 100755
--- a/vpr/src/route/route_export.h
+++ b/vpr/src/route/route_export.h
@@ -4,6 +4,8 @@
#include <memory>
#include "timing_info_fwd.h"
#include "route_common.h"
+#include "rr_node_fwd.h"
+#include "vtr_vector.h"
void try_graph(int width_fac, t_router_opts router_opts,
t_det_routing_arch *det_routing_arch, t_segment_inf * segment_inf,
@@ -24,9 +26,9 @@
bool feasible_routing();
-std::vector<int> collect_congested_rr_nodes();
+std::vector<RRNodeId> collect_congested_rr_nodes();
-std::vector<std::set<ClusterNetId>> collect_rr_node_nets();
+vtr::vector<RRNodeId, std::set<ClusterNetId>> collect_rr_node_nets();
t_clb_opins_used alloc_route_structs();
diff --git a/vpr/src/route/route_tree_type.h b/vpr/src/route/route_tree_type.h
index 8529909..8230c09 100644
--- a/vpr/src/route/route_tree_type.h
+++ b/vpr/src/route/route_tree_type.h
@@ -44,7 +44,7 @@
t_rt_node *parent_node;
short parent_switch;
bool re_expand;
- int inode;
+ RRNodeId inode;
float C_downstream;
float R_upstream;
float Tdel;
diff --git a/vpr/src/route/rr_graph.cpp b/vpr/src/route/rr_graph.cpp
index 06645c7..d47d401 100644
--- a/vpr/src/route/rr_graph.cpp
+++ b/vpr/src/route/rr_graph.cpp
@@ -2200,7 +2200,7 @@
}
/* Prints all the data about node inode to file fp. */
-void print_rr_node(FILE * fp, const std::vector<t_rr_node> &L_rr_node, int inode) {
+void print_rr_node(FILE * fp, const vtr::vector<RRNodeId, t_rr_node> &L_rr_node, RRNodeId inode) {
std::string info = describe_rr_node(inode);
fprintf(fp, "%s\n", info.c_str());
@@ -2238,7 +2238,7 @@
fprintf(fp, "C_load: %g\n", device_ctx.rr_indexed_data[index].C_load);
}
-std::string describe_rr_node(int inode) {
+std::string describe_rr_node(RRNodeId inode) {
auto& device_ctx = g_vpr_ctx.device();
std::string msg = vtr::string_fmt("RR node: %d", inode);
diff --git a/vpr/src/route/rr_graph.h b/vpr/src/route/rr_graph.h
index 1368e2a..0f39b99 100755
--- a/vpr/src/route/rr_graph.h
+++ b/vpr/src/route/rr_graph.h
@@ -7,6 +7,8 @@
#define INCLUDE_TRACK_BUFFERS false
#include "device_grid.h"
+#include "rr_node_fwd.h"
+#include "vtr_vector.h"
enum e_graph_type {
GRAPH_GLOBAL, /* One node per channel with wire capacity > 1 and full connectivity */
@@ -46,9 +48,9 @@
void print_rr_indexed_data(FILE * fp, int index); /* For debugging only */
//Returns a brief one-line summary of an RR node
-std::string describe_rr_node(int inode);
+std::string describe_rr_node(RRNodeId inode);
-void print_rr_node(FILE *fp, const std::vector<t_rr_node> &L_rr_node, int inode);
+void print_rr_node(FILE *fp, const vtr::vector<RRNodeId, t_rr_node> &L_rr_node, RRNodeId inode);
void init_fan_in(std::vector<t_rr_node>& L_rr_node, const int num_rr_nodes);
diff --git a/vpr/src/route/rr_graph2.cpp b/vpr/src/route/rr_graph2.cpp
index 59b9e98..2d06501 100755
--- a/vpr/src/route/rr_graph2.cpp
+++ b/vpr/src/route/rr_graph2.cpp
@@ -2687,7 +2687,7 @@
}
void partition_rr_graph_edges(DeviceContext& device_ctx) {
- for (size_t inode = 0; inode < device_ctx.rr_nodes.size(); ++inode) {
+ for (auto inode : device_ctx.rr_nodes.keys()) {
device_ctx.rr_nodes[inode].partition_edges();
}
}
diff --git a/vpr/src/route/rr_graph_area.cpp b/vpr/src/route/rr_graph_area.cpp
index 61d8095..5ab7b58 100755
--- a/vpr/src/route/rr_graph_area.cpp
+++ b/vpr/src/route/rr_graph_area.cpp
@@ -5,6 +5,7 @@
#include "vtr_log.h"
#include "vtr_math.h"
#include "vtr_memory.h"
+#include "vtr_vector.h"
#include "vpr_types.h"
#include "vpr_error.h"
@@ -33,8 +34,11 @@
int wire_to_ipin_switch, float R_minW_nmos, float R_minW_pmos,
const float trans_sram_bit);
-static float get_cblock_trans(int *num_inputs_to_cblock, int wire_to_ipin_switch,
- int max_inputs_to_cblock, float trans_sram_bit);
+static float get_cblock_trans(
+ vtr::vector<RRNodeId, int>& num_inputs_to_cblock,
+ int wire_to_ipin_switch,
+ int max_inputs_to_cblock,
+ float trans_sram_bit);
static float *alloc_and_load_unsharable_switch_trans(int num_switch,
float trans_sram_bit, float R_minW_nmos);
@@ -101,9 +105,9 @@
* optimistic (but I still think it's pretty reasonable). */
auto& device_ctx = g_vpr_ctx.device();
- int *num_inputs_to_cblock; /* [0..device_ctx.rr_nodes.size()-1], but all entries not */
-
- /* corresponding to IPINs will be 0. */
+ /* all entries in num_inputs_to_cblock not corresponding to IPINs will be zero.
+ By default the vector should be value-initialized with zero for its integer elements.*/
+ vtr::vector<RRNodeId, int> num_inputs_to_cblock(device_ctx.rr_nodes.size());
bool * cblock_counted; /* [0..max(device_ctx.grid.width(),device_ctx.grid.height())] -- 0th element unused. */
float *shared_buffer_trans; /* [0..max(device_ctx.grid.width(),device_ctx.grid.height())] */
@@ -144,7 +148,8 @@
trans_track_to_cblock_buf = 0;
}
- num_inputs_to_cblock = (int *) vtr::calloc(device_ctx.rr_nodes.size(), sizeof(int));
+ num_inputs_to_cblock.resize(device_ctx.rr_nodes.size()); // Should be value-initialized
+ // to zero by default
maxlen = max(device_ctx.grid.width(), device_ctx.grid.height());
cblock_counted = (bool *) vtr::calloc(maxlen, sizeof(bool));
@@ -156,7 +161,7 @@
sharable_switch_trans = alloc_and_load_sharable_switch_trans(num_switch,
R_minW_nmos, R_minW_pmos);
- for (size_t from_node = 0; from_node < device_ctx.rr_nodes.size(); from_node++) {
+ for (auto from_node : device_ctx.rr_nodes.keys()) {
from_rr_type = device_ctx.rr_nodes[from_node].type();
@@ -168,7 +173,7 @@
for (iedge = 0; iedge < num_edges; iedge++) {
- size_t to_node = device_ctx.rr_nodes[from_node].edge_sink_node(iedge);
+ auto to_node = device_ctx.rr_nodes[from_node].edge_sink_node(iedge);
to_rr_type = device_ctx.rr_nodes[to_node].type();
/* Ignore any uninitialized rr_graph nodes */
@@ -287,7 +292,7 @@
input_cblock_trans = get_cblock_trans(num_inputs_to_cblock, wire_to_ipin_switch,
max_inputs_to_cblock, trans_sram_bit);
- free(num_inputs_to_cblock);
+ num_inputs_to_cblock.clear();
ntrans_sharing += input_cblock_trans;
ntrans_no_sharing += input_cblock_trans;
@@ -308,12 +313,13 @@
auto& device_ctx = g_vpr_ctx.device();
bool * cblock_counted; /* [0..max(device_ctx.grid.width(),device_ctx.grid.height())] -- 0th element unused. */
- int *num_inputs_to_cblock; /* [0..device_ctx.rr_nodes.size()-1], but all entries not */
- /* corresponding to IPINs will be 0. */
+ /* All entries in num_inputs_to_cblock not corresponding to IPINs will be zero.
+ By default the vector is value-initialized meaning the integers will be initialized to zero.*/
+ vtr::vector<RRNodeId, int> num_inputs_to_cblock(device_ctx.rr_nodes.size());
t_rr_type from_rr_type, to_rr_type;
- int i, j, iseg, to_node, iedge, num_edges, maxlen;
+ int i, j, iseg, iedge, num_edges, maxlen;
int max_inputs_to_cblock;
float input_cblock_trans;
@@ -322,8 +328,7 @@
a single mux. We should count this mux only once as we look at the outgoing
switches of all rr nodes. Thus we keep track of which muxes we have already
counted via the variable below. */
- bool *chan_node_switch_done;
- chan_node_switch_done = (bool *) vtr::calloc(device_ctx.rr_nodes.size(), sizeof(bool));
+ vtr::vector<RRNodeId, bool> chan_node_switch_done(device_ctx.rr_nodes.size());
/* The variable below is an accumulator variable that will add up all the *
* transistors in the routing. Make double so that it doesn't stop *
@@ -354,12 +359,11 @@
trans_track_to_cblock_buf = 0;
}
- num_inputs_to_cblock = (int *) vtr::calloc(device_ctx.rr_nodes.size(), sizeof(int));
maxlen = max(device_ctx.grid.width(), device_ctx.grid.height());
cblock_counted = (bool *) vtr::calloc(maxlen, sizeof(bool));
ntrans = 0;
- for (size_t from_node = 0; from_node < device_ctx.rr_nodes.size(); from_node++) {
+ for (auto from_node : device_ctx.rr_nodes.keys()) {
from_rr_type = device_ctx.rr_nodes[from_node].type();
@@ -372,7 +376,7 @@
/* Increment number of inputs per cblock if IPIN */
for (iedge = 0; iedge < num_edges; iedge++) {
- to_node = device_ctx.rr_nodes[from_node].edge_sink_node(iedge);
+ auto to_node = device_ctx.rr_nodes[from_node].edge_sink_node(iedge);
to_rr_type = device_ctx.rr_nodes[to_node].type();
/* Ignore any uninitialized rr_graph nodes */
@@ -475,8 +479,8 @@
max_inputs_to_cblock, trans_sram_bit);
free(cblock_counted);
- free(num_inputs_to_cblock);
- free(chan_node_switch_done);
+ num_inputs_to_cblock.clear();
+ chan_node_switch_done.clear();
ntrans += input_cblock_trans;
@@ -485,7 +489,7 @@
vtr::printf_info("\tTotal routing area: %#g, per logic tile: %#g\n", ntrans, ntrans / (float) (device_ctx.grid.width() * device_ctx.grid.height()));
}
-static float get_cblock_trans(int *num_inputs_to_cblock, int wire_to_ipin_switch,
+static float get_cblock_trans(vtr::vector<RRNodeId, int>& num_inputs_to_cblock, int wire_to_ipin_switch,
int max_inputs_to_cblock, float trans_sram_bit) {
/* Computes the transistors in the input connection block multiplexers and *
@@ -516,7 +520,7 @@
trans_count = 0.;
- for (size_t i = 0; i < device_ctx.rr_nodes.size(); i++) {
+ for (auto i : device_ctx.rr_nodes.keys()) {
num_inputs = num_inputs_to_cblock[i];
trans_count += trans_per_cblock[num_inputs];
}
diff --git a/vpr/src/route/rr_graph_util.cpp b/vpr/src/route/rr_graph_util.cpp
index d2deb59..46acdb1 100755
--- a/vpr/src/route/rr_graph_util.cpp
+++ b/vpr/src/route/rr_graph_util.cpp
@@ -6,7 +6,7 @@
#include "globals.h"
#include "rr_graph_util.h"
-int seg_index_of_cblock(t_rr_type from_rr_type, int to_node) {
+int seg_index_of_cblock(t_rr_type from_rr_type, RRNodeId to_node) {
/* Returns the segment number (distance along the channel) of the connection *
* box from from_rr_type (CHANX or CHANY) to to_node (IPIN). */
@@ -20,7 +20,7 @@
return (device_ctx.rr_nodes[to_node].ylow());
}
-int seg_index_of_sblock(int from_node, int to_node) {
+int seg_index_of_sblock(RRNodeId from_node, RRNodeId to_node) {
/* Returns the segment number (distance along the channel) of the switch box *
* box from from_node (CHANX or CHANY) to to_node (CHANX or CHANY). The *
diff --git a/vpr/src/route/rr_graph_util.h b/vpr/src/route/rr_graph_util.h
index de5fef0..c6a454e 100755
--- a/vpr/src/route/rr_graph_util.h
+++ b/vpr/src/route/rr_graph_util.h
@@ -1,7 +1,7 @@
#ifndef RR_GRAPH_UTIL_H
#define RR_GRAPH_UTIL_H
-int seg_index_of_cblock(t_rr_type from_rr_type, int to_node);
+int seg_index_of_cblock(t_rr_type from_rr_type, RRNodeId to_node);
-int seg_index_of_sblock(int from_node, int to_node);
+int seg_index_of_sblock(RRNodeId from_node, RRNodeId to_node);
#endif
diff --git a/vpr/src/route/rr_node.cpp b/vpr/src/route/rr_node.cpp
index bfe0751..b316271 100644
--- a/vpr/src/route/rr_node.cpp
+++ b/vpr/src/route/rr_node.cpp
@@ -237,9 +237,9 @@
dir_side_.side = new_side;
}
-void t_rr_node::set_edge_sink_node(short iedge, int sink_node) {
+void t_rr_node::set_edge_sink_node(short iedge, RRNodeId sink_node) {
VTR_ASSERT(iedge < num_edges());
- VTR_ASSERT(sink_node >= 0);
+ //TODO: Assert node id is valid
edges_[iedge].sink_node = sink_node;
}
diff --git a/vpr/src/route/rr_node.h b/vpr/src/route/rr_node.h
index a998cb5..d1731f5 100644
--- a/vpr/src/route/rr_node.h
+++ b/vpr/src/route/rr_node.h
@@ -75,7 +75,7 @@
short num_configurable_edges() const { return num_configurable_edges_; }
short num_non_configurable_edges() const { return num_edges() - num_configurable_edges(); }
- int edge_sink_node(short iedge) const { VTR_ASSERT_SAFE(iedge < num_edges()); return edges_[iedge].sink_node; }
+ RRNodeId edge_sink_node(short iedge) const { VTR_ASSERT_SAFE(iedge < num_edges()); return edges_[iedge].sink_node; }
short edge_switch(short iedge) const { VTR_ASSERT_SAFE(iedge < num_edges()); return edges_[iedge].switch_id; }
bool edge_is_configurable(short iedge) const;
short fan_in() const;
@@ -119,7 +119,7 @@
void partition_edges();
void set_num_edges(short); //Note will remove any previous edges
- void set_edge_sink_node(short iedge, int sink_node);
+ void set_edge_sink_node(short iedge, RRNodeId sink_node);
void set_edge_switch(short iedge, short switch_index);
void set_edge_is_configurable(short iedge, bool is_configurable);
void set_fan_in(short);
@@ -144,7 +144,7 @@
//The edge information is stored in a structure to economize on the number of pointers held
//by t_rr_node (to save memory), and is not exposed externally
struct t_rr_edge {
- int sink_node = -1; //The ID of the sink RR node associated with this edge
+ RRNodeId sink_node; //The ID of the sink RR node associated with this edge
short switch_id = -1; //The ID of the switch type this edge represents
};
diff --git a/vpr/src/route/rr_node_fwd.h b/vpr/src/route/rr_node_fwd.h
index 4504477..8876308 100644
--- a/vpr/src/route/rr_node_fwd.h
+++ b/vpr/src/route/rr_node_fwd.h
@@ -1,7 +1,6 @@
#ifndef RR_NODE_FWD_H
#define RR_NODE_FWD_H
#include "vtr_strong_id.h"
-#include "rr_node.h"
/*
* StrongId's for the t_rr_node class