Skip to content

Commit

Permalink
unrolling loop of histogram buliding in order_bin.
Browse files Browse the repository at this point in the history
  • Loading branch information
guolinke committed Mar 1, 2017
1 parent 4228bb7 commit a05e895
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/io/ordered_sparse_bin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,51 @@ class OrderedSparseBin: public OrderedBin {
// get current leaf boundary
const data_size_t start = leaf_start_[leaf];
const data_size_t end = start + leaf_cnt_[leaf];
const int rest = (end - start) % 4;
data_size_t i = start;
// use data on current leaf to construct histogram
for (data_size_t i = start; i < end; ++i) {
const VAL_T bin = ordered_pair_[i].bin;
const data_size_t idx = ordered_pair_[i].ridx;
out[bin].sum_gradients += gradient[idx];
out[bin].sum_hessians += hessian[idx];
++out[bin].cnt;
for (; i < end - rest; i += 4) {

const VAL_T bin0 = ordered_pair_[i].bin;
const VAL_T bin1 = ordered_pair_[i + 1].bin;
const VAL_T bin2 = ordered_pair_[i + 2].bin;
const VAL_T bin3 = ordered_pair_[i + 3].bin;

const auto g0 = gradient[ordered_pair_[i].ridx];
const auto h0 = hessian[ordered_pair_[i].ridx];
const auto g1 = gradient[ordered_pair_[i + 1].ridx];
const auto h1 = hessian[ordered_pair_[i + 1].ridx];
const auto g2 = gradient[ordered_pair_[i + 2].ridx];
const auto h2 = hessian[ordered_pair_[i + 2].ridx];
const auto g3 = gradient[ordered_pair_[i + 3].ridx];
const auto h3 = hessian[ordered_pair_[i + 3].ridx];

out[bin0].sum_gradients += g0;
out[bin1].sum_gradients += g1;
out[bin2].sum_gradients += g2;
out[bin3].sum_gradients += g3;

out[bin0].sum_hessians += h0;
out[bin1].sum_hessians += h1;
out[bin2].sum_hessians += h2;
out[bin3].sum_hessians += h3;

++out[bin0].cnt;
++out[bin1].cnt;
++out[bin2].cnt;
++out[bin3].cnt;
}

for (; i < end; ++i) {

const VAL_T bin0 = ordered_pair_[i].bin;

const auto g0 = gradient[ordered_pair_[i].ridx];
const auto h0 = hessian[ordered_pair_[i].ridx];

out[bin0].sum_gradients += g0;
out[bin0].sum_hessians += h0;
++out[bin0].cnt;
}
}

Expand Down

0 comments on commit a05e895

Please sign in to comment.