Make binary bin search reusable. (#6058)

* Move binary search row to hist util.
* Remove dead code.
This commit is contained in:
Jiaming Yuan
2020-08-26 05:05:11 +08:00
committed by GitHub
parent 9c14e430af
commit 80c8547147
8 changed files with 56 additions and 102 deletions

View File

@@ -13,34 +13,6 @@
#include <thrust/binary_search.h>
namespace xgboost {
// Find a gidx value for a given feature otherwise return -1 if not found
__forceinline__ __device__ int BinarySearchRow(
bst_uint begin, bst_uint end,
common::CompressedIterator<uint32_t> data,
int const fidx_begin, int const fidx_end) {
bst_uint previous_middle = UINT32_MAX;
while (end != begin) {
auto middle = begin + (end - begin) / 2;
if (middle == previous_middle) {
break;
}
previous_middle = middle;
auto gidx = data[middle];
if (gidx >= fidx_begin && gidx < fidx_end) {
return gidx;
} else if (gidx < fidx_begin) {
begin = middle;
} else {
end = middle;
}
}
// Value is missing
return -1;
}
/** \brief Struct for accessing and manipulating an ellpack matrix on the
* device. Does not own underlying memory and may be trivially copied into
* kernels.*/
@@ -83,11 +55,11 @@ struct EllpackDeviceAccessor {
if (is_dense) {
gidx = gidx_iter[row_begin + fidx];
} else {
gidx = BinarySearchRow(row_begin,
row_end,
gidx_iter,
feature_segments[fidx],
feature_segments[fidx + 1]);
gidx = common::BinarySearchBin(row_begin,
row_end,
gidx_iter,
feature_segments[fidx],
feature_segments[fidx + 1]);
}
return gidx;
}