Skip to content

Commit 9ee1ba7

Browse files
write channel coordinate and occupancy percentage to file
1 parent d1f794e commit 9ee1ba7

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

vpr/src/base/stats.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ static void load_channel_occupancies(const Netlist<>& net_list,
3232
vtr::Matrix<int>& chany_occ);
3333

3434
/**
35-
* @brief Writes channel occupancy data to text files.
35+
* @brief Writes detailed channel occupancy info to text files.
3636
*
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
3942
*
4043
* @param chanx_occ Matrix containing occupancy values for X-directed channels.
4144
* @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 /***/) {
244247

245248
static void write_channel_occupancy_to_file(const vtr::Matrix<int>& chanx_occ,
246249
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
248253
std::ofstream chanx_file("chanx_occupancy.txt");
249254
if (chanx_file.is_open()) {
255+
chanx_file << "x,y,occupancy,percentage,capacity\n";
250256
for (size_t j = 0; j < chanx_occ.dim_size(1); ++j) {
257+
int capacity = device_ctx.chan_width.x_list[j];
251258
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";
255262
}
256-
chanx_file << "\n";
257263
}
258264
chanx_file.close();
259265
} else {
260266
VTR_LOG_WARN("Failed to open chanx_occupancy.txt for writing.\n");
261267
}
262268

263-
// Write Y-directed channel occupancy
269+
// Write Y-directed channels
264270
std::ofstream chany_file("chany_occupancy.txt");
265271
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";
271279
}
272-
chany_file << "\n";
273280
}
274281
chany_file.close();
275282
} else {

0 commit comments

Comments
 (0)