Skip to content

Commit

Permalink
Fix Histogram allocation.
Browse files Browse the repository at this point in the history
nidx_map is cleared after `Reset`, but histogram data size isn't changed hence
histogram recycling is used in later iterations.  After a reset(building new
tree), newly allocated node will start from 0, while recycling always choose
the node with smallest index, which happens to be our newly allocated node 0.
  • Loading branch information
trivialfis committed Apr 9, 2019
1 parent b72eab3 commit 7900bd4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/tree/updater_gpu_hist.cu
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,18 @@ class DeviceHistogram {
dh::safe_cuda(cudaSetDevice(device_id_));
if (data_.size() >= kStopGrowingSize) {
// Recycle histogram memory
std::pair<int, size_t> old_entry = *nidx_map_.begin();
nidx_map_.erase(old_entry.first);
dh::safe_cuda(cudaMemsetAsync(data_.data().get() + old_entry.second, 0,
n_bins_ * sizeof(GradientSumT)));
nidx_map_[nidx] = old_entry.second;
if (current_size + n_bins_ * sizeof(GradientSumT) < kStopGrowingSize) {
// just insert the new node.
nidx_map_[nidx] = current_size;
dh::safe_cuda(cudaMemsetAsync(data_.data().get() + current_size, 0,
n_bins_ * sizeof(GradientSumT)));
} else {
std::pair<int, size_t> old_entry = *nidx_map_.begin();
nidx_map_.erase(old_entry.first);
dh::safe_cuda(cudaMemsetAsync(data_.data().get() + old_entry.second, 0,
n_bins_ * sizeof(GradientSumT)));
nidx_map_[nidx] = old_entry.second;
}
} else {
// Append new node histogram
nidx_map_[nidx] = current_size;
Expand Down

0 comments on commit 7900bd4

Please sign in to comment.