77
88#include " routing_predictor.h"
99
10+ namespace {
11+
1012class LinearModel {
1113 public:
1214 LinearModel (float slope = std::numeric_limits<float >::quiet_NaN(), float y_intercept = std::numeric_limits<float >::quiet_NaN())
@@ -35,15 +37,6 @@ class LinearModel {
3537 float y_intercept_;
3638};
3739
38- template <typename T>
39- float variance (std::vector<float > values, float avg);
40-
41- float covariance (const std::vector<size_t >& x_values, const std::vector<float >& y_values, float x_avg, float y_avg);
42- LinearModel simple_linear_regression (const std::vector<size_t >& x_values, const std::vector<float >& y_values);
43- t_routing_predictor_fit fit_model (const std::vector<size_t >& iterations,
44- const std::vector<size_t >& overuse,
45- float history_factor);
46-
4740template <typename T>
4841float variance (const std::vector<T>& values, float avg) {
4942 float var = 0 ;
@@ -65,11 +58,6 @@ float covariance(const std::vector<size_t>& x_values, const std::vector<float>&
6558 return cov;
6659}
6760
68- float RoutingPredictor::get_slope () const {
69- // Return cached slope, computed in add_iteration_overuse()
70- return slope_;
71- }
72-
7361LinearModel simple_linear_regression (const std::vector<size_t >& x_values, const std::vector<float >& y_values) {
7462 float y_avg = std::accumulate (y_values.begin (), y_values.end (), 0 .) / y_values.size ();
7563 float x_avg = std::accumulate (x_values.begin (), x_values.end (), 0 .) / x_values.size ();
@@ -83,9 +71,14 @@ LinearModel simple_linear_regression(const std::vector<size_t>& x_values, const
8371 return LinearModel (beta, alpha);
8472}
8573
86- t_routing_predictor_fit fit_model (const std::vector<size_t >& iterations,
87- const std::vector<size_t >& overuse,
88- float history_factor) {
74+ } // namespace
75+
76+ float RoutingPredictor::get_slope () const {
77+ // Return cached slope, computed in add_iteration_overuse()
78+ return slope_;
79+ }
80+
81+ t_routing_predictor_fit RoutingPredictor::fit_model_ (float history_factor) const {
8982 // For pathfinder-based routing overuse tends to follow a negative-exponential:
9083 //
9184 // ^
@@ -138,15 +131,15 @@ t_routing_predictor_fit fit_model(const std::vector<size_t>& iterations,
138131 // (since the history inspected grows as the number of iterations increases,
139132 // later iterations use a longer history which helps reduce the noise caused by
140133 // small numbers of overused nodes)
141- size_t start = overuse .size () - std::round (history_factor * overuse .size ());
142- size_t end = overuse .size ();
134+ size_t start = iterations_ .size () - std::round (history_factor * iterations_ .size ());
135+ size_t end = iterations_ .size ();
143136
144137 // Calculate the log overuse for the history we are interested in
145138 std::vector<float > hist_log_overuse;
146139 std::vector<size_t > hist_iters;
147140 for (size_t i = start; i < end; ++i) {
148- hist_log_overuse.push_back (std::log (overuse [i]));
149- hist_iters.push_back (iterations [i]);
141+ hist_log_overuse.push_back (std::log (iteration_overused_rr_node_counts_ [i]));
142+ hist_iters.push_back (iterations_ [i]);
150143 }
151144
152145 // We fit a linear model to the log of the overuse, this keeps the model simple but
@@ -210,7 +203,7 @@ float RoutingPredictor::estimate_overuse_slope() {
210203 float history_factor = FIXED_HISTORY_SIZE / iterations_.size (); // Fixed history size
211204
212205 if (iterations_.size () >= FIXED_HISTORY_SIZE ) {
213- t_routing_predictor_fit fit = fit_model (iterations_, iteration_overused_rr_node_counts_, history_factor);
206+ t_routing_predictor_fit fit = fit_model_ ( history_factor);
214207 LinearModel model (fit.slope , fit.y_intercept );
215208
216209 float log_curr_usage = model.find_y_for_x_value (*(--iterations_.end ()));
@@ -236,7 +229,7 @@ void RoutingPredictor::add_iteration_overuse(size_t iteration, size_t overused_r
236229 last_fit_ = t_routing_predictor_fit ();
237230 last_estimate_ = std::numeric_limits<float >::quiet_NaN ();
238231 if (iterations_.size () > min_history_) {
239- last_fit_ = fit_model (iterations_, iteration_overused_rr_node_counts_, history_factor_);
232+ last_fit_ = fit_model_ ( history_factor_);
240233 slope_ = last_fit_.slope ;
241234
242235 LinearModel model (last_fit_.slope , last_fit_.y_intercept );
0 commit comments