From deae99e662caf3c126184a8416e960295aa6024a Mon Sep 17 00:00:00 2001 From: Dmitry Razdoburdin Date: Fri, 2 Sep 2022 13:39:45 +0200 Subject: [PATCH] Optimization/buildhist/hist util (#8218) * BuildHistKernel optimization Co-authored-by: dmitry.razdoburdin --- src/common/hist_util.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/hist_util.cc b/src/common/hist_util.cc index b2a268763..e55477c95 100644 --- a/src/common/hist_util.cc +++ b/src/common/hist_util.cc @@ -192,11 +192,14 @@ void BuildHistKernel(const std::vector &gpair, } const BinIdxType *gr_index_local = gradient_index + icol_start; + // The trick with pgh_t buffer helps the compiler to generate faster binary. + const float pgh_t[] = {pgh[idx_gh], pgh[idx_gh + 1]}; for (size_t j = 0; j < row_size; ++j) { const uint32_t idx_bin = two * (static_cast(gr_index_local[j]) + (any_missing ? 0 : offsets[j])); - hist_data[idx_bin] += pgh[idx_gh]; - hist_data[idx_bin + 1] += pgh[idx_gh + 1]; + auto hist_local = hist_data + idx_bin; + *(hist_local) += pgh_t[0]; + *(hist_local + 1) += pgh_t[1]; } } }