Upgrade clang-tidy on CI. (#5469)
* Correct all clang-tidy errors. * Upgrade clang-tidy to 10 on CI. Co-authored-by: Hyunsu Cho <chohyu01@cs.washington.edu>
This commit is contained in:
@@ -128,7 +128,7 @@ void FeatureInteractionConstraint::Configure(
|
||||
s_sets_ptr_ = dh::ToSpan(d_sets_ptr_);
|
||||
|
||||
d_feature_buffer_storage_.resize(LBitField64::ComputeStorageSize(n_features));
|
||||
feature_buffer_ = dh::ToSpan(d_feature_buffer_storage_);
|
||||
feature_buffer_ = LBitField64{dh::ToSpan(d_feature_buffer_storage_)};
|
||||
|
||||
// --- Initialize result buffers.
|
||||
output_buffer_bits_storage_.resize(LBitField64::ComputeStorageSize(n_features));
|
||||
|
||||
@@ -31,8 +31,6 @@ class FeatureInteractionConstraintHost {
|
||||
// splits_[nid] contains the set of all feature IDs that have been used for
|
||||
// splits in node nid and its parents
|
||||
std::vector< std::unordered_set<bst_feature_t> > splits_;
|
||||
|
||||
std::vector<bst_feature_t> return_buffer;
|
||||
// string passed by user.
|
||||
std::string interaction_constraint_str_;
|
||||
// number of features in DMatrix/Booster
|
||||
|
||||
@@ -153,7 +153,7 @@ ExternalMemoryNoSampling::ExternalMemoryNoSampling(EllpackPageImpl* page,
|
||||
size_t n_rows,
|
||||
const BatchParam& batch_param)
|
||||
: batch_param_(batch_param),
|
||||
page_(new EllpackPageImpl(batch_param.gpu_id, page->cuts_, page->is_dense,
|
||||
page_(new EllpackPageImpl(batch_param.gpu_id, page->Cuts(), page->is_dense,
|
||||
page->row_stride, n_rows)) {}
|
||||
|
||||
GradientBasedSample ExternalMemoryNoSampling::Sample(common::Span<GradientPair> gpair,
|
||||
@@ -201,7 +201,6 @@ GradientBasedSample ExternalMemoryUniformSampling::Sample(common::Span<GradientP
|
||||
|
||||
// Count the sampled rows.
|
||||
size_t sample_rows = thrust::count_if(dh::tbegin(gpair), dh::tend(gpair), IsNonZero());
|
||||
size_t n_rows = dmat->Info().num_row_;
|
||||
|
||||
// Compact gradient pairs.
|
||||
gpair_.resize(sample_rows);
|
||||
@@ -219,7 +218,7 @@ GradientBasedSample ExternalMemoryUniformSampling::Sample(common::Span<GradientP
|
||||
// Create a new ELLPACK page with empty rows.
|
||||
page_.reset(); // Release the device memory first before reallocating
|
||||
page_.reset(new EllpackPageImpl(
|
||||
batch_param_.gpu_id, original_page_->cuts_, original_page_->is_dense,
|
||||
batch_param_.gpu_id, original_page_->Cuts(), original_page_->is_dense,
|
||||
original_page_->row_stride, sample_rows));
|
||||
|
||||
// Compact the ELLPACK pages into the single sample page.
|
||||
@@ -299,7 +298,7 @@ GradientBasedSample ExternalMemoryGradientBasedSampling::Sample(common::Span<Gra
|
||||
|
||||
// Create a new ELLPACK page with empty rows.
|
||||
page_.reset(); // Release the device memory first before reallocating
|
||||
page_.reset(new EllpackPageImpl(batch_param_.gpu_id, original_page_->cuts_,
|
||||
page_.reset(new EllpackPageImpl(batch_param_.gpu_id, original_page_->Cuts(),
|
||||
original_page_->is_dense,
|
||||
original_page_->row_stride, sample_rows));
|
||||
|
||||
|
||||
@@ -64,54 +64,55 @@ void RowPartitioner::SortPosition(common::Span<bst_node_t> position,
|
||||
cub::DeviceScan::ExclusiveSum(temp_storage.data().get(), temp_storage_bytes,
|
||||
in_itr, out_itr, position.size(), stream);
|
||||
}
|
||||
|
||||
RowPartitioner::RowPartitioner(int device_idx, size_t num_rows)
|
||||
: device_idx(device_idx) {
|
||||
dh::safe_cuda(cudaSetDevice(device_idx));
|
||||
ridx_a.resize(num_rows);
|
||||
ridx_b.resize(num_rows);
|
||||
position_a.resize(num_rows);
|
||||
position_b.resize(num_rows);
|
||||
ridx = dh::DoubleBuffer<RowIndexT>{&ridx_a, &ridx_b};
|
||||
position = dh::DoubleBuffer<bst_node_t>{&position_a, &position_b};
|
||||
ridx_segments.emplace_back(Segment(0, num_rows));
|
||||
: device_idx_(device_idx) {
|
||||
dh::safe_cuda(cudaSetDevice(device_idx_));
|
||||
ridx_a_.resize(num_rows);
|
||||
ridx_b_.resize(num_rows);
|
||||
position_a_.resize(num_rows);
|
||||
position_b_.resize(num_rows);
|
||||
ridx_ = dh::DoubleBuffer<RowIndexT>{&ridx_a_, &ridx_b_};
|
||||
position_ = dh::DoubleBuffer<bst_node_t>{&position_a_, &position_b_};
|
||||
ridx_segments_.emplace_back(Segment(0, num_rows));
|
||||
|
||||
thrust::sequence(
|
||||
thrust::device_pointer_cast(ridx.CurrentSpan().data()),
|
||||
thrust::device_pointer_cast(ridx.CurrentSpan().data() + ridx.Size()));
|
||||
thrust::device_pointer_cast(ridx_.CurrentSpan().data()),
|
||||
thrust::device_pointer_cast(ridx_.CurrentSpan().data() + ridx_.Size()));
|
||||
thrust::fill(
|
||||
thrust::device_pointer_cast(position.Current()),
|
||||
thrust::device_pointer_cast(position.Current() + position.Size()), 0);
|
||||
left_counts.resize(256);
|
||||
thrust::fill(left_counts.begin(), left_counts.end(), 0);
|
||||
streams.resize(2);
|
||||
for (auto& stream : streams) {
|
||||
thrust::device_pointer_cast(position_.Current()),
|
||||
thrust::device_pointer_cast(position_.Current() + position_.Size()), 0);
|
||||
left_counts_.resize(256);
|
||||
thrust::fill(left_counts_.begin(), left_counts_.end(), 0);
|
||||
streams_.resize(2);
|
||||
for (auto& stream : streams_) {
|
||||
dh::safe_cuda(cudaStreamCreate(&stream));
|
||||
}
|
||||
}
|
||||
RowPartitioner::~RowPartitioner() {
|
||||
dh::safe_cuda(cudaSetDevice(device_idx));
|
||||
for (auto& stream : streams) {
|
||||
dh::safe_cuda(cudaSetDevice(device_idx_));
|
||||
for (auto& stream : streams_) {
|
||||
dh::safe_cuda(cudaStreamDestroy(stream));
|
||||
}
|
||||
}
|
||||
|
||||
common::Span<const RowPartitioner::RowIndexT> RowPartitioner::GetRows(
|
||||
bst_node_t nidx) {
|
||||
auto segment = ridx_segments.at(nidx);
|
||||
auto segment = ridx_segments_.at(nidx);
|
||||
// Return empty span here as a valid result
|
||||
// Will error if we try to construct a span from a pointer with size 0
|
||||
if (segment.Size() == 0) {
|
||||
return common::Span<const RowPartitioner::RowIndexT>();
|
||||
}
|
||||
return ridx.CurrentSpan().subspan(segment.begin, segment.Size());
|
||||
return ridx_.CurrentSpan().subspan(segment.begin, segment.Size());
|
||||
}
|
||||
|
||||
common::Span<const RowPartitioner::RowIndexT> RowPartitioner::GetRows() {
|
||||
return ridx.CurrentSpan();
|
||||
return ridx_.CurrentSpan();
|
||||
}
|
||||
|
||||
common::Span<const bst_node_t> RowPartitioner::GetPosition() {
|
||||
return position.CurrentSpan();
|
||||
return position_.CurrentSpan();
|
||||
}
|
||||
std::vector<RowPartitioner::RowIndexT> RowPartitioner::GetRowsHost(
|
||||
bst_node_t nidx) {
|
||||
@@ -135,22 +136,22 @@ void RowPartitioner::SortPositionAndCopy(const Segment& segment,
|
||||
cudaStream_t stream) {
|
||||
SortPosition(
|
||||
// position_in
|
||||
common::Span<bst_node_t>(position.Current() + segment.begin,
|
||||
common::Span<bst_node_t>(position_.Current() + segment.begin,
|
||||
segment.Size()),
|
||||
// position_out
|
||||
common::Span<bst_node_t>(position.other() + segment.begin,
|
||||
segment.Size()),
|
||||
common::Span<bst_node_t>(position_.Other() + segment.begin,
|
||||
segment.Size()),
|
||||
// row index in
|
||||
common::Span<RowIndexT>(ridx.Current() + segment.begin, segment.Size()),
|
||||
common::Span<RowIndexT>(ridx_.Current() + segment.begin, segment.Size()),
|
||||
// row index out
|
||||
common::Span<RowIndexT>(ridx.other() + segment.begin, segment.Size()),
|
||||
common::Span<RowIndexT>(ridx_.Other() + segment.begin, segment.Size()),
|
||||
left_nidx, right_nidx, d_left_count, stream);
|
||||
// Copy back key/value
|
||||
const auto d_position_current = position.Current() + segment.begin;
|
||||
const auto d_position_other = position.other() + segment.begin;
|
||||
const auto d_ridx_current = ridx.Current() + segment.begin;
|
||||
const auto d_ridx_other = ridx.other() + segment.begin;
|
||||
dh::LaunchN(device_idx, segment.Size(), stream, [=] __device__(size_t idx) {
|
||||
const auto d_position_current = position_.Current() + segment.begin;
|
||||
const auto d_position_other = position_.Other() + segment.begin;
|
||||
const auto d_ridx_current = ridx_.Current() + segment.begin;
|
||||
const auto d_ridx_other = ridx_.Other() + segment.begin;
|
||||
dh::LaunchN(device_idx_, segment.Size(), stream, [=] __device__(size_t idx) {
|
||||
d_position_current[idx] = d_position_other[idx];
|
||||
d_ridx_current[idx] = d_ridx_other[idx];
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ class RowPartitioner {
|
||||
static constexpr bst_node_t kIgnoredTreePosition = -1;
|
||||
|
||||
private:
|
||||
int device_idx;
|
||||
int device_idx_;
|
||||
/*! \brief In here if you want to find the rows belong to a node nid, first you need to
|
||||
* get the indices segment from ridx_segments[nid], then get the row index that
|
||||
* represents position of row in input data X. `RowPartitioner::GetRows` would be a
|
||||
@@ -45,22 +45,22 @@ class RowPartitioner {
|
||||
* node id -> segment -> indices of rows belonging to node
|
||||
*/
|
||||
/*! \brief Range of row index for each node, pointers into ridx below. */
|
||||
std::vector<Segment> ridx_segments;
|
||||
dh::caching_device_vector<RowIndexT> ridx_a;
|
||||
dh::caching_device_vector<RowIndexT> ridx_b;
|
||||
dh::caching_device_vector<bst_node_t> position_a;
|
||||
dh::caching_device_vector<bst_node_t> position_b;
|
||||
std::vector<Segment> ridx_segments_;
|
||||
dh::caching_device_vector<RowIndexT> ridx_a_;
|
||||
dh::caching_device_vector<RowIndexT> ridx_b_;
|
||||
dh::caching_device_vector<bst_node_t> position_a_;
|
||||
dh::caching_device_vector<bst_node_t> position_b_;
|
||||
/*! \brief mapping for node id -> rows.
|
||||
* This looks like:
|
||||
* node id | 1 | 2 |
|
||||
* rows idx | 3, 5, 1 | 13, 31 |
|
||||
*/
|
||||
dh::DoubleBuffer<RowIndexT> ridx;
|
||||
dh::DoubleBuffer<RowIndexT> ridx_;
|
||||
/*! \brief mapping for row -> node id. */
|
||||
dh::DoubleBuffer<bst_node_t> position;
|
||||
dh::DoubleBuffer<bst_node_t> position_;
|
||||
dh::caching_device_vector<int64_t>
|
||||
left_counts; // Useful to keep a bunch of zeroed memory for sort position
|
||||
std::vector<cudaStream_t> streams;
|
||||
left_counts_; // Useful to keep a bunch of zeroed memory for sort position
|
||||
std::vector<cudaStream_t> streams_;
|
||||
|
||||
public:
|
||||
RowPartitioner(int device_idx, size_t num_rows);
|
||||
@@ -108,19 +108,19 @@ class RowPartitioner {
|
||||
template <typename UpdatePositionOpT>
|
||||
void UpdatePosition(bst_node_t nidx, bst_node_t left_nidx,
|
||||
bst_node_t right_nidx, UpdatePositionOpT op) {
|
||||
dh::safe_cuda(cudaSetDevice(device_idx));
|
||||
Segment segment = ridx_segments.at(nidx); // rows belongs to node nidx
|
||||
auto d_ridx = ridx.CurrentSpan();
|
||||
auto d_position = position.CurrentSpan();
|
||||
if (left_counts.size() <= nidx) {
|
||||
left_counts.resize((nidx * 2) + 1);
|
||||
thrust::fill(left_counts.begin(), left_counts.end(), 0);
|
||||
dh::safe_cuda(cudaSetDevice(device_idx_));
|
||||
Segment segment = ridx_segments_.at(nidx); // rows belongs to node nidx
|
||||
auto d_ridx = ridx_.CurrentSpan();
|
||||
auto d_position = position_.CurrentSpan();
|
||||
if (left_counts_.size() <= nidx) {
|
||||
left_counts_.resize((nidx * 2) + 1);
|
||||
thrust::fill(left_counts_.begin(), left_counts_.end(), 0);
|
||||
}
|
||||
// Now we divide the row segment into left and right node.
|
||||
|
||||
int64_t* d_left_count = left_counts.data().get() + nidx;
|
||||
int64_t* d_left_count = left_counts_.data().get() + nidx;
|
||||
// Launch 1 thread for each row
|
||||
dh::LaunchN<1, 128>(device_idx, segment.Size(), [=] __device__(size_t idx) {
|
||||
dh::LaunchN<1, 128>(device_idx_, segment.Size(), [=] __device__(size_t idx) {
|
||||
// LaunchN starts from zero, so we restore the row index by adding segment.begin
|
||||
idx += segment.begin;
|
||||
RowIndexT ridx = d_ridx[idx];
|
||||
@@ -132,19 +132,19 @@ class RowPartitioner {
|
||||
// Overlap device to host memory copy (left_count) with sort
|
||||
int64_t left_count;
|
||||
dh::safe_cuda(cudaMemcpyAsync(&left_count, d_left_count, sizeof(int64_t),
|
||||
cudaMemcpyDeviceToHost, streams[0]));
|
||||
cudaMemcpyDeviceToHost, streams_[0]));
|
||||
|
||||
SortPositionAndCopy(segment, left_nidx, right_nidx, d_left_count,
|
||||
streams[1]);
|
||||
streams_[1]);
|
||||
|
||||
dh::safe_cuda(cudaStreamSynchronize(streams[0]));
|
||||
dh::safe_cuda(cudaStreamSynchronize(streams_[0]));
|
||||
CHECK_LE(left_count, segment.Size());
|
||||
CHECK_GE(left_count, 0);
|
||||
ridx_segments.resize(std::max(int(ridx_segments.size()),
|
||||
std::max(left_nidx, right_nidx) + 1));
|
||||
ridx_segments[left_nidx] =
|
||||
ridx_segments_.resize(std::max(static_cast<bst_node_t>(ridx_segments_.size()),
|
||||
std::max(left_nidx, right_nidx) + 1));
|
||||
ridx_segments_[left_nidx] =
|
||||
Segment(segment.begin, segment.begin + left_count);
|
||||
ridx_segments[right_nidx] =
|
||||
ridx_segments_[right_nidx] =
|
||||
Segment(segment.begin + left_count, segment.end);
|
||||
}
|
||||
|
||||
@@ -159,9 +159,9 @@ class RowPartitioner {
|
||||
*/
|
||||
template <typename FinalisePositionOpT>
|
||||
void FinalisePosition(FinalisePositionOpT op) {
|
||||
auto d_position = position.Current();
|
||||
const auto d_ridx = ridx.Current();
|
||||
dh::LaunchN(device_idx, position.Size(), [=] __device__(size_t idx) {
|
||||
auto d_position = position_.Current();
|
||||
const auto d_ridx = ridx_.Current();
|
||||
dh::LaunchN(device_idx_, position_.Size(), [=] __device__(size_t idx) {
|
||||
auto position = d_position[idx];
|
||||
RowIndexT ridx = d_ridx[idx];
|
||||
bst_node_t new_position = op(ridx, position);
|
||||
@@ -189,10 +189,10 @@ class RowPartitioner {
|
||||
/** \brief Used to demarcate a contiguous set of row indices associated with
|
||||
* some tree node. */
|
||||
struct Segment {
|
||||
size_t begin;
|
||||
size_t end;
|
||||
size_t begin { 0 };
|
||||
size_t end { 0 };
|
||||
|
||||
Segment() : begin{0}, end{0} {}
|
||||
Segment() = default;
|
||||
|
||||
Segment(size_t begin, size_t end) : begin(begin), end(end) {
|
||||
CHECK_GE(end, begin);
|
||||
|
||||
@@ -319,9 +319,9 @@ XGBOOST_DEVICE inline float CalcWeight(const TrainingParams &p, GpairT sum_grad)
|
||||
/*! \brief core statistics used for tree construction */
|
||||
struct XGBOOST_ALIGNAS(16) GradStats {
|
||||
/*! \brief sum gradient statistics */
|
||||
double sum_grad;
|
||||
double sum_grad { 0 };
|
||||
/*! \brief sum hessian statistics */
|
||||
double sum_hess;
|
||||
double sum_hess { 0 };
|
||||
|
||||
public:
|
||||
XGBOOST_DEVICE double GetGrad() const { return sum_grad; }
|
||||
@@ -332,7 +332,7 @@ struct XGBOOST_ALIGNAS(16) GradStats {
|
||||
return os;
|
||||
}
|
||||
|
||||
XGBOOST_DEVICE GradStats() : sum_grad{0}, sum_hess{0} {
|
||||
XGBOOST_DEVICE GradStats() {
|
||||
static_assert(sizeof(GradStats) == 16,
|
||||
"Size of GradStats is not 16 bytes.");
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class TreeGenerator {
|
||||
auto const split_index = tree[nid].SplitIndex();
|
||||
std::string result;
|
||||
if (split_index < fmap_.Size()) {
|
||||
switch (fmap_.type(split_index)) {
|
||||
switch (fmap_.TypeOf(split_index)) {
|
||||
case FeatureMap::kIndicator: {
|
||||
result = this->Indicator(tree, nid, depth);
|
||||
break;
|
||||
@@ -536,7 +536,7 @@ class GraphvizGenerator : public TreeGenerator {
|
||||
" {nid} [ label=\"{fname}{<}{cond}\" {params}]\n";
|
||||
|
||||
// Indicator only has fname.
|
||||
bool has_less = (split >= fmap_.Size()) || fmap_.type(split) != FeatureMap::kIndicator;
|
||||
bool has_less = (split >= fmap_.Size()) || fmap_.TypeOf(split) != FeatureMap::kIndicator;
|
||||
std::string result = SuperT::Match(kNodeTemplate, {
|
||||
{"{nid}", std::to_string(nid)},
|
||||
{"{fname}", split < fmap_.Size() ? fmap_.Name(split) :
|
||||
@@ -674,7 +674,7 @@ void RegTree::Save(dmlc::Stream* fo) const {
|
||||
}
|
||||
|
||||
void RegTree::LoadModel(Json const& in) {
|
||||
fromJson(in["tree_param"], ¶m);
|
||||
FromJson(in["tree_param"], ¶m);
|
||||
auto n_nodes = param.num_nodes;
|
||||
CHECK_NE(n_nodes, 0);
|
||||
// stats
|
||||
@@ -742,7 +742,7 @@ void RegTree::SaveModel(Json* p_out) const {
|
||||
auto& out = *p_out;
|
||||
CHECK_EQ(param.num_nodes, static_cast<int>(nodes_.size()));
|
||||
CHECK_EQ(param.num_nodes, static_cast<int>(stats_.size()));
|
||||
out["tree_param"] = toJson(param);
|
||||
out["tree_param"] = ToJson(param);
|
||||
CHECK_EQ(get<String>(out["tree_param"]["num_nodes"]), std::to_string(param.num_nodes));
|
||||
using I = Integer::Int;
|
||||
auto n_nodes = param.num_nodes;
|
||||
|
||||
@@ -40,11 +40,11 @@ class BaseMaker: public TreeUpdater {
|
||||
|
||||
void LoadConfig(Json const& in) override {
|
||||
auto const& config = get<Object const>(in);
|
||||
fromJson(config.at("train_param"), &this->param_);
|
||||
FromJson(config.at("train_param"), &this->param_);
|
||||
}
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["train_param"] = toJson(param_);
|
||||
out["train_param"] = ToJson(param_);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -64,13 +64,13 @@ class ColMaker: public TreeUpdater {
|
||||
|
||||
void LoadConfig(Json const& in) override {
|
||||
auto const& config = get<Object const>(in);
|
||||
fromJson(config.at("train_param"), &this->param_);
|
||||
fromJson(config.at("colmaker_train_param"), &this->colmaker_param_);
|
||||
FromJson(config.at("train_param"), &this->param_);
|
||||
FromJson(config.at("colmaker_train_param"), &this->colmaker_param_);
|
||||
}
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["train_param"] = toJson(param_);
|
||||
out["colmaker_train_param"] = toJson(colmaker_param_);
|
||||
out["train_param"] = ToJson(param_);
|
||||
out["colmaker_train_param"] = ToJson(colmaker_param_);
|
||||
}
|
||||
|
||||
char const* Name() const override {
|
||||
@@ -134,23 +134,23 @@ class ColMaker: public TreeUpdater {
|
||||
/*! \brief statistics of data */
|
||||
GradStats stats;
|
||||
/*! \brief last feature value scanned */
|
||||
bst_float last_fvalue;
|
||||
bst_float last_fvalue { 0 };
|
||||
/*! \brief current best solution */
|
||||
SplitEntry best;
|
||||
// constructor
|
||||
ThreadEntry() : last_fvalue{0} {}
|
||||
ThreadEntry() = default;
|
||||
};
|
||||
struct NodeEntry {
|
||||
/*! \brief statics for node entry */
|
||||
GradStats stats;
|
||||
/*! \brief loss of this node, without split */
|
||||
bst_float root_gain;
|
||||
bst_float root_gain { 0.0f };
|
||||
/*! \brief weight calculated related to current data */
|
||||
bst_float weight;
|
||||
bst_float weight { 0.0f };
|
||||
/*! \brief current best solution */
|
||||
SplitEntry best;
|
||||
// constructor
|
||||
NodeEntry() : root_gain{0.0f}, weight{0.0f} {}
|
||||
NodeEntry() = default;
|
||||
};
|
||||
// actual builder that runs the algorithm
|
||||
class Builder {
|
||||
|
||||
@@ -53,16 +53,15 @@ enum DefaultDirection {
|
||||
};
|
||||
|
||||
struct DeviceSplitCandidate {
|
||||
float loss_chg;
|
||||
DefaultDirection dir;
|
||||
int findex;
|
||||
float fvalue;
|
||||
float loss_chg {-FLT_MAX};
|
||||
DefaultDirection dir {kLeftDir};
|
||||
int findex {-1};
|
||||
float fvalue {0};
|
||||
|
||||
GradientPair left_sum;
|
||||
GradientPair right_sum;
|
||||
|
||||
XGBOOST_DEVICE DeviceSplitCandidate()
|
||||
: loss_chg(-FLT_MAX), dir(kLeftDir), fvalue(0), findex(-1) {}
|
||||
XGBOOST_DEVICE DeviceSplitCandidate() {} // NOLINT
|
||||
|
||||
template <typename ParamT>
|
||||
XGBOOST_DEVICE void Update(const DeviceSplitCandidate& other,
|
||||
@@ -105,7 +104,7 @@ struct DeviceSplitCandidate {
|
||||
|
||||
struct DeviceSplitCandidateReduceOp {
|
||||
GPUTrainingParam param;
|
||||
DeviceSplitCandidateReduceOp(GPUTrainingParam param) : param(param) {}
|
||||
explicit DeviceSplitCandidateReduceOp(GPUTrainingParam param) : param(std::move(param)) {}
|
||||
XGBOOST_DEVICE DeviceSplitCandidate operator()(
|
||||
const DeviceSplitCandidate& a, const DeviceSplitCandidate& b) const {
|
||||
DeviceSplitCandidate best;
|
||||
@@ -117,38 +116,26 @@ struct DeviceSplitCandidateReduceOp {
|
||||
|
||||
struct DeviceNodeStats {
|
||||
GradientPair sum_gradients;
|
||||
float root_gain;
|
||||
float weight;
|
||||
float root_gain {-FLT_MAX};
|
||||
float weight {-FLT_MAX};
|
||||
|
||||
/** default direction for missing values */
|
||||
DefaultDirection dir;
|
||||
DefaultDirection dir {kLeftDir};
|
||||
/** threshold value for comparison */
|
||||
float fvalue;
|
||||
float fvalue {0.0f};
|
||||
GradientPair left_sum;
|
||||
GradientPair right_sum;
|
||||
/** \brief The feature index. */
|
||||
int fidx;
|
||||
int fidx{kUnusedNode};
|
||||
/** node id (used as key for reduce/scan) */
|
||||
NodeIdT idx;
|
||||
NodeIdT idx{kUnusedNode};
|
||||
|
||||
HOST_DEV_INLINE DeviceNodeStats()
|
||||
: sum_gradients(),
|
||||
root_gain(-FLT_MAX),
|
||||
weight(-FLT_MAX),
|
||||
dir(kLeftDir),
|
||||
fvalue(0.f),
|
||||
left_sum(),
|
||||
right_sum(),
|
||||
fidx(kUnusedNode),
|
||||
idx(kUnusedNode) {}
|
||||
XGBOOST_DEVICE DeviceNodeStats() {} // NOLINT
|
||||
|
||||
template <typename ParamT>
|
||||
HOST_DEV_INLINE DeviceNodeStats(GradientPair sum_gradients, NodeIdT nidx,
|
||||
const ParamT& param)
|
||||
: sum_gradients(sum_gradients),
|
||||
dir(kLeftDir),
|
||||
fvalue(0.f),
|
||||
fidx(kUnusedNode),
|
||||
idx(nidx) {
|
||||
this->root_gain =
|
||||
CalcGain(param, sum_gradients.GetGrad(), sum_gradients.GetHess());
|
||||
|
||||
@@ -628,7 +628,7 @@ struct GPUHistMakerDevice {
|
||||
auto d_node_hist_histogram = hist.GetNodeHistogram(nidx_histogram);
|
||||
auto d_node_hist_subtraction = hist.GetNodeHistogram(nidx_subtraction);
|
||||
|
||||
dh::LaunchN(device_id, page->cuts_.TotalBins(), [=] __device__(size_t idx) {
|
||||
dh::LaunchN(device_id, page->Cuts().TotalBins(), [=] __device__(size_t idx) {
|
||||
d_node_hist_subtraction[idx] =
|
||||
d_node_hist_parent[idx] - d_node_hist_histogram[idx];
|
||||
});
|
||||
@@ -756,7 +756,7 @@ struct GPUHistMakerDevice {
|
||||
reducer->AllReduceSum(
|
||||
reinterpret_cast<typename GradientSumT::ValueT*>(d_node_hist),
|
||||
reinterpret_cast<typename GradientSumT::ValueT*>(d_node_hist),
|
||||
page->cuts_.TotalBins() * (sizeof(GradientSumT) / sizeof(typename GradientSumT::ValueT)));
|
||||
page->Cuts().TotalBins() * (sizeof(GradientSumT) / sizeof(typename GradientSumT::ValueT)));
|
||||
reducer->Synchronize();
|
||||
|
||||
monitor.StopCuda("AllReduce");
|
||||
@@ -945,20 +945,20 @@ inline void GPUHistMakerDevice<GradientSumT>::InitHistogram() {
|
||||
// check if we can use shared memory for building histograms
|
||||
// (assuming atleast we need 2 CTAs per SM to maintain decent latency
|
||||
// hiding)
|
||||
auto histogram_size = sizeof(GradientSumT) * page->cuts_.TotalBins();
|
||||
auto histogram_size = sizeof(GradientSumT) * page->Cuts().TotalBins();
|
||||
auto max_smem = dh::MaxSharedMemory(device_id);
|
||||
if (histogram_size <= max_smem) {
|
||||
use_shared_memory_histograms = true;
|
||||
}
|
||||
|
||||
// Init histogram
|
||||
hist.Init(device_id, page->cuts_.TotalBins());
|
||||
hist.Init(device_id, page->Cuts().TotalBins());
|
||||
}
|
||||
|
||||
template <typename GradientSumT>
|
||||
class GPUHistMakerSpecialised {
|
||||
public:
|
||||
GPUHistMakerSpecialised() : initialised_{false}, p_last_fmat_{nullptr} {}
|
||||
GPUHistMakerSpecialised() = default;
|
||||
void Configure(const Args& args, GenericParameter const* generic_param) {
|
||||
param_.UpdateAllowUnknown(args);
|
||||
generic_param_ = generic_param;
|
||||
@@ -1002,7 +1002,7 @@ class GPUHistMakerSpecialised {
|
||||
device_ = generic_param_->gpu_id;
|
||||
CHECK_GE(device_, 0) << "Must have at least one device";
|
||||
info_ = &dmat->Info();
|
||||
reducer_.Init({device_});
|
||||
reducer_.Init({device_}); // NOLINT
|
||||
|
||||
// Synchronise the column sampling seed
|
||||
uint32_t column_sampling_seed = common::GlobalRandom()();
|
||||
@@ -1083,14 +1083,14 @@ class GPUHistMakerSpecialised {
|
||||
std::unique_ptr<GPUHistMakerDevice<GradientSumT>> maker; // NOLINT
|
||||
|
||||
private:
|
||||
bool initialised_;
|
||||
bool initialised_ { false };
|
||||
|
||||
GPUHistMakerTrainParam hist_maker_param_;
|
||||
GenericParameter const* generic_param_;
|
||||
|
||||
dh::AllReducer reducer_;
|
||||
|
||||
DMatrix* p_last_fmat_;
|
||||
DMatrix* p_last_fmat_ { nullptr };
|
||||
int device_{-1};
|
||||
|
||||
common::Monitor monitor_;
|
||||
@@ -1123,22 +1123,22 @@ class GPUHistMaker : public TreeUpdater {
|
||||
|
||||
void LoadConfig(Json const& in) override {
|
||||
auto const& config = get<Object const>(in);
|
||||
fromJson(config.at("gpu_hist_train_param"), &this->hist_maker_param_);
|
||||
FromJson(config.at("gpu_hist_train_param"), &this->hist_maker_param_);
|
||||
if (hist_maker_param_.single_precision_histogram) {
|
||||
float_maker_.reset(new GPUHistMakerSpecialised<GradientPair>());
|
||||
fromJson(config.at("train_param"), &float_maker_->param_);
|
||||
FromJson(config.at("train_param"), &float_maker_->param_);
|
||||
} else {
|
||||
double_maker_.reset(new GPUHistMakerSpecialised<GradientPairPrecise>());
|
||||
fromJson(config.at("train_param"), &double_maker_->param_);
|
||||
FromJson(config.at("train_param"), &double_maker_->param_);
|
||||
}
|
||||
}
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["gpu_hist_train_param"] = toJson(hist_maker_param_);
|
||||
out["gpu_hist_train_param"] = ToJson(hist_maker_param_);
|
||||
if (hist_maker_param_.single_precision_histogram) {
|
||||
out["train_param"] = toJson(float_maker_->param_);
|
||||
out["train_param"] = ToJson(float_maker_->param_);
|
||||
} else {
|
||||
out["train_param"] = toJson(double_maker_->param_);
|
||||
out["train_param"] = ToJson(double_maker_->param_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ class TreePruner: public TreeUpdater {
|
||||
|
||||
void LoadConfig(Json const& in) override {
|
||||
auto const& config = get<Object const>(in);
|
||||
fromJson(config.at("train_param"), &this->param_);
|
||||
FromJson(config.at("train_param"), &this->param_);
|
||||
}
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["train_param"] = toJson(param_);
|
||||
out["train_param"] = ToJson(param_);
|
||||
}
|
||||
bool CanModifyTree() const override {
|
||||
return true;
|
||||
|
||||
@@ -565,7 +565,7 @@ void QuantileHistMaker::Builder::InitData(const GHistIndexMatrix& gmat,
|
||||
}
|
||||
hist_builder_ = GHistBuilder(this->nthread_, nbins);
|
||||
|
||||
std::vector<size_t>& row_indices = row_set_collection_.row_indices_;
|
||||
std::vector<size_t>& row_indices = *row_set_collection_.Data();
|
||||
row_indices.resize(info.num_row_);
|
||||
auto* p_row_indices = row_indices.data();
|
||||
// mark subsample and build list of member rows
|
||||
@@ -978,15 +978,15 @@ void QuantileHistMaker::Builder::ApplySplit(const std::vector<ExpandEntry> nodes
|
||||
common::ParallelFor2d(space, this->nthread_, [&](size_t node_in_set, common::Range1d r) {
|
||||
const int32_t nid = nodes[node_in_set].nid;
|
||||
switch (column_matrix.GetTypeSize()) {
|
||||
case common::UINT8_BINS_TYPE_SIZE:
|
||||
case common::kUint8BinsTypeSize:
|
||||
PartitionKernel<uint8_t>(node_in_set, nid, r,
|
||||
split_conditions[node_in_set], column_matrix, *p_tree);
|
||||
break;
|
||||
case common::UINT16_BINS_TYPE_SIZE:
|
||||
case common::kUint16BinsTypeSize:
|
||||
PartitionKernel<uint16_t>(node_in_set, nid, r,
|
||||
split_conditions[node_in_set], column_matrix, *p_tree);
|
||||
break;
|
||||
case common::UINT32_BINS_TYPE_SIZE:
|
||||
case common::kUint32BinsTypeSize:
|
||||
PartitionKernel<uint32_t>(node_in_set, nid, r,
|
||||
split_conditions[node_in_set], column_matrix, *p_tree);
|
||||
break;
|
||||
|
||||
@@ -81,7 +81,7 @@ using xgboost::common::Column;
|
||||
/*! \brief construct a tree using quantized feature values */
|
||||
class QuantileHistMaker: public TreeUpdater {
|
||||
public:
|
||||
QuantileHistMaker() {}
|
||||
QuantileHistMaker() = default;
|
||||
void Configure(const Args& args) override;
|
||||
|
||||
void Update(HostDeviceVector<GradientPair>* gpair,
|
||||
@@ -93,11 +93,11 @@ class QuantileHistMaker: public TreeUpdater {
|
||||
|
||||
void LoadConfig(Json const& in) override {
|
||||
auto const& config = get<Object const>(in);
|
||||
fromJson(config.at("train_param"), &this->param_);
|
||||
FromJson(config.at("train_param"), &this->param_);
|
||||
}
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["train_param"] = toJson(param_);
|
||||
out["train_param"] = ToJson(param_);
|
||||
}
|
||||
|
||||
char const* Name() const override {
|
||||
@@ -141,7 +141,8 @@ class QuantileHistMaker: public TreeUpdater {
|
||||
FeatureInteractionConstraintHost int_constraints_,
|
||||
DMatrix const* fmat)
|
||||
: param_(param), pruner_(std::move(pruner)),
|
||||
spliteval_(std::move(spliteval)), interaction_constraints_{int_constraints_},
|
||||
spliteval_(std::move(spliteval)),
|
||||
interaction_constraints_{std::move(int_constraints_)},
|
||||
p_last_tree_(nullptr), p_last_fmat_(fmat) {
|
||||
builder_monitor_.Init("Quantile::Builder");
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ class TreeRefresher: public TreeUpdater {
|
||||
}
|
||||
void LoadConfig(Json const& in) override {
|
||||
auto const& config = get<Object const>(in);
|
||||
fromJson(config.at("train_param"), &this->param_);
|
||||
FromJson(config.at("train_param"), &this->param_);
|
||||
}
|
||||
void SaveConfig(Json* p_out) const override {
|
||||
auto& out = *p_out;
|
||||
out["train_param"] = toJson(param_);
|
||||
out["train_param"] = ToJson(param_);
|
||||
}
|
||||
char const* Name() const override {
|
||||
return "refresh";
|
||||
|
||||
@@ -81,13 +81,13 @@ class SketchMaker: public BaseMaker {
|
||||
// statistics needed in the gradient calculation
|
||||
struct SKStats {
|
||||
/*! \brief sum of all positive gradient */
|
||||
double pos_grad;
|
||||
double pos_grad { 0 };
|
||||
/*! \brief sum of all negative gradient */
|
||||
double neg_grad;
|
||||
double neg_grad { 0 };
|
||||
/*! \brief sum of hessian statistics */
|
||||
double sum_hess;
|
||||
double sum_hess { 0 };
|
||||
|
||||
SKStats() : pos_grad{0}, neg_grad{0}, sum_hess{0} {}
|
||||
SKStats() = default;
|
||||
|
||||
// accumulate statistics
|
||||
void Add(const GradientPair& gpair) {
|
||||
|
||||
Reference in New Issue
Block a user