From 649e7a6f38fb656c572dbda365fd5ffa11c78fcf Mon Sep 17 00:00:00 2001 From: Dmitry Razdoburdin <> Date: Mon, 19 Aug 2024 02:34:48 -0700 Subject: [PATCH] remove pruner; add preductions cache tests for sycl --- plugin/sycl/tree/hist_updater.cc | 9 ++--- plugin/sycl/tree/hist_updater.h | 7 +--- plugin/sycl/tree/updater_quantile_hist.cc | 10 +---- plugin/sycl/tree/updater_quantile_hist.h | 1 - tests/cpp/plugin/test_sycl_hist_updater.cc | 38 +++++-------------- .../cpp/plugin/test_sycl_prediction_cache.cc | 23 +++++++++++ 6 files changed, 38 insertions(+), 50 deletions(-) create mode 100644 tests/cpp/plugin/test_sycl_prediction_cache.cc diff --git a/plugin/sycl/tree/hist_updater.cc b/plugin/sycl/tree/hist_updater.cc index 6ebe98414178..c641db7beed6 100644 --- a/plugin/sycl/tree/hist_updater.cc +++ b/plugin/sycl/tree/hist_updater.cc @@ -311,8 +311,7 @@ template void HistUpdater::Update( xgboost::tree::TrainParam const *param, const common::GHistIndexMatrix &gmat, - linalg::Matrix *gpair, - const USMVector& gpair_device, + const USMVector& gpair, DMatrix *p_fmat, xgboost::common::Span> out_position, RegTree *p_tree) { @@ -321,11 +320,11 @@ void HistUpdater::Update( tree_evaluator_.Reset(qu_, param_, p_fmat->Info().num_col_); interaction_constraints_.Reset(); - this->InitData(gmat, gpair_device, *p_fmat, *p_tree); + this->InitData(gmat, gpair, *p_fmat, *p_tree); if (param_.grow_policy == xgboost::tree::TrainParam::kLossGuide) { - ExpandWithLossGuide(gmat, p_tree, gpair_device); + ExpandWithLossGuide(gmat, p_tree, gpair); } else { - ExpandWithDepthWise(gmat, p_tree, gpair_device); + ExpandWithDepthWise(gmat, p_tree, gpair); } for (int nid = 0; nid < p_tree->NumNodes(); ++nid) { diff --git a/plugin/sycl/tree/hist_updater.h b/plugin/sycl/tree/hist_updater.h index b8c565184058..5f23bc5848ac 100644 --- a/plugin/sycl/tree/hist_updater.h +++ b/plugin/sycl/tree/hist_updater.h @@ -11,7 +11,6 @@ #include #pragma GCC diagnostic pop -#include #include #include #include @@ -54,12 +53,10 @@ class HistUpdater { explicit HistUpdater(const Context* ctx, ::sycl::queue qu, const xgboost::tree::TrainParam& param, - std::unique_ptr pruner, FeatureInteractionConstraintHost int_constraints_, DMatrix const* fmat) : ctx_(ctx), qu_(qu), param_(param), tree_evaluator_(qu, param, fmat->Info().num_col_), - pruner_(std::move(pruner)), interaction_constraints_{std::move(int_constraints_)}, p_last_tree_(nullptr), p_last_fmat_(fmat) { builder_monitor_.Init("SYCL::Quantile::HistUpdater"); @@ -75,8 +72,7 @@ class HistUpdater { // update one tree, growing void Update(xgboost::tree::TrainParam const *param, const common::GHistIndexMatrix &gmat, - linalg::Matrix *gpair, - const USMVector& gpair_device, + const USMVector& gpair, DMatrix *p_fmat, xgboost::common::Span> out_position, RegTree *p_tree); @@ -210,7 +206,6 @@ class HistUpdater { std::vector> best_splits_host_; TreeEvaluator tree_evaluator_; - std::unique_ptr pruner_; FeatureInteractionConstraintHost interaction_constraints_; // back pointers to tree and data matrix diff --git a/plugin/sycl/tree/updater_quantile_hist.cc b/plugin/sycl/tree/updater_quantile_hist.cc index 6b0289a073a2..ee7a7ad0f101 100644 --- a/plugin/sycl/tree/updater_quantile_hist.cc +++ b/plugin/sycl/tree/updater_quantile_hist.cc @@ -4,7 +4,6 @@ */ #include #include -#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wtautological-constant-compare" @@ -29,12 +28,6 @@ void QuantileHistMaker::Configure(const Args& args) { const DeviceOrd device_spec = ctx_->Device(); qu_ = device_manager.GetQueue(device_spec); - // initialize pruner - if (!pruner_) { - pruner_.reset(TreeUpdater::Create("prune", ctx_, task_)); - } - pruner_->Configure(args); - param_.UpdateAllowUnknown(args); hist_maker_param_.UpdateAllowUnknown(args); @@ -56,7 +49,6 @@ void QuantileHistMaker::SetPimpl(std::unique_ptr>* pim ctx_, qu_, param_, - std::move(pruner_), int_constraint_, dmat)); if (collective::IsDistributed()) { LOG(FATAL) << "Distributed mode is not yet upstreamed for sycl"; @@ -80,7 +72,7 @@ void QuantileHistMaker::CallUpdate( qu_.wait(); for (auto tree : trees) { - pimpl->Update(param, gmat_, gpair, gpair_device_, dmat, out_position, tree); + pimpl->Update(param, gmat_, gpair_device_, dmat, out_position, tree); } } diff --git a/plugin/sycl/tree/updater_quantile_hist.h b/plugin/sycl/tree/updater_quantile_hist.h index 3e5f306868b4..693255b26157 100644 --- a/plugin/sycl/tree/updater_quantile_hist.h +++ b/plugin/sycl/tree/updater_quantile_hist.h @@ -103,7 +103,6 @@ class QuantileHistMaker: public TreeUpdater { std::unique_ptr> pimpl_fp32; std::unique_ptr> pimpl_fp64; - std::unique_ptr pruner_; FeatureInteractionConstraintHost int_constraint_; ::sycl::queue qu_; diff --git a/tests/cpp/plugin/test_sycl_hist_updater.cc b/tests/cpp/plugin/test_sycl_hist_updater.cc index 7789b44381dd..a341f4645e60 100644 --- a/tests/cpp/plugin/test_sycl_hist_updater.cc +++ b/tests/cpp/plugin/test_sycl_hist_updater.cc @@ -21,10 +21,8 @@ class TestHistUpdater : public HistUpdater { TestHistUpdater(const Context* ctx, ::sycl::queue qu, const xgboost::tree::TrainParam& param, - std::unique_ptr pruner, FeatureInteractionConstraintHost int_constraints_, DMatrix const* fmat) : HistUpdater(ctx, qu, param, - std::move(pruner), int_constraints_, fmat) {} void TestInitSampling(const USMVector &gpair, @@ -110,14 +108,12 @@ void TestHistUpdaterSampling(const xgboost::tree::TrainParam& param) { DeviceManager device_manager; auto qu = device_manager.GetQueue(ctx.Device()); - ObjInfo task{ObjInfo::kRegression}; auto p_fmat = RandomDataGenerator{num_rows, num_columns, 0.0}.GenerateDMatrix(); FeatureInteractionConstraintHost int_constraints; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); USMVector row_indices_0(&qu, num_rows); USMVector row_indices_1(&qu, num_rows); @@ -165,14 +161,12 @@ void TestHistUpdaterInitData(const xgboost::tree::TrainParam& param, bool has_ne DeviceManager device_manager; auto qu = device_manager.GetQueue(ctx.Device()); - ObjInfo task{ObjInfo::kRegression}; auto p_fmat = RandomDataGenerator{num_rows, num_columns, 0.0}.GenerateDMatrix(); FeatureInteractionConstraintHost int_constraints; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); USMVector gpair(&qu, num_rows); GenerateRandomGPairs(&qu, gpair.Data(), num_rows, has_neg_hess); @@ -221,14 +215,12 @@ void TestHistUpdaterBuildHistogramsLossGuide(const xgboost::tree::TrainParam& pa DeviceManager device_manager; auto qu = device_manager.GetQueue(ctx.Device()); - ObjInfo task{ObjInfo::kRegression}; auto p_fmat = RandomDataGenerator{num_rows, num_columns, sparsity}.GenerateDMatrix(); FeatureInteractionConstraintHost int_constraints; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); updater.SetHistSynchronizer(new BatchHistSynchronizer()); updater.SetHistRowsAdder(new BatchHistRowsAdder()); @@ -285,14 +277,12 @@ void TestHistUpdaterInitNewNode(const xgboost::tree::TrainParam& param, float sp DeviceManager device_manager; auto qu = device_manager.GetQueue(ctx.Device()); - ObjInfo task{ObjInfo::kRegression}; auto p_fmat = RandomDataGenerator{num_rows, num_columns, sparsity}.GenerateDMatrix(); FeatureInteractionConstraintHost int_constraints; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); updater.SetHistSynchronizer(new BatchHistSynchronizer()); updater.SetHistRowsAdder(new BatchHistRowsAdder()); @@ -345,14 +335,12 @@ void TestHistUpdaterEvaluateSplits(const xgboost::tree::TrainParam& param) { DeviceManager device_manager; auto qu = device_manager.GetQueue(ctx.Device()); - ObjInfo task{ObjInfo::kRegression}; auto p_fmat = RandomDataGenerator{num_rows, num_columns, 0.0f}.GenerateDMatrix(); FeatureInteractionConstraintHost int_constraints; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); updater.SetHistSynchronizer(new BatchHistSynchronizer()); updater.SetHistRowsAdder(new BatchHistRowsAdder()); @@ -423,8 +411,6 @@ void TestHistUpdaterApplySplit(const xgboost::tree::TrainParam& param, float spa DeviceManager device_manager; auto qu = device_manager.GetQueue(ctx.Device()); - ObjInfo task{ObjInfo::kRegression}; - auto p_fmat = RandomDataGenerator{num_rows, num_columns, sparsity}.GenerateDMatrix(); sycl::DeviceMatrix dmat; dmat.Init(qu, p_fmat.get()); @@ -439,8 +425,7 @@ void TestHistUpdaterApplySplit(const xgboost::tree::TrainParam& param, float spa nodes.emplace_back(tree::ExpandEntry(0, tree.GetDepth(0))); FeatureInteractionConstraintHost int_constraints; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); USMVector gpair(&qu, num_rows); GenerateRandomGPairs(&qu, gpair.Data(), num_rows, false); @@ -455,8 +440,7 @@ void TestHistUpdaterApplySplit(const xgboost::tree::TrainParam& param, float spa std::vector row_indices_desired_host(num_rows); size_t n_left, n_right; { - std::unique_ptr pruner4verification{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater4verification(&ctx, qu, param, std::move(pruner4verification), int_constraints, p_fmat.get()); + TestHistUpdater updater4verification(&ctx, qu, param, int_constraints, p_fmat.get()); auto* row_set_collection4verification = updater4verification.TestInitData(gmat, gpair, *p_fmat, tree); size_t n_nodes = nodes.size(); @@ -526,9 +510,7 @@ void TestHistUpdaterExpandWithLossGuide(const xgboost::tree::TrainParam& param) RegTree tree; FeatureInteractionConstraintHost int_constraints; - ObjInfo task{ObjInfo::kRegression}; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); updater.SetHistSynchronizer(new BatchHistSynchronizer()); updater.SetHistRowsAdder(new BatchHistRowsAdder()); auto* row_set_collection = updater.TestInitData(gmat, gpair, *p_fmat, tree); @@ -576,9 +558,7 @@ void TestHistUpdaterExpandWithDepthWise(const xgboost::tree::TrainParam& param) RegTree tree; FeatureInteractionConstraintHost int_constraints; - ObjInfo task{ObjInfo::kRegression}; - std::unique_ptr pruner{TreeUpdater::Create("prune", &ctx, &task)}; - TestHistUpdater updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get()); + TestHistUpdater updater(&ctx, qu, param, int_constraints, p_fmat.get()); updater.SetHistSynchronizer(new BatchHistSynchronizer()); updater.SetHistRowsAdder(new BatchHistRowsAdder()); auto* row_set_collection = updater.TestInitData(gmat, gpair, *p_fmat, tree); diff --git a/tests/cpp/plugin/test_sycl_prediction_cache.cc b/tests/cpp/plugin/test_sycl_prediction_cache.cc new file mode 100644 index 000000000000..43f99dc63925 --- /dev/null +++ b/tests/cpp/plugin/test_sycl_prediction_cache.cc @@ -0,0 +1,23 @@ +/** + * Copyright 2020-2024 by XGBoost contributors + */ +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtautological-constant-compare" +#pragma GCC diagnostic ignored "-W#pragma-messages" +#include "../tree/test_prediction_cache.h" +#pragma GCC diagnostic pop + +namespace xgboost::sycl::tree { + +class SyclPredictionCache : public xgboost::TestPredictionCache {}; + +TEST_F(SyclPredictionCache, Hist) { + Context ctx; + ctx.UpdateAllowUnknown(Args{{"device", "sycl"}}); + + this->RunTest(&ctx, "grow_quantile_histmaker_sycl", "one_output_per_tree"); +} + +} // namespace xgboost::sycl::tree