-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sycl] add loss guided hist building (#10251)
Co-authored-by: Dmitry Razdoburdin <>
- Loading branch information
1 parent
9b46505
commit f588252
Showing
7 changed files
with
459 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*! | ||
* Copyright 2017-2024 by Contributors | ||
* \file hist_row_adder.h | ||
*/ | ||
#ifndef PLUGIN_SYCL_TREE_HIST_ROW_ADDER_H_ | ||
#define PLUGIN_SYCL_TREE_HIST_ROW_ADDER_H_ | ||
|
||
#include <vector> | ||
#include <algorithm> | ||
|
||
namespace xgboost { | ||
namespace sycl { | ||
namespace tree { | ||
|
||
template <typename GradientSumT> | ||
class HistRowsAdder { | ||
public: | ||
virtual void AddHistRows(HistUpdater<GradientSumT>* builder, | ||
std::vector<int>* sync_ids, RegTree *p_tree) = 0; | ||
virtual ~HistRowsAdder() = default; | ||
}; | ||
|
||
template <typename GradientSumT> | ||
class BatchHistRowsAdder: public HistRowsAdder<GradientSumT> { | ||
public: | ||
void AddHistRows(HistUpdater<GradientSumT>* builder, | ||
std::vector<int>* sync_ids, RegTree *p_tree) override { | ||
builder->builder_monitor_.Start("AddHistRows"); | ||
|
||
for (auto const& entry : builder->nodes_for_explicit_hist_build_) { | ||
int nid = entry.nid; | ||
auto event = builder->hist_.AddHistRow(nid); | ||
} | ||
for (auto const& node : builder->nodes_for_subtraction_trick_) { | ||
auto event = builder->hist_.AddHistRow(node.nid); | ||
} | ||
|
||
builder->builder_monitor_.Stop("AddHistRows"); | ||
} | ||
}; | ||
|
||
} // namespace tree | ||
} // namespace sycl | ||
} // namespace xgboost | ||
|
||
#endif // PLUGIN_SYCL_TREE_HIST_ROW_ADDER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*! | ||
* Copyright 2017-2024 by Contributors | ||
* \file hist_synchronizer.h | ||
*/ | ||
#ifndef PLUGIN_SYCL_TREE_HIST_SYNCHRONIZER_H_ | ||
#define PLUGIN_SYCL_TREE_HIST_SYNCHRONIZER_H_ | ||
|
||
#include <vector> | ||
|
||
#include "../common/hist_util.h" | ||
#include "expand_entry.h" | ||
|
||
namespace xgboost { | ||
namespace sycl { | ||
namespace tree { | ||
|
||
template <typename GradientSumT> | ||
class HistUpdater; | ||
|
||
template <typename GradientSumT> | ||
class HistSynchronizer { | ||
public: | ||
virtual void SyncHistograms(HistUpdater<GradientSumT>* builder, | ||
const std::vector<int>& sync_ids, | ||
RegTree *p_tree) = 0; | ||
virtual ~HistSynchronizer() = default; | ||
}; | ||
|
||
template <typename GradientSumT> | ||
class BatchHistSynchronizer: public HistSynchronizer<GradientSumT> { | ||
public: | ||
void SyncHistograms(HistUpdater<GradientSumT>* builder, | ||
const std::vector<int>& sync_ids, | ||
RegTree *p_tree) override { | ||
builder->builder_monitor_.Start("SyncHistograms"); | ||
const size_t nbins = builder->hist_builder_.GetNumBins(); | ||
|
||
hist_sync_events_.resize(builder->nodes_for_explicit_hist_build_.size()); | ||
for (int i = 0; i < builder->nodes_for_explicit_hist_build_.size(); i++) { | ||
const auto entry = builder->nodes_for_explicit_hist_build_[i]; | ||
auto& this_hist = builder->hist_[entry.nid]; | ||
|
||
if (!(*p_tree)[entry.nid].IsRoot()) { | ||
const size_t parent_id = (*p_tree)[entry.nid].Parent(); | ||
auto& parent_hist = builder->hist_[parent_id]; | ||
auto& sibling_hist = builder->hist_[entry.GetSiblingId(p_tree, parent_id)]; | ||
hist_sync_events_[i] = common::SubtractionHist(builder->qu_, &sibling_hist, parent_hist, | ||
this_hist, nbins, ::sycl::event()); | ||
} | ||
} | ||
builder->qu_.wait_and_throw(); | ||
|
||
builder->builder_monitor_.Stop("SyncHistograms"); | ||
} | ||
|
||
std::vector<::sycl::event> GetEvents() const { | ||
return hist_sync_events_; | ||
} | ||
|
||
private: | ||
std::vector<::sycl::event> hist_sync_events_; | ||
}; | ||
|
||
} // namespace tree | ||
} // namespace sycl | ||
} // namespace xgboost | ||
|
||
#endif // PLUGIN_SYCL_TREE_HIST_SYNCHRONIZER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.