@@ -32,10 +32,13 @@ static void load_channel_occupancies(const Netlist<>& net_list,
32
32
vtr::Matrix<int >& chany_occ);
33
33
34
34
/* *
35
- * @brief Writes channel occupancy data to text files.
35
+ * @brief Writes detailed channel occupancy info to text files.
36
36
*
37
- * Writes the occupancy of X-directed and Y-directed channels into
38
- * "chanx_occupancy.txt" and "chany_occupancy.txt" respectively.
37
+ * For each channel segment in X and Y directions, outputs:
38
+ * - Channel coordinate (x, y)
39
+ * - Occupancy count
40
+ * - Occupancy percentage (occupancy / capacity)
41
+ * - Channel capacity
39
42
*
40
43
* @param chanx_occ Matrix containing occupancy values for X-directed channels.
41
44
* @param chany_occ Matrix containing occupancy values for Y-directed channels.
@@ -244,32 +247,36 @@ static void get_channel_occupancy_stats(const Netlist<>& net_list, bool /***/) {
244
247
245
248
static void write_channel_occupancy_to_file (const vtr::Matrix<int >& chanx_occ,
246
249
const vtr::Matrix<int >& chany_occ) {
247
- // Write X-directed channel occupancy
250
+ const auto & device_ctx = g_vpr_ctx.device ();
251
+
252
+ // Write X-directed channels
248
253
std::ofstream chanx_file (" chanx_occupancy.txt" );
249
254
if (chanx_file.is_open ()) {
255
+ chanx_file << " x,y,occupancy,percentage,capacity\n " ;
250
256
for (size_t j = 0 ; j < chanx_occ.dim_size (1 ); ++j) {
257
+ int capacity = device_ctx.chan_width .x_list [j];
251
258
for (size_t i = 0 ; i < chanx_occ.dim_size (0 ); ++i) {
252
- chanx_file << chanx_occ[i][j];
253
- if (i != chanx_occ. dim_size ( 0 ) - 1 )
254
- chanx_file << " , " ;
259
+ 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 " ;
255
262
}
256
- chanx_file << " \n " ;
257
263
}
258
264
chanx_file.close ();
259
265
} else {
260
266
VTR_LOG_WARN (" Failed to open chanx_occupancy.txt for writing.\n " );
261
267
}
262
268
263
- // Write Y-directed channel occupancy
269
+ // Write Y-directed channels
264
270
std::ofstream chany_file (" chany_occupancy.txt" );
265
271
if (chany_file.is_open ()) {
266
- for (size_t j = 0 ; j < chany_occ.dim_size (1 ); ++j) {
267
- for (size_t i = 0 ; i < chany_occ.dim_size (0 ); ++i) {
268
- chany_file << chany_occ[i][j];
269
- if (i != chany_occ.dim_size (0 ) - 1 )
270
- chany_file << " ," ;
272
+ chany_file << " x,y,occupancy,percentage,capacity\n " ;
273
+ for (size_t i = 0 ; i < chany_occ.dim_size (0 ); ++i) {
274
+ int capacity = device_ctx.chan_width .y_list [i];
275
+ for (size_t j = 0 ; j < chany_occ.dim_size (1 ); ++j) {
276
+ 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 " ;
271
279
}
272
- chany_file << " \n " ;
273
280
}
274
281
chany_file.close ();
275
282
} else {
0 commit comments