Skip to content

Commit

Permalink
Merge pull request #1007 from milroy/perf-fix
Browse files Browse the repository at this point in the history
Improve Fluxion match performance
  • Loading branch information
mergify[bot] authored Feb 16, 2023
2 parents f7bdcb5 + b21c605 commit 35d3c96
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
12 changes: 6 additions & 6 deletions resource/evaluators/fold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ namespace resource_model {

namespace fold {
struct greater {
bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
inline bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
{
return a.score > b.score;
}
};

struct less {
bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
inline bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
{
return a.score < b.score;
}
};

struct interval_greater {
bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
inline bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
{
return *(ivset.find (a.score)) > *(ivset.find (b.score));
}
boost::icl::interval_set<int64_t> ivset;
};

struct interval_less {
bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
inline bool operator() (const eval_egroup_t &a, const eval_egroup_t &b) const
{
return *(ivset.find (a.score)) < *(ivset.find (b.score));
}
boost::icl::interval_set<int64_t> ivset;
};

struct plus {
const int64_t operator() (const int64_t result,
const eval_egroup_t &a) const
inline const int64_t operator() (const int64_t &result,
const eval_egroup_t &a) const
{
return result + a.score;
}
Expand Down
6 changes: 3 additions & 3 deletions resource/policies/dfu_match_multilevel_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class multilevel_id_t : public dfu_match_cb_t
unsigned int add_by,
unsigned int multiply_by);
score_factor_t (const score_factor_t &o) = default;
int64_t calc_factor (int64_t base_factor, int64_t break_tie) const;
int64_t calc_factor (int64_t base_factor, int64_t break_tie);
int64_t m_factor = 0;

private:
std::string m_type;
Expand All @@ -116,11 +117,10 @@ class multilevel_id_t : public dfu_match_cb_t
};

void set_base_factor (const std::string &type, unsigned int id);
int64_t calc_multilevel_scores () const;

FOLD m_comp;
unsigned m_stop_on_k_matches = 0;
std::vector<int64_t> m_multilevel_scores;
int64_t m_multilevel_scores = 0;
std::unordered_map<std::string, score_factor_t> m_multilevel_factors;
};

Expand Down
30 changes: 12 additions & 18 deletions resource/policies/dfu_match_multilevel_id_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ multilevel_id_t<FOLD>::score_factor_t::score_factor_t (const std::string &type,
template<typename FOLD>
int64_t multilevel_id_t<FOLD>::score_factor_t::calc_factor (
int64_t base_factor,
int64_t break_tie) const
int64_t break_tie)
{
int64_t add, mul, tie, factor;
int64_t add, mul, tie;
if (base_factor < 0 || break_tie < 0) {
errno = EINVAL;
return -1;
Expand All @@ -61,15 +61,8 @@ int64_t multilevel_id_t<FOLD>::score_factor_t::calc_factor (
errno = EOVERFLOW;
return -1;
}
factor = mul + tie;
return factor;
}

template<typename FOLD>
int64_t multilevel_id_t<FOLD>::calc_multilevel_scores () const
{
return std::accumulate (m_multilevel_scores.begin (),
m_multilevel_scores.end (), 0);
m_factor = mul + tie;
return m_factor;
}


Expand Down Expand Up @@ -138,6 +131,7 @@ int multilevel_id_t<FOLD>::dom_finish_graph (
dfu.choose_accum_best_k (subsystem, type, count, m_comp);
}
dfu.set_overall_score (score);
m_multilevel_scores = 0;
return (score == MATCH_MET)? 0 : -1;
}

Expand All @@ -164,10 +158,10 @@ int multilevel_id_t<FOLD>::dom_discover_vtx (
if (g[u].id < -1)
return -1;
auto &f = m_multilevel_factors[g[u].type];
int64_t factor = f.calc_factor (g[u].id+1, g[u].uniq_id);
int64_t factor = f.calc_factor (g[u].id+1, g[u].uniq_id);
if (factor < 0)
return factor;
m_multilevel_scores.push_back (factor);
m_multilevel_scores += factor;
}
incr ();
return 0;
Expand All @@ -184,7 +178,6 @@ int multilevel_id_t<FOLD>::dom_finish_vtx (
{
int64_t score = MATCH_MET;
int64_t overall;
unsigned prefix;

for (auto &resource : resources) {
if (resource.type != g[u].type)
Expand All @@ -203,11 +196,12 @@ int multilevel_id_t<FOLD>::dom_finish_vtx (
}
}

if (m_multilevel_factors.find (g[u].type) != m_multilevel_factors.end ())
m_multilevel_scores.pop_back ();
auto factor = m_multilevel_factors.find (g[u].type);
if (factor != m_multilevel_factors.end ())
m_multilevel_scores -= factor->second.m_factor;

prefix = calc_multilevel_scores ();
overall = (score == MATCH_MET)? (score + prefix + g[u].id + 1) : score;
overall = (score == MATCH_MET)? (score + m_multilevel_scores
+ g[u].id + 1) : score;
dfu.set_overall_score (overall);
decr ();
return (score == MATCH_MET)? 0 : -1;
Expand Down

0 comments on commit 35d3c96

Please sign in to comment.