Skip to content

Commit

Permalink
remove pruner; add preductions cache tests for sycl
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Razdoburdin committed Aug 19, 2024
1 parent d2f4680 commit 649e7a6
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 50 deletions.
9 changes: 4 additions & 5 deletions plugin/sycl/tree/hist_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ template <typename GradientSumT>
void HistUpdater<GradientSumT>::Update(
xgboost::tree::TrainParam const *param,
const common::GHistIndexMatrix &gmat,
linalg::Matrix<GradientPair> *gpair,
const USMVector<GradientPair, MemoryType::on_device>& gpair_device,
const USMVector<GradientPair, MemoryType::on_device>& gpair,
DMatrix *p_fmat,
xgboost::common::Span<HostDeviceVector<bst_node_t>> out_position,
RegTree *p_tree) {
Expand All @@ -321,11 +320,11 @@ void HistUpdater<GradientSumT>::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) {
Expand Down
7 changes: 1 addition & 6 deletions plugin/sycl/tree/hist_updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <xgboost/tree_updater.h>
#pragma GCC diagnostic pop

#include <utility>
#include <vector>
#include <memory>
#include <queue>
Expand Down Expand Up @@ -54,12 +53,10 @@ class HistUpdater {
explicit HistUpdater(const Context* ctx,
::sycl::queue qu,
const xgboost::tree::TrainParam& param,
std::unique_ptr<TreeUpdater> 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");
Expand All @@ -75,8 +72,7 @@ class HistUpdater {
// update one tree, growing
void Update(xgboost::tree::TrainParam const *param,
const common::GHistIndexMatrix &gmat,
linalg::Matrix<GradientPair> *gpair,
const USMVector<GradientPair, MemoryType::on_device>& gpair_device,
const USMVector<GradientPair, MemoryType::on_device>& gpair,
DMatrix *p_fmat,
xgboost::common::Span<HostDeviceVector<bst_node_t>> out_position,
RegTree *p_tree);
Expand Down Expand Up @@ -210,7 +206,6 @@ class HistUpdater {
std::vector<SplitEntry<GradientSumT>> best_splits_host_;

TreeEvaluator<GradientSumT> tree_evaluator_;
std::unique_ptr<TreeUpdater> pruner_;
FeatureInteractionConstraintHost interaction_constraints_;

// back pointers to tree and data matrix
Expand Down
10 changes: 1 addition & 9 deletions plugin/sycl/tree/updater_quantile_hist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
#include <vector>
#include <memory>
#include <utility>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtautological-constant-compare"
Expand All @@ -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);

Expand All @@ -56,7 +49,6 @@ void QuantileHistMaker::SetPimpl(std::unique_ptr<HistUpdater<GradientSumT>>* pim
ctx_,
qu_,
param_,
std::move(pruner_),
int_constraint_, dmat));
if (collective::IsDistributed()) {
LOG(FATAL) << "Distributed mode is not yet upstreamed for sycl";
Expand All @@ -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);
}
}

Expand Down
1 change: 0 additions & 1 deletion plugin/sycl/tree/updater_quantile_hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class QuantileHistMaker: public TreeUpdater {
std::unique_ptr<HistUpdater<float>> pimpl_fp32;
std::unique_ptr<HistUpdater<double>> pimpl_fp64;

std::unique_ptr<TreeUpdater> pruner_;
FeatureInteractionConstraintHost int_constraint_;

::sycl::queue qu_;
Expand Down
38 changes: 9 additions & 29 deletions tests/cpp/plugin/test_sycl_hist_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ class TestHistUpdater : public HistUpdater<GradientSumT> {
TestHistUpdater(const Context* ctx,
::sycl::queue qu,
const xgboost::tree::TrainParam& param,
std::unique_ptr<TreeUpdater> pruner,
FeatureInteractionConstraintHost int_constraints_,
DMatrix const* fmat) : HistUpdater<GradientSumT>(ctx, qu, param,
std::move(pruner),
int_constraints_, fmat) {}

void TestInitSampling(const USMVector<GradientPair, MemoryType::on_device> &gpair,
Expand Down Expand Up @@ -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<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};

TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());

USMVector<size_t, MemoryType::on_device> row_indices_0(&qu, num_rows);
USMVector<size_t, MemoryType::on_device> row_indices_1(&qu, num_rows);
Expand Down Expand Up @@ -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<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};

TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());

USMVector<GradientPair, MemoryType::on_device> gpair(&qu, num_rows);
GenerateRandomGPairs(&qu, gpair.Data(), num_rows, has_neg_hess);
Expand Down Expand Up @@ -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<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};

TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());
updater.SetHistSynchronizer(new BatchHistSynchronizer<GradientSumT>());
updater.SetHistRowsAdder(new BatchHistRowsAdder<GradientSumT>());

Expand Down Expand Up @@ -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<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};

TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());
updater.SetHistSynchronizer(new BatchHistSynchronizer<GradientSumT>());
updater.SetHistRowsAdder(new BatchHistRowsAdder<GradientSumT>());

Expand Down Expand Up @@ -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<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};

TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());
updater.SetHistSynchronizer(new BatchHistSynchronizer<GradientSumT>());
updater.SetHistRowsAdder(new BatchHistRowsAdder<GradientSumT>());

Expand Down Expand Up @@ -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());
Expand All @@ -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<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());
USMVector<GradientPair, MemoryType::on_device> gpair(&qu, num_rows);
GenerateRandomGPairs(&qu, gpair.Data(), num_rows, false);

Expand All @@ -455,8 +440,7 @@ void TestHistUpdaterApplySplit(const xgboost::tree::TrainParam& param, float spa
std::vector<size_t> row_indices_desired_host(num_rows);
size_t n_left, n_right;
{
std::unique_ptr<TreeUpdater> pruner4verification{TreeUpdater::Create("prune", &ctx, &task)};
TestHistUpdater<GradientSumT> updater4verification(&ctx, qu, param, std::move(pruner4verification), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> 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();
Expand Down Expand Up @@ -526,9 +510,7 @@ void TestHistUpdaterExpandWithLossGuide(const xgboost::tree::TrainParam& param)

RegTree tree;
FeatureInteractionConstraintHost int_constraints;
ObjInfo task{ObjInfo::kRegression};
std::unique_ptr<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());
updater.SetHistSynchronizer(new BatchHistSynchronizer<GradientSumT>());
updater.SetHistRowsAdder(new BatchHistRowsAdder<GradientSumT>());
auto* row_set_collection = updater.TestInitData(gmat, gpair, *p_fmat, tree);
Expand Down Expand Up @@ -576,9 +558,7 @@ void TestHistUpdaterExpandWithDepthWise(const xgboost::tree::TrainParam& param)

RegTree tree;
FeatureInteractionConstraintHost int_constraints;
ObjInfo task{ObjInfo::kRegression};
std::unique_ptr<TreeUpdater> pruner{TreeUpdater::Create("prune", &ctx, &task)};
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, std::move(pruner), int_constraints, p_fmat.get());
TestHistUpdater<GradientSumT> updater(&ctx, qu, param, int_constraints, p_fmat.get());
updater.SetHistSynchronizer(new BatchHistSynchronizer<GradientSumT>());
updater.SetHistRowsAdder(new BatchHistRowsAdder<GradientSumT>());
auto* row_set_collection = updater.TestInitData(gmat, gpair, *p_fmat, tree);
Expand Down
23 changes: 23 additions & 0 deletions tests/cpp/plugin/test_sycl_prediction_cache.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright 2020-2024 by XGBoost contributors
*/
#include <gtest/gtest.h>

#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

0 comments on commit 649e7a6

Please sign in to comment.