14 const int num_infos = work_balance_infos.size();
17 work_balance_infos[0].weight = 1.0;
20 else if (num_infos == 0) {
25 const double weight = 1.0 / num_infos;
27 balance_info.weight = weight;
33 double total_time = 0;
35 total_time += info.time_spent;
46 const int num_infos = work_balance_infos.size();
49 const double time_average = total_time / num_infos;
51 double total_weight = 0;
53 new_weights.reserve(num_infos);
60 const double lerp_weight = 1.0 / num_infos;
62 bool has_big_difference =
false;
65 const double time_target =
lerp(info.time_spent, time_average, lerp_weight);
66 const double new_weight = info.weight * time_target / info.time_spent;
67 new_weights.push_back(new_weight);
68 total_weight += new_weight;
70 if (
std::fabs(1.0 - time_target / time_average) > 0.02) {
71 has_big_difference =
true;
75 if (!has_big_difference) {
79 const double total_weight_inv = 1.0 / total_weight;
80 for (
int i = 0; i < num_infos; ++i) {
82 info.
weight = new_weights[i] * total_weight_inv;
#define CCL_NAMESPACE_END
ccl_device_inline float2 fabs(const float2 &a)
static float lerp(float t, float a, float b)
CCL_NAMESPACE_BEGIN void work_balance_do_initial(vector< WorkBalanceInfo > &work_balance_infos)
bool work_balance_do_rebalance(vector< WorkBalanceInfo > &work_balance_infos)
static double calculate_total_time(const vector< WorkBalanceInfo > &work_balance_infos)