Skip to content

Commit 3c8afb7

Browse files
committed
[vpr][crr] change crr_sw_temp_id to std::optional
1 parent 16e8086 commit 3c8afb7

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

libs/librrgraph/src/base/rr_graph_builder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ void RRGraphBuilder::reorder_nodes(e_rr_node_reorder_algorithm reorder_rr_graph_
176176
});
177177
}
178178

179-
void RRGraphBuilder::create_edge_in_cache(RRNodeId src, RRNodeId dest, RRSwitchId edge_switch, bool remapped, std::string sw_template_id_) {
180-
edges_to_build_.emplace_back(src, dest, size_t(edge_switch), remapped, std::move(sw_template_id_));
179+
void RRGraphBuilder::create_edge_in_cache(RRNodeId src,
180+
RRNodeId dest,
181+
RRSwitchId edge_switch,
182+
bool remapped,
183+
std::optional<std::string> sw_template_id_) {
184+
edges_to_build_.emplace_back(src, dest, size_t(edge_switch), remapped, sw_template_id_);
181185
is_edge_dirty_ = true; // Adding a new edge revokes the flag
182186
is_incoming_edge_dirty_ = true;
183187
}

libs/librrgraph/src/base/rr_graph_builder.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ class RRGraphBuilder {
290290

291291
/** @brief Add a new edge to the cache of edges to be built
292292
* @note This will not add an edge to storage. You need to call build_edges() after all the edges are cached. */
293-
void create_edge_in_cache(RRNodeId src, RRNodeId dest, RRSwitchId edge_switch, bool remapped, std::string sw_template_id_="");
293+
void create_edge_in_cache(RRNodeId src,
294+
RRNodeId dest,
295+
RRSwitchId edge_switch,
296+
bool remapped,
297+
std::optional<std::string> sw_template_id_=std::nullopt);
294298

295299
/** @brief Add a new edge to the cache of edges to be built
296300
* @note This will not add an edge to storage! You need to call build_edges() after all the edges are cached! */
@@ -333,8 +337,12 @@ class RRGraphBuilder {
333337
* remap the arch switch id to rr switch id, the edge switch id of this edge shouldn't be changed. For example, when the intra-cluster graph
334338
* is built and the rr-graph related to global resources are read from a file, this parameter is true since the intra-cluster switches are
335339
* also listed in rr-graph file. So, we use that list to use the rr switch id instead of passing arch switch id for intra-cluster edges.*/
336-
inline void emplace_back_edge(RRNodeId src, RRNodeId dest, short edge_switch, bool remapped, std::string sw_template_id="") {
337-
node_storage_.emplace_back_edge(src, dest, edge_switch, remapped, std::move(sw_template_id));
340+
inline void emplace_back_edge(RRNodeId src,
341+
RRNodeId dest,
342+
short edge_switch,
343+
bool remapped,
344+
std::optional<std::string> sw_template_id=std::nullopt) {
345+
node_storage_.emplace_back_edge(src, dest, edge_switch, remapped, sw_template_id);
338346
}
339347
/** @brief Append 1 more RR node to the RR graph. */
340348
inline void emplace_back() {

libs/librrgraph/src/base/rr_graph_storage.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ void t_rr_graph_storage::reserve_edges(size_t num_edges) {
1919
edge_sw_template_id_.reserve(num_edges);
2020
}
2121

22-
void t_rr_graph_storage::emplace_back_edge(RRNodeId src, RRNodeId dest, short edge_switch, bool remapped, std::string sw_template_id) {
22+
void t_rr_graph_storage::emplace_back_edge(RRNodeId src,
23+
RRNodeId dest,
24+
short edge_switch,
25+
bool remapped,
26+
std::optional<std::string> sw_template_id) {
2327
// Cannot mutate edges once edges have been read!
2428
VTR_ASSERT(!edges_read_);
2529
edge_src_node_.emplace_back(src);
2630
edge_dest_node_.emplace_back(dest);
2731
edge_switch_.emplace_back(edge_switch);
2832
edge_remapped_.emplace_back(remapped);
29-
edge_sw_template_id_.emplace_back(sw_template_id);
33+
edge_sw_template_id_.emplace_back(std::move(sw_template_id));
3034
}
3135

3236
// Typical node to edge ratio. This allows a preallocation guess for the edges

libs/librrgraph/src/base/rr_graph_storage.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ class t_rr_graph_storage {
485485
return edge_source_node(edge_id(id, iedge));
486486
}
487487

488-
std::string edge_sw_template_id(RREdgeId edge) const {
488+
const std::optional<std::string>& edge_sw_template_id(RREdgeId edge) const {
489489
return edge_sw_template_id_[edge];
490490
}
491491

@@ -833,7 +833,11 @@ class t_rr_graph_storage {
833833
* of the node. Also, the information about switches is fly-weighted and are accessible with IDs. Thus,
834834
* the number of rr switch types can be higher than the number of arch switch types.
835835
*/
836-
void emplace_back_edge(RRNodeId src, RRNodeId dest, short edge_switch, bool remapped, std::string sw_template_id);
836+
void emplace_back_edge(RRNodeId src,
837+
RRNodeId dest,
838+
short edge_switch,
839+
bool remapped,
840+
std::optional<std::string> sw_template_id);
837841

838842
/** @brief Adds a batch of edges.*/
839843
void alloc_and_load_edges(const t_rr_edge_info_set* rr_edges_to_create);
@@ -933,7 +937,7 @@ class t_rr_graph_storage {
933937
array_rearrange(edge_src_node_, RRNodeId::INVALID());
934938
array_rearrange(edge_dest_node_, RRNodeId::INVALID());
935939
array_rearrange(edge_switch_, LIBRRGRAPH_UNDEFINED_VAL);
936-
array_rearrange(edge_sw_template_id_, "");
940+
array_rearrange(edge_sw_template_id_, std::nullopt);
937941
array_rearrange(edge_remapped_, false);
938942
}
939943

@@ -1112,7 +1116,7 @@ class t_rr_graph_storage {
11121116
* This information can be used for various analyses, such as identifying
11131117
* which edges within each pattern are used most or least frequently.
11141118
*/
1115-
vtr::vector<RREdgeId, std::string> edge_sw_template_id_;
1119+
vtr::vector<RREdgeId, std::optional<std::string>> edge_sw_template_id_;
11161120

11171121
/** @brief
11181122
* The following data structures are only used for tileable routing resource graph.
@@ -1178,7 +1182,7 @@ class t_rr_graph_view {
11781182
const vtr::array_view_id<RREdgeId, const RRNodeId> edge_src_node,
11791183
const vtr::array_view_id<RREdgeId, const RRNodeId> edge_dest_node,
11801184
const vtr::array_view_id<RREdgeId, const short> edge_switch,
1181-
const vtr::array_view_id<RREdgeId, const std::string> edge_sw_template_id,
1185+
const vtr::array_view_id<RREdgeId, const std::optional<std::string>> edge_sw_template_id,
11821186
const std::unordered_map<std::string, RRNodeId>& virtual_clock_network_root_idx,
11831187
const vtr::array_view_id<RRNodeId, const int16_t> node_bend_start,
11841188
const vtr::array_view_id<RRNodeId, const int16_t> node_bend_end)
@@ -1380,7 +1384,7 @@ class t_rr_graph_view {
13801384
return edge_switch_[edge];
13811385
}
13821386

1383-
std::string edge_sw_template_id(RREdgeId edge) const {
1387+
std::optional<std::string> edge_sw_template_id(RREdgeId edge) const {
13841388
return edge_sw_template_id_[edge];
13851389
}
13861390

@@ -1402,7 +1406,7 @@ class t_rr_graph_view {
14021406
vtr::array_view_id<RREdgeId, const RRNodeId> edge_src_node_;
14031407
vtr::array_view_id<RREdgeId, const RRNodeId> edge_dest_node_;
14041408
vtr::array_view_id<RREdgeId, const short> edge_switch_;
1405-
vtr::array_view_id<RREdgeId, const std::string> edge_sw_template_id_;
1409+
vtr::array_view_id<RREdgeId, const std::optional<std::string>> edge_sw_template_id_;
14061410
const std::unordered_map<std::string, RRNodeId>& virtual_clock_network_root_idx_;
14071411

14081412
vtr::array_view_id<RRNodeId, const int16_t> node_bend_start_;

libs/librrgraph/src/base/rr_graph_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class RRGraphView {
515515
return node_storage_.edge_source_node(id, iedge);
516516
}
517517

518-
inline std::string edge_sw_template_id(RREdgeId edge) const {
518+
inline const std::optional<std::string>& edge_sw_template_id(RREdgeId edge) const {
519519
return node_storage_.edge_sw_template_id(edge);
520520
}
521521

vpr/src/base/stats.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ void write_sb_count_stats(const Netlist<>& net_list,
240240
RRNodeId sink_node = rt_node.inode;
241241
std::vector<RREdgeId> edges = rr_graph.find_edges(src_node, sink_node);
242242
VTR_ASSERT(edges.size() == 1);
243-
std::string sb_id = rr_graph.edge_sw_template_id(edges[0]);
244-
if (sb_id.empty()) {
243+
const std::optional<std::string>& sb_id = rr_graph.edge_sw_template_id(edges[0]);
244+
if (!sb_id) {
245245
continue;
246246
}
247-
if (sb_count.find(sb_id) == sb_count.end()) {
248-
sb_count[sb_id] = 0;
247+
if (sb_count.find(*sb_id) == sb_count.end()) {
248+
sb_count[*sb_id] = 0;
249249
}
250-
sb_count[sb_id]++;
250+
sb_count[*sb_id]++;
251251
}
252252
}
253253
}

vpr/src/route/rr_graph_generation/tileable_rr_graph/crr_generator/crr_edge_builder.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ void build_crr_gsb_edges(RRGraphBuilder& rr_graph_builder,
7070
rr_switch_id = find_or_create_crr_switch_id(delay_ps);
7171
}
7272
VTR_ASSERT(rr_switch_id != RRSwitchId::INVALID());
73-
rr_graph_builder.create_edge_in_cache(connection.src_node(), connection.sink_node(), rr_switch_id, false, connection.sw_template_id());
73+
rr_graph_builder.create_edge_in_cache(connection.src_node(),
74+
connection.sink_node(),
75+
rr_switch_id,
76+
false,
77+
std::make_optional(connection.sw_template_id()));
7478
}
7579
}

0 commit comments

Comments
 (0)