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

@@ -24,10 +24,11 @@ TEST(cpu_predictor, Test) {
auto dmat = CreateDMatrix(n_row, n_col, 0);
// Test predict batch
std::vector<float> out_predictions;
HostDeviceVector<float> out_predictions;
cpu_predictor->PredictBatch(dmat.get(), &out_predictions, model, 0);
std::vector<float>& out_predictions_h = out_predictions.data_h();
for (int i = 0; i < out_predictions.size(); i++) {
ASSERT_EQ(out_predictions[i], 1.5);
ASSERT_EQ(out_predictions_h[i], 1.5);
}
// Test predict instance

View File

@@ -33,13 +33,15 @@ TEST(gpu_predictor, Test) {
auto dmat = CreateDMatrix(n_row, n_col, 0);
// Test predict batch
std::vector<float> gpu_out_predictions;
std::vector<float> cpu_out_predictions;
HostDeviceVector<float> gpu_out_predictions;
HostDeviceVector<float> cpu_out_predictions;
gpu_predictor->PredictBatch(dmat.get(), &gpu_out_predictions, model, 0);
cpu_predictor->PredictBatch(dmat.get(), &cpu_out_predictions, model, 0);
std::vector<float>& gpu_out_predictions_h = gpu_out_predictions.data_h();
std::vector<float>& cpu_out_predictions_h = cpu_out_predictions.data_h();
float abs_tolerance = 0.001;
for (int i = 0; i < gpu_out_predictions.size(); i++) {
ASSERT_LT(std::abs(gpu_out_predictions[i] - cpu_out_predictions[i]),
ASSERT_LT(std::abs(gpu_out_predictions_h[i] - cpu_out_predictions_h[i]),
abs_tolerance);
}
// Test predict instance