Fix span reverse iterator. (#7387)

* Fix span reverse iterator.

* Disable `rbegin` on device code to avoid calling host function.
* Add `trbegin` and friends.
This commit is contained in:
Jiaming Yuan
2021-11-02 13:35:59 +08:00
committed by GitHub
parent 8211e5f341
commit 6295dc3b67
3 changed files with 37 additions and 11 deletions

View File

@@ -957,6 +957,16 @@ thrust::device_ptr<T> tend(xgboost::common::Span<T>& span) { // NOLINT
return tbegin(span) + span.size();
}
template <typename T>
XGBOOST_DEVICE auto trbegin(xgboost::common::Span<T> &span) { // NOLINT
return thrust::make_reverse_iterator(span.data() + span.size());
}
template <typename T>
XGBOOST_DEVICE auto trend(xgboost::common::Span<T> &span) { // NOLINT
return trbegin(span) + span.size();
}
template <typename T>
thrust::device_ptr<T const> tcbegin(xgboost::common::Span<T> const& span) { // NOLINT
return thrust::device_ptr<T const>(span.data());
@@ -967,6 +977,16 @@ thrust::device_ptr<T const> tcend(xgboost::common::Span<T> const& span) { // NO
return tcbegin(span) + span.size();
}
template <typename T>
XGBOOST_DEVICE auto tcrbegin(xgboost::common::Span<T> const &span) { // NOLINT
return thrust::make_reverse_iterator(span.data() + span.size());
}
template <typename T>
XGBOOST_DEVICE auto tcrend(xgboost::common::Span<T> const &span) { // NOLINT
return tcrbegin(span) + span.size();
}
// This type sorts an array which is divided into multiple groups. The sorting is influenced
// by the function object 'Comparator'
template <typename T>