Move prediction cache to Learner. (#5220)
* Move prediction cache into Learner. * Clean-ups - Remove duplicated cache in Learner and GBM. - Remove ad-hoc fix of invalid cache. - Remove `PredictFromCache` in predictors. - Remove prediction cache for linear altogether, as it's only moving the prediction into training process but doesn't provide any actual overall speed gain. - The cache is now unique to Learner, which means the ownership is no longer shared by any other components. * Changes - Add version to prediction cache. - Use weak ptr to check expired DMatrix. - Pass shared pointer instead of raw pointer.
This commit is contained in:
33
tests/cpp/predictor/test_predictor.cc
Normal file
33
tests/cpp/predictor/test_predictor.cc
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* Copyright 2020 by Contributors
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <gtest/gtest.h>
|
||||
#include <xgboost/predictor.h>
|
||||
#include <xgboost/data.h>
|
||||
|
||||
#include "../helpers.h"
|
||||
#include "xgboost/generic_parameters.h"
|
||||
|
||||
namespace xgboost {
|
||||
TEST(Predictor, PredictionCache) {
|
||||
size_t constexpr kRows = 16, kCols = 4;
|
||||
|
||||
PredictionContainer container;
|
||||
DMatrix* m;
|
||||
// Add a cache that is immediately expired.
|
||||
auto add_cache = [&]() {
|
||||
auto *pp_dmat = CreateDMatrix(kRows, kCols, 0);
|
||||
auto p_dmat = *pp_dmat;
|
||||
container.Cache(p_dmat, GenericParameter::kCpuId);
|
||||
m = p_dmat.get();
|
||||
delete pp_dmat;
|
||||
};
|
||||
|
||||
add_cache();
|
||||
ASSERT_EQ(container.Container().size(), 0);
|
||||
add_cache();
|
||||
EXPECT_ANY_THROW(container.Entry(m));
|
||||
}
|
||||
} // namespace xgboost
|
||||
Reference in New Issue
Block a user