Skip to content

Commit da0d678

Browse files
committed
[vpr] fixed a bug where rr graph I/O always require node_ptc_nums
1 parent 1088c3c commit da0d678

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

libs/librrgraph/src/base/rr_graph_builder.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,39 @@ std::vector<RREdgeId> RRGraphBuilder::node_in_edges(RRNodeId node) const {
240240

241241
void RRGraphBuilder::set_node_ptc_nums(RRNodeId node, const std::string& ptc_str) {
242242
VTR_ASSERT(size_t(node) < node_storage_.size());
243-
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
244243
std::vector<std::string> ptc_tokens = vtr::StringToken(ptc_str).split(",");
245244
VTR_ASSERT(ptc_tokens.size() >= 1);
246245
set_node_ptc_num(node, std::stoi(ptc_tokens[0]));
247-
node_ptc_nums_[node].resize(ptc_tokens.size());
248-
for (size_t iptc = 0; iptc < ptc_tokens.size(); iptc++) {
249-
node_ptc_nums_[node].push_back(std::stoi(ptc_tokens[iptc]));
246+
if (ptc_tokens.size() > 1) {
247+
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
248+
node_ptc_nums_[node].resize(ptc_tokens.size());
249+
for (size_t iptc = 0; iptc < ptc_tokens.size(); iptc++) {
250+
node_ptc_nums_[node][iptc] = std::stoi(ptc_tokens[iptc]);
251+
}
250252
}
251253
}
252254

253255
std::string RRGraphBuilder::node_ptc_nums_to_string(RRNodeId node) const {
254-
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
255256
std::string ret;
256-
for (size_t iptc = 0; iptc < node_ptc_nums_[node].size(); iptc++) {
257-
ret += std::to_string(node_ptc_nums_[node][iptc]) + ",";
257+
if (node_ptc_nums_.empty()) {
258+
ret = std::to_string(node_storage_.node_ptc_num(node));
259+
} else {
260+
VTR_ASSERT(size_t(node) < node_ptc_nums_.size());
261+
for (size_t iptc = 0; iptc < node_ptc_nums_[node].size(); iptc++) {
262+
ret += std::to_string(node_ptc_nums_[node][iptc]) + ",";
263+
}
264+
/* Remove the last comma */
265+
ret.pop_back();
258266
}
259-
/* Remove the last comma */
260-
ret.pop_back();
261267
return ret;
262268
}
263-
269+
270+
bool RRGraphBuilder::node_contain_multiple_ptc(RRNodeId node) const {
271+
if (node_ptc_nums_.empty()) {
272+
return false;
273+
}
274+
return node_ptc_nums_[node].size() > 1;
275+
}
264276

265277
void RRGraphBuilder::add_node_track_num(RRNodeId node, vtr::Point<size_t> node_offset, short track_id) {
266278
VTR_ASSERT(size_t(node) < node_storage_.size());

libs/librrgraph/src/base/rr_graph_builder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ class RRGraphBuilder {
232232
/** @brief With a given node, output ptc numbers into a string (use comma as delima). This function is used by rr graph writer only. Not suggested for internal builder!!! */
233233
std::string node_ptc_nums_to_string(RRNodeId node) const;
234234

235+
/** @brief Identify if a node contains multiple ptc numbers. Mainly used by I/O reader only. Not suggest for internal builder */
236+
bool node_contain_multiple_ptc(RRNodeId node) const;
237+
235238
/** @brief Set the node direction; The node direction is only available of routing channel nodes, such as x-direction routing tracks (CHANX) and y-direction routing tracks (CHANY). For other nodes types, this value is not meaningful and should be set to NONE. */
236239
inline void set_node_direction(RRNodeId id, Direction new_direction) {
237240
node_storage_.set_node_direction(id, new_direction);

libs/librrgraph/src/io/rr_graph_uxsdcxx_serializer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,10 @@ class RrGraphSerializer final : public uxsd::RrGraphBase<RrGraphContextTypes> {
17921792
auto node = (*rr_nodes_)[inode];
17931793
rr_graph_builder.add_node_to_all_locs(node.id());
17941794
/* Set track numbers as a node may have multiple ptc */
1795-
if (CHANX == rr_graph_->node_type(node.id()) || CHANY == rr_graph_->node_type(node.id())) {
1796-
rr_graph_builder.add_track_node_to_lookup(node.id());
1795+
if (rr_graph_builder.node_contain_multiple_ptc(node.id())) {
1796+
if (CHANX == rr_graph_->node_type(node.id()) || CHANY == rr_graph_->node_type(node.id())) {
1797+
rr_graph_builder.add_track_node_to_lookup(node.id());
1798+
}
17971799
}
17981800
}
17991801
}

0 commit comments

Comments
 (0)