[sycl] add data initialisation for training (#10222)
Co-authored-by: Dmitry Razdoburdin <> Co-authored-by: Philip Hyunsu Cho <chohyu01@cs.washington.edu> Co-authored-by: Jiaming Yuan <jm.yuan@outlook.com>
This commit is contained in:
committed by
GitHub
parent
5e64276a9b
commit
dcc9639b91
@@ -50,6 +50,80 @@ void HistUpdater<GradientSumT>::InitSampling(
|
||||
qu_.wait();
|
||||
}
|
||||
|
||||
template<typename GradientSumT>
|
||||
void HistUpdater<GradientSumT>::InitData(
|
||||
Context const * ctx,
|
||||
const common::GHistIndexMatrix& gmat,
|
||||
const USMVector<GradientPair, MemoryType::on_device> &gpair,
|
||||
const DMatrix& fmat,
|
||||
const RegTree& tree) {
|
||||
CHECK((param_.max_depth > 0 || param_.max_leaves > 0))
|
||||
<< "max_depth or max_leaves cannot be both 0 (unlimited); "
|
||||
<< "at least one should be a positive quantity.";
|
||||
if (param_.grow_policy == xgboost::tree::TrainParam::kDepthWise) {
|
||||
CHECK(param_.max_depth > 0) << "max_depth cannot be 0 (unlimited) "
|
||||
<< "when grow_policy is depthwise.";
|
||||
}
|
||||
builder_monitor_.Start("InitData");
|
||||
const auto& info = fmat.Info();
|
||||
|
||||
// initialize the row set
|
||||
{
|
||||
row_set_collection_.Clear();
|
||||
USMVector<size_t, MemoryType::on_device>* row_indices = &(row_set_collection_.Data());
|
||||
row_indices->Resize(&qu_, info.num_row_);
|
||||
size_t* p_row_indices = row_indices->Data();
|
||||
// mark subsample and build list of member rows
|
||||
if (param_.subsample < 1.0f) {
|
||||
CHECK_EQ(param_.sampling_method, xgboost::tree::TrainParam::kUniform)
|
||||
<< "Only uniform sampling is supported, "
|
||||
<< "gradient-based sampling is only support by GPU Hist.";
|
||||
InitSampling(gpair, row_indices);
|
||||
} else {
|
||||
int has_neg_hess = 0;
|
||||
const GradientPair* gpair_ptr = gpair.DataConst();
|
||||
::sycl::event event;
|
||||
{
|
||||
::sycl::buffer<int, 1> flag_buf(&has_neg_hess, 1);
|
||||
event = qu_.submit([&](::sycl::handler& cgh) {
|
||||
auto flag_buf_acc = flag_buf.get_access<::sycl::access::mode::read_write>(cgh);
|
||||
cgh.parallel_for<>(::sycl::range<1>(::sycl::range<1>(info.num_row_)),
|
||||
[=](::sycl::item<1> pid) {
|
||||
const size_t idx = pid.get_id(0);
|
||||
p_row_indices[idx] = idx;
|
||||
if (gpair_ptr[idx].GetHess() < 0.0f) {
|
||||
AtomicRef<int> has_neg_hess_ref(flag_buf_acc[0]);
|
||||
has_neg_hess_ref.fetch_max(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (has_neg_hess) {
|
||||
size_t max_idx = 0;
|
||||
{
|
||||
::sycl::buffer<size_t, 1> flag_buf(&max_idx, 1);
|
||||
event = qu_.submit([&](::sycl::handler& cgh) {
|
||||
cgh.depends_on(event);
|
||||
auto flag_buf_acc = flag_buf.get_access<::sycl::access::mode::read_write>(cgh);
|
||||
cgh.parallel_for<>(::sycl::range<1>(::sycl::range<1>(info.num_row_)),
|
||||
[=](::sycl::item<1> pid) {
|
||||
const size_t idx = pid.get_id(0);
|
||||
if (gpair_ptr[idx].GetHess() >= 0.0f) {
|
||||
AtomicRef<size_t> max_idx_ref(flag_buf_acc[0]);
|
||||
p_row_indices[max_idx_ref++] = idx;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
row_indices->Resize(&qu_, max_idx, 0, &event);
|
||||
}
|
||||
qu_.wait_and_throw();
|
||||
}
|
||||
}
|
||||
row_set_collection_.Init();
|
||||
}
|
||||
|
||||
template class HistUpdater<float>;
|
||||
template class HistUpdater<double>;
|
||||
|
||||
|
||||
@@ -47,7 +47,19 @@ class HistUpdater {
|
||||
void InitSampling(const USMVector<GradientPair, MemoryType::on_device> &gpair,
|
||||
USMVector<size_t, MemoryType::on_device>* row_indices);
|
||||
|
||||
|
||||
void InitData(Context const * ctx,
|
||||
const common::GHistIndexMatrix& gmat,
|
||||
const USMVector<GradientPair, MemoryType::on_device> &gpair,
|
||||
const DMatrix& fmat,
|
||||
const RegTree& tree);
|
||||
|
||||
// --data fields--
|
||||
size_t sub_group_size_;
|
||||
|
||||
// the internal row sets
|
||||
common::RowSetCollection row_set_collection_;
|
||||
|
||||
const xgboost::tree::TrainParam& param_;
|
||||
TreeEvaluator<GradientSumT> tree_evaluator_;
|
||||
std::unique_ptr<TreeUpdater> pruner_;
|
||||
|
||||
Reference in New Issue
Block a user