Skip to content

Commit 0576503

Browse files
committed
rr_graph: use median instead of mode for C/R Node values
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent fa4d7ab commit 0576503

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

libs/libvtrutil/src/vtr_math.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <map>
2+
#include <algorithm>
23

34
#include "vtr_assert.h"
45
#include "vtr_error.h"
@@ -20,6 +21,19 @@ int ipow(int base, int exp) {
2021
return result;
2122
}
2223

24+
float median(std::vector<float> vector) {
25+
VTR_ASSERT(vector.size() > 0);
26+
27+
std::sort(vector.begin(), vector.end());
28+
29+
auto size = vector.size();
30+
if (size % 2 == 0) {
31+
return (float)(vector[size / 2 - 1] + vector[size / 2]) / 2;
32+
}
33+
34+
return (float)vector[size / 2];
35+
}
36+
2337
/* Performs linear interpolation or extrapolation on the set of (x,y) values specified by the xy_map.
2438
* A requested x value is passed in, and we return the interpolated/extrapolated y value at this requested value of x.
2539
* Meant for maps where both key and element are numbers.

libs/libvtrutil/src/vtr_math.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define VTR_MATH_H
33

44
#include <map>
5+
#include <vector>
56
#include <cmath>
67

78
#include "vtr_assert.h"
@@ -10,6 +11,9 @@ namespace vtr {
1011
/*********************** Math operations *************************************/
1112
int ipow(int base, int exp);
1213

14+
//Returns the median of an input vector.
15+
float median(std::vector<float> vector);
16+
1317
template<typename X, typename Y>
1418
Y linear_interpolate_or_extrapolate(const std::map<X, Y>* xy_map, X requested_x);
1519

vpr/src/route/rr_graph_indexed_data.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "vtr_assert.h"
66
#include "vtr_log.h"
77
#include "vtr_memory.h"
8+
#include "vtr_math.h"
89

910
#include "vpr_types.h"
1011
#include "vpr_error.h"
@@ -390,8 +391,9 @@ static void load_rr_indexed_data_T_values() {
390391
auto switch_T_total_histogram = build_histogram(switch_T_total[cost_index], 10);
391392
auto switch_Cinternal_total_histogram = build_histogram(switch_Cinternal_total[cost_index], 10);
392393

393-
float Rnode = get_histogram_mode(R_total_histogram);
394-
float Cnode = get_histogram_mode(C_total_histogram);
394+
// Sort Rnode and Cnode
395+
float Cnode = vtr::median(C_total[cost_index]);
396+
float Rnode = vtr::median(R_total[cost_index]);
395397
float Rsw = get_histogram_mode(switch_R_total_histogram);
396398
float Tsw = get_histogram_mode(switch_T_total_histogram);
397399
float Cinternalsw = get_histogram_mode(switch_Cinternal_total_histogram);

0 commit comments

Comments
 (0)