From cede2aabaf5d66f37680f6a5a997ac5c7ec5d868 Mon Sep 17 00:00:00 2001 From: "dmitry.razdoburdin" Date: Thu, 1 Sep 2022 07:58:28 -0700 Subject: [PATCH 1/2] BuildHistKernel optimization --- 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 b2a268763b80..b5c954f01045 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 helps the compiler to use more effective processor instructions. + 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]; } } } From 0622ea356401251ddf6642ca9c235cee96b414ae Mon Sep 17 00:00:00 2001 From: "dmitry.razdoburdin" Date: Fri, 2 Sep 2022 01:05:04 -0700 Subject: [PATCH 2/2] Changes the comment --- src/common/hist_util.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/hist_util.cc b/src/common/hist_util.cc index b5c954f01045..e55477c95de2 100644 --- a/src/common/hist_util.cc +++ b/src/common/hist_util.cc @@ -192,7 +192,7 @@ void BuildHistKernel(const std::vector &gpair, } const BinIdxType *gr_index_local = gradient_index + icol_start; - // The trick with pgh_t helps the compiler to use more effective processor instructions. + // 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]) +