4
4
#include < set>
5
5
#include < fstream>
6
6
#include < string>
7
+ #include < iomanip>
7
8
8
9
#include " physical_types_util.h"
9
10
#include " route_tree.h"
@@ -249,18 +250,35 @@ static void write_channel_occupancy_to_file(const vtr::Matrix<int>& chanx_occ,
249
250
const vtr::Matrix<int >& chany_occ) {
250
251
const auto & device_ctx = g_vpr_ctx.device ();
251
252
253
+ constexpr int w_coord = 6 ;
254
+ constexpr int w_value = 12 ;
255
+ constexpr int w_percent = 10 ;
256
+
252
257
// Write X-directed channels
253
258
std::ofstream chanx_file (" chanx_occupancy.txt" );
254
259
if (chanx_file.is_open ()) {
255
- chanx_file << " x,y,occupancy,percentage,capacity\n " ;
260
+ chanx_file << std::setw (w_coord) << " x"
261
+ << std::setw (w_coord) << " y"
262
+ << std::setw (w_value) << " occupancy"
263
+ << std::setw (w_percent) << " %"
264
+ << std::setw (w_value) << " capacity"
265
+ << " \n " ;
266
+
256
267
for (size_t j = 0 ; j < chanx_occ.dim_size (1 ); ++j) {
257
268
int capacity = device_ctx.chan_width .x_list [j];
258
269
for (size_t i = 0 ; i < chanx_occ.dim_size (0 ); ++i) {
259
270
int occ = chanx_occ[i][j];
260
- float percent = capacity > 0 ? static_cast <float >(occ) / capacity : 0 .0f ;
261
- chanx_file << i << " ," << j << " ," << occ << " ," << percent << " ," << capacity << " \n " ;
271
+ float percent = capacity > 0 ? static_cast <float >(occ) / capacity * 100 .0f : 0 .0f ;
272
+
273
+ chanx_file << std::setw (w_coord) << i
274
+ << std::setw (w_coord) << j
275
+ << std::setw (w_value) << occ
276
+ << std::setw (w_percent) << std::fixed << std::setprecision (3 ) << percent
277
+ << std::setw (w_value) << capacity
278
+ << " \n " ;
262
279
}
263
280
}
281
+
264
282
chanx_file.close ();
265
283
} else {
266
284
VTR_LOG_WARN (" Failed to open chanx_occupancy.txt for writing.\n " );
@@ -269,15 +287,28 @@ static void write_channel_occupancy_to_file(const vtr::Matrix<int>& chanx_occ,
269
287
// Write Y-directed channels
270
288
std::ofstream chany_file (" chany_occupancy.txt" );
271
289
if (chany_file.is_open ()) {
272
- chany_file << " x,y,occupancy,percentage,capacity\n " ;
290
+ chany_file << std::setw (w_coord) << " x"
291
+ << std::setw (w_coord) << " y"
292
+ << std::setw (w_value) << " occupancy"
293
+ << std::setw (w_percent) << " %"
294
+ << std::setw (w_value) << " capacity"
295
+ << " \n " ;
296
+
273
297
for (size_t i = 0 ; i < chany_occ.dim_size (0 ); ++i) {
274
298
int capacity = device_ctx.chan_width .y_list [i];
275
299
for (size_t j = 0 ; j < chany_occ.dim_size (1 ); ++j) {
276
300
int occ = chany_occ[i][j];
277
- float percent = capacity > 0 ? static_cast <float >(occ) / capacity : 0 .0f ;
278
- chany_file << i << " ," << j << " ," << occ << " ," << percent << " ," << capacity << " \n " ;
301
+ float percent = capacity > 0 ? static_cast <float >(occ) / capacity * 100 .0f : 0 .0f ;
302
+
303
+ chany_file << std::setw (w_coord) << i
304
+ << std::setw (w_coord) << j
305
+ << std::setw (w_value) << occ
306
+ << std::setw (w_percent) << std::fixed << std::setprecision (3 ) << percent
307
+ << std::setw (w_value) << capacity
308
+ << " \n " ;
279
309
}
280
310
}
311
+
281
312
chany_file.close ();
282
313
} else {
283
314
VTR_LOG_WARN (" Failed to open chany_occupancy.txt for writing.\n " );
0 commit comments