Use ellpack for prediction only when sparsepage doesn't exist. (#5504)

This commit is contained in:
Jiaming Yuan
2020-04-10 12:15:46 +08:00
committed by GitHub
parent ad826e913f
commit 6671b42dd4
35 changed files with 166 additions and 116 deletions

View File

@@ -85,7 +85,7 @@ XGB_DLL int XGDMatrixCreateFromArrayInterfaceColumns(char const* c_json_strs,
int nthread,
DMatrixHandle* out) {
API_BEGIN();
LOG(FATAL) << "XGBoost not compiled with CUDA";
common::AssertGPUSupport();
API_END();
}
@@ -94,7 +94,7 @@ XGB_DLL int XGDMatrixCreateFromArrayInterface(char const* c_json_strs,
int nthread,
DMatrixHandle* out) {
API_BEGIN();
LOG(FATAL) << "XGBoost not compiled with CUDA";
common::AssertGPUSupport();
API_END();
}
@@ -521,7 +521,7 @@ XGB_DLL int XGBoosterPredictFromArrayInterfaceColumns(BoosterHandle handle,
float const** out_result) {
API_BEGIN();
CHECK_HANDLE();
LOG(FATAL) << "XGBoost not compiled with CUDA.";
common::AssertGPUSupport();
API_END();
}
XGB_DLL int XGBoosterPredictFromArrayInterface(BoosterHandle handle,
@@ -535,7 +535,7 @@ XGB_DLL int XGBoosterPredictFromArrayInterface(BoosterHandle handle,
const float **out_result) {
API_BEGIN();
CHECK_HANDLE();
LOG(FATAL) << "XGBoost not compiled with CUDA.";
common::AssertGPUSupport();
API_END();
}
#endif // !defined(XGBOOST_USE_CUDA)

View File

@@ -147,6 +147,13 @@ class Range {
};
int AllVisibleGPUs();
inline void AssertGPUSupport() {
#ifndef XGBOOST_USE_CUDA
LOG(FATAL) << "XGBoost version not compiled with GPU support.";
#endif // XGBOOST_USE_CUDA
}
} // namespace common
} // namespace xgboost
#endif // XGBOOST_COMMON_COMMON_H_

View File

@@ -293,7 +293,7 @@ void MetaInfo::SetInfo(const char* key, const void* dptr, DataType dtype, size_t
#if !defined(XGBOOST_USE_CUDA)
void MetaInfo::SetInfo(const char * c_key, std::string const& interface_str) {
LOG(FATAL) << "XGBoost version is not compiled with GPU support";
common::AssertGPUSupport();
}
#endif // !defined(XGBOOST_USE_CUDA)

View File

@@ -22,6 +22,7 @@
#include "gblinear_model.h"
#include "../common/timer.h"
#include "../common/common.h"
namespace xgboost {
namespace gbm {
@@ -68,7 +69,7 @@ class GBLinear : public GradientBooster {
updater_->Configure(cfg);
monitor_.Init("GBLinear");
if (param_.updater == "gpu_coord_descent") {
this->AssertGPUSupport();
common::AssertGPUSupport();
}
}

View File

@@ -172,7 +172,7 @@ void GBTree::ConfigureUpdaters() {
tparam_.updater_seq = "grow_quantile_histmaker";
break;
case TreeMethod::kGPUHist: {
this->AssertGPUSupport();
common::AssertGPUSupport();
tparam_.updater_seq = "grow_gpu_hist";
break;
}
@@ -391,17 +391,21 @@ GBTree::GetPredictor(HostDeviceVector<float> const *out_pred,
CHECK(gpu_predictor_);
return gpu_predictor_;
#else
this->AssertGPUSupport();
common::AssertGPUSupport();
#endif // defined(XGBOOST_USE_CUDA)
}
CHECK(cpu_predictor_);
return cpu_predictor_;
}
auto on_device =
f_dmat &&
(f_dmat->PageExists<EllpackPage>() ||
(*(f_dmat->GetBatches<SparsePage>().begin())).data.DeviceCanRead());
// Data comes from Device DMatrix.
auto is_ellpack = f_dmat && f_dmat->PageExists<EllpackPage>() &&
!f_dmat->PageExists<SparsePage>();
// Data comes from device memory, like CuDF or CuPy.
auto is_from_device =
f_dmat && f_dmat->PageExists<SparsePage>() &&
(*(f_dmat->GetBatches<SparsePage>().begin())).data.DeviceCanRead();
auto on_device = is_ellpack || is_from_device;
// Use GPU Predictor if data is already on device and gpu_id is set.
if (on_device && generic_param_->gpu_id >= 0) {
@@ -434,7 +438,7 @@ GBTree::GetPredictor(HostDeviceVector<float> const *out_pred,
CHECK(gpu_predictor_);
return gpu_predictor_;
#else
this->AssertGPUSupport();
common::AssertGPUSupport();
return cpu_predictor_;
#endif // defined(XGBOOST_USE_CUDA)
}

View File

@@ -348,7 +348,14 @@ class GPUPredictor : public xgboost::Predictor {
model_.Init(model, tree_begin, tree_end, generic_param_->gpu_id);
out_preds->SetDevice(generic_param_->gpu_id);
if (dmat->PageExists<EllpackPage>()) {
if (dmat->PageExists<SparsePage>()) {
size_t batch_offset = 0;
for (auto &batch : dmat->GetBatches<SparsePage>()) {
this->PredictInternal(batch, model.learner_model_param->num_feature,
out_preds, batch_offset);
batch_offset += batch.Size() * model.learner_model_param->num_output_group;
}
} else {
size_t batch_offset = 0;
for (auto const& page : dmat->GetBatches<EllpackPage>()) {
this->PredictInternal(
@@ -356,13 +363,6 @@ class GPUPredictor : public xgboost::Predictor {
batch_offset);
batch_offset += page.Impl()->n_rows;
}
} else {
size_t batch_offset = 0;
for (auto &batch : dmat->GetBatches<SparsePage>()) {
this->PredictInternal(batch, model.learner_model_param->num_feature,
out_preds, batch_offset);
batch_offset += batch.Size() * model.learner_model_param->num_output_group;
}
}
}