Rename and extract Context. (#8528)
* Rename `GenericParameter` to `Context`. * Rename header file to reflect the change. * Rename all references.
This commit is contained in:
@@ -71,7 +71,7 @@ void LinearCheckLayer(unsigned layer_begin) {
|
||||
*/
|
||||
class GBLinear : public GradientBooster {
|
||||
public:
|
||||
explicit GBLinear(LearnerModelParam const* learner_model_param, GenericParameter const* ctx)
|
||||
explicit GBLinear(LearnerModelParam const* learner_model_param, Context const* ctx)
|
||||
: GradientBooster{ctx},
|
||||
learner_model_param_{learner_model_param},
|
||||
model_{learner_model_param},
|
||||
@@ -179,7 +179,7 @@ class GBLinear : public GradientBooster {
|
||||
unsigned) override {
|
||||
model_.LazyInitModel();
|
||||
LinearCheckLayer(layer_begin);
|
||||
auto base_margin = p_fmat->Info().base_margin_.View(GenericParameter::kCpuId);
|
||||
auto base_margin = p_fmat->Info().base_margin_.View(Context::kCpuId);
|
||||
const int ngroup = model_.learner_model_param->num_output_group;
|
||||
const size_t ncolumns = model_.learner_model_param->num_feature + 1;
|
||||
// allocate space for (#features + bias) times #groups times #rows
|
||||
@@ -250,7 +250,7 @@ class GBLinear : public GradientBooster {
|
||||
linalg::TensorView<float, 2> scores{
|
||||
*out_scores,
|
||||
{learner_model_param_->num_feature, n_groups},
|
||||
GenericParameter::kCpuId};
|
||||
Context::kCpuId};
|
||||
for (size_t i = 0; i < learner_model_param_->num_feature; ++i) {
|
||||
for (bst_group_t g = 0; g < n_groups; ++g) {
|
||||
scores(i, g) = model_[i][g];
|
||||
@@ -355,7 +355,7 @@ DMLC_REGISTER_PARAMETER(GBLinearTrainParam);
|
||||
|
||||
XGBOOST_REGISTER_GBM(GBLinear, "gblinear")
|
||||
.describe("Linear booster, implement generalized linear model.")
|
||||
.set_body([](LearnerModelParam const* booster_config, GenericParameter const* ctx) {
|
||||
.set_body([](LearnerModelParam const* booster_config, Context const* ctx) {
|
||||
return new GBLinear(booster_config, ctx);
|
||||
});
|
||||
} // namespace gbm
|
||||
|
||||
@@ -3,21 +3,23 @@
|
||||
* \file gbm.cc
|
||||
* \brief Registry of gradient boosters.
|
||||
*/
|
||||
#include "xgboost/gbm.h"
|
||||
|
||||
#include <dmlc/registry.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "xgboost/gbm.h"
|
||||
#include "xgboost/context.h"
|
||||
#include "xgboost/learner.h"
|
||||
#include "xgboost/generic_parameters.h"
|
||||
|
||||
namespace dmlc {
|
||||
DMLC_REGISTRY_ENABLE(::xgboost::GradientBoosterReg);
|
||||
} // namespace dmlc
|
||||
|
||||
namespace xgboost {
|
||||
GradientBooster* GradientBooster::Create(const std::string& name, GenericParameter const* ctx,
|
||||
GradientBooster* GradientBooster::Create(const std::string& name, Context const* ctx,
|
||||
LearnerModelParam const* learner_model_param) {
|
||||
auto *e = ::dmlc::Registry< ::xgboost::GradientBoosterReg>::Get()->Find(name);
|
||||
if (e == nullptr) {
|
||||
|
||||
@@ -67,7 +67,7 @@ void GBTree::Configure(const Args& cfg) {
|
||||
#if defined(XGBOOST_USE_ONEAPI)
|
||||
if (!oneapi_predictor_) {
|
||||
oneapi_predictor_ = std::unique_ptr<Predictor>(
|
||||
Predictor::Create("oneapi_predictor", this->generic_param_));
|
||||
Predictor::Create("oneapi_predictor", this->ctx_));
|
||||
}
|
||||
oneapi_predictor_->Configure(cfg);
|
||||
#endif // defined(XGBOOST_USE_ONEAPI)
|
||||
@@ -204,7 +204,7 @@ void GPUCopyGradient(HostDeviceVector<GradientPair> const*, bst_group_t, bst_gro
|
||||
void CopyGradient(HostDeviceVector<GradientPair> const* in_gpair, int32_t n_threads,
|
||||
bst_group_t n_groups, bst_group_t group_id,
|
||||
HostDeviceVector<GradientPair>* out_gpair) {
|
||||
if (in_gpair->DeviceIdx() != GenericParameter::kCpuId) {
|
||||
if (in_gpair->DeviceIdx() != Context::kCpuId) {
|
||||
GPUCopyGradient(in_gpair, n_groups, group_id, out_gpair);
|
||||
} else {
|
||||
std::vector<GradientPair> &tmp_h = out_gpair->HostVector();
|
||||
@@ -651,7 +651,7 @@ void GPUDartInplacePredictInc(common::Span<float> /*out_predts*/, common::Span<f
|
||||
|
||||
class Dart : public GBTree {
|
||||
public:
|
||||
explicit Dart(LearnerModelParam const* booster_config, GenericParameter const* ctx)
|
||||
explicit Dart(LearnerModelParam const* booster_config, Context const* ctx)
|
||||
: GBTree(booster_config, ctx) {}
|
||||
|
||||
void Configure(const Args& cfg) override {
|
||||
@@ -741,7 +741,7 @@ class Dart : public GBTree {
|
||||
auto n_groups = model_.learner_model_param->num_output_group;
|
||||
|
||||
PredictionCacheEntry predts; // temporary storage for prediction
|
||||
if (ctx_->gpu_id != GenericParameter::kCpuId) {
|
||||
if (ctx_->gpu_id != Context::kCpuId) {
|
||||
predts.predictions.SetDevice(ctx_->gpu_id);
|
||||
}
|
||||
predts.predictions.Resize(p_fmat->Info().num_row_ * n_groups, 0);
|
||||
@@ -763,7 +763,7 @@ class Dart : public GBTree {
|
||||
CHECK_EQ(p_out_preds->predictions.Size(), predts.predictions.Size());
|
||||
|
||||
size_t n_rows = p_fmat->Info().num_row_;
|
||||
if (predts.predictions.DeviceIdx() != GenericParameter::kCpuId) {
|
||||
if (predts.predictions.DeviceIdx() != Context::kCpuId) {
|
||||
p_out_preds->predictions.SetDevice(predts.predictions.DeviceIdx());
|
||||
GPUDartPredictInc(p_out_preds->predictions.DeviceSpan(),
|
||||
predts.predictions.DeviceSpan(), w, n_rows, n_groups,
|
||||
@@ -1019,13 +1019,13 @@ DMLC_REGISTER_PARAMETER(DartTrainParam);
|
||||
|
||||
XGBOOST_REGISTER_GBM(GBTree, "gbtree")
|
||||
.describe("Tree booster, gradient boosted trees.")
|
||||
.set_body([](LearnerModelParam const* booster_config, GenericParameter const* ctx) {
|
||||
.set_body([](LearnerModelParam const* booster_config, Context const* ctx) {
|
||||
auto* p = new GBTree(booster_config, ctx);
|
||||
return p;
|
||||
});
|
||||
XGBOOST_REGISTER_GBM(Dart, "dart")
|
||||
.describe("Tree booster, dart.")
|
||||
.set_body([](LearnerModelParam const* booster_config, GenericParameter const* ctx) {
|
||||
.set_body([](LearnerModelParam const* booster_config, Context const* ctx) {
|
||||
GBTree* p = new Dart(booster_config, ctx);
|
||||
return p;
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*!
|
||||
* Copyright 2021 by Contributors
|
||||
*/
|
||||
#include "xgboost/span.h"
|
||||
#include "xgboost/generic_parameters.h"
|
||||
#include "xgboost/linalg.h"
|
||||
#include "../common/device_helpers.cuh"
|
||||
#include "xgboost/context.h"
|
||||
#include "xgboost/linalg.h"
|
||||
#include "xgboost/span.h"
|
||||
|
||||
namespace xgboost {
|
||||
namespace gbm {
|
||||
|
||||
@@ -190,7 +190,7 @@ bool SliceTrees(int32_t layer_begin, int32_t layer_end, int32_t step, GBTreeMode
|
||||
// gradient boosted trees
|
||||
class GBTree : public GradientBooster {
|
||||
public:
|
||||
explicit GBTree(LearnerModelParam const* booster_config, GenericParameter const* ctx)
|
||||
explicit GBTree(LearnerModelParam const* booster_config, Context const* ctx)
|
||||
: GradientBooster{ctx}, model_(booster_config, ctx_) {}
|
||||
|
||||
void Configure(const Args& cfg) override;
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
#ifndef XGBOOST_GBM_GBTREE_MODEL_H_
|
||||
#define XGBOOST_GBM_GBTREE_MODEL_H_
|
||||
|
||||
#include <dmlc/parameter.h>
|
||||
#include <dmlc/io.h>
|
||||
#include <xgboost/model.h>
|
||||
#include <xgboost/tree_model.h>
|
||||
#include <xgboost/parameter.h>
|
||||
#include <dmlc/parameter.h>
|
||||
#include <xgboost/context.h>
|
||||
#include <xgboost/learner.h>
|
||||
#include <xgboost/model.h>
|
||||
#include <xgboost/parameter.h>
|
||||
#include <xgboost/tree_model.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../common/threading_utils.h"
|
||||
@@ -89,7 +90,7 @@ struct GBTreeModelParam : public dmlc::Parameter<GBTreeModelParam> {
|
||||
|
||||
struct GBTreeModel : public Model {
|
||||
public:
|
||||
explicit GBTreeModel(LearnerModelParam const* learner_model, GenericParameter const* ctx)
|
||||
explicit GBTreeModel(LearnerModelParam const* learner_model, Context const* ctx)
|
||||
: learner_model_param{learner_model}, ctx_{ctx} {}
|
||||
void Configure(const Args& cfg) {
|
||||
// initialize model parameters if not yet been initialized.
|
||||
@@ -143,7 +144,7 @@ struct GBTreeModel : public Model {
|
||||
std::vector<int> tree_info;
|
||||
|
||||
private:
|
||||
GenericParameter const* ctx_;
|
||||
Context const* ctx_;
|
||||
};
|
||||
} // namespace gbm
|
||||
} // namespace xgboost
|
||||
|
||||
Reference in New Issue
Block a user