2323#include " segment_stats.h"
2424#include " channel_stats.h"
2525
26+ #include " crr_common.h"
27+
2628/* ********************* Subroutines local to this module *********************/
2729
30+ // Helper struct to parse the sb_id keys
31+ struct SBKeyParts {
32+ std::string filename;
33+ size_t row;
34+ size_t col;
35+ };
36+
37+ // Parse the key to extract filename, row, and column
38+ static SBKeyParts parse_sb_key (const std::string& key) {
39+ SBKeyParts parts;
40+
41+ // Find the last two underscores
42+ size_t last_underscore = key.rfind (' _' );
43+ size_t second_last_underscore = key.rfind (' _' , last_underscore - 1 );
44+
45+ parts.filename = key.substr (0 , second_last_underscore);
46+ parts.row = std::stoi (key.substr (second_last_underscore + 1 , last_underscore - second_last_underscore - 1 ));
47+ parts.col = std::stoi (key.substr (last_underscore + 1 ));
48+
49+ return parts;
50+ }
51+
52+ // Read CSV file and keep first NUM_EMPTY_ROWS rows completely and first NUM_EMPTY_COLS columns of all other rows
53+ static std::vector<std::vector<std::string>> read_and_trim_csv (const std::string& filepath) {
54+ std::vector<std::vector<std::string>> data;
55+ std::ifstream file (filepath);
56+
57+ if (!file.is_open ()) {
58+ return data;
59+ }
60+
61+ std::string line;
62+ int row_count = 0 ;
63+ while (std::getline (file, line)) {
64+ std::vector<std::string> row;
65+ std::stringstream ss (line);
66+ std::string cell;
67+ int col_count = 0 ;
68+
69+ if (row_count < NUM_EMPTY_ROWS) {
70+ // Keep entire row for first NUM_EMPTY_ROWS rows
71+ while (std::getline (ss, cell, ' ,' )) {
72+ row.push_back (cell);
73+ }
74+ } else {
75+ // Keep only first NUM_EMPTY_COLS columns for other rows
76+ while (std::getline (ss, cell, ' ,' ) && col_count < NUM_EMPTY_COLS) {
77+ row.push_back (cell);
78+ col_count++;
79+ }
80+ }
81+
82+ data.push_back (row);
83+ row_count++;
84+ }
85+
86+ file.close ();
87+ return data;
88+ }
89+
2890/* *
2991 * @brief Loads the two arrays passed in with the total occupancy at each of the
3092 * channel segments in the FPGA.
@@ -149,9 +211,6 @@ void write_sb_count_stats(const Netlist<>& net_list, const std::string& /*out_di
149211
150212 RRNodeId src_node = parent_rt_node.inode ;
151213 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- }
155214 std::vector<RREdgeId> edges = rr_graph.find_edges (src_node, sink_node);
156215 VTR_ASSERT (edges.size () == 1 );
157216 std::string sb_id = rr_graph.edge_crr_id (edges[0 ]);
@@ -167,11 +226,6 @@ void write_sb_count_stats(const Netlist<>& net_list, const std::string& /*out_di
167226 }
168227
169228 // 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 ();
175229}
176230
177231void length_and_bends_stats (const Netlist<>& net_list, bool is_flat) {
0 commit comments