Skip to content

Commit 53490a8

Browse files
committed
[vpr][route][crr] add remove_dangling_chan_nodes
1 parent 2aa56e2 commit 53490a8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

vpr/src/route/rr_graph_generation/tileable_rr_graph/tileable_rr_graph_builder.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* producing large FPGA fabrics.
88
***********************************************************************/
99
/* Headers from vtrutil library */
10+
#include <fstream>
11+
1012
#include "vtr_assert.h"
1113
#include "vtr_time.h"
1214
#include "vtr_log.h"
@@ -28,6 +30,8 @@
2830

2931
#include "globals.h"
3032

33+
static void remove_dangling_chan_nodes(RRGraphBuilder& rr_graph_builder);
34+
3135
/************************************************************************
3236
* Main function of this file
3337
* Builder for a detailed uni-directional tileable rr_graph
@@ -286,6 +290,10 @@ void build_tileable_unidir_rr_graph(const std::vector<t_physical_tile_type>& typ
286290
// Save the track ids for tileable routing resource graph
287291
device_ctx.rr_node_track_ids = rr_node_track_ids;
288292

293+
if (crr_opts.remove_dangling_nodes) {
294+
remove_dangling_chan_nodes(device_ctx.rr_graph_builder);
295+
}
296+
289297
// Build incoming edges
290298
device_ctx.rr_graph_builder.partition_edges();
291299
device_ctx.rr_graph_builder.build_in_edges();
@@ -309,3 +317,34 @@ void build_tileable_unidir_rr_graph(const std::vector<t_physical_tile_type>& typ
309317

310318
check_rr_graph(device_ctx.rr_graph, types, device_ctx.rr_indexed_data, grids, vib_grid, device_ctx.chan_width, e_graph_type::UNIDIR_TILEABLE, false);
311319
}
320+
321+
static void remove_dangling_chan_nodes(RRGraphBuilder& rr_graph_builder) {
322+
t_rr_graph_storage& rr_nodes = rr_graph_builder.rr_nodes();
323+
std::vector<RRNodeId> dangling_nodes;
324+
325+
for (size_t node_index = 0; node_index < rr_nodes.size(); ++node_index) {
326+
RRNodeId node = RRNodeId(node_index);
327+
if (rr_nodes.node_type(node) == e_rr_type::CHANX || rr_nodes.node_type(node) == e_rr_type::CHANY) {
328+
if (rr_nodes.fan_in(node) == 0) {
329+
dangling_nodes.push_back(node);
330+
}
331+
}
332+
}
333+
334+
// Print the info about nodes to be removed in removed_nodes.txt
335+
std::ofstream removed_nodes_file("removed_nodes.txt");
336+
for (const auto& node : dangling_nodes) {
337+
size_t node_index = size_t(node);
338+
auto node_type = rr_nodes.node_type(node);
339+
auto x_low = rr_nodes.node_xlow(node);
340+
auto y_low = rr_nodes.node_ylow(node);
341+
auto x_high = rr_nodes.node_xhigh(node);
342+
auto y_high = rr_nodes.node_yhigh(node);
343+
removed_nodes_file << node_index << " " << rr_node_typename[node_type] << " (" << x_low << "," << y_low << ") to (" << x_high << "," << y_high << ")" << std::endl;
344+
}
345+
removed_nodes_file.close();
346+
347+
rr_nodes.remove_nodes(dangling_nodes);
348+
349+
350+
}

0 commit comments

Comments
 (0)