From bde1ebc209e749775ccced5155c8b1b4e7af240e Mon Sep 17 00:00:00 2001 From: Rong Ou Date: Fri, 4 Aug 2023 00:14:31 -0700 Subject: [PATCH] Switch back to the GPUIDX macro (#9438) --- tests/cpp/common/test_quantile.cu | 6 ++-- tests/cpp/helpers.h | 15 ++++----- tests/cpp/linear/test_json_io.h | 2 +- tests/cpp/linear/test_linear.cc | 4 +-- tests/cpp/metric/test_auc.h | 12 +++---- tests/cpp/metric/test_elementwise_metric.h | 38 +++++++++++----------- tests/cpp/metric/test_metric.cc | 2 +- tests/cpp/metric/test_multiclass_metric.h | 8 ++--- tests/cpp/metric/test_rank_metric.cc | 2 +- tests/cpp/metric/test_rank_metric.h | 8 ++--- tests/cpp/metric/test_survival_metric.cu | 4 +-- tests/cpp/metric/test_survival_metric.h | 6 ++-- tests/cpp/objective/test_aft_obj.cc | 10 +++--- tests/cpp/objective/test_hinge.cc | 2 +- tests/cpp/objective/test_lambdarank_obj.cc | 2 +- tests/cpp/objective/test_multiclass_obj.cc | 6 ++-- tests/cpp/objective/test_quantile_obj.cc | 4 +-- tests/cpp/objective/test_regression_obj.cc | 32 +++++++++--------- tests/cpp/plugin/test_example_objective.cc | 2 +- tests/cpp/plugin/test_federated_adapter.cu | 4 +-- tests/cpp/predictor/test_gpu_predictor.cu | 4 +-- 21 files changed, 85 insertions(+), 88 deletions(-) diff --git a/tests/cpp/common/test_quantile.cu b/tests/cpp/common/test_quantile.cu index 28d698685..a5ecbb598 100644 --- a/tests/cpp/common/test_quantile.cu +++ b/tests/cpp/common/test_quantile.cu @@ -351,7 +351,7 @@ void TestAllReduceBasic() { auto const world = collective::GetWorldSize(); constexpr size_t kRows = 1000, kCols = 100; RunWithSeedsAndBins(kRows, [=](int32_t seed, size_t n_bins, MetaInfo const& info) { - auto const device = GetGPUId(); + auto const device = GPUIDX; // Set up single node version; HostDeviceVector ft({}, device); @@ -440,7 +440,7 @@ void TestColumnSplitBasic() { }()}; // Generate cuts for distributed environment. - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); HistogramCuts distributed_cuts = common::DeviceSketch(&ctx, m.get(), kBins); // Generate cuts for single node environment @@ -483,7 +483,7 @@ void TestSameOnAllWorkers() { RunWithSeedsAndBins(kRows, [=](int32_t seed, size_t n_bins, MetaInfo const &info) { auto const rank = collective::GetRank(); - auto const device = GetGPUId(); + auto const device = GPUIDX; HostDeviceVector ft({}, device); SketchContainer sketch_distributed(ft, n_bins, kCols, kRows, device); HostDeviceVector storage({}, device); diff --git a/tests/cpp/helpers.h b/tests/cpp/helpers.h index 6cb0b3405..e39375dfa 100644 --- a/tests/cpp/helpers.h +++ b/tests/cpp/helpers.h @@ -34,6 +34,12 @@ #define DeclareUnifiedTest(name) name #endif +#if defined(__CUDACC__) +#define GPUIDX (common::AllVisibleGPUs() == 1 ? 0 : collective::GetRank()) +#else +#define GPUIDX (-1) +#endif + #if defined(__CUDACC__) #define DeclareUnifiedDistributedTest(name) MGPU ## name #else @@ -540,15 +546,6 @@ void RunWithInMemoryCommunicator(int32_t world_size, Function&& function, Args&& #endif } -inline int GetGPUId() { -#if defined(__CUDACC__) - auto const n_gpus = common::AllVisibleGPUs(); - return n_gpus == 1 ? 0 : collective::GetRank(); -#else - return -1; -#endif -} - class BaseMGPUTest : public ::testing::Test { protected: int world_size_; diff --git a/tests/cpp/linear/test_json_io.h b/tests/cpp/linear/test_json_io.h index 48d4497c3..c423448e2 100644 --- a/tests/cpp/linear/test_json_io.h +++ b/tests/cpp/linear/test_json_io.h @@ -12,7 +12,7 @@ namespace xgboost { inline void TestUpdaterJsonIO(std::string updater_str) { - Context ctx{MakeCUDACtx(GetGPUId())}; + Context ctx{MakeCUDACtx(GPUIDX)}; Json config_0 {Object() }; { diff --git a/tests/cpp/linear/test_linear.cc b/tests/cpp/linear/test_linear.cc index f15a47e64..6b2d17e10 100644 --- a/tests/cpp/linear/test_linear.cc +++ b/tests/cpp/linear/test_linear.cc @@ -17,7 +17,7 @@ TEST(Linear, Shotgun) { auto p_fmat = xgboost::RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix(); - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); LearnerModelParam mparam{MakeMP(kCols, .5, 1)}; { @@ -49,7 +49,7 @@ TEST(Linear, coordinate) { auto p_fmat = xgboost::RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix(); - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); LearnerModelParam mparam{MakeMP(kCols, .5, 1)}; auto updater = std::unique_ptr( diff --git a/tests/cpp/metric/test_auc.h b/tests/cpp/metric/test_auc.h index cd0095ebb..0dd3dd83e 100644 --- a/tests/cpp/metric/test_auc.h +++ b/tests/cpp/metric/test_auc.h @@ -11,7 +11,7 @@ namespace xgboost { namespace metric { inline void VerifyBinaryAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr uni_ptr{Metric::Create("auc", &ctx)}; Metric* metric = uni_ptr.get(); ASSERT_STREQ(metric->Name(), "auc"); @@ -54,7 +54,7 @@ inline void VerifyBinaryAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) } inline void VerifyMultiClassAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr uni_ptr{Metric::Create("auc", &ctx)}; auto metric = uni_ptr.get(); @@ -115,7 +115,7 @@ inline void VerifyMultiClassAUC(DataSplitMode data_split_mode = DataSplitMode::k } inline void VerifyRankingAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{Metric::Create("auc", &ctx)}; // single group @@ -149,7 +149,7 @@ inline void VerifyRankingAUC(DataSplitMode data_split_mode = DataSplitMode::kRow } inline void VerifyPRAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric* metric = xgboost::Metric::Create("aucpr", &ctx); ASSERT_STREQ(metric->Name(), "aucpr"); @@ -186,7 +186,7 @@ inline void VerifyPRAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { } inline void VerifyMultiClassPRAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{Metric::Create("aucpr", &ctx)}; @@ -210,7 +210,7 @@ inline void VerifyMultiClassPRAUC(DataSplitMode data_split_mode = DataSplitMode: } inline void VerifyRankingPRAUC(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{Metric::Create("aucpr", &ctx)}; diff --git a/tests/cpp/metric/test_elementwise_metric.h b/tests/cpp/metric/test_elementwise_metric.h index 9a3d3fe9f..a32bb0438 100644 --- a/tests/cpp/metric/test_elementwise_metric.h +++ b/tests/cpp/metric/test_elementwise_metric.h @@ -46,7 +46,7 @@ inline void CheckDeterministicMetricElementWise(StringView name, int32_t device) } inline void VerifyRMSE(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("rmse", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "rmse"); @@ -71,11 +71,11 @@ inline void VerifyRMSE(DataSplitMode data_split_mode = DataSplitMode::kRow) { 0.6708f, 0.001f); delete metric; - CheckDeterministicMetricElementWise(StringView{"rmse"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"rmse"}, GPUIDX); } inline void VerifyRMSLE(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("rmsle", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "rmsle"); @@ -100,11 +100,11 @@ inline void VerifyRMSLE(DataSplitMode data_split_mode = DataSplitMode::kRow) { 0.2415f, 1e-4); delete metric; - CheckDeterministicMetricElementWise(StringView{"rmsle"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"rmsle"}, GPUIDX); } inline void VerifyMAE(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("mae", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "mae"); @@ -129,11 +129,11 @@ inline void VerifyMAE(DataSplitMode data_split_mode = DataSplitMode::kRow) { 0.54f, 0.001f); delete metric; - CheckDeterministicMetricElementWise(StringView{"mae"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"mae"}, GPUIDX); } inline void VerifyMAPE(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("mape", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "mape"); @@ -158,11 +158,11 @@ inline void VerifyMAPE(DataSplitMode data_split_mode = DataSplitMode::kRow) { 1.3250f, 0.001f); delete metric; - CheckDeterministicMetricElementWise(StringView{"mape"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"mape"}, GPUIDX); } inline void VerifyMPHE(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{xgboost::Metric::Create("mphe", &ctx)}; metric->Configure({}); ASSERT_STREQ(metric->Name(), "mphe"); @@ -186,7 +186,7 @@ inline void VerifyMPHE(DataSplitMode data_split_mode = DataSplitMode::kRow) { { 1, 2, 9, 8}, {}, data_split_mode), 0.1922f, 1e-4); - CheckDeterministicMetricElementWise(StringView{"mphe"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"mphe"}, GPUIDX); metric->Configure({{"huber_slope", "0.1"}}); EXPECT_NEAR(GetMetricEval(metric.get(), @@ -197,7 +197,7 @@ inline void VerifyMPHE(DataSplitMode data_split_mode = DataSplitMode::kRow) { } inline void VerifyLogLoss(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("logloss", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "logloss"); @@ -226,11 +226,11 @@ inline void VerifyLogLoss(DataSplitMode data_split_mode = DataSplitMode::kRow) { 1.3138f, 0.001f); delete metric; - CheckDeterministicMetricElementWise(StringView{"logloss"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"logloss"}, GPUIDX); } inline void VerifyError(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("error", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "error"); @@ -288,11 +288,11 @@ inline void VerifyError(DataSplitMode data_split_mode = DataSplitMode::kRow) { 0.45f, 0.001f); delete metric; - CheckDeterministicMetricElementWise(StringView{"error@0.5"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"error@0.5"}, GPUIDX); } inline void VerifyPoissonNegLogLik(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric * metric = xgboost::Metric::Create("poisson-nloglik", &ctx); metric->Configure({}); ASSERT_STREQ(metric->Name(), "poisson-nloglik"); @@ -321,18 +321,18 @@ inline void VerifyPoissonNegLogLik(DataSplitMode data_split_mode = DataSplitMode 1.5783f, 0.001f); delete metric; - CheckDeterministicMetricElementWise(StringView{"poisson-nloglik"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"poisson-nloglik"}, GPUIDX); } inline void VerifyMultiRMSE(DataSplitMode data_split_mode = DataSplitMode::kRow) { size_t n_samples = 32, n_targets = 8; - linalg::Tensor y{{n_samples, n_targets}, GetGPUId()}; + linalg::Tensor y{{n_samples, n_targets}, GPUIDX}; auto &h_y = y.Data()->HostVector(); std::iota(h_y.begin(), h_y.end(), 0); HostDeviceVector predt(n_samples * n_targets, 0); - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{Metric::Create("rmse", &ctx)}; metric->Configure({}); @@ -347,7 +347,7 @@ inline void VerifyMultiRMSE(DataSplitMode data_split_mode = DataSplitMode::kRow) } inline void VerifyQuantile(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{Metric::Create("quantile", &ctx)}; HostDeviceVector predts{0.1f, 0.9f, 0.1f, 0.9f}; diff --git a/tests/cpp/metric/test_metric.cc b/tests/cpp/metric/test_metric.cc index c629a1481..f43751366 100644 --- a/tests/cpp/metric/test_metric.cc +++ b/tests/cpp/metric/test_metric.cc @@ -4,7 +4,7 @@ #include "../helpers.h" namespace xgboost { TEST(Metric, UnknownMetric) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); xgboost::Metric* metric = nullptr; EXPECT_ANY_THROW(metric = xgboost::Metric::Create("unknown_name", &ctx)); EXPECT_NO_THROW(metric = xgboost::Metric::Create("rmse", &ctx)); diff --git a/tests/cpp/metric/test_multiclass_metric.h b/tests/cpp/metric/test_multiclass_metric.h index f147c91fa..5fdead596 100644 --- a/tests/cpp/metric/test_multiclass_metric.h +++ b/tests/cpp/metric/test_multiclass_metric.h @@ -60,8 +60,8 @@ inline void TestMultiClassError(int device, DataSplitMode data_split_mode) { } inline void VerifyMultiClassError(DataSplitMode data_split_mode = DataSplitMode::kRow) { - TestMultiClassError(GetGPUId(), data_split_mode); - CheckDeterministicMetricMultiClass(StringView{"merror"}, GetGPUId()); + TestMultiClassError(GPUIDX, data_split_mode); + CheckDeterministicMetricMultiClass(StringView{"merror"}, GPUIDX); } inline void TestMultiClassLogLoss(int device, DataSplitMode data_split_mode) { @@ -81,8 +81,8 @@ inline void TestMultiClassLogLoss(int device, DataSplitMode data_split_mode) { } inline void VerifyMultiClassLogLoss(DataSplitMode data_split_mode = DataSplitMode::kRow) { - TestMultiClassLogLoss(GetGPUId(), data_split_mode); - CheckDeterministicMetricMultiClass(StringView{"mlogloss"}, GetGPUId()); + TestMultiClassLogLoss(GPUIDX, data_split_mode); + CheckDeterministicMetricMultiClass(StringView{"mlogloss"}, GPUIDX); } } // namespace metric diff --git a/tests/cpp/metric/test_rank_metric.cc b/tests/cpp/metric/test_rank_metric.cc index 066e981b9..fbf0611b3 100644 --- a/tests/cpp/metric/test_rank_metric.cc +++ b/tests/cpp/metric/test_rank_metric.cc @@ -22,7 +22,7 @@ namespace metric { #if !defined(__CUDACC__) TEST(Metric, AMS) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); EXPECT_ANY_THROW(Metric::Create("ams", &ctx)); Metric* metric = Metric::Create("ams@0.5f", &ctx); ASSERT_STREQ(metric->Name(), "ams@0.5"); diff --git a/tests/cpp/metric/test_rank_metric.h b/tests/cpp/metric/test_rank_metric.h index 82d3725f5..2f7785689 100644 --- a/tests/cpp/metric/test_rank_metric.h +++ b/tests/cpp/metric/test_rank_metric.h @@ -20,7 +20,7 @@ namespace xgboost::metric { inline void VerifyPrecision(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric{Metric::Create("pre", &ctx)}; ASSERT_STREQ(metric->Name(), "pre"); EXPECT_NEAR(GetMetricEval(metric.get(), {0, 1}, {0, 1}, {}, {}, data_split_mode), 0.5, 1e-7); @@ -44,7 +44,7 @@ inline void VerifyPrecision(DataSplitMode data_split_mode = DataSplitMode::kRow) } inline void VerifyNDCG(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); Metric * metric = xgboost::Metric::Create("ndcg", &ctx); ASSERT_STREQ(metric->Name(), "ndcg"); EXPECT_ANY_THROW(GetMetricEval(metric, {0, 1}, {}, {}, {}, data_split_mode)); @@ -102,7 +102,7 @@ inline void VerifyNDCG(DataSplitMode data_split_mode = DataSplitMode::kRow) { } inline void VerifyMAP(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); Metric * metric = xgboost::Metric::Create("map", &ctx); ASSERT_STREQ(metric->Name(), "map"); EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}, {}, {}, data_split_mode), 1, kRtEps); @@ -150,7 +150,7 @@ inline void VerifyMAP(DataSplitMode data_split_mode = DataSplitMode::kRow) { } inline void VerifyNDCGExpGain(DataSplitMode data_split_mode = DataSplitMode::kRow) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); auto p_fmat = xgboost::RandomDataGenerator{0, 0, 0}.GenerateDMatrix(); MetaInfo& info = p_fmat->Info(); diff --git a/tests/cpp/metric/test_survival_metric.cu b/tests/cpp/metric/test_survival_metric.cu index da97b083b..eec92dc99 100644 --- a/tests/cpp/metric/test_survival_metric.cu +++ b/tests/cpp/metric/test_survival_metric.cu @@ -31,7 +31,7 @@ TEST_F(DeclareUnifiedDistributedTest(MetricTest), IntervalRegressionAccuracyColu // Test configuration of AFT metric TEST(AFTNegLogLikMetric, DeclareUnifiedTest(Configuration)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr metric(Metric::Create("aft-nloglik", &ctx)); metric->Configure({{"aft_loss_distribution", "normal"}, {"aft_loss_distribution_scale", "10"}}); @@ -42,7 +42,7 @@ TEST(AFTNegLogLikMetric, DeclareUnifiedTest(Configuration)) { EXPECT_EQ(get(aft_param_json["aft_loss_distribution"]), "normal"); EXPECT_EQ(get(aft_param_json["aft_loss_distribution_scale"]), "10"); - CheckDeterministicMetricElementWise(StringView{"aft-nloglik"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"aft-nloglik"}, GPUIDX); } } // namespace common } // namespace xgboost diff --git a/tests/cpp/metric/test_survival_metric.h b/tests/cpp/metric/test_survival_metric.h index 5baa5b5a4..1626d3772 100644 --- a/tests/cpp/metric/test_survival_metric.h +++ b/tests/cpp/metric/test_survival_metric.h @@ -48,7 +48,7 @@ inline void CheckDeterministicMetricElementWise(StringView name, int32_t device) } inline void VerifyAFTNegLogLik(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); /** * Test aggregate output from the AFT metric over a small test data set. @@ -79,7 +79,7 @@ inline void VerifyAFTNegLogLik(DataSplitMode data_split_mode = DataSplitMode::kR } inline void VerifyIntervalRegressionAccuracy(DataSplitMode data_split_mode = DataSplitMode::kRow) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); auto p_fmat = EmptyDMatrix(); MetaInfo& info = p_fmat->Info(); @@ -101,7 +101,7 @@ inline void VerifyIntervalRegressionAccuracy(DataSplitMode data_split_mode = Dat info.labels_lower_bound_.HostVector()[0] = 70.0f; EXPECT_FLOAT_EQ(metric->Evaluate(preds, p_fmat), 0.25f); - CheckDeterministicMetricElementWise(StringView{"interval-regression-accuracy"}, GetGPUId()); + CheckDeterministicMetricElementWise(StringView{"interval-regression-accuracy"}, GPUIDX); } } // namespace common } // namespace xgboost diff --git a/tests/cpp/objective/test_aft_obj.cc b/tests/cpp/objective/test_aft_obj.cc index 60aebdf3a..74973918c 100644 --- a/tests/cpp/objective/test_aft_obj.cc +++ b/tests/cpp/objective/test_aft_obj.cc @@ -16,7 +16,7 @@ namespace xgboost { namespace common { TEST(Objective, DeclareUnifiedTest(AFTObjConfiguration)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr objective(ObjFunction::Create("survival:aft", &ctx)); objective->Configure({ {"aft_loss_distribution", "logistic"}, {"aft_loss_distribution_scale", "5"} }); @@ -77,7 +77,7 @@ static inline void CheckGPairOverGridPoints( } TEST(Objective, DeclareUnifiedTest(AFTObjGPairUncensoredLabels)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr obj(ObjFunction::Create("survival:aft", &ctx)); CheckGPairOverGridPoints(obj.get(), 100.0f, 100.0f, "normal", @@ -101,7 +101,7 @@ TEST(Objective, DeclareUnifiedTest(AFTObjGPairUncensoredLabels)) { } TEST(Objective, DeclareUnifiedTest(AFTObjGPairLeftCensoredLabels)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr obj(ObjFunction::Create("survival:aft", &ctx)); CheckGPairOverGridPoints(obj.get(), 0.0f, 20.0f, "normal", @@ -122,7 +122,7 @@ TEST(Objective, DeclareUnifiedTest(AFTObjGPairLeftCensoredLabels)) { } TEST(Objective, DeclareUnifiedTest(AFTObjGPairRightCensoredLabels)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr obj(ObjFunction::Create("survival:aft", &ctx)); CheckGPairOverGridPoints(obj.get(), 60.0f, std::numeric_limits::infinity(), "normal", @@ -146,7 +146,7 @@ TEST(Objective, DeclareUnifiedTest(AFTObjGPairRightCensoredLabels)) { } TEST(Objective, DeclareUnifiedTest(AFTObjGPairIntervalCensoredLabels)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr obj(ObjFunction::Create("survival:aft", &ctx)); CheckGPairOverGridPoints(obj.get(), 16.0f, 200.0f, "normal", diff --git a/tests/cpp/objective/test_hinge.cc b/tests/cpp/objective/test_hinge.cc index a4b8525fa..17d2609d4 100644 --- a/tests/cpp/objective/test_hinge.cc +++ b/tests/cpp/objective/test_hinge.cc @@ -6,7 +6,7 @@ #include "../helpers.h" namespace xgboost { TEST(Objective, DeclareUnifiedTest(HingeObj)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::unique_ptr obj{ObjFunction::Create("binary:hinge", &ctx)}; float eps = std::numeric_limits::min(); diff --git a/tests/cpp/objective/test_lambdarank_obj.cc b/tests/cpp/objective/test_lambdarank_obj.cc index 0c65780ae..c808e97f0 100644 --- a/tests/cpp/objective/test_lambdarank_obj.cc +++ b/tests/cpp/objective/test_lambdarank_obj.cc @@ -71,7 +71,7 @@ void TestNDCGGPair(Context const* ctx) { HostDeviceVector predts{0, 1, 0, 1}; MetaInfo info; - info.labels = linalg::Tensor{{0, 1, 0, 1}, {4, 1}, GetGPUId()}; + info.labels = linalg::Tensor{{0, 1, 0, 1}, {4, 1}, GPUIDX}; info.group_ptr_ = {0, 2, 4}; info.num_row_ = 4; HostDeviceVector gpairs; diff --git a/tests/cpp/objective/test_multiclass_obj.cc b/tests/cpp/objective/test_multiclass_obj.cc index fa8fc27e4..d028ef9cf 100644 --- a/tests/cpp/objective/test_multiclass_obj.cc +++ b/tests/cpp/objective/test_multiclass_obj.cc @@ -9,7 +9,7 @@ namespace xgboost { TEST(Objective, DeclareUnifiedTest(SoftmaxMultiClassObjGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args {{"num_class", "3"}}; std::unique_ptr obj { ObjFunction::Create("multi:softmax", &ctx) @@ -36,7 +36,7 @@ TEST(Objective, DeclareUnifiedTest(SoftmaxMultiClassObjGPair)) { } TEST(Objective, DeclareUnifiedTest(SoftmaxMultiClassBasic)) { - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::vector> args{ std::pair("num_class", "3")}; @@ -57,7 +57,7 @@ TEST(Objective, DeclareUnifiedTest(SoftmaxMultiClassBasic)) { } TEST(Objective, DeclareUnifiedTest(SoftprobMultiClassBasic)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args { std::pair("num_class", "3")}; diff --git a/tests/cpp/objective/test_quantile_obj.cc b/tests/cpp/objective/test_quantile_obj.cc index 5078440bb..b263b4a8f 100644 --- a/tests/cpp/objective/test_quantile_obj.cc +++ b/tests/cpp/objective/test_quantile_obj.cc @@ -14,7 +14,7 @@ namespace xgboost { TEST(Objective, DeclareUnifiedTest(Quantile)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); { Args args{{"quantile_alpha", "[0.6, 0.8]"}}; @@ -37,7 +37,7 @@ TEST(Objective, DeclareUnifiedTest(Quantile)) { } TEST(Objective, DeclareUnifiedTest(QuantileIntercept)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); Args args{{"quantile_alpha", "[0.6, 0.8]"}}; std::unique_ptr obj{ObjFunction::Create("reg:quantileerror", &ctx)}; obj->Configure(args); diff --git a/tests/cpp/objective/test_regression_obj.cc b/tests/cpp/objective/test_regression_obj.cc index 635fae997..b8a40603b 100644 --- a/tests/cpp/objective/test_regression_obj.cc +++ b/tests/cpp/objective/test_regression_obj.cc @@ -17,7 +17,7 @@ namespace xgboost { TEST(Objective, DeclareUnifiedTest(LinearRegressionGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:squarederror", &ctx)}; @@ -39,7 +39,7 @@ TEST(Objective, DeclareUnifiedTest(LinearRegressionGPair)) { } TEST(Objective, DeclareUnifiedTest(SquaredLog)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:squaredlogerror", &ctx)}; @@ -62,7 +62,7 @@ TEST(Objective, DeclareUnifiedTest(SquaredLog)) { } TEST(Objective, DeclareUnifiedTest(PseudoHuber)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); Args args; std::unique_ptr obj{ObjFunction::Create("reg:pseudohubererror", &ctx)}; @@ -91,7 +91,7 @@ TEST(Objective, DeclareUnifiedTest(PseudoHuber)) { } TEST(Objective, DeclareUnifiedTest(LogisticRegressionGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:logistic", &ctx)}; @@ -107,7 +107,7 @@ TEST(Objective, DeclareUnifiedTest(LogisticRegressionGPair)) { } TEST(Objective, DeclareUnifiedTest(LogisticRegressionBasic)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:logistic", &ctx)}; @@ -136,7 +136,7 @@ TEST(Objective, DeclareUnifiedTest(LogisticRegressionBasic)) { } TEST(Objective, DeclareUnifiedTest(LogisticRawGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj { ObjFunction::Create("binary:logitraw", &ctx) @@ -152,7 +152,7 @@ TEST(Objective, DeclareUnifiedTest(LogisticRawGPair)) { } TEST(Objective, DeclareUnifiedTest(PoissonRegressionGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj { ObjFunction::Create("count:poisson", &ctx) @@ -176,7 +176,7 @@ TEST(Objective, DeclareUnifiedTest(PoissonRegressionGPair)) { } TEST(Objective, DeclareUnifiedTest(PoissonRegressionBasic)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj { ObjFunction::Create("count:poisson", &ctx) @@ -205,7 +205,7 @@ TEST(Objective, DeclareUnifiedTest(PoissonRegressionBasic)) { } TEST(Objective, DeclareUnifiedTest(GammaRegressionGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj { ObjFunction::Create("reg:gamma", &ctx) @@ -227,7 +227,7 @@ TEST(Objective, DeclareUnifiedTest(GammaRegressionGPair)) { } TEST(Objective, DeclareUnifiedTest(GammaRegressionBasic)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:gamma", &ctx)}; @@ -256,7 +256,7 @@ TEST(Objective, DeclareUnifiedTest(GammaRegressionBasic)) { } TEST(Objective, DeclareUnifiedTest(TweedieRegressionGPair)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:tweedie", &ctx)}; @@ -280,7 +280,7 @@ TEST(Objective, DeclareUnifiedTest(TweedieRegressionGPair)) { #if defined(__CUDACC__) TEST(Objective, CPU_vs_CUDA) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); ObjFunction* obj = ObjFunction::Create("reg:squarederror", &ctx); HostDeviceVector cpu_out_preds; @@ -331,7 +331,7 @@ TEST(Objective, CPU_vs_CUDA) { #endif TEST(Objective, DeclareUnifiedTest(TweedieRegressionBasic)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("reg:tweedie", &ctx)}; @@ -360,7 +360,7 @@ TEST(Objective, DeclareUnifiedTest(TweedieRegressionBasic)) { // CoxRegression not implemented in GPU code, no need for testing. #if !defined(__CUDACC__) TEST(Objective, CoxRegressionGPair) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::vector> args; std::unique_ptr obj{ObjFunction::Create("survival:cox", &ctx)}; @@ -375,7 +375,7 @@ TEST(Objective, CoxRegressionGPair) { #endif TEST(Objective, DeclareUnifiedTest(AbsoluteError)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); std::unique_ptr obj{ObjFunction::Create("reg:absoluteerror", &ctx)}; obj->Configure({}); CheckConfigReload(obj, "reg:absoluteerror"); @@ -419,7 +419,7 @@ TEST(Objective, DeclareUnifiedTest(AbsoluteError)) { } TEST(Objective, DeclareUnifiedTest(AbsoluteErrorLeaf)) { - Context ctx = MakeCUDACtx(GetGPUId()); + Context ctx = MakeCUDACtx(GPUIDX); bst_target_t constexpr kTargets = 3, kRows = 16; std::unique_ptr obj{ObjFunction::Create("reg:absoluteerror", &ctx)}; obj->Configure({}); diff --git a/tests/cpp/plugin/test_example_objective.cc b/tests/cpp/plugin/test_example_objective.cc index 29fe2ad2b..ccb83c781 100644 --- a/tests/cpp/plugin/test_example_objective.cc +++ b/tests/cpp/plugin/test_example_objective.cc @@ -5,7 +5,7 @@ namespace xgboost { TEST(Plugin, ExampleObjective) { - xgboost::Context ctx = MakeCUDACtx(GetGPUId()); + xgboost::Context ctx = MakeCUDACtx(GPUIDX); auto* obj = xgboost::ObjFunction::Create("mylogistic", &ctx); ASSERT_EQ(obj->DefaultEvalMetric(), std::string{"logloss"}); delete obj; diff --git a/tests/cpp/plugin/test_federated_adapter.cu b/tests/cpp/plugin/test_federated_adapter.cu index 75422fcca..8aa5304ea 100644 --- a/tests/cpp/plugin/test_federated_adapter.cu +++ b/tests/cpp/plugin/test_federated_adapter.cu @@ -27,7 +27,7 @@ namespace { void VerifyAllReduceSum() { auto const world_size = collective::GetWorldSize(); auto const rank = collective::GetRank(); - auto const device = GetGPUId(); + auto const device = GPUIDX; int count = 3; common::SetDevice(device); thrust::device_vector buffer(count, 0); @@ -49,7 +49,7 @@ namespace { void VerifyAllGatherV() { auto const world_size = collective::GetWorldSize(); auto const rank = collective::GetRank(); - auto const device = GetGPUId(); + auto const device = GPUIDX; int const count = rank + 2; common::SetDevice(device); thrust::device_vector buffer(count, 0); diff --git a/tests/cpp/predictor/test_gpu_predictor.cu b/tests/cpp/predictor/test_gpu_predictor.cu index ecddf2288..3a65e3e06 100644 --- a/tests/cpp/predictor/test_gpu_predictor.cu +++ b/tests/cpp/predictor/test_gpu_predictor.cu @@ -60,7 +60,7 @@ void VerifyBasicColumnSplit(std::array, 32> const& expected_r auto const world_size = collective::GetWorldSize(); auto const rank = collective::GetRank(); - auto ctx = MakeCUDACtx(GetGPUId()); + auto ctx = MakeCUDACtx(GPUIDX); std::unique_ptr predictor = std::unique_ptr(Predictor::Create("gpu_predictor", &ctx)); predictor->Configure({}); @@ -283,7 +283,7 @@ TEST(GPUPredictor, CategoricalPredictLeaf) { TEST(GPUPredictor, PredictLeafBasic) { size_t constexpr kRows = 5, kCols = 5; auto dmat = RandomDataGenerator(kRows, kCols, 0).Device(0).GenerateDMatrix(); - auto lparam = MakeCUDACtx(GetGPUId()); + auto lparam = MakeCUDACtx(GPUIDX); std::unique_ptr gpu_predictor = std::unique_ptr(Predictor::Create("gpu_predictor", &lparam)); gpu_predictor->Configure({});