Skip to content

RRGraphView rr_segments() Implementation #1910

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 3 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct DeviceContext : public Context {
std::vector<t_rr_switch_inf> rr_switch_inf;

///@brief Wire segment types in RR graph
std::vector<t_segment_inf> rr_segments;
vtr::vector<RRSegmentId, t_segment_inf> rr_segments;

int num_arch_switches;
t_arch_switch_inf* arch_switch_inf; // [0..(num_arch_switches-1)]
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 vtr::vector<RRIndexedDataId, 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 vtr::vector<RRSegmentId, t_segment_inf>& rr_segments)
: node_storage_(node_storage)
, node_lookup_(node_lookup)
, rr_indexed_data_(rr_indexed_data)
Expand Down
12 changes: 9 additions & 3 deletions vpr/src/device/rr_graph_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class 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);
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments);

/* Disable copy constructors and copy assignment operator
* This is to avoid accidental copy because it could be an expensive operation considering that the
Expand Down Expand Up @@ -209,7 +209,7 @@ class RRGraphView {
} else if (node_type(node) == CHANX || node_type(node) == CHANY) { //for channels, we would like to describe the component with segment specific information
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 += rr_segments(RRSegmentId(seg_index)).name; //Write the segment name
coordinate_string += " length:" + std::to_string(node_length(node)); //add the length of the segment
//Figure out the starting and ending coordinate of the segment depending on the direction

Expand Down Expand Up @@ -258,7 +258,13 @@ class RRGraphView {
* This API is very powerful and developers should not use it unless it is necessary,
* e.g the node type is unknown. If the node type is known, the more specific routines, `node_pin_num()`,
* `node_track_num()`and `node_class_num()`, for different types of nodes should be used.*/
/** @brief Return detailed routing segment information with a given id* @note The routing segments here may not be exactly same as those defined in architecture file. They have been
* adapted to fit the context of routing resource graphs.
*/

inline const t_segment_inf& rr_segments(RRSegmentId seg_id) const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From @vaughnbetz: in future, we should think about more high-level API, e.g.,
seg_timing()
seg_delay()
seg_length()

return rr_segments_[seg_id];
}
inline short node_ptc_num(RRNodeId node) const {
return node_storage_.node_ptc_num(node);
}
Expand Down Expand Up @@ -303,7 +309,7 @@ class RRGraphView {
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data_;

/* Segment info for rr nodes */
const std::vector<t_segment_inf>& rr_segments_;
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments_;
};

#endif
2 changes: 1 addition & 1 deletion vpr/src/power/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ static void power_usage_routing(t_power_usage* power_usage,
wire_length = rr_graph.node_yhigh(rr_node) - rr_graph.node_ylow(rr_node) + 1;
}
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;
C_wire = wire_length * rr_graph.rr_segments(RRSegmentId(seg_index)).Cmetal;
//(double)power_ctx.commonly_used->tile_length);
VTR_ASSERT(node_power->selected_input < node_fan_in);

Expand Down
6 changes: 3 additions & 3 deletions vpr/src/power/power_sizing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,19 @@ static double power_count_transistors_switchbox() {
power_ctx.arch->mux_transistor_size));

auto& device_ctx = g_vpr_ctx.device();

const auto& rr_graph = device_ctx.rr_graph;
for (size_t seg_idx = 0; seg_idx < device_ctx.rr_segments.size(); seg_idx++) {
/* In each switchbox, the different types of segments occur with relative freqencies.
* Thus the total number of wires of each segment type is (#tracks * freq * 2).
* The (x2) factor accounts for vertical and horizontal tracks.
* Of the wires of each segment type only (1/seglength) will have a mux&buffer.
*/
float freq_frac = (float)device_ctx.rr_segments[seg_idx].frequency
float freq_frac = (float)rr_graph.rr_segments(RRSegmentId(seg_idx)).frequency
/ (float)MAX_CHANNEL_WIDTH;

transistor_cnt += transistors_per_buf_mux * 2 * freq_frac
* power_ctx.solution_inf.channel_width
* (1 / (float)device_ctx.rr_segments[seg_idx].length);
* (1 / (float)rr_graph.rr_segments(RRSegmentId(seg_idx)).length);
}

