Skip to content

Commit d79f7db

Browse files
authored
Merge pull request #1910 from RapidSilicon/api_rr_segments_graphview
RRGraphView rr_segments() Implementation
2 parents 5398adb + 9d7b3e8 commit d79f7db

10 files changed

+47
-21
lines changed

vpr/src/base/vpr_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct DeviceContext : public Context {
174174
std::vector<t_rr_switch_inf> rr_switch_inf;
175175

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

179179
int num_arch_switches;
180180
t_arch_switch_inf* arch_switch_inf; // [0..(num_arch_switches-1)]

vpr/src/device/rr_graph_view.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "rr_node.h"
33
#include "physical_types.h"
44

5-
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)
5+
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)
66
: node_storage_(node_storage)
77
, node_lookup_(node_lookup)
88
, rr_indexed_data_(rr_indexed_data)

vpr/src/device/rr_graph_view.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class RRGraphView {
3838
RRGraphView(const t_rr_graph_storage& node_storage,
3939
const RRSpatialLookup& node_lookup,
4040
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data,
41-
const std::vector<t_segment_inf>& rr_segments);
41+
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments);
4242

4343
/* Disable copy constructors and copy assignment operator
4444
* This is to avoid accidental copy because it could be an expensive operation considering that the
@@ -209,7 +209,7 @@ class RRGraphView {
209209
} else if (node_type(node) == CHANX || node_type(node) == CHANY) { //for channels, we would like to describe the component with segment specific information
210210
RRIndexedDataId cost_index = node_cost_index(node);
211211
int seg_index = rr_indexed_data_[cost_index].seg_index;
212-
coordinate_string += rr_segments_[seg_index].name; //Write the segment name
212+
coordinate_string += rr_segments(RRSegmentId(seg_index)).name; //Write the segment name
213213
coordinate_string += " length:" + std::to_string(node_length(node)); //add the length of the segment
214214
//Figure out the starting and ending coordinate of the segment depending on the direction
215215

@@ -258,7 +258,13 @@ class RRGraphView {
258258
* This API is very powerful and developers should not use it unless it is necessary,
259259
* e.g the node type is unknown. If the node type is known, the more specific routines, `node_pin_num()`,
260260
* `node_track_num()`and `node_class_num()`, for different types of nodes should be used.*/
261+
/** @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
262+
* adapted to fit the context of routing resource graphs.
263+
*/
261264

265+
inline const t_segment_inf& rr_segments(RRSegmentId seg_id) const {
266+
return rr_segments_[seg_id];
267+
}
262268
inline short node_ptc_num(RRNodeId node) const {
263269
return node_storage_.node_ptc_num(node);
264270
}
@@ -303,7 +309,7 @@ class RRGraphView {
303309
const vtr::vector<RRIndexedDataId, t_rr_indexed_data>& rr_indexed_data_;
304310

305311
/* Segment info for rr nodes */
306-
const std::vector<t_segment_inf>& rr_segments_;
312+
const vtr::vector<RRSegmentId, t_segment_inf>& rr_segments_;
307313
};
308314

309315
#endif

vpr/src/power/power.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ static void power_usage_routing(t_power_usage* power_usage,
912912
wire_length = rr_graph.node_yhigh(rr_node) - rr_graph.node_ylow(rr_node) + 1;
913913
}
914914
int seg_index = device_ctx.rr_indexed_data[rr_graph.node_cost_index(rr_node)].seg_index;
915-
C_wire = wire_length * device_ctx.rr_segments[seg_index].Cmetal;
915+
C_wire = wire_length * rr_graph.rr_segments(RRSegmentId(seg_index)).Cmetal;
916916
//(double)power_ctx.commonly_used->tile_length);
917917
VTR_ASSERT(node_power->selected_input < node_fan_in);
918918

vpr/src/power/power_sizing.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,19 @@ static double power_count_transistors_switchbox() {
378378
power_ctx.arch->mux_transistor_size));
379379

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

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

396396
return transistor_cnt;

