Skip to content

Commit

Permalink
Fix rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Feb 28, 2023
1 parent be743af commit 3b0dae7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions include/xgboost/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ class DMatrixCache {
}
return container_.at(key).value;
}
/**
* \brief Re-initialize the item in cache.
*
* Since the shared_ptr is used to hold the item, any reference that lives outside of
* the cache can no-longer be reached from the cache.
*
* We use reset instead of erase to avoid walking through the whole cache for renewing
* a single item. (the cache is FIFO, needs to maintain the order).
*/
template <typename... Args>
void ResetItem(std::shared_ptr<DMatrix> m, Args const&... args) {
std::lock_guard<std::mutex> guard{lock_};
CheckConsistent();
auto key = Key{m.get(), std::this_thread::get_id()};
auto it = container_.find(key);
CHECK(it != container_.cend());
it->second = {m, std::make_shared<CacheT>(args...)};
CheckConsistent();
}
/**
* \brief Get a const reference to the underlying hash map. Clear expired caches before
* returning.
Expand Down
4 changes: 2 additions & 2 deletions src/metric/rank_metric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ class EvalRankWithCache : public Metric {

double Evaluate(HostDeviceVector<float> const& preds, std::shared_ptr<DMatrix> p_fmat) override {
auto const& info = p_fmat->Info();
auto& p_cache = cache_.CacheItem(p_fmat, ctx_, info, param_);
auto p_cache = cache_.CacheItem(p_fmat, ctx_, info, param_);
if (p_cache->Param() != param_) {
p_cache = std::make_shared<Cache>(ctx_, info, param_);
cache_.ResetItem(p_fmat, ctx_, info, param_);
}
CHECK(p_cache->Param() == param_);
CHECK_EQ(preds.Size(), info.labels.Size());
Expand Down

0 comments on commit 3b0dae7

Please sign in to comment.