Skip to content

Commit 7cd983f

Browse files
authored
Merge pull request #2179 from verilog-to-routing/track_dir_utilization
Print WL Information Based on Direction and Length
2 parents 8f86a05 + cca3076 commit 7cd983f

File tree

1 file changed

+58
-47
lines changed

1 file changed

+58
-47
lines changed

vpr/src/route/segment_stats.cpp

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ void get_segment_usage_stats(std::vector<t_segment_inf>& segment_inf) {
2020
* are counted as full-length segments (e.g. length 4 even if the last 2 *
2121
* units of wire were chopped off by the chip edge). */
2222

23-
int length, max_segment_length;
23+
int max_segment_length;
2424
RRIndexedDataId cost_index;
25-
int *seg_occ_by_length, *seg_cap_by_length; /* [0..max_segment_length] */
26-
int *seg_occ_by_type, *seg_cap_by_type; /* [0..num_segment-1] */
2725
float utilization;
2826

2927
auto& device_ctx = g_vpr_ctx.device();
@@ -41,37 +39,65 @@ void get_segment_usage_stats(std::vector<t_segment_inf>& segment_inf) {
4139
max_segment_name_length = std::max(max_segment_name_length, static_cast<int>(segment_inf[seg_type].name.size()));
4240
}
4341

44-
seg_occ_by_length = new int[max_segment_length + 1];
45-
seg_cap_by_length = new int[max_segment_length + 1];
42+
std::map<e_parallel_axis, std::vector<int>> directed_occ_by_length = {
43+
{X_AXIS, std::vector<int>(max_segment_length + 1, 0)},
44+
{Y_AXIS, std::vector<int>(max_segment_length + 1, 0)}};
4645

47-
for (int i = 0; i < max_segment_length + 1; i++) {
48-
seg_occ_by_length[i] = 0;
49-
seg_cap_by_length[i] = 0;
50-
}
51-
52-
seg_occ_by_type = new int[segment_inf.size()];
53-
seg_cap_by_type = new int[segment_inf.size()];
54-
55-
for (size_t i = 0; i < segment_inf.size(); i++) {
56-
seg_occ_by_type[i] = 0;
57-
seg_cap_by_type[i] = 0;
58-
}
46+
std::map<e_parallel_axis, std::vector<int>> directed_cap_by_length = {
47+
{X_AXIS, std::vector<int>(max_segment_length + 1, 0)},
48+
{Y_AXIS, std::vector<int>(max_segment_length + 1, 0)}};
5949

6050
for (const RRNodeId& rr_id : device_ctx.rr_graph.nodes()) {
6151
size_t inode = (size_t)rr_id;
62-
if (rr_graph.node_type(rr_id) == CHANX || rr_graph.node_type(rr_id) == CHANY) {
52+
auto node_type = rr_graph.node_type(rr_id);
53+
if (node_type == CHANX || node_type == CHANY) {
6354
cost_index = rr_graph.node_cost_index(rr_id);
6455
size_t seg_type = device_ctx.rr_indexed_data[cost_index].seg_index;
65-
56+
int length = -1;
6657
if (!segment_inf[seg_type].longline)
6758
length = segment_inf[seg_type].length;
6859
else
6960
length = LONGLINE;
7061
const short& inode_capacity = rr_graph.node_capacity(rr_id);
71-
seg_occ_by_length[length] += route_ctx.rr_node_route_inf[inode].occ();
72-
seg_cap_by_length[length] += inode_capacity;
73-
seg_occ_by_type[seg_type] += route_ctx.rr_node_route_inf[inode].occ();
74-
seg_cap_by_type[seg_type] += inode_capacity;
62+
int occ = route_ctx.rr_node_route_inf[inode].occ();
63+
auto ax = (node_type == CHANX) ? X_AXIS : Y_AXIS;
64+
directed_occ_by_length[ax][length] += occ;
65+
directed_cap_by_length[ax][length] += inode_capacity;
66+
}
67+
}
68+
69+
VTR_LOG("\n");
70+
VTR_LOG("Total Number of Wiring Segments by Direction: direction length number\n");
71+
VTR_LOG(" --------- ------ -------\n");
72+
for (int length = 0; length <= max_segment_length; length++) {
73+
for (auto ax : {X_AXIS, Y_AXIS}) {
74+
std::string ax_name = (ax == X_AXIS) ? "X" : "Y";
75+
if (directed_cap_by_length[ax][length] != 0) {
76+
std::string length_str = (length == LONGLINE) ? "longline" : std::to_string(length);
77+
VTR_LOG(" %s%s %s%s %6d\n",
78+
std::string(std::max(9 - (int)ax_name.length(), 0), ' ').c_str(),
79+
ax_name.c_str(),
80+
std::string(std::max(6 - (int)length_str.length(), 0), ' ').c_str(),
81+
length_str.c_str(),
82+
directed_cap_by_length[ax][length]);
83+
}
84+
}
85+
}
86+
87+
for (auto ax : {X_AXIS, Y_AXIS}) {
88+
std::string ax_name = (ax == X_AXIS) ? "X" : "Y";
89+
VTR_LOG("\n");
90+
VTR_LOG("%s - Directed Wiring Segment usage by length: length utilization\n", ax_name.c_str());
91+
VTR_LOG(" ------ -----------\n");
92+
for (int length = 0; length <= max_segment_length; length++) {
93+
if (directed_cap_by_length[ax][length] != 0) {
94+
std::string length_str = (length == LONGLINE) ? "longline" : std::to_string(length);
95+
utilization = (float)directed_occ_by_length[ax][length] / (float)directed_cap_by_length[ax][length];
96+
VTR_LOG(" %s%s %11.3g\n",
97+
std::string(std::max(6 - (int)length_str.length(), 0), ' ').c_str(),
98+
length_str.c_str(),
99+
utilization);
100+
}
75101
}
76102
}
77103

@@ -80,33 +106,18 @@ void get_segment_usage_stats(std::vector<t_segment_inf>& segment_inf) {
80106
VTR_LOG(" %s ---- -----------\n", std::string(std::max(4, max_segment_name_length), '-').c_str());
81107

82108
for (size_t seg_type = 0; seg_type < segment_inf.size(); seg_type++) {
83-
if (seg_cap_by_type[seg_type] != 0) {
109+
int seg_length = segment_inf[seg_type].length;
110+
if (directed_cap_by_length[X_AXIS][seg_length] != 0 || directed_cap_by_length[Y_AXIS][seg_length] != 0) {
84111
std::string seg_name = segment_inf[seg_type].name;
85112
int seg_name_size = static_cast<int>(seg_name.size());
86-
utilization = (float)seg_occ_by_type[seg_type] / (float)seg_cap_by_type[seg_type];
113+
int occ = 0;
114+
int cap = 0;
115+
for (auto ax : {X_AXIS, Y_AXIS}) {
116+
occ += directed_occ_by_length[ax][seg_length];
117+
cap = directed_cap_by_length[ax][seg_length];
118+
}
119+
utilization = (float)occ / (float)cap;
87120
VTR_LOG(" %s%s %4d %11.3g\n", std::string(std::max(4 - seg_name_size, (max_segment_name_length - seg_name_size)), ' ').c_str(), seg_name.c_str(), seg_type, utilization);
88121
}
89122
}
90-
91-
VTR_LOG("\n");
92-
VTR_LOG("Segment usage by length: length utilization\n");
93-
VTR_LOG(" ------ -----------\n");
94-
95-
for (length = 1; length <= max_segment_length; length++) {
96-
if (seg_cap_by_length[length] != 0) {
97-
utilization = (float)seg_occ_by_length[length] / (float)seg_cap_by_length[length];
98-
VTR_LOG(" %6d %11.3g\n", length, utilization);
99-
}
100-
}
101-
VTR_LOG("\n");
102-
103-
if (seg_cap_by_length[LONGLINE] != 0) {
104-
utilization = (float)seg_occ_by_length[LONGLINE] / (float)seg_cap_by_length[LONGLINE];
105-
VTR_LOG(" longline %5.3g\n", utilization);
106-
}
107-
108-
delete[](seg_occ_by_length);
109-
delete[](seg_cap_by_length);
110-
delete[](seg_occ_by_type);
111-
delete[](seg_cap_by_type);
112123
}

0 commit comments

Comments
 (0)