| 80 | static_assert(CostLearner::kMaxT == DraftPolicy::kMaxT && CostLearner::kCtxBuckets == DraftPolicy::kCtxBuckets, "one table shape"); |
| 81 | |
| 82 | void CostLearner::add(int bucket, int t, double ms, double busy_age_s) { |
| 83 | if (!(ms > 0.0) || !std::isfinite(ms)) return; |
| 84 | bucket = std::clamp(bucket, 0, kCtxBuckets - 1); |
| 85 | t = std::clamp(t, 1, kMaxT); |
| 86 | const bool late = busy_age_s > kFreshS; // a GPU that has been busy for long can run in another state than a request after a pause finds it |
| 87 | ++(late ? late_ : rounds_); |
| 88 | auto& v = (late ? late_s_ : s_)[(size_t) bucket][(size_t) t]; |
| 89 | if ((int) v.size() < kKeep) v.push_back((float) ms); |
| 90 | } |
| 91 | |
| 92 | void CostLearner::reset() { |
| 93 | for (auto& b : s_) |
no test coverage detected