xgboost

span.h
Go to the documentation of this file.
1
29 #ifndef XGBOOST_SPAN_H_
30 #define XGBOOST_SPAN_H_
31
32 #include <xgboost/base.h>
33 #include <xgboost/logging.h>
34
35 #include <cinttypes> // size_t
36 #include <limits> // numeric_limits
37 #include <iterator>
38 #include <type_traits>
39 #include <cstdio>
40
58 #if defined(_MSC_VER) && _MSC_VER < 1910
59
60 #define __span_noexcept
61
62 #pragma push_macro("constexpr")
63 #define constexpr /*constexpr*/
64
65 #else
66
67 #define __span_noexcept noexcept
68
69 #endif // defined(_MSC_VER) && _MSC_VER < 1910
70
71 namespace xgboost {
72 namespace common {
73
74 // Usual logging facility is not available inside device code.
75 // assert is not supported in mac as of CUDA 10.0
76 #define KERNEL_CHECK(cond) \
77 do { \
78 if (!(cond)) { \
79 printf("\nKernel error:\n" \
80 "In: %s: %d\n" \
81 "\t%s\n\tExpecting: %s\n" \
82 "\tBlock: [%d, %d, %d], Thread: [%d, %d, %d]\n\n", \
83 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, blockIdx.x, \
84 blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z); \
85 asm("trap;"); \
86 } \
87 } while (0);
88
89 #if defined(__CUDA_ARCH__)
90 #define SPAN_CHECK KERNEL_CHECK
91 #elif defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1 // R package
92 #define SPAN_CHECK CHECK // check from dmlc
93 #else // not CUDA, not R
94 #define SPAN_CHECK(cond) \
95 do { \
96 if (XGBOOST_EXPECT(!(cond), false)) { \
97 fprintf(stderr, "[xgboost] Condition %s failed.\n", #cond); \
98 fflush(stderr); /* It seems stderr on Windows is beffered? */ \
99 std::terminate(); \
100 } \
101 } while (0);
102 #endif // __CUDA_ARCH__
103
104 #if defined(__CUDA_ARCH__)
105 #define SPAN_LT(lhs, rhs) \
106 if (!((lhs) < (rhs))) { \
107 printf("[xgboost] Condition: %lu < %lu failed\n", \
108 static_cast<size_t>(lhs), static_cast<size_t>(rhs)); \
109 asm("trap;"); \
110 }
111 #else
112 #define SPAN_LT(lhs, rhs) SPAN_CHECK((lhs) < (rhs))
113 #endif // defined(__CUDA_ARCH__)
114
115 namespace detail {
122 using ptrdiff_t = typename std::conditional< // NOLINT
123 std::is_same<std::ptrdiff_t, std::int64_t>::value,
124 std::ptrdiff_t, std::int64_t>::type;
125 } // namespace detail
126
127 #if defined(_MSC_VER) && _MSC_VER < 1910
128 constexpr const std::size_t
129 dynamic_extent = std::numeric_limits<std::size_t>::max(); // NOLINT
130 #else
131 constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max(); // NOLINT
132 #endif // defined(_MSC_VER) && _MSC_VER < 1910
133
134 enum class byte : unsigned char {}; // NOLINT
135
136 template <class ElementType, std::size_t Extent>
137 class Span;
138
139 namespace detail {
140
141 template <typename SpanType, bool IsConst>
142 class SpanIterator {
143 using ElementType = typename SpanType::element_type;
144
145 public:
146 using iterator_category = std::random_access_iterator_tag; // NOLINT
147 using value_type = typename SpanType::value_type; // NOLINT
148 using difference_type = detail::ptrdiff_t; // NOLINT
149
150 using reference = typename std::conditional< // NOLINT
151 IsConst, const ElementType, ElementType>::type&;
152 using pointer = typename std::add_pointer<reference>::type; // NOLINT
153
154 constexpr SpanIterator() = default;
155
156 XGBOOST_DEVICE constexpr SpanIterator(
157 const SpanType* _span,
158 typename SpanType::index_type _idx) __span_noexcept :
159 span_(_span), index_(_idx) {}
160
161 friend SpanIterator<SpanType, true>;
162 template <bool B, typename std::enable_if<!B && IsConst>::type* = nullptr>
163 XGBOOST_DEVICE constexpr SpanIterator( // NOLINT
164 const SpanIterator<SpanType, B>& other_) __span_noexcept
165 : SpanIterator(other_.span_, other_.index_) {}
166
167 XGBOOST_DEVICE reference operator*() const {
168 SPAN_CHECK(index_ < span_->size());
169 return *(span_->data() + index_);
170 }
171 XGBOOST_DEVICE reference operator[](difference_type n) const {
172 return *(*this + n);
173 }
174
175 XGBOOST_DEVICE pointer operator->() const {
176 SPAN_CHECK(index_ != span_->size());
177 return span_->data() + index_;
178 }
179
180 XGBOOST_DEVICE SpanIterator& operator++() {
181 SPAN_CHECK(index_ != span_->size());
182 index_++;
183 return *this;
184 }
185
186 XGBOOST_DEVICE SpanIterator operator++(int) {
187 auto ret = *this;
188 ++(*this);
189 return ret;
190 }
191
192 XGBOOST_DEVICE SpanIterator& operator--() {
193 SPAN_CHECK(index_ != 0 && index_ <= span_->size());
194 index_--;
195 return *this;
196 }
197
198 XGBOOST_DEVICE SpanIterator operator--(int) {
199 auto ret = *this;
200 --(*this);
201 return ret;
202 }
203
204 XGBOOST_DEVICE SpanIterator operator+(difference_type n) const {
205 auto ret = *this;
206 return ret += n;
207 }
208
209 XGBOOST_DEVICE SpanIterator& operator+=(difference_type n) {
210 SPAN_CHECK((index_ + n) <= span_->size());
211 index_ += n;
212 return *this;
213 }
214
215 XGBOOST_DEVICE difference_type operator-(SpanIterator rhs) const {
216 SPAN_CHECK(span_ == rhs.span_);
217 return index_ - rhs.index_;
218 }
219
220 XGBOOST_DEVICE SpanIterator operator-(difference_type n) const {
221 auto ret = *this;
222 return ret -= n;
223 }
224
225 XGBOOST_DEVICE SpanIterator& operator-=(difference_type n) {
226 return *this += -n;
227 }
228
229 // friends
230 XGBOOST_DEVICE constexpr friend bool operator==(
231 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
232 return _lhs.span_ == _rhs.span_ && _lhs.index_ == _rhs.index_;
233 }
234
235 XGBOOST_DEVICE constexpr friend bool operator!=(
236 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
237 return !(_lhs == _rhs);
238 }
239
240 XGBOOST_DEVICE constexpr friend bool operator<(
241 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
242 return _lhs.index_ < _rhs.index_;
243 }
244
245 XGBOOST_DEVICE constexpr friend bool operator<=(
246 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
247 return !(_rhs < _lhs);
248 }
249
250 XGBOOST_DEVICE constexpr friend bool operator>(
251 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
252 return _rhs < _lhs;
253 }
254
255 XGBOOST_DEVICE constexpr friend bool operator>=(
256 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
257 return !(_rhs > _lhs);
258 }
259
260 protected:
261 const SpanType *span_ { nullptr };
262 typename SpanType::index_type index_ { 0 };
263 };
264
265
266 // It's tempting to use constexpr instead of structs to do the following meta
267 // programming. But remember that we are supporting MSVC 2013 here.
268
276 template <std::size_t Extent, std::size_t Offset, std::size_t Count>
277 struct ExtentValue : public std::integral_constant<
278 std::size_t, Count != dynamic_extent ?
279 Count : (Extent != dynamic_extent ? Extent - Offset : Extent)> {};
280
285 template <typename T, std::size_t Extent>
286 struct ExtentAsBytesValue : public std::integral_constant<
287 std::size_t,
288 Extent == dynamic_extent ?
289 Extent : sizeof(T) * Extent> {};
290
291 template <std::size_t From, std::size_t To>
292 struct IsAllowedExtentConversion : public std::integral_constant<
293 bool, From == To || From == dynamic_extent || To == dynamic_extent> {};
294
295 template <class From, class To>
296 struct IsAllowedElementTypeConversion : public std::integral_constant<
297 bool, std::is_convertible<From(*)[], To(*)[]>::value> {};
298
299 template <class T>
300 struct IsSpanOracle : std::false_type {};
301
302 template <class T, std::size_t Extent>
303 struct IsSpanOracle<Span<T, Extent>> : std::true_type {};
304
305 template <class T>
306 struct IsSpan : public IsSpanOracle<typename std::remove_cv<T>::type> {};
307
308 // Re-implement std algorithms here to adopt CUDA.
309 template <typename T>
310 struct Less {
311 XGBOOST_DEVICE constexpr bool operator()(const T& _x, const T& _y) const {
312 return _x < _y;
313 }
314 };
315
316 template <typename T>
317 struct Greater {
318 XGBOOST_DEVICE constexpr bool operator()(const T& _x, const T& _y) const {
319 return _x > _y;
320 }
321 };
322
323 template <class InputIt1, class InputIt2,
324 class Compare =
325 detail::Less<decltype(std::declval<InputIt1>().operator*())>>
326 XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1,
327 InputIt2 first2, InputIt2 last2) {
328 Compare comp;
329 for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
330 if (comp(*first1, *first2)) {
331 return true;
332 }
333 if (comp(*first2, *first1)) {
334 return false;
335 }
336 }
337 return first1 == last1 && first2 != last2;
338 }
339
340 } // namespace detail
341
342
410 template <typename T,
411 std::size_t Extent = dynamic_extent>
412 class Span {
413 public:
414 using element_type = T; // NOLINT
415 using value_type = typename std::remove_cv<T>::type; // NOLINT
416 using index_type = std::size_t; // NOLINT
417 using difference_type = detail::ptrdiff_t; // NOLINT
418 using pointer = T*; // NOLINT
419 using reference = T&; // NOLINT
420
421 using iterator = detail::SpanIterator<Span<T, Extent>, false>; // NOLINT
422 using const_iterator = const detail::SpanIterator<Span<T, Extent>, true>; // NOLINT
423 using reverse_iterator = detail::SpanIterator<Span<T, Extent>, false>; // NOLINT
424 using const_reverse_iterator = const detail::SpanIterator<Span<T, Extent>, true>; // NOLINT
425
426 // constructors
427 constexpr Span() __span_noexcept = default;
428
429 XGBOOST_DEVICE Span(pointer _ptr, index_type _count) :
430 size_(_count), data_(_ptr) {
431 SPAN_CHECK(!(Extent != dynamic_extent && _count != Extent));
432 SPAN_CHECK(_ptr || _count == 0);
433 }
434
435 XGBOOST_DEVICE Span(pointer _first, pointer _last) :
436 size_(_last - _first), data_(_first) {
437 SPAN_CHECK(data_ || size_ == 0);
438 }
439
440 template <std::size_t N>
441 XGBOOST_DEVICE constexpr Span(element_type (&arr)[N]) // NOLINT
442 __span_noexcept : size_(N), data_(&arr[0]) {}
443
444 template <class Container,
445 class = typename std::enable_if<
446 !std::is_const<element_type>::value &&
447 !detail::IsSpan<Container>::value &&
448 std::is_convertible<typename Container::pointer, pointer>::value &&
449 std::is_convertible<typename Container::pointer,
450 decltype(std::declval<Container>().data())>::value>::type>
451 Span(Container& _cont) : // NOLINT
452 size_(_cont.size()), data_(_cont.data()) {
453 static_assert(!detail::IsSpan<Container>::value, "Wrong constructor of Span is called.");
454 }
455
456 template <class Container,
457 class = typename std::enable_if<
458 std::is_const<element_type>::value &&
459 !detail::IsSpan<Container>::value &&
460 std::is_convertible<typename Container::pointer, pointer>::value &&
461 std::is_convertible<typename Container::pointer,
462 decltype(std::declval<Container>().data())>::value>::type>
463 Span(const Container& _cont) : size_(_cont.size()), // NOLINT
464 data_(_cont.data()) {
465 static_assert(!detail::IsSpan<Container>::value, "Wrong constructor of Span is called.");
466 }
467
468 template <class U, std::size_t OtherExtent,
469 class = typename std::enable_if<
470 detail::IsAllowedElementTypeConversion<U, T>::value &&
471 detail::IsAllowedExtentConversion<OtherExtent, Extent>::value>>
472 XGBOOST_DEVICE constexpr Span(const Span<U, OtherExtent>& _other) // NOLINT
473 __span_noexcept : size_(_other.size()), data_(_other.data()) {}
474
475 XGBOOST_DEVICE constexpr Span(const Span& _other)
476 __span_noexcept : size_(_other.size()), data_(_other.data()) {}
477
478 XGBOOST_DEVICE Span& operator=(const Span& _other) __span_noexcept {
479 size_ = _other.size();
480 data_ = _other.data();
481 return *this;
482 }
483
484 XGBOOST_DEVICE ~Span() __span_noexcept {}; // NOLINT
485
486 XGBOOST_DEVICE constexpr iterator begin() const __span_noexcept { // NOLINT
487 return {this, 0};
488 }
489
490 XGBOOST_DEVICE constexpr iterator end() const __span_noexcept { // NOLINT
491 return {this, size()};
492 }
493
494 XGBOOST_DEVICE constexpr const_iterator cbegin() const __span_noexcept { // NOLINT
495 return {this, 0};
496 }
497
498 XGBOOST_DEVICE constexpr const_iterator cend() const __span_noexcept { // NOLINT
499 return {this, size()};
500 }
501
502 XGBOOST_DEVICE constexpr reverse_iterator rbegin() const __span_noexcept { // NOLINT
503 return reverse_iterator{end()};
504 }
505
506 XGBOOST_DEVICE constexpr reverse_iterator rend() const __span_noexcept { // NOLINT
507 return reverse_iterator{begin()};
508 }
509
510 XGBOOST_DEVICE constexpr const_reverse_iterator crbegin() const __span_noexcept { // NOLINT
511 return const_reverse_iterator{cend()};
512 }
513
514 XGBOOST_DEVICE constexpr const_reverse_iterator crend() const __span_noexcept { // NOLINT
515 return const_reverse_iterator{cbegin()};
516 }
517
518 // element access
519
520 XGBOOST_DEVICE reference front() const { // NOLINT
521 return (*this)[0];
522 }
523
524 XGBOOST_DEVICE reference back() const { // NOLINT
525 return (*this)[size() - 1];
526 }
527
528 XGBOOST_DEVICE reference operator[](index_type _idx) const {
529 SPAN_LT(_idx, size());
530 return data()[_idx];
531 }
532
533 XGBOOST_DEVICE reference operator()(index_type _idx) const {
534 return this->operator[](_idx);
535 }
536
537 XGBOOST_DEVICE constexpr pointer data() const __span_noexcept { // NOLINT
538 return data_;
539 }
540
541 // Observers
542 XGBOOST_DEVICE constexpr index_type size() const __span_noexcept { // NOLINT
543 return size_;
544 }
545 XGBOOST_DEVICE constexpr index_type size_bytes() const __span_noexcept { // NOLINT
546 return size() * sizeof(T);
547 }
548
549 XGBOOST_DEVICE constexpr bool empty() const __span_noexcept { // NOLINT
550 return size() == 0;
551 }
552
553 // Subviews
554 template <std::size_t Count>
555 XGBOOST_DEVICE Span<element_type, Count> first() const { // NOLINT
556 SPAN_CHECK(Count <= size());
557 return {data(), Count};
558 }
559
560 XGBOOST_DEVICE Span<element_type, dynamic_extent> first( // NOLINT
561 std::size_t _count) const {
562 SPAN_CHECK(_count <= size());
563 return {data(), _count};
564 }
565
566 template <std::size_t Count>
567 XGBOOST_DEVICE Span<element_type, Count> last() const { // NOLINT
568 SPAN_CHECK(Count <= size());
569 return {data() + size() - Count, Count};
570 }
571
572 XGBOOST_DEVICE Span<element_type, dynamic_extent> last( // NOLINT
573 std::size_t _count) const {
574 SPAN_CHECK(_count <= size());
575 return subspan(size() - _count, _count);
576 }
577
582 template <std::size_t Offset,
583 std::size_t Count = dynamic_extent>
584 XGBOOST_DEVICE auto subspan() const -> // NOLINT
585 Span<element_type,
586 detail::ExtentValue<Extent, Offset, Count>::value> {
587 SPAN_CHECK((Count == dynamic_extent) ?
588 (Offset <= size()) : (Offset + Count <= size()));
589 return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
590 }
591
592 XGBOOST_DEVICE Span<element_type, dynamic_extent> subspan( // NOLINT
593 index_type _offset,
594 index_type _count = dynamic_extent) const {
595 SPAN_CHECK((_count == dynamic_extent) ?
596 (_offset <= size()) : (_offset + _count <= size()));
597 return {data() + _offset, _count ==
598 dynamic_extent ? size() - _offset : _count};
599 }
600
601 private:
602 index_type size_ { 0 };
603 pointer data_ { nullptr };
604 };
605
606 template <class T, std::size_t X, class U, std::size_t Y>
607 XGBOOST_DEVICE bool operator==(Span<T, X> l, Span<U, Y> r) {
608 if (l.size() != r.size()) {
609 return false;
610 }
611 for (auto l_beg = l.cbegin(), r_beg = r.cbegin(); l_beg != l.cend();
612 ++l_beg, ++r_beg) {
613 if (*l_beg != *r_beg) {
614 return false;
615 }
616 }
617 return true;
618 }
619
620 template <class T, std::size_t X, class U, std::size_t Y>
621 XGBOOST_DEVICE constexpr bool operator!=(Span<T, X> l, Span<U, Y> r) {
622 return !(l == r);
623 }
624
625 template <class T, std::size_t X, class U, std::size_t Y>
626 XGBOOST_DEVICE constexpr bool operator<(Span<T, X> l, Span<U, Y> r) {
627 return detail::LexicographicalCompare(l.begin(), l.end(),
628 r.begin(), r.end());
629 }
630
631 template <class T, std::size_t X, class U, std::size_t Y>
632 XGBOOST_DEVICE constexpr bool operator<=(Span<T, X> l, Span<U, Y> r) {
633 return !(l > r);
634 }
635
636 template <class T, std::size_t X, class U, std::size_t Y>
637 XGBOOST_DEVICE constexpr bool operator>(Span<T, X> l, Span<U, Y> r) {
638 return detail::LexicographicalCompare<
639 typename Span<T, X>::iterator, typename Span<U, Y>::iterator,
640 detail::Greater<typename Span<T, X>::element_type>>(l.begin(), l.end(),
641 r.begin(), r.end());
642 }
643
644 template <class T, std::size_t X, class U, std::size_t Y>
645 XGBOOST_DEVICE constexpr bool operator>=(Span<T, X> l, Span<U, Y> r) {
646 return !(l < r);
647 }
648
649 template <class T, std::size_t E>
650 XGBOOST_DEVICE auto as_bytes(Span<T, E> s) __span_noexcept -> // NOLINT
651 Span<const byte, detail::ExtentAsBytesValue<T, E>::value> {
652 return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
653 }
654
655 template <class T, std::size_t E>
656 XGBOOST_DEVICE auto as_writable_bytes(Span<T, E> s) __span_noexcept -> // NOLINT
657 Span<byte, detail::ExtentAsBytesValue<T, E>::value> {
658 return {reinterpret_cast<byte*>(s.data()), s.size_bytes()};
659 }
660
661 } // namespace common
662 } // namespace xgboost
663
664 #if defined(_MSC_VER) &&_MSC_VER < 1910
665 #undef constexpr
666 #pragma pop_macro("constexpr")
667 #undef __span_noexcept
668 #endif // _MSC_VER < 1910
669
670 #endif // XGBOOST_SPAN_H_
xgboost::common::detail::SpanIterator::operator--
XGBOOST_DEVICE SpanIterator operator--(int)
Definition: span.h:198
xgboost::common::detail::Less::operator()
constexpr XGBOOST_DEVICE bool operator()(const T &_x, const T &_y) const
Definition: span.h:311
xgboost::common::detail::ptrdiff_t
typename std::conditional< std::is_same< std::ptrdiff_t, std::int64_t >::value, std::ptrdiff_t, std::int64_t >::type ptrdiff_t
Definition: span.h:124
xgboost::common::Span::Span
constexpr Span() __span_noexcept=default
xgboost::common::operator<=
constexpr XGBOOST_DEVICE bool operator<=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:632
xgboost::common::Span::end
constexpr XGBOOST_DEVICE iterator end() const __span_noexcept
Definition: span.h:490
xgboost::common::Span::last
XGBOOST_DEVICE Span< element_type, dynamic_extent > last(std::size_t _count) const
Definition: span.h:572
xgboost::common::detail::Greater::operator()
constexpr XGBOOST_DEVICE bool operator()(const T &_x, const T &_y) const
Definition: span.h:318
xgboost::common::detail::SpanIterator::operator--
XGBOOST_DEVICE SpanIterator & operator--()
Definition: span.h:192
__span_noexcept
#define __span_noexcept
span class based on ISO++20 span
Definition: span.h:67
xgboost::common::detail::SpanIterator::operator==
constexpr XGBOOST_DEVICE friend bool operator==(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:230
xgboost::common::detail::ExtentValue
Definition: span.h:277
xgboost::common::operator>=
constexpr XGBOOST_DEVICE bool operator>=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:645
xgboost::common::Span::Span
XGBOOST_DEVICE Span(pointer _first, pointer _last)
Definition: span.h:435
xgboost::common::Span< xgboost::Entry const >::index_type
std::size_t index_type
Definition: span.h:416
xgboost::common::byte
byte
Definition: span.h:134
xgboost::common::detail::IsAllowedExtentConversion
Definition: span.h:292
xgboost::common::operator==
XGBOOST_DEVICE bool operator==(Span< T, X > l, Span< U, Y > r)
Definition: span.h:607
xgboost::common::detail::SpanIterator::operator->
XGBOOST_DEVICE pointer operator->() const
Definition: span.h:175
xgboost::common::detail::SpanIterator::operator++
XGBOOST_DEVICE SpanIterator & operator++()
Definition: span.h:180
xgboost::common::Span< xgboost::Entry const >::element_type
xgboost::Entry const element_type
Definition: span.h:414
xgboost::common::detail::SpanIterator::operator-
XGBOOST_DEVICE SpanIterator operator-(difference_type n) const
Definition: span.h:220
xgboost::common::Span::subspan
XGBOOST_DEVICE Span< element_type, dynamic_extent > subspan(index_type _offset, index_type _count=dynamic_extent) const
Definition: span.h:592
xgboost::common::operator<
constexpr XGBOOST_DEVICE bool operator<(Span< T, X > l, Span< U, Y > r)
Definition: span.h:626
xgboost::common::detail::SpanIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: span.h:146
base.h
defines configuration macros of xgboost.
SPAN_CHECK
#define SPAN_CHECK(cond)
Definition: span.h:94
xgboost::common::Span::operator[]
XGBOOST_DEVICE reference operator[](index_type _idx) const
Definition: span.h:528
xgboost::common::detail::SpanIterator::operator>
constexpr XGBOOST_DEVICE friend bool operator>(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:250
xgboost::common::detail::LexicographicalCompare
XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
Definition: span.h:326
xgboost::common::Span< xgboost::Entry const >::difference_type
detail::ptrdiff_t difference_type
Definition: span.h:417
xgboost::common::Span::back
XGBOOST_DEVICE reference back() const
Definition: span.h:524
xgboost::common::detail::SpanIterator::operator-=
XGBOOST_DEVICE SpanIterator & operator-=(difference_type n)
Definition: span.h:225
xgboost::common::Span::size_bytes
constexpr XGBOOST_DEVICE index_type size_bytes() const __span_noexcept
Definition: span.h:545
xgboost::common::detail::SpanIterator::difference_type
detail::ptrdiff_t difference_type
Definition: span.h:148
xgboost::common::Span::Span
constexpr XGBOOST_DEVICE Span(element_type(&arr)[N]) __span_noexcept
Definition: span.h:441
xgboost::common::operator>
constexpr XGBOOST_DEVICE bool operator>(Span< T, X > l, Span< U, Y > r)
Definition: span.h:637
xgboost::common::detail::SpanIterator::operator+=
XGBOOST_DEVICE SpanIterator & operator+=(difference_type n)
Definition: span.h:209
xgboost::common::detail::SpanIterator::operator*
XGBOOST_DEVICE reference operator*() const
Definition: span.h:167
xgboost::common::Span::empty
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:549
xgboost::common::dynamic_extent
constexpr std::size_t dynamic_extent
Definition: span.h:131
xgboost::common::detail::SpanIterator::SpanIterator
constexpr SpanIterator()=default
xgboost::common::detail::SpanIterator::operator+
XGBOOST_DEVICE SpanIterator operator+(difference_type n) const
Definition: span.h:204
xgboost::common::as_writable_bytes
XGBOOST_DEVICE auto as_writable_bytes(Span< T, E > s) __span_noexcept -> Span< byte, detail::ExtentAsBytesValue< T, E >::value >
Definition: span.h:656
xgboost::common::Span::begin
constexpr XGBOOST_DEVICE iterator begin() const __span_noexcept
Definition: span.h:486
xgboost::common::detail::SpanIterator
Definition: span.h:142
xgboost::common::Span< xgboost::Entry const >::reference
xgboost::Entry const & reference
Definition: span.h:419
xgboost::common::detail::SpanIterator::operator-
XGBOOST_DEVICE difference_type operator-(SpanIterator rhs) const
Definition: span.h:215
xgboost::common::detail::SpanIterator::operator[]
XGBOOST_DEVICE reference operator[](difference_type n) const
Definition: span.h:171
xgboost::common::Span::Span
Span(Container &_cont)
Definition: span.h:451
xgboost::common::Span::subspan
XGBOOST_DEVICE auto subspan() const -> Span< element_type, detail::ExtentValue< Extent, Offset, Count >::value >
Definition: span.h:584
xgboost::common::detail::SpanIterator::SpanIterator
constexpr XGBOOST_DEVICE SpanIterator(const SpanIterator< SpanType, B > &other_) __span_noexcept
Definition: span.h:163
xgboost::common::operator!=
constexpr XGBOOST_DEVICE bool operator!=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:621
xgboost::common::Span::front
XGBOOST_DEVICE reference front() const
Definition: span.h:520
xgboost::common::detail::SpanIterator::span_
const SpanType * span_
Definition: span.h:261
xgboost::common::detail::SpanIterator::operator<
constexpr XGBOOST_DEVICE friend bool operator<(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:240
xgboost::common::Span::operator()
XGBOOST_DEVICE reference operator()(index_type _idx) const
Definition: span.h:533
xgboost::common::detail::IsSpanOracle
Definition: span.h:300
xgboost::common::Span< xgboost::Entry const >::value_type
typename std::remove_cv< xgboost::Entry const >::type value_type
Definition: span.h:415
xgboost::common::detail::SpanIterator::operator<=
constexpr XGBOOST_DEVICE friend bool operator<=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:245
xgboost::common::Span::crend
constexpr XGBOOST_DEVICE const_reverse_iterator crend() const __span_noexcept
Definition: span.h:514
xgboost::common::Span::first
XGBOOST_DEVICE Span< element_type, dynamic_extent > first(std::size_t _count) const
Definition: span.h:560
xgboost::common::Span::rbegin
constexpr XGBOOST_DEVICE reverse_iterator rbegin() const __span_noexcept
Definition: span.h:502
xgboost::common::detail::SpanIterator::operator>=
constexpr XGBOOST_DEVICE friend bool operator>=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:255
xgboost::common::Span< xgboost::Entry const >::pointer
xgboost::Entry const * pointer
Definition: span.h:418
SPAN_LT
#define SPAN_LT(lhs, rhs)
Definition: span.h:112
xgboost::common::detail::Greater
Definition: span.h:317
xgboost::common::Span::first
XGBOOST_DEVICE Span< element_type, Count > first() const
Definition: span.h:555
xgboost::common::detail::IsSpan
Definition: span.h:306
xgboost::common::Span
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:137
xgboost::common::Span::operator=
XGBOOST_DEVICE Span & operator=(const Span &_other) __span_noexcept
Definition: span.h:478
xgboost::common::detail::IsAllowedElementTypeConversion
Definition: span.h:296
xgboost::common::Span::cbegin
constexpr XGBOOST_DEVICE const_iterator cbegin() const __span_noexcept
Definition: span.h:494
xgboost::common::Span::crbegin
constexpr XGBOOST_DEVICE const_reverse_iterator crbegin() const __span_noexcept
Definition: span.h:510
xgboost::common::Span::size
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:542
xgboost::common::Span::last
XGBOOST_DEVICE Span< element_type, Count > last() const
Definition: span.h:567
xgboost::common::Span::data
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:537
xgboost::common::Span::cend
constexpr XGBOOST_DEVICE const_iterator cend() const __span_noexcept
Definition: span.h:498
xgboost::common::as_bytes
XGBOOST_DEVICE auto as_bytes(Span< T, E > s) __span_noexcept -> Span< const byte, detail::ExtentAsBytesValue< T, E >::value >
Definition: span.h:650
xgboost::common::Span::Span
Span(const Container &_cont)
Definition: span.h:463
xgboost::common::detail::ExtentAsBytesValue
Definition: span.h:286
xgboost::common::detail::SpanIterator::operator++
XGBOOST_DEVICE SpanIterator operator++(int)
Definition: span.h:186
xgboost::common::Span::Span
constexpr XGBOOST_DEVICE Span(const Span &_other) __span_noexcept
Definition: span.h:475
xgboost::common::detail::SpanIterator::operator!=
constexpr XGBOOST_DEVICE friend bool operator!=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:235
xgboost::common::detail::SpanIterator::pointer
typename std::add_pointer< reference >::type pointer
Definition: span.h:152
xgboost::common::detail::SpanIterator::reference
typename std::conditional< IsConst, const ElementType, ElementType >::type & reference
Definition: span.h:151
xgboost::common::detail::SpanIterator::index_
SpanType::index_type index_
Definition: span.h:262
XGBOOST_DEVICE
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
xgboost::common::detail::Less
Definition: span.h:310
xgboost::common::detail::SpanIterator::value_type
typename SpanType::value_type value_type
Definition: span.h:147
xgboost::common::Span::~Span
XGBOOST_DEVICE ~Span() __span_noexcept
Definition: span.h:484
xgboost
namespace of xgboost
Definition: base.h:110
xgboost::common::Span::rend
constexpr XGBOOST_DEVICE reverse_iterator rend() const __span_noexcept
Definition: span.h:506
xgboost::common::detail::SpanIterator::SpanIterator
constexpr XGBOOST_DEVICE SpanIterator(const SpanType *_span, typename SpanType::index_type _idx) __span_noexcept
Definition: span.h:156
xgboost::common::Span::Span
constexpr XGBOOST_DEVICE Span(const Span< U, OtherExtent > &_other) __span_noexcept
Definition: span.h:472