return transistor_cnt;
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/route/router_lookahead_extended_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ std::pair<float, float> ExtendedMapLookahead::get_expected_delay_and_cong(RRNode
float expected_cost = expected_delay_cost + expected_cong_cost;

VTR_LOGV_DEBUG(f_router_debug, "Requested lookahead from node %d to %d\n", size_t(from_node), size_t(to_node));
const std::string& segment_name = device_ctx.rr_segments[from_seg_index].name;
const std::string& segment_name = rr_graph.rr_segments(RRSegmentId(from_seg_index)).name;
VTR_LOGV_DEBUG(f_router_debug, "Lookahead returned %s (%d) with distance (%d, %d)\n",
segment_name.c_str(), from_seg_index,
dx, dy);
Expand Down
10 changes: 8 additions & 2 deletions vpr/src/route/rr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ static void build_rr_graph(const t_graph_type graph_type,
}

/* START SEG_DETAILS */
device_ctx.rr_segments = segment_inf;
size_t num_segments = segment_inf.size();
device_ctx.rr_segments.reserve(num_segments);
for (long unsigned int iseg = 0; iseg < num_segments; ++iseg) {
device_ctx.rr_segments.push_back(segment_inf[(iseg)]);
}
int num_seg_details = 0;
t_seg_details* seg_details = nullptr;

Expand Down Expand Up @@ -1350,6 +1354,8 @@ void free_rr_graph() {

device_ctx.rr_switch_inf.clear();

device_ctx.rr_segments.clear();

device_ctx.switch_fanin_remap.clear();

device_ctx.rr_node_metadata.clear();
Expand Down Expand Up @@ -2439,7 +2445,7 @@ std::string describe_rr_node(int inode) {
if (seg_index < (int)device_ctx.rr_segments.size()) {
msg += vtr::string_fmt(" track: %d longline: %d",
rr_graph.node_track_num(RRNodeId(inode)),
device_ctx.rr_segments[seg_index].longline);
rr_graph.rr_segments(RRSegmentId(seg_index)).longline);
} else {
msg += vtr::string_fmt(" track: %d seg_type: ILLEGAL_SEG_INDEX %d",
rr_graph.node_track_num(RRNodeId(inode)),
Expand Down
6 changes: 5 additions & 1 deletion vpr/src/route/rr_graph_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ void load_rr_file(const t_graph_type graph_type,

auto& device_ctx = g_vpr_ctx.mutable_device();

device_ctx.rr_segments = segment_inf;
size_t num_segments = segment_inf.size();
device_ctx.rr_segments.reserve(num_segments);
for (long unsigned int iseg = 0; iseg < num_segments; ++iseg) {
device_ctx.rr_segments.push_back(segment_inf[(iseg)]);
}

RrGraphSerializer reader(
graph_type,
Expand Down
26 changes: 19 additions & 7 deletions vpr/src/route/rr_graph_uxsdcxx_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "check_rr_graph.h"
#include "rr_graph2.h"
#include "rr_graph_indexed_data.h"

#include "globals.h"
class MetadataBind {
public:
MetadataBind(vtr::string_internment* strings, vtr::interned_string empty)
Expand Down Expand Up @@ -265,7 +265,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
vtr::vector<RRIndexedDataId, t_rr_indexed_data>* rr_indexed_data,
const size_t num_arch_switches,
const t_arch_switch_inf* arch_switch_inf,
const std::vector<t_segment_inf>& segment_inf,
const vtr::vector<RRSegmentId, t_segment_inf>& segment_inf,
const std::vector<t_physical_tile_type>& physical_tile_types,
const DeviceGrid& grid,
MetadataStorage<int>* rr_node_metadata,
Expand Down Expand Up @@ -1152,7 +1152,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
* </xs:complexType>
*/
inline int get_segment_id(const t_segment_inf*& segment) final {
return segment - &segment_inf_.at(0);
return segment - &segment_inf_.at(RRSegmentId(0));
}
inline const char* get_segment_name(const t_segment_inf*& segment) final {
return segment->name.c_str();
Expand Down Expand Up @@ -1180,14 +1180,14 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
}
}
inline const t_segment_inf* add_segments_segment(void*& /*ctx*/, int id) final {
return &segment_inf_.at(id);
return &segment_inf_.at(RRSegmentId(id));
}
inline void finish_segments_segment(const t_segment_inf*& /*iter*/) final {}
inline size_t num_segments_segment(void*& /*iter*/) final {
return segment_inf_.size();
}
inline const t_segment_inf* get_segments_segment(int n, void*& /*ctx*/) final {
return &segment_inf_.at(n);
return &segment_inf_.at(RRSegmentId(n));
}

inline void* init_rr_graph_segments(void*& /*ctx*/) final {
Expand Down Expand Up @@ -1547,12 +1547,24 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
}

void finish_load() final {
auto& device_ctx = g_vpr_ctx.mutable_device();
process_rr_node_indices();

rr_graph_builder_->init_fan_in();
/* Create a temp copy to convert from vtr::vector to std::vector
* This is required because the ``alloc_and_load_rr_indexed_data()`` function supports only std::vector data
* type for ``rr_segments``
* Note that this is a dirty fix (to avoid massive code changes)
* TODO: The ``alloc_and_load_rr_indexed_data()`` function should embrace ``vtr::vector`` for ``rr_segments``
*/
std::vector<t_segment_inf> temp_rr_segs;
temp_rr_segs.reserve(segment_inf_.size());
for (auto& rr_seg : device_ctx.rr_segments) {
temp_rr_segs.push_back(rr_seg);
}

alloc_and_load_rr_indexed_data(
segment_inf_,
temp_rr_segs,
*wire_to_rr_ipin_switch_,
base_cost_type_);

Expand Down Expand Up @@ -1873,7 +1885,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {

const size_t num_arch_switches_;
const t_arch_switch_inf* arch_switch_inf_;
const std::vector<t_segment_inf>& segment_inf_;
const vtr::vector<RRSegmentId, t_segment_inf>& segment_inf_;
const std::vector<t_physical_tile_type>& physical_tile_types_;
const DeviceGrid& grid_;
MetadataStorage<int>* rr_node_metadata_;
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/util/vpr_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ std::string rr_node_arch_name(int inode) {
auto cost_index = rr_graph.node_cost_index(RRNodeId(inode));
int seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;

rr_node_arch_name += device_ctx.rr_segments[seg_index].name;
rr_node_arch_name += rr_graph.rr_segments(RRSegmentId(seg_index)).name;
}

return rr_node_arch_name;
Expand Down