Re-introduce double buffer in UpdatePosition, to fix perf regression in gpu_hist (#6757)

* Revert "gpu_hist performance tweaks (#5707)"

This reverts commit f779980f7e.

* Address reviewer's comment

* Fix build error
This commit is contained in:
Philip Hyunsu Cho
2021-03-18 13:56:10 -07:00
committed by GitHub
parent e2d8a99413
commit 4230dcb614
3 changed files with 63 additions and 21 deletions

View File

@@ -549,6 +549,36 @@ class TemporaryArray {
size_t size_;
};
/**
* \brief A double buffer, useful for algorithms like sort.
*/
template <typename T>
class DoubleBuffer {
public:
cub::DoubleBuffer<T> buff;
xgboost::common::Span<T> a, b;
DoubleBuffer() = default;
template <typename VectorT>
DoubleBuffer(VectorT *v1, VectorT *v2) {
a = xgboost::common::Span<T>(v1->data().get(), v1->size());
b = xgboost::common::Span<T>(v2->data().get(), v2->size());
buff = cub::DoubleBuffer<T>(a.data(), b.data());
}
size_t Size() const {
CHECK_EQ(a.size(), b.size());
return a.size();
}
cub::DoubleBuffer<T> &CubBuffer() { return buff; }
T *Current() { return buff.Current(); }
xgboost::common::Span<T> CurrentSpan() {
return xgboost::common::Span<T>{buff.Current(), Size()};
}
T *Other() { return buff.Alternate(); }
};
/**
* \brief Copies device span to std::vector.
*