From 3d8d5b0f8568eca5d6977737511dbeeb97eddb72 Mon Sep 17 00:00:00 2001 From: igor_rukhovich Date: Thu, 19 Nov 2020 16:19:58 +0300 Subject: [PATCH 1/2] Improved InitSampling function speed by 2.12 times --- src/tree/updater_quantile_hist.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tree/updater_quantile_hist.cc b/src/tree/updater_quantile_hist.cc index 46a82ea3887e..ee40e63b17bd 100644 --- a/src/tree/updater_quantile_hist.cc +++ b/src/tree/updater_quantile_hist.cc @@ -691,17 +691,18 @@ void QuantileHistMaker::Builder::InitSampling(const std::vector(std::numeric_limits::max() + * param_.subsample); #pragma omp parallel num_threads(nthread) { const size_t tid = omp_get_thread_num(); const size_t ibegin = tid * discard_size; const size_t iend = (tid == (nthread - 1)) ? info.num_row_ : ibegin + discard_size; - std::bernoulli_distribution coin_flip(param_.subsample); - rnds[tid].discard(2*discard_size * tid); + rnds[tid].discard(discard_size * tid); for (size_t i = ibegin; i < iend; ++i) { - if (gpair[i].GetHess() >= 0.0f && coin_flip(rnds[tid])) { + if (gpair[i].GetHess() >= 0.0f && rnds[tid]() < coin_flip_border) { p_row_indices[ibegin + row_offsets[tid]++] = i; } } From f797c7b4996f5af46ba9959773c2c6df6e6487b7 Mon Sep 17 00:00:00 2001 From: igor_rukhovich Date: Thu, 19 Nov 2020 23:09:51 +0300 Subject: [PATCH 2/2] Added explicit conversion --- src/tree/updater_quantile_hist.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tree/updater_quantile_hist.cc b/src/tree/updater_quantile_hist.cc index ee40e63b17bd..a751673d5164 100644 --- a/src/tree/updater_quantile_hist.cc +++ b/src/tree/updater_quantile_hist.cc @@ -691,8 +691,8 @@ void QuantileHistMaker::Builder::InitSampling(const std::vector(std::numeric_limits::max() - * param_.subsample); + auto upper_border = static_cast(std::numeric_limits::max()); + uint32_t coin_flip_border = static_cast(upper_border * param_.subsample); #pragma omp parallel num_threads(nthread) { const size_t tid = omp_get_thread_num();