Skip to content

Commit 4c0f2dd

Browse files
committed
[vpr][base] add write_sb_count_stats to stats
1 parent ecec621 commit 4c0f2dd

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

vpr/src/base/stats.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,54 @@ void routing_stats(const Netlist<>& net_list,
126126
}
127127
}
128128

129+
void write_sb_count_stats(const Netlist<>& net_list, const std::string& /*out_dir*/) {
130+
const auto& rr_graph = g_vpr_ctx.device().rr_graph;
131+
const auto& route_ctx = g_vpr_ctx.routing();
132+
std::unordered_map<std::string, int> sb_count;
133+
134+
for (ParentNetId net_id : net_list.nets()) {
135+
if (!net_list.net_is_ignored(net_id) && net_list.net_sinks(net_id).size() != 0) {
136+
const vtr::optional<RouteTree>& tree = route_ctx.route_trees[net_id];
137+
if (!tree) {
138+
continue;
139+
}
140+
141+
for (const RouteTreeNode& rt_node : tree.value().all_nodes()) {
142+
auto parent = rt_node.parent();
143+
// Skip the root node
144+
if (!parent) {
145+
continue;
146+
}
147+
148+
const RouteTreeNode& parent_rt_node = parent.value();
149+
150+
RRNodeId src_node = parent_rt_node.inode;
151+
RRNodeId sink_node = rt_node.inode;
152+
if (size_t(src_node) == 175454 && size_t(sink_node) == 213534) {
153+
VTR_LOG("Here - Source node: %zu, Sink node: %zu\n", size_t(src_node), size_t(sink_node));
154+
}
155+
std::vector<RREdgeId> edges = rr_graph.find_edges(src_node, sink_node);
156+
VTR_ASSERT(edges.size() == 1);
157+
std::string sb_id = rr_graph.edge_crr_id(edges[0]);
158+
if (sb_id.empty()) {
159+
continue;
160+
}
161+
if (sb_count.find(sb_id) == sb_count.end()) {
162+
sb_count[sb_id] = 0;
163+
}
164+
sb_count[sb_id]++;
165+
}
166+
}
167+
}
168+
169+
// Write the sb_count to a file
170+
std::ofstream file("sb_count.txt");
171+
for (const auto& [sb_id, count] : sb_count) {
172+
file << sb_id << "," << count << "\n";
173+
}
174+
file.close();
175+
}
176+
129177
void length_and_bends_stats(const Netlist<>& net_list, bool is_flat) {
130178
int max_bends = 0;
131179
int total_bends = 0;

vpr/src/base/stats.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void routing_stats(const Netlist<>& net_list,
2424
RRSwitchId wire_to_ipin_switch,
2525
bool is_flat);
2626

27+
void write_sb_count_stats(const Netlist<>& net_list, const std::string& out_dir);
28+
2729
void print_wirelen_prob_dist(bool is_flat);
2830

2931
void print_lambda();

0 commit comments

Comments
 (0)