Skip to content

Commit

Permalink
CI fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SmirnovEgorRu committed Dec 30, 2019
1 parent d671ea2 commit 57e6a93
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/common/hist_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ void GHistIndexBlockMatrix::Init(const GHistIndexMatrix& gmat,
}
}

/*!
* \brief fill a histogram by zeroes
*/
void InitilizeHistByZeroes(GHistRow hist) {
memset(hist.data(), '\0', hist.size()*sizeof(tree::GradStats));
}

void GHistBuilder::BuildHist(const std::vector<GradientPair>& gpair,
const RowSetCollection::Elem row_indices,
const GHistIndexMatrix& gmat,
Expand Down
30 changes: 17 additions & 13 deletions src/common/hist_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ class GHistIndexBlockMatrix {
*/
using GHistRow = Span<tree::GradStats>;

/*!
* \brief fill a histogram by zeroes
*/
void InitilizeHistByZeroes(GHistRow hist);

/*!
* \brief histogram of gradient statistics for multiple nodes
*/
Expand All @@ -369,9 +374,12 @@ class HistCollection {

// initialize histogram collection
void Init(uint32_t nbins) {
nbins_ = nbins;
if (nbins_ != nbins) {
nbins_ = nbins;
// quite expensive operation, so let's do this only once
data_.clear();
}
row_ptr_.clear();
data_.clear();
}

// create an empty histogram for i-th node
Expand All @@ -382,13 +390,16 @@ class HistCollection {
}
CHECK_EQ(row_ptr_[nid], kMax);

row_ptr_[nid] = data_.size();
data_.resize(data_.size() + nbins_);
row_ptr_[nid] = nbins_ * nid;

if (data_.size() <= nbins_ * (nid + 1)) {
data_.resize(nbins_ * (nid + 1));
}
}

private:
/*! \brief number of all bins over all features */
uint32_t nbins_;
uint32_t nbins_ = 0;

std::vector<tree::GradStats> data_;

Expand Down Expand Up @@ -433,7 +444,7 @@ class HistBuffer {
GHistRow hist = hist_[tid * nodes_ + nid];

if (!hist_was_used_[tid * nodes_ + nid]) {
InitilizeHist(hist);
InitilizeHistByZeroes(hist);
hist_was_used_[tid * nodes_ + nid] = true;
}

Expand All @@ -457,13 +468,6 @@ class HistBuffer {
}

protected:
// fill hist by zeroes
void InitilizeHist(GHistRow hist) {
for (auto& val : hist) {
val = tree::GradStats(0.0f, 0.0f);
}
}

/*! \brief number of bins in each histogram */
size_t nbins_ = 0;
/*! \brief number of threads for parallel computation */
Expand Down
10 changes: 7 additions & 3 deletions src/tree/updater_quantile_hist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,22 @@ void QuantileHistMaker::Builder::SyncHistograms(
builder_monitor_.Start("SyncHistograms");

const bool isDistributed = rabit::IsDistributed();
builder_monitor_.Start("AddHistRow");
for (auto const& node : nodes_for_subtraction_trick_) {
hist_.AddHistRow(node.nid);
}
builder_monitor_.Stop("AddHistRow");

const size_t nbins = gmat.cut.Ptrs().back();
common::BlockedSpace2d space(nodes_for_explicit_hist_build_.size(), [&](size_t node) {
return nbins;
}, 512);
}, 1024);

common::ParallelFor2d(space, [&](size_t node, common::Range1d r) {
const auto entry = nodes_for_explicit_hist_build_[node];
auto this_hist = hist_[entry.nid];
// Merging histograms from each thread into once
common::InitilizeHistByZeroes({this_hist.data() + r.begin(), this_hist.data() + r.end()});
hist_buffer_.ReduceHist(this_hist, node, r.begin(), r.end());

if (!(*p_tree)[entry.nid].IsRoot() && entry.sibling_nid > -1 && !isDistributed) {
Expand Down Expand Up @@ -156,9 +159,8 @@ void QuantileHistMaker::Builder::BuildHistogramsLossGuide(
if (entry.sibling_nid > -1) {
nodes_for_subtraction_trick_.emplace_back(entry.sibling_nid, entry.nid,
p_tree->GetDepth(entry.sibling_nid), 0.0f, 0);

SyncHistograms(starting_index, sync_count, gmat, p_tree);
}
SyncHistograms(starting_index, sync_count, gmat, p_tree);
}

void QuantileHistMaker::Builder::BuildLocalHistograms(
Expand All @@ -172,6 +174,7 @@ void QuantileHistMaker::Builder::BuildLocalHistograms(

hist_buffer_.Reset(this->nthread_, nodes_for_explicit_hist_build_.size());

builder_monitor_.Start("AddHistRow");
size_t node_count = 0;
for (auto const& entry : nodes_for_explicit_hist_build_) {
int nid = entry.nid;
Expand All @@ -180,6 +183,7 @@ void QuantileHistMaker::Builder::BuildLocalHistograms(
node_count++;
}
(*sync_count) = node_count;
builder_monitor_.Stop("AddHistRow");

// create space of size (# rows in each node)
common::BlockedSpace2d space(nodes_for_explicit_hist_build_.size(), [&](size_t node) {
Expand Down

0 comments on commit 57e6a93

Please sign in to comment.