Skip to content

Commit 15c5340

Browse files
authored
Merge pull request #2408 from verilog-to-routing/fix_segment_occ_msg
Fix Segment Usage Message
2 parents 8e59d59 + a88044a commit 15c5340

File tree

1 file changed

+57
-28
lines changed

1 file changed

+57
-28
lines changed

vpr/src/route/segment_stats.cpp

+57-28
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,67 @@ 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 max_segment_length;
2423
RRIndexedDataId cost_index;
2524
float utilization;
2625

2726
auto& device_ctx = g_vpr_ctx.device();
2827
const auto& rr_graph = device_ctx.rr_graph;
2928
auto& route_ctx = g_vpr_ctx.routing();
3029

31-
max_segment_length = 0;
3230
int max_segment_name_length = 0;
33-
for (size_t seg_type = 0; seg_type < segment_inf.size(); seg_type++) {
34-
if (segment_inf[seg_type].longline == false) {
35-
max_segment_length = std::max(max_segment_length,
36-
segment_inf[seg_type].length);
31+
std::map<e_parallel_axis, std::map<int, int>> directed_occ_by_length = {
32+
{X_AXIS, std::map<int, int>()},
33+
{Y_AXIS, std::map<int, int>()}};
34+
35+
std::map<e_parallel_axis, std::map<int, int>> directed_cap_by_length = {
36+
{X_AXIS, std::map<int, int>()},
37+
{Y_AXIS, std::map<int, int>()}};
38+
39+
std::set<int, std::less<int>> segment_lengths;
40+
for (const auto& seg_inf : segment_inf) {
41+
int seg_length = seg_inf.longline ? LONGLINE : seg_inf.length;
42+
43+
for (auto ax : {X_AXIS, Y_AXIS}) {
44+
directed_cap_by_length[ax].insert({seg_length, 0});
45+
directed_occ_by_length[ax].insert({seg_length, 0});
3746
}
3847

39-
max_segment_name_length = std::max(max_segment_name_length, static_cast<int>(segment_inf[seg_type].name.size()));
48+
segment_lengths.insert(seg_length);
49+
50+
max_segment_name_length = std::max(max_segment_name_length, static_cast<int>(seg_inf.name.size()));
4051
}
4152

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)}};
53+
std::map<e_parallel_axis, std::vector<int>> directed_occ_by_type = {
54+
{X_AXIS, std::vector<int>(segment_inf.size(), 0)},
55+
{Y_AXIS, std::vector<int>(segment_inf.size(), 0)}};
4556

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)}};
57+
std::map<e_parallel_axis, std::vector<int>> directed_cap_by_type = {
58+
{X_AXIS, std::vector<int>(segment_inf.size(), 0)},
59+
{Y_AXIS, std::vector<int>(segment_inf.size(), 0)}};
4960

5061
for (RRNodeId inode : device_ctx.rr_graph.nodes()) {
5162
auto node_type = rr_graph.node_type(inode);
5263
if (node_type == CHANX || node_type == CHANY) {
5364
cost_index = rr_graph.node_cost_index(inode);
5465
size_t seg_type = device_ctx.rr_indexed_data[cost_index].seg_index;
55-
int length = -1;
56-
if (!segment_inf[seg_type].longline)
57-
length = segment_inf[seg_type].length;
58-
else
59-
length = LONGLINE;
66+
int length = segment_inf[seg_type].longline ? LONGLINE : segment_inf[seg_type].length;
67+
6068
const short& inode_capacity = rr_graph.node_capacity(inode);
6169
int occ = route_ctx.rr_node_route_inf[inode].occ();
6270
auto ax = (node_type == CHANX) ? X_AXIS : Y_AXIS;
71+
6372
directed_occ_by_length[ax][length] += occ;
6473
directed_cap_by_length[ax][length] += inode_capacity;
74+
75+
directed_occ_by_type[ax][seg_type] += occ;
76+
directed_cap_by_type[ax][seg_type] += inode_capacity;
6577
}
6678
}
6779

