Rename and extract Context. (#8528)

* Rename `GenericParameter` to `Context`.
* Rename header file to reflect the change.
* Rename all references.
This commit is contained in:
Jiaming Yuan
2022-12-07 04:58:54 +08:00
committed by GitHub
parent 05fc6f3ca9
commit 3e26107a9c
105 changed files with 548 additions and 574 deletions

View File

@@ -2,7 +2,7 @@
* Copyright 2017-2022 XGBoost contributors
*/
#include <gtest/gtest.h>
#include <xgboost/generic_parameters.h>
#include <xgboost/context.h>
#include <xgboost/json.h>
#include <xgboost/objective.h>
@@ -12,12 +12,10 @@
namespace xgboost {
TEST(Objective, DeclareUnifiedTest(LinearRegressionGPair)) {
GenericParameter tparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("reg:squarederror", &tparam)
};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:squarederror", &ctx)};
obj->Configure(args);
CheckObjFunction(obj,
@@ -36,10 +34,10 @@ TEST(Objective, DeclareUnifiedTest(LinearRegressionGPair)) {
}
TEST(Objective, DeclareUnifiedTest(SquaredLog)) {
GenericParameter tparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj { ObjFunction::Create("reg:squaredlogerror", &tparam) };
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:squaredlogerror", &ctx)};
obj->Configure(args);
CheckConfigReload(obj, "reg:squaredlogerror");
@@ -59,10 +57,10 @@ TEST(Objective, DeclareUnifiedTest(SquaredLog)) {
}
TEST(Objective, DeclareUnifiedTest(PseudoHuber)) {
GenericParameter tparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
Args args;
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:pseudohubererror", &tparam)};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:pseudohubererror", &ctx)};
obj->Configure(args);
CheckConfigReload(obj, "reg:pseudohubererror");
@@ -88,9 +86,9 @@ TEST(Objective, DeclareUnifiedTest(PseudoHuber)) {
}
TEST(Objective, DeclareUnifiedTest(LogisticRegressionGPair)) {
GenericParameter tparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj { ObjFunction::Create("reg:logistic", &tparam) };
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:logistic", &ctx)};
obj->Configure(args);
CheckConfigReload(obj, "reg:logistic");
@@ -104,11 +102,9 @@ TEST(Objective, DeclareUnifiedTest(LogisticRegressionGPair)) {
}
TEST(Objective, DeclareUnifiedTest(LogisticRegressionBasic)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("reg:logistic", &lparam)
};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:logistic", &ctx)};
obj->Configure(args);
CheckConfigReload(obj, "reg:logistic");
@@ -135,10 +131,10 @@ TEST(Objective, DeclareUnifiedTest(LogisticRegressionBasic)) {
}
TEST(Objective, DeclareUnifiedTest(LogisticRawGPair)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("binary:logitraw", &lparam)
ObjFunction::Create("binary:logitraw", &ctx)
};
obj->Configure(args);
@@ -151,10 +147,10 @@ TEST(Objective, DeclareUnifiedTest(LogisticRawGPair)) {
}
TEST(Objective, DeclareUnifiedTest(PoissonRegressionGPair)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("count:poisson", &lparam)
ObjFunction::Create("count:poisson", &ctx)
};
args.emplace_back(std::make_pair("max_delta_step", "0.1f"));
@@ -175,10 +171,10 @@ TEST(Objective, DeclareUnifiedTest(PoissonRegressionGPair)) {
}
TEST(Objective, DeclareUnifiedTest(PoissonRegressionBasic)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("count:poisson", &lparam)
ObjFunction::Create("count:poisson", &ctx)
};
obj->Configure(args);
@@ -204,10 +200,10 @@ TEST(Objective, DeclareUnifiedTest(PoissonRegressionBasic)) {
}
TEST(Objective, DeclareUnifiedTest(GammaRegressionGPair)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("reg:gamma", &lparam)
ObjFunction::Create("reg:gamma", &ctx)
};
obj->Configure(args);
@@ -226,11 +222,9 @@ TEST(Objective, DeclareUnifiedTest(GammaRegressionGPair)) {
}
TEST(Objective, DeclareUnifiedTest(GammaRegressionBasic)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("reg:gamma", &lparam)
};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:gamma", &ctx)};
obj->Configure(args);
CheckConfigReload(obj, "reg:gamma");
@@ -257,11 +251,9 @@ TEST(Objective, DeclareUnifiedTest(GammaRegressionBasic)) {
}
TEST(Objective, DeclareUnifiedTest(TweedieRegressionGPair)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("reg:tweedie", &lparam)
};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:tweedie", &ctx)};
args.emplace_back(std::make_pair("tweedie_variance_power", "1.1f"));
obj->Configure(args);
@@ -283,10 +275,9 @@ TEST(Objective, DeclareUnifiedTest(TweedieRegressionGPair)) {
#if defined(__CUDACC__)
TEST(Objective, CPU_vs_CUDA) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
ObjFunction * obj =
ObjFunction::Create("reg:squarederror", &lparam);
ObjFunction* obj = ObjFunction::Create("reg:squarederror", &ctx);
HostDeviceVector<GradientPair> cpu_out_preds;
HostDeviceVector<GradientPair> cuda_out_preds;
@@ -309,12 +300,12 @@ TEST(Objective, CPU_vs_CUDA) {
{
// CPU
lparam.gpu_id = -1;
ctx.gpu_id = -1;
obj->GetGradient(preds, info, 0, &cpu_out_preds);
}
{
// CUDA
lparam.gpu_id = 0;
ctx.gpu_id = 0;
obj->GetGradient(preds, info, 0, &cuda_out_preds);
}
@@ -335,11 +326,9 @@ TEST(Objective, CPU_vs_CUDA) {
#endif
TEST(Objective, DeclareUnifiedTest(TweedieRegressionBasic)) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("reg:tweedie", &lparam)
};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("reg:tweedie", &ctx)};
obj->Configure(args);
CheckConfigReload(obj, "reg:tweedie");
@@ -366,11 +355,9 @@ TEST(Objective, DeclareUnifiedTest(TweedieRegressionBasic)) {
// CoxRegression not implemented in GPU code, no need for testing.
#if !defined(__CUDACC__)
TEST(Objective, CoxRegressionGPair) {
GenericParameter lparam = CreateEmptyGenericParam(GPUIDX);
Context ctx = CreateEmptyGenericParam(GPUIDX);
std::vector<std::pair<std::string, std::string>> args;
std::unique_ptr<ObjFunction> obj {
ObjFunction::Create("survival:cox", &lparam)
};
std::unique_ptr<ObjFunction> obj{ObjFunction::Create("survival:cox", &ctx)};
obj->Configure(args);
CheckObjFunction(obj,