vpr/src/route/router_lookahead_extended_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ std::pair<float, float> ExtendedMapLookahead::get_expected_delay_and_cong(RRNode
229229
float expected_cost = expected_delay_cost + expected_cong_cost;
230230

231231
VTR_LOGV_DEBUG(f_router_debug, "Requested lookahead from node %d to %d\n", size_t(from_node), size_t(to_node));
232-
const std::string& segment_name = device_ctx.rr_segments[from_seg_index].name;
232+
const std::string& segment_name = rr_graph.rr_segments(RRSegmentId(from_seg_index)).name;
233233
VTR_LOGV_DEBUG(f_router_debug, "Lookahead returned %s (%d) with distance (%d, %d)\n",
234234
segment_name.c_str(), from_seg_index,
235235
dx, dy);

vpr/src/route/rr_graph.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ static void build_rr_graph(const t_graph_type graph_type,
444444
}
445445

446446
/* START SEG_DETAILS */
447-
device_ctx.rr_segments = segment_inf;
447+
size_t num_segments = segment_inf.size();
448+
device_ctx.rr_segments.reserve(num_segments);
449+
for (long unsigned int iseg = 0; iseg < num_segments; ++iseg) {
450+
device_ctx.rr_segments.push_back(segment_inf[(iseg)]);
451+
}
448452
int num_seg_details = 0;
449453
t_seg_details* seg_details = nullptr;
450454

@@ -1350,6 +1354,8 @@ void free_rr_graph() {
13501354

13511355
device_ctx.rr_switch_inf.clear();
13521356

1357+
device_ctx.rr_segments.clear();
1358+
13531359
device_ctx.switch_fanin_remap.clear();
13541360

13551361
device_ctx.rr_node_metadata.clear();
@@ -2439,7 +2445,7 @@ std::string describe_rr_node(int inode) {
24392445
if (seg_index < (int)device_ctx.rr_segments.size()) {
24402446
msg += vtr::string_fmt(" track: %d longline: %d",
24412447
rr_graph.node_track_num(RRNodeId(inode)),
2442-
device_ctx.rr_segments[seg_index].longline);
2448+
rr_graph.rr_segments(RRSegmentId(seg_index)).longline);
24432449
} else {
24442450
msg += vtr::string_fmt(" track: %d seg_type: ILLEGAL_SEG_INDEX %d",
24452451
rr_graph.node_track_num(RRNodeId(inode)),

vpr/src/route/rr_graph_reader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ void load_rr_file(const t_graph_type graph_type,
4747

4848
auto& device_ctx = g_vpr_ctx.mutable_device();
4949

50-
device_ctx.rr_segments = segment_inf;
50+
size_t num_segments = segment_inf.size();
51+
device_ctx.rr_segments.reserve(num_segments);
52+
for (long unsigned int iseg = 0; iseg < num_segments; ++iseg) {
53+
device_ctx.rr_segments.push_back(segment_inf[(iseg)]);
54+
}
5155

5256
RrGraphSerializer reader(
5357
graph_type,

vpr/src/route/rr_graph_uxsdcxx_serializer.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "check_rr_graph.h"
1717
#include "rr_graph2.h"
1818
#include "rr_graph_indexed_data.h"
19-
2019
class MetadataBind {
2120
public:
2221
MetadataBind(vtr::string_internment* strings, vtr::interned_string empty)
@@ -265,7 +264,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
265264
vtr::vector<RRIndexedDataId, t_rr_indexed_data>* rr_indexed_data,
266265
const size_t num_arch_switches,
267266
const t_arch_switch_inf* arch_switch_inf,
268-
const std::vector<t_segment_inf>& segment_inf,
267+
const vtr::vector<RRSegmentId, t_segment_inf>& segment_inf,
269268
const std::vector<t_physical_tile_type>& physical_tile_types,
270269
const DeviceGrid& grid,
271270
MetadataStorage<int>* rr_node_metadata,
@@ -1152,7 +1151,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
11521151
* </xs:complexType>
11531152
*/
11541153
inline int get_segment_id(const t_segment_inf*& segment) final {
1155-
return segment - &segment_inf_.at(0);
1154+
return segment - &segment_inf_.at(RRSegmentId(0));
11561155
}
11571156
inline const char* get_segment_name(const t_segment_inf*& segment) final {
11581157
return segment->name.c_str();
@@ -1180,14 +1179,14 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
11801179
}
11811180
}
11821181
inline const t_segment_inf* add_segments_segment(void*& /*ctx*/, int id) final {
1183-
return &segment_inf_.at(id);
1182+
return &segment_inf_.at(RRSegmentId(id));
11841183
}
11851184
inline void finish_segments_segment(const t_segment_inf*& /*iter*/) final {}
11861185
inline size_t num_segments_segment(void*& /*iter*/) final {
11871186
return segment_inf_.size();
11881187
}
11891188
inline const t_segment_inf* get_segments_segment(int n, void*& /*ctx*/) final {
1190-
return &segment_inf_.at(n);
1189+
return &segment_inf_.at(RRSegmentId(n));
11911190
}
11921191

11931192
inline void* init_rr_graph_segments(void*& /*ctx*/) final {
@@ -1550,9 +1549,20 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
15501549
process_rr_node_indices();
15511550

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

15541564
alloc_and_load_rr_indexed_data(
1555-
segment_inf_,
1565+
temp_rr_segs,
15561566
*wire_to_rr_ipin_switch_,
15571567
base_cost_type_);
15581568

@@ -1873,7 +1883,7 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
18731883

18741884
const size_t num_arch_switches_;
18751885
const t_arch_switch_inf* arch_switch_inf_;
1876-
const std::vector<t_segment_inf>& segment_inf_;
1886+
const vtr::vector<RRSegmentId, t_segment_inf>& segment_inf_;
18771887
const std::vector<t_physical_tile_type>& physical_tile_types_;
18781888
const DeviceGrid& grid_;
18791889
MetadataStorage<int>* rr_node_metadata_;

vpr/src/util/vpr_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ std::string rr_node_arch_name(int inode) {
219219
auto cost_index = rr_graph.node_cost_index(RRNodeId(inode));
220220
int seg_index = device_ctx.rr_indexed_data[cost_index].seg_index;
221221

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

225225
return rr_node_arch_name;

0 commit comments

Comments
 (0)