Rename and extract Context. (#8528)
* Rename `GenericParameter` to `Context`. * Rename header file to reflect the change. * Rename all references.
This commit is contained in:
@@ -2,17 +2,17 @@
|
||||
* Copyright 2019-2022 by XGBoost Contributors
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include <thrust/device_vector.h>
|
||||
#include <thrust/host_vector.h>
|
||||
#include <thrust/sequence.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
#include "../../../../src/tree/gpu_hist/row_partitioner.cuh"
|
||||
#include "../../helpers.h"
|
||||
#include "xgboost/base.h"
|
||||
#include "xgboost/generic_parameters.h"
|
||||
#include "xgboost/context.h"
|
||||
#include "xgboost/task.h"
|
||||
#include "xgboost/tree_model.h"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace xgboost {
|
||||
namespace tree {
|
||||
TEST(Approx, Partitioner) {
|
||||
size_t n_samples = 1024, n_features = 1, base_rowid = 0;
|
||||
GenericParameter ctx;
|
||||
Context ctx;
|
||||
CommonRowPartitioner partitioner{&ctx, n_samples, base_rowid};
|
||||
ASSERT_EQ(partitioner.base_rowid, base_rowid);
|
||||
ASSERT_EQ(partitioner.Size(), 1);
|
||||
@@ -69,7 +69,7 @@ TEST(Approx, Partitioner) {
|
||||
namespace {
|
||||
void TestLeafPartition(size_t n_samples) {
|
||||
size_t const n_features = 2, base_rowid = 0;
|
||||
GenericParameter ctx;
|
||||
Context ctx;
|
||||
common::RowSetCollection row_set;
|
||||
CommonRowPartitioner partitioner{&ctx, n_samples, base_rowid};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "../filesystem.h" // dmlc::TemporaryDirectory
|
||||
#include "../helpers.h"
|
||||
#include "../histogram_helpers.h"
|
||||
#include "xgboost/generic_parameters.h"
|
||||
#include "xgboost/context.h"
|
||||
#include "xgboost/json.h"
|
||||
|
||||
namespace xgboost {
|
||||
@@ -170,9 +170,9 @@ void TestHistogramIndexImpl() {
|
||||
|
||||
// Build 2 matrices and build a histogram maker with that
|
||||
|
||||
GenericParameter generic_param(CreateEmptyGenericParam(0));
|
||||
tree::GPUHistMaker hist_maker{&generic_param,ObjInfo{ObjInfo::kRegression}},
|
||||
hist_maker_ext{&generic_param,ObjInfo{ObjInfo::kRegression}};
|
||||
Context ctx(CreateEmptyGenericParam(0));
|
||||
tree::GPUHistMaker hist_maker{&ctx, ObjInfo{ObjInfo::kRegression}},
|
||||
hist_maker_ext{&ctx, ObjInfo{ObjInfo::kRegression}};
|
||||
std::unique_ptr<DMatrix> hist_maker_dmat(
|
||||
CreateSparsePageDMatrixWithRC(kNRows, kNCols, 0, true));
|
||||
|
||||
@@ -239,8 +239,8 @@ void UpdateTree(HostDeviceVector<GradientPair>* gpair, DMatrix* dmat,
|
||||
{"sampling_method", sampling_method},
|
||||
};
|
||||
|
||||
GenericParameter generic_param(CreateEmptyGenericParam(0));
|
||||
tree::GPUHistMaker hist_maker{&generic_param,ObjInfo{ObjInfo::kRegression}};
|
||||
Context ctx(CreateEmptyGenericParam(0));
|
||||
tree::GPUHistMaker hist_maker{&ctx,ObjInfo{ObjInfo::kRegression}};
|
||||
hist_maker.Configure(args);
|
||||
|
||||
std::vector<HostDeviceVector<bst_node_t>> position(1);
|
||||
@@ -384,9 +384,9 @@ TEST(GpuHist, ExternalMemoryWithSampling) {
|
||||
}
|
||||
|
||||
TEST(GpuHist, ConfigIO) {
|
||||
GenericParameter generic_param(CreateEmptyGenericParam(0));
|
||||
Context ctx(CreateEmptyGenericParam(0));
|
||||
std::unique_ptr<TreeUpdater> updater{
|
||||
TreeUpdater::Create("grow_gpu_hist", &generic_param, ObjInfo{ObjInfo::kRegression})};
|
||||
TreeUpdater::Create("grow_gpu_hist", &ctx, ObjInfo{ObjInfo::kRegression})};
|
||||
updater->Configure(Args{});
|
||||
|
||||
Json j_updater { Object() };
|
||||
@@ -404,7 +404,7 @@ TEST(GpuHist, ConfigIO) {
|
||||
}
|
||||
|
||||
TEST(GpuHist, MaxDepth) {
|
||||
GenericParameter generic_param(CreateEmptyGenericParam(0));
|
||||
Context ctx(CreateEmptyGenericParam(0));
|
||||
size_t constexpr kRows = 16;
|
||||
size_t constexpr kCols = 4;
|
||||
auto p_mat = RandomDataGenerator{kRows, kCols, 0}.GenerateDMatrix();
|
||||
|
||||
@@ -63,12 +63,12 @@ class TestPredictionCache : public ::testing::Test {
|
||||
void RunTest(std::string updater_name) {
|
||||
{
|
||||
omp_set_num_threads(1);
|
||||
GenericParameter ctx;
|
||||
Context ctx;
|
||||
ctx.InitAllowUnknown(Args{{"nthread", "8"}});
|
||||
if (updater_name == "grow_gpu_hist") {
|
||||
ctx.gpu_id = 0;
|
||||
} else {
|
||||
ctx.gpu_id = GenericParameter::kCpuId;
|
||||
ctx.gpu_id = Context::kCpuId;
|
||||
}
|
||||
|
||||
std::unique_ptr<TreeUpdater> updater{
|
||||
@@ -82,7 +82,7 @@ class TestPredictionCache : public ::testing::Test {
|
||||
HostDeviceVector<float> out_prediction_cached;
|
||||
out_prediction_cached.SetDevice(ctx.gpu_id);
|
||||
out_prediction_cached.Resize(n_samples_);
|
||||
auto cache = linalg::VectorView<float>{ctx.gpu_id == GenericParameter::kCpuId
|
||||
auto cache = linalg::VectorView<float>{ctx.gpu_id == Context::kCpuId
|
||||
? out_prediction_cached.HostSpan()
|
||||
: out_prediction_cached.DeviceSpan(),
|
||||
{out_prediction_cached.Size()},
|
||||
|
||||
@@ -31,7 +31,7 @@ TEST(Updater, Prune) {
|
||||
std::shared_ptr<DMatrix> p_dmat {
|
||||
RandomDataGenerator{32, 10, 0}.GenerateDMatrix() };
|
||||
|
||||
auto lparam = CreateEmptyGenericParam(GPUIDX);
|
||||
auto ctx = CreateEmptyGenericParam(GPUIDX);
|
||||
|
||||
// prepare tree
|
||||
RegTree tree = RegTree();
|
||||
@@ -39,7 +39,7 @@ TEST(Updater, Prune) {
|
||||
std::vector<RegTree*> trees {&tree};
|
||||
// prepare pruner
|
||||
std::unique_ptr<TreeUpdater> pruner(
|
||||
TreeUpdater::Create("prune", &lparam, ObjInfo{ObjInfo::kRegression}));
|
||||
TreeUpdater::Create("prune", &ctx, ObjInfo{ObjInfo::kRegression}));
|
||||
pruner->Configure(cfg);
|
||||
|
||||
// loss_chg < min_split_loss;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace xgboost {
|
||||
namespace tree {
|
||||
TEST(QuantileHist, Partitioner) {
|
||||
size_t n_samples = 1024, n_features = 1, base_rowid = 0;
|
||||
GenericParameter ctx;
|
||||
Context ctx;
|
||||
ctx.InitAllowUnknown(Args{});
|
||||
|
||||
CommonRowPartitioner partitioner{&ctx, n_samples, base_rowid};
|
||||
|
||||
@@ -29,11 +29,11 @@ TEST(Updater, Refresh) {
|
||||
{"reg_lambda", "1"}};
|
||||
|
||||
RegTree tree = RegTree();
|
||||
auto lparam = CreateEmptyGenericParam(GPUIDX);
|
||||
auto ctx = CreateEmptyGenericParam(GPUIDX);
|
||||
tree.param.UpdateAllowUnknown(cfg);
|
||||
std::vector<RegTree*> trees {&tree};
|
||||
std::vector<RegTree*> trees{&tree};
|
||||
std::unique_ptr<TreeUpdater> refresher(
|
||||
TreeUpdater::Create("refresh", &lparam, ObjInfo{ObjInfo::kRegression}));
|
||||
TreeUpdater::Create("refresh", &ctx, ObjInfo{ObjInfo::kRegression}));
|
||||
|
||||
tree.ExpandNode(0, 2, 0.2f, false, 0.0, 0.2f, 0.8f, 0.0f, 0.0f,
|
||||
/*left_sum=*/0.0f, /*right_sum=*/0.0f);
|
||||
|
||||
@@ -67,8 +67,8 @@ class UpdaterEtaTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
void RunTest(std::string updater) {
|
||||
GenericParameter ctx(updater == "grow_gpu_hist" ? CreateEmptyGenericParam(0)
|
||||
: CreateEmptyGenericParam(Context::kCpuId));
|
||||
Context ctx(updater == "grow_gpu_hist" ? CreateEmptyGenericParam(0)
|
||||
: CreateEmptyGenericParam(Context::kCpuId));
|
||||
float eta = 0.4;
|
||||
auto up_0 = std::unique_ptr<TreeUpdater>{
|
||||
TreeUpdater::Create(updater, &ctx, ObjInfo{ObjInfo::kClassification})};
|
||||
@@ -140,9 +140,8 @@ class TestMinSplitLoss : public ::testing::Test {
|
||||
// test gamma
|
||||
{"gamma", std::to_string(gamma)}};
|
||||
|
||||
std::cout << "updater:" << updater << std::endl;
|
||||
GenericParameter ctx(updater == "grow_gpu_hist" ? CreateEmptyGenericParam(0)
|
||||
: CreateEmptyGenericParam(Context::kCpuId));
|
||||
Context ctx(updater == "grow_gpu_hist" ? CreateEmptyGenericParam(0)
|
||||
: CreateEmptyGenericParam(Context::kCpuId));
|
||||
std::cout << ctx.gpu_id << std::endl;
|
||||
auto up = std::unique_ptr<TreeUpdater>{
|
||||
TreeUpdater::Create(updater, &ctx, ObjInfo{ObjInfo::kRegression})};
|
||||
|
||||
Reference in New Issue
Block a user