6880
VTR_LOG("\n");
6981
VTR_LOG("Total Number of Wiring Segments by Direction: direction length number\n");
7082
VTR_LOG(" --------- ------ -------\n");
71-
for (int length = 0; length <= max_segment_length; length++) {
83+
for (auto length : segment_lengths) {
7284
for (auto ax : {X_AXIS, Y_AXIS}) {
7385
std::string ax_name = (ax == X_AXIS) ? "X" : "Y";
7486
if (directed_cap_by_length[ax][length] != 0) {
@@ -88,35 +100,52 @@ void get_segment_usage_stats(std::vector<t_segment_inf>& segment_inf) {
88100
VTR_LOG("\n");
89101
VTR_LOG("%s - Directed Wiring Segment usage by length: length utilization\n", ax_name.c_str());
90102
VTR_LOG(" ------ -----------\n");
91-
for (int length = 0; length <= max_segment_length; length++) {
103+
for (auto length : segment_lengths) {
92104
if (directed_cap_by_length[ax][length] != 0) {
93105
std::string length_str = (length == LONGLINE) ? "longline" : std::to_string(length);
94106
utilization = (float)directed_occ_by_length[ax][length] / (float)directed_cap_by_length[ax][length];
95107
VTR_LOG(" %s%s %11.3g\n",
96-
std::string(std::max(6 - (int)length_str.length(), 0), ' ').c_str(),
108+
std::string(std::max(7 - (int)length_str.length(), 0), ' ').c_str(),
97109
length_str.c_str(),
98110
utilization);
99111
}
100112
}
101113
}
102114

103115
VTR_LOG("\n");
104-
VTR_LOG("Segment usage by type (index): %sname type utilization\n", std::string(std::max(max_segment_name_length - 4, 0), ' ').c_str());
105-
VTR_LOG(" %s ---- -----------\n", std::string(std::max(4, max_segment_name_length), '-').c_str());
116+
VTR_LOG("Segment occupancy by length: Length utilization\n");
117+
VTR_LOG(" ------ -----------\n");
118+
for (const auto& seg_length : segment_lengths) {
119+
if (directed_cap_by_length[X_AXIS][seg_length] != 0 || directed_cap_by_length[Y_AXIS][seg_length] != 0) {
120+
std::string seg_name = "L" + std::to_string(seg_length);
121+
122+
int occ = 0;
123+
int cap = 0;
124+
for (auto ax : {X_AXIS, Y_AXIS}) {
125+
occ += directed_occ_by_length[ax][seg_length];
126+
cap += directed_cap_by_length[ax][seg_length];
127+
}
128+
utilization = (float)occ / (float)cap;
129+
VTR_LOG(" %s %11.3g\n", seg_name.c_str(), utilization);
130+
}
131+
}
132+
133+
VTR_LOG("\n");
134+
VTR_LOG("Segment occupancy by type: %sname type utilization\n", std::string(std::max(max_segment_name_length - 4, 0), ' ').c_str());
135+
VTR_LOG(" %s ---- -----------\n", std::string(std::max(4, max_segment_name_length), '-').c_str());
106136

107137
for (size_t seg_type = 0; seg_type < segment_inf.size(); seg_type++) {
108-
int seg_length = segment_inf[seg_type].length;
109-
if (directed_cap_by_length[X_AXIS][seg_length] != 0 || directed_cap_by_length[Y_AXIS][seg_length] != 0) {
138+
if (directed_cap_by_type[X_AXIS][seg_type] != 0 || directed_cap_by_type[Y_AXIS][seg_type] != 0) {
110139
std::string seg_name = segment_inf[seg_type].name;
111140
int seg_name_size = static_cast<int>(seg_name.size());
112141
int occ = 0;
113142
int cap = 0;
114143
for (auto ax : {X_AXIS, Y_AXIS}) {
115-
occ += directed_occ_by_length[ax][seg_length];
116-
cap += directed_cap_by_length[ax][seg_length];
144+
occ += directed_occ_by_type[ax][seg_type];
145+
cap += directed_cap_by_type[ax][seg_type];
117146
}
118147
utilization = (float)occ / (float)cap;
119-
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);
148+
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);
120149
}
121150
}
122151
}

0 commit comments

Comments
 (0)