Replaced std::vector-based interfaces with HostDeviceVector-based interfaces. (#3116)

* Replaced std::vector-based interfaces with HostDeviceVector-based interfaces.

- replacement was performed in the learner, boosters, predictors,
  updaters, and objective functions
- only interfaces used in training were replaced;
  interfaces like PredictInstance() still use std::vector
- refactoring necessary for replacement of interfaces was also performed,
  such as using HostDeviceVector in prediction cache

* HostDeviceVector-based interfaces for custom objective function example plugin.
This commit is contained in:
Andrew V. Adinetz
2018-02-28 01:00:04 +01:00
committed by Rory Mitchell
parent 11bfa8584d
commit d5992dd881
38 changed files with 371 additions and 519 deletions

View File

@@ -38,10 +38,13 @@ void CheckObjFunction(xgboost::ObjFunction * obj,
info.labels = labels;
info.weights = weights;
std::vector<xgboost::bst_gpair> gpair;
obj->GetGradient(preds, info, 1, &gpair);
xgboost::HostDeviceVector<xgboost::bst_float> in_preds(preds);
ASSERT_EQ(gpair.size(), preds.size());
xgboost::HostDeviceVector<xgboost::bst_gpair> out_gpair;
obj->GetGradient(&in_preds, info, 1, &out_gpair);
std::vector<xgboost::bst_gpair>& gpair = out_gpair.data_h();
ASSERT_EQ(gpair.size(), in_preds.size());
for (int i = 0; i < static_cast<int>(gpair.size()); ++i) {
EXPECT_NEAR(gpair[i].GetGrad(), out_grad[i], 0.01)
<< "Unexpected grad for pred=" << preds[i] << " label=" << labels[i]