Skip to content

Commit 0449dc1

Browse files
committed
rr_graph_indexed_data: add histogram and select its mode
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 9b2d8e7 commit 0449dc1

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

vpr/src/route/rr_graph_indexed_data.cpp

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "rr_graph_indexed_data.h"
1717
#include "read_xml_arch_file.h"
1818

19+
#include "histogram.h"
20+
1921
#include "echo_files.h"
2022

2123
/******************* Subroutines local to this module ************************/
@@ -302,18 +304,18 @@ static void load_rr_indexed_data_T_values() {
302304
auto& rr_indexed_data = device_ctx.rr_indexed_data;
303305

304306
std::vector<int> num_nodes_of_index(rr_indexed_data.size(), 0);
305-
std::vector<float> C_total(rr_indexed_data.size(), 0.0);
306-
std::vector<float> R_total(rr_indexed_data.size(), 0.0);
307+
std::vector<std::vector<float>> C_total(rr_indexed_data.size());
308+
std::vector<std::vector<float>> R_total(rr_indexed_data.size());
307309

308310
/* August 2014: Not all wire-to-wire switches connecting from some wire segment will
309311
* necessarily have the same delay. i.e. a mux with less inputs will have smaller delay
310312
* than a mux with a greater number of inputs. So to account for these differences we will
311313
* get the average R/Tdel/Cinternal values by first averaging them for a single wire segment
312314
* (first for loop below), and then by averaging this value over all wire segments in the channel
313315
* (second for loop below) */
314-
std::vector<double> switch_R_total(rr_indexed_data.size(), 0.0);
315-
std::vector<double> switch_T_total(rr_indexed_data.size(), 0.0);
316-
std::vector<double> switch_Cinternal_total(rr_indexed_data.size(), 0.0);
316+
std::vector<std::vector<float>> switch_R_total(rr_indexed_data.size());
317+
std::vector<std::vector<float>> switch_T_total(rr_indexed_data.size());
318+
std::vector<std::vector<float>> switch_Cinternal_total(rr_indexed_data.size());
317319
std::vector<short> switches_buffered(rr_indexed_data.size(), UNDEFINED);
318320

319321
/* Get average C and R values for all the segments of this type in one *
@@ -343,12 +345,12 @@ static void load_rr_indexed_data_T_values() {
343345
VTR_ASSERT(num_switches > 0);
344346

345347
num_nodes_of_index[cost_index]++;
346-
C_total[cost_index] += rr_nodes[inode].C();
347-
R_total[cost_index] += rr_nodes[inode].R();
348+
C_total[cost_index].push_back(rr_nodes[inode].C());
349+
R_total[cost_index].push_back(rr_nodes[inode].R());
348350

349-
switch_R_total[cost_index] += avg_switch_R;
350-
switch_T_total[cost_index] += avg_switch_T;
351-
switch_Cinternal_total[cost_index] += avg_switch_Cinternal;
351+
switch_R_total[cost_index].push_back(avg_switch_R);
352+
switch_T_total[cost_index].push_back(avg_switch_T);
353+
switch_Cinternal_total[cost_index].push_back(avg_switch_Cinternal);
352354
if (buffered == UNDEFINED) {
353355
/* this segment does not have any outgoing edges to other general routing wires */
354356
continue;
@@ -370,6 +372,8 @@ static void load_rr_indexed_data_T_values() {
370372
}
371373
}
372374

375+
auto& segment_inf = device_ctx.rr_segments;
376+
373377
for (size_t cost_index = CHANX_COST_INDEX_START;
374378
cost_index < rr_indexed_data.size(); cost_index++) {
375379
if (num_nodes_of_index[cost_index] == 0) { /* Segments don't exist. */
@@ -378,11 +382,17 @@ static void load_rr_indexed_data_T_values() {
378382
rr_indexed_data[cost_index].T_quadratic = 0.0;
379383
rr_indexed_data[cost_index].C_load = 0.0;
380384
} else {
381-
float Rnode = R_total[cost_index] / num_nodes_of_index[cost_index];
382-
float Cnode = C_total[cost_index] / num_nodes_of_index[cost_index];
383-
float Rsw = (float)switch_R_total[cost_index] / num_nodes_of_index[cost_index];
384-
float Tsw = (float)switch_T_total[cost_index] / num_nodes_of_index[cost_index];
385-
float Cinternalsw = (float)switch_Cinternal_total[cost_index] / num_nodes_of_index[cost_index];
385+
auto C_total_histogram = build_histogram(C_total[cost_index], 10);
386+
auto R_total_histogram = build_histogram(R_total[cost_index], 10);
387+
auto switch_R_total_histogram = build_histogram(switch_R_total[cost_index], 10);
388+
auto switch_T_total_histogram = build_histogram(switch_T_total[cost_index], 10);
389+
auto switch_Cinternal_total_histogram = build_histogram(switch_Cinternal_total[cost_index], 10);
390+
391+
float Rnode = get_histogram_mode(R_total_histogram);
392+
float Cnode = get_histogram_mode(C_total_histogram);
393+
float Rsw = get_histogram_mode(switch_R_total_histogram);
394+
float Tsw = get_histogram_mode(switch_T_total_histogram);
395+
float Cinternalsw = get_histogram_mode(switch_Cinternal_total_histogram);
386396

387397
if (switches_buffered[cost_index]) {
388398
// Here, we are computing the linear time delay for buffered switches. Tlinear is

vpr/src/util/histogram.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ void print_histogram(std::vector<HistogramBucket> histogram) {
6464
}
6565
}
6666

67+
float get_histogram_mode(std::vector<HistogramBucket> histogram) {
68+
size_t max_count = 0;
69+
float mode = 0.0;
70+
for (auto bucket : histogram) {
71+
if (bucket.count > max_count) {
72+
mode = bucket.max_value;
73+
74+
max_count = bucket.count;
75+
}
76+
}
77+
78+
return mode;
79+
}
80+
6781
std::vector<std::string> format_histogram(std::vector<HistogramBucket> histogram, size_t width) {
6882
std::vector<std::string> lines;
6983

vpr/src/util/histogram.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ std::vector<HistogramBucket> build_histogram(std::vector<float> values, size_t n
1919

2020
void print_histogram(std::vector<HistogramBucket> histogram);
2121

22+
float get_histogram_mode(std::vector<HistogramBucket> histogram);
23+
2224
std::vector<std::string> format_histogram(std::vector<HistogramBucket> histogram, size_t width = 80);
2325

2426
#endif

0 commit comments

Comments
 (0)