Skip to content

RRGraphView node_cost_index() Implementation #1843

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
2 changes: 1 addition & 1 deletion vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ struct DeviceContext : public Context {
*/
t_rr_graph_storage rr_nodes; // autogenerated in build_rr_graph

std::vector<t_rr_indexed_data> rr_indexed_data; // [0 .. num_rr_indexed_data-1]
vtr::vector<RRIndexedDataId, t_rr_indexed_data> rr_indexed_data; // [0 .. num_rr_indexed_data-1]

///@brief Fly-weighted Resistance/Capacitance data for RR Nodes
std::vector<t_rr_rc_data> rr_rc_data;
Expand Down
2 changes: 2 additions & 0 deletions vpr/src/device/rr_graph_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class RRGraph;

struct rr_node_id_tag;
struct rr_edge_id_tag;
struct rr_indexed_data_id_tag;
struct rr_switch_id_tag;
struct rr_segment_id_tag;

typedef vtr::StrongId<rr_node_id_tag, unsigned int> RRNodeId;
typedef vtr::StrongId<rr_edge_id_tag, unsigned int> RREdgeId;
typedef vtr::StrongId<rr_indexed_data_id_tag, unsigned int> RRIndexedDataId;
typedef vtr::StrongId<rr_switch_id_tag, short> RRSwitchId;
typedef vtr::StrongId<rr_segment_id_tag, short> RRSegmentId;

Expand Down
8 changes: 4 additions & 4 deletions vpr/src/device/rr_graph_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ short RRGraph::node_class_num(const RRNodeId& node) const {
return node_ptc_num(node);
}

short RRGraph::node_cost_index(const RRNodeId& node) const {
RRIndexedDataId RRGraph::node_cost_index(const RRNodeId& node) const {
VTR_ASSERT_SAFE(valid_node_id(node));
return node_cost_indices_[node];
return RRIndexedDataId(node_cost_indices_[node]);
}

Direction RRGraph::node_direction(const RRNodeId& node) const {
Expand Down Expand Up @@ -990,9 +990,9 @@ void RRGraph::set_node_class_num(const RRNodeId& node, const short& class_id) {
set_node_ptc_num(node, class_id);
}

void RRGraph::set_node_cost_index(const RRNodeId& node, const short& cost_index) {
void RRGraph::set_node_cost_index(const RRNodeId& node, const RRIndexedDataId& cost_index) {
VTR_ASSERT(valid_node_id(node));
node_cost_indices_[node] = cost_index;
node_cost_indices_[node] = (size_t)cost_index;
}

void RRGraph::set_node_direction(const RRNodeId& node, const Direction& direction) {
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/device/rr_graph_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class RRGraph {
* when used in evaluate different routing paths
* See cross-reference section in this header file for more details
*/
short node_cost_index(const RRNodeId& node) const;
RRIndexedDataId node_cost_index(const RRNodeId& node) const;

/* Get the directionality of a node
* see node coordinate for details
Expand Down Expand Up @@ -669,7 +669,7 @@ class RRGraph {

/* Set the routing cost index for node, see node_cost_index() for details */
/* TODO: the cost index should be changed to a StrongId!!! */
void set_node_cost_index(const RRNodeId& node, const short& cost_index);
void set_node_cost_index(const RRNodeId& node, const RRIndexedDataId& cost_index);

/* Set the directionality for a node, only applicable to CHANX and CHANY */
void set_node_direction(const RRNodeId& node, const Direction& direction);
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/device/rr_graph_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "rr_node.h"
#include "physical_types.h"

RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage, const RRSpatialLookup& node_lookup, const std::vector<t_rr_indexed_data>& rr_indexed_data, const std::vector<t_segment_inf>& rr_segments)
RRGraphView::RRGraphView(const t_rr_graph_storage& node_storage, const RRSpatialLookup& node_lookup, const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data, const std::vector<t_segment_inf>& rr_segments)
: node_storage_(node_storage)
, node_lookup_(node_lookup)
, rr_indexed_data_(rr_indexed_data)
Expand Down
8 changes: 4 additions & 4 deletions vpr/src/device/rr_graph_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class RRGraphView {
/* See detailed comments about the data structures in the internal data storage section of this file */
RRGraphView(const t_rr_graph_storage& node_storage,
const RRSpatialLookup& node_lookup,
const std::vector<t_rr_indexed_data>& rr_indexed_data,
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
const std::vector<t_segment_inf>& rr_segments);

/* Disable copy constructors and copy assignment operator
Expand Down Expand Up @@ -207,7 +207,7 @@ class RRGraphView {
arrow = "";
}
if (node_type(node) == CHANX || node_type(node) == CHANY) { //for channels, we would like to describe the component with segment specific information
int cost_index = node_cost_index(node);
RRIndexedDataId cost_index = node_cost_index(node);
int seg_index = rr_indexed_data_[cost_index].seg_index;
coordinate_string += rr_segments_[seg_index].name; //Write the segment name
coordinate_string += " length:" + std::to_string(node_length(node)); //add the length of the segment
Expand Down Expand Up @@ -245,7 +245,7 @@ class RRGraphView {
}

/** @brief Get the cost index of a routing resource node. This function is inlined for runtime optimization. */
inline short node_cost_index(RRNodeId node) const {
RRIndexedDataId node_cost_index(RRNodeId node) const {
return node_storage_.node_cost_index(node);
}

Expand All @@ -263,7 +263,7 @@ class RRGraphView {
const RRSpatialLookup& node_lookup_;

/* rr_indexed_data_ and rr_segments_ are needed to lookup the segment information in node_coordinate_to_string() */
const std::vector<t_rr_indexed_data>& rr_indexed_data_;
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data_;

/* Segment info for rr nodes */
const std::vector<t_segment_inf>& rr_segments_;
Expand Down
15 changes: 8 additions & 7 deletions vpr/src/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,16 +858,17 @@ static void power_usage_routing(t_power_usage* power_usage,
for (size_t rr_node_idx = 0; rr_node_idx < device_ctx.rr_nodes.size(); rr_node_idx++) {
t_power_usage sub_power_usage;
auto node = device_ctx.rr_nodes[rr_node_idx];
RRNodeId rr_node = RRNodeId(rr_node_idx);
t_rr_node_power* node_power = &rr_node_power[rr_node_idx];
float C_wire;
float buffer_size;
int connectionbox_fanout;
int switchbox_fanout;
//float C_per_seg_split;
int wire_length;
const t_edge_size node_fan_in = rr_graph.node_fan_in(RRNodeId(rr_node_idx));
const t_edge_size node_fan_in = rr_graph.node_fan_in(rr_node);

switch (rr_graph.node_type(RRNodeId(rr_node_idx))) {
switch (rr_graph.node_type(rr_node)) {
case SOURCE:
case SINK:
case OPIN:
Expand Down Expand Up @@ -905,12 +906,12 @@ static void power_usage_routing(t_power_usage* power_usage,
VTR_ASSERT(node_power->in_prob);

wire_length = 0;
if (rr_graph.node_type(RRNodeId(rr_node_idx)) == CHANX) {
wire_length = rr_graph.node_xhigh(node.id()) - rr_graph.node_xlow(node.id()) + 1;
} else if (rr_graph.node_type(RRNodeId(rr_node_idx)) == CHANY) {
wire_length = rr_graph.node_yhigh(node.id()) - rr_graph.node_ylow(node.id()) + 1;
if (rr_graph.node_type(rr_node) == CHANX) {
wire_length = rr_graph.node_xhigh(rr_node) - rr_graph.node_xlow(rr_node) + 1;
} else if (rr_graph.node_type(rr_node) == CHANY) {
wire_length = rr_graph.node_yhigh(rr_node) - rr_graph.node_ylow(rr_node) + 1;
}
int seg_index = device_ctx.rr_indexed_data[node.cost_index()].seg_index;
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(rr_node)].seg_index;
C_wire = wire_length * device_ctx.rr_segments[seg_index].Cmetal;
//(double)power_ctx.commonly_used->tile_length);
VTR_ASSERT(node_power->selected_input < node_fan_in);
Expand Down
7 changes: 4 additions & 3 deletions vpr/src/route/check_rr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
int xlow, ylow, xhigh, yhigh, ptc_num, capacity;
t_rr_type rr_type;
t_physical_tile_type_ptr type;
int nodes_per_chan, tracks_per_node, num_edges, cost_index;
int nodes_per_chan, tracks_per_node, num_edges;
RRIndexedDataId cost_index;
float C, R;
const auto& rr_graph = device_ctx.rr_graph;
RRNodeId rr_node = RRNodeId(inode);
Expand All @@ -307,7 +308,7 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
yhigh = rr_graph.node_yhigh(rr_node);
ptc_num = device_ctx.rr_nodes[inode].ptc_num();
capacity = rr_graph.node_capacity(rr_node);
cost_index = device_ctx.rr_nodes[inode].cost_index();
cost_index = rr_graph.node_cost_index(rr_node);
type = nullptr;

const auto& grid = device_ctx.grid;
Expand All @@ -326,7 +327,7 @@ void check_rr_node(int inode, enum e_route_type route_type, const DeviceContext&
"in check_rr_node: inode %d (type %d) had a ptc_num of %d.\n", inode, rr_type, ptc_num);
}

if (cost_index < 0 || cost_index >= (int)device_ctx.rr_indexed_data.size()) {
if (!cost_index || (size_t)cost_index >= (size_t)device_ctx.rr_indexed_data.size()) {
VPR_FATAL_ERROR(VPR_ERROR_ROUTE,
"in check_rr_node: node %d cost index (%d) is out of range.\n", inode, cost_index);
}
Expand Down
3 changes: 2 additions & 1 deletion vpr/src/route/clock_connection_builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ RRNodeId RoutingToClockConnection::create_virtual_clock_network_sink_node(int x,
rr_graph.set_node_ptc_num(node_index, ptc);
rr_graph_builder.set_node_coordinates(node_index, x, y, x, y);
rr_graph_builder.set_node_capacity(node_index, 1);
rr_graph.set_node_cost_index(node_index, SINK_COST_INDEX);
rr_graph.set_node_cost_index(node_index, RRIndexedDataId(SINK_COST_INDEX));
rr_graph.set_node_type(node_index, SINK);

float R = 0.;
float C = 0.;
rr_graph.set_node_rc_index(node_index, find_create_rr_rc_data(R, C));
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/clock_network_builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ int ClockRib::create_chanx_wire(int x_start,
VTR_ASSERT_MSG(false, "Unidentified direction type for clock rib");
break;
}
node.set_cost_index(CHANX_COST_INDEX_START + seg_index); // Actual value set later
node.set_cost_index(RRIndexedDataId(CHANX_COST_INDEX_START + seg_index)); // Actual value set later

/* Add the node to spatial lookup */
auto& rr_graph = (*rr_nodes);
Expand Down Expand Up @@ -648,7 +648,7 @@ int ClockSpine::create_chany_wire(int y_start,
VTR_ASSERT_MSG(false, "Unidentified direction type for clock rib");
break;
}
node.set_cost_index(CHANX_COST_INDEX_START + num_segments + seg_index);
node.set_cost_index(RRIndexedDataId(CHANX_COST_INDEX_START + num_segments + seg_index));

/* Add the node to spatial lookup */
auto& rr_graph = (*rr_nodes);
Expand Down
4 changes: 2 additions & 2 deletions vpr/src/route/route_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ float get_rr_cong_cost(int inode, float pres_fac);
/* Returns the base cost of using this rr_node */
inline float get_single_rr_cong_base_cost(int inode) {
auto& device_ctx = g_vpr_ctx.device();
auto cost_index = device_ctx.rr_nodes[inode].cost_index();
auto cost_index = device_ctx.rr_graph.node_cost_index(RRNodeId(inode));

return device_ctx.rr_indexed_data[cost_index].base_cost;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ inline float get_single_rr_cong_cost(int inode, float pres_fac) {
pres_cost = 1.;
}

auto cost_index = device_ctx.rr_nodes[inode].cost_index();
auto cost_index = rr_graph.node_cost_index(RRNodeId(inode));

float cost = device_ctx.rr_indexed_data[cost_index].base_cost * route_ctx.rr_node_route_inf[inode].acc_cost * pres_cost;

Expand Down
6 changes: 3 additions & 3 deletions vpr/src/route/route_timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,10 +1550,10 @@ void update_rr_base_costs(int fanout) {
factor = sqrt(fanout);

for (index = CHANX_COST_INDEX_START; index < device_ctx.rr_indexed_data.size(); index++) {
if (device_ctx.rr_indexed_data[index].T_quadratic > 0.) { /* pass transistor */
device_ctx.rr_indexed_data[index].base_cost = device_ctx.rr_indexed_data[index].saved_base_cost * factor;
if (device_ctx.rr_indexed_data[RRIndexedDataId(index)].T_quadratic > 0.) { /* pass transistor */
device_ctx.rr_indexed_data[RRIndexedDataId(index)].base_cost = device_ctx.rr_indexed_data[RRIndexedDataId(index)].saved_base_cost * factor;
} else {
device_ctx.rr_indexed_data[index].base_cost = device_ctx.rr_indexed_data[index].saved_base_cost;
device_ctx.rr_indexed_data[RRIndexedDataId(index)].base_cost = device_ctx.rr_indexed_data[RRIndexedDataId(index)].saved_base_cost;
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions vpr/src/route/router_lookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n
int num_segs_ortho_dir = 0;
int num_segs_same_dir = get_expected_segs_to_target(node, target_node, &num_segs_ortho_dir);

int cost_index = device_ctx.rr_nodes.node_cost_index(node);
auto cost_index = rr_graph.node_cost_index(node);
int ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;

const auto& same_data = device_ctx.rr_indexed_data[cost_index];
const auto& ortho_data = device_ctx.rr_indexed_data[ortho_cost_index];
const auto& ipin_data = device_ctx.rr_indexed_data[IPIN_COST_INDEX];
const auto& sink_data = device_ctx.rr_indexed_data[SINK_COST_INDEX];
const auto& ortho_data = device_ctx.rr_indexed_data[RRIndexedDataId(ortho_cost_index)];
const auto& ipin_data = device_ctx.rr_indexed_data[RRIndexedDataId(IPIN_COST_INDEX)];
const auto& sink_data = device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)];

float cong_cost = num_segs_same_dir * same_data.base_cost
+ num_segs_ortho_dir * ortho_data.base_cost
Expand All @@ -83,7 +83,7 @@ std::pair<float, float> ClassicLookahead::get_expected_delay_and_cong(RRNodeId n

return std::make_pair(params.criticality * Tdel, (1 - params.criticality) * cong_cost);
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
return std::make_pair(0., device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost);
return std::make_pair(0., device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)].base_cost);

} else { /* Change this if you want to investigate route-throughs */
return std::make_pair(0., 0.);
Expand Down Expand Up @@ -113,17 +113,18 @@ static int get_expected_segs_to_target(RRNodeId inode, RRNodeId target_node, int
const auto& rr_graph = device_ctx.rr_graph;

t_rr_type rr_type;
int target_x, target_y, num_segs_same_dir, cost_index, ortho_cost_index;
int target_x, target_y, num_segs_same_dir, ortho_cost_index;
RRIndexedDataId cost_index;
int no_need_to_pass_by_clb;
float inv_length, ortho_inv_length, ylow, yhigh, xlow, xhigh;

target_x = rr_graph.node_xlow(target_node);
target_y = rr_graph.node_ylow(target_node);

cost_index = device_ctx.rr_nodes.node_cost_index(inode);
cost_index = rr_graph.node_cost_index(inode);
inv_length = device_ctx.rr_indexed_data[cost_index].inv_length;
ortho_cost_index = device_ctx.rr_indexed_data[cost_index].ortho_cost_index;
ortho_inv_length = device_ctx.rr_indexed_data[ortho_cost_index].inv_length;
ortho_inv_length = device_ctx.rr_indexed_data[RRIndexedDataId(ortho_cost_index)].inv_length;
rr_type = rr_graph.node_type(inode);

if (rr_type == CHANX) {
Expand Down
5 changes: 1 addition & 4 deletions vpr/src/route/router_lookahead_cost_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ void CostMap::set_counts(size_t seg_count) {
*/
int CostMap::node_to_segment(int from_node_ind) const {
const auto& device_ctx = g_vpr_ctx.device();

auto& from_node = device_ctx.rr_nodes[from_node_ind];

int from_cost_index = from_node.cost_index();
auto from_cost_index = device_ctx.rr_graph.node_cost_index(RRNodeId(from_node_ind));
return device_ctx.rr_indexed_data[from_cost_index].seg_index;
}

Expand Down
5 changes: 2 additions & 3 deletions vpr/src/route/router_lookahead_extended_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ bool ExtendedMapLookahead::add_paths(RRNodeId start_node,
auto parent = start_node;
for (auto it = path.rbegin(); it != path.rend(); it++) {
RRNodeId this_node(*it);
auto& here = device_ctx.rr_nodes[*it];
int seg_index = device_ctx.rr_indexed_data[here.cost_index()].seg_index;
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(this_node)].seg_index;

int from_x = rr_graph.node_xlow(this_node);
int from_y = rr_graph.node_ylow(this_node);
Expand Down Expand Up @@ -587,7 +586,7 @@ float ExtendedMapLookahead::get_expected_cost(
} else if (rr_type == IPIN) { /* Change if you're allowing route-throughs */
// This is to return only the cost between the IPIN and SINK. No need to
// query the cost map, as the routing of this connection is almost done.
return device_ctx.rr_indexed_data[SINK_COST_INDEX].base_cost;
return device_ctx.rr_indexed_data[RRIndexedDataId(SINK_COST_INDEX)].base_cost;
} else { /* Change this if you want to investigate route-throughs */
return 0.;
}
Expand Down
Loading